Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): filter out task dependencies on itself #28261

Merged
merged 1 commit into from
Oct 3, 2024
Merged
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
65 changes: 65 additions & 0 deletions packages/nx/src/tasks-runner/create-task-graph.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1490,6 +1490,71 @@ describe('createTaskGraph', () => {
});
});

it('should handle cycles where tasks seem to depend on themselves (lib1:build -> lib2 -> lib1:build)', () => {
projectGraph = {
nodes: {
lib1: {
name: 'lib1',
type: 'lib',
data: {
root: 'lib1-root',
targets: {
build: {
executor: 'nx:run-commands',
},
},
},
},
lib2: {
name: 'lib2',
type: 'lib',
data: {
root: 'lib2-root',
targets: {},
},
},
},
dependencies: {
lib1: [{ source: 'lib1', target: 'lib2', type: 'static' }],
lib2: [{ source: 'lib2', target: 'lib1', type: 'static' }],
},
};

const taskGraph = createTaskGraph(
projectGraph,
{
build: [{ target: 'build', dependencies: true }],
},
['lib1'],
['build'],
'development',
{
__overrides_unparsed__: [],
}
);
expect(taskGraph).toEqual({
roots: ['lib1:build'],
tasks: {
'lib1:build': expect.objectContaining({
id: 'lib1:build',
target: {
project: 'lib1',
target: 'build',
},
outputs: expect.arrayContaining([expect.any(String)]),
overrides: {
__overrides_unparsed__: [],
},
projectRoot: 'lib1-root',
parallelism: true,
}),
},
dependencies: {
'lib1:build': [],
},
});
});

it('should handle cycles between projects where all projects do not contain the same task target (lib1:build -> lib2:build -> lib3 -> lib4:build -> lib1:build)', () => {
projectGraph = {
nodes: {
Expand Down
10 changes: 6 additions & 4 deletions packages/nx/src/tasks-runner/create-task-graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,12 @@ export class ProcessTasks {

this.filterDummyTasks();

for (const projectName of Object.keys(this.dependencies)) {
if (this.dependencies[projectName].length > 1) {
this.dependencies[projectName] = [
...new Set(this.dependencies[projectName]).values(),
for (const taskId of Object.keys(this.dependencies)) {
if (this.dependencies[taskId].length > 0) {
this.dependencies[taskId] = [
...new Set(
this.dependencies[taskId].filter((d) => d !== taskId)
).values(),
];
}
}
Expand Down