Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(misc): ensure tsBuildInfoFile is generated inside outDir #29343

Merged
merged 1 commit into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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",
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ describe('app', () => {
"moduleResolution": "nodenext",
"outDir": "out-tsc/myapp",
"rootDir": "src",
"tsBuildInfoFile": "out-tsc/myapp/tsconfig.app.tsbuildinfo",
"types": [
"node",
"express",
Expand Down
18 changes: 17 additions & 1 deletion packages/js/src/utils/typescript/ts-solution-setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -141,6 +141,22 @@ export function updateTsconfigFiles(
...compilerOptions,
};

if (rootDir && rootDir !== '.') {
// when rootDir is different from '.', the tsbuildinfo file is output
// at `<outDir>/<relative path to config from rootDir>/`, 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<string> = json.exclude
? new Set(['dist', ...json.exclude, ...exclude])
: new Set(exclude);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ describe('application generator', () => {
"outDir": "out-tsc/myapp",
"rootDir": "src",
"target": "es2021",
"tsBuildInfoFile": "out-tsc/myapp/tsconfig.app.tsbuildinfo",
"types": [
"node",
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -949,6 +949,7 @@ describe('app (legacy)', () => {
"resolveJsonModule": true,
"rootDir": "src",
"strict": true,
"tsBuildInfoFile": "out-tsc/myapp/tsconfig.tsbuildinfo",
"types": [
"jest",
"node",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,7 @@ describe('app', () => {
"moduleResolution": "nodenext",
"outDir": "out-tsc/myapp",
"rootDir": "src",
"tsBuildInfoFile": "out-tsc/myapp/tsconfig.app.tsbuildinfo",
"types": [
"node",
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ describe('app', () => {
"outDir": "out-tsc/myapp",
"resolveJsonModule": true,
"rootDir": "src",
"tsBuildInfoFile": "out-tsc/myapp/tsconfig.app.tsbuildinfo",
},
"exclude": [
"dist",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/generators/host/host.rspack.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions packages/react/src/generators/library/library.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
],
Expand Down
1 change: 1 addition & 0 deletions packages/vue/src/generators/library/library.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
],
Expand Down
Loading