Skip to content

Commit 693261b

Browse files
committed
Fix: missing --aggregate-output in npm-run-all
1 parent 096779b commit 693261b

File tree

9 files changed

+67
-25
lines changed

9 files changed

+67
-25
lines changed

bin/common/parse-cli-args.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,11 @@ function parseCLIArgsCore(set, args) { // eslint-disable-line complexity
221221
}
222222
}
223223

224+
if (!set.parallel && set.aggregateOutput) {
225+
throw new Error("Invalid Option: --aggregate-output (without parallel)")
226+
}
224227
if (!set.parallel && set.race) {
225-
const race = args.indexOf("--race") !== -1 ? "race" : "r"
228+
const race = args.indexOf("--race") !== -1 ? "--race" : "-r"
226229
throw new Error(`Invalid Option: ${race} (without parallel)`)
227230
}
228231
if (!set.parallel && set.maxParallel !== 0) {

bin/npm-run-all/help.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ Usage:
2727
<tasks> : A list of npm-scripts' names and Glob-like patterns.
2828
2929
Options:
30+
--aggregate-output - - - Avoid interleaving output by delaying printing of
31+
each command's output until it has finished.
3032
-c, --continue-on-error - Set the flag to continue executing
3133
other/subsequent tasks even if a task threw an
3234
error. 'npm-run-all' itself will exit with

bin/npm-run-all/main.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ module.exports = function npmRunAll(args, stdout, stderr) {
5252
arguments: argv.rest,
5353
race: group.parallel && argv.race,
5454
npmPath: argv.npmPath,
55+
aggregateOutput: group.parallel && argv.aggregateOutput,
5556
}
5657
))
5758
},

bin/run-p/help.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@ Usage:
2727
<tasks> : A list of npm-scripts' names and Glob-like patterns.
2828
2929
Options:
30+
--aggregate-output - - - Avoid interleaving output by delaying printing of
31+
each command's output until it has finished.
3032
-c, --continue-on-error - Set the flag to continue executing other tasks
3133
even if a task threw an error. 'run-p' itself
3234
will exit with non-zero code if one or more tasks
3335
threw error(s).
3436
--max-parallel <number> - Set the maximum number of parallelism. Default is
3537
unlimited.
36-
--aggregate-output - Avoid interleaving output by delaying printing of
37-
each command's output until it has finished.
3838
--npm-path <string> - - - Set the path to npm. Default is the value of
3939
environment variable npm_execpath.
4040
If the variable is not defined, then it's "npm."

docs/node-api.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ Run npm-scripts.
3535

3636
- **patterns** `string|string[]` -- Glob-like patterns for script names.
3737
- **options** `object`
38+
- **options.aggregateOutput** `boolean` --
39+
The flag to avoid interleaving output by delaying printing of each command's output until it has finished.
40+
This option is valid only with `options.parallel` option.
41+
Default is `false`.
3842
- **options.arguments** `string[]` --
3943
An argument list to replace argument placeholders (such as `{1}`, `{2}`). If pattern text has `{1}`, it's replaced by `options.arguments[0]`.
4044
Default is an empty array.
@@ -47,6 +51,7 @@ Run npm-scripts.
4751
Default is `false`.
4852
- **options.maxParallel** `number` --
4953
The maximum number of parallelism.
54+
This option is valid only with `options.parallel` option.
5055
Default is `Number.POSITIVE_INFINITY`.
5156
- **options.npmPath** `string` --
5257
The path to npm.

docs/npm-run-all.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ Usage:
1313
<tasks> : A list of npm-scripts' names and Glob-like patterns.
1414
1515
Options:
16+
--aggregate-output - - - Avoid interleaving output by delaying printing of
17+
each command's output until it has finished.
1618
-c, --continue-on-error - Set the flag to continue executing
1719
other/subsequent tasks even if a task threw an
1820
error. 'npm-run-all' itself will exit with

docs/run-p.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ Usage:
1616
<tasks> : A list of npm-scripts' names and Glob-like patterns.
1717
1818
Options:
19+
--aggregate-output - - - Avoid interleaving output by delaying printing of
20+
each command's output until it has finished.
1921
-c, --continue-on-error - Set the flag to continue executing other tasks
2022
even if a task threw an error. 'run-p' itself
2123
will exit with non-zero code if one or more tasks
2224
threw error(s).
2325
--max-parallel <number> - Set the maximum number of parallelism. Default is
2426
unlimited.
25-
--aggregate-output - Avoid interleaving output by delaying printing of
26-
each command's output until it has finished.
2727
--npm-path <string> - - - Set the path to npm. Default is the value of
2828
environment variable npm_execpath.
2929
If the variable is not defined, then it's "npm."

lib/index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,11 @@ module.exports = function npmRunAll(patternOrPatterns, options) { //eslint-disab
236236
if (typeof maxParallel !== "number" || !(maxParallel >= 0)) {
237237
throw new Error("Invalid options.maxParallel")
238238
}
239+
if (!parallel && aggregateOutput) {
240+
throw new Error("Invalid options.aggregateOutput; It requires options.parallel")
241+
}
239242
if (!parallel && race) {
240-
throw new Error("Invalid options.race")
243+
throw new Error("Invalid options.race; It requires options.parallel")
241244
}
242245

243246
const prefixOptions = [].concat(

test/aggregate-output.js

Lines changed: 45 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,11 @@ describe("[aggregated-output] npm-run-all", () => {
3636
}
3737

3838
describe("should not intermingle output of various commands", () => {
39-
const EXPECTED_SERIALIZED_TEXT = [
40-
createExpectedOutput("first"),
41-
createExpectedOutput("second"),
42-
`${createExpectedOutput("third")}\n`,
43-
].join("\n")
44-
4539
const EXPECTED_PARALLELIZED_TEXT = [
4640
createExpectedOutput("second"),
4741
createExpectedOutput("third"),
48-
`${createExpectedOutput("first")}\n`,
42+
createExpectedOutput("first"),
43+
"",
4944
].join("\n")
5045

5146
let stdout = null
@@ -54,28 +49,59 @@ describe("[aggregated-output] npm-run-all", () => {
5449
stdout = new BufferStream()
5550
})
5651

57-
it("Node API", async () => {
52+
it("Node API with parallel", async () => {
5853
await nodeApi(
5954
["test-task:delayed first 300", "test-task:delayed second 100", "test-task:delayed third 200"],
60-
{ stdout, silent: true, aggregateOutput: true }
55+
{ stdout, parallel: true, silent: true, aggregateOutput: true }
6156
)
62-
assert.equal(stdout.value, EXPECTED_SERIALIZED_TEXT)
57+
assert.equal(stdout.value, EXPECTED_PARALLELIZED_TEXT)
6358
})
6459

65-
it("npm-run-all command", async () => {
60+
it("Node API without parallel should fail", async () => {
61+
try {
62+
await nodeApi(
63+
["test-task:delayed first 300", "test-task:delayed second 100", "test-task:delayed third 200"],
64+
{ stdout, silent: true, aggregateOutput: true }
65+
)
66+
}
67+
catch (_err) {
68+
return
69+
}
70+
assert(false, "should fail")
71+
})
72+
73+
it("npm-run-all command with parallel", async () => {
6674
await runAll(
67-
["test-task:delayed first 300", "test-task:delayed second 100", "test-task:delayed third 200", "--silent", "--aggregate-output"],
75+
["--parallel", "test-task:delayed first 300", "test-task:delayed second 100", "test-task:delayed third 200", "--silent", "--aggregate-output"],
6876
stdout
6977
)
70-
assert.equal(stdout.value, EXPECTED_SERIALIZED_TEXT)
78+
assert.equal(stdout.value, EXPECTED_PARALLELIZED_TEXT)
7179
})
7280

73-
it("run-s command", async () => {
74-
await runSeq(
75-
["test-task:delayed first 300", "test-task:delayed second 100", "test-task:delayed third 200", "--silent", "--aggregate-output"],
76-
stdout
77-
)
78-
assert.equal(stdout.value, EXPECTED_SERIALIZED_TEXT)
81+
it("npm-run-all command without parallel should fail", async () => {
82+
try {
83+
await runAll(
84+
["test-task:delayed first 300", "test-task:delayed second 100", "test-task:delayed third 200", "--silent", "--aggregate-output"],
85+
stdout
86+
)
87+
}
88+
catch (_err) {
89+
return
90+
}
91+
assert(false, "should fail")
92+
})
93+
94+
it("run-s command should fail", async () => {
95+
try {
96+
await runSeq(
97+
["test-task:delayed first 300", "test-task:delayed second 100", "test-task:delayed third 200", "--silent", "--aggregate-output"],
98+
stdout
99+
)
100+
}
101+
catch (_err) {
102+
return
103+
}
104+
assert(false, "should fail")
79105
})
80106

81107
it("run-p command", async () => {

0 commit comments

Comments
 (0)