Skip to content

Commit

Permalink
refactor(@angular-devkit/build-angular): use Webpack builder result p…
Browse files Browse the repository at this point in the history
…rovided 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.
  • Loading branch information
clydin authored and alan-agius4 committed Mar 15, 2021
1 parent ff32ada commit 6fd4da2
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 20 deletions.
22 changes: 11 additions & 11 deletions packages/angular_devkit/build_angular/src/browser/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,12 @@ export function buildWebpackBrowser(
const spinner = new Spinner();
spinner.enabled = options.progress !== false;

const { webpackStats: webpackRawStats, success, emittedFiles = [] } = buildEvent;
const {
webpackStats: webpackRawStats,
success,
emittedFiles = [],
outputPath: webpackOutputPath,
} = buildEvent;
if (!webpackRawStats) {
throw new Error('Webpack stats build result is required.');
}
Expand Down Expand Up @@ -311,8 +316,7 @@ export function buildWebpackBrowser(
baseOutputPath,
Array.from(outputPaths.values()),
scriptsEntryPointName,
// tslint:disable-next-line: no-non-null-assertion
webpackStats.outputPath!,
webpackOutputPath,
target <= ScriptTarget.ES5,
options.i18nMissingTranslation,
);
Expand Down Expand Up @@ -386,8 +390,7 @@ export function buildWebpackBrowser(

// Retrieve the content/map for the file
// NOTE: Additional future optimizations will read directly from memory
// tslint:disable-next-line: no-non-null-assertion
let filename = path.join(webpackStats.outputPath!, file.file);
let filename = path.join(webpackOutputPath, file.file);
const code = fs.readFileSync(filename, 'utf8');
let map;
if (actionOptions.sourceMaps) {
Expand Down Expand Up @@ -537,12 +540,10 @@ export function buildWebpackBrowser(
[
{
glob: '**/*',
// tslint:disable-next-line: no-non-null-assertion
input: webpackStats.outputPath!,
input: webpackOutputPath,
output: '',
ignore: [...processedFiles].map(f =>
// tslint:disable-next-line: no-non-null-assertion
path.relative(webpackStats.outputPath!, f),
path.relative(webpackOutputPath, f),
),
},
],
Expand Down Expand Up @@ -598,8 +599,7 @@ export function buildWebpackBrowser(
baseOutputPath,
Array.from(outputPaths.values()),
scriptsEntryPointName,
// tslint:disable-next-line: no-non-null-assertion
webpackStats.outputPath!,
webpackOutputPath,
target <= ScriptTarget.ES5,
options.i18nMissingTranslation,
);
Expand Down
11 changes: 5 additions & 6 deletions packages/angular_devkit/build_angular/src/extract-i18n/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ export async function execute(
return {
success: false,
error: `Ivy extraction requires the '@angular/localize' package.`,
outputPath: outFile,
};
}
}
Expand All @@ -270,13 +271,11 @@ export async function execute(
},
).toPromise();

// Complete if using VE
if (!usingIvy) {
return webpackResult;
}
// Set the outputPath to the extraction output location for downstream consumers
webpackResult.outputPath = outFile;

// Nothing to process if the Webpack build failed
if (!webpackResult.success) {
// Complete if using VE or if Webpack build failed
if (!usingIvy || !webpackResult.success) {
return webpackResult;
}

Expand Down
5 changes: 2 additions & 3 deletions packages/angular_devkit/build_angular/src/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export function execute(
},
}).pipe(
concatMap(async output => {
const { emittedFiles = [], webpackStats } = output;
const { emittedFiles = [], outputPath, webpackStats } = output;
if (!webpackStats) {
throw new Error('Webpack stats build result is required.');
}
Expand All @@ -108,8 +108,7 @@ export function execute(
baseOutputPath,
Array.from(outputPaths.values()),
[],
// tslint:disable-next-line: no-non-null-assertion
webpackStats.outputPath!,
outputPath,
target <= ScriptTarget.ES5,
options.i18nMissingTranslation,
);
Expand Down

0 comments on commit 6fd4da2

Please sign in to comment.