Skip to content

Commit

Permalink
fix(@angular-devkit/build-angular): ensure compilation errors propaga…
Browse files Browse the repository at this point in the history
…te to all bundle actions

If the TypeScript and/or Angular AOT compiler fails to initialize or emit files due to an error,
the shared compilation state between the browser code bundle action and any additional bundle actions
(polyfills, server, etc.) will now carry an error flag to ensure that the additional bundle actions
bypass file emit. The file emit bypass is necessary in these cases to prevent an unintentional and
misleading error about a file not being included in the compilation.

(cherry picked from commit 38b7667)
  • Loading branch information
clydin committed Nov 15, 2023
1 parent e1d6ee2 commit 596f763
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@

export class SharedTSCompilationState {
#pendingCompilation = true;
#resolveCompilationReady: (() => void) | undefined;
#compilationReadyPromise: Promise<void> | undefined;
#resolveCompilationReady: ((value: boolean) => void) | undefined;
#compilationReadyPromise: Promise<boolean> | undefined;
#hasErrors = true;

get waitUntilReady(): Promise<void> {
get waitUntilReady(): Promise<boolean> {
if (!this.#pendingCompilation) {
return Promise.resolve();
return Promise.resolve(this.#hasErrors);
}

this.#compilationReadyPromise ??= new Promise((resolve) => {
Expand All @@ -23,8 +24,9 @@ export class SharedTSCompilationState {
return this.#compilationReadyPromise;
}

markAsReady(): void {
this.#resolveCompilationReady?.();
markAsReady(hasErrors: boolean): void {
this.#hasErrors = hasErrors;
this.#resolveCompilationReady?.(hasErrors);
this.#compilationReadyPromise = undefined;
this.#pendingCompilation = false;
}
Expand All @@ -34,7 +36,7 @@ export class SharedTSCompilationState {
}

dispose(): void {
this.markAsReady();
this.markAsReady(true);
globalSharedCompilationState = undefined;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,7 @@ export function createCompilerPlugin(
}

if (compilation instanceof NoopCompilation) {
await sharedTSCompilationState.waitUntilReady;
hasCompilationErrors = false;
hasCompilationErrors = await sharedTSCompilationState.waitUntilReady;

return result;
}
Expand Down Expand Up @@ -318,7 +317,7 @@ export function createCompilerPlugin(
// Reset the setup warnings so that they are only shown during the first build.
setupWarnings = undefined;

sharedTSCompilationState.markAsReady();
sharedTSCompilationState.markAsReady(hasCompilationErrors);

return result;
});
Expand Down Expand Up @@ -409,7 +408,7 @@ export function createCompilerPlugin(

build.onEnd((result) => {
// Ensure other compilations are unblocked if the main compilation throws during start
sharedTSCompilationState?.markAsReady();
sharedTSCompilationState?.markAsReady(hasCompilationErrors);

for (const { outputFiles, metafile } of additionalResults.values()) {
// Add any additional output files to the main output files
Expand Down

0 comments on commit 596f763

Please sign in to comment.