Skip to content

Commit e20a7d8

Browse files
committed
Remove unnecessary usage of system and compilerHost
1 parent 071d790 commit e20a7d8

File tree

1 file changed

+23
-19
lines changed

1 file changed

+23
-19
lines changed

src/tsc/tsc.ts

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,7 @@ namespace ts {
5454

5555
export function executeCommandLine(args: string[]): void {
5656
if (args.length > 0 && ((args[0].toLowerCase() === "--build") || (args[0].toLowerCase() === "-b"))) {
57-
const reportDiag = createDiagnosticReporter(sys, defaultIsPretty());
58-
const report = (message: DiagnosticMessage, ...args: string[]) => reportDiag(createCompilerDiagnostic(message, ...args));
59-
const buildHost: BuildHost = {
60-
error: report,
61-
verbose: report,
62-
message: report,
63-
errorDiagnostic: d => reportDiag(d)
64-
};
65-
const result = performBuild(args.slice(1), createCompilerHost({}), buildHost);
57+
const result = performBuild(args.slice(1));
6658
// undefined = in watch mode, do not exit
6759
if (result !== undefined) {
6860
return sys.exit(result);
@@ -172,7 +164,7 @@ namespace ts {
172164
}
173165
}
174166

175-
function performBuild(args: string[], compilerHost: CompilerHost, buildHost: BuildHost): number | undefined {
167+
function performBuild(args: string[]): number | undefined {
176168
const buildOpts: CommandLineOption[] = [
177169
{
178170
name: "help",
@@ -243,24 +235,28 @@ namespace ts {
243235
}
244236

245237
if (buildOptions.help) {
246-
printHelp(buildOpts, "--build "); return ExitStatus.Success;
238+
printHelp(buildOpts, "--build ");
239+
return ExitStatus.Success;
247240
}
248241

242+
// Update to pretty if host supports it
243+
updateReportDiagnostic({});
244+
249245
// Nonsensical combinations
250246
if (buildOptions.clean && buildOptions.force) {
251-
buildHost.error(Diagnostics.Options_0_and_1_cannot_be_combined, "clean", "force");
247+
reportDiagnostic(createCompilerDiagnostic(Diagnostics.Options_0_and_1_cannot_be_combined, "clean", "force"));
252248
return ExitStatus.DiagnosticsPresent_OutputsSkipped;
253249
}
254250
if (buildOptions.clean && buildOptions.verbose) {
255-
buildHost.error(Diagnostics.Options_0_and_1_cannot_be_combined, "clean", "verbose");
251+
reportDiagnostic(createCompilerDiagnostic(Diagnostics.Options_0_and_1_cannot_be_combined, "clean", "verbose"));
256252
return ExitStatus.DiagnosticsPresent_OutputsSkipped;
257253
}
258254
if (buildOptions.clean && buildOptions.watch) {
259-
buildHost.error(Diagnostics.Options_0_and_1_cannot_be_combined, "clean", "watch");
255+
reportDiagnostic(createCompilerDiagnostic(Diagnostics.Options_0_and_1_cannot_be_combined, "clean", "watch"));
260256
return ExitStatus.DiagnosticsPresent_OutputsSkipped;
261257
}
262258
if (buildOptions.watch && buildOptions.dry) {
263-
buildHost.error(Diagnostics.Options_0_and_1_cannot_be_combined, "watch", "dry");
259+
reportDiagnostic(createCompilerDiagnostic(Diagnostics.Options_0_and_1_cannot_be_combined, "watch", "dry"));
264260
return ExitStatus.DiagnosticsPresent_OutputsSkipped;
265261
}
266262

@@ -269,7 +265,15 @@ namespace ts {
269265
addProject(".");
270266
}
271267

272-
const builder = createSolutionBuilder(compilerHost, buildHost, projects, buildOptions);
268+
const report = (message: DiagnosticMessage, ...args: string[]) => reportDiagnostic(createCompilerDiagnostic(message, ...args));
269+
const buildHost: BuildHost = {
270+
error: report,
271+
verbose: report,
272+
message: report,
273+
errorDiagnostic: d => reportDiagnostic(d)
274+
};
275+
276+
const builder = createSolutionBuilder(createCompilerHost({}), buildHost, projects, buildOptions);
273277
if (buildOptions.clean) {
274278
return builder.cleanAllProjects();
275279
}
@@ -283,9 +287,9 @@ namespace ts {
283287
return builder.buildAllProjects();
284288

285289
function addProject(projectSpecification: string) {
286-
const fileName = resolvePath(compilerHost.getCurrentDirectory(), projectSpecification);
287-
const refPath = resolveProjectReferencePath(compilerHost, { path: fileName });
288-
if (!compilerHost.fileExists(refPath)) {
290+
const fileName = resolvePath(sys.getCurrentDirectory(), projectSpecification);
291+
const refPath = resolveProjectReferencePath(sys, { path: fileName });
292+
if (!sys.fileExists(refPath)) {
289293
return buildHost.error(Diagnostics.File_0_does_not_exist, fileName);
290294
}
291295
projects.push(refPath);

0 commit comments

Comments
 (0)