Skip to content

Commit c50269a

Browse files
authored
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 #
1 parent 6882ad1 commit c50269a

File tree

2 files changed

+127
-1
lines changed

2 files changed

+127
-1
lines changed

packages/nx/src/tasks-runner/create-task-graph.spec.ts

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1966,6 +1966,132 @@ describe('createTaskGraph', () => {
19661966
});
19671967
});
19681968

1969+
it('should not conflate dependencies of dummy tasks', () => {
1970+
projectGraph = {
1971+
nodes: {
1972+
app1: {
1973+
name: 'app1',
1974+
type: 'app',
1975+
data: {
1976+
root: 'app1-root',
1977+
targets: {
1978+
test: {
1979+
executor: 'nx:run-commands',
1980+
dependsOn: ['^dep2'],
1981+
},
1982+
lint: {
1983+
executor: 'nx:run-commands',
1984+
dependsOn: ['^dep'],
1985+
},
1986+
},
1987+
},
1988+
},
1989+
lib1: {
1990+
name: 'lib1',
1991+
type: 'app',
1992+
data: {
1993+
root: 'lib1-root',
1994+
targets: {},
1995+
},
1996+
},
1997+
lib2: {
1998+
name: 'lib2',
1999+
type: 'app',
2000+
data: {
2001+
root: 'lib2-root',
2002+
targets: {
2003+
dep: {
2004+
executor: 'nx:run-commands',
2005+
},
2006+
dep2: {
2007+
executor: 'nx:run-commands',
2008+
},
2009+
},
2010+
},
2011+
},
2012+
},
2013+
dependencies: {
2014+
app1: [{ source: 'app1', target: 'lib1', type: 'static' }],
2015+
lib1: [{ source: 'lib1', target: 'lib2', type: 'static' }],
2016+
lib2: [],
2017+
},
2018+
};
2019+
2020+
const taskGraph = createTaskGraph(
2021+
projectGraph,
2022+
{},
2023+
['app1'],
2024+
['lint', 'test'],
2025+
undefined,
2026+
{
2027+
__overrides_unparsed__: [],
2028+
}
2029+
);
2030+
expect(taskGraph).toEqual({
2031+
roots: ['lib2:dep', 'lib2:dep2'],
2032+
tasks: {
2033+
'app1:lint': {
2034+
id: 'app1:lint',
2035+
target: {
2036+
project: 'app1',
2037+
target: 'lint',
2038+
},
2039+
outputs: [],
2040+
overrides: {
2041+
__overrides_unparsed__: [],
2042+
},
2043+
projectRoot: 'app1-root',
2044+
parallelism: true,
2045+
},
2046+
'app1:test': {
2047+
id: 'app1:test',
2048+
target: {
2049+
project: 'app1',
2050+
target: 'test',
2051+
},
2052+
outputs: [],
2053+
overrides: {
2054+
__overrides_unparsed__: [],
2055+
},
2056+
projectRoot: 'app1-root',
2057+
parallelism: true,
2058+
},
2059+
'lib2:dep': {
2060+
id: 'lib2:dep',
2061+
target: {
2062+
project: 'lib2',
2063+
target: 'dep',
2064+
},
2065+
outputs: [],
2066+
overrides: {
2067+
__overrides_unparsed__: [],
2068+
},
2069+
projectRoot: 'lib2-root',
2070+
parallelism: true,
2071+
},
2072+
'lib2:dep2': {
2073+
id: 'lib2:dep2',
2074+
target: {
2075+
project: 'lib2',
2076+
target: 'dep2',
2077+
},
2078+
outputs: [],
2079+
overrides: {
2080+
__overrides_unparsed__: [],
2081+
},
2082+
projectRoot: 'lib2-root',
2083+
parallelism: true,
2084+
},
2085+
},
2086+
dependencies: {
2087+
'app1:lint': ['lib2:dep'],
2088+
'app1:test': ['lib2:dep2'],
2089+
'lib2:dep': [],
2090+
'lib2:dep2': [],
2091+
},
2092+
});
2093+
});
2094+
19692095
it('should exclude task dependencies', () => {
19702096
projectGraph = {
19712097
nodes: {

packages/nx/src/tasks-runner/create-task-graph.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ export class ProcessTasks {
289289
} else {
290290
const dummyId = this.getId(
291291
depProject.name,
292-
DUMMY_TASK_TARGET,
292+
task.target.target + DUMMY_TASK_TARGET,
293293
undefined
294294
);
295295
this.dependencies[task.id].push(dummyId);

0 commit comments

Comments
 (0)