Skip to content

Commit 99a0e7c

Browse files
authored
fix(misc): ensure tsBuildInfoFile is generated inside outDir (#29343)
<!-- Please make sure you have read the submission guidelines before posting an PR --> <!-- https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr --> <!-- Please make sure that your commit message follows our format --> <!-- Example: `fix(nx): must begin with lowercase` --> <!-- If this is a particularly complex change or feature addition, you can request a dedicated Nx release for this pull request branch. Mention someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they will confirm if the PR warrants its own release for testing purposes, and generate it for you if appropriate. --> ## Current Behavior <!-- This is the behavior we have today --> ## Expected Behavior <!-- This is the behavior we should expect with the changes in this PR --> ## Related Issue(s) <!-- Please link the issue being fixed so it gets closed when this is merged. --> Fixes #
1 parent 13ec93c commit 99a0e7c

File tree

13 files changed

+29
-3
lines changed

13 files changed

+29
-3
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,7 @@ describe('app', () => {
405405
"noUnusedLocals": false,
406406
"outDir": "out-tsc/my-app",
407407
"rootDir": "src",
408+
"tsBuildInfoFile": "out-tsc/my-app/tsconfig.app.tsbuildinfo",
408409
"types": [
409410
"node",
410411
],

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ describe('app', () => {
260260
"moduleResolution": "nodenext",
261261
"outDir": "out-tsc/myapp",
262262
"rootDir": "src",
263+
"tsBuildInfoFile": "out-tsc/myapp/tsconfig.app.tsbuildinfo",
263264
"types": [
264265
"node",
265266
"express",

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
} from '@nx/devkit';
1111
import { FsTree } from 'nx/src/generators/tree';
1212
import { isUsingPackageManagerWorkspaces } from '../package-manager-workspaces';
13-
import { relative } from 'node:path/posix';
13+
import { basename, join, relative } from 'node:path/posix';
1414

1515
export function isUsingTypeScriptPlugin(tree: Tree): boolean {
1616
const nxJson = readNxJson(tree);
@@ -141,6 +141,22 @@ export function updateTsconfigFiles(
141141
...compilerOptions,
142142
};
143143

144+
if (rootDir && rootDir !== '.') {
145+
// when rootDir is different from '.', the tsbuildinfo file is output
146+
// at `<outDir>/<relative path to config from rootDir>/`, so we need
147+
// to set it explicitly to ensure it's output to the outDir
148+
// https://www.typescriptlang.org/tsconfig/#tsBuildInfoFile
149+
json.compilerOptions.tsBuildInfoFile = join(
150+
'out-tsc',
151+
projectRoot.split('/').at(-1),
152+
basename(runtimeTsconfigFileName, '.json') + '.tsbuildinfo'
153+
);
154+
} else if (json.compilerOptions.tsBuildInfoFile) {
155+
// when rootDir is '.' or not set, it would be output to the outDir, so
156+
// we don't need to set it explicitly
157+
delete json.compilerOptions.tsBuildInfoFile;
158+
}
159+
144160
const excludeSet: Set<string> = json.exclude
145161
? new Set(['dist', ...json.exclude, ...exclude])
146162
: new Set(exclude);

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,7 @@ describe('application generator', () => {
286286
"outDir": "out-tsc/myapp",
287287
"rootDir": "src",
288288
"target": "es2021",
289+
"tsBuildInfoFile": "out-tsc/myapp/tsconfig.app.tsbuildinfo",
289290
"types": [
290291
"node",
291292
],

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -949,6 +949,7 @@ describe('app (legacy)', () => {
949949
"resolveJsonModule": true,
950950
"rootDir": "src",
951951
"strict": true,
952+
"tsBuildInfoFile": "out-tsc/myapp/tsconfig.tsbuildinfo",
952953
"types": [
953954
"jest",
954955
"node",

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,7 @@ describe('app', () => {
662662
"moduleResolution": "nodenext",
663663
"outDir": "out-tsc/myapp",
664664
"rootDir": "src",
665+
"tsBuildInfoFile": "out-tsc/myapp/tsconfig.app.tsbuildinfo",
665666
"types": [
666667
"node",
667668
],

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@ describe('app', () => {
267267
"outDir": "out-tsc/myapp",
268268
"resolveJsonModule": true,
269269
"rootDir": "src",
270+
"tsBuildInfoFile": "out-tsc/myapp/tsconfig.app.tsbuildinfo",
270271
},
271272
"exclude": [
272273
"dist",

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,7 @@ describe('app', () => {
330330
"noUnusedLocals": false,
331331
"outDir": "out-tsc/my-app",
332332
"rootDir": "src",
333+
"tsBuildInfoFile": "out-tsc/my-app/tsconfig.app.tsbuildinfo",
333334
"types": [
334335
"node",
335336
],

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1331,7 +1331,7 @@ describe('app', () => {
13311331
"moduleResolution": "bundler",
13321332
"outDir": "out-tsc/myapp",
13331333
"rootDir": "src",
1334-
"tsBuildInfoFile": "dist/tsconfig.lib.tsbuildinfo",
1334+
"tsBuildInfoFile": "out-tsc/myapp/tsconfig.app.tsbuildinfo",
13351335
"types": [
13361336
"node",
13371337
"@nx/react/typings/cssmodule.d.ts",

packages/react/src/generators/host/host.rspack.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ describe('hostGenerator', () => {
508508
"moduleResolution": "bundler",
509509
"outDir": "out-tsc/myapp",
510510
"rootDir": "src",
511-
"tsBuildInfoFile": "dist/tsconfig.lib.tsbuildinfo",
511+
"tsBuildInfoFile": "out-tsc/myapp/tsconfig.app.tsbuildinfo",
512512
"types": [
513513
"node",
514514
"@nx/react/typings/cssmodule.d.ts",

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,6 +1039,7 @@ module.exports = withNx(
10391039
"moduleResolution": "bundler",
10401040
"outDir": "out-tsc/mylib",
10411041
"rootDir": "src",
1042+
"tsBuildInfoFile": "out-tsc/mylib/tsconfig.lib.tsbuildinfo",
10421043
"types": [
10431044
"node",
10441045
"@nx/react/typings/cssmodule.d.ts",

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ describe('application generator', () => {
206206
"outDir": "out-tsc/test",
207207
"resolveJsonModule": true,
208208
"rootDir": "src",
209+
"tsBuildInfoFile": "out-tsc/test/tsconfig.app.tsbuildinfo",
209210
"types": [
210211
"vite/client",
211212
],

packages/vue/src/generators/library/library.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,7 @@ module.exports = [
526526
"outDir": "out-tsc/my-lib",
527527
"resolveJsonModule": true,
528528
"rootDir": "src",
529+
"tsBuildInfoFile": "out-tsc/my-lib/tsconfig.lib.tsbuildinfo",
529530
"types": [
530531
"vite/client",
531532
],

0 commit comments

Comments
 (0)