UNPKG

5.5 kBMarkdownView Raw
1| [index](../README.md) | [npm-run-all](npm-run-all.md) | [run-s](run-s.md) | run-p | [Node API](node-api.md) |
2|-----------------------|-------------------------------|-------------------|-------|-------------------------|
3
4# `run-p` command
5
6A CLI command to run given npm-scripts in parallel.
7This command is the shorthand of `npm-run-all -p`.
8
9```
10Usage:
11 $ run-p [--help | -h | --version | -v]
12 $ run-p [OPTIONS] <tasks>
13
14 Run given npm-scripts in parallel.
15
16 <tasks> : A list of npm-scripts' names and Glob-like patterns.
17
18Options:
19 -c, --continue-on-error - Set the flag to continue executing other tasks
20 even if a task threw an error. 'run-p' itself
21 will exit with non-zero code if one or more tasks
22 threw error(s).
23 --max-parallel <number> - Set the maximum number of parallelism. Default is
24 unlimited.
25 --aggregate-output - Avoid interleaving output by delaying printing of
26 each command's output until it has finished.
27 --npm-path <string> - - - Set the path to npm. Default is the value of
28 environment variable npm_execpath.
29 If the variable is not defined, then it's "npm."
30 In this case, the "npm" command must be found in
31 environment variable PATH.
32 -l, --print-label - - - - Set the flag to print the task name as a prefix
33 on each line of output. Tools in tasks may stop
34 coloring their output if this option was given.
35 -n, --print-name - - - - Set the flag to print the task name before
36 running each task.
37 -r, --race - - - - - - - Set the flag to kill all tasks when a task
38 finished with zero.
39 -s, --silent - - - - - - Set 'silent' to the log level of npm.
40
41 Shorthand aliases can be combined.
42 For example, '-clns' equals to '-c -l -n -s'.
43
44Examples:
45 $ run-p watch:**
46 $ run-p --print-label "build:** -- --watch"
47 $ run-p -l "build:** -- --watch"
48 $ run-p start-server start-browser start-electron
49```
50
51### npm-scripts
52
53It's `"scripts"` field of `package.json`.
54For example:
55
56```json
57{
58 "scripts": {
59 "clean": "rimraf dist",
60 "lint": "eslint src",
61 "build": "babel src -o lib"
62 }
63}
64```
65
66We can run a script with `npm run` command.
67On the other hand, this `run-p` command runs multiple scripts in parallel.
68
69The following 2 commands are similar.
70The `run-p` command is shorter and **available on Windows**.
71
72```
73$ run-p lint build
74$ npm run lint & npm run build
75```
76
77**Note1:** If a script exited with a non-zero code, the other scripts and those descendant processes are killed with `SIGTERM` (On Windows, with `taskkill.exe /F /T`).
78If `--continue-on-error` option is given, this behavior will be disabled.
79
80**Note2:** `&` operator does not work on Windows' `cmd.exe`. But `run-p` works fine there.
81
82### Glob-like pattern matching for script names
83
84We can use [glob]-like patterns to specify npm-scripts.
85The difference is one -- the separator is `:` instead of `/`.
86
87```
88$ run-p watch:*
89```
90
91In this case, runs sub scripts of `watch`. For example: `watch:html`, `watch:js`.
92But, doesn't run sub-sub scripts. For example: `watch:js:index`.
93
94```
95$ run-p watch:**
96```
97
98If we use a globstar `**`, runs both sub scripts and sub-sub scripts.
99
100`run-p` reads the actual npm-script list from `package.json` in the current directory, then filters the scripts by glob-like patterns, then runs those.
101
102### Run with arguments
103
104We can enclose a script name or a pattern in quotes to use arguments.
105The following 2 commands are similar.
106
107```
108$ run-p "build:* -- --watch"
109$ npm run build:aaa -- --watch & npm run build:bbb -- --watch
110```
111
112When we use a pattern, arguments are forwarded to every matched script.
113
114### Argument placeholders
115
116We can use placeholders to give the arguments preceded by `--` to scripts.
117
118```
119$ run-p "start-server -- --port {1}" -- 8080
120```
121
122This is useful to pass through arguments from `npm run` command.
123
124```json
125{
126 "scripts": {
127 "start": "run-p \"start-server -- --port {1}\" --"
128 }
129}
130```
131
132```
133$ npm run start 8080
134
135> example@0.0.0 start /path/to/package.json
136> run-p "start-server -- --port {1}" -- "8080"
137```
138
139There are the following placeholders:
140
141- `{1}`, `{2}`, ... -- An argument. `{1}` is the 1st argument. `{2}` is the 2nd.
142- `{@}` -- All arguments.
143- `{*}` -- All arguments as combined.
144
145Those are similar to [Shell Parameters](http://www.gnu.org/software/bash/manual/bashref.html#Shell-Parameters). But please note arguments are enclosed by double quotes automatically (similar to npm).
146
147### Known Limitations
148
149- If `--print-label` option is given, some tools in scripts might stop coloring their output.
150 Because some coloring library (e.g. [chalk]) will stop coloring if `process.stdout` is not a TTY.
151 `run-p` changes the `process.stdout` of child processes to a pipe in order to add labels to the head of each line if `--print-label` option is given.<br>
152 For example, [eslint] stops coloring under `run-p --print-label`. But [eslint] has `--color` option to force coloring, we can use it.
153
154[glob]: https://www.npmjs.com/package/glob#glob-primer
155[chalk]: https://www.npmjs.com/package/chalk
156[eslint]: https://www.npmjs.com/package/eslint