Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't mutate stats configuration (webpack 3.8.0+ compatibility) #1174

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion bin/webpack-dev-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,9 @@ function processOptions(webpackOptions) {
};
}

if (typeof options.stats === 'object' && typeof options.stats.colors === 'undefined') { options.stats.colors = argv.color; }
if (typeof options.stats === 'object' && typeof options.stats.colors === 'undefined') {
options.stats = Object.assign({}, options.stats, { colors: argv.color });
Copy link
Contributor

@shellscape shellscape Nov 3, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I may be having a brain fart here, so please correct me if I'm wrong. this doesn't look like it'll avoid mutating the stats property. there's a larger issue here (which is resolved in the v3 beta branch) of the options passed being mutated on the whole:

var a = { stats: {} };

function doit (o) {
  o.stats = Object.assign({}, a.stats, { color: '0' });
}

doit(a);
a;

// returns
// {stats: {…}}
//   stats: {color: "0"}
//   __proto__: Object

I could be missing something, but I think the solution is to prevent the top level options object passed to devServer from being mutated.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, but it's the stats property value that shouldn't be mutated.

var stats = {};
var a = { stats: stats };

function doit (o) {
  o.stats = Object.assign({}, a.stats, { color: '0' });
}

doit(a);
stats;

// {}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, I see. Hadn't considered that case. Could you put a simple test for this in /test?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sadly I cannot write a good test case because when running test/cli.test.js, the package supports-color detect that it doesn't run in a tty, so it returns false (which webpack sees as valid).

}

if (argv.lazy) { options.lazy = true; }

Expand Down