Skip to content

Commit 19ac765

Browse files
committed
Return exit codes from tsbuild
1 parent 60d0e64 commit 19ac765

2 files changed

Lines changed: 33 additions & 19 deletions

File tree

src/compiler/tsbuild.ts

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ namespace ts {
422422
}
423423
];
424424

425-
export function performBuild(args: string[], compilerHost: CompilerHost, buildHost: BuildHost, system?: System) {
425+
export function performBuild(args: string[], compilerHost: CompilerHost, buildHost: BuildHost, system?: System): number {
426426
let verbose = false;
427427
let dry = false;
428428
let force = false;
@@ -455,24 +455,29 @@ namespace ts {
455455
case "--?":
456456
case "-?":
457457
case "--help":
458-
return printHelp(buildOpts, "--build ");
458+
printHelp(buildOpts, "--build ");
459+
return ExitStatus.Success;
459460
}
460461
// Not a flag, parse as filename
461462
addProject(arg);
462463
}
463464

464465
// Nonsensical combinations
465466
if (clean && force) {
466-
return buildHost.error(Diagnostics.Options_0_and_1_cannot_be_combined, "clean", "force");
467+
buildHost.error(Diagnostics.Options_0_and_1_cannot_be_combined, "clean", "force");
468+
return ExitStatus.DiagnosticsPresent_OutputsSkipped;
467469
}
468470
if (clean && verbose) {
469-
return buildHost.error(Diagnostics.Options_0_and_1_cannot_be_combined, "clean", "verbose");
471+
buildHost.error(Diagnostics.Options_0_and_1_cannot_be_combined, "clean", "verbose");
472+
return ExitStatus.DiagnosticsPresent_OutputsSkipped;
470473
}
471474
if (clean && watch) {
472-
return buildHost.error(Diagnostics.Options_0_and_1_cannot_be_combined, "clean", "watch");
475+
buildHost.error(Diagnostics.Options_0_and_1_cannot_be_combined, "clean", "watch");
476+
return ExitStatus.DiagnosticsPresent_OutputsSkipped;
473477
}
474478
if (watch && dry) {
475-
return buildHost.error(Diagnostics.Options_0_and_1_cannot_be_combined, "watch", "dry");
479+
buildHost.error(Diagnostics.Options_0_and_1_cannot_be_combined, "watch", "dry");
480+
return ExitStatus.DiagnosticsPresent_OutputsSkipped;
476481
}
477482

478483
if (projects.length === 0) {
@@ -482,14 +487,15 @@ namespace ts {
482487

483488
const builder = createSolutionBuilder(compilerHost, buildHost, projects, { dry, force, verbose }, system);
484489
if (clean) {
485-
builder.cleanAllProjects();
490+
return builder.cleanAllProjects();
486491
}
487492
else {
488-
builder.buildAllProjects();
493+
return builder.buildAllProjects();
489494
}
490495

491496
if (watch) {
492-
return builder.startWatching();
497+
builder.startWatching();
498+
return ExitStatus.Success;
493499
}
494500

495501
function addProject(projectSpecification: string) {
@@ -503,7 +509,6 @@ namespace ts {
503509
return buildHost.error(Diagnostics.File_0_does_not_exist, fileName);
504510
}
505511
projects.push(refPath);
506-
507512
}
508513
}
509514

@@ -776,7 +781,7 @@ namespace ts {
776781
let usesPrepend = false;
777782
if (project.projectReferences) {
778783
for (const ref of project.projectReferences) {
779-
usesPrepend = usesPrepend || ref.prepend;
784+
usesPrepend = usesPrepend || !!(ref.prepend);
780785
const resolvedRef = resolveProjectReferencePath(compilerHost, ref) as ResolvedConfigFileName;
781786
const refStatus = getUpToDateStatus(configFileCache.parseConfigFile(resolvedRef));
782787

@@ -835,7 +840,7 @@ namespace ts {
835840
}
836841

837842
if (usesPrepend) {
838-
psuedoUpToDate = false;
843+
pseudoUpToDate = false;
839844
}
840845

841846
// Up to date
@@ -1054,16 +1059,19 @@ namespace ts {
10541059
function cleanAllProjects() {
10551060
const resolvedNames: ReadonlyArray<ResolvedConfigFileName> | undefined = getAllProjectsInScope();
10561061
if (resolvedNames === undefined) {
1057-
return buildHost.message(Diagnostics.Skipping_clean_because_not_all_projects_could_be_located);
1062+
buildHost.message(Diagnostics.Skipping_clean_because_not_all_projects_could_be_located);
1063+
return ExitStatus.DiagnosticsPresent_OutputsSkipped;
10581064
}
10591065

10601066
const filesToDelete = getFilesToClean(resolvedNames);
10611067
if (filesToDelete === undefined) {
1062-
return buildHost.message(Diagnostics.Skipping_clean_because_not_all_projects_could_be_located);
1068+
buildHost.message(Diagnostics.Skipping_clean_because_not_all_projects_could_be_located);
1069+
return ExitStatus.DiagnosticsPresent_OutputsSkipped;
10631070
}
10641071

10651072
if (context.options.dry) {
1066-
return buildHost.message(Diagnostics.A_non_dry_build_would_delete_the_following_files_Colon_0, filesToDelete.map(f => `\r\n * ${f}`).join(""));
1073+
buildHost.message(Diagnostics.A_non_dry_build_would_delete_the_following_files_Colon_0, filesToDelete.map(f => `\r\n * ${f}`).join(""));
1074+
return ExitStatus.Success;
10671075
}
10681076

10691077
// Do this check later to allow --clean --dry to function even if the host can't delete files
@@ -1074,6 +1082,8 @@ namespace ts {
10741082
for (const output of filesToDelete) {
10751083
compilerHost.deleteFile(output);
10761084
}
1085+
1086+
return ExitStatus.Success;
10771087
}
10781088

10791089
function resolveProjectName(name: string): ResolvedConfigFileName | undefined {
@@ -1101,16 +1111,18 @@ namespace ts {
11011111
return resolvedNames;
11021112
}
11031113

1104-
function buildAllProjects() {
1114+
function buildAllProjects(): number {
11051115
const graph = getGlobalDependencyGraph();
1106-
if (graph === undefined) return;
1116+
if (graph === undefined) return ExitStatus.DiagnosticsPresent_OutputsSkipped;
11071117

11081118
const queue = graph.buildQueue;
11091119
reportBuildQueue(graph);
11101120

1121+
let anyFailed = false;
11111122
for (const next of queue) {
11121123
const proj = configFileCache.parseConfigFile(next);
11131124
if (proj === undefined) {
1125+
anyFailed = true;
11141126
break;
11151127
}
11161128
const status = getUpToDateStatus(proj);
@@ -1142,8 +1154,10 @@ namespace ts {
11421154
continue;
11431155
}
11441156

1145-
buildSingleProject(next);
1157+
const buildResult = buildSingleProject(next);
1158+
anyFailed = anyFailed || !!(buildResult & BuildResultFlags.AnyErrors);
11461159
}
1160+
return anyFailed ? ExitStatus.DiagnosticsPresent_OutputsSkipped : ExitStatus.Success;
11471161
}
11481162

11491163
/**

src/tsc/tsc.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ namespace ts {
5858
message: report,
5959
errorDiagnostic: d => reportDiag(d)
6060
};
61-
return performBuild(args.slice(1), createCompilerHost({}), buildHost, sys);
61+
return sys.exit(performBuild(args.slice(1), createCompilerHost({}), buildHost, sys));
6262
}
6363

6464
const commandLine = parseCommandLine(args);

0 commit comments

Comments
 (0)