From b3736a3c09f39f5ee5dc12d98535fe4b6803ea3b Mon Sep 17 00:00:00 2001 From: Alan Agius Date: Tue, 27 Jul 2021 16:01:32 +0200 Subject: [PATCH] fix(@angular-devkit/build-webpack): emit result when webpack is closed With this change we emit the compilation result when the compilation is closed, when the compilation is not in watch mode. This is needed so that when persistent caching is enabled and architect promise API is used (`.result`) instead of `.output` we wait for the cache to be written prior to terminating the process/resolving the result promise. The `result` API currently, takes the first emit https://github.com/angular/angular-cli/blob/4f9df9f4a4da81c9ecd8733204226c030f8f7d56/packages/angular_devkit/architect/src/schedule-by-name.ts#L118-L120 Closes #21419 (cherry picked from commit 61535302204a2a767f85053b7efaa6ac5ac64098) --- .../build_angular/src/app-shell/index.ts | 8 +++----- .../build_webpack/src/webpack/index.ts | 14 +++++++++----- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/packages/angular_devkit/build_angular/src/app-shell/index.ts b/packages/angular_devkit/build_angular/src/app-shell/index.ts index 10c03cdb97eb..71dc853fec82 100644 --- a/packages/angular_devkit/build_angular/src/app-shell/index.ts +++ b/packages/angular_devkit/build_angular/src/app-shell/index.ts @@ -180,10 +180,9 @@ async function _appShellBuilder( let spinner: Spinner | undefined; try { - // Using `.result` instead of `.output` causes Webpack FS cache not to be created. const [browserResult, serverResult] = await Promise.all([ - browserTargetRun.output.toPromise() as Promise, - serverTargetRun.output.toPromise() as Promise, + browserTargetRun.result as Promise, + serverTargetRun.result as Promise, ]); if (browserResult.success === false || browserResult.baseOutputPath === undefined) { @@ -203,8 +202,7 @@ async function _appShellBuilder( return { success: false, error: err.message }; } finally { - // workaround for [tsetse] All Promises in async functions must either be awaited or used in an expression. - const _ = Promise.all([browserTargetRun.stop(), serverTargetRun.stop()]); + await Promise.all([browserTargetRun.stop(), serverTargetRun.stop()]); } } diff --git a/packages/angular_devkit/build_webpack/src/webpack/index.ts b/packages/angular_devkit/build_webpack/src/webpack/index.ts index 8749e1237d0d..0dec67cb1fd6 100644 --- a/packages/angular_devkit/build_webpack/src/webpack/index.ts +++ b/packages/angular_devkit/build_webpack/src/webpack/index.ts @@ -72,16 +72,20 @@ export function runWebpack( log(stats, config); const statsOptions = typeof config.stats === 'boolean' ? undefined : config.stats; - - obs.next({ + const result = { success: !stats.hasErrors(), webpackStats: shouldProvideStats ? stats.toJson(statsOptions) : undefined, emittedFiles: getEmittedFiles(stats.compilation), outputPath: stats.compilation.outputOptions.path, - } as unknown as BuildResult); + } as unknown as BuildResult; - if (!config.watch) { - webpackCompiler.close(() => obs.complete()); + if (config.watch) { + obs.next(result); + } else { + webpackCompiler.close(() => { + obs.next(result); + obs.complete(); + }); } };