Skip to content

Commit

Permalink
fix(js): use uuid when generating tmp tsconfig (#30118)
Browse files Browse the repository at this point in the history
## Current Behavior
When multiple processes/tasks are running in parallel for a single
project that produce tmp tsconfig files for buildable libraries, they
can clobber each other.

## Expected Behavior
Ensure the config file is generated with a unique id to prevent
clobbering

(cherry picked from commit 46e5dce)
  • Loading branch information
Coly010 authored and FrozenPandaz committed Feb 20, 2025
1 parent 51d4d7a commit 4bf7608
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
3 changes: 2 additions & 1 deletion packages/js/src/utils/buildable-libs-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { output } from 'nx/src/utils/output';
import { dirname, join, relative, extname, resolve } from 'path';
import type * as ts from 'typescript';
import { readTsConfigPaths } from './typescript/ts-config';
import { randomUUID } from 'crypto';

function isBuildable(target: string, node: ProjectGraphProjectNode): boolean {
return (
Expand Down Expand Up @@ -443,7 +444,7 @@ export function createTmpTsConfig(
'tmp',
projectRoot,
process.env.NX_TASK_TARGET_TARGET ?? 'build',
'tsconfig.generated.json'
`tsconfig.generated.${randomUUID()}.json`
);
if (tsconfigPath === tmpTsConfigPath) {
return tsconfigPath;
Expand Down
15 changes: 8 additions & 7 deletions packages/vite/plugins/nx-tsconfig-paths.plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,14 @@ export function nxViteTsPaths(options: nxViteTsPathsOptions = {}) {
projectRoot = config.root;
const projectRootFromWorkspaceRoot = relative(workspaceRoot, projectRoot);
let foundTsConfigPath = getTsConfig(
join(
workspaceRoot,
'tmp',
projectRootFromWorkspaceRoot,
process.env.NX_TASK_TARGET_TARGET ?? 'build',
'tsconfig.generated.json'
)
process.env.NX_TSCONFIG_PATH ??
join(
workspaceRoot,
'tmp',
projectRootFromWorkspaceRoot,
process.env.NX_TASK_TARGET_TARGET ?? 'build',
'tsconfig.generated.json'
)
);
if (!foundTsConfigPath) {
throw new Error(stripIndents`Unable to find a tsconfig in the workspace!
Expand Down

0 comments on commit 4bf7608

Please sign in to comment.