From 99a0e7c5a086a2613742f6f4eb7fff0fd66d8be1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leosvel=20P=C3=A9rez=20Espinosa?= Date: Mon, 16 Dec 2024 14:53:18 +0100 Subject: [PATCH] fix(misc): ensure `tsBuildInfoFile` is generated inside `outDir` (#29343) ## Current Behavior ## Expected Behavior ## Related Issue(s) Fixes # --- .../generators/application/application.spec.ts | 1 + .../generators/application/application.spec.ts | 1 + .../src/utils/typescript/ts-solution-setup.ts | 18 +++++++++++++++++- .../generators/application/application.spec.ts | 1 + .../generators/application/application.spec.ts | 1 + .../generators/application/application.spec.ts | 1 + .../generators/application/application.spec.ts | 1 + .../generators/application/application.spec.ts | 1 + .../generators/application/application.spec.ts | 2 +- .../src/generators/host/host.rspack.spec.ts | 2 +- .../src/generators/library/library.spec.ts | 1 + .../generators/application/application.spec.ts | 1 + .../vue/src/generators/library/library.spec.ts | 1 + 13 files changed, 29 insertions(+), 3 deletions(-) diff --git a/packages/expo/src/generators/application/application.spec.ts b/packages/expo/src/generators/application/application.spec.ts index 24ce4173ec20e..0ca0bcb614c1e 100644 --- a/packages/expo/src/generators/application/application.spec.ts +++ b/packages/expo/src/generators/application/application.spec.ts @@ -405,6 +405,7 @@ describe('app', () => { "noUnusedLocals": false, "outDir": "out-tsc/my-app", "rootDir": "src", + "tsBuildInfoFile": "out-tsc/my-app/tsconfig.app.tsbuildinfo", "types": [ "node", ], diff --git a/packages/express/src/generators/application/application.spec.ts b/packages/express/src/generators/application/application.spec.ts index 7de92c58e455d..733799d4004d2 100644 --- a/packages/express/src/generators/application/application.spec.ts +++ b/packages/express/src/generators/application/application.spec.ts @@ -260,6 +260,7 @@ describe('app', () => { "moduleResolution": "nodenext", "outDir": "out-tsc/myapp", "rootDir": "src", + "tsBuildInfoFile": "out-tsc/myapp/tsconfig.app.tsbuildinfo", "types": [ "node", "express", diff --git a/packages/js/src/utils/typescript/ts-solution-setup.ts b/packages/js/src/utils/typescript/ts-solution-setup.ts index c726556004337..86a2749b4e0be 100644 --- a/packages/js/src/utils/typescript/ts-solution-setup.ts +++ b/packages/js/src/utils/typescript/ts-solution-setup.ts @@ -10,7 +10,7 @@ import { } from '@nx/devkit'; import { FsTree } from 'nx/src/generators/tree'; import { isUsingPackageManagerWorkspaces } from '../package-manager-workspaces'; -import { relative } from 'node:path/posix'; +import { basename, join, relative } from 'node:path/posix'; export function isUsingTypeScriptPlugin(tree: Tree): boolean { const nxJson = readNxJson(tree); @@ -141,6 +141,22 @@ export function updateTsconfigFiles( ...compilerOptions, }; + if (rootDir && rootDir !== '.') { + // when rootDir is different from '.', the tsbuildinfo file is output + // at `//`, so we need + // to set it explicitly to ensure it's output to the outDir + // https://www.typescriptlang.org/tsconfig/#tsBuildInfoFile + json.compilerOptions.tsBuildInfoFile = join( + 'out-tsc', + projectRoot.split('/').at(-1), + basename(runtimeTsconfigFileName, '.json') + '.tsbuildinfo' + ); + } else if (json.compilerOptions.tsBuildInfoFile) { + // when rootDir is '.' or not set, it would be output to the outDir, so + // we don't need to set it explicitly + delete json.compilerOptions.tsBuildInfoFile; + } + const excludeSet: Set = json.exclude ? new Set(['dist', ...json.exclude, ...exclude]) : new Set(exclude); diff --git a/packages/nest/src/generators/application/application.spec.ts b/packages/nest/src/generators/application/application.spec.ts index de6999353a90c..7ff0c9c045ccb 100644 --- a/packages/nest/src/generators/application/application.spec.ts +++ b/packages/nest/src/generators/application/application.spec.ts @@ -286,6 +286,7 @@ describe('application generator', () => { "outDir": "out-tsc/myapp", "rootDir": "src", "target": "es2021", + "tsBuildInfoFile": "out-tsc/myapp/tsconfig.app.tsbuildinfo", "types": [ "node", ], diff --git a/packages/next/src/generators/application/application.spec.ts b/packages/next/src/generators/application/application.spec.ts index a1977fc601f22..a40cd7a3c6340 100644 --- a/packages/next/src/generators/application/application.spec.ts +++ b/packages/next/src/generators/application/application.spec.ts @@ -949,6 +949,7 @@ describe('app (legacy)', () => { "resolveJsonModule": true, "rootDir": "src", "strict": true, + "tsBuildInfoFile": "out-tsc/myapp/tsconfig.tsbuildinfo", "types": [ "jest", "node", diff --git a/packages/node/src/generators/application/application.spec.ts b/packages/node/src/generators/application/application.spec.ts index 3c64143e1b473..cdb87747de3e0 100644 --- a/packages/node/src/generators/application/application.spec.ts +++ b/packages/node/src/generators/application/application.spec.ts @@ -662,6 +662,7 @@ describe('app', () => { "moduleResolution": "nodenext", "outDir": "out-tsc/myapp", "rootDir": "src", + "tsBuildInfoFile": "out-tsc/myapp/tsconfig.app.tsbuildinfo", "types": [ "node", ], diff --git a/packages/nuxt/src/generators/application/application.spec.ts b/packages/nuxt/src/generators/application/application.spec.ts index d5c222c75a2d1..0821310fc66d1 100644 --- a/packages/nuxt/src/generators/application/application.spec.ts +++ b/packages/nuxt/src/generators/application/application.spec.ts @@ -267,6 +267,7 @@ describe('app', () => { "outDir": "out-tsc/myapp", "resolveJsonModule": true, "rootDir": "src", + "tsBuildInfoFile": "out-tsc/myapp/tsconfig.app.tsbuildinfo", }, "exclude": [ "dist", diff --git a/packages/react-native/src/generators/application/application.spec.ts b/packages/react-native/src/generators/application/application.spec.ts index 51f3fc653e930..de3c282e2e3db 100644 --- a/packages/react-native/src/generators/application/application.spec.ts +++ b/packages/react-native/src/generators/application/application.spec.ts @@ -330,6 +330,7 @@ describe('app', () => { "noUnusedLocals": false, "outDir": "out-tsc/my-app", "rootDir": "src", + "tsBuildInfoFile": "out-tsc/my-app/tsconfig.app.tsbuildinfo", "types": [ "node", ], diff --git a/packages/react/src/generators/application/application.spec.ts b/packages/react/src/generators/application/application.spec.ts index 3da3698851e8e..2c30887ebb644 100644 --- a/packages/react/src/generators/application/application.spec.ts +++ b/packages/react/src/generators/application/application.spec.ts @@ -1331,7 +1331,7 @@ describe('app', () => { "moduleResolution": "bundler", "outDir": "out-tsc/myapp", "rootDir": "src", - "tsBuildInfoFile": "dist/tsconfig.lib.tsbuildinfo", + "tsBuildInfoFile": "out-tsc/myapp/tsconfig.app.tsbuildinfo", "types": [ "node", "@nx/react/typings/cssmodule.d.ts", diff --git a/packages/react/src/generators/host/host.rspack.spec.ts b/packages/react/src/generators/host/host.rspack.spec.ts index 032ab68ce10d6..fa2f2cac27b54 100644 --- a/packages/react/src/generators/host/host.rspack.spec.ts +++ b/packages/react/src/generators/host/host.rspack.spec.ts @@ -508,7 +508,7 @@ describe('hostGenerator', () => { "moduleResolution": "bundler", "outDir": "out-tsc/myapp", "rootDir": "src", - "tsBuildInfoFile": "dist/tsconfig.lib.tsbuildinfo", + "tsBuildInfoFile": "out-tsc/myapp/tsconfig.app.tsbuildinfo", "types": [ "node", "@nx/react/typings/cssmodule.d.ts", diff --git a/packages/react/src/generators/library/library.spec.ts b/packages/react/src/generators/library/library.spec.ts index 13a46b13c809d..d41d9fb337085 100644 --- a/packages/react/src/generators/library/library.spec.ts +++ b/packages/react/src/generators/library/library.spec.ts @@ -1039,6 +1039,7 @@ module.exports = withNx( "moduleResolution": "bundler", "outDir": "out-tsc/mylib", "rootDir": "src", + "tsBuildInfoFile": "out-tsc/mylib/tsconfig.lib.tsbuildinfo", "types": [ "node", "@nx/react/typings/cssmodule.d.ts", diff --git a/packages/vue/src/generators/application/application.spec.ts b/packages/vue/src/generators/application/application.spec.ts index 7aa6caa4ff498..7ba61c6a6ce47 100644 --- a/packages/vue/src/generators/application/application.spec.ts +++ b/packages/vue/src/generators/application/application.spec.ts @@ -206,6 +206,7 @@ describe('application generator', () => { "outDir": "out-tsc/test", "resolveJsonModule": true, "rootDir": "src", + "tsBuildInfoFile": "out-tsc/test/tsconfig.app.tsbuildinfo", "types": [ "vite/client", ], diff --git a/packages/vue/src/generators/library/library.spec.ts b/packages/vue/src/generators/library/library.spec.ts index 79ebba4e39a17..0dd3ac12d0079 100644 --- a/packages/vue/src/generators/library/library.spec.ts +++ b/packages/vue/src/generators/library/library.spec.ts @@ -526,6 +526,7 @@ module.exports = [ "outDir": "out-tsc/my-lib", "resolveJsonModule": true, "rootDir": "src", + "tsBuildInfoFile": "out-tsc/my-lib/tsconfig.lib.tsbuildinfo", "types": [ "vite/client", ],