Skip to content

Commit aa6774a

Browse files
authored
fix: prevent sorting when npm-run-all2 is used (#361)
Add support for npm-run-all2 to prevent script sorting when sequential wildcard execution is needed. Closes #359
1 parent 27e4b7b commit aa6774a

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

index.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,13 +223,16 @@ const hasDevDependency = (dependency, packageJson) => {
223223
}
224224

225225
const runSRegExp =
226-
/(?<=^|[\s&;<>|(])(?:run-s|npm-run-all .*(?:--sequential|--serial|-s))(?=$|[\s&;<>|)])/
226+
/(?<=^|[\s&;<>|(])(?:run-s|npm-run-all2? .*(?:--sequential|--serial|-s))(?=$|[\s&;<>|)])/
227227

228228
const isSequentialScript = (command) =>
229229
command.includes('*') && runSRegExp.test(command)
230230

231231
const hasSequentialScript = (packageJson) => {
232-
if (!hasDevDependency('npm-run-all', packageJson)) {
232+
if (
233+
!hasDevDependency('npm-run-all', packageJson) &&
234+
!hasDevDependency('npm-run-all2', packageJson)
235+
) {
233236
return false
234237
}
235238
const scripts = ['scripts', 'betterScripts'].flatMap((field) =>

tests/scripts.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,15 @@ function sortScriptsWithNpmRunAll(script) {
6767

6868
return Object.keys(sortPackageJson(packageJson).scripts)
6969
}
70+
function sortScriptsWithNpmRunAll2(script) {
71+
const packageJson = {
72+
scripts: { z: 'z', a: 'a', maybeRunS: script },
73+
devDependencies: { 'npm-run-all2': '^1.0.0' },
74+
}
75+
76+
return Object.keys(sortPackageJson(packageJson).scripts)
77+
}
78+
7079
const sortedScripts = ['a', 'maybeRunS', 'z']
7180
const unsortedScripts = ['z', 'a', 'maybeRunS']
7281
for (const { script, expected } of [
@@ -108,6 +117,10 @@ for (const { script, expected } of [
108117
test(`command: '${script}'`, (t) => {
109118
t.deepEqual(sortScriptsWithNpmRunAll(script), expected)
110119
})
120+
121+
test(`command: '${script}' with npm-run-all2`, (t) => {
122+
t.deepEqual(sortScriptsWithNpmRunAll2(script), expected)
123+
})
111124
}
112125

113126
for (const field of ['scripts', 'betterScripts']) {
@@ -127,6 +140,16 @@ for (const field of ['scripts', 'betterScripts']) {
127140
})
128141
}
129142

143+
// npm-run-all2
144+
for (const { script, expected } of [
145+
// Should NOT sort
146+
{ script: 'npm-run-all2 -s "lint:*"', expected: unsortedScripts },
147+
]) {
148+
test(`command: '${script}' with npm-run-all2`, (t) => {
149+
t.deepEqual(sortScriptsWithNpmRunAll2(script), expected)
150+
})
151+
}
152+
130153
for (const field of ['scripts', 'betterScripts']) {
131154
test(
132155
`${field} does not sort pre/post scripts with colon together`,

0 commit comments

Comments
 (0)