@vltpkg/promise-spawn 0.0.0-0.1730239248325 → 0.0.0-10

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 CHANGED
@@ -1,24 +1,29 @@
1
- # `@vltpkg/promise-spawn`
1
+ ![promise-spawn](https://github.com/user-attachments/assets/8dcb044f-7611-4db9-8042-3a964e270d61)
2
2
 
3
- Spawn a process and return a promise that resolves when the
4
- process closes. Fork of
5
- [`@npmcli/promise-spawn`](http://npm.im/@npmcli/promise-spawn)
3
+ # @vltpkg/promise-spawn
4
+
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).
8
+
9
+ **[Usage](#usage)** · **[API](#api)** ·
10
+ **[Caveats](#typescript-inference-caveats)**
6
11
 
7
12
  ## Differences from `@npmcli/promise-spawn`
8
13
 
9
- - A `SpawnPromise(cmd, args, options)` class is added that
10
- handles most of the functionality.
14
+ - A `SpawnPromise(cmd, args, options)` class is added that handles
15
+ most of the functionality.
11
16
  - `promiseSpawn.open()` is removed
12
- - When run as root, it just runs the command as root, it doesn't
13
- 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..
14
19
  - No special handling for `shell: true` processes, and thus, no
15
- escaping of arguments in that case. (It's just passed through
16
- to Node's `spawn()` method.)
17
- - Fully type-aware, even down to inferring the presence and type
18
- of `stdout` and `stderr` properties, as well as the properties
19
- 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.
20
25
 
21
- ## USAGE
26
+ ## Usage
22
27
 
23
28
  ```js
24
29
  import { promiseSpawn, SpawnPromise } from '@vltpkg/promise-spawn'
@@ -59,37 +64,38 @@ Result or error will be decorated with the properties in the `extra`
59
64
  object. You can use this to attach some helpful info about _why_ the
60
65
  command is being run, if it makes sense for your use case.
61
66
 
62
- If `stdio` is set to anything other than `'inherit'`, then the result/error
63
- will be decorated with `stdout` and `stderr` values. If `stdioString` is
64
- set to `true`, these will be strings. Otherwise they will be Buffer
65
- 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.
66
71
 
67
- Returned promise is decorated with the `stdin` stream if the process is set
68
- to pipe from `stdin`. Writing to this stream writes to the `stdin` of the
69
- 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.
70
75
 
71
76
  #### Options
72
77
 
73
- - `stdioString` Boolean, default `true`. Return stdout/stderr
74
- output as trimmed strings rather than buffers.
75
- - `acceptFail` Boolean, default `false`. If true, then a process
76
- that closes with `status` other than 0, or `signal` other than
77
- `null`, will reject the promise. If true, then failure exits
78
- resolve the promise normally. This is useful when you need to
79
- run a process where an exit status of `>0` is informative, to
80
- avoid creating an Error object for it.
81
- - Any other options for `child_process.spawn` can be passed as
82
- 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.
87
+
88
+ ## TypeScript Inference Caveats
83
89
 
84
- ## TypeScript Inference Caveat (and workaround)
90
+ _Workaround:_
85
91
 
86
- If you provide a complex stdio option like `['pipe', 'inherit']`,
87
- then this will of course mean that `stdin` is set to a writable
88
- stream, `stderr` is set to a readable stream (because that's the
89
- 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`.
90
96
 
91
- The types will accurately infer this from the type of the
92
- 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:
93
99
 
94
100
  ```
95
101
  const result = await promiseSpawn(cmd, args, {
@@ -101,13 +107,13 @@ result.stderr
101
107
  // ^? string
102
108
  ```
103
109
 
104
- TS will infer the `options.stdio` property to be `('pipe' |
105
- 'inherit')[]`. Since the second item of such an array _might_ be
106
- set to `'pipe'` at some point, TS will infer the return value to
107
- 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 }`.
108
114
 
109
- To get around this, typecast the field to its literal value. This
110
- 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:
111
117
 
112
118
  ```js
113
119
  const result = await promiseSpawn(cmd, args, {
@@ -1,71 +1,71 @@
1
- import { ChildProcess, IOType, SpawnOptions, StdioOptions } from 'child_process';
1
+ import type { ChildProcess, IOType, SpawnOptions, StdioOptions } from 'node:child_process';
2
2
  export type IOTypeNoPipe = Exclude<IOType, IOTypePipe>;
3
3
  export type IOTypePipe = 'overlapped' | 'pipe' | null | undefined;
4
- export type PromiseSpawnOptions = SpawnOptions & {
4
+ export interface PromiseSpawnOptions extends SpawnOptions {
5
5
  stdioString?: boolean;
6
6
  acceptFail?: boolean;
7
- };
8
- export type PromiseSpawnOptionsString = PromiseSpawnOptions & {
7
+ }
8
+ export interface PromiseSpawnOptionsString extends PromiseSpawnOptions {
9
9
  stdioString?: true;
10
- };
11
- export type PromiseSpawnOptionsBuffer = PromiseSpawnOptions & {
10
+ }
11
+ export interface PromiseSpawnOptionsBuffer extends PromiseSpawnOptions {
12
12
  stdioString: false;
13
- };
14
- export type PromiseSpawnOptionsStdin = PromiseSpawnOptions & {
13
+ }
14
+ export interface PromiseSpawnOptionsStdin extends PromiseSpawnOptions {
15
15
  stdio?: Exclude<IOTypePipe, null> | [
16
16
  stdin?: IOTypePipe,
17
17
  stdout?: Exclude<StdioOptions, IOType>[number],
18
18
  stderr?: Exclude<StdioOptions, IOType>[number]
19
19
  ];
20
- };
21
- export type PromiseSpawnOptionsNoStdin = PromiseSpawnOptions & {
20
+ }
21
+ export interface PromiseSpawnOptionsNoStdin extends PromiseSpawnOptions {
22
22
  stdio: IOTypeNoPipe | IOTypeNoPipe[] | [
23
23
  stdin: IOTypeNoPipe | number,
24
24
  stdout?: Exclude<StdioOptions, IOType>[number],
25
25
  stderr?: Exclude<StdioOptions, IOType>[number]
26
26
  ];
27
- };
28
- export type PromiseSpawnOptionsStdout = PromiseSpawnOptions & {
27
+ }
28
+ export interface PromiseSpawnOptionsStdout extends PromiseSpawnOptions {
29
29
  stdio?: Exclude<IOTypePipe, null> | [
30
30
  stdin: Exclude<StdioOptions, IOType>[number] | undefined,
31
31
  stdout?: IOTypePipe,
32
32
  stderr?: Exclude<StdioOptions, IOType>[number]
33
33
  ];
34
- };
35
- export type PromiseSpawnOptionsStdoutString = PromiseSpawnOptionsStdout & {
34
+ }
35
+ export interface PromiseSpawnOptionsStdoutString extends PromiseSpawnOptionsStdout {
36
36
  stdioString?: true;
37
- };
38
- export type PromiseSpawnOptionsStdoutBuffer = PromiseSpawnOptionsStdout & {
37
+ }
38
+ export interface PromiseSpawnOptionsStdoutBuffer extends PromiseSpawnOptionsStdout {
39
39
  stdioString: false;
40
- };
41
- export type PromiseSpawnOptionsNoStdout = PromiseSpawnOptions & {
40
+ }
41
+ export interface PromiseSpawnOptionsNoStdout extends PromiseSpawnOptions {
42
42
  stdio: IOTypeNoPipe | IOTypeNoPipe[] | [
43
43
  stdin: Exclude<StdioOptions, IOType>[number] | undefined,
44
44
  stdout?: IOTypeNoPipe,
45
45
  stderr?: Exclude<StdioOptions, IOType>[number]
46
46
  ];
47
- };
48
- export type PromiseSpawnOptionsStderr = PromiseSpawnOptions & {
47
+ }
48
+ export interface PromiseSpawnOptionsStderr extends PromiseSpawnOptions {
49
49
  stdio?: Exclude<IOTypePipe, null> | [
50
50
  stdin: Exclude<StdioOptions, IOType>[number] | undefined,
51
51
  stdout: Exclude<StdioOptions, IOType>[number] | undefined,
52
52
  stderr?: IOTypePipe
53
53
  ];
54
- };
55
- export type PromiseSpawnOptionsStderrString = PromiseSpawnOptionsStderr & {
54
+ }
55
+ export interface PromiseSpawnOptionsStderrString extends PromiseSpawnOptionsStderr {
56
56
  stdioString?: true;
57
- };
58
- export type PromiseSpawnOptionsStderrBuffer = PromiseSpawnOptionsStderr & {
57
+ }
58
+ export interface PromiseSpawnOptionsStderrBuffer extends PromiseSpawnOptionsStderr {
59
59
  stdioString: false;
60
- };
61
- export type PromiseSpawnOptionsNoStderr = PromiseSpawnOptions & {
60
+ }
61
+ export interface PromiseSpawnOptionsNoStderr extends PromiseSpawnOptions {
62
62
  stdio: IOTypeNoPipe | IOTypeNoPipe[] | [
63
63
  stdin: Exclude<StdioOptions, IOType>[number] | undefined,
64
64
  stdout: Exclude<StdioOptions, IOType>[number] | undefined,
65
65
  stderr: IOTypeNoPipe
66
66
  ];
67
- };
68
- export type SpawnResult = {
67
+ }
68
+ export interface SpawnResult {
69
69
  command: string;
70
70
  args: string[];
71
71
  cwd: string;
@@ -73,62 +73,63 @@ export type SpawnResult = {
73
73
  signal: NodeJS.Signals | null;
74
74
  stdout: Buffer | string | null;
75
75
  stderr: Buffer | string | null;
76
- };
77
- export type SpawnResultString = SpawnResult & {
76
+ }
77
+ export interface SpawnResultString extends SpawnResult {
78
78
  stdout: string | null;
79
79
  stderr: string | null;
80
- };
81
- export type SpawnResultBuffer = SpawnResult & {
80
+ }
81
+ export interface SpawnResultBuffer extends SpawnResult {
82
82
  stdout: Buffer | null;
83
83
  stderr: Buffer | null;
84
- };
85
- export type SpawnResultStdout = SpawnResult & {
84
+ }
85
+ export interface SpawnResultStdout extends SpawnResult {
86
86
  stdout: Buffer | string;
87
- };
88
- export type SpawnResultStdoutString = SpawnResultString & {
87
+ }
88
+ export interface SpawnResultStdoutString extends SpawnResultString {
89
89
  stdout: string;
90
- };
91
- export type SpawnResultStdoutBuffer = SpawnResultBuffer & {
90
+ }
91
+ export interface SpawnResultStdoutBuffer extends SpawnResultBuffer {
92
92
  stdout: Buffer;
93
- };
94
- export type SpawnResultNoStdout = SpawnResult & {
93
+ }
94
+ export interface SpawnResultNoStdout extends SpawnResult {
95
95
  stdout: null;
96
- };
97
- export type SpawnResultStderr = SpawnResult & {
96
+ }
97
+ export interface SpawnResultStderr extends SpawnResult {
98
98
  stderr: Buffer | string;
99
- };
100
- export type SpawnResultStderrString = SpawnResultString & {
99
+ }
100
+ export interface SpawnResultStderrString extends SpawnResultString {
101
101
  stderr: string;
102
- };
103
- export type SpawnResultStderrBuffer = SpawnResultBuffer & {
102
+ }
103
+ export interface SpawnResultStderrBuffer extends SpawnResultBuffer {
104
104
  stderr: Buffer;
105
- };
106
- export type SpawnResultNoStderr = SpawnResult & {
105
+ }
106
+ export interface SpawnResultNoStderr extends SpawnResult {
107
107
  stderr: null;
108
- };
109
- export type SpawnResultNoStdio = SpawnResult & {
108
+ }
109
+ export interface SpawnResultNoStdio extends SpawnResult {
110
110
  stderr: null;
111
111
  stdout: null;
112
- };
113
- export type SpawnResultStdioStrings = SpawnResult & {
112
+ }
113
+ export interface SpawnResultStdioStrings extends SpawnResult {
114
114
  stdout: string;
115
115
  stderr: string;
116
- };
117
- export type SpawnResultStdioBuffers = SpawnResult & {
116
+ }
117
+ export interface SpawnResultStdioBuffers extends SpawnResult {
118
118
  stdout: Buffer;
119
119
  stderr: Buffer;
120
- };
121
- export type SpawnResultByOptions<T extends PromiseSpawnOptions> = SpawnResult & {
120
+ }
121
+ export type Override<T, R> = Omit<T, keyof R> & R;
122
+ export type SpawnResultByOptions<T extends PromiseSpawnOptions> = Override<SpawnResult, {
122
123
  stdout: T extends PromiseSpawnOptionsNoStdout ? null : T extends PromiseSpawnOptionsStdoutBuffer ? Buffer : T extends PromiseSpawnOptionsStdoutString ? string : T extends PromiseSpawnOptionsBuffer ? Buffer | null : T extends PromiseSpawnOptionsString ? string | null : Buffer | string | null;
123
124
  stderr: T extends PromiseSpawnOptionsNoStderr ? null : T extends PromiseSpawnOptionsStderrBuffer ? Buffer : T extends PromiseSpawnOptionsStderrString ? string : T extends PromiseSpawnOptionsBuffer ? Buffer | null : T extends PromiseSpawnOptionsString ? string | null : Buffer | string | null;
124
- };
125
- export type ChildProcessByOptions<T extends PromiseSpawnOptions> = ChildProcess & {
125
+ }>;
126
+ export type ChildProcessByOptions<T extends PromiseSpawnOptions> = Override<ChildProcess, {
126
127
  stdin: T extends PromiseSpawnOptionsNoStdin ? null : Exclude<ChildProcess['stdin'], null>;
127
128
  stdout: T extends PromiseSpawnOptionsNoStdout ? null : Exclude<ChildProcess['stdout'], null>;
128
129
  stderr: T extends PromiseSpawnOptionsNoStderr ? null : Exclude<ChildProcess['stderr'], null>;
129
- };
130
+ }>;
130
131
  /**
131
- * Subtype of Promise returned by {@link spawnPromise}.
132
+ * Subtype of Promise returned by {@link promiseSpawn}.
132
133
  *
133
134
  * Resolution value is inferred from the provided options.
134
135
  */
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EACL,YAAY,EACZ,MAAM,EAEN,YAAY,EACZ,YAAY,EACb,MAAM,eAAe,CAAA;AAYtB,MAAM,MAAM,YAAY,GAAG,OAAO,CAAC,MAAM,EAAE,UAAU,CAAC,CAAA;AACtD,MAAM,MAAM,UAAU,GAAG,YAAY,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,CAAA;AACjE,MAAM,MAAM,mBAAmB,GAAG,YAAY,GAAG;IAC/C,WAAW,CAAC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1
  import { error } from '@vltpkg/error-cause';
2
- import { spawn, } from 'child_process';
2
+ import { spawn } from 'node:child_process';
3
3
  const isPipe = (stdio = 'pipe', fd) => stdio === 'pipe' || stdio === 'overlapped' || stdio === null ? true
4
4
  : Array.isArray(stdio) ? isPipe(stdio[fd], fd)
5
5
  : false;
@@ -16,7 +16,7 @@ function stdioResult(stdout, stderr, o) {
16
16
  };
17
17
  }
18
18
  /**
19
- * Subtype of Promise returned by {@link spawnPromise}.
19
+ * Subtype of Promise returned by {@link promiseSpawn}.
20
20
  *
21
21
  * Resolution value is inferred from the provided options.
22
22
  */
@@ -39,40 +39,57 @@ export class SpawnPromise extends Promise {
39
39
  proc = spawn(command, args, opts);
40
40
  const stdout = [];
41
41
  const stderr = [];
42
- const reject = (er) => rej(error('command failed', {
43
- command,
44
- args,
45
- cwd: opts.cwd ?? process.cwd(),
46
- ...stdioResult(stdout, stderr, opts),
47
- ...extra,
48
- cause: er,
49
- }));
50
- proc.on('error', reject);
51
- if (proc.stdout) {
52
- proc.stdout
53
- .on('data', c => stdout.push(c))
54
- .on('error', er => reject(er));
55
- }
56
- if (proc.stderr) {
57
- proc.stderr
58
- .on('data', c => stderr.push(c))
59
- .on('error', er => reject(er));
60
- }
61
- proc.on('close', (status, signal) => {
62
- const result = {
42
+ // Don't use the spread operator on successResult or errorResult
43
+ // as that kills any typechecking for the known keys.
44
+ const reject = (er, status, signal) => {
45
+ const stdio = stdioResult(stdout, stderr, opts);
46
+ const errorResult = {
63
47
  command,
64
48
  args,
65
- cwd: opts.cwd ?? process.cwd(),
66
- /* c8 ignore next 2 - because windows */
67
- status: status ?? null,
68
- signal: signal ?? null,
69
- ...stdioResult(stdout, stderr, opts),
70
- ...extra,
49
+ stdout: stdio.stdout,
50
+ stderr: stdio.stderr,
51
+ cwd: opts.cwd?.toString() ?? process.cwd(),
71
52
  };
72
- if ((status || signal) && !opts.acceptFail)
73
- rej(error('command failed', result));
74
- else
75
- res(result);
53
+ if (er !== undefined) {
54
+ errorResult.cause = er;
55
+ }
56
+ if (status !== undefined) {
57
+ errorResult.status = status;
58
+ }
59
+ if (signal !== undefined) {
60
+ errorResult.signal = signal;
61
+ }
62
+ Object.assign(errorResult, extra);
63
+ rej(error('command failed', errorResult));
64
+ };
65
+ const resolve = (status, signal) => {
66
+ const stdio = stdioResult(stdout, stderr, opts);
67
+ const successResult = {
68
+ command,
69
+ args,
70
+ status,
71
+ signal,
72
+ stdout: stdio.stdout,
73
+ stderr: stdio.stderr,
74
+ cwd: opts.cwd?.toString() ?? process.cwd(),
75
+ };
76
+ Object.assign(successResult, extra);
77
+ res(successResult);
78
+ };
79
+ proc.on('error', reject);
80
+ proc.stdout
81
+ ?.on('data', c => stdout.push(c))
82
+ .on('error', er => reject(er));
83
+ proc.stderr
84
+ ?.on('data', c => stderr.push(c))
85
+ .on('error', er => reject(er));
86
+ proc.on('close', (status = null, signal = null) => {
87
+ if ((status || signal) && !opts.acceptFail) {
88
+ reject(undefined, status, signal);
89
+ }
90
+ else {
91
+ resolve(status, signal);
92
+ }
76
93
  });
77
94
  });
78
95
  this.process = proc;
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAA;AAC3C,OAAO,EAGL,KAAK,GAGN,MAAM,eAAe,CAAA;AAEtB,MAAM,MAAM,GAAG,CACb,QAEmB,MAAM,EACzB,EAAU,EACW,EAAE,CACvB,KAAK,KAAK,MAAM,IAAI,KAAK,KAAK,YAAY,IAAI,KAAK,KAAK,IAAI,CAAC,CAAC,CAAC,IAAI;IACnE,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;QAC9C,CAAC,CAAC,KAAK,CAAA;AA0FT,SAAS,WAAW,CAClB,MAAgB,EAChB,MAAgB,EAChB,CA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oBACpC,GAAG,KAAK;iBACsB,CAAA;gBAChC,IAAI,CAAC,MAAM,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU;oBACxC,GAAG,CAAC,KAAK,CAAC,gBAAgB,EAAE,MAAM,CAAC,CAAC,CAAA;;oBACjC,GAAG,CAAC,MAAM,CAAC,CAAA;YAClB,CAAC,CAAC,CAAA;QACJ,CAAC,CAAC,CAAA;QACF,IAAI,CAAC,OAAO,GAAG,IAAI,CAAA;QACnB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAA;IACzB,CAAC;CACF;AAED;;;GAGG;AACH,MAAM,UAAU,YAAY,CAI1B,OAAe,EAAE,IAAc,EAAE,OAAO,EAAO,EAAE,QAAQ,EAAO;IAChE,OAAO,IAAI,YAAY,CAAO,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,CAAC,CAAA;AAC3D,CAAC","sourcesContent":["import { error } from '@vltpkg/error-cause'\nimport {\n ChildProcess,\n IOType,\n spawn,\n SpawnOptions,\n StdioOptions,\n} from 'child_process'\n\nconst isPipe = (\n stdio:\n | Exclude<StdioOptions, IOType>[number]\n | StdioOptions = 'pipe',\n fd: number,\n): stdio is IOTypePipe =>\n stdio === 'pipe' || stdio === 'overlapped' || stdio === null ? true\n : Array.isArray(stdio) ? isPipe(stdio[fd], fd)\n : false\n\nexport type IOTypeNoPipe = Exclude<IOType, IOTypePipe>\nexport type IOTypePipe = 'overlapped' | 'pipe' | null | undefined\nexport type PromiseSpawnOptions = SpawnOptions & {\n stdioString?: boolean\n acceptFail?: boolean\n}\nexport type PromiseSpawnOptionsString = PromiseSpawnOptions & {\n stdioString?: true\n}\nexport type PromiseSpawnOptionsBuffer = PromiseSpawnOptions & {\n stdioString: false\n}\nexport type PromiseSpawnOptionsStdin = PromiseSpawnOptions & {\n stdio?:\n | Exclude<IOTypePipe, null>\n | [\n stdin?: IOTypePipe,\n stdout?: Exclude<StdioOptions, IOType>[number],\n stderr?: Exclude<StdioOptions, IOType>[number],\n ]\n}\nexport type PromiseSpawnOptionsNoStdin = PromiseSpawnOptions & {\n stdio:\n | IOTypeNoPipe\n | IOTypeNoPipe[]\n | [\n stdin: IOTypeNoPipe | number,\n stdout?: Exclude<StdioOptions, IOType>[number],\n stderr?: Exclude<StdioOptions, IOType>[number],\n ]\n}\nexport type PromiseSpawnOptionsStdout = PromiseSpawnOptions & {\n stdio?:\n | Exclude<IOTypePipe, null>\n | [\n stdin: Exclude<StdioOptions, IOType>[number] | undefined,\n stdout?: IOTypePipe,\n stderr?: Exclude<StdioOptions, IOType>[number],\n ]\n}\nexport type PromiseSpawnOptionsStdoutString =\n PromiseSpawnOptionsStdout & {\n stdioString?: true\n }\nexport type PromiseSpawnOptionsStdoutBuffer =\n PromiseSpawnOptionsStdout & {\n stdioString: false\n }\nexport type PromiseSpawnOptionsNoStdout = PromiseSpawnOptions & {\n stdio:\n | IOTypeNoPipe\n | IOTypeNoPipe[]\n | [\n stdin: Exclude<StdioOptions, IOType>[number] | undefined,\n stdout?: IOTypeNoPipe,\n stderr?: Exclude<StdioOptions, IOType>[number],\n ]\n}\n/* c8 ignore start - weird windows coverage bug */\nexport type PromiseSpawnOptionsStderr = PromiseSpawnOptions & {\n stdio?:\n | Exclude<IOTypePipe, null>\n | [\n stdin: Exclude<StdioOptions, IOType>[number] | undefined,\n stdout: Exclude<StdioOptions, IOType>[number] | undefined,\n stderr?: IOTypePipe,\n ]\n}\n/* c8 ignore stop */\nexport type PromiseSpawnOptionsStderrString =\n PromiseSpawnOptionsStderr & {\n stdioString?: true\n }\nexport type PromiseSpawnOptionsStderrBuffer =\n PromiseSpawnOptionsStderr & {\n stdioString: false\n }\nexport type PromiseSpawnOptionsNoStderr = PromiseSpawnOptions & {\n stdio:\n | IOTypeNoPipe\n | IOTypeNoPipe[]\n | [\n stdin: Exclude<StdioOptions, IOType>[number] | undefined,\n stdout: Exclude<StdioOptions, IOType>[number] | undefined,\n stderr: IOTypeNoPipe,\n ]\n}\n\nfunction stdioResult<O extends PromiseSpawnOptions>(\n stdout: Buffer[],\n stderr: Buffer[],\n o: O,\n): {\n stdout: SpawnResultByOptions<O>['stdout']\n stderr: SpawnResultByOptions<O>['stderr']\n} {\n return {\n stdout: (!isPipe(o.stdio, 1) ? null\n : o.stdioString !== false ?\n Buffer.concat(stdout).toString().trim()\n : Buffer.concat(stdout)) as SpawnResultByOptions<O>['stdout'],\n stderr: (!isPipe(o.stdio, 2) ? null\n : o.stdioString !== false ?\n Buffer.concat(stderr).toString().trim()\n : Buffer.concat(stderr)) as SpawnResultByOptions<O>['stderr'],\n }\n}\n\nexport type SpawnResult = {\n command: string\n args: string[]\n cwd: string\n status: number | null\n signal: NodeJS.Signals | null\n stdout: Buffer | string | null\n stderr: Buffer | string | null\n}\nexport type SpawnResultString = SpawnResult & {\n stdout: string | null\n stderr: string | null\n}\nexport type SpawnResultBuffer = SpawnResult & {\n stdout: Buffer | null\n stderr: Buffer | null\n}\nexport type SpawnResultStdout = SpawnResult & {\n stdout: Buffer | string\n}\nexport type SpawnResultStdoutString = SpawnResultString & {\n stdout: string\n}\nexport type SpawnResultStdoutBuffer = SpawnResultBuffer & {\n stdout: Buffer\n}\nexport type SpawnResultNoStdout = SpawnResult & {\n stdout: null\n}\nexport type SpawnResultStderr = SpawnResult & {\n stderr: Buffer | string\n}\nexport type SpawnResultStderrString = SpawnResultString & {\n stderr: string\n}\nexport type SpawnResultStderrBuffer = SpawnResultBuffer & {\n stderr: Buffer\n}\nexport type SpawnResultNoStderr = SpawnResult & {\n stderr: null\n}\n\nexport type SpawnResultNoStdio = SpawnResult & {\n stderr: null\n stdout: null\n}\nexport type SpawnResultStdioStrings = SpawnResult & {\n stdout: string\n stderr: string\n}\nexport type SpawnResultStdioBuffers = SpawnResult & {\n stdout: Buffer\n stderr: Buffer\n}\n\nexport type SpawnResultByOptions<T extends PromiseSpawnOptions> =\n SpawnResult & {\n stdout: T extends PromiseSpawnOptionsNoStdout ? null\n : T extends PromiseSpawnOptionsStdoutBuffer ? Buffer\n : T extends PromiseSpawnOptionsStdoutString ? string\n : T extends PromiseSpawnOptionsBuffer ? Buffer | null\n : T extends PromiseSpawnOptionsString ? string | null\n : Buffer | string | null\n stderr: T extends PromiseSpawnOptionsNoStderr ? null\n : T extends PromiseSpawnOptionsStderrBuffer ? Buffer\n : T extends PromiseSpawnOptionsStderrString ? string\n : T extends PromiseSpawnOptionsBuffer ? Buffer | null\n : T extends PromiseSpawnOptionsString ? string | null\n : Buffer | string | null\n }\n\nexport type ChildProcessByOptions<T extends PromiseSpawnOptions> =\n ChildProcess & {\n stdin: T extends PromiseSpawnOptionsNoStdin ? null\n : Exclude<ChildProcess['stdin'], null>\n stdout: T extends PromiseSpawnOptionsNoStdout ? null\n : Exclude<ChildProcess['stdout'], null>\n stderr: T extends PromiseSpawnOptionsNoStderr ? null\n : Exclude<ChildProcess['stderr'], null>\n }\n\n/**\n * Subtype of Promise returned by {@link spawnPromise}.\n *\n * Resolution value is inferred from the provided options.\n */\nexport class SpawnPromise<\n O extends PromiseSpawnOptions,\n T extends object = object,\n> extends Promise<SpawnResultByOptions<O> & T> {\n [Symbol.toStringTag] = 'SpawnPromise'\n\n /** The spawned process this promise references */\n process!: ChildProcessByOptions<O>\n\n /** Expose the child process stdin, if available */\n stdin!: ChildProcessByOptions<O>['stdin']\n\n /**\n * Set static `Symbol.species` back to the base Promise class so that\n * v8 doesn't get confused by the changed constructor signature.\n */\n static get [Symbol.species]() {\n return Promise\n }\n\n constructor(\n command: string,\n args: string[],\n opts: O,\n extra: T = {} as T,\n ) {\n let proc!: ChildProcessByOptions<O>\n super((res, rej) => {\n proc = spawn(command, args, opts) as ChildProcessByOptions<O>\n const stdout: Buffer[] = []\n const stderr: Buffer[] = []\n const reject = (er: Error) =>\n rej(\n error('command failed', {\n command,\n args,\n cwd: opts.cwd ?? process.cwd(),\n ...stdioResult(stdout, stderr, opts),\n ...extra,\n cause: er,\n }),\n )\n proc.on('error', reject)\n if (proc.stdout) {\n proc.stdout\n .on('data', c => stdout.push(c))\n .on('error', er => reject(er))\n }\n if (proc.stderr) {\n proc.stderr\n .on('data', c => stderr.push(c))\n .on('error', er => reject(er))\n }\n proc.on('close', (status, signal) => {\n const result = {\n command,\n args,\n cwd: opts.cwd ?? process.cwd(),\n /* c8 ignore next 2 - because windows */\n status: status ?? null,\n signal: signal ?? null,\n ...stdioResult(stdout, stderr, opts),\n ...extra,\n } as SpawnResultByOptions<O> & T\n if ((status || signal) && !opts.acceptFail)\n rej(error('command failed', result))\n else res(result)\n })\n })\n this.process = proc\n this.stdin = proc.stdin\n }\n}\n\n/**\n * Spawn the specified command, and return a promise that resolves when\n * the process closes or has an error.\n */\nexport function promiseSpawn<\n O extends PromiseSpawnOptions = PromiseSpawnOptionsStderrString &\n PromiseSpawnOptionsStdoutString,\n E extends object = object,\n>(command: string, args: string[], opts = {} as O, extra = {} as E) {\n return new SpawnPromise<O, E>(command, args, opts, extra)\n}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAA;AAE3C,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAA;AAQ1C,MAAM,MAAM,GAAG,CACb,QAEmB,MAAM,EACzB,EAAU,EACW,EAAE,CACvB,KAAK,KAAK,MAAM,IAAI,KAAK,KAAK,YAAY,IAAI,KAAK,KAAK,IAAI,CAAC,CAAC,CAAC,IAAI;IACnE,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;QAC9C,CAAC,CAAC,KAAK,CAAA;AAiGT,SAAS,WAAW,CAClB,MAAgB,EAChB,MAAgB,EAChB,CAAI;IAKJ,OAAO;QACL,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,EAAE,CAA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from '@vltpkg/error-cause'\nimport type { ErrorCauseOptions } from '@vltpkg/error-cause'\nimport { spawn } from 'node:child_process'\nimport type {\n ChildProcess,\n IOType,\n SpawnOptions,\n StdioOptions,\n} from 'node:child_process'\n\nconst isPipe = (\n stdio:\n | Exclude<StdioOptions, IOType>[number]\n | StdioOptions = 'pipe',\n fd: number,\n): stdio is IOTypePipe =>\n stdio === 'pipe' || stdio === 'overlapped' || stdio === null ? true\n : Array.isArray(stdio) ? isPipe(stdio[fd], fd)\n : false\n\nexport type IOTypeNoPipe = Exclude<IOType, IOTypePipe>\nexport type IOTypePipe = 'overlapped' | 'pipe' | null | undefined\n\nexport interface PromiseSpawnOptions extends SpawnOptions {\n stdioString?: boolean\n acceptFail?: boolean\n}\nexport interface PromiseSpawnOptionsString\n extends PromiseSpawnOptions {\n stdioString?: true\n}\nexport interface PromiseSpawnOptionsBuffer\n extends PromiseSpawnOptions {\n stdioString: false\n}\nexport interface PromiseSpawnOptionsStdin\n extends PromiseSpawnOptions {\n stdio?:\n | Exclude<IOTypePipe, null>\n | [\n stdin?: IOTypePipe,\n stdout?: Exclude<StdioOptions, IOType>[number],\n stderr?: Exclude<StdioOptions, IOType>[number],\n ]\n}\nexport interface PromiseSpawnOptionsNoStdin\n extends PromiseSpawnOptions {\n stdio:\n | IOTypeNoPipe\n | IOTypeNoPipe[]\n | [\n stdin: IOTypeNoPipe | number,\n stdout?: Exclude<StdioOptions, IOType>[number],\n stderr?: Exclude<StdioOptions, IOType>[number],\n ]\n}\nexport interface PromiseSpawnOptionsStdout\n extends PromiseSpawnOptions {\n stdio?:\n | Exclude<IOTypePipe, null>\n | [\n stdin: Exclude<StdioOptions, IOType>[number] | undefined,\n stdout?: IOTypePipe,\n stderr?: Exclude<StdioOptions, IOType>[number],\n ]\n}\nexport interface PromiseSpawnOptionsStdoutString\n extends PromiseSpawnOptionsStdout {\n stdioString?: true\n}\nexport interface PromiseSpawnOptionsStdoutBuffer\n extends PromiseSpawnOptionsStdout {\n stdioString: false\n}\nexport interface PromiseSpawnOptionsNoStdout\n extends PromiseSpawnOptions {\n stdio:\n | IOTypeNoPipe\n | IOTypeNoPipe[]\n | [\n stdin: Exclude<StdioOptions, IOType>[number] | undefined,\n stdout?: IOTypeNoPipe,\n stderr?: Exclude<StdioOptions, IOType>[number],\n ]\n}\nexport interface PromiseSpawnOptionsStderr\n extends PromiseSpawnOptions {\n stdio?:\n | Exclude<IOTypePipe, null>\n | [\n stdin: Exclude<StdioOptions, IOType>[number] | undefined,\n stdout: Exclude<StdioOptions, IOType>[number] | undefined,\n stderr?: IOTypePipe,\n ]\n}\nexport interface PromiseSpawnOptionsStderrString\n extends PromiseSpawnOptionsStderr {\n stdioString?: true\n}\nexport interface PromiseSpawnOptionsStderrBuffer\n extends PromiseSpawnOptionsStderr {\n stdioString: false\n}\nexport interface PromiseSpawnOptionsNoStderr\n extends PromiseSpawnOptions {\n stdio:\n | IOTypeNoPipe\n | IOTypeNoPipe[]\n | [\n stdin: Exclude<StdioOptions, IOType>[number] | undefined,\n stdout: Exclude<StdioOptions, IOType>[number] | undefined,\n stderr: IOTypeNoPipe,\n ]\n}\n\nfunction stdioResult<O extends PromiseSpawnOptions>(\n stdout: Buffer[],\n stderr: Buffer[],\n o: O,\n): {\n stdout: SpawnResultByOptions<O>['stdout']\n stderr: SpawnResultByOptions<O>['stderr']\n} {\n return {\n stdout: (!isPipe(o.stdio, 1) ? null\n : o.stdioString !== false ?\n Buffer.concat(stdout).toString().trim()\n : Buffer.concat(stdout)) as SpawnResultByOptions<O>['stdout'],\n stderr: (!isPipe(o.stdio, 2) ? null\n : o.stdioString !== false ?\n Buffer.concat(stderr).toString().trim()\n : Buffer.concat(stderr)) as SpawnResultByOptions<O>['stderr'],\n }\n}\n\nexport interface SpawnResult {\n command: string\n args: string[]\n cwd: string\n status: number | null\n signal: NodeJS.Signals | null\n stdout: Buffer | string | null\n stderr: Buffer | string | null\n}\nexport interface SpawnResultString extends SpawnResult {\n stdout: string | null\n stderr: string | null\n}\nexport interface SpawnResultBuffer extends SpawnResult {\n stdout: Buffer | null\n stderr: Buffer | null\n}\nexport interface SpawnResultStdout extends SpawnResult {\n stdout: Buffer | string\n}\nexport interface SpawnResultStdoutString extends SpawnResultString {\n stdout: string\n}\nexport interface SpawnResultStdoutBuffer extends SpawnResultBuffer {\n stdout: Buffer\n}\nexport interface SpawnResultNoStdout extends SpawnResult {\n stdout: null\n}\nexport interface SpawnResultStderr extends SpawnResult {\n stderr: Buffer | string\n}\nexport interface SpawnResultStderrString extends SpawnResultString {\n stderr: string\n}\nexport interface SpawnResultStderrBuffer extends SpawnResultBuffer {\n stderr: Buffer\n}\nexport interface SpawnResultNoStderr extends SpawnResult {\n stderr: null\n}\nexport interface SpawnResultNoStdio extends SpawnResult {\n stderr: null\n stdout: null\n}\nexport interface SpawnResultStdioStrings extends SpawnResult {\n stdout: string\n stderr: string\n}\nexport interface SpawnResultStdioBuffers extends SpawnResult {\n stdout: Buffer\n stderr: Buffer\n}\n\nexport type Override<T, R> = Omit<T, keyof R> & R\n\nexport type SpawnResultByOptions<T extends PromiseSpawnOptions> =\n Override<\n SpawnResult,\n {\n stdout: T extends PromiseSpawnOptionsNoStdout ? null\n : T extends PromiseSpawnOptionsStdoutBuffer ? Buffer\n : T extends PromiseSpawnOptionsStdoutString ? string\n : T extends PromiseSpawnOptionsBuffer ? Buffer | null\n : T extends PromiseSpawnOptionsString ? string | null\n : Buffer | string | null\n stderr: T extends PromiseSpawnOptionsNoStderr ? null\n : T extends PromiseSpawnOptionsStderrBuffer ? Buffer\n : T extends PromiseSpawnOptionsStderrString ? string\n : T extends PromiseSpawnOptionsBuffer ? Buffer | null\n : T extends PromiseSpawnOptionsString ? string | null\n : Buffer | string | null\n }\n >\n\nexport type ChildProcessByOptions<T extends PromiseSpawnOptions> =\n Override<\n ChildProcess,\n {\n stdin: T extends PromiseSpawnOptionsNoStdin ? null\n : Exclude<ChildProcess['stdin'], null>\n stdout: T extends PromiseSpawnOptionsNoStdout ? null\n : Exclude<ChildProcess['stdout'], null>\n stderr: T extends PromiseSpawnOptionsNoStderr ? null\n : Exclude<ChildProcess['stderr'], null>\n }\n >\n\n/**\n * Subtype of Promise returned by {@link promiseSpawn}.\n *\n * Resolution value is inferred from the provided options.\n */\nexport class SpawnPromise<\n O extends PromiseSpawnOptions,\n T extends object = object,\n> extends Promise<SpawnResultByOptions<O> & T> {\n [Symbol.toStringTag] = 'SpawnPromise'\n\n /** The spawned process this promise references */\n process!: ChildProcessByOptions<O>\n\n /** Expose the child process stdin, if available */\n stdin!: ChildProcessByOptions<O>['stdin']\n\n /**\n * Set static `Symbol.species` back to the base Promise class so that\n * v8 doesn't get confused by the changed constructor signature.\n */\n static get [Symbol.species]() {\n return Promise\n }\n\n constructor(\n command: string,\n args: string[],\n opts: O,\n extra: T = {} as T,\n ) {\n let proc!: ChildProcessByOptions<O>\n super((res, rej) => {\n proc = spawn(command, args, opts) as ChildProcessByOptions<O>\n const stdout: Buffer[] = []\n const stderr: Buffer[] = []\n // Don't use the spread operator on successResult or errorResult\n // as that kills any typechecking for the known keys.\n const reject = (\n er?: Error,\n status?: number | null,\n signal?: NodeJS.Signals | null,\n ) => {\n const stdio = stdioResult(stdout, stderr, opts)\n const errorResult: ErrorCauseOptions = {\n command,\n args,\n stdout: stdio.stdout,\n stderr: stdio.stderr,\n cwd: opts.cwd?.toString() ?? process.cwd(),\n }\n if (er !== undefined) {\n errorResult.cause = er\n }\n if (status !== undefined) {\n errorResult.status = status\n }\n if (signal !== undefined) {\n errorResult.signal = signal\n }\n Object.assign(errorResult, extra)\n rej(error('command failed', errorResult))\n }\n const resolve = (\n status: number | null,\n signal: NodeJS.Signals | null,\n ) => {\n const stdio = stdioResult(stdout, stderr, opts)\n const successResult: SpawnResultByOptions<O> = {\n command,\n args,\n status,\n signal,\n stdout: stdio.stdout,\n stderr: stdio.stderr,\n cwd: opts.cwd?.toString() ?? process.cwd(),\n }\n Object.assign(successResult, extra)\n res(successResult as SpawnResultByOptions<O> & T)\n }\n proc.on('error', reject)\n proc.stdout\n ?.on('data', c => stdout.push(c as Buffer))\n .on('error', er => reject(er))\n proc.stderr\n ?.on('data', c => stderr.push(c as Buffer))\n .on('error', er => reject(er))\n proc.on('close', (status = null, signal = null) => {\n if ((status || signal) && !opts.acceptFail) {\n reject(undefined, status, signal)\n } else {\n resolve(status, signal)\n }\n })\n })\n this.process = proc\n this.stdin = proc.stdin\n }\n}\n\n/**\n * Spawn the specified command, and return a promise that resolves when\n * the process closes or has an error.\n */\nexport function promiseSpawn<\n O extends PromiseSpawnOptions = PromiseSpawnOptionsStderrString &\n PromiseSpawnOptionsStdoutString,\n E extends object = object,\n>(command: string, args: string[], opts = {} as O, extra = {} as E) {\n return new SpawnPromise<O, E>(command, args, opts, extra)\n}\n"]}
package/package.json CHANGED
@@ -1,9 +1,15 @@
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-0.1730239248325",
4
+ "version": "0.0.0-10",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/vltpkg/vltpkg.git",
8
+ "directory": "src/promise-spawn"
9
+ },
5
10
  "tshy": {
6
11
  "selfLink": false,
12
+ "liveDev": true,
7
13
  "dialects": [
8
14
  "esm"
9
15
  ],
@@ -13,23 +19,23 @@
13
19
  }
14
20
  },
15
21
  "dependencies": {
16
- "@vltpkg/error-cause": "0.0.0-0.1730239248325"
22
+ "@vltpkg/error-cause": "0.0.0-10"
17
23
  },
18
24
  "devDependencies": {
19
- "@eslint/js": "^9.8.0",
20
- "@types/eslint__js": "^8.42.3",
21
- "@types/node": "^22.4.1",
22
- "eslint": "^9.8.0",
23
- "prettier": "^3.3.2",
25
+ "@eslint/js": "^9.25.0",
26
+ "@types/node": "^22.14.1",
27
+ "eslint": "^9.25.0",
28
+ "prettier": "^3.5.3",
24
29
  "spawk": "^1.8.2",
25
- "tap": "^21.0.1",
30
+ "tap": "^21.1.0",
26
31
  "tshy": "^3.0.2",
27
- "typescript": "^5.5.4",
28
- "typescript-eslint": "^8.0.1"
32
+ "typedoc": "~0.27.6",
33
+ "typescript": "5.7.3",
34
+ "typescript-eslint": "^8.30.1"
29
35
  },
30
36
  "license": "ISC",
31
37
  "engines": {
32
- "node": "20 || >=22"
38
+ "node": ">=22"
33
39
  },
34
40
  "tap": {
35
41
  "extends": "../../tap-config.yaml"
@@ -54,9 +60,9 @@
54
60
  "format:check": "prettier --check . --ignore-path ../../.prettierignore --cache",
55
61
  "lint": "eslint . --fix",
56
62
  "lint:check": "eslint .",
57
- "presnap": "tshy",
58
63
  "snap": "tap",
59
- "pretest": "tshy",
60
- "test": "tap"
64
+ "test": "tap",
65
+ "posttest": "tsc --noEmit",
66
+ "typecheck": "tsc --noEmit"
61
67
  }
62
68
  }