@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.
Files changed (2) hide show
  1. package/README.md +41 -43
  2. 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 closes. Fork of [`@npmcli/promise-spawn`](http://npm.im/@npmcli/promise-spawn).
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
- handles most of the functionality.
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
- try to infer the uid/gid based on the owner of the cwd..
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
- to Node's `spawn()` method.)
23
- - Fully type-aware, even down to inferring the presence and type
24
- of `stdout` and `stderr` properties, as well as the properties
25
- added via the optional `extra` argument.
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 result/error
69
- will be decorated with `stdout` and `stderr` values. If `stdioString` is
70
- set to `true`, these will be strings. Otherwise they will be Buffer
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 is set
74
- to pipe from `stdin`. Writing to this stream writes to the `stdin` of 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
- output as trimmed strings rather than buffers.
81
- - `acceptFail` Boolean, default `false`. If true, then a process
82
- that closes with `status` other than 0, or `signal` other than
83
- `null`, will reject the promise. If true, then failure exits
84
- resolve the promise normally. This is useful when you need to
85
- run a process where an exit status of `>0` is informative, to
86
- avoid creating an Error object for it.
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
- then this will of course mean that `stdin` is set to a writable
96
- stream, `stderr` is set to a readable stream (because that's the
97
- default), but `stdout` is set to `null`.
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
- argument. However, observe this incorrect result:
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 `('pipe' |
113
- 'inherit')[]`. Since the second item of such an array _might_ be
114
- set to `'pipe'` at some point, TS will infer the return value to
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
- is a bit noisy, but works fine:
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-3",
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-3"
22
+ "@vltpkg/error-cause": "0.0.0-4"
23
23
  },
24
24
  "devDependencies": {
25
25
  "@eslint/js": "^9.20.0",