Skip to content

Commit ac9c7e9

Browse files
authored
fix(core): issue with registering file dependencies (#15523)
1 parent 0383fa6 commit ac9c7e9

File tree

2 files changed

+46
-6
lines changed

2 files changed

+46
-6
lines changed

packages/nx/src/project-graph/project-graph-builder.spec.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,43 @@ describe('ProjectGraphBuilder', () => {
148148
});
149149
});
150150

151+
it(`should record deps for all files when duplicated`, () => {
152+
builder.addStaticDependency('source', 'target', 'source/index.ts');
153+
builder.addStaticDependency('source', 'target', 'source/second.ts');
154+
155+
const graph = builder.getUpdatedProjectGraph();
156+
expect(graph.dependencies).toEqual({
157+
source: [
158+
{
159+
source: 'source',
160+
target: 'target',
161+
type: 'static',
162+
},
163+
],
164+
target: [],
165+
});
166+
expect(graph.nodes.source.data.files[0]).toMatchObject({
167+
file: 'source/index.ts',
168+
dependencies: [
169+
{
170+
source: 'source',
171+
target: 'target',
172+
type: 'static',
173+
},
174+
],
175+
});
176+
expect(graph.nodes.source.data.files[1]).toMatchObject({
177+
file: 'source/second.ts',
178+
dependencies: [
179+
{
180+
source: 'source',
181+
target: 'target',
182+
type: 'static',
183+
},
184+
],
185+
});
186+
});
187+
151188
it(`remove dependency`, () => {
152189
builder.addNode({
153190
name: 'target2',

packages/nx/src/project-graph/project-graph-builder.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -278,12 +278,11 @@ export class ProjectGraphBuilder {
278278
if (!this.graph.dependencies[sourceProjectName]) {
279279
this.graph.dependencies[sourceProjectName] = [];
280280
}
281-
// do not add duplicate
282-
if (
283-
this.graph.dependencies[sourceProjectName].find(
284-
(d) => d.target === targetProjectName && d.type === type
285-
)
286-
) {
281+
const isDuplicate = !!this.graph.dependencies[sourceProjectName].find(
282+
(d) => d.target === targetProjectName && d.type === type
283+
);
284+
// do not add duplicate to project
285+
if (isDuplicate && !sourceProjectFile) {
287286
return;
288287
}
289288

@@ -317,6 +316,10 @@ export class ProjectGraphBuilder {
317316
}
318317
}
319318

319+
if (isDuplicate) {
320+
return;
321+
}
322+
320323
this.graph.dependencies[sourceProjectName].push(dependency);
321324
}
322325

0 commit comments

Comments
 (0)