From f17b45921e38f9b65c3b88bfbca85520c5df84c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=F0=9F=9A=80=20Jack?= Date: Wed, 20 Nov 2024 10:02:02 +1100 Subject: [PATCH] fix(js): only add typescript project references for explicit dependencies in sync generator This change omits references to implicit dependency tsconfigs for typescript projects in the sync generator, since given that they are not referenced directly in code there is no need for project references. Fixes #28997 --- .../typescript-sync/typescript-sync.spec.ts | 25 +++++++++++++++++++ .../typescript-sync/typescript-sync.ts | 9 +++++++ 2 files changed, 34 insertions(+) diff --git a/packages/js/src/generators/typescript-sync/typescript-sync.spec.ts b/packages/js/src/generators/typescript-sync/typescript-sync.spec.ts index 69bb2b140a53f..7cae2c2ca1f44 100644 --- a/packages/js/src/generators/typescript-sync/typescript-sync.spec.ts +++ b/packages/js/src/generators/typescript-sync/typescript-sync.spec.ts @@ -57,6 +57,14 @@ describe('syncGenerator()', () => { }); } + function addProjectWithImplicitDependencies( + name: string, + implicitDependencies: string[] + ) { + addProject(name); + projectGraph.nodes[name].data.implicitDependencies = implicitDependencies; + } + beforeEach(async () => { tree = createTreeWithEmptyWorkspace(); projectGraph = { @@ -612,6 +620,23 @@ describe('syncGenerator()', () => { `); }); + it('should not add a reference if dependent project is an implicit dependency', async () => { + addProject('implicit-dep'); + addProjectWithImplicitDependencies('foo', ['implicit-dep']); + + await syncGenerator(tree); + + expect(tree.read('packages/foo/tsconfig.json').toString('utf-8')) + .toMatchInlineSnapshot(` + "{ + "compilerOptions": { + "composite": true + } + } + " + `); + }); + describe('without custom sync generator options', () => { it.each` runtimeTsConfigFileName diff --git a/packages/js/src/generators/typescript-sync/typescript-sync.ts b/packages/js/src/generators/typescript-sync/typescript-sync.ts index 1b0936ac258d8..c11e28a9d98af 100644 --- a/packages/js/src/generators/typescript-sync/typescript-sync.ts +++ b/packages/js/src/generators/typescript-sync/typescript-sync.ts @@ -465,6 +465,10 @@ function collectProjectDependencies( collectedDependencies.set(projectName, []); + const implicitDependencies = new Set( + projectGraph.nodes[projectName].data.implicitDependencies ?? [] + ); + for (const dep of projectGraph.dependencies[projectName]) { const targetProjectNode = projectGraph.nodes[dep.target]; if (!targetProjectNode) { @@ -472,6 +476,11 @@ function collectProjectDependencies( continue; } + if (implicitDependencies.has(targetProjectNode.name)) { + // It's an implicit dependency and therefore not explicitly referenced in code + continue; + } + // Add the target project node to the list of dependencies for the current project if ( !collectedDependencies