From c50269a61a46e59bcfe9b4c35c4503040a4429b8 Mon Sep 17 00:00:00 2001 From: Jason Jean Date: Fri, 8 Nov 2024 08:02:19 -0500 Subject: [PATCH] fix(core): create different dummy tasks for different targets (#28837) ## Current Behavior Task dependencies were getting conflated between different targets. If nx runs lint tasks which depend on TaskA and test tasks which depend on TaskB... the task graph was reporting that both lint and test tasks depended on TaskA.. which is incorrect. ## Expected Behavior Task dependencies are not conflated between different targets. If lint tasks depend on TaskA and test tasks depend on TaskB.. then... lint tasks will truly depend on TaskA and test tasks will truly depend on TaskB properly. ## Related Issue(s) Fixes # --- .../tasks-runner/create-task-graph.spec.ts | 126 ++++++++++++++++++ .../nx/src/tasks-runner/create-task-graph.ts | 2 +- 2 files changed, 127 insertions(+), 1 deletion(-) diff --git a/packages/nx/src/tasks-runner/create-task-graph.spec.ts b/packages/nx/src/tasks-runner/create-task-graph.spec.ts index 0f45f49f1c..4fa5768a29 100644 --- a/packages/nx/src/tasks-runner/create-task-graph.spec.ts +++ b/packages/nx/src/tasks-runner/create-task-graph.spec.ts @@ -1966,6 +1966,132 @@ describe('createTaskGraph', () => { }); }); + it('should not conflate dependencies of dummy tasks', () => { + projectGraph = { + nodes: { + app1: { + name: 'app1', + type: 'app', + data: { + root: 'app1-root', + targets: { + test: { + executor: 'nx:run-commands', + dependsOn: ['^dep2'], + }, + lint: { + executor: 'nx:run-commands', + dependsOn: ['^dep'], + }, + }, + }, + }, + lib1: { + name: 'lib1', + type: 'app', + data: { + root: 'lib1-root', + targets: {}, + }, + }, + lib2: { + name: 'lib2', + type: 'app', + data: { + root: 'lib2-root', + targets: { + dep: { + executor: 'nx:run-commands', + }, + dep2: { + executor: 'nx:run-commands', + }, + }, + }, + }, + }, + dependencies: { + app1: [{ source: 'app1', target: 'lib1', type: 'static' }], + lib1: [{ source: 'lib1', target: 'lib2', type: 'static' }], + lib2: [], + }, + }; + + const taskGraph = createTaskGraph( + projectGraph, + {}, + ['app1'], + ['lint', 'test'], + undefined, + { + __overrides_unparsed__: [], + } + ); + expect(taskGraph).toEqual({ + roots: ['lib2:dep', 'lib2:dep2'], + tasks: { + 'app1:lint': { + id: 'app1:lint', + target: { + project: 'app1', + target: 'lint', + }, + outputs: [], + overrides: { + __overrides_unparsed__: [], + }, + projectRoot: 'app1-root', + parallelism: true, + }, + 'app1:test': { + id: 'app1:test', + target: { + project: 'app1', + target: 'test', + }, + outputs: [], + overrides: { + __overrides_unparsed__: [], + }, + projectRoot: 'app1-root', + parallelism: true, + }, + 'lib2:dep': { + id: 'lib2:dep', + target: { + project: 'lib2', + target: 'dep', + }, + outputs: [], + overrides: { + __overrides_unparsed__: [], + }, + projectRoot: 'lib2-root', + parallelism: true, + }, + 'lib2:dep2': { + id: 'lib2:dep2', + target: { + project: 'lib2', + target: 'dep2', + }, + outputs: [], + overrides: { + __overrides_unparsed__: [], + }, + projectRoot: 'lib2-root', + parallelism: true, + }, + }, + dependencies: { + 'app1:lint': ['lib2:dep'], + 'app1:test': ['lib2:dep2'], + 'lib2:dep': [], + 'lib2:dep2': [], + }, + }); + }); + it('should exclude task dependencies', () => { projectGraph = { nodes: { diff --git a/packages/nx/src/tasks-runner/create-task-graph.ts b/packages/nx/src/tasks-runner/create-task-graph.ts index 27e5c72a2b..6ad8fb5880 100644 --- a/packages/nx/src/tasks-runner/create-task-graph.ts +++ b/packages/nx/src/tasks-runner/create-task-graph.ts @@ -289,7 +289,7 @@ export class ProcessTasks { } else { const dummyId = this.getId( depProject.name, - DUMMY_TASK_TARGET, + task.target.target + DUMMY_TASK_TARGET, undefined ); this.dependencies[task.id].push(dummyId);