@vltpkg/promise-spawn 0.0.0-3 → 0.0.0-4
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 +41 -43
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -2,27 +2,26 @@
|
|
|
2
2
|
|
|
3
3
|
# @vltpkg/promise-spawn
|
|
4
4
|
|
|
5
|
-
Spawn a process and return a promise that resolves when the process
|
|
5
|
+
Spawn a process and return a promise that resolves when the process
|
|
6
|
+
closes. Fork of
|
|
7
|
+
[`@npmcli/promise-spawn`](http://npm.im/@npmcli/promise-spawn).
|
|
6
8
|
|
|
7
|
-
**[Usage](#usage)**
|
|
8
|
-
·
|
|
9
|
-
**[API](#api)**
|
|
10
|
-
·
|
|
9
|
+
**[Usage](#usage)** · **[API](#api)** ·
|
|
11
10
|
**[Caveats](#typescript-inference-caveats)**
|
|
12
11
|
|
|
13
12
|
## Differences from `@npmcli/promise-spawn`
|
|
14
13
|
|
|
15
|
-
- A `SpawnPromise(cmd, args, options)` class is added that
|
|
16
|
-
|
|
14
|
+
- A `SpawnPromise(cmd, args, options)` class is added that handles
|
|
15
|
+
most of the functionality.
|
|
17
16
|
- `promiseSpawn.open()` is removed
|
|
18
|
-
- When run as root, it just runs the command as root, it doesn't
|
|
19
|
-
|
|
17
|
+
- When run as root, it just runs the command as root, it doesn't try
|
|
18
|
+
to infer the uid/gid based on the owner of the cwd..
|
|
20
19
|
- No special handling for `shell: true` processes, and thus, no
|
|
21
|
-
escaping of arguments in that case. (It's just passed through
|
|
22
|
-
|
|
23
|
-
- Fully type-aware, even down to inferring the presence and type
|
|
24
|
-
|
|
25
|
-
|
|
20
|
+
escaping of arguments in that case. (It's just passed through to
|
|
21
|
+
Node's `spawn()` method.)
|
|
22
|
+
- Fully type-aware, even down to inferring the presence and type of
|
|
23
|
+
`stdout` and `stderr` properties, as well as the properties added
|
|
24
|
+
via the optional `extra` argument.
|
|
26
25
|
|
|
27
26
|
## Usage
|
|
28
27
|
|
|
@@ -65,39 +64,38 @@ Result or error will be decorated with the properties in the `extra`
|
|
|
65
64
|
object. You can use this to attach some helpful info about _why_ the
|
|
66
65
|
command is being run, if it makes sense for your use case.
|
|
67
66
|
|
|
68
|
-
If `stdio` is set to anything other than `'inherit'`, then the
|
|
69
|
-
will be decorated with `stdout` and `stderr` values. If
|
|
70
|
-
set to `true`, these will be strings. Otherwise they
|
|
71
|
-
objects.
|
|
67
|
+
If `stdio` is set to anything other than `'inherit'`, then the
|
|
68
|
+
result/error will be decorated with `stdout` and `stderr` values. If
|
|
69
|
+
`stdioString` is set to `true`, these will be strings. Otherwise they
|
|
70
|
+
will be Buffer objects.
|
|
72
71
|
|
|
73
|
-
Returned promise is decorated with the `stdin` stream if the process
|
|
74
|
-
to pipe from `stdin`. Writing to this stream writes to the
|
|
75
|
-
spawned process.
|
|
72
|
+
Returned promise is decorated with the `stdin` stream if the process
|
|
73
|
+
is set to pipe from `stdin`. Writing to this stream writes to the
|
|
74
|
+
`stdin` of the spawned process.
|
|
76
75
|
|
|
77
76
|
#### Options
|
|
78
77
|
|
|
79
|
-
- `stdioString` Boolean, default `true`. Return stdout/stderr
|
|
80
|
-
|
|
81
|
-
- `acceptFail` Boolean, default `false`. If true, then a process
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
- Any other options for `child_process.spawn` can be passed as
|
|
88
|
-
well.
|
|
78
|
+
- `stdioString` Boolean, default `true`. Return stdout/stderr output
|
|
79
|
+
as trimmed strings rather than buffers.
|
|
80
|
+
- `acceptFail` Boolean, default `false`. If true, then a process that
|
|
81
|
+
closes with `status` other than 0, or `signal` other than `null`,
|
|
82
|
+
will reject the promise. If true, then failure exits resolve the
|
|
83
|
+
promise normally. This is useful when you need to run a process
|
|
84
|
+
where an exit status of `>0` is informative, to avoid creating an
|
|
85
|
+
Error object for it.
|
|
86
|
+
- Any other options for `child_process.spawn` can be passed as well.
|
|
89
87
|
|
|
90
88
|
## TypeScript Inference Caveats
|
|
91
89
|
|
|
92
90
|
_Workaround:_
|
|
93
91
|
|
|
94
|
-
If you provide a complex stdio option like `['pipe', 'inherit']`,
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
92
|
+
If you provide a complex stdio option like `['pipe', 'inherit']`, then
|
|
93
|
+
this will of course mean that `stdin` is set to a writable stream,
|
|
94
|
+
`stderr` is set to a readable stream (because that's the default), but
|
|
95
|
+
`stdout` is set to `null`.
|
|
98
96
|
|
|
99
|
-
The types will accurately infer this from the type of the
|
|
100
|
-
|
|
97
|
+
The types will accurately infer this from the type of the argument.
|
|
98
|
+
However, observe this incorrect result:
|
|
101
99
|
|
|
102
100
|
```
|
|
103
101
|
const result = await promiseSpawn(cmd, args, {
|
|
@@ -109,13 +107,13 @@ result.stderr
|
|
|
109
107
|
// ^? string
|
|
110
108
|
```
|
|
111
109
|
|
|
112
|
-
TS will infer the `options.stdio` property to be
|
|
113
|
-
'inherit')[]`. Since the second item of such an array
|
|
114
|
-
set to `'pipe'` at some point, TS will infer the return
|
|
115
|
-
include `{ stdout: string }`.
|
|
110
|
+
TS will infer the `options.stdio` property to be
|
|
111
|
+
`('pipe' | 'inherit')[]`. Since the second item of such an array
|
|
112
|
+
_might_ be set to `'pipe'` at some point, TS will infer the return
|
|
113
|
+
value to include `{ stdout: string }`.
|
|
116
114
|
|
|
117
|
-
To get around this, typecast the field to its literal value. This
|
|
118
|
-
|
|
115
|
+
To get around this, typecast the field to its literal value. This is a
|
|
116
|
+
bit noisy, but works fine:
|
|
119
117
|
|
|
120
118
|
```js
|
|
121
119
|
const result = await promiseSpawn(cmd, args, {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vltpkg/promise-spawn",
|
|
3
3
|
"description": "Spawn a process and return a promise that resolves when it finishes",
|
|
4
|
-
"version": "0.0.0-
|
|
4
|
+
"version": "0.0.0-4",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "git+https://github.com/vltpkg/vltpkg.git",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
}
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@vltpkg/error-cause": "0.0.0-
|
|
22
|
+
"@vltpkg/error-cause": "0.0.0-4"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"@eslint/js": "^9.20.0",
|