Skip to content

Commit 106da58

Browse files
authored
feat: support typescript build mode (#9870)
1 parent f79e7db commit 106da58

15 files changed

Lines changed: 137 additions & 8 deletions

File tree

‎docs/guide/cli-generated.md‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -791,6 +791,13 @@ Allow JavaScript files to be typechecked. By default takes the value from tsconf
791791

792792
Ignore type errors from source files
793793

794+
### typecheck.build
795+
796+
- **CLI:** `--typecheck.build`
797+
- **Config:** [typecheck.build](/config/typecheck#typecheck-build)
798+
799+
Use TypeScript build mode
800+
794801
### typecheck.tsconfig
795802

796803
- **CLI:** `--typecheck.tsconfig <path>`

‎packages/vitest/src/node/cli/cli-config.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -726,6 +726,9 @@ export const cliOptionsConfig: VitestCLIOptions = {
726726
ignoreSourceErrors: {
727727
description: 'Ignore type errors from source files',
728728
},
729+
build: {
730+
description: 'Use TypeScript build mode',
731+
},
729732
tsconfig: {
730733
description: 'Path to a custom tsconfig file',
731734
argument: '<path>',

‎packages/vitest/src/node/types/config.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,6 +1014,10 @@ export interface TypecheckConfig {
10141014
* Do not fail, if Vitest found errors outside the test files.
10151015
*/
10161016
ignoreSourceErrors?: boolean
1017+
/**
1018+
* Use TypeScript build mode.
1019+
*/
1020+
build?: boolean
10171021
/**
10181022
* Path to tsconfig, relative to the project root.
10191023
*/

‎packages/vitest/src/typecheck/typechecker.ts‎

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -294,16 +294,25 @@ export class Typechecker {
294294
const { root, watch, typecheck } = this.project.config
295295

296296
const args = [
297-
'--noEmit',
298297
'--pretty',
299298
'false',
300-
'--incremental',
301-
'--tsBuildInfoFile',
302-
join(
303-
process.versions.pnp ? join(os.tmpdir(), this.project.hash) : distDir,
304-
'tsconfig.tmp.tsbuildinfo',
305-
),
306299
]
300+
301+
if (typecheck.build) {
302+
args.unshift('--build')
303+
}
304+
else {
305+
args.push(
306+
'--noEmit',
307+
'--incremental',
308+
'--tsBuildInfoFile',
309+
join(
310+
process.versions.pnp ? join(os.tmpdir(), this.project.hash) : distDir,
311+
'tsconfig.tmp.tsbuildinfo',
312+
),
313+
)
314+
}
315+
307316
// use builtin watcher because it's faster
308317
if (watch) {
309318
args.push('--watch')
@@ -312,7 +321,11 @@ export class Typechecker {
312321
args.push('--allowJs', '--checkJs')
313322
}
314323
if (typecheck.tsconfig) {
315-
args.push('-p', resolve(root, typecheck.tsconfig))
324+
if (!typecheck.build) {
325+
args.push('-p')
326+
}
327+
328+
args.push(resolve(root, typecheck.tsconfig))
316329
}
317330
this._output = ''
318331
this._startTime = performance.now()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
!/packages/project-b/node_modules
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"name": "@vitest/test-integration-project-references",
3+
"type": "module",
4+
"private": true,
5+
"scripts": {
6+
"test": "(rm -rf packages/*/dist || true) && vitest run"
7+
},
8+
"devDependencies": {
9+
"vitest": "workspace:*"
10+
},
11+
"workspaces": [
12+
"packages/*"
13+
]
14+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"name": "project-a",
3+
"type": "module",
4+
"private": true,
5+
"exports": "./src/index.ts"
6+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export type A = number
2+
export const a: A = 1
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"compilerOptions": {
3+
"composite": true,
4+
"target": "esnext",
5+
"lib": ["DOM", "ESNext"],
6+
"module": "nodenext",
7+
"types": [],
8+
"strict": true,
9+
"declaration": true,
10+
"declarationMap": true,
11+
"outDir": "dist",
12+
"sourceMap": true,
13+
"verbatimModuleSyntax": true,
14+
"skipLibCheck": false
15+
},
16+
"files": ["src/index.ts"]
17+
}

‎test/e2e/project-references/packages/project-b/node_modules/project-a‎

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)