@vltpkg/promise-spawn 1.0.0-rc.18 → 1.0.0-rc.22
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/package.json +22 -18
- package/dist/index.d.ts +0 -154
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -107
- package/dist/index.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,15 +1,18 @@
|
|
|
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": "1.0.0-rc.
|
|
4
|
+
"version": "1.0.0-rc.22",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "git+https://github.com/vltpkg/vltpkg.git",
|
|
8
8
|
"directory": "src/promise-spawn"
|
|
9
9
|
},
|
|
10
|
-
"author":
|
|
10
|
+
"author": {
|
|
11
|
+
"name": "vlt technology inc.",
|
|
12
|
+
"email": "support@vlt.sh"
|
|
13
|
+
},
|
|
11
14
|
"dependencies": {
|
|
12
|
-
"@vltpkg/error-cause": "1.0.0-rc.
|
|
15
|
+
"@vltpkg/error-cause": "1.0.0-rc.22"
|
|
13
16
|
},
|
|
14
17
|
"devDependencies": {
|
|
15
18
|
"@eslint/js": "^9.39.1",
|
|
@@ -24,33 +27,34 @@
|
|
|
24
27
|
},
|
|
25
28
|
"license": "ISC",
|
|
26
29
|
"engines": {
|
|
27
|
-
"node": ">=22.
|
|
30
|
+
"node": ">=22.22.0"
|
|
31
|
+
},
|
|
32
|
+
"scripts": {
|
|
33
|
+
"format": "prettier --write . --log-level warn --ignore-path ../../.prettierignore --cache",
|
|
34
|
+
"format:check": "prettier --check . --ignore-path ../../.prettierignore --cache",
|
|
35
|
+
"lint": "eslint . --fix",
|
|
36
|
+
"lint:check": "eslint .",
|
|
37
|
+
"prepack": "tsc -p tsconfig.publish.json && ../../scripts/update-dist-exports.ts",
|
|
38
|
+
"snap": "tap",
|
|
39
|
+
"test": "tap",
|
|
40
|
+
"posttest": "tsc --noEmit",
|
|
41
|
+
"typecheck": "tsc --noEmit"
|
|
28
42
|
},
|
|
29
43
|
"tap": {
|
|
30
44
|
"extends": "../../tap-config.yaml"
|
|
31
45
|
},
|
|
32
46
|
"prettier": "../../.prettierrc.js",
|
|
33
|
-
"module": "./
|
|
47
|
+
"module": "./src/index.ts",
|
|
34
48
|
"type": "module",
|
|
35
49
|
"exports": {
|
|
36
50
|
"./package.json": "./package.json",
|
|
37
51
|
".": {
|
|
38
52
|
"import": {
|
|
39
|
-
"default": "./
|
|
53
|
+
"default": "./src/index.ts"
|
|
40
54
|
}
|
|
41
55
|
}
|
|
42
56
|
},
|
|
43
57
|
"files": [
|
|
44
58
|
"dist"
|
|
45
|
-
]
|
|
46
|
-
|
|
47
|
-
"format": "prettier --write . --log-level warn --ignore-path ../../.prettierignore --cache",
|
|
48
|
-
"format:check": "prettier --check . --ignore-path ../../.prettierignore --cache",
|
|
49
|
-
"lint": "eslint . --fix",
|
|
50
|
-
"lint:check": "eslint .",
|
|
51
|
-
"snap": "tap",
|
|
52
|
-
"test": "tap",
|
|
53
|
-
"posttest": "tsc --noEmit",
|
|
54
|
-
"typecheck": "tsc --noEmit"
|
|
55
|
-
}
|
|
56
|
-
}
|
|
59
|
+
]
|
|
60
|
+
}
|
package/dist/index.d.ts
DELETED
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
import type { ChildProcess, IOType, SpawnOptions, StdioOptions } from 'node:child_process';
|
|
2
|
-
export type IOTypeNoPipe = Exclude<IOType, IOTypePipe>;
|
|
3
|
-
export type IOTypePipe = 'overlapped' | 'pipe' | null | undefined;
|
|
4
|
-
export interface PromiseSpawnOptions extends SpawnOptions {
|
|
5
|
-
stdioString?: boolean;
|
|
6
|
-
acceptFail?: boolean;
|
|
7
|
-
}
|
|
8
|
-
export interface PromiseSpawnOptionsString extends PromiseSpawnOptions {
|
|
9
|
-
stdioString?: true;
|
|
10
|
-
}
|
|
11
|
-
export interface PromiseSpawnOptionsBuffer extends PromiseSpawnOptions {
|
|
12
|
-
stdioString: false;
|
|
13
|
-
}
|
|
14
|
-
export interface PromiseSpawnOptionsStdin extends PromiseSpawnOptions {
|
|
15
|
-
stdio?: Exclude<IOTypePipe, null> | [
|
|
16
|
-
stdin?: IOTypePipe,
|
|
17
|
-
stdout?: Exclude<StdioOptions, IOType>[number],
|
|
18
|
-
stderr?: Exclude<StdioOptions, IOType>[number]
|
|
19
|
-
];
|
|
20
|
-
}
|
|
21
|
-
export interface PromiseSpawnOptionsNoStdin extends PromiseSpawnOptions {
|
|
22
|
-
stdio: IOTypeNoPipe | IOTypeNoPipe[] | [
|
|
23
|
-
stdin: IOTypeNoPipe | number,
|
|
24
|
-
stdout?: Exclude<StdioOptions, IOType>[number],
|
|
25
|
-
stderr?: Exclude<StdioOptions, IOType>[number]
|
|
26
|
-
];
|
|
27
|
-
}
|
|
28
|
-
export interface PromiseSpawnOptionsStdout extends PromiseSpawnOptions {
|
|
29
|
-
stdio?: Exclude<IOTypePipe, null> | [
|
|
30
|
-
stdin: Exclude<StdioOptions, IOType>[number] | undefined,
|
|
31
|
-
stdout?: IOTypePipe,
|
|
32
|
-
stderr?: Exclude<StdioOptions, IOType>[number]
|
|
33
|
-
];
|
|
34
|
-
}
|
|
35
|
-
export interface PromiseSpawnOptionsStdoutString extends PromiseSpawnOptionsStdout {
|
|
36
|
-
stdioString?: true;
|
|
37
|
-
}
|
|
38
|
-
export interface PromiseSpawnOptionsStdoutBuffer extends PromiseSpawnOptionsStdout {
|
|
39
|
-
stdioString: false;
|
|
40
|
-
}
|
|
41
|
-
export interface PromiseSpawnOptionsNoStdout extends PromiseSpawnOptions {
|
|
42
|
-
stdio: IOTypeNoPipe | IOTypeNoPipe[] | [
|
|
43
|
-
stdin: Exclude<StdioOptions, IOType>[number] | undefined,
|
|
44
|
-
stdout?: IOTypeNoPipe,
|
|
45
|
-
stderr?: Exclude<StdioOptions, IOType>[number]
|
|
46
|
-
];
|
|
47
|
-
}
|
|
48
|
-
export interface PromiseSpawnOptionsStderr extends PromiseSpawnOptions {
|
|
49
|
-
stdio?: Exclude<IOTypePipe, null> | [
|
|
50
|
-
stdin: Exclude<StdioOptions, IOType>[number] | undefined,
|
|
51
|
-
stdout: Exclude<StdioOptions, IOType>[number] | undefined,
|
|
52
|
-
stderr?: IOTypePipe
|
|
53
|
-
];
|
|
54
|
-
}
|
|
55
|
-
export interface PromiseSpawnOptionsStderrString extends PromiseSpawnOptionsStderr {
|
|
56
|
-
stdioString?: true;
|
|
57
|
-
}
|
|
58
|
-
export interface PromiseSpawnOptionsStderrBuffer extends PromiseSpawnOptionsStderr {
|
|
59
|
-
stdioString: false;
|
|
60
|
-
}
|
|
61
|
-
export interface PromiseSpawnOptionsNoStderr extends PromiseSpawnOptions {
|
|
62
|
-
stdio: IOTypeNoPipe | IOTypeNoPipe[] | [
|
|
63
|
-
stdin: Exclude<StdioOptions, IOType>[number] | undefined,
|
|
64
|
-
stdout: Exclude<StdioOptions, IOType>[number] | undefined,
|
|
65
|
-
stderr: IOTypeNoPipe
|
|
66
|
-
];
|
|
67
|
-
}
|
|
68
|
-
export interface SpawnResult {
|
|
69
|
-
command: string;
|
|
70
|
-
args: string[];
|
|
71
|
-
cwd: string;
|
|
72
|
-
status: number | null;
|
|
73
|
-
signal: NodeJS.Signals | null;
|
|
74
|
-
stdout: Buffer | string | null;
|
|
75
|
-
stderr: Buffer | string | null;
|
|
76
|
-
}
|
|
77
|
-
export interface SpawnResultString extends SpawnResult {
|
|
78
|
-
stdout: string | null;
|
|
79
|
-
stderr: string | null;
|
|
80
|
-
}
|
|
81
|
-
export interface SpawnResultBuffer extends SpawnResult {
|
|
82
|
-
stdout: Buffer | null;
|
|
83
|
-
stderr: Buffer | null;
|
|
84
|
-
}
|
|
85
|
-
export interface SpawnResultStdout extends SpawnResult {
|
|
86
|
-
stdout: Buffer | string;
|
|
87
|
-
}
|
|
88
|
-
export interface SpawnResultStdoutString extends SpawnResultString {
|
|
89
|
-
stdout: string;
|
|
90
|
-
}
|
|
91
|
-
export interface SpawnResultStdoutBuffer extends SpawnResultBuffer {
|
|
92
|
-
stdout: Buffer;
|
|
93
|
-
}
|
|
94
|
-
export interface SpawnResultNoStdout extends SpawnResult {
|
|
95
|
-
stdout: null;
|
|
96
|
-
}
|
|
97
|
-
export interface SpawnResultStderr extends SpawnResult {
|
|
98
|
-
stderr: Buffer | string;
|
|
99
|
-
}
|
|
100
|
-
export interface SpawnResultStderrString extends SpawnResultString {
|
|
101
|
-
stderr: string;
|
|
102
|
-
}
|
|
103
|
-
export interface SpawnResultStderrBuffer extends SpawnResultBuffer {
|
|
104
|
-
stderr: Buffer;
|
|
105
|
-
}
|
|
106
|
-
export interface SpawnResultNoStderr extends SpawnResult {
|
|
107
|
-
stderr: null;
|
|
108
|
-
}
|
|
109
|
-
export interface SpawnResultNoStdio extends SpawnResult {
|
|
110
|
-
stderr: null;
|
|
111
|
-
stdout: null;
|
|
112
|
-
}
|
|
113
|
-
export interface SpawnResultStdioStrings extends SpawnResult {
|
|
114
|
-
stdout: string;
|
|
115
|
-
stderr: string;
|
|
116
|
-
}
|
|
117
|
-
export interface SpawnResultStdioBuffers extends SpawnResult {
|
|
118
|
-
stdout: Buffer;
|
|
119
|
-
stderr: Buffer;
|
|
120
|
-
}
|
|
121
|
-
export type Override<T, R> = Omit<T, keyof R> & R;
|
|
122
|
-
export type SpawnResultByOptions<T extends PromiseSpawnOptions> = Override<SpawnResult, {
|
|
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;
|
|
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;
|
|
125
|
-
}>;
|
|
126
|
-
export type ChildProcessByOptions<T extends PromiseSpawnOptions> = Override<ChildProcess, {
|
|
127
|
-
stdin: T extends PromiseSpawnOptionsNoStdin ? null : Exclude<ChildProcess['stdin'], null>;
|
|
128
|
-
stdout: T extends PromiseSpawnOptionsNoStdout ? null : Exclude<ChildProcess['stdout'], null>;
|
|
129
|
-
stderr: T extends PromiseSpawnOptionsNoStderr ? null : Exclude<ChildProcess['stderr'], null>;
|
|
130
|
-
}>;
|
|
131
|
-
/**
|
|
132
|
-
* Subtype of Promise returned by {@link promiseSpawn}.
|
|
133
|
-
*
|
|
134
|
-
* Resolution value is inferred from the provided options.
|
|
135
|
-
*/
|
|
136
|
-
export declare class SpawnPromise<O extends PromiseSpawnOptions, T extends object = object> extends Promise<SpawnResultByOptions<O> & T> {
|
|
137
|
-
[Symbol.toStringTag]: string;
|
|
138
|
-
/** The spawned process this promise references */
|
|
139
|
-
process: ChildProcessByOptions<O>;
|
|
140
|
-
/** Expose the child process stdin, if available */
|
|
141
|
-
stdin: ChildProcessByOptions<O>['stdin'];
|
|
142
|
-
/**
|
|
143
|
-
* Set static `Symbol.species` back to the base Promise class so that
|
|
144
|
-
* v8 doesn't get confused by the changed constructor signature.
|
|
145
|
-
*/
|
|
146
|
-
static get [Symbol.species](): PromiseConstructor;
|
|
147
|
-
constructor(command: string, args: string[], opts: O, extra?: T);
|
|
148
|
-
}
|
|
149
|
-
/**
|
|
150
|
-
* Spawn the specified command, and return a promise that resolves when
|
|
151
|
-
* the process closes or has an error.
|
|
152
|
-
*/
|
|
153
|
-
export declare function promiseSpawn<O extends PromiseSpawnOptions = PromiseSpawnOptionsStderrString & PromiseSpawnOptionsStdoutString, E extends object = object>(command: string, args: string[], opts?: O, extra?: E): SpawnPromise<O, E>;
|
|
154
|
-
//# sourceMappingURL=index.d.ts.map
|
package/dist/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AS,MAAM,GAAG,MAAM,EACzB,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,IAAI,GAAS,CAAC,EAAE,KAAK,GAAS,CAAC,sBAEjE"}
|
package/dist/index.js
DELETED
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
import { error } from '@vltpkg/error-cause';
|
|
2
|
-
import { spawn } from 'node:child_process';
|
|
3
|
-
const isPipe = (stdio = 'pipe', fd) => stdio === 'pipe' || stdio === 'overlapped' || stdio === null ? true
|
|
4
|
-
: Array.isArray(stdio) ? isPipe(stdio[fd], fd)
|
|
5
|
-
: false;
|
|
6
|
-
function stdioResult(stdout, stderr, o) {
|
|
7
|
-
return {
|
|
8
|
-
stdout: (!isPipe(o.stdio, 1) ? null
|
|
9
|
-
: o.stdioString !== false ?
|
|
10
|
-
Buffer.concat(stdout).toString().trim()
|
|
11
|
-
: Buffer.concat(stdout)),
|
|
12
|
-
stderr: (!isPipe(o.stdio, 2) ? null
|
|
13
|
-
: o.stdioString !== false ?
|
|
14
|
-
Buffer.concat(stderr).toString().trim()
|
|
15
|
-
: Buffer.concat(stderr)),
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Subtype of Promise returned by {@link promiseSpawn}.
|
|
20
|
-
*
|
|
21
|
-
* Resolution value is inferred from the provided options.
|
|
22
|
-
*/
|
|
23
|
-
export class SpawnPromise extends Promise {
|
|
24
|
-
[Symbol.toStringTag] = 'SpawnPromise';
|
|
25
|
-
/** The spawned process this promise references */
|
|
26
|
-
process;
|
|
27
|
-
/** Expose the child process stdin, if available */
|
|
28
|
-
stdin;
|
|
29
|
-
/**
|
|
30
|
-
* Set static `Symbol.species` back to the base Promise class so that
|
|
31
|
-
* v8 doesn't get confused by the changed constructor signature.
|
|
32
|
-
*/
|
|
33
|
-
static get [Symbol.species]() {
|
|
34
|
-
return Promise;
|
|
35
|
-
}
|
|
36
|
-
constructor(command, args, opts, extra = {}) {
|
|
37
|
-
let proc;
|
|
38
|
-
super((res, rej) => {
|
|
39
|
-
proc = spawn(command, args, opts);
|
|
40
|
-
const stdout = [];
|
|
41
|
-
const stderr = [];
|
|
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 = {
|
|
47
|
-
command,
|
|
48
|
-
args,
|
|
49
|
-
stdout: stdio.stdout,
|
|
50
|
-
stderr: stdio.stderr,
|
|
51
|
-
cwd: opts.cwd?.toString() ?? process.cwd(),
|
|
52
|
-
};
|
|
53
|
-
if (er !== undefined) {
|
|
54
|
-
errorResult.cause = er;
|
|
55
|
-
}
|
|
56
|
-
if (status !== undefined) {
|
|
57
|
-
errorResult.status = status;
|
|
58
|
-
}
|
|
59
|
-
/* c8 ignore next 3 - hard to test on win32 so coverage fails */
|
|
60
|
-
if (signal !== undefined) {
|
|
61
|
-
errorResult.signal = signal;
|
|
62
|
-
}
|
|
63
|
-
Object.assign(errorResult, extra);
|
|
64
|
-
rej(error('command failed', errorResult));
|
|
65
|
-
};
|
|
66
|
-
const resolve = (status, signal) => {
|
|
67
|
-
const stdio = stdioResult(stdout, stderr, opts);
|
|
68
|
-
const successResult = {
|
|
69
|
-
command,
|
|
70
|
-
args,
|
|
71
|
-
status,
|
|
72
|
-
signal,
|
|
73
|
-
stdout: stdio.stdout,
|
|
74
|
-
stderr: stdio.stderr,
|
|
75
|
-
cwd: opts.cwd?.toString() ?? process.cwd(),
|
|
76
|
-
};
|
|
77
|
-
Object.assign(successResult, extra);
|
|
78
|
-
res(successResult);
|
|
79
|
-
};
|
|
80
|
-
proc.on('error', reject);
|
|
81
|
-
proc.stdout
|
|
82
|
-
?.on('data', c => stdout.push(c))
|
|
83
|
-
.on('error', reject);
|
|
84
|
-
proc.stderr
|
|
85
|
-
?.on('data', c => stderr.push(c))
|
|
86
|
-
.on('error', reject);
|
|
87
|
-
proc.on('close', (status, signal) => {
|
|
88
|
-
if ((status || signal) && !opts.acceptFail) {
|
|
89
|
-
reject(undefined, status, signal);
|
|
90
|
-
}
|
|
91
|
-
else {
|
|
92
|
-
resolve(status, signal);
|
|
93
|
-
}
|
|
94
|
-
});
|
|
95
|
-
});
|
|
96
|
-
this.process = proc;
|
|
97
|
-
this.stdin = proc.stdin;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
/**
|
|
101
|
-
* Spawn the specified command, and return a promise that resolves when
|
|
102
|
-
* the process closes or has an error.
|
|
103
|
-
*/
|
|
104
|
-
export function promiseSpawn(command, args, opts = {}, extra = {}) {
|
|
105
|
-
return new SpawnPromise(command, args, opts, extra);
|
|
106
|
-
}
|
|
107
|
-
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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;AAqFT,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,C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C,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC,CAAA;YACxB,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,MAAM,CAAC,CAAA;YACtB,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,MAAM,CAAC,CAAA;YACtB,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE;gBAClC,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 extends PromiseSpawnOptions {\n stdioString?: true\n}\nexport interface PromiseSpawnOptionsBuffer extends PromiseSpawnOptions {\n stdioString: false\n}\nexport interface PromiseSpawnOptionsStdin 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 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 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 extends PromiseSpawnOptionsStdout {\n stdioString?: true\n}\nexport interface PromiseSpawnOptionsStdoutBuffer extends PromiseSpawnOptionsStdout {\n stdioString: false\n}\nexport interface PromiseSpawnOptionsNoStdout 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 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 extends PromiseSpawnOptionsStderr {\n stdioString?: true\n}\nexport interface PromiseSpawnOptionsStderrBuffer extends PromiseSpawnOptionsStderr {\n stdioString: false\n}\nexport interface PromiseSpawnOptionsNoStderr 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 /* c8 ignore next 3 - hard to test on win32 so coverage fails */\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', reject)\n proc.stderr\n ?.on('data', c => stderr.push(c as Buffer))\n .on('error', reject)\n proc.on('close', (status, signal) => {\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"]}
|