Skip to content

Commit

Permalink
fix(misc): ensure tsBuildInfoFile is generated inside outDir (#29343
Browse files Browse the repository at this point in the history
)

<!-- 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 #
  • Loading branch information
leosvelperez authored Dec 16, 2024
1 parent 13ec93c commit 99a0e7c
Show file tree
Hide file tree
Showing 13 changed files with 29 additions and 3 deletions.
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

0 comments on commit 99a0e7c

Please sign in to comment.