Skip to content

Commit

Permalink
fix(@angular-devkit/build-angular): prevent hanging initial build dur…
Browse files Browse the repository at this point in the history
…ing 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 c3447e3)
  • Loading branch information
clydin authored and dgp1130 committed Jan 17, 2023
1 parent 387472a commit bf4639a
Showing 1 changed file with 16 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
Expand All @@ -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...');
Expand Down

0 comments on commit bf4639a

Please sign in to comment.