Skip to content

Commit fa9a648

Browse files
clydinfilipesilva
authored andcommitted
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.
1 parent 114a309 commit fa9a648

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

packages/angular_devkit/build_optimizer/src/build-optimizer/webpack-plugin.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,18 @@ export class BuildOptimizerWebpackPlugin {
1212
apply(compiler: Compiler) {
1313
compiler.hooks.normalModuleFactory.tap('BuildOptimizerWebpackPlugin', nmf => {
1414
nmf.hooks.module.tap('BuildOptimizerWebpackPlugin', (module, data) => {
15-
const resolveData = data.resourceResolveData;
16-
if (resolveData && resolveData.descriptionFileData) {
15+
const { descriptionFileData } = data.resourceResolveData;
16+
if (descriptionFileData) {
1717
// Only TS packages should use Build Optimizer.
18-
const typings = resolveData.descriptionFileData.typings;
1918
// Notes:
2019
// - a TS package might not have defined typings but still use .d.ts files next to their
2120
// .js files. We don't cover that case because the Angular Package Format (APF) calls for
2221
// using the Typings field and Build Optimizer is geared towards APF. Maybe we could
2322
// provide configuration options to the plugin to cover that case if there's demand.
2423
// - a JS-only package that also happens to provides typings will also be flagged by this
2524
// check. Not sure there's a good way to skip those.
26-
module.factoryMeta.skipBuildOptimizer = !typings;
25+
const skipBuildOptimizer = !descriptionFileData.typings;
26+
module.factoryMeta = { ...module.factoryMeta, skipBuildOptimizer };
2727
}
2828

2929
return module;

0 commit comments

Comments
 (0)