refactor(@angular-devkit/build-angular): use Webpack builder result provided output path

By using the output path provided directly by the Webpack builder's result, one additional reason for using the expensive `Stats.toJson` call is removed.
This change also removes multiple linting disable rule comments now that the output path property is guaranteed to be present.
This commit is contained in:
Charles Lyding 2021-03-14 09:48:18 -04:00 committed by Alan Agius
parent ff32ada86b
commit 6fd4da2ebf
3 changed files with 18 additions and 20 deletions

View File

@ -257,7 +257,12 @@ export function buildWebpackBrowser(
const spinner = new Spinner(); const spinner = new Spinner();
spinner.enabled = options.progress !== false; spinner.enabled = options.progress !== false;
const { webpackStats: webpackRawStats, success, emittedFiles = [] } = buildEvent; const {
webpackStats: webpackRawStats,
success,
emittedFiles = [],
outputPath: webpackOutputPath,
} = buildEvent;
if (!webpackRawStats) { if (!webpackRawStats) {
throw new Error('Webpack stats build result is required.'); throw new Error('Webpack stats build result is required.');
} }
@ -311,8 +316,7 @@ export function buildWebpackBrowser(
baseOutputPath, baseOutputPath,
Array.from(outputPaths.values()), Array.from(outputPaths.values()),
scriptsEntryPointName, scriptsEntryPointName,
// tslint:disable-next-line: no-non-null-assertion webpackOutputPath,
webpackStats.outputPath!,
target <= ScriptTarget.ES5, target <= ScriptTarget.ES5,
options.i18nMissingTranslation, options.i18nMissingTranslation,
); );
@ -386,8 +390,7 @@ export function buildWebpackBrowser(
// Retrieve the content/map for the file // Retrieve the content/map for the file
// NOTE: Additional future optimizations will read directly from memory // NOTE: Additional future optimizations will read directly from memory
// tslint:disable-next-line: no-non-null-assertion let filename = path.join(webpackOutputPath, file.file);
let filename = path.join(webpackStats.outputPath!, file.file);
const code = fs.readFileSync(filename, 'utf8'); const code = fs.readFileSync(filename, 'utf8');
let map; let map;
if (actionOptions.sourceMaps) { if (actionOptions.sourceMaps) {
@ -537,12 +540,10 @@ export function buildWebpackBrowser(
[ [
{ {
glob: '**/*', glob: '**/*',
// tslint:disable-next-line: no-non-null-assertion input: webpackOutputPath,
input: webpackStats.outputPath!,
output: '', output: '',
ignore: [...processedFiles].map(f => ignore: [...processedFiles].map(f =>
// tslint:disable-next-line: no-non-null-assertion path.relative(webpackOutputPath, f),
path.relative(webpackStats.outputPath!, f),
), ),
}, },
], ],
@ -598,8 +599,7 @@ export function buildWebpackBrowser(
baseOutputPath, baseOutputPath,
Array.from(outputPaths.values()), Array.from(outputPaths.values()),
scriptsEntryPointName, scriptsEntryPointName,
// tslint:disable-next-line: no-non-null-assertion webpackOutputPath,
webpackStats.outputPath!,
target <= ScriptTarget.ES5, target <= ScriptTarget.ES5,
options.i18nMissingTranslation, options.i18nMissingTranslation,
); );

View File

@ -257,6 +257,7 @@ export async function execute(
return { return {
success: false, success: false,
error: `Ivy extraction requires the '@angular/localize' package.`, error: `Ivy extraction requires the '@angular/localize' package.`,
outputPath: outFile,
}; };
} }
} }
@ -270,13 +271,11 @@ export async function execute(
}, },
).toPromise(); ).toPromise();
// Complete if using VE // Set the outputPath to the extraction output location for downstream consumers
if (!usingIvy) { webpackResult.outputPath = outFile;
return webpackResult;
}
// Nothing to process if the Webpack build failed // Complete if using VE or if Webpack build failed
if (!webpackResult.success) { if (!usingIvy || !webpackResult.success) {
return webpackResult; return webpackResult;
} }

View File

@ -92,7 +92,7 @@ export function execute(
}, },
}).pipe( }).pipe(
concatMap(async output => { concatMap(async output => {
const { emittedFiles = [], webpackStats } = output; const { emittedFiles = [], outputPath, webpackStats } = output;
if (!webpackStats) { if (!webpackStats) {
throw new Error('Webpack stats build result is required.'); throw new Error('Webpack stats build result is required.');
} }
@ -108,8 +108,7 @@ export function execute(
baseOutputPath, baseOutputPath,
Array.from(outputPaths.values()), Array.from(outputPaths.values()),
[], [],
// tslint:disable-next-line: no-non-null-assertion outputPath,
webpackStats.outputPath!,
target <= ScriptTarget.ES5, target <= ScriptTarget.ES5,
options.i18nMissingTranslation, options.i18nMissingTranslation,
); );