Skip to content

Do not mutate the config object #1124

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

Closed
2 of 3 tasks
dwjft opened this issue Sep 28, 2017 · 4 comments
Closed
2 of 3 tasks

Do not mutate the config object #1124

dwjft opened this issue Sep 28, 2017 · 4 comments

Comments

@dwjft
Copy link

dwjft commented Sep 28, 2017

  • Operating System: OS X
  • Node Version: 8.6
  • NPM Version: 5.4.2
  • webpack Version: 2.5.1
  • webpack-dev-server Version: 2.9.1
  • This is a bug
  • This is a feature request
  • This is a modification request

Code

let server;
const devServerConfig = {};
const startServer = () => {
  if (server) { server.close(); }
  // webpack plugin code, calls `startServer` on error
  server = new WebpackDevServer(compiler, devServerConfig);
  server.listen(8080);
};
startServer();
  // Server.js, line 33. this is the thrown error
  const validationErrors = webpack.validateSchema(optionsSchema, options);
  if (validationErrors.length) {
    throw new OptionsValidationError(validationErrors);
  }

Expected Behavior

  • When I start a webpack-dev-server, it should validate the options passed through correctly.
  • When I start a new webpack-dev-server, it should validate the options passed through correctly.

Actual Behavior

  • When I start a webpack-dev-server for the first time, the devServerConfig is mutated with a bunch of extra fields populated by the dev server itself.
  • When I try to start a new webpack-dev-server, the config object does not pass validation on line 33 of Server.js because it mutated the config object.

For Bugs; How can we reproduce the behavior?

See the code snippets.

For Features; What is the motivation and/or use-case for the feature?

@shellscape
Copy link
Contributor

@dwjft please provide the structure of your options before and after the first run, only then will we know what to look for specifically.

@dwjft
Copy link
Author

dwjft commented Sep 28, 2017

I mean, you can figure that out by just reading the snippet of code.

const config = {};
new WebpackDevServer(compiler, config);
console.log(config);
/**
 * output: 
 * config: {
    reportTime: false,
    reporter: [Function: defaultReporter],
    log: [Function: bound bound consoleCall],
    warn: [Function: bound bound consoleCall],
    error: [Function: bound bound consoleCall] }
*/

@shellscape
Copy link
Contributor

@dwjft as reporter you should provide all available info. thanks for the paste, we'll look into what's modifying that and see what we can put in place.

@shellscape
Copy link
Contributor

This is going to land in the beta branch in the next week or so, and has been implemented in the refactor-lib branch that is currently WIP. If someone steps up to fix this in the 2.9.x branch, we'll happily review a PR, but our energies right now are being directed towards getting 3.0.0@beta out the door.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants