in-parallel-lit 0.1.2 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +99 -1
- package/package.json +9 -1
- package/src/bin.js +8 -3
- package/src/index.js +10 -4
package/README.md
CHANGED
|
@@ -17,7 +17,7 @@ $ yarn global add in-parallel-lit
|
|
|
17
17
|
## Usage
|
|
18
18
|
|
|
19
19
|
```bash
|
|
20
|
-
$
|
|
20
|
+
$ in-parallel "ping google.com -c 3" "ping 127.0.0.1 -c 3"
|
|
21
21
|
|
|
22
22
|
# Prints:
|
|
23
23
|
# -------
|
|
@@ -39,6 +39,104 @@ $ npx in-parallel "ping google.com -c 3" "ping 127.0.0.1 -c 3"
|
|
|
39
39
|
# [ping google.com -c 3] round-trip min/avg/max/stddev = 29.115/36.574/50.207/9.654 ms
|
|
40
40
|
```
|
|
41
41
|
|
|
42
|
+
## Options
|
|
43
|
+
|
|
44
|
+
### `-n, --names`
|
|
45
|
+
|
|
46
|
+
List of custom names to be used in prefix template.
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
$ in-parallel -n "google,localhost" "ping google.com -c 2" "ping 127.0.0.1 -c 2"
|
|
50
|
+
|
|
51
|
+
# Prints:
|
|
52
|
+
# -------
|
|
53
|
+
# [localhost] PING 127.0.0.1 (127.0.0.1): 56 data bytes
|
|
54
|
+
# [localhost] 64 bytes from 127.0.0.1: icmp_seq=0 ttl=64 time=0.051 ms
|
|
55
|
+
# [google] PING google.com (142.250.186.46): 56 data bytes
|
|
56
|
+
# [google] 64 bytes from 142.250.186.46: icmp_seq=0 ttl=56 time=18.726 ms
|
|
57
|
+
# [localhost] 64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.205 ms
|
|
58
|
+
# [localhost]
|
|
59
|
+
# [localhost] --- 127.0.0.1 ping statistics ---
|
|
60
|
+
# [localhost] 2 packets transmitted, 2 packets received, 0.0% packet loss
|
|
61
|
+
# [localhost] round-trip min/avg/max/stddev = 0.051/0.128/0.205/0.077 ms
|
|
62
|
+
# [google] 64 bytes from 142.250.186.46: icmp_seq=1 ttl=56 time=18.386 ms
|
|
63
|
+
# [google]
|
|
64
|
+
# [google] --- google.com ping statistics ---
|
|
65
|
+
# [google] 2 packets transmitted, 2 packets received, 0.0% packet loss
|
|
66
|
+
# [google] round-trip min/avg/max/stddev = 18.386/18.556/18.726/0.170 ms
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### `-c, --continue-on-error`
|
|
70
|
+
|
|
71
|
+
Set the flag to continue executing other/subsequent tasks even if a task threw
|
|
72
|
+
an error. `in-parallel` itself will exit with non-zero code if one or more
|
|
73
|
+
tasks threw error(s).
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
$ in-parallel -c "<command that fails>" "ping 127.0.0.1 -c 2"
|
|
77
|
+
|
|
78
|
+
# Prints:
|
|
79
|
+
# -------
|
|
80
|
+
# [ping 127.0.0.1 -c 2] PING 127.0.0.1 (127.0.0.1): 56 data bytes
|
|
81
|
+
# [ping 127.0.0.1 -c 2] 64 bytes from 127.0.0.1: icmp_seq=0 ttl=64 time=0.054 ms
|
|
82
|
+
# [ping 127.0.0.1 -c 2] 64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.201 ms
|
|
83
|
+
# [ping 127.0.0.1 -c 2]
|
|
84
|
+
# [ping 127.0.0.1 -c 2] --- 127.0.0.1 ping statistics ---
|
|
85
|
+
# [ping 127.0.0.1 -c 2] 2 packets transmitted, 2 packets received, 0.0% packet loss
|
|
86
|
+
# [ping 127.0.0.1 -c 2] round-trip min/avg/max/stddev = 0.054/0.128/0.201/0.074 ms
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### `--max-parallel`
|
|
90
|
+
|
|
91
|
+
Set the maximum number of parallelism. Default is unlimited (`0`).
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
$ in-parallel --max-parallel 1 "ping google.com -c 2" "ping 127.0.0.1 -c 2"
|
|
95
|
+
|
|
96
|
+
# Prints:
|
|
97
|
+
# -------
|
|
98
|
+
# [ping google.com -c 2] PING google.com (142.250.186.46): 56 data bytes
|
|
99
|
+
# [ping google.com -c 2] 64 bytes from 142.250.186.46: icmp_seq=0 ttl=56 time=19.455 ms
|
|
100
|
+
# [ping google.com -c 2] 64 bytes from 142.250.186.46: icmp_seq=1 ttl=56 time=18.799 ms
|
|
101
|
+
# [ping google.com -c 2]
|
|
102
|
+
# [ping google.com -c 2] --- google.com ping statistics ---
|
|
103
|
+
# [ping google.com -c 2] 2 packets transmitted, 2 packets received, 0.0% packet loss
|
|
104
|
+
# [ping google.com -c 2] round-trip min/avg/max/stddev = 18.799/19.127/19.455/0.328 ms
|
|
105
|
+
# [ping 127.0.0.1 -c 2] PING 127.0.0.1 (127.0.0.1): 56 data bytes
|
|
106
|
+
# [ping 127.0.0.1 -c 2] 64 bytes from 127.0.0.1: icmp_seq=0 ttl=64 time=0.050 ms
|
|
107
|
+
# [ping 127.0.0.1 -c 2] 64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.120 ms
|
|
108
|
+
# [ping 127.0.0.1 -c 2]
|
|
109
|
+
# [ping 127.0.0.1 -c 2] --- 127.0.0.1 ping statistics ---
|
|
110
|
+
# [ping 127.0.0.1 -c 2] 2 packets transmitted, 2 packets received, 0.0% packet loss
|
|
111
|
+
# [ping 127.0.0.1 -c 2] round-trip min/avg/max/stddev = 0.050/0.085/0.120/0.035 ms
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### `--aggregate-output`
|
|
115
|
+
|
|
116
|
+
Avoid interleaving output by delaying printing of each command's output until
|
|
117
|
+
it has finished.
|
|
118
|
+
|
|
119
|
+
```bash
|
|
120
|
+
$ in-parallel --aggregate-output "ping google.com -c 2" "ping 127.0.0.1 -c 2"
|
|
121
|
+
|
|
122
|
+
# Prints:
|
|
123
|
+
# -------
|
|
124
|
+
# [ping 127.0.0.1 -c 2] PING 127.0.0.1 (127.0.0.1): 56 data bytes
|
|
125
|
+
# [ping 127.0.0.1 -c 2] 64 bytes from 127.0.0.1: icmp_seq=0 ttl=64 time=0.052 ms
|
|
126
|
+
# [ping 127.0.0.1 -c 2] 64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.076 ms
|
|
127
|
+
# [ping 127.0.0.1 -c 2]
|
|
128
|
+
# [ping 127.0.0.1 -c 2] --- 127.0.0.1 ping statistics ---
|
|
129
|
+
# [ping 127.0.0.1 -c 2] 2 packets transmitted, 2 packets received, 0.0% packet loss
|
|
130
|
+
# [ping 127.0.0.1 -c 2] round-trip min/avg/max/stddev = 0.052/0.064/0.076/0.012 ms
|
|
131
|
+
# [ping google.com -c 2] PING google.com (142.250.186.46): 56 data bytes
|
|
132
|
+
# [ping google.com -c 2] 64 bytes from 142.250.186.46: icmp_seq=0 ttl=56 time=18.493 ms
|
|
133
|
+
# [ping google.com -c 2] 64 bytes from 142.250.186.46: icmp_seq=1 ttl=56 time=18.072 ms
|
|
134
|
+
# [ping google.com -c 2]
|
|
135
|
+
# [ping google.com -c 2] --- google.com ping statistics ---
|
|
136
|
+
# [ping google.com -c 2] 2 packets transmitted, 2 packets received, 0.0% packet loss
|
|
137
|
+
# [ping google.com -c 2] round-trip min/avg/max/stddev = 18.072/18.282/18.493/0.211 ms
|
|
138
|
+
```
|
|
139
|
+
|
|
42
140
|
## Development
|
|
43
141
|
|
|
44
142
|
(1) Install dependencies
|
package/package.json
CHANGED
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "in-parallel-lit",
|
|
3
3
|
"description": "Run multiple processes in parallel",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.2.0",
|
|
5
5
|
"author": "Joel Voss <mail@joelvoss.com>",
|
|
6
6
|
"license": "MIT",
|
|
7
|
+
"homepage": "https://github.com/joelvoss/in-parallel-lit",
|
|
8
|
+
"bugs": {
|
|
9
|
+
"url": "https://github.com/joelvoss/in-parallel-lit/issues"
|
|
10
|
+
},
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "git+https://github.com/joelvoss/in-parallel-lit.git"
|
|
14
|
+
},
|
|
7
15
|
"type": "module",
|
|
8
16
|
"engines": {
|
|
9
17
|
"node": ">= 14"
|
package/src/bin.js
CHANGED
|
@@ -17,16 +17,21 @@ async function run(argv) {
|
|
|
17
17
|
.version(packageJson.version)
|
|
18
18
|
.describe(packageJson.description)
|
|
19
19
|
.option(
|
|
20
|
-
|
|
20
|
+
`-n, --names`,
|
|
21
|
+
`List of custom names to be used in prefix template.`,
|
|
22
|
+
)
|
|
23
|
+
.example(`-n "first,second" "ping google.com" "ping 172.0.0.1"`)
|
|
24
|
+
.option(
|
|
25
|
+
`-c, --continue-on-error`,
|
|
21
26
|
`Set the flag to continue executing other/subsequent tasks even if a task threw an error. 'in-parallel' itself will exit with non-zero code if one or more tasks threw error(s).`,
|
|
22
27
|
)
|
|
23
28
|
.option(
|
|
24
|
-
|
|
29
|
+
`--max-parallel`,
|
|
25
30
|
`Set the maximum number of parallelism. Default is unlimited.`,
|
|
26
31
|
0,
|
|
27
32
|
)
|
|
28
33
|
.option(
|
|
29
|
-
|
|
34
|
+
`--aggregate-output`,
|
|
30
35
|
`Avoid interleaving output by delaying printing of each command's output until it has finished.`,
|
|
31
36
|
false,
|
|
32
37
|
)
|
package/src/index.js
CHANGED
|
@@ -15,6 +15,9 @@ import { getStreamKind } from './lib/get-stream-kind.js';
|
|
|
15
15
|
export function prog(opts, proc) {
|
|
16
16
|
const { _: tasks, ...options } = opts;
|
|
17
17
|
|
|
18
|
+
const customTaskNames =
|
|
19
|
+
options.names != null ? options.names.split(',').map(n => n.trim()) : [];
|
|
20
|
+
|
|
18
21
|
return new Promise((resolve, reject) => {
|
|
19
22
|
let results = [];
|
|
20
23
|
let queue = [];
|
|
@@ -56,20 +59,22 @@ export function prog(opts, proc) {
|
|
|
56
59
|
return;
|
|
57
60
|
}
|
|
58
61
|
|
|
62
|
+
const task = queue.shift();
|
|
63
|
+
|
|
59
64
|
const originalOutputStream = proc.stdout;
|
|
60
65
|
const optionsClone = {
|
|
61
|
-
...Object.assign({}, options),
|
|
62
66
|
stdout: proc.stdout,
|
|
63
67
|
stderr: proc.stderr,
|
|
64
68
|
stdin: proc.stdin,
|
|
69
|
+
customName: customTaskNames[task.index],
|
|
65
70
|
};
|
|
71
|
+
|
|
66
72
|
const writer = new MemoryWritable();
|
|
67
73
|
|
|
68
74
|
if (options['aggregate-output']) {
|
|
69
75
|
optionsClone.stdout = writer;
|
|
70
76
|
}
|
|
71
77
|
|
|
72
|
-
const task = queue.shift();
|
|
73
78
|
const promise = runTask(task.name, optionsClone);
|
|
74
79
|
|
|
75
80
|
promises.push(promise);
|
|
@@ -137,6 +142,7 @@ export function prog(opts, proc) {
|
|
|
137
142
|
* @prop {stream.Readable} stdin
|
|
138
143
|
* @prop {stream.Writable} stdout
|
|
139
144
|
* @prop {stream.Writable} stderr
|
|
145
|
+
* @prop {string} [customName=]
|
|
140
146
|
*/
|
|
141
147
|
|
|
142
148
|
/**
|
|
@@ -150,8 +156,8 @@ function runTask(name, opts) {
|
|
|
150
156
|
|
|
151
157
|
const task = new Promise((resolve, reject) => {
|
|
152
158
|
const stdin = opts.stdin;
|
|
153
|
-
const stdout = wrapStreamWithLabel(opts.stdout, name);
|
|
154
|
-
const stderr = wrapStreamWithLabel(opts.stderr, name);
|
|
159
|
+
const stdout = wrapStreamWithLabel(opts.stdout, opts.customName || name);
|
|
160
|
+
const stderr = wrapStreamWithLabel(opts.stderr, opts.customName || name);
|
|
155
161
|
|
|
156
162
|
const stdinKind = getStreamKind(stdin, process.stdin);
|
|
157
163
|
const stdoutKind = getStreamKind(stdout, process.stdout);
|