Skip to content

Commit 80c1545

Browse files
committed
fix: don't attempt to run validate scripts if there are none to be run
1 parent 09cc0e4 commit 80c1545

File tree

3 files changed

+19
-9
lines changed

3 files changed

+19
-9
lines changed

src/scripts/__tests__/__snapshots__/validate.js.snap

+2
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,5 @@ exports[`validate does not include "lint" if it doesn't have that script 1`] = `
1313
exports[`validate does not include "test" if it doesn't have that script 1`] = `concurrently --kill-others-on-fail --prefix [{name}] --names build,lint,flow --prefix-colors bgBlue.bold.reset,bgGreen.bold.reset,bgMagenta.bold.reset "yarn run build" "yarn run lint" "yarn run flow"`;
1414

1515
exports[`validate doesn't use test or lint if it's in pre-commit 1`] = `concurrently --kill-others-on-fail --prefix [{name}] --names build,flow --prefix-colors bgBlue.bold.reset,bgGreen.bold.reset "yarn run build" "yarn run flow"`;
16+
17+
exports[`validate exits if there are no scripts to be run 1`] = ``;

src/scripts/__tests__/validate.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@ cases(
1616
try {
1717
// tests
1818
require('../validate')
19-
expect(crossSpawnSyncMock).toHaveBeenCalledTimes(1)
20-
const [firstCall] = crossSpawnSyncMock.mock.calls
21-
const [script, calledArgs] = firstCall
19+
const [crossSpawnFirstCall] = crossSpawnSyncMock.mock.calls
20+
const [script, calledArgs] = crossSpawnFirstCall || ['', []]
2221
expect([script, ...calledArgs].join(' ')).toMatchSnapshot()
2322
} catch (error) {
2423
throw error
@@ -58,6 +57,9 @@ cases(
5857
}
5958
}),
6059
},
60+
'exits if there are no scripts to be run': {
61+
setup: withDefaultSetup(setupWithScripts([])),
62+
},
6163
},
6264
)
6365

src/scripts/validate.js

+12-6
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,16 @@ const scripts = useDefaultScripts
2727
return scriptsToRun
2828
}, {})
2929

30-
const result = spawn.sync(
31-
resolveBin('concurrently'),
32-
getConcurrentlyArgs(scripts),
33-
{stdio: 'inherit'},
34-
)
30+
const scriptCount = Object.values(scripts).filter(Boolean).length
3531

36-
process.exit(result.status)
32+
if (scriptCount > 0) {
33+
const result = spawn.sync(
34+
resolveBin('concurrently'),
35+
getConcurrentlyArgs(scripts),
36+
{stdio: 'inherit'},
37+
)
38+
39+
process.exit(result.status)
40+
} else {
41+
process.exit(0)
42+
}

0 commit comments

Comments
 (0)