@@ -11,6 +11,42 @@ import { CancellationToken } from './CancellationToken';
11
11
import * as minimatch from 'minimatch' ;
12
12
import { VueProgram } from './VueProgram' ;
13
13
14
+ interface TypeScriptInstance {
15
+ parseJsonConfigFileContent (
16
+ json : any ,
17
+ host : ts . ParseConfigHost ,
18
+ basePath : string ,
19
+ existingOptions ?: ts . CompilerOptions ,
20
+ configFileName ?: string ,
21
+ resolutionStack ?: ts . Path [ ] ,
22
+ extraFileExtensions ?: ReadonlyArray < ts . FileExtensionInfo >
23
+ ) : ts . ParsedCommandLine ;
24
+ readConfigFile (
25
+ fileName : string ,
26
+ readFile : ( path : string ) => string | undefined
27
+ ) : {
28
+ config ?: any ;
29
+ error ?: ts . Diagnostic ;
30
+ } ;
31
+ createCompilerHost (
32
+ options : ts . CompilerOptions ,
33
+ setParentNodes ?: boolean
34
+ ) : ts . CompilerHost ;
35
+ createProgram (
36
+ rootNames : ReadonlyArray < string > ,
37
+ options : ts . CompilerOptions ,
38
+ host ?: ts . CompilerHost ,
39
+ oldProgram ?: ts . Program ,
40
+ configFileParsingDiagnostics ?: ReadonlyArray < ts . Diagnostic >
41
+ ) : ts . Program ;
42
+ flattenDiagnosticMessageText (
43
+ messageText : string | ts . DiagnosticMessageChain | undefined ,
44
+ newLine : string
45
+ ) : string ;
46
+
47
+ sys : ts . System ;
48
+ }
49
+
14
50
// Need some augmentation here - linterOptions.exclude is not (yet) part of the official
15
51
// types for tslint.
16
52
interface ConfigurationFile extends Configuration . IConfigurationFile {
@@ -34,6 +70,7 @@ export class IncrementalChecker {
34
70
linterConfig : ConfigurationFile ;
35
71
linterExclusions : minimatch . IMinimatch [ ] ;
36
72
73
+ typescript : TypeScriptInstance ;
37
74
program : ts . Program ;
38
75
programConfig : ts . ParsedCommandLine ;
39
76
watcher : FilesWatcher ;
@@ -50,6 +87,7 @@ export class IncrementalChecker {
50
87
checkSyntacticErrors : boolean ,
51
88
vue : boolean
52
89
) {
90
+ // TODO: set `typescript`
53
91
this . programConfigFile = programConfigFile ;
54
92
this . compilerOptions = compilerOptions ;
55
93
this . linterConfigFile = linterConfigFile ;
@@ -71,18 +109,25 @@ export class IncrementalChecker {
71
109
} ) ) ;
72
110
}
73
111
74
- static loadProgramConfig ( configFile : string , compilerOptions : object ) {
75
- const tsconfig = ts . readConfigFile ( configFile , ts . sys . readFile ) . config ;
112
+ static loadProgramConfig (
113
+ typescript : TypeScriptInstance ,
114
+ configFile : string ,
115
+ compilerOptions : object
116
+ ) {
117
+ const tsconfig = typescript . readConfigFile (
118
+ configFile ,
119
+ typescript . sys . readFile
120
+ ) . config ;
76
121
77
122
tsconfig . compilerOptions = tsconfig . compilerOptions || { } ;
78
123
tsconfig . compilerOptions = {
79
124
...tsconfig . compilerOptions ,
80
125
...compilerOptions
81
126
} ;
82
127
83
- const parsed = ts . parseJsonConfigFileContent (
128
+ const parsed = typescript . parseJsonConfigFileContent (
84
129
tsconfig ,
85
- ts . sys ,
130
+ typescript . sys ,
86
131
path . dirname ( configFile )
87
132
) ;
88
133
@@ -98,12 +143,13 @@ export class IncrementalChecker {
98
143
}
99
144
100
145
static createProgram (
146
+ typescript : TypeScriptInstance ,
101
147
programConfig : ts . ParsedCommandLine ,
102
148
files : FilesRegister ,
103
149
watcher : FilesWatcher ,
104
150
oldProgram : ts . Program
105
151
) {
106
- const host = ts . createCompilerHost ( programConfig . options ) ;
152
+ const host = typescript . createCompilerHost ( programConfig . options ) ;
107
153
const realGetSourceFile = host . getSourceFile ;
108
154
109
155
host . getSourceFile = ( filePath , languageVersion , onError ) => {
@@ -129,7 +175,7 @@ export class IncrementalChecker {
129
175
return files . getData ( filePath ) . source ;
130
176
} ;
131
177
132
- return ts . createProgram (
178
+ return typescript . createProgram (
133
179
programConfig . fileNames ,
134
180
programConfig . options ,
135
181
host ,
@@ -217,11 +263,13 @@ export class IncrementalChecker {
217
263
this . programConfig =
218
264
this . programConfig ||
219
265
IncrementalChecker . loadProgramConfig (
266
+ this . typescript ,
220
267
this . programConfigFile ,
221
268
this . compilerOptions
222
269
) ;
223
270
224
271
return IncrementalChecker . createProgram (
272
+ this . typescript ,
225
273
this . programConfig ,
226
274
this . files ,
227
275
this . watcher ,
@@ -272,7 +320,7 @@ export class IncrementalChecker {
272
320
return NormalizedMessage . deduplicate (
273
321
diagnostics . map ( d =>
274
322
NormalizedMessage . createFromDiagnostic (
275
- ts . flattenDiagnosticMessageText ,
323
+ this . typescript . flattenDiagnosticMessageText ,
276
324
d
277
325
)
278
326
)
0 commit comments