Skip to content

Commit 84617b0

Browse files
cogwirrelleosvelperez
authored andcommitted
fix(js): only add typescript project references for explicit dependencies in sync generator (#28998)
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. ## Current Behavior TypeScript sync generator adds references to any dependency project which has a tsconfig (where composite is true), including implicit dependencies where these references are unnecessary and can potentially cause build failures. See [example repo](https://github.com/cogwirrel/nx-sync-generator-implicit-deps-example). ## Expected Behavior Only explicit dependencies should be referenced in tsconfigs. ## Related Issue(s) Fixes #28997 --------- Co-authored-by: Leosvel Pérez Espinosa <[email protected]> (cherry picked from commit 9e78142)
1 parent 6f9f461 commit 84617b0

File tree

7 files changed

+27
-33
lines changed

7 files changed

+27
-33
lines changed

packages/js/src/generators/typescript-sync/typescript-sync.spec.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,14 @@ describe('syncGenerator()', () => {
5858
});
5959
}
6060

61+
function addProjectWithImplicitDependencies(
62+
name: string,
63+
implicitDependencies: string[]
64+
) {
65+
addProject(name);
66+
projectGraph.nodes[name].data.implicitDependencies = implicitDependencies;
67+
}
68+
6169
beforeEach(async () => {
6270
tree = createTreeWithEmptyWorkspace();
6371
projectGraph = {
@@ -634,6 +642,23 @@ describe('syncGenerator()', () => {
634642
`);
635643
});
636644

645+
it('should not add a reference if dependent project is an implicit dependency', async () => {
646+
addProject('implicit-dep');
647+
addProjectWithImplicitDependencies('foo', ['implicit-dep']);
648+
649+
await syncGenerator(tree);
650+
651+
expect(tree.read('packages/foo/tsconfig.json').toString('utf-8'))
652+
.toMatchInlineSnapshot(`
653+
"{
654+
"compilerOptions": {
655+
"composite": true
656+
}
657+
}
658+
"
659+
`);
660+
});
661+
637662
describe('without custom sync generator options', () => {
638663
it.each`
639664
runtimeTsConfigFileName

packages/js/src/generators/typescript-sync/typescript-sync.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -477,8 +477,8 @@ function collectProjectDependencies(
477477

478478
for (const dep of projectGraph.dependencies[projectName]) {
479479
const targetProjectNode = projectGraph.nodes[dep.target];
480-
if (!targetProjectNode) {
481-
// It's an npm dependency
480+
if (!targetProjectNode || dep.type === 'implicit') {
481+
// It's an npm or an implicit dependency
482482
continue;
483483
}
484484

packages/js/src/utils/typescript/ts-solution-setup.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -183,17 +183,6 @@ export function updateTsconfigFiles(
183183
});
184184
}
185185

186-
if (tree.exists(tsconfigE2E)) {
187-
// tsconfig.json for e2e projects need to have references array
188-
updateJson(tree, tsconfigE2E, (json) => {
189-
json.references ??= [];
190-
const projectPath = relative(e2eRoot, projectRoot);
191-
if (!json.references.some((x) => x.path === projectPath))
192-
json.references.push({ path: projectPath });
193-
return json;
194-
});
195-
}
196-
197186
if (tree.exists('tsconfig.json')) {
198187
updateJson(tree, 'tsconfig.json', (json) => {
199188
const projectPath = './' + projectRoot;

packages/next/src/generators/application/application.spec.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1038,11 +1038,6 @@ describe('app (legacy)', () => {
10381038
"**/*.cy.jsx",
10391039
"**/*.d.ts",
10401040
],
1041-
"references": [
1042-
{
1043-
"path": "../myapp",
1044-
},
1045-
],
10461041
}
10471042
`);
10481043
});

packages/nuxt/src/generators/application/application.spec.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -362,11 +362,6 @@ describe('app', () => {
362362
"src/**/*.test.js",
363363
"src/**/*.d.ts",
364364
],
365-
"references": [
366-
{
367-
"path": "../myapp",
368-
},
369-
],
370365
}
371366
`);
372367
});

packages/react/src/generators/application/application.spec.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1447,11 +1447,6 @@ describe('app', () => {
14471447
"src/**/*.test.js",
14481448
"src/**/*.d.ts",
14491449
],
1450-
"references": [
1451-
{
1452-
"path": "../myapp",
1453-
},
1454-
],
14551450
}
14561451
`);
14571452
});

packages/remix/src/generators/application/application.impl.spec.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -522,11 +522,6 @@ describe('Remix Application', () => {
522522
"src/**/*.test.js",
523523
"src/**/*.d.ts",
524524
],
525-
"references": [
526-
{
527-
"path": "../myapp",
528-
},
529-
],
530525
}
531526
`);
532527
});

0 commit comments

Comments
 (0)