Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 19 additions & 11 deletions packages/webpack-cli/src/webpack-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2237,6 +2237,10 @@ class WebpackCLI implements IWebpackCLI {
}

// Output warnings
if (!Object.isExtensible(item)) {
return;
}

if (
options.isWatchingLikeCommand &&
options.argv &&
Expand All @@ -2263,7 +2267,7 @@ class WebpackCLI implements IWebpackCLI {
};

// Setup default cache options
if (isFileSystemCacheOptions(item)) {
if (isFileSystemCacheOptions(item) && Object.isExtensible(item.cache)) {
const configPath = config.path.get(item);

if (configPath) {
Expand Down Expand Up @@ -2321,22 +2325,26 @@ class WebpackCLI implements IWebpackCLI {
colors = Boolean(this.colors.isColorSupported);
}

item.stats.colors = colors;
if (Object.isExtensible(item.stats)) {
item.stats.colors = colors;
}

// Apply CLI plugin
if (!item.plugins) {
item.plugins = [];
}

item.plugins.unshift(
new CLIPlugin({
configPath: config.path.get(item),
helpfulOutput: !options.json,
progress: options.progress,
analyze: options.analyze,
isMultiCompiler: Array.isArray(config.options),
}),
);
if (Object.isExtensible(item.plugins)) {
item.plugins.unshift(
new CLIPlugin({
configPath: config.path.get(item),
helpfulOutput: !options.json,
progress: options.progress,
analyze: options.analyze,
isMultiCompiler: Array.isArray(config.options),
}),
);
}
};

if (Array.isArray(config.options)) {
Expand Down
16 changes: 16 additions & 0 deletions test/build/config/object-freeze-partial/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"use strict";
const { resolve } = require("path");
const { run } = require("../../../utils/test-utils");

describe("config with partial `Object.freeze({})`", () => {
it("should not throw error", async () => {
const { exitCode, stderr, stdout } = await run(__dirname, [
"-c",
resolve(__dirname, "webpack.config.js"),
]);

expect(exitCode).toBe(0);
expect(stderr).toBeFalsy();
expect(stdout).toBeTruthy();
});
});
1 change: 1 addition & 0 deletions test/build/config/object-freeze-partial/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log("Percy Weasley");
5 changes: 5 additions & 0 deletions test/build/config/object-freeze-partial/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
cache: Object.freeze({ type: "filesystem" }),
stats: Object.freeze({}),
plugins: Object.freeze([]),
};
16 changes: 16 additions & 0 deletions test/build/config/object-freeze/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"use strict";
const { resolve } = require("path");
const { run } = require("../../../utils/test-utils");

describe("config with `Object.freeze({})`", () => {
it("should not throw error", async () => {
const { exitCode, stderr, stdout } = await run(__dirname, [
"-c",
resolve(__dirname, "webpack.config.js"),
]);

expect(exitCode).toBe(0);
expect(stderr).toBeFalsy();
expect(stdout).toBeTruthy();
});
});
1 change: 1 addition & 0 deletions test/build/config/object-freeze/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log("Percy Weasley");
1 change: 1 addition & 0 deletions test/build/config/object-freeze/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = Object.freeze({});