Skip to content

Commit 6e06644

Browse files
committed
Remove typscript usage from IncrementalChecker
1 parent 84026c8 commit 6e06644

File tree

1 file changed

+56
-10
lines changed

1 file changed

+56
-10
lines changed

src/IncrementalChecker.ts

Lines changed: 56 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,42 @@ import { CancellationToken } from './CancellationToken';
1111
import * as minimatch from 'minimatch';
1212
import { VueProgram } from './VueProgram';
1313

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+
1450
// Need some augmentation here - linterOptions.exclude is not (yet) part of the official
1551
// types for tslint.
1652
interface ConfigurationFile extends Configuration.IConfigurationFile {
@@ -33,6 +69,7 @@ export class IncrementalChecker {
3369
linterConfig: ConfigurationFile;
3470
linterExclusions: minimatch.IMinimatch[];
3571

72+
typescript: TypeScriptInstance;
3673
program: ts.Program;
3774
programConfig: ts.ParsedCommandLine;
3875
watcher: FilesWatcher;
@@ -48,6 +85,7 @@ export class IncrementalChecker {
4885
checkSyntacticErrors: boolean,
4986
vue: boolean
5087
) {
88+
// TODO: set `typescript`
5189
this.programConfigFile = programConfigFile;
5290
this.linterConfigFile = linterConfigFile;
5391
this.watchPaths = watchPaths;
@@ -68,13 +106,16 @@ export class IncrementalChecker {
68106
}));
69107
}
70108

71-
static loadProgramConfig(configFile: string) {
72-
return ts.parseJsonConfigFileContent(
109+
static loadProgramConfig(typescript: TypeScriptInstance, configFile: string) {
110+
return typescript.parseJsonConfigFileContent(
73111
// 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,
78119
path.dirname(configFile)
79120
);
80121
}
@@ -88,12 +129,13 @@ export class IncrementalChecker {
88129
}
89130

90131
static createProgram(
132+
typescript: TypeScriptInstance,
91133
programConfig: ts.ParsedCommandLine,
92134
files: FilesRegister,
93135
watcher: FilesWatcher,
94136
oldProgram: ts.Program
95137
) {
96-
const host = ts.createCompilerHost(programConfig.options);
138+
const host = typescript.createCompilerHost(programConfig.options);
97139
const realGetSourceFile = host.getSourceFile;
98140

99141
host.getSourceFile = (filePath, languageVersion, onError) => {
@@ -119,7 +161,7 @@ export class IncrementalChecker {
119161
return files.getData(filePath).source;
120162
};
121163

122-
return ts.createProgram(
164+
return typescript.createProgram(
123165
programConfig.fileNames,
124166
programConfig.options,
125167
host,
@@ -203,9 +245,13 @@ export class IncrementalChecker {
203245
loadDefaultProgram() {
204246
this.programConfig =
205247
this.programConfig ||
206-
IncrementalChecker.loadProgramConfig(this.programConfigFile);
248+
IncrementalChecker.loadProgramConfig(
249+
this.typescript,
250+
this.programConfigFile
251+
);
207252

208253
return IncrementalChecker.createProgram(
254+
this.typescript,
209255
this.programConfig,
210256
this.files,
211257
this.watcher,
@@ -256,7 +302,7 @@ export class IncrementalChecker {
256302
return NormalizedMessage.deduplicate(
257303
diagnostics.map(d =>
258304
NormalizedMessage.createFromDiagnostic(
259-
ts.flattenDiagnosticMessageText,
305+
this.typescript.flattenDiagnosticMessageText,
260306
d
261307
)
262308
)

0 commit comments

Comments
 (0)