Skip to content

Commit

Permalink
fix(core): create different dummy tasks for different targets (#28837)
Browse files Browse the repository at this point in the history
<!-- Please make sure you have read the submission guidelines before
posting an PR -->
<!--
https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr
-->

<!-- Please make sure that your commit message follows our format -->
<!-- Example: `fix(nx): must begin with lowercase` -->

<!-- If this is a particularly complex change or feature addition, you
can request a dedicated Nx release for this pull request branch. Mention
someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they
will confirm if the PR warrants its own release for testing purposes,
and generate it for you if appropriate. -->

## Current Behavior
<!-- This is the behavior we have today -->

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
<!-- This is the behavior we should expect with the changes in this PR
-->

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)
<!-- Please link the issue being fixed so it gets closed when this is
merged. -->

Fixes #

(cherry picked from commit c50269a)
  • Loading branch information
FrozenPandaz committed Nov 8, 2024
1 parent 4ea3d21 commit a36b512
Show file tree
Hide file tree
Showing 2 changed files with 127 additions and 1 deletion.
126 changes: 126 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 @@ -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: {
Expand Down
2 changes: 1 addition & 1 deletion packages/nx/src/tasks-runner/create-task-graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit a36b512

Please sign in to comment.