Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): Skip dependencies already added (avoid circular dependencies) #9744

Merged
merged 3 commits into from
May 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 12 additions & 0 deletions packages/nx/src/utils/project-graph-utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,18 @@ describe('project graph utils', () => {
expect(paths).toContain(projGraph.nodes['core'].data.sourceRoot);
});

it('should handle circular dependencies', () => {
projGraph.dependencies['core'] = [
{
type: 'static',
source: 'core',
target: 'demo-app',
},
];
const paths = getSourceDirOfDependentProjects('demo-app', projGraph);
expect(paths).toContain(projGraph.nodes['ui'].data.sourceRoot);
});

it('should throw an error if the project does not exist', () => {
expect(() =>
getSourceDirOfDependentProjects('non-existent-app', projGraph)
Expand Down
5 changes: 5 additions & 0 deletions packages/nx/src/utils/project-graph-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,11 @@ function collectDependentProjectNodesNames(
continue;
}

// skip dependencies already added (avoid circular dependencies)
if (dependencyNodeNames.has(dependencyName)) {
continue;
}

dependencyNodeNames.add(dependencyName);

// Get the dependencies of the dependencies
Expand Down