Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 14 additions & 22 deletions src/build-change-graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ async function buildChangeGraph({
return path.relative(workspaceMeta.cwd, cwd);
});

let longestBranch;

for (let _package of collectPackages(workspaceMeta)) {
if (!_package.packageName || !_package.version) {
continue;
Expand Down Expand Up @@ -179,17 +181,7 @@ async function buildChangeGraph({
}
}

let changedFiles = await getPackageChangedFiles({
fromCommit: _fromCommit,
toCommit,
packageCwd: _package.cwd,
shouldRunPerPackage: false,
shouldExcludeDeleted,
options: {
cwd: workspaceMeta.cwd,
cached,
},
});
let changedFiles = [];

let newFiles = changedFiles;

Expand All @@ -203,23 +195,23 @@ async function buildChangeGraph({
}

if (!newFiles.length) {
continue;
// continue;
}

let changedReleasableFiles = await getChangedReleasableFiles({
changedFiles: newFiles,
packageCwd: _package.cwd,
workspacesCwd: workspaceMeta.cwd,
shouldExcludeDevChanges,
fromCommit: _fromCommit,
nextConfig,
});
let changedReleasableFiles = [];

if (shouldOnlyIncludeReleasable && !changedReleasableFiles.length) {
continue;
// continue;
}

let dag = buildDAG(workspaceMeta, _package.packageName);
let {
dag,
longestBranch: _longestBranch,
} = buildDAG(workspaceMeta, _package.packageName);

if (_longestBranch.length > (longestBranch?.length ?? 0)) {
longestBranch = _longestBranch;
}

packagesWithChanges[_package.packageName] = {
changedFiles: newFiles,
Expand Down
67 changes: 51 additions & 16 deletions src/build-dag.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ function thirdPass({

visitedNodes[currentPackageName] = group.node;

let longestBranch = branch;

for (let _package of collectPackages(workspaceMeta)) {
if (_package.packageName === currentPackageName) {
continue;
Expand All @@ -42,14 +44,18 @@ function thirdPass({
if (visitedNode) {
let isCycle = branch.includes(_package.packageName);

group.node.dependents.push({
let {
newGroup,
} = createPackageNode({
parent,
dependencyType,
dependencyRange,
isCycle,
node: visitedNode,
});

group.node.dependents.push(newGroup);

continue;
}

Expand All @@ -67,19 +73,29 @@ function thirdPass({

group.node.dependents.push(newGroup);

if (dependencyType === 'devDependencies') {
continue;
}

// We don't want to check if it's private here because
// you could have a chain of private packages, and you
// want to bump them all the way down.
// if (group.node.isPackage) {
thirdPass({
let _longestBranch = thirdPass({
workspaceMeta,
group: newGroup,
branch: newBranch,
visitedNodes,
});

if (_longestBranch.length > longestBranch.length) {
longestBranch = _longestBranch;
}
// }
}
}

return longestBranch;
}

function createPackageNode({
Expand All @@ -88,24 +104,41 @@ function createPackageNode({
dependencyType,
dependencyRange,
parent,
branch,
branch = [],
node,
isCycle = false,
}) {
let _package = workspaceMeta.packages[packageName] ?? workspaceMeta;
let newNode;

if (node) {
newNode = node;
} else {
let _package = workspaceMeta.packages[packageName] ?? workspaceMeta;

newNode = {
isPackage: !_package.isPrivate,
cwd: _package.cwd,
packageName,
version: _package.version,
dependents: [],
};
}

let node = {
isPackage: !_package.isPrivate,
cwd: _package.cwd,
packageName,
version: _package.version,
dependents: [],
};
let longestChain;

if (isCycle) {
longestChain = Infinity;
} else {
longestChain = (parent?.longestChain ?? 0) + 1;
}

let group = {
parent,
dependencyType,
dependencyRange,
isCycle: false,
node,
isCycle,
node: newNode,
longestChain,
};

let newBranch = [...branch, packageName].filter(Boolean);
Expand All @@ -123,19 +156,21 @@ function buildDAG(workspaceMeta, packageName) {
} = createPackageNode({
workspaceMeta,
packageName,
branch: [],
});

let visitedNodes = {};

thirdPass({
let longestBranch = thirdPass({
workspaceMeta,
group: newGroup,
branch: newBranch,
visitedNodes,
});

return newGroup;
return {
dag: newGroup,
longestBranch,
};
}

module.exports = buildDAG;