fix(core): create different dummy tasks for different targets (#28837)

<!-- 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 #
This commit is contained in:
Jason Jean 2024-11-08 08:02:19 -05:00 committed by GitHub
parent 6882ad14e4
commit c50269a61a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 127 additions and 1 deletions

View File

@ -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: {

View File

@ -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);