Skip to content

Commit 7c80acc

Browse files
leosvelperezFrozenPandaz
authored andcommitted
fix(core): avoid dropping unrelated continuous deps in makeAcyclic (#34389)
## Current Behavior Cycles in the task graph could remove unrelated `continuousDependencies` when the cycle exists only in `dependencies`, leading to missing continuous task edges. ## Expected Behavior Cycle removal only removes the specific cyclic edge from the list where it appears, preserving unrelated continuous dependencies. (cherry picked from commit 6c9f0cb)
1 parent c3a9980 commit 7c80acc

2 files changed

Lines changed: 45 additions & 2 deletions

File tree

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

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,43 @@ describe('task graph utils', () => {
184184
});
185185
expect(graph.roots).toEqual(['d', 'e']);
186186
});
187+
188+
it('should not drop unrelated dependencies when only one dep type has the cycle', () => {
189+
const graph = {
190+
roots: ['d'],
191+
dependencies: {
192+
a: ['b', 'c'],
193+
b: ['d'],
194+
c: ['e'],
195+
d: [],
196+
e: ['a'],
197+
},
198+
continuousDependencies: {
199+
a: ['b'],
200+
b: [],
201+
c: [],
202+
d: [],
203+
e: ['b'],
204+
},
205+
};
206+
207+
makeAcyclic(graph);
208+
209+
expect(graph.dependencies).toEqual({
210+
a: ['b', 'c'],
211+
b: ['d'],
212+
c: ['e'],
213+
d: [],
214+
e: [],
215+
});
216+
expect(graph.continuousDependencies).toEqual({
217+
a: ['b'],
218+
b: [],
219+
c: [],
220+
d: [],
221+
e: ['b'],
222+
});
223+
});
187224
});
188225

189226
describe('validateNoAtomizedTasks', () => {

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,14 @@ function _makeAcyclic(
8686
const continuousDeps = graph.continuousDependencies?.[id] ?? [];
8787
for (const d of [...deps, ...continuousDeps]) {
8888
if (path.includes(d)) {
89-
deps.splice(deps.indexOf(d), 1);
90-
continuousDeps.splice(continuousDeps.indexOf(d), 1);
89+
const depsIdx = deps.indexOf(d);
90+
if (depsIdx >= 0) {
91+
deps.splice(depsIdx, 1);
92+
}
93+
const continuousIdx = continuousDeps.indexOf(d);
94+
if (continuousIdx >= 0) {
95+
continuousDeps.splice(continuousIdx, 1);
96+
}
9197
} else {
9298
_makeAcyclic(graph, d, visited, [...path, d]);
9399
}

0 commit comments

Comments
 (0)