Skip to content

Commit 978e9f9

Browse files
authored
Merge pull request webpack#5635 from webpack/bugfix/clone-options
clone options and don't modify them
2 parents a4cf91f + 5020104 commit 978e9f9

5 files changed

Lines changed: 29 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: 19 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,13 @@ 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 => {
72+
if(typeof value === "boolean") {
73+
return value;
74+
} else {
75+
return Object.assign({}, value);
76+
}
77+
});
7278
this.set("node.console", false);
7379
this.set("node.process", true);
7480
this.set("node.global", true);
@@ -77,11 +83,18 @@ class WebpackOptionsDefaulter extends OptionsDefaulter {
7783
this.set("node.__filename", "mock");
7884
this.set("node.__dirname", "mock");
7985

86+
this.set("performance", "call", value => {
87+
if(typeof value === "boolean") {
88+
return value;
89+
} else {
90+
return Object.assign({}, value);
91+
}
92+
});
8093
this.set("performance.maxAssetSize", 250000);
8194
this.set("performance.maxEntrypointSize", 250000);
8295
this.set("performance.hints", false);
8396

84-
this.set("resolve", {});
97+
this.set("resolve", "call", value => Object.assign({}, value));
8598
this.set("resolve.unsafeCache", true);
8699
this.set("resolve.modules", ["node_modules"]);
87100
this.set("resolve.extensions", [".js", ".json"]);
@@ -101,7 +114,8 @@ class WebpackOptionsDefaulter extends OptionsDefaulter {
101114
this.set("resolve.cacheWithContext", "make", (options) => {
102115
return Array.isArray(options.resolve.plugins) && options.resolve.plugins.length > 0;
103116
});
104-
this.set("resolveLoader", {});
117+
118+
this.set("resolveLoader", "call", value => Object.assign({}, value));
105119
this.set("resolveLoader.unsafeCache", true);
106120
this.set("resolveLoader.mainFields", ["loader", "main"]);
107121
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)