@vltpkg/promise-spawn 0.0.0-2 → 0.0.0-21

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
@@ -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, {
@@ -1,4 +1,4 @@
1
- import type { 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
4
  export interface PromiseSpawnOptions extends SpawnOptions {
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,YAAY,EACZ,MAAM,EACN,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;AAEjE,MAAM,WAAW,mBAAoB,SAAQ,YAAY;IACvD,WAAW,CAAC,EAAE,OAAO,CAAA;IACrB,UAAU,CAAC,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OAAO,CAAC,YAAY,CAAC,QAAQ,CAAC,EAAE,IAAI,CAAC,CAAA;IACvC,MAAM,EAAE,CAAC,SAAS,2BAA2B,GAAG,IAAI,GAClD,OAAO,CAAC,YAAY,CAAC,QAAQ,CAAC,EAAE,IAAI,CAAC,CAAA;CACxC,CACF,CAAA;AAEH;;;;GAIG;AACH,qBAAa,YAAY,CACvB,CAAC,SAAS,mBAAmB,EAC7B,CAAC,SAAS,MAAM,GAAG,MAAM,CACzB,SAAQ,OAAO,CAAC,oBAAoB,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;IAC5C,CAAC,MAAM,CAAC,WAAW,CAAC,SAAiB;IAErC,kDAAkD;IAClD,OAAO,EAAG,qBAAqB,CAAC,CAAC,CAAC,CAAA;IAElC,mDAAmD;IACnD,KAAK,EAAG,qBAAqB,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAA;IAEzC;;;OAGG;IACH,MAAM,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,uBAE1B;gBAGC,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,MAAM,EAAE,EACd,IAAI,EAAE,CAAC,EACP,KAAK,GAAE,CAAW;CAqErB;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAC1B,CAAC,SAAS,mBAAmB,GAAG,+BAA+B,GAC7D,+BAA+B,EACjC,CAAC,SAAS,MAAM,GAAG,MAAM,EACzB,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,IAAI,GAAS,CAAC,EAAE,KAAK,GAAS,CAAC,sBAEjE"}
package/dist/esm/index.js CHANGED
@@ -1,5 +1,5 @@
1
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;
@@ -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,EAAE,KAAK,EAAE,MAAM,eAAe,CAAA;AAQrC,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,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI;YACnC,CAAC,CAAC,CAAC,CAAC,WAAW,KAAK,KAAK,CAAC,CAAC;gBACzB,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE,CAAC,IAAI,EAAE;gBACzC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAsC;QAC7D,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,CA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AAU,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 { spawn } from 'child_process'\nimport type {\n ChildProcess,\n IOType,\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\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 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 as Buffer))\n .on('error', er => reject(er))\n }\n if (proc.stderr) {\n proc.stderr\n .on('data', c => stderr.push(c as Buffer))\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,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI;YACnC,CAAC,CAAC,CAAC,CAAC,WAAW,KAAK,KAAK,CAAC,CAAC;gBACzB,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE,CAAC,IAAI,EAAE;gBACzC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAsC;QAC7D,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,EAAE,CAA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AChC,IAAI,CAAC,MAAM;gBACT,EAAE,EAAE,CAAC,MAAM,EAAE,CAAC,CAAC,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,CAAW,CAAC,CAAC;iBAC1C,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,EAAE,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAA;YAChC,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,MAAM,GAAG,IAAI,EAAE,MAAM,GAAG,IAAI,EAAE,EAAE;gBAChD,IAAI,CAAC,MAAM,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC;oBAC3C,MAAM,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,CAAC,CAAA;gBACnC,CAAC;qBAAM,CAAC;oBACN,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;gBACzB,CAAC;YACH,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 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,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-2",
4
+ "version": "0.0.0-21",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/vltpkg/vltpkg.git",
@@ -19,20 +19,19 @@
19
19
  }
20
20
  },
21
21
  "dependencies": {
22
- "@vltpkg/error-cause": "0.0.0-2"
22
+ "@vltpkg/error-cause": "0.0.0-21"
23
23
  },
24
24
  "devDependencies": {
25
- "@eslint/js": "^9.20.0",
26
- "@types/eslint__js": "^8.42.3",
27
- "@types/node": "^22.13.1",
28
- "eslint": "^9.20.0",
29
- "prettier": "^3.4.2",
25
+ "@eslint/js": "^9.28.0",
26
+ "@types/node": "^22.15.29",
27
+ "eslint": "^9.28.0",
28
+ "prettier": "^3.6.0",
30
29
  "spawk": "^1.8.2",
31
30
  "tap": "^21.1.0",
32
31
  "tshy": "^3.0.2",
33
- "typedoc": "0.27.6",
32
+ "typedoc": "~0.27.9",
34
33
  "typescript": "5.7.3",
35
- "typescript-eslint": "^8.23.0"
34
+ "typescript-eslint": "^8.33.1"
36
35
  },
37
36
  "license": "ISC",
38
37
  "engines": {
@@ -64,6 +63,7 @@
64
63
  "snap": "tap",
65
64
  "test": "tap",
66
65
  "posttest": "tsc --noEmit",
66
+ "tshy": "tshy",
67
67
  "typecheck": "tsc --noEmit"
68
68
  }
69
69
  }