Skip to content

Commit f04cce8

Browse files
committed
clone options and don't modify them
fixes webpack#5628
1 parent fb8afe7 commit f04cce8

5 files changed

Lines changed: 17 additions & 5 deletions

File tree

‎lib/OptionsDefaulter.js‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class OptionsDefaulter {
3030
}
3131

3232
process(options) {
33+
// TODO: change this for webpack 4: options = Object.assign({}, options);
3334
for(let name in this.defaults) {
3435
switch(this.config[name]) {
3536
case undefined:
@@ -55,6 +56,7 @@ class OptionsDefaulter {
5556
throw new Error("OptionsDefaulter cannot process " + this.config[name]);
5657
}
5758
}
59+
// TODO: change this for webpack 4: return options;
5860
}
5961

6062
set(name, config, def) {

‎lib/WebpackOptionsDefaulter.js‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class WebpackOptionsDefaulter extends OptionsDefaulter {
1616
this.set("context", process.cwd());
1717
this.set("target", "web");
1818

19+
this.set("module", "call", value => Object.assign({}, value));
1920
this.set("module.unknownContextRequest", ".");
2021
this.set("module.unknownContextRegExp", false);
2122
this.set("module.unknownContextRecursive", true);
@@ -29,7 +30,6 @@ class WebpackOptionsDefaulter extends OptionsDefaulter {
2930
this.set("module.wrappedContextCritical", false);
3031
this.set("module.strictExportPresence", false);
3132
this.set("module.strictThisContextOnImports", false);
32-
3333
this.set("module.unsafeCache", true);
3434

3535
this.set("output", "call", (value, options) => {
@@ -40,7 +40,7 @@ class WebpackOptionsDefaulter extends OptionsDefaulter {
4040
} else if(typeof value !== "object") {
4141
return {};
4242
} else {
43-
return value;
43+
return Object.assign({}, value);
4444
}
4545
});
4646
this.set("output.filename", "[name].js");
@@ -68,7 +68,7 @@ class WebpackOptionsDefaulter extends OptionsDefaulter {
6868
this.set("output.devtoolLineToLine", false);
6969
this.set("output.strictModuleExceptionHandling", false);
7070

71-
this.set("node", {});
71+
this.set("node", "call", value => Object.assign({}, value));
7272
this.set("node.console", false);
7373
this.set("node.process", true);
7474
this.set("node.global", true);
@@ -77,11 +77,12 @@ class WebpackOptionsDefaulter extends OptionsDefaulter {
7777
this.set("node.__filename", "mock");
7878
this.set("node.__dirname", "mock");
7979

80+
this.set("performance", "call", value => Object.assign({}, value));
8081
this.set("performance.maxAssetSize", 250000);
8182
this.set("performance.maxEntrypointSize", 250000);
8283
this.set("performance.hints", false);
8384

84-
this.set("resolve", {});
85+
this.set("resolve", "call", value => Object.assign({}, value));
8586
this.set("resolve.unsafeCache", true);
8687
this.set("resolve.modules", ["node_modules"]);
8788
this.set("resolve.extensions", [".js", ".json"]);
@@ -101,7 +102,8 @@ class WebpackOptionsDefaulter extends OptionsDefaulter {
101102
this.set("resolve.cacheWithContext", "make", (options) => {
102103
return Array.isArray(options.resolve.plugins) && options.resolve.plugins.length > 0;
103104
});
104-
this.set("resolveLoader", {});
105+
106+
this.set("resolveLoader", "call", value => Object.assign({}, value));
105107
this.set("resolveLoader.unsafeCache", true);
106108
this.set("resolveLoader.mainFields", ["loader", "main"]);
107109
this.set("resolveLoader.extensions", [".js", ".json"]);

‎lib/webpack.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ function webpack(options, callback) {
2222
if(Array.isArray(options)) {
2323
compiler = new MultiCompiler(options.map(options => webpack(options)));
2424
} else if(typeof options === "object") {
25+
// TODO webpack 4: process returns options
2526
new WebpackOptionsDefaulter().process(options);
2627

2728
compiler = new Compiler();
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
it("should compile and run the test", function() {
2+
3+
});
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module.exports = {
2+
resolve: Object.freeze({})
3+
// this fails to compile when the object is not cloned
4+
};

0 commit comments

Comments
 (0)