Skip to content

Commit

Permalink
fix(core): skip dependencies already added (avoid circular dependenci…
Browse files Browse the repository at this point in the history
…es) (#9744)

* fix(core): Skip dependencies already added (avoid circular)

The project utility method `collectDependentProjectNodesNames()`
produces a stack overflow (e.g. producing project dependencies for
`tailwind.config.js` when circular dependencies exist.

Fix by adding loop detection for "already add" dependencies.

* cleanup(core): Correct formating

* chore(core): add test for circular dependencies in getSourceDirOfDependentProjects

Co-authored-by: Jason Jean <jasonjean1993@gmail.com>
  • Loading branch information
danielsharvey and FrozenPandaz committed May 4, 2022
1 parent 4a91966 commit 8e4a38e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
12 changes: 12 additions & 0 deletions packages/nx/src/utils/project-graph-utils.spec.ts
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
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

1 comment on commit 8e4a38e

@vercel
Copy link

@vercel vercel bot commented on 8e4a38e May 4, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

nx-dev – ./

nx-dev-nrwl.vercel.app
nx-five.vercel.app
nx-dev-git-master-nrwl.vercel.app
nx.dev

Please sign in to comment.