From 755b4d93ebb31801e9ab13224a1c4b5184298bfe Mon Sep 17 00:00:00 2001 From: Eli <88557639+lishaduck@users.noreply.github.com> Date: Sun, 15 Mar 2026 18:41:51 -0500 Subject: [PATCH] feat: support build mode --- docs/guide/cli-generated.md | 7 +++++ packages/vitest/src/node/cli/cli-config.ts | 3 ++ packages/vitest/src/node/types/config.ts | 4 +++ packages/vitest/src/typecheck/typechecker.ts | 29 ++++++++++++++------ 4 files changed, 35 insertions(+), 8 deletions(-) diff --git a/docs/guide/cli-generated.md b/docs/guide/cli-generated.md index 6b82b3926181..2127c7cc1016 100644 --- a/docs/guide/cli-generated.md +++ b/docs/guide/cli-generated.md @@ -742,6 +742,13 @@ Allow JavaScript files to be typechecked. By default takes the value from tsconf Ignore type errors from source files +### typecheck.build + +- **CLI:** `--typecheck.build` +- **Config:** [typecheck.build](/config/typecheck#typecheck-build) + +Use TypeScript build mode + ### typecheck.tsconfig - **CLI:** `--typecheck.tsconfig ` diff --git a/packages/vitest/src/node/cli/cli-config.ts b/packages/vitest/src/node/cli/cli-config.ts index ddf7641096b2..9dbb3b142d86 100644 --- a/packages/vitest/src/node/cli/cli-config.ts +++ b/packages/vitest/src/node/cli/cli-config.ts @@ -685,6 +685,9 @@ export const cliOptionsConfig: VitestCLIOptions = { ignoreSourceErrors: { description: 'Ignore type errors from source files', }, + build: { + description: 'Use TypeScript build mode', + }, tsconfig: { description: 'Path to a custom tsconfig file', argument: '', diff --git a/packages/vitest/src/node/types/config.ts b/packages/vitest/src/node/types/config.ts index e530e30e3ad3..160f7107d7e2 100644 --- a/packages/vitest/src/node/types/config.ts +++ b/packages/vitest/src/node/types/config.ts @@ -989,6 +989,10 @@ export interface TypecheckConfig { * Do not fail, if Vitest found errors outside the test files. */ ignoreSourceErrors?: boolean + /** + * Use TypeScript build mode. + */ + build?: boolean /** * Path to tsconfig, relative to the project root. */ diff --git a/packages/vitest/src/typecheck/typechecker.ts b/packages/vitest/src/typecheck/typechecker.ts index 55340f10e0a4..2fd216a7779e 100644 --- a/packages/vitest/src/typecheck/typechecker.ts +++ b/packages/vitest/src/typecheck/typechecker.ts @@ -294,16 +294,25 @@ export class Typechecker { const { root, watch, typecheck } = this.project.config const args = [ - '--noEmit', '--pretty', 'false', - '--incremental', - '--tsBuildInfoFile', - join( - process.versions.pnp ? join(os.tmpdir(), this.project.hash) : distDir, - 'tsconfig.tmp.tsbuildinfo', - ), ] + + if (typecheck.build) { + args.push('--build') + } + else { + args.push( + '--noEmit', + '--incremental', + '--tsBuildInfoFile', + join( + process.versions.pnp ? join(os.tmpdir(), this.project.hash) : distDir, + 'tsconfig.tmp.tsbuildinfo', + ), + ) + } + // use builtin watcher because it's faster if (watch) { args.push('--watch') @@ -312,7 +321,11 @@ export class Typechecker { args.push('--allowJs', '--checkJs') } if (typecheck.tsconfig) { - args.push('-p', resolve(root, typecheck.tsconfig)) + if (!typecheck.build) { + args.push('-p') + } + + args.push(resolve(root, typecheck.tsconfig)) } this._output = '' this._startTime = performance.now()