@@ -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 {
@@ -33,6 +69,7 @@ export class IncrementalChecker {
33
69
linterConfig : ConfigurationFile ;
34
70
linterExclusions : minimatch . IMinimatch [ ] ;
35
71
72
+ typescript : TypeScriptInstance ;
36
73
program : ts . Program ;
37
74
programConfig : ts . ParsedCommandLine ;
38
75
watcher : FilesWatcher ;
@@ -48,6 +85,7 @@ export class IncrementalChecker {
48
85
checkSyntacticErrors : boolean ,
49
86
vue : boolean
50
87
) {
88
+ // TODO: set `typescript`
51
89
this . programConfigFile = programConfigFile ;
52
90
this . linterConfigFile = linterConfigFile ;
53
91
this . watchPaths = watchPaths ;
@@ -68,13 +106,16 @@ export class IncrementalChecker {
68
106
} ) ) ;
69
107
}
70
108
71
- static loadProgramConfig ( configFile : string ) {
72
- return ts . parseJsonConfigFileContent (
109
+ static loadProgramConfig ( typescript : TypeScriptInstance , configFile : string ) {
110
+ return typescript . parseJsonConfigFileContent (
73
111
// Regardless of the setting in the tsconfig.json we want isolatedModules to be false
74
- Object . assign ( ts . readConfigFile ( configFile , ts . sys . readFile ) . config , {
75
- isolatedModules : false
76
- } ) ,
77
- ts . sys ,
112
+ Object . assign (
113
+ typescript . readConfigFile ( configFile , typescript . sys . readFile ) . config ,
114
+ {
115
+ isolatedModules : false
116
+ }
117
+ ) ,
118
+ typescript . sys ,
78
119
path . dirname ( configFile )
79
120
) ;
80
121
}
@@ -88,12 +129,13 @@ export class IncrementalChecker {
88
129
}
89
130
90
131
static createProgram (
132
+ typescript : TypeScriptInstance ,
91
133
programConfig : ts . ParsedCommandLine ,
92
134
files : FilesRegister ,
93
135
watcher : FilesWatcher ,
94
136
oldProgram : ts . Program
95
137
) {
96
- const host = ts . createCompilerHost ( programConfig . options ) ;
138
+ const host = typescript . createCompilerHost ( programConfig . options ) ;
97
139
const realGetSourceFile = host . getSourceFile ;
98
140
99
141
host . getSourceFile = ( filePath , languageVersion , onError ) => {
@@ -119,7 +161,7 @@ export class IncrementalChecker {
119
161
return files . getData ( filePath ) . source ;
120
162
} ;
121
163
122
- return ts . createProgram (
164
+ return typescript . createProgram (
123
165
programConfig . fileNames ,
124
166
programConfig . options ,
125
167
host ,
@@ -203,9 +245,13 @@ export class IncrementalChecker {
203
245
loadDefaultProgram ( ) {
204
246
this . programConfig =
205
247
this . programConfig ||
206
- IncrementalChecker . loadProgramConfig ( this . programConfigFile ) ;
248
+ IncrementalChecker . loadProgramConfig (
249
+ this . typescript ,
250
+ this . programConfigFile
251
+ ) ;
207
252
208
253
return IncrementalChecker . createProgram (
254
+ this . typescript ,
209
255
this . programConfig ,
210
256
this . files ,
211
257
this . watcher ,
@@ -256,7 +302,7 @@ export class IncrementalChecker {
256
302
return NormalizedMessage . deduplicate (
257
303
diagnostics . map ( d =>
258
304
NormalizedMessage . createFromDiagnostic (
259
- ts . flattenDiagnosticMessageText ,
305
+ this . typescript . flattenDiagnosticMessageText ,
260
306
d
261
307
)
262
308
)
0 commit comments