From bf4639a6e97670972c3d5b137230e2f08467010e Mon Sep 17 00:00:00 2001 From: Charles Lyding <19598772+clydin@users.noreply.github.com> Date: Fri, 13 Jan 2023 10:33:58 -0500 Subject: [PATCH] fix(@angular-devkit/build-angular): prevent hanging initial build during exception with esbuild When using the experimental esbuild-based browser application builder and an exception is thrown during the initial build, the process may hang indefinitely due to the Sass worker pool not shutting down fully. This does not happen for rebuilds after the initial. To remedy this situation, The initial build is now wrapped in a try block to ensure that a full shutdown of the Sass worker pool occurs. (cherry picked from commit c3447e3640b059b62e4c2c5d18543195b0d6c820) --- .../src/builders/browser-esbuild/index.ts | 26 ++++++++++++------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/packages/angular_devkit/build_angular/src/builders/browser-esbuild/index.ts b/packages/angular_devkit/build_angular/src/builders/browser-esbuild/index.ts index c54daf74f643..54d03b7a21bd 100644 --- a/packages/angular_devkit/build_angular/src/builders/browser-esbuild/index.ts +++ b/packages/angular_devkit/build_angular/src/builders/browser-esbuild/index.ts @@ -450,7 +450,7 @@ export async function* buildEsbuildBrowser( 'JIT mode is currently not supported by this experimental builder. AOT mode must be used.', ); - return { success: false }; + return; } // Inform user of experimental status of builder and options @@ -461,7 +461,7 @@ export async function* buildEsbuildBrowser( if (!projectName) { context.logger.error(`The 'browser-esbuild' builder requires a target to be specified.`); - return { success: false }; + return; } const normalizedOptions = await normalizeOptions(context, projectName, initialOptions); @@ -478,18 +478,24 @@ export async function* buildEsbuildBrowser( assertIsError(e); context.logger.error('Unable to create output directory: ' + e.message); - return { success: false }; + return; } // Initial build - let result = await execute(normalizedOptions, context); - yield result.output; - - // Finish if watch mode is not enabled - if (!initialOptions.watch) { - shutdownSassWorkerPool(); + let result: ExecutionResult; + try { + result = await execute(normalizedOptions, context); + yield result.output; - return; + // Finish if watch mode is not enabled + if (!initialOptions.watch) { + return; + } + } finally { + // Ensure Sass workers are shutdown if not watching + if (!initialOptions.watch) { + shutdownSassWorkerPool(); + } } context.logger.info('Watch mode enabled. Watching for file changes...');