Skip to content

Commit 6967a66

Browse files
michael-wolfendenKent C. Dodds
authored andcommitted
fix(cli): the --all-scripts flag should skip scripts that don't call the webpack cli (#115)
* fix(cli): the --all-scripts flag should skip scripts that don't call the webpack cli 111 * Replaced `includes` with `indexOf` * Remove duplicate test script
1 parent a1e801f commit 6967a66

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed

src/bin/script-parsers.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
export function webpackConfig(script) {
2+
const callsWebpackCli = script.split(' ').indexOf('webpack') !== -1
3+
if (!callsWebpackCli) return undefined
4+
25
// Try to parse webpack config name. Not fool proof. Maybe
36
// there's a neater way.
47
const parts = script.split('--config')

src/bin/script-parsers.test.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,46 @@ describe('webpack config name parser', () => {
1212
webpackConfig('webpack --profile --json > stats.json') === 'webpack.config.js'
1313
)
1414
})
15+
16+
it('should return undefined when script does not call the webpack cli', () => {
17+
const sciptsThatDoNotCallWebpackCli = [
18+
'karma start',
19+
'istanbul check-coverage --statements 23 --branches 5 --functions 9 --lines 24',
20+
'npm test -- --auto-watch --no-single-run',
21+
'npm-run-all --parallel validate-webpack:* lint test --serial check-coverage',
22+
'webpack-validator webpack.config.js --env.dev',
23+
'webpack-validator webpack.config.js --env.prod',
24+
'rimraf dist',
25+
'cpy src/index.html src/favicon.ico dist',
26+
'npm run clean-dist && npm run copy-files',
27+
'npm run clean-and-copy',
28+
'webpack-dev-server --env.dev --content-base dist',
29+
'npm run clean-and-copy',
30+
'eslint .',
31+
'npm install && npm run validate',
32+
]
33+
34+
sciptsThatDoNotCallWebpackCli.forEach(script => {
35+
assert(
36+
webpackConfig(script) === undefined
37+
)
38+
})
39+
})
40+
41+
it('should not return undefined when script calls the webpack cli', () => {
42+
const scriptsThatCallWebpacCli = [
43+
'webpack --env.dev',
44+
'webpack --env.prod -p',
45+
'NODE_ENV=development webpack --config demo.js',
46+
'webpack --profile --json > stats.json',
47+
]
48+
49+
scriptsThatCallWebpacCli.forEach(script => {
50+
assert(
51+
webpackConfig(script) !== undefined
52+
)
53+
})
54+
})
1555
})
1656

1757
describe('node env parser', () => {

src/bin/validate-all-scripts.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ module.exports = function validateAllScripts(scripts, quiet) {
66
const script = scripts[name]
77
const webpackConfigFile = parse.webpackConfig(script)
88

9+
if (webpackConfigFile === undefined) return
10+
911
if (script.indexOf('SET NODE_ENV=') === 0 || script.indexOf('NODE_ENV=') === 0) {
1012
process.env.node_env = parse.nodeEnv(script)
1113
} else {

0 commit comments

Comments
 (0)