Skip to content

Commit

Permalink
fix(core): filter out task dependencies on itself
Browse files Browse the repository at this point in the history
  • Loading branch information
FrozenPandaz committed Oct 2, 2024
1 parent 81892b5 commit 9f0b6cd
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 4 deletions.
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

0 comments on commit 9f0b6cd

Please sign in to comment.