fix(@angular-devkit/build-optimizer): handle undefined factoryMeta in Webpack plugin

A Webpack module's `factoryMeta` property is not guaranteed to be defined.  This change ensures that the build optimizer skip property is added even in the case of no `factoryMeta` currently defined.
This commit is contained in:
Charles Lyding 2020-08-05 14:49:15 -04:00 committed by Filipe Silva
parent 114a309b0a
commit fa9a648cae

View File

@ -12,10 +12,9 @@ export class BuildOptimizerWebpackPlugin {
apply(compiler: Compiler) {
compiler.hooks.normalModuleFactory.tap('BuildOptimizerWebpackPlugin', nmf => {
nmf.hooks.module.tap('BuildOptimizerWebpackPlugin', (module, data) => {
const resolveData = data.resourceResolveData;
if (resolveData && resolveData.descriptionFileData) {
const { descriptionFileData } = data.resourceResolveData;
if (descriptionFileData) {
// Only TS packages should use Build Optimizer.
const typings = resolveData.descriptionFileData.typings;
// Notes:
// - a TS package might not have defined typings but still use .d.ts files next to their
// .js files. We don't cover that case because the Angular Package Format (APF) calls for
@ -23,7 +22,8 @@ export class BuildOptimizerWebpackPlugin {
// provide configuration options to the plugin to cover that case if there's demand.
// - a JS-only package that also happens to provides typings will also be flagged by this
// check. Not sure there's a good way to skip those.
module.factoryMeta.skipBuildOptimizer = !typings;
const skipBuildOptimizer = !descriptionFileData.typings;
module.factoryMeta = { ...module.factoryMeta, skipBuildOptimizer };
}
return module;