Skip to content

Commit 5c43068

Browse files
authored
fix: respect falsy boolean options in ProgressPlugin and ManifestPlugin (#20823)
The `||` operator used for default values incorrectly overrode user-provided falsy values like `modules: false` or `entries: false` with the truthy defaults. Use object spread for ProgressPlugin and explicit `!== undefined` check for ManifestPlugin to preserve user intent.
1 parent 3f5fe0d commit 5c43068

4 files changed

Lines changed: 33 additions & 13 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"webpack": patch
3+
---
4+
5+
Fix `||` default value handling in ProgressPlugin and ManifestPlugin that incorrectly overrode user-provided falsy values (e.g. `modules: false`, `entries: false`, `entrypoints: false`).

lib/ManifestPlugin.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ class ManifestPlugin {
7373
);
7474
});
7575

76-
const entrypoints = this.options.entrypoints || true;
76+
const entrypoints =
77+
this.options.entrypoints !== undefined ? this.options.entrypoints : true;
7778
const serialize =
7879
this.options.serialize ||
7980
((manifest) => JSON.stringify(manifest, null, 2));

lib/ProgressPlugin.js

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -175,18 +175,16 @@ class ProgressPlugin {
175175
/** @type {ProgressPluginOptions} */
176176
this.options = options;
177177

178-
this.profile = options.profile || DEFAULT_OPTIONS.profile;
179-
this.handler = options.handler;
180-
this.modulesCount = options.modulesCount || DEFAULT_OPTIONS.modulesCount;
181-
this.dependenciesCount =
182-
options.dependenciesCount || DEFAULT_OPTIONS.dependenciesCount;
183-
this.showEntries = options.entries || DEFAULT_OPTIONS.entries;
184-
this.showModules = options.modules || DEFAULT_OPTIONS.modules;
185-
this.showDependencies =
186-
options.dependencies || DEFAULT_OPTIONS.dependencies;
187-
this.showActiveModules =
188-
options.activeModules || DEFAULT_OPTIONS.activeModules;
189-
this.percentBy = options.percentBy || DEFAULT_OPTIONS.percentBy;
178+
const merged = { ...DEFAULT_OPTIONS, ...options };
179+
this.profile = merged.profile;
180+
this.handler = merged.handler;
181+
this.modulesCount = merged.modulesCount;
182+
this.dependenciesCount = merged.dependenciesCount;
183+
this.showEntries = merged.entries;
184+
this.showModules = merged.modules;
185+
this.showDependencies = merged.dependencies;
186+
this.showActiveModules = merged.activeModules;
187+
this.percentBy = merged.percentBy;
190188
}
191189

192190
/**

test/ProgressPlugin.test.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,22 @@ describe("ProgressPlugin", () => {
262262
});
263263
});
264264

265+
it("should respect falsy boolean options", () => {
266+
const plugin = new webpack.ProgressPlugin({
267+
modules: false,
268+
dependencies: false,
269+
entries: false,
270+
activeModules: false,
271+
profile: false
272+
});
273+
274+
expect(plugin.showModules).toBe(false);
275+
expect(plugin.showDependencies).toBe(false);
276+
expect(plugin.showEntries).toBe(false);
277+
expect(plugin.showActiveModules).toBe(false);
278+
expect(plugin.profile).toBe(false);
279+
});
280+
265281
it("should get the custom handler text from the log", () => {
266282
const compiler = createSimpleCompilerWithCustomHandler();
267283

0 commit comments

Comments
 (0)