From 61b30162ae32e34d4dd6ad219a7cd877aab21cca Mon Sep 17 00:00:00 2001 From: Nourman Hajar Date: Mon, 23 Dec 2024 15:41:37 +0700 Subject: [PATCH] fix(typecheck): use unique temp and tsbuildinfo file for each tsconfig file (fix #7107) (#7112) --- packages/vitest/src/typecheck/parse.ts | 10 +++++++--- test/typescript/test/__snapshots__/runner.test.ts.snap | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/vitest/src/typecheck/parse.ts b/packages/vitest/src/typecheck/parse.ts index 9b6efcf81622..635358e01001 100644 --- a/packages/vitest/src/typecheck/parse.ts +++ b/packages/vitest/src/typecheck/parse.ts @@ -75,9 +75,13 @@ export async function getTsconfig(root: string, config: TypecheckConfig) { throw new Error('no tsconfig.json found') } + const tsconfigName = basename(tsconfig.path, '.json') + const tempTsConfigName = `${tsconfigName}.vitest-temp.json` + const tempTsbuildinfoName = `${tsconfigName}.tmp.tsbuildinfo` + const tempConfigPath = join( dirname(tsconfig.path), - 'tsconfig.vitest-temp.json', + tempTsConfigName, ) try { @@ -88,7 +92,7 @@ export async function getTsconfig(root: string, config: TypecheckConfig) { tmpTsConfig.compilerOptions.incremental = true tmpTsConfig.compilerOptions.tsBuildInfoFile = join( process.versions.pnp ? join(os.tmpdir(), 'vitest') : __dirname, - 'tsconfig.tmp.tsbuildinfo', + tempTsbuildinfoName, ) const tsconfigFinalContent = JSON.stringify(tmpTsConfig, null, 2) @@ -96,7 +100,7 @@ export async function getTsconfig(root: string, config: TypecheckConfig) { return { path: tempConfigPath, config: tmpTsConfig } } catch (err) { - throw new Error('failed to write tsconfig.temp.json', { cause: err }) + throw new Error(`failed to write ${tempTsConfigName}`, { cause: err }) } } diff --git a/test/typescript/test/__snapshots__/runner.test.ts.snap b/test/typescript/test/__snapshots__/runner.test.ts.snap index 0f45400db132..4175a032a0b8 100644 --- a/test/typescript/test/__snapshots__/runner.test.ts.snap +++ b/test/typescript/test/__snapshots__/runner.test.ts.snap @@ -96,7 +96,7 @@ Vitest caught 1 unhandled error during the test run. This might cause false positive tests. Resolve unhandled errors to make sure your tests are not affected. ⎯⎯⎯⎯⎯⎯ Typecheck Error ⎯⎯⎯⎯⎯⎯⎯ -Error: error TS18003: No inputs were found in config file '/tsconfig.vitest-temp.json'. Specified 'include' paths were '["src"]' and 'exclude' paths were '["**/dist/**"]'. +Error: error TS18003: No inputs were found in config file '/tsconfig.empty.vitest-temp.json'. Specified 'include' paths were '["src"]' and 'exclude' paths were '["**/dist/**"]'. ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯