Skip to content

Commit

Permalink
Merge pull request microsoft#34365 from elibarzilay/fix-exit-code-on-…
Browse files Browse the repository at this point in the history
…bogus-build-file

Fix exit code on bogus build file
  • Loading branch information
elibarzilay committed Oct 15, 2019
2 parents ab56cc0 + 730a52b commit 22c15a2
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 16 deletions.
24 changes: 9 additions & 15 deletions src/compiler/tsbuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1788,31 +1788,25 @@ namespace ts {

let reportQueue = true;
let successfulProjects = 0;
let errorProjects = 0;
while (true) {
const invalidatedProject = getNextInvalidatedProject(state, buildOrder, reportQueue);
if (!invalidatedProject) break;
reportQueue = false;
invalidatedProject.done(cancellationToken);
if (state.diagnostics.has(invalidatedProject.projectPath)) {
errorProjects++;
}
else {
successfulProjects++;
}
if (!state.diagnostics.has(invalidatedProject.projectPath)) successfulProjects++;
}

disableCache(state);
reportErrorSummary(state, buildOrder);
startWatching(state, buildOrder);

return isCircularBuildOrder(buildOrder) ?
ExitStatus.ProjectReferenceCycle_OutputsSkupped :
errorProjects ?
successfulProjects ?
ExitStatus.DiagnosticsPresent_OutputsGenerated :
ExitStatus.DiagnosticsPresent_OutputsSkipped :
ExitStatus.Success;
return isCircularBuildOrder(buildOrder)
? ExitStatus.ProjectReferenceCycle_OutputsSkipped
: !buildOrder.some(p => state.diagnostics.has(toResolvedConfigFilePath(state, p)))
? ExitStatus.Success
: successfulProjects
? ExitStatus.DiagnosticsPresent_OutputsGenerated
: ExitStatus.DiagnosticsPresent_OutputsSkipped;
}

function clean(state: SolutionBuilderState, project?: string, onlyReferences?: boolean) {
Expand All @@ -1821,7 +1815,7 @@ namespace ts {

if (isCircularBuildOrder(buildOrder)) {
reportErrors(state, buildOrder.circularDiagnostics);
return ExitStatus.ProjectReferenceCycle_OutputsSkupped;
return ExitStatus.ProjectReferenceCycle_OutputsSkipped;
}

const { options, host } = state;
Expand Down
3 changes: 3 additions & 0 deletions src/compiler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3261,6 +3261,9 @@ namespace ts {
InvalidProject_OutputsSkipped = 3,

// When build is skipped because project references form cycle
ProjectReferenceCycle_OutputsSkipped = 4,

/** @deprecated Use ProjectReferenceCycle_OutputsSkipped instead. */
ProjectReferenceCycle_OutputsSkupped = 4,
}

Expand Down
1 change: 1 addition & 0 deletions src/testRunner/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
"unittests/tsbuild/demo.ts",
"unittests/tsbuild/emitDeclarationOnly.ts",
"unittests/tsbuild/emptyFiles.ts",
"unittests/tsbuild/exitCodeOnBogusFile.ts",
"unittests/tsbuild/graphOrdering.ts",
"unittests/tsbuild/inferredTypeFromTransitiveModule.ts",
"unittests/tsbuild/javascriptProjectEmit.ts",
Expand Down
2 changes: 1 addition & 1 deletion src/testRunner/unittests/tsbuild/demo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ namespace ts {
}
]`
),
expectedExitStatus: ExitStatus.ProjectReferenceCycle_OutputsSkupped,
expectedExitStatus: ExitStatus.ProjectReferenceCycle_OutputsSkipped,
expectedDiagnostics: () => [
getExpectedDiagnosticForProjectsInBuild("src/animals/tsconfig.json", "src/zoo/tsconfig.json", "src/core/tsconfig.json", "src/tsconfig.json"),
errorDiagnostic([
Expand Down
11 changes: 11 additions & 0 deletions src/testRunner/unittests/tsbuild/exitCodeOnBogusFile.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace ts {
// https://github.com/microsoft/TypeScript/issues/33849
describe("unittests:: tsbuild:: exitCodeOnBogusFile:: test exit code", () => {
verifyTsc({
scenario: "exitCodeOnBogusFile",
subScenario: `test exit code`,
fs: () => loadProjectFromFiles({}, symbolLibContent),
commandLineArgs: ["-b", "bogus.json"]
});
});
}
2 changes: 2 additions & 0 deletions tests/baselines/reference/api/tsserverlibrary.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1964,6 +1964,8 @@ declare namespace ts {
DiagnosticsPresent_OutputsSkipped = 1,
DiagnosticsPresent_OutputsGenerated = 2,
InvalidProject_OutputsSkipped = 3,
ProjectReferenceCycle_OutputsSkipped = 4,
/** @deprecated Use ProjectReferenceCycle_OutputsSkipped instead. */
ProjectReferenceCycle_OutputsSkupped = 4
}
export interface EmitResult {
Expand Down
2 changes: 2 additions & 0 deletions tests/baselines/reference/api/typescript.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1964,6 +1964,8 @@ declare namespace ts {
DiagnosticsPresent_OutputsSkipped = 1,
DiagnosticsPresent_OutputsGenerated = 2,
InvalidProject_OutputsSkipped = 3,
ProjectReferenceCycle_OutputsSkipped = 4,
/** @deprecated Use ProjectReferenceCycle_OutputsSkipped instead. */
ProjectReferenceCycle_OutputsSkupped = 4
}
export interface EmitResult {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//// [/lib/initial-buildOutput.txt]
/lib/tsc -b bogus.json
error TS6053: File '/bogus.json' not found.
exitCode:: 1


0 comments on commit 22c15a2

Please sign in to comment.