Skip to content

Commit 596f763

Browse files
committed
fix(@angular-devkit/build-angular): ensure compilation errors propagate 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)
1 parent e1d6ee2 commit 596f763

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

packages/angular_devkit/build_angular/src/tools/esbuild/angular/compilation-state.ts

+9-7
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@
88

99
export class SharedTSCompilationState {
1010
#pendingCompilation = true;
11-
#resolveCompilationReady: (() => void) | undefined;
12-
#compilationReadyPromise: Promise<void> | undefined;
11+
#resolveCompilationReady: ((value: boolean) => void) | undefined;
12+
#compilationReadyPromise: Promise<boolean> | undefined;
13+
#hasErrors = true;
1314

14-
get waitUntilReady(): Promise<void> {
15+
get waitUntilReady(): Promise<boolean> {
1516
if (!this.#pendingCompilation) {
16-
return Promise.resolve();
17+
return Promise.resolve(this.#hasErrors);
1718
}
1819

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

26-
markAsReady(): void {
27-
this.#resolveCompilationReady?.();
27+
markAsReady(hasErrors: boolean): void {
28+
this.#hasErrors = hasErrors;
29+
this.#resolveCompilationReady?.(hasErrors);
2830
this.#compilationReadyPromise = undefined;
2931
this.#pendingCompilation = false;
3032
}
@@ -34,7 +36,7 @@ export class SharedTSCompilationState {
3436
}
3537

3638
dispose(): void {
37-
this.markAsReady();
39+
this.markAsReady(true);
3840
globalSharedCompilationState = undefined;
3941
}
4042
}

packages/angular_devkit/build_angular/src/tools/esbuild/angular/compiler-plugin.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -263,8 +263,7 @@ export function createCompilerPlugin(
263263
}
264264

265265
if (compilation instanceof NoopCompilation) {
266-
await sharedTSCompilationState.waitUntilReady;
267-
hasCompilationErrors = false;
266+
hasCompilationErrors = await sharedTSCompilationState.waitUntilReady;
268267

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

321-
sharedTSCompilationState.markAsReady();
320+
sharedTSCompilationState.markAsReady(hasCompilationErrors);
322321

323322
return result;
324323
});
@@ -409,7 +408,7 @@ export function createCompilerPlugin(
409408

410409
build.onEnd((result) => {
411410
// Ensure other compilations are unblocked if the main compilation throws during start
412-
sharedTSCompilationState?.markAsReady();
411+
sharedTSCompilationState?.markAsReady(hasCompilationErrors);
413412

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

0 commit comments

Comments
 (0)