Skip to content

Commit

Permalink
fix(core): issue with registering file dependencies (#15523)
Browse files Browse the repository at this point in the history
(cherry picked from commit ac9c7e9)
  • Loading branch information
forivall authored and FrozenPandaz committed Mar 8, 2023
1 parent ebb130d commit 14121a0
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 6 deletions.
37 changes: 37 additions & 0 deletions packages/nx/src/project-graph/project-graph-builder.spec.ts
Expand Up @@ -148,6 +148,43 @@ describe('ProjectGraphBuilder', () => {
});
});

it(`should record deps for all files when duplicated`, () => {
builder.addStaticDependency('source', 'target', 'source/index.ts');
builder.addStaticDependency('source', 'target', 'source/second.ts');

const graph = builder.getUpdatedProjectGraph();
expect(graph.dependencies).toEqual({
source: [
{
source: 'source',
target: 'target',
type: 'static',
},
],
target: [],
});
expect(graph.nodes.source.data.files[0]).toMatchObject({
file: 'source/index.ts',
dependencies: [
{
source: 'source',
target: 'target',
type: 'static',
},
],
});
expect(graph.nodes.source.data.files[1]).toMatchObject({
file: 'source/second.ts',
dependencies: [
{
source: 'source',
target: 'target',
type: 'static',
},
],
});
});

it(`remove dependency`, () => {
builder.addNode({
name: 'target2',
Expand Down
15 changes: 9 additions & 6 deletions packages/nx/src/project-graph/project-graph-builder.ts
Expand Up @@ -278,12 +278,11 @@ export class ProjectGraphBuilder {
if (!this.graph.dependencies[sourceProjectName]) {
this.graph.dependencies[sourceProjectName] = [];
}
// do not add duplicate
if (
this.graph.dependencies[sourceProjectName].find(
(d) => d.target === targetProjectName && d.type === type
)
) {
const isDuplicate = !!this.graph.dependencies[sourceProjectName].find(
(d) => d.target === targetProjectName && d.type === type
);
// do not add duplicate to project
if (isDuplicate && !sourceProjectFile) {
return;
}

Expand Down Expand Up @@ -317,6 +316,10 @@ export class ProjectGraphBuilder {
}
}

if (isDuplicate) {
return;
}

this.graph.dependencies[sourceProjectName].push(dependency);
}

Expand Down

0 comments on commit 14121a0

Please sign in to comment.