Skip to content

Commit

Permalink
fix(js): only add typescript project references for explicit dependen…
Browse files Browse the repository at this point in the history
…cies 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 nrwl#28997
  • Loading branch information
cogwirrel committed Nov 19, 2024
1 parent 636cd77 commit f17b459
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
25 changes: 25 additions & 0 deletions packages/js/src/generators/typescript-sync/typescript-sync.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions packages/js/src/generators/typescript-sync/typescript-sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -465,13 +465,22 @@ 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) {
// It's an npm dependency
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
Expand Down

0 comments on commit f17b459

Please sign in to comment.