1
+ import path from 'path'
1
2
import {
2
3
DiagnosticCategory ,
3
4
getFormattedDiagnostic ,
@@ -18,7 +19,8 @@ export interface TypeCheckResult {
18
19
export async function runTypeCheck (
19
20
ts : typeof import ( 'typescript' ) ,
20
21
baseDir : string ,
21
- tsConfigPath : string
22
+ tsConfigPath : string ,
23
+ cacheDir ?: string
22
24
) : Promise < TypeCheckResult > {
23
25
const effectiveConfiguration = await getTypeScriptConfiguration (
24
26
ts ,
@@ -35,11 +37,28 @@ export async function runTypeCheck(
35
37
}
36
38
const requiredConfig = getRequiredConfiguration ( ts )
37
39
38
- const program = ts . createProgram ( effectiveConfiguration . fileNames , {
40
+ const options = {
39
41
...effectiveConfiguration . options ,
40
42
...requiredConfig ,
41
43
noEmit : true ,
42
- } )
44
+ }
45
+
46
+ let program : import ( 'typescript' ) . Program
47
+ let incremental = false
48
+ if ( options . incremental && cacheDir ) {
49
+ incremental = true
50
+ const builderProgram = ts . createIncrementalProgram ( {
51
+ rootNames : effectiveConfiguration . fileNames ,
52
+ options : {
53
+ ...options ,
54
+ incremental : true ,
55
+ tsBuildInfoFile : path . join ( cacheDir , '.tsbuildinfo' ) ,
56
+ } ,
57
+ } )
58
+ program = builderProgram . getProgram ( )
59
+ } else {
60
+ program = ts . createProgram ( effectiveConfiguration . fileNames , options )
61
+ }
43
62
const result = program . emit ( )
44
63
45
64
// Intended to match:
@@ -79,6 +98,6 @@ export async function runTypeCheck(
79
98
warnings,
80
99
inputFilesCount : effectiveConfiguration . fileNames . length ,
81
100
totalFilesCount : program . getSourceFiles ( ) . length ,
82
- incremental : false ,
101
+ incremental,
83
102
}
84
103
}
0 commit comments