js-dxtools / webpack-validator

Validates your webpack config with Joi
MIT License
295 stars 29 forks source link

Expected behaviour of --all-scripts flag #111

Closed michael-wolfenden closed 8 years ago

michael-wolfenden commented 8 years ago

Issue

Given the following:

  "scripts": {
    "development": "webpack --config config/webpack.config.development.js",
    "production": "webpack --config config/webpack.config.production.js",
    "validate": "webpack-validator --all-scripts"
  }

Running:

> npm run validate

Produces the following error:


Validating development
Reading: config/webpack.config.development.js
[webpack-validator] Config is valid.
[webpack-validator] Config is valid.
development is valid

Validating production
Reading: config/webpack.config.production.js
[webpack-validator] Config is valid.
[webpack-validator] Config is valid.
production is valid

Validating validate
Reading: webpack.config.js
module.js:442
    throw err;
    ^

Error: Cannot find module 'D:\Dev\webpack-2-spike\webpack.config.js'

Expected

I expected webpack-validator to only execute against the development and production scripts as they have the --config flag.

Investigation

The issue is that it also parses the validate script, which doesn't have a --config flag and in this case, the code defaults to webpack.config.js which doesn't exist.

See https://github.com/js-dxtools/webpack-validator/blob/b52bf8c298c7da0c9bb4ff493752f1ce29c23bda/src/bin/script-parsers.js#L11

Question

Is this the expected behavior, or should we ignore scripts that don't point to config files?

bebraw commented 8 years ago

It definitely should skip validate script. The check for webpack is likely too loose.

michael-wolfenden commented 8 years ago

Happy to send a PR, should we only take into account scripts with the --config flag?

kentcdodds commented 8 years ago

should we only take into account scripts with the --config flag?

Probably not.

michael-wolfenden commented 8 years ago

Skip scripts that don't call webpack?