fix(core): skip dependencies already added (avoid circular dependencies) (#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>
This commit is contained in:
Daniel Harvey 2022-05-05 06:16:17 +08:00 committed by GitHub
parent 4a91966cb4
commit 8e4a38e764
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 0 deletions

View File

@ -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)

View File

@ -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