storybook 10.2.0-alpha.1 → 10.2.0-alpha.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/dist/_browser-chunks/{Color-TNPFN3FC.js → Color-XESOIGZP.js} +9 -568
- package/dist/_browser-chunks/{WithTooltip-IO6J4KBT.js → WithTooltip-65CFNBJE.js} +70 -70
- package/dist/_browser-chunks/{chunk-45UGUKRX.js → chunk-242VQQM5.js} +1 -1
- package/dist/_browser-chunks/{chunk-JP7NCOJX.js → chunk-3LY4VQVK.js} +1 -1
- package/dist/_browser-chunks/{chunk-VYJQ7RU5.js → chunk-G4M6MXF4.js} +31 -27
- package/dist/_browser-chunks/{chunk-BRX2HXH7.js → chunk-IH6QJILI.js} +1 -1
- package/dist/_browser-chunks/{chunk-AS2HQEYC.js → chunk-IWQGIXJS.js} +1 -1
- package/dist/_browser-chunks/{chunk-3IAH5M2U.js → chunk-IYCKG66Y.js} +5 -5
- package/dist/_browser-chunks/{chunk-UD6FQLAF.js → chunk-JK6U3MQW.js} +3 -3
- package/dist/_browser-chunks/{chunk-FQ7SLVLR.js → chunk-JVRDBUUP.js} +20 -1
- package/dist/_browser-chunks/{chunk-GFLS4VP3.js → chunk-LCHBOIHN.js} +6 -6
- package/dist/_browser-chunks/{chunk-CHUV5WSW.js → chunk-LE2LTDW3.js} +1 -1
- package/dist/_browser-chunks/{chunk-IPA5A322.js → chunk-MEXTPDJG.js} +1 -1
- package/dist/_browser-chunks/{chunk-XJNX76GA.js → chunk-NQJGOFZV.js} +4 -4
- package/dist/_browser-chunks/chunk-NZMVUW5T.js +7 -0
- package/dist/_browser-chunks/{chunk-2XZMBGTA.js → chunk-POMIZRJL.js} +3 -3
- package/dist/_browser-chunks/{chunk-RP5RXKFU.js → chunk-Q5RYDXT3.js} +38 -30
- package/dist/_browser-chunks/{chunk-SS2NHR7W.js → chunk-RBABWY22.js} +18 -18
- package/dist/_browser-chunks/{chunk-AXG2BOBL.js → chunk-S6TK43XQ.js} +10 -10
- package/dist/_browser-chunks/{chunk-AIOS4NGK.js → chunk-SWJP5COI.js} +11 -11
- package/dist/_browser-chunks/{chunk-H6XK3RSC.js → chunk-UAYGIC3L.js} +6 -6
- package/dist/_browser-chunks/{chunk-YKE5S47A.js → chunk-V2VKKSMQ.js} +18 -18
- package/dist/_browser-chunks/{chunk-GFY5R5EY.js → chunk-V5NV5R37.js} +1 -1
- package/dist/_browser-chunks/chunk-VIJ7SQRO.js +568 -0
- package/dist/_browser-chunks/{chunk-3OXGAGBE.js → chunk-XLJZ7AOP.js} +14 -14
- package/dist/_browser-chunks/{chunk-P4F4UVXX.js → chunk-YKABRMAI.js} +15 -15
- package/dist/_browser-chunks/{chunk-WJYERY3R.js → chunk-ZCFV7BZB.js} +2 -2
- package/dist/_browser-chunks/{formatter-QJ4M4OGQ.js → formatter-EIJCOSYU.js} +2 -2
- package/dist/_browser-chunks/{syntaxhighlighter-IQDEPFLK.js → syntaxhighlighter-ED5Y7EFY.js} +119 -119
- package/dist/_node-chunks/{builder-manager-LXL5N6M5.js → builder-manager-IL56SHZF.js} +23 -22
- package/dist/_node-chunks/camelcase-P3NIWBZX.js +62 -0
- package/dist/_node-chunks/{chunk-SR5ZYD7K.js → chunk-BP66TAYC.js} +8 -8
- package/dist/_node-chunks/{chunk-R3WYNAT5.js → chunk-D3YJHXPC.js} +6 -6
- package/dist/_node-chunks/{chunk-5GNBLJKS.js → chunk-E2KSZELU.js} +8 -8
- package/dist/_node-chunks/{chunk-KXDU466E.js → chunk-EKU7ASGO.js} +31 -31
- package/dist/_node-chunks/chunk-GLYH3TSV.js +61 -0
- package/dist/_node-chunks/{chunk-GOOBGRAV.js → chunk-JXL37VS7.js} +34 -24
- package/dist/_node-chunks/{chunk-4BQMSZKI.js → chunk-KH2A547Y.js} +165 -191
- package/dist/_node-chunks/{chunk-77APSTTM.js → chunk-KP3IIE5P.js} +8 -9
- package/dist/_node-chunks/{chunk-5NWCBUGD.js → chunk-LZ5NNY6S.js} +6 -6
- package/dist/_node-chunks/{chunk-AJUO2ZU3.js → chunk-MLCI5FPI.js} +9 -9
- package/dist/_node-chunks/{chunk-CLNMK7MP.js → chunk-OVKHHS4W.js} +5434 -1625
- package/dist/_node-chunks/{chunk-ET4VMMZG.js → chunk-OZHIDIRL.js} +77 -16
- package/dist/_node-chunks/{chunk-TX77W2KY.js → chunk-POAHHCVK.js} +597 -593
- package/dist/_node-chunks/chunk-Q6PDB4Y6.js +126 -0
- package/dist/_node-chunks/{chunk-VFTNRF5X.js → chunk-QF3YWFYM.js} +17 -17
- package/dist/_node-chunks/{chunk-KMTK5W6O.js → chunk-RGJIQDLW.js} +48 -26
- package/dist/_node-chunks/{chunk-FTR6MHOX.js → chunk-SME7252C.js} +59 -147
- package/dist/_node-chunks/{chunk-LEDV47V2.js → chunk-TAETXAN6.js} +15 -15
- package/dist/_node-chunks/chunk-TPSZ4QDT.js +20 -0
- package/dist/_node-chunks/{chunk-PGFQADZC.js → chunk-WULYWBBT.js} +7 -7
- package/dist/_node-chunks/{chunk-JYMZJCZ7.js → chunk-XBDIQU4P.js} +62 -124
- package/dist/_node-chunks/chunk-XXOA6ULE.js +18 -0
- package/dist/_node-chunks/{chunk-ZI2RAI3I.js → chunk-YCQRVBE4.js} +26 -7
- package/dist/_node-chunks/{chunk-TP6ICLTL.js → chunk-YELE6V4D.js} +6 -6
- package/dist/_node-chunks/{chunk-GYZQMMTN.js → chunk-Z2CJCEHN.js} +9 -9
- package/dist/_node-chunks/{chunk-F7377GT2.js → chunk-Z2ETF7EI.js} +111 -38
- package/dist/_node-chunks/chunk-ZHSAQXJF.js +23 -0
- package/dist/_node-chunks/{dist-HGQ5R6JU.js → dist-5MXCD6KF.js} +10 -10
- package/dist/_node-chunks/{globby-5XJTXKUJ.js → globby-322GM5CY.js} +155 -164
- package/dist/_node-chunks/{lib-XNLTS2RI.js → lib-IXZT5UQX.js} +16 -16
- package/dist/_node-chunks/{mdx-N42X6CFJ-7WF3QWVO.js → mdx-N42X6CFJ-DBPHTSPN.js} +11 -11
- package/dist/_node-chunks/{p-limit-RBKYTJKF.js → p-limit-TLN4WCPA.js} +19 -15
- package/dist/babel/index.js +10 -10
- package/dist/bin/core.js +40 -34
- package/dist/bin/dispatcher.js +11 -11
- package/dist/bin/loader.js +14 -11
- package/dist/channels/index.js +3 -3
- package/dist/cli/index.d.ts +1330 -250
- package/dist/cli/index.js +18 -18
- package/dist/common/index.d.ts +1344 -289
- package/dist/common/index.js +22 -22
- package/dist/components/index.d.ts +9 -2
- package/dist/components/index.js +339 -317
- package/dist/core-events/index.d.ts +4 -2
- package/dist/core-events/index.js +4 -2
- package/dist/core-server/index.d.ts +71 -2
- package/dist/core-server/index.js +3381 -3529
- package/dist/core-server/presets/common-manager.css +2 -2
- package/dist/core-server/presets/common-manager.js +93 -65
- package/dist/core-server/presets/common-override-preset.js +9 -9
- package/dist/core-server/presets/common-preset.js +86 -118
- package/dist/csf/index.d.ts +41 -11
- package/dist/csf/index.js +46 -39
- package/dist/csf-tools/index.js +9 -9
- package/dist/docs-tools/index.js +5 -5
- package/dist/instrumenter/index.js +1 -1
- package/dist/manager/globals-runtime.js +9402 -7204
- package/dist/manager/runtime.js +186 -143
- package/dist/manager-api/index.js +34 -26
- package/dist/manager-errors.d.ts +24 -0
- package/dist/manager-errors.js +2 -2
- package/dist/mocking-utils/index.js +14 -14
- package/dist/node-logger/index.d.ts +1456 -111
- package/dist/node-logger/index.js +9 -9
- package/dist/preview/runtime.js +4608 -2436
- package/dist/preview-api/index.js +12 -12
- package/dist/preview-errors.d.ts +24 -0
- package/dist/preview-errors.js +3 -3
- package/dist/router/index.js +11 -11
- package/dist/server-errors.d.ts +59 -3
- package/dist/server-errors.js +22 -11
- package/dist/telemetry/index.d.ts +10 -3
- package/dist/telemetry/index.js +27 -25
- package/dist/test/index.js +3237 -1653
- package/dist/theming/create.js +3 -3
- package/dist/theming/index.d.ts +5 -5
- package/dist/theming/index.js +38 -38
- package/dist/types/index.d.ts +12 -6
- package/dist/viewport/index.d.ts +3 -3
- package/package.json +27 -33
- package/dist/_browser-chunks/chunk-EZSQOHRI.js +0 -18
- package/dist/_browser-chunks/chunk-QKODTO7K.js +0 -7
- package/dist/_node-chunks/camelcase-64II7H4U.js +0 -37
- package/dist/_node-chunks/chunk-4EZYJUAC.js +0 -70
- package/dist/_node-chunks/chunk-COQ27OZ3.js +0 -61
- package/dist/_node-chunks/chunk-MC2R4DSD.js +0 -20
- package/dist/_node-chunks/chunk-NEENMS4J.js +0 -18
- package/dist/_node-chunks/chunk-VR5LMO3F.js +0 -72
- package/dist/_node-chunks/chunk-XEPVDCRL.js +0 -23
package/dist/cli/index.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import * as semver from 'semver';
|
|
2
2
|
import { JsPackageManager as JsPackageManager$1, PackageJson } from 'storybook/internal/common';
|
|
3
3
|
import { SupportedFramework as SupportedFramework$1, SupportedRenderer, SupportedLanguage, Feature, PackageJson as PackageJson$1, NormalizedProjectAnnotations, ProjectAnnotations, ComposedStoryFn } from 'storybook/internal/types';
|
|
4
|
-
import { Buffer } from 'node:buffer';
|
|
5
4
|
import { ChildProcess } from 'node:child_process';
|
|
6
|
-
import {
|
|
5
|
+
import { SignalConstants } from 'node:os';
|
|
6
|
+
import { Duplex, Readable, Writable } from 'node:stream';
|
|
7
|
+
import { TransformStream, ReadableStream, WritableStream } from 'node:stream/web';
|
|
7
8
|
|
|
8
9
|
declare function detectPnp(): Promise<boolean>;
|
|
9
10
|
|
|
@@ -89,7 +90,7 @@ declare class AngularJSON {
|
|
|
89
90
|
write(): void;
|
|
90
91
|
}
|
|
91
92
|
|
|
92
|
-
declare function getRendererDir(packageManager: JsPackageManager$1, renderer: SupportedFramework$1 | SupportedRenderer): Promise<string>;
|
|
93
|
+
declare function getRendererDir(packageManager: JsPackageManager$1, renderer: SupportedFramework$1 | SupportedRenderer): Promise<string | null>;
|
|
93
94
|
|
|
94
95
|
declare enum ProjectType {
|
|
95
96
|
ANGULAR = "angular",
|
|
@@ -104,7 +105,6 @@ declare enum ProjectType {
|
|
|
104
105
|
REACT_NATIVE = "react_native",
|
|
105
106
|
REACT_NATIVE_AND_RNW = "react_native_and_rnw",
|
|
106
107
|
REACT_NATIVE_WEB = "react_native_web",
|
|
107
|
-
REACT_PROJECT = "react_project",
|
|
108
108
|
REACT_SCRIPTS = "react_scripts",
|
|
109
109
|
SERVER = "server",
|
|
110
110
|
SOLID = "solid",
|
|
@@ -116,487 +116,1562 @@ declare enum ProjectType {
|
|
|
116
116
|
WEB_COMPONENTS = "web_components"
|
|
117
117
|
}
|
|
118
118
|
|
|
119
|
-
type
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
119
|
+
type Not<Value extends boolean> = Value extends true ? false : true;
|
|
120
|
+
|
|
121
|
+
type And<First extends boolean, Second extends boolean> = First extends true ? Second : false;
|
|
122
|
+
|
|
123
|
+
type Or<First extends boolean, Second extends boolean> = First extends true ? true : Second;
|
|
124
|
+
|
|
125
|
+
type Unless<Condition extends boolean, ThenValue, ElseValue = never> = Condition extends true ? ElseValue : ThenValue;
|
|
126
|
+
|
|
127
|
+
type AndUnless<Condition extends boolean, ThenValue, ElseValue = unknown> = Condition extends true ? ElseValue : ThenValue;
|
|
128
|
+
|
|
129
|
+
// Whether any of T's union element is the same as one of U's union element.
|
|
130
|
+
// `&` does not work here.
|
|
131
|
+
type Intersects<T, U> = true extends (T extends U ? true : false) ? true : false;
|
|
132
|
+
|
|
133
|
+
// `options.std*: Generator`
|
|
134
|
+
// @todo Use `string`, `Uint8Array` or `unknown` for both the argument and the return type, based on whether `encoding: 'buffer'` and `objectMode: true` are used.
|
|
135
|
+
// See https://github.com/sindresorhus/execa/issues/694
|
|
136
|
+
type GeneratorTransform<IsSync extends boolean> = (chunk: unknown) =>
|
|
137
|
+
| Unless<IsSync, AsyncGenerator<unknown, void, void>>
|
|
138
|
+
| Generator<unknown, void, void>;
|
|
139
|
+
type GeneratorFinal<IsSync extends boolean> = () =>
|
|
140
|
+
| Unless<IsSync, AsyncGenerator<unknown, void, void>>
|
|
141
|
+
| Generator<unknown, void, void>;
|
|
142
|
+
|
|
143
|
+
type TransformCommon = {
|
|
144
|
+
/**
|
|
145
|
+
If `true`, allow `transformOptions.transform` and `transformOptions.final` to return any type, not just `string` or `Uint8Array`.
|
|
146
|
+
*/
|
|
147
|
+
readonly objectMode?: boolean;
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
A transform or an array of transforms can be passed to the `stdin`, `stdout`, `stderr` or `stdio` option.
|
|
152
|
+
|
|
153
|
+
A transform is either a generator function or a plain object with the following members.
|
|
154
|
+
*/
|
|
155
|
+
type GeneratorTransformFull<IsSync extends boolean> = {
|
|
156
|
+
/**
|
|
157
|
+
Map or filter the input or output of the subprocess.
|
|
158
|
+
*/
|
|
159
|
+
readonly transform: GeneratorTransform<IsSync>;
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
Create additional lines after the last one.
|
|
163
|
+
*/
|
|
164
|
+
readonly final?: GeneratorFinal<IsSync>;
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
If `true`, iterate over arbitrary chunks of `Uint8Array`s instead of line `string`s.
|
|
168
|
+
*/
|
|
169
|
+
readonly binary?: boolean;
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
If `true`, keep newlines in each `line` argument. Also, this allows multiple `yield`s to produces a single line.
|
|
173
|
+
*/
|
|
174
|
+
readonly preserveNewlines?: boolean;
|
|
175
|
+
} & TransformCommon;
|
|
176
|
+
|
|
177
|
+
// `options.std*: Duplex`
|
|
178
|
+
type DuplexTransform = {
|
|
179
|
+
readonly transform: Duplex;
|
|
180
|
+
} & TransformCommon;
|
|
181
|
+
|
|
182
|
+
// `options.std*: TransformStream`
|
|
183
|
+
type WebTransform = {
|
|
184
|
+
readonly transform: TransformStream;
|
|
185
|
+
} & TransformCommon;
|
|
186
|
+
|
|
187
|
+
type IsStandardStream<FdNumber extends string> = FdNumber extends keyof StandardStreams ? true : false;
|
|
188
|
+
|
|
189
|
+
type StandardStreams = readonly ['stdin', 'stdout', 'stderr'];
|
|
190
|
+
|
|
191
|
+
// When `options.stdin|stdout|stderr|stdio` is set to one of those values, no stream is created
|
|
192
|
+
type NoStreamStdioOption<FdNumber extends string> =
|
|
123
193
|
| 'ignore'
|
|
124
194
|
| 'inherit'
|
|
125
|
-
|
|
|
195
|
+
| 'ipc'
|
|
126
196
|
| number
|
|
127
|
-
|
|
|
197
|
+
| Readable
|
|
198
|
+
| Writable
|
|
199
|
+
| Unless<IsStandardStream<FdNumber>, undefined>
|
|
200
|
+
| readonly [NoStreamStdioOption<FdNumber>];
|
|
201
|
+
|
|
202
|
+
// `options.stdio` when it is not an array
|
|
203
|
+
type SimpleStdioOption<
|
|
204
|
+
IsSync extends boolean,
|
|
205
|
+
IsExtra extends boolean,
|
|
206
|
+
IsArray extends boolean,
|
|
207
|
+
> =
|
|
208
|
+
| undefined
|
|
209
|
+
| 'pipe'
|
|
210
|
+
| Unless<And<And<Not<IsSync>, IsArray>, IsExtra>, 'inherit'>
|
|
211
|
+
| Unless<IsArray, 'ignore'>
|
|
212
|
+
| Unless<IsSync, 'overlapped'>;
|
|
213
|
+
|
|
214
|
+
// Values available in both `options.stdin|stdio` and `options.stdout|stderr|stdio`
|
|
215
|
+
type CommonStdioOption<
|
|
216
|
+
IsSync extends boolean,
|
|
217
|
+
IsExtra extends boolean,
|
|
218
|
+
IsArray extends boolean,
|
|
219
|
+
> =
|
|
220
|
+
| SimpleStdioOption<IsSync, IsExtra, IsArray>
|
|
221
|
+
| URL
|
|
222
|
+
| {readonly file: string; readonly append?: boolean}
|
|
223
|
+
| GeneratorTransform<IsSync>
|
|
224
|
+
| GeneratorTransformFull<IsSync>
|
|
225
|
+
| Unless<And<Not<IsSync>, IsArray>, 3 | 4 | 5 | 6 | 7 | 8 | 9>
|
|
226
|
+
| Unless<Or<IsSync, IsArray>, 'ipc'>
|
|
227
|
+
| Unless<IsSync, DuplexTransform | WebTransform | TransformStream>;
|
|
228
|
+
|
|
229
|
+
// Synchronous iterables excluding strings, Uint8Arrays and Arrays
|
|
230
|
+
type IterableObject<IsArray extends boolean> = Iterable<unknown>
|
|
231
|
+
& object
|
|
232
|
+
& {readonly BYTES_PER_ELEMENT?: never}
|
|
233
|
+
& AndUnless<IsArray, {readonly lastIndexOf?: never}>;
|
|
234
|
+
|
|
235
|
+
// `process.stdin|stdout|stderr` are `Duplex` with a `fd` property.
|
|
236
|
+
// This ensures they can only be passed to `stdin`/`stdout`/`stderr`, based on their direction.
|
|
237
|
+
type ProcessStdinFd = {readonly fd?: 0};
|
|
238
|
+
type ProcessStdoutStderrFd = {readonly fd?: 1 | 2};
|
|
239
|
+
|
|
240
|
+
// Values available only in `options.stdin|stdio`
|
|
241
|
+
type InputStdioOption<
|
|
242
|
+
IsSync extends boolean = boolean,
|
|
243
|
+
IsExtra extends boolean = boolean,
|
|
244
|
+
IsArray extends boolean = boolean,
|
|
245
|
+
> =
|
|
246
|
+
| 0
|
|
247
|
+
| Unless<And<IsSync, IsExtra>, Uint8Array | IterableObject<IsArray>>
|
|
248
|
+
| Unless<And<IsSync, IsArray>, Readable & ProcessStdinFd>
|
|
249
|
+
| Unless<IsSync, (AsyncIterable<unknown> & ProcessStdinFd) | ReadableStream>;
|
|
250
|
+
|
|
251
|
+
// Values available only in `options.stdout|stderr|stdio`
|
|
252
|
+
type OutputStdioOption<
|
|
253
|
+
IsSync extends boolean,
|
|
254
|
+
IsArray extends boolean,
|
|
255
|
+
> =
|
|
256
|
+
| 1
|
|
257
|
+
| 2
|
|
258
|
+
| Unless<And<IsSync, IsArray>, Writable & ProcessStdoutStderrFd>
|
|
259
|
+
| Unless<IsSync, WritableStream>;
|
|
260
|
+
|
|
261
|
+
// `options.stdin` array items
|
|
262
|
+
type StdinSingleOption<
|
|
263
|
+
IsSync extends boolean,
|
|
264
|
+
IsExtra extends boolean,
|
|
265
|
+
IsArray extends boolean,
|
|
266
|
+
> =
|
|
267
|
+
| CommonStdioOption<IsSync, IsExtra, IsArray>
|
|
268
|
+
| InputStdioOption<IsSync, IsExtra, IsArray>;
|
|
269
|
+
|
|
270
|
+
// `options.stdin`
|
|
271
|
+
type StdinOptionCommon<
|
|
272
|
+
IsSync extends boolean = boolean,
|
|
273
|
+
IsExtra extends boolean = boolean,
|
|
274
|
+
> =
|
|
275
|
+
| StdinSingleOption<IsSync, IsExtra, false>
|
|
276
|
+
| ReadonlyArray<StdinSingleOption<IsSync, IsExtra, true>>;
|
|
277
|
+
|
|
278
|
+
// `options.stdout|stderr` array items
|
|
279
|
+
type StdoutStderrSingleOption<
|
|
280
|
+
IsSync extends boolean,
|
|
281
|
+
IsExtra extends boolean,
|
|
282
|
+
IsArray extends boolean,
|
|
283
|
+
> =
|
|
284
|
+
| CommonStdioOption<IsSync, IsExtra, IsArray>
|
|
285
|
+
| OutputStdioOption<IsSync, IsArray>;
|
|
286
|
+
|
|
287
|
+
// `options.stdout|stderr`
|
|
288
|
+
type StdoutStderrOptionCommon<
|
|
289
|
+
IsSync extends boolean = boolean,
|
|
290
|
+
IsExtra extends boolean = boolean,
|
|
291
|
+
> =
|
|
292
|
+
| StdoutStderrSingleOption<IsSync, IsExtra, false>
|
|
293
|
+
| ReadonlyArray<StdoutStderrSingleOption<IsSync, IsExtra, true>>;
|
|
294
|
+
|
|
295
|
+
// `options.stdio[3+]`
|
|
296
|
+
type StdioExtraOptionCommon<IsSync extends boolean> =
|
|
297
|
+
| StdinOptionCommon<IsSync, true>
|
|
298
|
+
| StdoutStderrOptionCommon<IsSync, true>;
|
|
299
|
+
|
|
300
|
+
// `options.stdin|stdout|stderr|stdio` array items
|
|
301
|
+
type StdioSingleOption<
|
|
302
|
+
IsSync extends boolean = boolean,
|
|
303
|
+
IsExtra extends boolean = boolean,
|
|
304
|
+
IsArray extends boolean = boolean,
|
|
305
|
+
> =
|
|
306
|
+
| StdinSingleOption<IsSync, IsExtra, IsArray>
|
|
307
|
+
| StdoutStderrSingleOption<IsSync, IsExtra, IsArray>;
|
|
308
|
+
|
|
309
|
+
// Get `options.stdin|stdout|stderr|stdio` items if it is an array, else keep as is
|
|
310
|
+
type StdioSingleOptionItems<StdioOptionType> = StdioOptionType extends readonly StdioSingleOption[]
|
|
311
|
+
? StdioOptionType[number]
|
|
312
|
+
: StdioOptionType;
|
|
313
|
+
|
|
314
|
+
// `options.stdin|stdout|stderr|stdio`
|
|
315
|
+
type StdioOptionCommon<IsSync extends boolean = boolean> =
|
|
316
|
+
| StdinOptionCommon<IsSync>
|
|
317
|
+
| StdoutStderrOptionCommon<IsSync>;
|
|
318
|
+
|
|
319
|
+
// `options.stdio` when it is an array
|
|
320
|
+
type StdioOptionsArray<IsSync extends boolean = boolean> = readonly [
|
|
321
|
+
StdinOptionCommon<IsSync, false>,
|
|
322
|
+
StdoutStderrOptionCommon<IsSync, false>,
|
|
323
|
+
StdoutStderrOptionCommon<IsSync, false>,
|
|
324
|
+
...ReadonlyArray<StdioExtraOptionCommon<IsSync>>,
|
|
325
|
+
];
|
|
326
|
+
|
|
327
|
+
// `options.stdio`
|
|
328
|
+
type StdioOptionsProperty<IsSync extends boolean = boolean> =
|
|
329
|
+
| SimpleStdioOption<IsSync, false, false>
|
|
330
|
+
| StdioOptionsArray<IsSync>;
|
|
331
|
+
|
|
332
|
+
// Message when the `serialization` option is `'advanced'`
|
|
333
|
+
type AdvancedMessage =
|
|
334
|
+
| string
|
|
335
|
+
| number
|
|
336
|
+
| boolean
|
|
337
|
+
| null
|
|
338
|
+
| object;
|
|
128
339
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
340
|
+
// Message when the `serialization` option is `'json'`
|
|
341
|
+
type JsonMessage =
|
|
342
|
+
| string
|
|
343
|
+
| number
|
|
344
|
+
| boolean
|
|
345
|
+
| null
|
|
346
|
+
| readonly JsonMessage[]
|
|
347
|
+
| {readonly [key: string | number]: JsonMessage};
|
|
348
|
+
|
|
349
|
+
/**
|
|
350
|
+
Type of messages exchanged between a process and its subprocess using `sendMessage()`, `getOneMessage()` and `getEachMessage()`.
|
|
351
|
+
|
|
352
|
+
This requires the `ipc` option to be `true`. The type of `message` depends on the `serialization` option.
|
|
353
|
+
*/
|
|
354
|
+
type Message<
|
|
355
|
+
Serialization extends Options['serialization'] = Options['serialization'],
|
|
356
|
+
> = Serialization extends 'json' ? JsonMessage : AdvancedMessage;
|
|
357
|
+
|
|
358
|
+
/**
|
|
359
|
+
Options to `sendMessage()` and `subprocess.sendMessage()`
|
|
360
|
+
*/
|
|
361
|
+
type SendMessageOptions = {
|
|
362
|
+
/**
|
|
363
|
+
Throw when the other process is not receiving or listening to messages.
|
|
364
|
+
|
|
365
|
+
@default false
|
|
366
|
+
*/
|
|
367
|
+
readonly strict?: boolean;
|
|
368
|
+
};
|
|
369
|
+
|
|
370
|
+
/**
|
|
371
|
+
Options to `getOneMessage()` and `subprocess.getOneMessage()`
|
|
372
|
+
*/
|
|
373
|
+
type GetOneMessageOptions<
|
|
374
|
+
Serialization extends Options['serialization'],
|
|
375
|
+
> = {
|
|
376
|
+
/**
|
|
377
|
+
Ignore any `message` that returns `false`.
|
|
378
|
+
*/
|
|
379
|
+
readonly filter?: (message: Message<Serialization>) => boolean;
|
|
380
|
+
|
|
381
|
+
/**
|
|
382
|
+
Keep the subprocess alive while `getOneMessage()` is waiting.
|
|
383
|
+
|
|
384
|
+
@default true
|
|
385
|
+
*/
|
|
386
|
+
readonly reference?: boolean;
|
|
387
|
+
};
|
|
388
|
+
|
|
389
|
+
/**
|
|
390
|
+
Options to `getEachMessage()` and `subprocess.getEachMessage()`
|
|
391
|
+
*/
|
|
392
|
+
type GetEachMessageOptions = {
|
|
393
|
+
/**
|
|
394
|
+
Keep the subprocess alive while `getEachMessage()` is waiting.
|
|
395
|
+
|
|
396
|
+
@default true
|
|
397
|
+
*/
|
|
398
|
+
readonly reference?: boolean;
|
|
399
|
+
};
|
|
400
|
+
|
|
401
|
+
// IPC methods in the subprocess
|
|
402
|
+
type IpcMethods<
|
|
403
|
+
IpcEnabled extends boolean,
|
|
404
|
+
Serialization extends Options['serialization'],
|
|
405
|
+
> = IpcEnabled extends true
|
|
406
|
+
? {
|
|
407
|
+
/**
|
|
408
|
+
Send a `message` to the subprocess.
|
|
409
|
+
|
|
410
|
+
This requires the `ipc` option to be `true`. The type of `message` depends on the `serialization` option.
|
|
411
|
+
*/
|
|
412
|
+
sendMessage(message: Message<Serialization>, sendMessageOptions?: SendMessageOptions): Promise<void>;
|
|
413
|
+
|
|
414
|
+
/**
|
|
415
|
+
Receive a single `message` from the subprocess.
|
|
416
|
+
|
|
417
|
+
This requires the `ipc` option to be `true`. The type of `message` depends on the `serialization` option.
|
|
418
|
+
*/
|
|
419
|
+
getOneMessage(getOneMessageOptions?: GetOneMessageOptions<Serialization>): Promise<Message<Serialization>>;
|
|
420
|
+
|
|
421
|
+
/**
|
|
422
|
+
Iterate over each `message` from the subprocess.
|
|
423
|
+
|
|
424
|
+
This requires the `ipc` option to be `true`. The type of `message` depends on the `serialization` option.
|
|
425
|
+
*/
|
|
426
|
+
getEachMessage(getEachMessageOptions?: GetEachMessageOptions): AsyncIterableIterator<Message<Serialization>>;
|
|
427
|
+
}
|
|
428
|
+
// Those methods only work if the `ipc` option is `true`.
|
|
429
|
+
// At runtime, they are actually defined, in order to provide with a nice error message.
|
|
430
|
+
// At type check time, they are typed as `undefined` to prevent calling them.
|
|
431
|
+
: {
|
|
432
|
+
sendMessage: undefined;
|
|
433
|
+
getOneMessage: undefined;
|
|
434
|
+
getEachMessage: undefined;
|
|
435
|
+
};
|
|
436
|
+
|
|
437
|
+
// Whether IPC is enabled, based on the `ipc`, `ipcInput` and `gracefulCancel` options
|
|
438
|
+
type HasIpc<OptionsType extends Options> = HasIpcOption<
|
|
439
|
+
OptionsType['ipc'],
|
|
440
|
+
'ipcInput' extends keyof OptionsType ? OptionsType['ipcInput'] : undefined,
|
|
441
|
+
'gracefulCancel' extends keyof OptionsType ? OptionsType['gracefulCancel'] : undefined
|
|
442
|
+
>;
|
|
443
|
+
|
|
444
|
+
type HasIpcOption<
|
|
445
|
+
IpcOption extends Options['ipc'],
|
|
446
|
+
IpcInputOption extends Options['ipcInput'],
|
|
447
|
+
GracefulCancelOption extends Options['gracefulCancel'],
|
|
448
|
+
> = IpcOption extends true
|
|
449
|
+
? true
|
|
450
|
+
: IpcOption extends false
|
|
451
|
+
? false
|
|
452
|
+
: IpcInputOption extends undefined
|
|
453
|
+
? GracefulCancelOption extends true
|
|
454
|
+
? true
|
|
455
|
+
: false
|
|
456
|
+
: true;
|
|
457
|
+
|
|
458
|
+
type FileDescriptorOption = `fd${number}`;
|
|
459
|
+
|
|
460
|
+
// `from` option of `subprocess.readable|duplex|iterable|pipe()`
|
|
461
|
+
// Also used by fd-specific options
|
|
462
|
+
type FromOption = 'stdout' | 'stderr' | 'all' | FileDescriptorOption;
|
|
463
|
+
|
|
464
|
+
// `to` option of `subprocess.writable|duplex|pipe()`
|
|
465
|
+
type ToOption = 'stdin' | FileDescriptorOption;
|
|
466
|
+
|
|
467
|
+
// Options which can be fd-specific like `{verbose: {stdout: 'none', stderr: 'full'}}`
|
|
468
|
+
type FdGenericOption<OptionType> = OptionType | GenericOptionObject<OptionType>;
|
|
469
|
+
|
|
470
|
+
type GenericOptionObject<OptionType> = {
|
|
471
|
+
readonly [FdName in GenericFromOption]?: OptionType
|
|
472
|
+
};
|
|
473
|
+
|
|
474
|
+
type GenericFromOption = FromOption | 'ipc';
|
|
475
|
+
|
|
476
|
+
// Retrieve fd-specific option's value
|
|
477
|
+
type FdSpecificOption<
|
|
478
|
+
GenericOption extends FdGenericOption<unknown>,
|
|
479
|
+
FdNumber extends string,
|
|
480
|
+
> = GenericOption extends GenericOptionObject<unknown>
|
|
481
|
+
? FdSpecificObjectOption<GenericOption, FdNumber>
|
|
482
|
+
: GenericOption;
|
|
483
|
+
|
|
484
|
+
type FdSpecificObjectOption<
|
|
485
|
+
GenericOption extends GenericOptionObject<unknown>,
|
|
486
|
+
FdNumber extends string,
|
|
487
|
+
> = keyof GenericOption extends GenericFromOption
|
|
488
|
+
? FdNumberToFromOption<FdNumber, keyof GenericOption> extends never
|
|
489
|
+
? undefined
|
|
490
|
+
: GenericOption[FdNumberToFromOption<FdNumber, keyof GenericOption>]
|
|
491
|
+
: GenericOption;
|
|
492
|
+
|
|
493
|
+
type FdNumberToFromOption<
|
|
494
|
+
FdNumber extends string,
|
|
495
|
+
GenericOptionKeys extends GenericFromOption,
|
|
496
|
+
> = FdNumber extends '1'
|
|
497
|
+
? 'stdout' extends GenericOptionKeys
|
|
498
|
+
? 'stdout'
|
|
499
|
+
: 'fd1' extends GenericOptionKeys
|
|
500
|
+
? 'fd1'
|
|
501
|
+
: 'all' extends GenericOptionKeys
|
|
502
|
+
? 'all'
|
|
503
|
+
: never
|
|
504
|
+
: FdNumber extends '2'
|
|
505
|
+
? 'stderr' extends GenericOptionKeys
|
|
506
|
+
? 'stderr'
|
|
507
|
+
: 'fd2' extends GenericOptionKeys
|
|
508
|
+
? 'fd2'
|
|
509
|
+
: 'all' extends GenericOptionKeys
|
|
510
|
+
? 'all'
|
|
511
|
+
: never
|
|
512
|
+
: `fd${FdNumber}` extends GenericOptionKeys
|
|
513
|
+
? `fd${FdNumber}`
|
|
514
|
+
: 'ipc' extends GenericOptionKeys
|
|
515
|
+
? 'ipc'
|
|
516
|
+
: never;
|
|
517
|
+
|
|
518
|
+
// `result.*` defined only on failure, i.e. on `error.*`
|
|
519
|
+
type ErrorProperties =
|
|
520
|
+
| 'name'
|
|
521
|
+
| 'message'
|
|
522
|
+
| 'stack'
|
|
523
|
+
| 'cause'
|
|
524
|
+
| 'shortMessage'
|
|
525
|
+
| 'originalMessage'
|
|
526
|
+
| 'code';
|
|
527
|
+
|
|
528
|
+
// `options.stdio`, normalized as an array
|
|
529
|
+
type StdioOptionNormalizedArray<OptionsType extends CommonOptions> = StdioOptionNormalized<OptionsType['stdio']>;
|
|
530
|
+
|
|
531
|
+
type StdioOptionNormalized<StdioOption extends CommonOptions['stdio']> = StdioOption extends StdioOptionsArray
|
|
532
|
+
? StdioOption
|
|
533
|
+
: StdioOption extends StdinOptionCommon
|
|
534
|
+
? StdioOption extends StdoutStderrOptionCommon
|
|
535
|
+
? readonly [StdioOption, StdioOption, StdioOption]
|
|
536
|
+
: DefaultStdioOption
|
|
537
|
+
: DefaultStdioOption;
|
|
538
|
+
|
|
539
|
+
// `options.stdio` default value
|
|
540
|
+
type DefaultStdioOption = readonly ['pipe', 'pipe', 'pipe'];
|
|
541
|
+
|
|
542
|
+
// `options.stdin|stdout|stderr|stdio` for a given file descriptor
|
|
543
|
+
type FdStdioOption<
|
|
544
|
+
FdNumber extends string,
|
|
545
|
+
OptionsType extends CommonOptions,
|
|
546
|
+
> = FdStdioOptionProperty<FdNumber, OptionsType>;
|
|
547
|
+
|
|
548
|
+
type FdStdioOptionProperty<
|
|
549
|
+
FdNumber extends string,
|
|
550
|
+
OptionsType extends CommonOptions,
|
|
551
|
+
> = string extends FdNumber ? StdioOptionCommon
|
|
552
|
+
: FdNumber extends keyof StandardStreams
|
|
553
|
+
? StandardStreams[FdNumber] extends keyof OptionsType
|
|
554
|
+
? OptionsType[StandardStreams[FdNumber]] extends undefined
|
|
555
|
+
? FdStdioArrayOption<FdNumber, OptionsType>
|
|
556
|
+
: OptionsType[StandardStreams[FdNumber]]
|
|
557
|
+
: FdStdioArrayOption<FdNumber, OptionsType>
|
|
558
|
+
: FdStdioArrayOption<FdNumber, OptionsType>;
|
|
559
|
+
|
|
560
|
+
// `options.stdio[FdNumber]`, excluding `options.stdin|stdout|stderr`
|
|
561
|
+
type FdStdioArrayOption<
|
|
562
|
+
FdNumber extends string,
|
|
563
|
+
OptionsType extends CommonOptions,
|
|
564
|
+
> = FdStdioArrayOptionProperty<FdNumber, StdioOptionNormalizedArray<OptionsType>>;
|
|
565
|
+
|
|
566
|
+
type FdStdioArrayOptionProperty<
|
|
567
|
+
FdNumber extends string,
|
|
568
|
+
StdioOptionsType,
|
|
569
|
+
> = string extends FdNumber
|
|
570
|
+
? StdioOptionCommon | undefined
|
|
571
|
+
: StdioOptionsType extends StdioOptionsArray
|
|
572
|
+
? FdNumber extends keyof StdioOptionsType
|
|
573
|
+
? StdioOptionsType[FdNumber]
|
|
574
|
+
: StdioOptionNormalizedArray<CommonOptions> extends StdioOptionsType
|
|
575
|
+
? StdioOptionsType[number]
|
|
576
|
+
: undefined
|
|
577
|
+
: undefined;
|
|
578
|
+
|
|
579
|
+
// Whether a file descriptor is in object mode
|
|
580
|
+
// I.e. whether `result.stdout|stderr|stdio|all` is an array of `unknown` due to `objectMode: true`
|
|
581
|
+
type IsObjectFd<
|
|
582
|
+
FdNumber extends string,
|
|
583
|
+
OptionsType extends CommonOptions,
|
|
584
|
+
> = IsObjectStdioOption<FdStdioOption<FdNumber, OptionsType>>;
|
|
585
|
+
|
|
586
|
+
type IsObjectStdioOption<StdioOptionType> = IsObjectStdioSingleOption<StdioSingleOptionItems<StdioOptionType>>;
|
|
587
|
+
|
|
588
|
+
type IsObjectStdioSingleOption<StdioSingleOptionType> = StdioSingleOptionType extends TransformCommon
|
|
589
|
+
? BooleanObjectMode<StdioSingleOptionType['objectMode']>
|
|
590
|
+
: StdioSingleOptionType extends DuplexTransform
|
|
591
|
+
? StdioSingleOptionType['transform']['readableObjectMode']
|
|
592
|
+
: false;
|
|
593
|
+
|
|
594
|
+
type BooleanObjectMode<ObjectModeOption extends boolean | undefined> = ObjectModeOption extends true ? true : false;
|
|
595
|
+
|
|
596
|
+
// Whether `result.stdio[FdNumber]` is an input stream
|
|
597
|
+
type IsInputFd<
|
|
598
|
+
FdNumber extends string,
|
|
599
|
+
OptionsType extends CommonOptions,
|
|
600
|
+
> = FdNumber extends '0'
|
|
601
|
+
? true
|
|
602
|
+
: Intersects<StdioSingleOptionItems<FdStdioArrayOption<FdNumber, OptionsType>>, InputStdioOption>;
|
|
603
|
+
|
|
604
|
+
// Whether `result.stdin|stdout|stderr|all|stdio[*]` is `undefined`
|
|
605
|
+
type IgnoresResultOutput<
|
|
606
|
+
FdNumber extends string,
|
|
607
|
+
OptionsType extends CommonOptions,
|
|
608
|
+
> = FdSpecificOption<OptionsType['buffer'], FdNumber> extends false
|
|
609
|
+
? true
|
|
610
|
+
: IsInputFd<FdNumber, OptionsType> extends true
|
|
611
|
+
? true
|
|
612
|
+
: IgnoresSubprocessOutput<FdNumber, OptionsType>;
|
|
613
|
+
|
|
614
|
+
// Whether `subprocess.stdout|stderr|all` is `undefined|null`
|
|
615
|
+
type IgnoresSubprocessOutput<
|
|
616
|
+
FdNumber extends string,
|
|
617
|
+
OptionsType extends CommonOptions,
|
|
618
|
+
> = IgnoresOutput<FdNumber, FdStdioOption<FdNumber, OptionsType>>;
|
|
619
|
+
|
|
620
|
+
type IgnoresOutput<
|
|
621
|
+
FdNumber extends string,
|
|
622
|
+
StdioOptionType,
|
|
623
|
+
> = StdioOptionType extends NoStreamStdioOption<FdNumber> ? true : false;
|
|
624
|
+
|
|
625
|
+
type DefaultEncodingOption = 'utf8';
|
|
626
|
+
type TextEncodingOption =
|
|
627
|
+
| DefaultEncodingOption
|
|
628
|
+
| 'utf16le';
|
|
629
|
+
|
|
630
|
+
type BufferEncodingOption = 'buffer';
|
|
631
|
+
type BinaryEncodingOption =
|
|
632
|
+
| BufferEncodingOption
|
|
140
633
|
| 'hex'
|
|
141
634
|
| 'base64'
|
|
142
635
|
| 'base64url'
|
|
143
|
-
| '
|
|
144
|
-
|
|
|
145
|
-
|
|
146
|
-
|
|
636
|
+
| 'latin1'
|
|
637
|
+
| 'ascii';
|
|
638
|
+
|
|
639
|
+
// `options.encoding`
|
|
640
|
+
type EncodingOption =
|
|
641
|
+
| TextEncodingOption
|
|
642
|
+
| BinaryEncodingOption
|
|
643
|
+
| undefined;
|
|
147
644
|
|
|
148
|
-
|
|
645
|
+
// `result.stdout|stderr|stdio`
|
|
646
|
+
type ResultStdioNotAll<
|
|
647
|
+
FdNumber extends string,
|
|
648
|
+
OptionsType extends CommonOptions,
|
|
649
|
+
> = ResultStdio<FdNumber, FdNumber, FdNumber, OptionsType>;
|
|
650
|
+
|
|
651
|
+
// `result.stdout|stderr|stdio|all`
|
|
652
|
+
type ResultStdio<
|
|
653
|
+
MainFdNumber extends string,
|
|
654
|
+
ObjectFdNumber extends string,
|
|
655
|
+
LinesFdNumber extends string,
|
|
656
|
+
OptionsType extends CommonOptions,
|
|
657
|
+
> = ResultStdioProperty<
|
|
658
|
+
ObjectFdNumber,
|
|
659
|
+
LinesFdNumber,
|
|
660
|
+
IgnoresResultOutput<MainFdNumber, OptionsType>,
|
|
661
|
+
OptionsType
|
|
662
|
+
>;
|
|
663
|
+
|
|
664
|
+
type ResultStdioProperty<
|
|
665
|
+
ObjectFdNumber extends string,
|
|
666
|
+
LinesFdNumber extends string,
|
|
667
|
+
StreamOutputIgnored,
|
|
668
|
+
OptionsType extends CommonOptions,
|
|
669
|
+
> = StreamOutputIgnored extends true
|
|
670
|
+
? undefined
|
|
671
|
+
: ResultStdioItem<
|
|
672
|
+
IsObjectFd<ObjectFdNumber, OptionsType>,
|
|
673
|
+
FdSpecificOption<OptionsType['lines'], LinesFdNumber>,
|
|
674
|
+
OptionsType['encoding']
|
|
675
|
+
>;
|
|
676
|
+
|
|
677
|
+
type ResultStdioItem<
|
|
678
|
+
IsObjectResult,
|
|
679
|
+
LinesOption extends boolean | undefined,
|
|
680
|
+
Encoding extends CommonOptions['encoding'],
|
|
681
|
+
> = IsObjectResult extends true ? unknown[]
|
|
682
|
+
: Encoding extends BufferEncodingOption
|
|
683
|
+
? Uint8Array
|
|
684
|
+
: LinesOption extends true
|
|
685
|
+
? Encoding extends BinaryEncodingOption
|
|
686
|
+
? string
|
|
687
|
+
: string[]
|
|
688
|
+
: string;
|
|
689
|
+
|
|
690
|
+
// `result.all`
|
|
691
|
+
type ResultAll<OptionsType extends CommonOptions> =
|
|
692
|
+
ResultAllProperty<OptionsType['all'], OptionsType>;
|
|
693
|
+
|
|
694
|
+
type ResultAllProperty<
|
|
695
|
+
AllOption extends CommonOptions['all'],
|
|
696
|
+
OptionsType extends CommonOptions,
|
|
697
|
+
> = AllOption extends true
|
|
698
|
+
? ResultStdio<
|
|
699
|
+
AllMainFd<OptionsType>,
|
|
700
|
+
AllObjectFd<OptionsType>,
|
|
701
|
+
AllLinesFd<OptionsType>,
|
|
702
|
+
OptionsType
|
|
703
|
+
>
|
|
704
|
+
: undefined;
|
|
705
|
+
|
|
706
|
+
type AllMainFd<OptionsType extends CommonOptions> =
|
|
707
|
+
IgnoresResultOutput<'1', OptionsType> extends true ? '2' : '1';
|
|
708
|
+
|
|
709
|
+
type AllObjectFd<OptionsType extends CommonOptions> =
|
|
710
|
+
IsObjectFd<'1', OptionsType> extends true ? '1' : '2';
|
|
711
|
+
|
|
712
|
+
type AllLinesFd<OptionsType extends CommonOptions> =
|
|
713
|
+
FdSpecificOption<OptionsType['lines'], '1'> extends true ? '1' : '2';
|
|
714
|
+
|
|
715
|
+
// `result.stdio`
|
|
716
|
+
type ResultStdioArray<OptionsType extends CommonOptions> =
|
|
717
|
+
MapResultStdio<StdioOptionNormalizedArray<OptionsType>, OptionsType>;
|
|
718
|
+
|
|
719
|
+
type MapResultStdio<
|
|
720
|
+
StdioOptionsArrayType,
|
|
721
|
+
OptionsType extends CommonOptions,
|
|
722
|
+
> = {
|
|
723
|
+
-readonly [FdNumber in keyof StdioOptionsArrayType]: ResultStdioNotAll<
|
|
724
|
+
FdNumber extends string ? FdNumber : string,
|
|
725
|
+
OptionsType
|
|
726
|
+
>
|
|
727
|
+
};
|
|
728
|
+
|
|
729
|
+
// `result.ipcOutput`
|
|
730
|
+
// This is empty unless the `ipc` option is `true`.
|
|
731
|
+
// Also, this is empty if the `buffer` option is `false`.
|
|
732
|
+
type ResultIpcOutput<
|
|
733
|
+
IsSync,
|
|
734
|
+
OptionsType extends CommonOptions,
|
|
735
|
+
> = IsSync extends true
|
|
736
|
+
? []
|
|
737
|
+
: ResultIpcAsync<
|
|
738
|
+
FdSpecificOption<OptionsType['buffer'], 'ipc'>,
|
|
739
|
+
HasIpc<StricterOptions<OptionsType, Options>>,
|
|
740
|
+
OptionsType['serialization']
|
|
741
|
+
>;
|
|
742
|
+
|
|
743
|
+
type ResultIpcAsync<
|
|
744
|
+
BufferOption extends boolean | undefined,
|
|
745
|
+
IpcEnabled extends boolean,
|
|
746
|
+
SerializationOption extends CommonOptions['serialization'],
|
|
747
|
+
> = BufferOption extends false
|
|
748
|
+
? []
|
|
749
|
+
: IpcEnabled extends true
|
|
750
|
+
? Array<Message<SerializationOption>>
|
|
751
|
+
: [];
|
|
752
|
+
|
|
753
|
+
declare abstract class CommonResult<
|
|
754
|
+
IsSync extends boolean,
|
|
755
|
+
OptionsType extends CommonOptions,
|
|
756
|
+
> {
|
|
149
757
|
/**
|
|
150
|
-
|
|
151
|
-
- the spawned process is [`detached`](https://nodejs.org/api/child_process.html#child_process_options_detached)
|
|
152
|
-
- the parent process is terminated abruptly, for example, with `SIGKILL` as opposed to `SIGTERM` or a normal exit
|
|
758
|
+
The output of the subprocess on [`stdout`](https://en.wikipedia.org/wiki/Standard_streams#Standard_output_(stdout)).
|
|
153
759
|
|
|
154
|
-
|
|
760
|
+
This is `undefined` if the `stdout` option is set to only `'inherit'`, `'ignore'`, `Writable` or `integer`, or if the `buffer` option is `false`.
|
|
761
|
+
|
|
762
|
+
This is an array if the `lines` option is `true`, or if the `stdout` option is a transform in object mode.
|
|
155
763
|
*/
|
|
156
|
-
|
|
764
|
+
stdout: ResultStdioNotAll<'1', OptionsType>;
|
|
157
765
|
|
|
158
766
|
/**
|
|
159
|
-
|
|
767
|
+
The output of the subprocess on [`stderr`](https://en.wikipedia.org/wiki/Standard_streams#Standard_error_(stderr)).
|
|
160
768
|
|
|
161
|
-
|
|
769
|
+
This is `undefined` if the `stderr` option is set to only `'inherit'`, `'ignore'`, `Writable` or `integer`, or if the `buffer` option is `false`.
|
|
162
770
|
|
|
163
|
-
|
|
771
|
+
This is an array if the `lines` option is `true`, or if the `stderr` option is a transform in object mode.
|
|
164
772
|
*/
|
|
165
|
-
|
|
773
|
+
stderr: ResultStdioNotAll<'2', OptionsType>;
|
|
166
774
|
|
|
167
775
|
/**
|
|
168
|
-
|
|
776
|
+
The output of the subprocess with `result.stdout` and `result.stderr` interleaved.
|
|
169
777
|
|
|
170
|
-
|
|
778
|
+
This requires the `all` option to be `true`.
|
|
779
|
+
|
|
780
|
+
This is `undefined` if both `stdout` and `stderr` options are set to only `'inherit'`, `'ignore'`, `Writable` or `integer`, or if the `buffer` option is `false`.
|
|
781
|
+
|
|
782
|
+
This is an array if the `lines` option is `true`, or if either the `stdout` or `stderr` option is a transform in object mode.
|
|
171
783
|
*/
|
|
172
|
-
|
|
784
|
+
all: ResultAll<OptionsType>;
|
|
173
785
|
|
|
174
786
|
/**
|
|
175
|
-
|
|
787
|
+
The output of the subprocess on `stdin`, `stdout`, `stderr` and other file descriptors.
|
|
176
788
|
|
|
177
|
-
|
|
789
|
+
Items are `undefined` when their corresponding `stdio` option is set to only `'inherit'`, `'ignore'`, `Writable` or `integer`, or if the `buffer` option is `false`.
|
|
178
790
|
|
|
179
|
-
|
|
791
|
+
Items are arrays when their corresponding `stdio` option is a transform in object mode.
|
|
792
|
+
*/
|
|
793
|
+
stdio: ResultStdioArray<OptionsType>;
|
|
180
794
|
|
|
181
|
-
|
|
795
|
+
/**
|
|
796
|
+
All the messages sent by the subprocess to the current process.
|
|
182
797
|
|
|
183
|
-
|
|
798
|
+
This is empty unless the `ipc` option is `true`. Also, this is empty if the `buffer` option is `false`.
|
|
184
799
|
*/
|
|
185
|
-
|
|
800
|
+
ipcOutput: ResultIpcOutput<IsSync, OptionsType>;
|
|
186
801
|
|
|
187
802
|
/**
|
|
188
|
-
|
|
803
|
+
Results of the other subprocesses that were piped into this subprocess.
|
|
189
804
|
|
|
190
|
-
|
|
805
|
+
This array is initially empty and is populated each time the `subprocess.pipe()` method resolves.
|
|
806
|
+
*/
|
|
807
|
+
pipedFrom: Unless<IsSync, Result$1[], []>;
|
|
191
808
|
|
|
192
|
-
|
|
809
|
+
/**
|
|
810
|
+
The file and arguments that were run.
|
|
193
811
|
*/
|
|
194
|
-
|
|
812
|
+
command: string;
|
|
195
813
|
|
|
196
814
|
/**
|
|
197
|
-
Same
|
|
815
|
+
Same as `command` but escaped.
|
|
816
|
+
*/
|
|
817
|
+
escapedCommand: string;
|
|
198
818
|
|
|
199
|
-
|
|
819
|
+
/**
|
|
820
|
+
The current directory in which the command was run.
|
|
821
|
+
*/
|
|
822
|
+
cwd: string;
|
|
823
|
+
|
|
824
|
+
/**
|
|
825
|
+
Duration of the subprocess, in milliseconds.
|
|
200
826
|
*/
|
|
201
|
-
|
|
827
|
+
durationMs: number;
|
|
202
828
|
|
|
203
829
|
/**
|
|
204
|
-
|
|
830
|
+
Whether the subprocess failed to run.
|
|
205
831
|
|
|
206
|
-
|
|
832
|
+
When this is `true`, the result is an `ExecaError` instance with additional error-related properties.
|
|
207
833
|
*/
|
|
208
|
-
|
|
834
|
+
failed: boolean;
|
|
209
835
|
|
|
210
836
|
/**
|
|
211
|
-
|
|
837
|
+
Whether the subprocess timed out due to the `timeout` option.
|
|
838
|
+
*/
|
|
839
|
+
timedOut: boolean;
|
|
212
840
|
|
|
213
|
-
|
|
841
|
+
/**
|
|
842
|
+
Whether the subprocess was canceled using the `cancelSignal` option.
|
|
214
843
|
*/
|
|
215
|
-
|
|
844
|
+
isCanceled: boolean;
|
|
216
845
|
|
|
217
846
|
/**
|
|
218
|
-
|
|
847
|
+
Whether the subprocess was canceled using both the `cancelSignal` and the `gracefulCancel` options.
|
|
848
|
+
*/
|
|
849
|
+
isGracefullyCanceled: boolean;
|
|
219
850
|
|
|
220
|
-
|
|
851
|
+
/**
|
|
852
|
+
Whether the subprocess failed because its output was larger than the `maxBuffer` option.
|
|
221
853
|
*/
|
|
222
|
-
|
|
854
|
+
isMaxBuffer: boolean;
|
|
855
|
+
|
|
856
|
+
/**
|
|
857
|
+
Whether the subprocess was terminated by a signal (like `SIGTERM`) sent by either:
|
|
858
|
+
- The current process.
|
|
859
|
+
- Another process. This case is [not supported on Windows](https://nodejs.org/api/process.html#signal-events).
|
|
860
|
+
*/
|
|
861
|
+
isTerminated: boolean;
|
|
862
|
+
|
|
863
|
+
/**
|
|
864
|
+
Whether the subprocess was terminated by the `SIGKILL` signal sent by the `forceKillAfterDelay` option.
|
|
865
|
+
*/
|
|
866
|
+
isForcefullyTerminated: boolean;
|
|
223
867
|
|
|
224
868
|
/**
|
|
225
|
-
|
|
869
|
+
The numeric [exit code](https://en.wikipedia.org/wiki/Exit_status) of the subprocess that was run.
|
|
870
|
+
|
|
871
|
+
This is `undefined` when the subprocess could not be spawned or was terminated by a signal.
|
|
872
|
+
*/
|
|
873
|
+
exitCode?: number;
|
|
874
|
+
|
|
875
|
+
/**
|
|
876
|
+
The name of the signal (like `SIGTERM`) that terminated the subprocess, sent by either:
|
|
877
|
+
- The current process.
|
|
878
|
+
- Another process. This case is [not supported on Windows](https://nodejs.org/api/process.html#signal-events).
|
|
879
|
+
|
|
880
|
+
If a signal terminated the subprocess, this property is defined and included in the error message. Otherwise it is `undefined`.
|
|
881
|
+
*/
|
|
882
|
+
signal?: keyof SignalConstants;
|
|
883
|
+
|
|
884
|
+
/**
|
|
885
|
+
A human-friendly description of the signal that was used to terminate the subprocess.
|
|
886
|
+
|
|
887
|
+
If a signal terminated the subprocess, this property is defined and included in the error message. Otherwise it is `undefined`. It is also `undefined` when the signal is very uncommon which should seldomly happen.
|
|
888
|
+
*/
|
|
889
|
+
signalDescription?: string;
|
|
890
|
+
|
|
891
|
+
/**
|
|
892
|
+
Error message when the subprocess failed to run.
|
|
893
|
+
*/
|
|
894
|
+
message?: string;
|
|
895
|
+
|
|
896
|
+
/**
|
|
897
|
+
This is the same as `error.message` except it does not include the subprocess output.
|
|
898
|
+
*/
|
|
899
|
+
shortMessage?: string;
|
|
900
|
+
|
|
901
|
+
/**
|
|
902
|
+
Original error message. This is the same as `error.message` excluding the subprocess output and some additional information added by Execa.
|
|
903
|
+
|
|
904
|
+
This exists only in specific instances, such as during a timeout.
|
|
905
|
+
*/
|
|
906
|
+
originalMessage?: string;
|
|
907
|
+
|
|
908
|
+
/**
|
|
909
|
+
Underlying error, if there is one. For example, this is set by `subprocess.kill(error)`.
|
|
910
|
+
|
|
911
|
+
This is usually an `Error` instance.
|
|
912
|
+
*/
|
|
913
|
+
cause?: unknown;
|
|
914
|
+
|
|
915
|
+
/**
|
|
916
|
+
Node.js-specific [error code](https://nodejs.org/api/errors.html#errorcode), when available.
|
|
917
|
+
*/
|
|
918
|
+
code?: string;
|
|
919
|
+
|
|
920
|
+
// We cannot `extend Error` because `message` must be optional. So we copy its types here.
|
|
921
|
+
readonly name?: Error['name'];
|
|
922
|
+
stack?: Error['stack'];
|
|
923
|
+
}
|
|
924
|
+
|
|
925
|
+
type SuccessResult$1<
|
|
926
|
+
IsSync extends boolean = boolean,
|
|
927
|
+
OptionsType extends CommonOptions = CommonOptions,
|
|
928
|
+
> = InstanceType<typeof CommonResult<IsSync, OptionsType>> & OmitErrorIfReject<OptionsType['reject']>;
|
|
929
|
+
|
|
930
|
+
type OmitErrorIfReject<RejectOption extends CommonOptions['reject']> = {
|
|
931
|
+
[ErrorProperty in ErrorProperties]: RejectOption extends false ? unknown : never
|
|
932
|
+
};
|
|
933
|
+
|
|
934
|
+
/**
|
|
935
|
+
Result of a subprocess successful execution.
|
|
936
|
+
|
|
937
|
+
When the subprocess fails, it is rejected with an `ExecaError` instead.
|
|
938
|
+
*/
|
|
939
|
+
type Result$1<OptionsType extends Options = Options> = SuccessResult$1<false, OptionsType>;
|
|
940
|
+
|
|
941
|
+
/**
|
|
942
|
+
Result of a subprocess successful execution.
|
|
943
|
+
|
|
944
|
+
When the subprocess fails, it is rejected with an `ExecaError` instead.
|
|
945
|
+
*/
|
|
946
|
+
type SyncResult<OptionsType extends SyncOptions = SyncOptions> = SuccessResult$1<true, OptionsType>;
|
|
947
|
+
|
|
948
|
+
type VerboseOption = FdGenericOption<
|
|
949
|
+
| 'none'
|
|
950
|
+
| 'short'
|
|
951
|
+
| 'full'
|
|
952
|
+
| VerboseFunction
|
|
953
|
+
>;
|
|
954
|
+
|
|
955
|
+
type VerboseFunction = (verboseLine: string, verboseObject: MinimalVerboseObject) => string | void;
|
|
956
|
+
|
|
957
|
+
type GenericVerboseObject = {
|
|
958
|
+
/**
|
|
959
|
+
Event type. This can be:
|
|
960
|
+
- `'command'`: subprocess start
|
|
961
|
+
- `'output'`: `stdout`/`stderr` output
|
|
962
|
+
- `'ipc'`: IPC output
|
|
963
|
+
- `'error'`: subprocess failure
|
|
964
|
+
- `'duration'`: subprocess success or failure
|
|
965
|
+
*/
|
|
966
|
+
type: 'command' | 'output' | 'ipc' | 'error' | 'duration';
|
|
967
|
+
|
|
968
|
+
/**
|
|
969
|
+
Depending on `verboseObject.type`, this is:
|
|
970
|
+
- `'command'`: the `result.escapedCommand`
|
|
971
|
+
- `'output'`: one line from `result.stdout` or `result.stderr`
|
|
972
|
+
- `'ipc'`: one IPC message from `result.ipcOutput`
|
|
973
|
+
- `'error'`: the `error.shortMessage`
|
|
974
|
+
- `'duration'`: the `result.durationMs`
|
|
975
|
+
*/
|
|
976
|
+
message: string;
|
|
977
|
+
|
|
978
|
+
/**
|
|
979
|
+
The file and arguments that were run. This is the same as `result.escapedCommand`.
|
|
980
|
+
*/
|
|
981
|
+
escapedCommand: string;
|
|
982
|
+
|
|
983
|
+
/**
|
|
984
|
+
Serial number identifying the subprocess within the current process. It is incremented from `'0'`.
|
|
985
|
+
|
|
986
|
+
This is helpful when multiple subprocesses are running at the same time.
|
|
987
|
+
|
|
988
|
+
This is similar to a [PID](https://en.wikipedia.org/wiki/Process_identifier) except it has no maximum limit, which means it never repeats. Also, it is usually shorter.
|
|
989
|
+
*/
|
|
990
|
+
commandId: string;
|
|
991
|
+
|
|
992
|
+
/**
|
|
993
|
+
Event date/time.
|
|
994
|
+
*/
|
|
995
|
+
timestamp: Date;
|
|
996
|
+
|
|
997
|
+
/**
|
|
998
|
+
Whether another subprocess is piped into this subprocess. This is `false` when `result.pipedFrom` is empty.
|
|
999
|
+
*/
|
|
1000
|
+
piped: boolean;
|
|
1001
|
+
};
|
|
1002
|
+
|
|
1003
|
+
type MinimalVerboseObject = GenericVerboseObject & {
|
|
1004
|
+
// We cannot use the `CommonOptions` type because it would make this type recursive
|
|
1005
|
+
options: object;
|
|
1006
|
+
result?: never;
|
|
1007
|
+
};
|
|
1008
|
+
|
|
1009
|
+
type CommonOptions<IsSync extends boolean = boolean> = {
|
|
1010
|
+
/**
|
|
1011
|
+
Prefer locally installed binaries when looking for a binary to execute.
|
|
1012
|
+
|
|
1013
|
+
@default `true` with `$`, `false` otherwise
|
|
1014
|
+
*/
|
|
1015
|
+
readonly preferLocal?: boolean;
|
|
1016
|
+
|
|
1017
|
+
/**
|
|
1018
|
+
Preferred path to find locally installed binaries, when using the `preferLocal` option.
|
|
1019
|
+
|
|
1020
|
+
@default `cwd` option
|
|
1021
|
+
*/
|
|
1022
|
+
readonly localDir?: string | URL;
|
|
1023
|
+
|
|
1024
|
+
/**
|
|
1025
|
+
If `true`, runs with Node.js. The first argument must be a Node.js file.
|
|
1026
|
+
|
|
1027
|
+
The subprocess inherits the current Node.js [CLI flags](https://nodejs.org/api/cli.html#options) and version. This can be overridden using the `nodeOptions` and `nodePath` options.
|
|
1028
|
+
|
|
1029
|
+
@default `true` with `execaNode()`, `false` otherwise
|
|
1030
|
+
*/
|
|
1031
|
+
readonly node?: boolean;
|
|
1032
|
+
|
|
1033
|
+
/**
|
|
1034
|
+
List of [CLI flags](https://nodejs.org/api/cli.html#cli_options) passed to the Node.js executable.
|
|
1035
|
+
|
|
1036
|
+
Requires the `node` option to be `true`.
|
|
1037
|
+
|
|
1038
|
+
@default [`process.execArgv`](https://nodejs.org/api/process.html#process_process_execargv) (current Node.js CLI flags)
|
|
1039
|
+
*/
|
|
1040
|
+
readonly nodeOptions?: readonly string[];
|
|
1041
|
+
|
|
1042
|
+
/**
|
|
1043
|
+
Path to the Node.js executable.
|
|
1044
|
+
|
|
1045
|
+
Requires the `node` option to be `true`.
|
|
1046
|
+
|
|
1047
|
+
@default [`process.execPath`](https://nodejs.org/api/process.html#process_process_execpath) (current Node.js executable)
|
|
1048
|
+
*/
|
|
1049
|
+
readonly nodePath?: string | URL;
|
|
1050
|
+
|
|
1051
|
+
/**
|
|
1052
|
+
If `true`, runs the command inside of a [shell](https://en.wikipedia.org/wiki/Shell_(computing)).
|
|
1053
|
+
|
|
1054
|
+
Uses [`/bin/sh`](https://en.wikipedia.org/wiki/Unix_shell) on UNIX and [`cmd.exe`](https://en.wikipedia.org/wiki/Cmd.exe) on Windows. A different shell can be specified as a string. The shell should understand the `-c` switch on UNIX or `/d /s /c` on Windows.
|
|
1055
|
+
|
|
1056
|
+
We recommend against using this option.
|
|
226
1057
|
|
|
227
1058
|
@default false
|
|
228
1059
|
*/
|
|
229
|
-
readonly
|
|
1060
|
+
readonly shell?: boolean | string | URL;
|
|
230
1061
|
|
|
231
1062
|
/**
|
|
232
|
-
|
|
1063
|
+
Current [working directory](https://en.wikipedia.org/wiki/Working_directory) of the subprocess.
|
|
233
1064
|
|
|
234
|
-
|
|
1065
|
+
This is also used to resolve the `nodePath` option when it is a relative path.
|
|
1066
|
+
|
|
1067
|
+
@default process.cwd()
|
|
235
1068
|
*/
|
|
236
|
-
readonly
|
|
1069
|
+
readonly cwd?: string | URL;
|
|
237
1070
|
|
|
238
1071
|
/**
|
|
239
|
-
|
|
1072
|
+
[Environment variables](https://en.wikipedia.org/wiki/Environment_variable).
|
|
1073
|
+
|
|
1074
|
+
Unless the `extendEnv` option is `false`, the subprocess also uses the current process' environment variables ([`process.env`](https://nodejs.org/api/process.html#processenv)).
|
|
1075
|
+
|
|
1076
|
+
@default [process.env](https://nodejs.org/api/process.html#processenv)
|
|
1077
|
+
*/
|
|
1078
|
+
readonly env?: Readonly<Partial<Record<string, string>>>;
|
|
1079
|
+
|
|
1080
|
+
/**
|
|
1081
|
+
If `true`, the subprocess uses both the `env` option and the current process' environment variables ([`process.env`](https://nodejs.org/api/process.html#processenv)).
|
|
1082
|
+
If `false`, only the `env` option is used, not `process.env`.
|
|
240
1083
|
|
|
241
1084
|
@default true
|
|
242
1085
|
*/
|
|
243
1086
|
readonly extendEnv?: boolean;
|
|
244
1087
|
|
|
245
1088
|
/**
|
|
246
|
-
|
|
1089
|
+
Write some input to the subprocess' [`stdin`](https://en.wikipedia.org/wiki/Standard_streams#Standard_input_(stdin)).
|
|
247
1090
|
|
|
248
|
-
|
|
1091
|
+
See also the `inputFile` and `stdin` options.
|
|
249
1092
|
*/
|
|
250
|
-
readonly
|
|
1093
|
+
readonly input?: string | Uint8Array | Readable;
|
|
251
1094
|
|
|
252
1095
|
/**
|
|
253
|
-
|
|
1096
|
+
Use a file as input to the subprocess' [`stdin`](https://en.wikipedia.org/wiki/Standard_streams#Standard_input_(stdin)).
|
|
254
1097
|
|
|
255
|
-
|
|
1098
|
+
See also the `input` and `stdin` options.
|
|
256
1099
|
*/
|
|
257
|
-
readonly
|
|
1100
|
+
readonly inputFile?: string | URL;
|
|
258
1101
|
|
|
259
1102
|
/**
|
|
260
|
-
|
|
1103
|
+
How to setup the subprocess' [standard input](https://en.wikipedia.org/wiki/Standard_streams#Standard_input_(stdin)). This can be `'pipe'`, `'overlapped'`, `'ignore`, `'inherit'`, a file descriptor integer, a Node.js `Readable` stream, a web `ReadableStream`, a `{ file: 'path' }` object, a file URL, an `Iterable`, an `AsyncIterable`, an `Uint8Array`, a generator function, a `Duplex` or a web `TransformStream`.
|
|
1104
|
+
|
|
1105
|
+
This can be an array of values such as `['inherit', 'pipe']` or `[fileUrl, 'pipe']`.
|
|
1106
|
+
|
|
1107
|
+
@default `'inherit'` with `$`, `'pipe'` otherwise
|
|
261
1108
|
*/
|
|
262
|
-
readonly
|
|
1109
|
+
readonly stdin?: StdinOptionCommon<IsSync>;
|
|
263
1110
|
|
|
264
1111
|
/**
|
|
265
|
-
|
|
1112
|
+
How to setup the subprocess' [standard output](https://en.wikipedia.org/wiki/Standard_streams#Standard_input_(stdin)). This can be `'pipe'`, `'overlapped'`, `'ignore`, `'inherit'`, a file descriptor integer, a Node.js `Writable` stream, a web `WritableStream`, a `{ file: 'path' }` object, a file URL, a generator function, a `Duplex` or a web `TransformStream`.
|
|
1113
|
+
|
|
1114
|
+
This can be an array of values such as `['inherit', 'pipe']` or `[fileUrl, 'pipe']`.
|
|
266
1115
|
|
|
267
1116
|
@default 'pipe'
|
|
268
1117
|
*/
|
|
269
|
-
readonly
|
|
1118
|
+
readonly stdout?: StdoutStderrOptionCommon<IsSync>;
|
|
270
1119
|
|
|
271
1120
|
/**
|
|
272
|
-
|
|
273
|
-
- `json`: Uses `JSON.stringify()` and `JSON.parse()`.
|
|
274
|
-
- `advanced`: Uses [`v8.serialize()`](https://nodejs.org/api/v8.html#v8_v8_serialize_value)
|
|
1121
|
+
How to setup the subprocess' [standard error](https://en.wikipedia.org/wiki/Standard_streams#Standard_input_(stdin)). This can be `'pipe'`, `'overlapped'`, `'ignore`, `'inherit'`, a file descriptor integer, a Node.js `Writable` stream, a web `WritableStream`, a `{ file: 'path' }` object, a file URL, a generator function, a `Duplex` or a web `TransformStream`.
|
|
275
1122
|
|
|
276
|
-
[
|
|
1123
|
+
This can be an array of values such as `['inherit', 'pipe']` or `[fileUrl, 'pipe']`.
|
|
277
1124
|
|
|
278
|
-
@default '
|
|
1125
|
+
@default 'pipe'
|
|
279
1126
|
*/
|
|
280
|
-
readonly
|
|
1127
|
+
readonly stderr?: StdoutStderrOptionCommon<IsSync>;
|
|
281
1128
|
|
|
282
1129
|
/**
|
|
283
|
-
|
|
1130
|
+
Like the `stdin`, `stdout` and `stderr` options but for all [file descriptors](https://en.wikipedia.org/wiki/File_descriptor) at once. For example, `{stdio: ['ignore', 'pipe', 'pipe']}` is the same as `{stdin: 'ignore', stdout: 'pipe', stderr: 'pipe'}`.
|
|
284
1131
|
|
|
285
|
-
|
|
1132
|
+
A single string can be used as a shortcut.
|
|
1133
|
+
|
|
1134
|
+
The array can have more than 3 items, to create additional file descriptors beyond `stdin`/`stdout`/`stderr`.
|
|
1135
|
+
|
|
1136
|
+
@default 'pipe'
|
|
286
1137
|
*/
|
|
287
|
-
readonly
|
|
1138
|
+
readonly stdio?: StdioOptionsProperty<IsSync>;
|
|
288
1139
|
|
|
289
1140
|
/**
|
|
290
|
-
|
|
1141
|
+
Add a `subprocess.all` stream and a `result.all` property. They contain the combined/interleaved output of the subprocess' `stdout` and `stderr`.
|
|
1142
|
+
|
|
1143
|
+
@default false
|
|
291
1144
|
*/
|
|
292
|
-
readonly
|
|
1145
|
+
readonly all?: boolean;
|
|
293
1146
|
|
|
294
1147
|
/**
|
|
295
|
-
|
|
1148
|
+
If the subprocess outputs text, specifies its character encoding, either [`'utf8'`](https://en.wikipedia.org/wiki/UTF-8) or [`'utf16le'`](https://en.wikipedia.org/wiki/UTF-16).
|
|
1149
|
+
|
|
1150
|
+
If it outputs binary data instead, this should be either:
|
|
1151
|
+
- `'buffer'`: returns the binary output as an `Uint8Array`.
|
|
1152
|
+
- [`'hex'`](https://en.wikipedia.org/wiki/Hexadecimal), [`'base64'`](https://en.wikipedia.org/wiki/Base64), [`'base64url'`](https://en.wikipedia.org/wiki/Base64#URL_applications), [`'latin1'`](https://nodejs.org/api/buffer.html#buffers-and-character-encodings) or [`'ascii'`](https://nodejs.org/api/buffer.html#buffers-and-character-encodings): encodes the binary output as a string.
|
|
1153
|
+
|
|
1154
|
+
The output is available with `result.stdout`, `result.stderr` and `result.stdio`.
|
|
1155
|
+
|
|
1156
|
+
@default 'utf8'
|
|
296
1157
|
*/
|
|
297
|
-
readonly
|
|
1158
|
+
readonly encoding?: EncodingOption;
|
|
298
1159
|
|
|
299
1160
|
/**
|
|
300
|
-
|
|
1161
|
+
Set `result.stdout`, `result.stderr`, `result.all` and `result.stdio` as arrays of strings, splitting the subprocess' output into lines.
|
|
1162
|
+
|
|
1163
|
+
This cannot be used if the `encoding` option is binary.
|
|
301
1164
|
|
|
302
|
-
|
|
303
|
-
- not cross-platform, encouraging shell-specific syntax.
|
|
304
|
-
- slower, because of the additional shell interpretation.
|
|
305
|
-
- unsafe, potentially allowing command injection.
|
|
1165
|
+
By default, this applies to both `stdout` and `stderr`, but different values can also be passed.
|
|
306
1166
|
|
|
307
1167
|
@default false
|
|
308
1168
|
*/
|
|
309
|
-
readonly
|
|
1169
|
+
readonly lines?: FdGenericOption<boolean>;
|
|
310
1170
|
|
|
311
1171
|
/**
|
|
312
|
-
|
|
1172
|
+
Strip the final [newline character](https://en.wikipedia.org/wiki/Newline) from the output.
|
|
313
1173
|
|
|
314
|
-
|
|
1174
|
+
If the `lines` option is true, this applies to each output line instead.
|
|
1175
|
+
|
|
1176
|
+
By default, this applies to both `stdout` and `stderr`, but different values can also be passed.
|
|
1177
|
+
|
|
1178
|
+
@default true
|
|
315
1179
|
*/
|
|
316
|
-
readonly
|
|
1180
|
+
readonly stripFinalNewline?: FdGenericOption<boolean>;
|
|
317
1181
|
|
|
318
1182
|
/**
|
|
319
|
-
|
|
1183
|
+
Largest amount of data allowed on `stdout`, `stderr` and `stdio`.
|
|
320
1184
|
|
|
321
|
-
|
|
1185
|
+
By default, this applies to both `stdout` and `stderr`, but different values can also be passed.
|
|
1186
|
+
|
|
1187
|
+
When reached, `error.isMaxBuffer` becomes `true`.
|
|
1188
|
+
|
|
1189
|
+
@default 100_000_000
|
|
322
1190
|
*/
|
|
323
|
-
readonly
|
|
1191
|
+
readonly maxBuffer?: FdGenericOption<number>;
|
|
324
1192
|
|
|
325
1193
|
/**
|
|
326
|
-
|
|
1194
|
+
When `buffer` is `false`, the `result.stdout`, `result.stderr`, `result.all` and `result.stdio` properties are not set.
|
|
327
1195
|
|
|
328
|
-
|
|
1196
|
+
By default, this applies to both `stdout` and `stderr`, but different values can also be passed.
|
|
1197
|
+
|
|
1198
|
+
@default true
|
|
329
1199
|
*/
|
|
330
|
-
readonly
|
|
1200
|
+
readonly buffer?: FdGenericOption<boolean>;
|
|
331
1201
|
|
|
332
1202
|
/**
|
|
333
|
-
|
|
1203
|
+
Enables exchanging messages with the subprocess using `subprocess.sendMessage(message)`, `subprocess.getOneMessage()` and `subprocess.getEachMessage()`.
|
|
334
1204
|
|
|
335
|
-
|
|
1205
|
+
The subprocess must be a Node.js file.
|
|
1206
|
+
|
|
1207
|
+
@default `true` if the `node`, `ipcInput` or `gracefulCancel` option is set, `false` otherwise
|
|
1208
|
+
*/
|
|
1209
|
+
readonly ipc?: Unless<IsSync, boolean>;
|
|
1210
|
+
|
|
1211
|
+
/**
|
|
1212
|
+
Specify the kind of serialization used for sending messages between subprocesses when using the `ipc` option.
|
|
1213
|
+
|
|
1214
|
+
@default 'advanced'
|
|
1215
|
+
*/
|
|
1216
|
+
readonly serialization?: Unless<IsSync, 'json' | 'advanced'>;
|
|
1217
|
+
|
|
1218
|
+
/**
|
|
1219
|
+
Sends an IPC message when the subprocess starts.
|
|
1220
|
+
|
|
1221
|
+
The subprocess must be a Node.js file. The value's type depends on the `serialization` option.
|
|
1222
|
+
*/
|
|
1223
|
+
readonly ipcInput?: Unless<IsSync, Message>;
|
|
1224
|
+
|
|
1225
|
+
/**
|
|
1226
|
+
If `verbose` is `'short'`, prints the command on [`stderr`](https://en.wikipedia.org/wiki/Standard_streams#Standard_error_(stderr)): its file, arguments, duration and (if it failed) error message.
|
|
1227
|
+
|
|
1228
|
+
If `verbose` is `'full'` or a function, the command's [`stdout`](https://en.wikipedia.org/wiki/Standard_streams#Standard_output_(stdout)), `stderr` and IPC messages are also printed.
|
|
1229
|
+
|
|
1230
|
+
A function can be passed to customize logging.
|
|
1231
|
+
|
|
1232
|
+
By default, this applies to both `stdout` and `stderr`, but different values can also be passed.
|
|
1233
|
+
|
|
1234
|
+
@default 'none'
|
|
1235
|
+
*/
|
|
1236
|
+
readonly verbose?: VerboseOption;
|
|
1237
|
+
|
|
1238
|
+
/**
|
|
1239
|
+
Setting this to `false` resolves the result's promise with the error instead of rejecting it.
|
|
1240
|
+
|
|
1241
|
+
@default true
|
|
1242
|
+
*/
|
|
1243
|
+
readonly reject?: boolean;
|
|
1244
|
+
|
|
1245
|
+
/**
|
|
1246
|
+
If `timeout` is greater than `0`, the subprocess will be terminated if it runs for longer than that amount of milliseconds.
|
|
1247
|
+
|
|
1248
|
+
On timeout, `error.timedOut` becomes `true`.
|
|
1249
|
+
|
|
1250
|
+
@default 0
|
|
336
1251
|
*/
|
|
337
|
-
readonly
|
|
1252
|
+
readonly timeout?: number;
|
|
338
1253
|
|
|
339
1254
|
/**
|
|
340
|
-
|
|
1255
|
+
When the `cancelSignal` is [aborted](https://developer.mozilla.org/en-US/docs/Web/API/AbortController/abort), terminate the subprocess using a `SIGTERM` signal.
|
|
341
1256
|
|
|
342
|
-
When `
|
|
1257
|
+
When aborted, `error.isCanceled` becomes `true`.
|
|
343
1258
|
|
|
344
1259
|
@example
|
|
345
1260
|
```
|
|
346
|
-
import {
|
|
1261
|
+
import {execaNode} from 'execa';
|
|
347
1262
|
|
|
348
|
-
const
|
|
349
|
-
const
|
|
1263
|
+
const controller = new AbortController();
|
|
1264
|
+
const cancelSignal = controller.signal;
|
|
350
1265
|
|
|
351
1266
|
setTimeout(() => {
|
|
352
|
-
|
|
353
|
-
},
|
|
1267
|
+
controller.abort();
|
|
1268
|
+
}, 5000);
|
|
354
1269
|
|
|
355
1270
|
try {
|
|
356
|
-
await
|
|
1271
|
+
await execaNode({cancelSignal})`build.js`;
|
|
357
1272
|
} catch (error) {
|
|
358
|
-
|
|
359
|
-
|
|
1273
|
+
if (error.isCanceled) {
|
|
1274
|
+
console.error('Canceled by cancelSignal.');
|
|
1275
|
+
}
|
|
1276
|
+
|
|
1277
|
+
throw error;
|
|
360
1278
|
}
|
|
361
1279
|
```
|
|
362
1280
|
*/
|
|
363
|
-
readonly
|
|
1281
|
+
readonly cancelSignal?: Unless<IsSync, AbortSignal>;
|
|
364
1282
|
|
|
365
1283
|
/**
|
|
366
|
-
|
|
1284
|
+
When the `cancelSignal` option is [aborted](https://developer.mozilla.org/en-US/docs/Web/API/AbortController/abort), do not send any `SIGTERM`. Instead, abort the [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal) returned by `getCancelSignal()`. The subprocess should use it to terminate gracefully.
|
|
1285
|
+
|
|
1286
|
+
The subprocess must be a Node.js file.
|
|
1287
|
+
|
|
1288
|
+
When aborted, `error.isGracefullyCanceled` becomes `true`.
|
|
367
1289
|
|
|
368
1290
|
@default false
|
|
369
1291
|
*/
|
|
370
|
-
readonly
|
|
1292
|
+
readonly gracefulCancel?: Unless<IsSync, boolean>;
|
|
371
1293
|
|
|
372
1294
|
/**
|
|
373
|
-
|
|
1295
|
+
If the subprocess is terminated but does not exit, forcefully exit it by sending [`SIGKILL`](https://en.wikipedia.org/wiki/Signal_(IPC)#SIGKILL).
|
|
374
1296
|
|
|
375
|
-
|
|
1297
|
+
When this happens, `error.isForcefullyTerminated` becomes `true`.
|
|
1298
|
+
|
|
1299
|
+
@default 5000
|
|
376
1300
|
*/
|
|
377
|
-
readonly
|
|
1301
|
+
readonly forceKillAfterDelay?: Unless<IsSync, number | boolean>;
|
|
378
1302
|
|
|
379
1303
|
/**
|
|
380
|
-
|
|
1304
|
+
Default [signal](https://en.wikipedia.org/wiki/Signal_(IPC)) used to terminate the subprocess.
|
|
1305
|
+
|
|
1306
|
+
This can be either a name (like `'SIGTERM'`) or a number (like `9`).
|
|
1307
|
+
|
|
1308
|
+
@default 'SIGTERM'
|
|
1309
|
+
*/
|
|
1310
|
+
readonly killSignal?: keyof SignalConstants | number;
|
|
381
1311
|
|
|
382
|
-
|
|
1312
|
+
/**
|
|
1313
|
+
Run the subprocess independently from the current process.
|
|
383
1314
|
|
|
384
1315
|
@default false
|
|
385
1316
|
*/
|
|
386
|
-
readonly
|
|
387
|
-
|
|
1317
|
+
readonly detached?: Unless<IsSync, boolean>;
|
|
1318
|
+
|
|
1319
|
+
/**
|
|
1320
|
+
Kill the subprocess when the current process exits.
|
|
388
1321
|
|
|
389
|
-
|
|
1322
|
+
@default true
|
|
1323
|
+
*/
|
|
1324
|
+
readonly cleanup?: Unless<IsSync, boolean>;
|
|
390
1325
|
|
|
391
|
-
type ExecaReturnBase<StdoutStderrType extends StdoutStderrAll> = {
|
|
392
1326
|
/**
|
|
393
|
-
|
|
1327
|
+
Sets the [user identifier](https://en.wikipedia.org/wiki/User_identifier) of the subprocess.
|
|
394
1328
|
|
|
395
|
-
|
|
1329
|
+
@default current user identifier
|
|
396
1330
|
*/
|
|
397
|
-
|
|
1331
|
+
readonly uid?: number;
|
|
398
1332
|
|
|
399
1333
|
/**
|
|
400
|
-
|
|
1334
|
+
Sets the [group identifier](https://en.wikipedia.org/wiki/Group_identifier) of the subprocess.
|
|
401
1335
|
|
|
402
|
-
|
|
403
|
-
Since the escaping is fairly basic, this should not be executed directly as a process, including using `execa()` or `execaCommand()`.
|
|
1336
|
+
@default current group identifier
|
|
404
1337
|
*/
|
|
405
|
-
|
|
1338
|
+
readonly gid?: number;
|
|
406
1339
|
|
|
407
1340
|
/**
|
|
408
|
-
|
|
1341
|
+
Value of [`argv[0]`](https://nodejs.org/api/process.html#processargv0) sent to the subprocess.
|
|
1342
|
+
|
|
1343
|
+
@default file being executed
|
|
409
1344
|
*/
|
|
410
|
-
|
|
1345
|
+
readonly argv0?: string;
|
|
411
1346
|
|
|
412
1347
|
/**
|
|
413
|
-
|
|
1348
|
+
On Windows, do not create a new console window.
|
|
1349
|
+
|
|
1350
|
+
@default true
|
|
414
1351
|
*/
|
|
415
|
-
|
|
1352
|
+
readonly windowsHide?: boolean;
|
|
416
1353
|
|
|
417
1354
|
/**
|
|
418
|
-
|
|
1355
|
+
If `false`, escapes the command arguments on Windows.
|
|
1356
|
+
|
|
1357
|
+
@default `true` if the `shell` option is `true`, `false` otherwise
|
|
419
1358
|
*/
|
|
420
|
-
|
|
1359
|
+
readonly windowsVerbatimArguments?: boolean;
|
|
1360
|
+
};
|
|
421
1361
|
|
|
1362
|
+
/**
|
|
1363
|
+
Subprocess options.
|
|
1364
|
+
|
|
1365
|
+
Some options are related to the subprocess output: `verbose`, `lines`, `stripFinalNewline`, `buffer`, `maxBuffer`. By default, those options apply to all file descriptors (`stdout`, `stderr`, etc.). A plain object can be passed instead to apply them to only `stdout`, `stderr`, `all` (both stdout and stderr), `ipc`, `fd3`, etc.
|
|
1366
|
+
|
|
1367
|
+
@example
|
|
1368
|
+
|
|
1369
|
+
```
|
|
1370
|
+
// Same value for stdout and stderr
|
|
1371
|
+
await execa({verbose: 'full'})`npm run build`;
|
|
1372
|
+
|
|
1373
|
+
// Different values for stdout and stderr
|
|
1374
|
+
await execa({verbose: {stdout: 'none', stderr: 'full'}})`npm run build`;
|
|
1375
|
+
```
|
|
1376
|
+
*/
|
|
1377
|
+
type Options = CommonOptions<false>;
|
|
1378
|
+
|
|
1379
|
+
/**
|
|
1380
|
+
Subprocess options, with synchronous methods.
|
|
1381
|
+
|
|
1382
|
+
Some options are related to the subprocess output: `verbose`, `lines`, `stripFinalNewline`, `buffer`, `maxBuffer`. By default, those options apply to all file descriptors (`stdout`, `stderr`, etc.). A plain object can be passed instead to apply them to only `stdout`, `stderr`, `all` (both stdout and stderr), `ipc`, `fd3`, etc.
|
|
1383
|
+
|
|
1384
|
+
@example
|
|
1385
|
+
|
|
1386
|
+
```
|
|
1387
|
+
// Same value for stdout and stderr
|
|
1388
|
+
execaSync({verbose: 'full'})`npm run build`;
|
|
1389
|
+
|
|
1390
|
+
// Different values for stdout and stderr
|
|
1391
|
+
execaSync({verbose: {stdout: 'none', stderr: 'full'}})`npm run build`;
|
|
1392
|
+
```
|
|
1393
|
+
*/
|
|
1394
|
+
type SyncOptions = CommonOptions<true>;
|
|
1395
|
+
|
|
1396
|
+
type StricterOptions<
|
|
1397
|
+
WideOptions extends CommonOptions,
|
|
1398
|
+
StrictOptions extends CommonOptions,
|
|
1399
|
+
> = WideOptions extends StrictOptions ? WideOptions : StrictOptions;
|
|
1400
|
+
|
|
1401
|
+
type TemplateExpressionItem =
|
|
1402
|
+
| string
|
|
1403
|
+
| number
|
|
1404
|
+
| Result$1
|
|
1405
|
+
| SyncResult;
|
|
1406
|
+
|
|
1407
|
+
/**
|
|
1408
|
+
Value allowed inside `${...}` when using the template string syntax.
|
|
1409
|
+
*/
|
|
1410
|
+
type TemplateExpression = TemplateExpressionItem | readonly TemplateExpressionItem[];
|
|
1411
|
+
|
|
1412
|
+
// `subprocess.pipe()` options
|
|
1413
|
+
type PipeOptions = {
|
|
422
1414
|
/**
|
|
423
|
-
|
|
1415
|
+
Which stream to pipe from the source subprocess. A [file descriptor](https://en.wikipedia.org/wiki/File_descriptor) like `"fd3"` can also be passed.
|
|
1416
|
+
|
|
1417
|
+
`"all"` pipes both `stdout` and `stderr`. This requires the `all` option to be `true`.
|
|
424
1418
|
*/
|
|
425
|
-
|
|
1419
|
+
readonly from?: FromOption;
|
|
426
1420
|
|
|
427
1421
|
/**
|
|
428
|
-
|
|
1422
|
+
Which stream to pipe to the destination subprocess. A [file descriptor](https://en.wikipedia.org/wiki/File_descriptor) like `"fd3"` can also be passed.
|
|
429
1423
|
*/
|
|
430
|
-
|
|
1424
|
+
readonly to?: ToOption;
|
|
431
1425
|
|
|
432
1426
|
/**
|
|
433
|
-
|
|
1427
|
+
Unpipe the subprocess when the signal aborts.
|
|
434
1428
|
*/
|
|
435
|
-
|
|
1429
|
+
readonly unpipeSignal?: AbortSignal;
|
|
1430
|
+
};
|
|
436
1431
|
|
|
1432
|
+
// `subprocess.pipe()`
|
|
1433
|
+
type PipableSubprocess = {
|
|
437
1434
|
/**
|
|
438
|
-
|
|
1435
|
+
[Pipe](https://nodejs.org/api/stream.html#readablepipedestination-options) the subprocess' `stdout` to a second Execa subprocess' `stdin`. This resolves with that second subprocess' result. If either subprocess is rejected, this is rejected with that subprocess' error instead.
|
|
439
1436
|
|
|
440
|
-
|
|
1437
|
+
This follows the same syntax as `execa(file, arguments?, options?)` except both regular options and pipe-specific options can be specified.
|
|
441
1438
|
*/
|
|
442
|
-
|
|
1439
|
+
pipe<OptionsType extends Options & PipeOptions = {}>(
|
|
1440
|
+
file: string | URL,
|
|
1441
|
+
arguments?: readonly string[],
|
|
1442
|
+
options?: OptionsType,
|
|
1443
|
+
): Promise<Result$1<OptionsType>> & PipableSubprocess;
|
|
1444
|
+
pipe<OptionsType extends Options & PipeOptions = {}>(
|
|
1445
|
+
file: string | URL,
|
|
1446
|
+
options?: OptionsType,
|
|
1447
|
+
): Promise<Result$1<OptionsType>> & PipableSubprocess;
|
|
443
1448
|
|
|
444
1449
|
/**
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
If a signal terminated the process, this property is defined and included in the error message. Otherwise it is `undefined`. It is also `undefined` when the signal is very uncommon which should seldomly happen.
|
|
1450
|
+
Like `subprocess.pipe(file, arguments?, options?)` but using a `command` template string instead. This follows the same syntax as `$`.
|
|
448
1451
|
*/
|
|
449
|
-
|
|
1452
|
+
pipe(templates: TemplateStringsArray, ...expressions: readonly TemplateExpression[]):
|
|
1453
|
+
Promise<Result$1<{}>> & PipableSubprocess;
|
|
1454
|
+
pipe<OptionsType extends Options & PipeOptions = {}>(options: OptionsType):
|
|
1455
|
+
(templates: TemplateStringsArray, ...expressions: readonly TemplateExpression[])
|
|
1456
|
+
=> Promise<Result$1<OptionsType>> & PipableSubprocess;
|
|
450
1457
|
|
|
451
1458
|
/**
|
|
452
|
-
|
|
1459
|
+
Like `subprocess.pipe(file, arguments?, options?)` but using the return value of another `execa()` call instead.
|
|
453
1460
|
*/
|
|
454
|
-
|
|
1461
|
+
pipe<Destination extends ResultPromise>(destination: Destination, options?: PipeOptions):
|
|
1462
|
+
Promise<Awaited<Destination>> & PipableSubprocess;
|
|
455
1463
|
};
|
|
456
1464
|
|
|
457
|
-
|
|
458
|
-
|
|
1465
|
+
// `subprocess.readable|duplex|iterable()` options
|
|
1466
|
+
type ReadableOptions = {
|
|
1467
|
+
/**
|
|
1468
|
+
Which stream to read from the subprocess. A [file descriptor](https://en.wikipedia.org/wiki/File_descriptor) like `"fd3"` can also be passed.
|
|
1469
|
+
|
|
1470
|
+
`"all"` reads both `stdout` and `stderr`. This requires the `all` option to be `true`.
|
|
1471
|
+
|
|
1472
|
+
@default 'stdout'
|
|
1473
|
+
*/
|
|
1474
|
+
readonly from?: FromOption;
|
|
459
1475
|
|
|
460
|
-
/**
|
|
461
|
-
Result of a child process execution. On success this is a plain object. On failure this is also an `Error` instance.
|
|
462
|
-
|
|
463
|
-
The child process fails when:
|
|
464
|
-
- its exit code is not `0`
|
|
465
|
-
- it was killed with a signal
|
|
466
|
-
- timing out
|
|
467
|
-
- being canceled
|
|
468
|
-
- there's not enough memory or there are already too many child processes
|
|
469
|
-
*/
|
|
470
|
-
type ExecaReturnValue<StdoutStderrType extends StdoutStderrAll = string> = {
|
|
471
1476
|
/**
|
|
472
|
-
|
|
1477
|
+
If `false`, iterates over lines. Each line is a string.
|
|
1478
|
+
|
|
1479
|
+
If `true`, iterates over arbitrary chunks of data. Each line is an [`Uint8Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array) (with `subprocess.iterable()`) or a [`Buffer`](https://nodejs.org/api/buffer.html#class-buffer) (with `subprocess.readable()`/`subprocess.duplex()`).
|
|
1480
|
+
|
|
1481
|
+
This is always `true` when the `encoding` option is binary.
|
|
473
1482
|
|
|
474
|
-
|
|
475
|
-
- the `all` option is `false` (default value)
|
|
476
|
-
- `execaSync()` was used
|
|
1483
|
+
@default `false` with `subprocess.iterable()`, `true` otherwise
|
|
477
1484
|
*/
|
|
478
|
-
|
|
1485
|
+
readonly binary?: boolean;
|
|
479
1486
|
|
|
480
1487
|
/**
|
|
481
|
-
|
|
1488
|
+
If both this option and the `binary` option is `false`, [newlines](https://en.wikipedia.org/wiki/Newline) are stripped from each line.
|
|
482
1489
|
|
|
483
|
-
|
|
1490
|
+
@default `false` with `subprocess.iterable()`, `true` otherwise
|
|
484
1491
|
*/
|
|
485
|
-
|
|
486
|
-
}
|
|
1492
|
+
readonly preserveNewlines?: boolean;
|
|
1493
|
+
};
|
|
487
1494
|
|
|
488
|
-
|
|
1495
|
+
// `subprocess.writable|duplex()` options
|
|
1496
|
+
type WritableOptions = {
|
|
489
1497
|
/**
|
|
490
|
-
|
|
1498
|
+
Which stream to write to the subprocess. A [file descriptor](https://en.wikipedia.org/wiki/File_descriptor) like `"fd3"` can also be passed.
|
|
491
1499
|
|
|
492
|
-
|
|
1500
|
+
@default 'stdin'
|
|
493
1501
|
*/
|
|
494
|
-
|
|
1502
|
+
readonly to?: ToOption;
|
|
1503
|
+
};
|
|
495
1504
|
|
|
1505
|
+
// `subprocess.duplex()` options
|
|
1506
|
+
type DuplexOptions = ReadableOptions & WritableOptions;
|
|
1507
|
+
|
|
1508
|
+
// `subprocess.iterable()` return value
|
|
1509
|
+
type SubprocessAsyncIterable<
|
|
1510
|
+
BinaryOption extends boolean | undefined,
|
|
1511
|
+
EncodingOption extends Options['encoding'],
|
|
1512
|
+
> = AsyncIterableIterator<
|
|
1513
|
+
EncodingOption extends BinaryEncodingOption
|
|
1514
|
+
? Uint8Array
|
|
1515
|
+
: BinaryOption extends true
|
|
1516
|
+
? Uint8Array
|
|
1517
|
+
: string
|
|
1518
|
+
>;
|
|
1519
|
+
|
|
1520
|
+
// `subprocess.stdin|stdout|stderr|stdio`
|
|
1521
|
+
type SubprocessStdioStream<
|
|
1522
|
+
FdNumber extends string,
|
|
1523
|
+
OptionsType extends Options,
|
|
1524
|
+
> = SubprocessStream<FdNumber, IgnoresSubprocessOutput<FdNumber, OptionsType>, OptionsType>;
|
|
1525
|
+
|
|
1526
|
+
type SubprocessStream<
|
|
1527
|
+
FdNumber extends string,
|
|
1528
|
+
StreamResultIgnored,
|
|
1529
|
+
OptionsType extends Options,
|
|
1530
|
+
> = StreamResultIgnored extends true
|
|
1531
|
+
? null
|
|
1532
|
+
: InputOutputStream<IsInputFd<FdNumber, OptionsType>>;
|
|
1533
|
+
|
|
1534
|
+
type InputOutputStream<IsInput extends boolean> = IsInput extends true
|
|
1535
|
+
? Writable
|
|
1536
|
+
: Readable;
|
|
1537
|
+
|
|
1538
|
+
// `subprocess.stdio`
|
|
1539
|
+
type SubprocessStdioArray<OptionsType extends Options> = MapStdioStreams<StdioOptionNormalizedArray<OptionsType>, OptionsType>;
|
|
1540
|
+
|
|
1541
|
+
// We cannot use mapped types because it must be compatible with Node.js `ChildProcess["stdio"]` which uses a tuple with exactly 5 items
|
|
1542
|
+
type MapStdioStreams<
|
|
1543
|
+
StdioOptionsArrayType,
|
|
1544
|
+
OptionsType extends Options,
|
|
1545
|
+
> = [
|
|
1546
|
+
SubprocessStdioStream<'0', OptionsType>,
|
|
1547
|
+
SubprocessStdioStream<'1', OptionsType>,
|
|
1548
|
+
SubprocessStdioStream<'2', OptionsType>,
|
|
1549
|
+
'3' extends keyof StdioOptionsArrayType ? SubprocessStdioStream<'3', OptionsType> : never,
|
|
1550
|
+
'4' extends keyof StdioOptionsArrayType ? SubprocessStdioStream<'4', OptionsType> : never,
|
|
1551
|
+
];
|
|
1552
|
+
|
|
1553
|
+
// `subprocess.all`
|
|
1554
|
+
type SubprocessAll<OptionsType extends Options> = AllStream<AllIgnored<OptionsType['all'], OptionsType>>;
|
|
1555
|
+
|
|
1556
|
+
type AllStream<IsIgnored> = IsIgnored extends true ? undefined : Readable;
|
|
1557
|
+
|
|
1558
|
+
type AllIgnored<
|
|
1559
|
+
AllOption,
|
|
1560
|
+
OptionsType extends Options,
|
|
1561
|
+
> = AllOption extends true
|
|
1562
|
+
? IgnoresSubprocessOutput<'1', OptionsType> extends true
|
|
1563
|
+
? IgnoresSubprocessOutput<'2', OptionsType>
|
|
1564
|
+
: false
|
|
1565
|
+
: true;
|
|
1566
|
+
|
|
1567
|
+
type ExecaCustomSubprocess<OptionsType extends Options> = {
|
|
496
1568
|
/**
|
|
497
|
-
|
|
1569
|
+
Process identifier ([PID](https://en.wikipedia.org/wiki/Process_identifier)).
|
|
1570
|
+
|
|
1571
|
+
This is `undefined` if the subprocess failed to spawn.
|
|
498
1572
|
*/
|
|
499
|
-
|
|
1573
|
+
pid?: number;
|
|
500
1574
|
|
|
501
1575
|
/**
|
|
502
|
-
|
|
1576
|
+
The subprocess [`stdin`](https://en.wikipedia.org/wiki/Standard_streams#Standard_input_(stdin)) as a stream.
|
|
503
1577
|
|
|
504
|
-
This is `
|
|
1578
|
+
This is `null` if the `stdin` option is set to `'inherit'`, `'ignore'`, `Readable` or `integer`.
|
|
505
1579
|
*/
|
|
506
|
-
|
|
507
|
-
} & Error & ExecaReturnBase<StdoutStderrType>;
|
|
1580
|
+
stdin: SubprocessStdioStream<'0', OptionsType>;
|
|
508
1581
|
|
|
509
|
-
type ExecaError<StdoutStderrType extends StdoutStderrAll = string> = {
|
|
510
1582
|
/**
|
|
511
|
-
The
|
|
1583
|
+
The subprocess [`stdout`](https://en.wikipedia.org/wiki/Standard_streams#Standard_output_(stdout)) as a stream.
|
|
512
1584
|
|
|
513
|
-
This is `
|
|
514
|
-
- the `all` option is `false` (default value)
|
|
515
|
-
- `execaSync()` was used
|
|
1585
|
+
This is `null` if the `stdout` option is set to `'inherit'`, `'ignore'`, `Writable` or `integer`, or if the `buffer` option is `false`.
|
|
516
1586
|
*/
|
|
517
|
-
|
|
1587
|
+
stdout: SubprocessStdioStream<'1', OptionsType>;
|
|
518
1588
|
|
|
519
1589
|
/**
|
|
520
|
-
|
|
1590
|
+
The subprocess [`stderr`](https://en.wikipedia.org/wiki/Standard_streams#Standard_error_(stderr)) as a stream.
|
|
1591
|
+
|
|
1592
|
+
This is `null` if the `stderr` option is set to `'inherit'`, `'ignore'`, `Writable` or `integer`, or if the `buffer` option is `false`.
|
|
521
1593
|
*/
|
|
522
|
-
|
|
523
|
-
} & ExecaSyncError<StdoutStderrType>;
|
|
1594
|
+
stderr: SubprocessStdioStream<'2', OptionsType>;
|
|
524
1595
|
|
|
525
|
-
type KillOptions = {
|
|
526
1596
|
/**
|
|
527
|
-
|
|
1597
|
+
Stream combining/interleaving `subprocess.stdout` and `subprocess.stderr`.
|
|
528
1598
|
|
|
529
|
-
|
|
1599
|
+
This requires the `all` option to be `true`.
|
|
530
1600
|
|
|
531
|
-
|
|
1601
|
+
This is `undefined` if `stdout` and `stderr` options are set to `'inherit'`, `'ignore'`, `Writable` or `integer`, or if the `buffer` option is `false`.
|
|
532
1602
|
*/
|
|
533
|
-
|
|
534
|
-
};
|
|
1603
|
+
all: SubprocessAll<OptionsType>;
|
|
535
1604
|
|
|
536
|
-
type ExecaChildPromise<StdoutStderrType extends StdoutStderrAll> = {
|
|
537
1605
|
/**
|
|
538
|
-
|
|
1606
|
+
The subprocess `stdin`, `stdout`, `stderr` and other files descriptors as an array of streams.
|
|
539
1607
|
|
|
540
|
-
|
|
541
|
-
- the `all` option is `false` (the default value)
|
|
542
|
-
- both `stdout` and `stderr` options are set to [`'inherit'`, `'ipc'`, `Stream` or `integer`](https://nodejs.org/dist/latest-v6.x/docs/api/child_process.html#child_process_options_stdio)
|
|
1608
|
+
Each array item is `null` if the corresponding `stdin`, `stdout`, `stderr` or `stdio` option is set to `'inherit'`, `'ignore'`, `Stream` or `integer`, or if the `buffer` option is `false`.
|
|
543
1609
|
*/
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
catch<ResultType = never>(
|
|
547
|
-
onRejected?: (reason: ExecaError<StdoutStderrType>) => ResultType | PromiseLike<ResultType>
|
|
548
|
-
): Promise<ExecaReturnValue<StdoutStderrType> | ResultType>;
|
|
1610
|
+
stdio: SubprocessStdioArray<OptionsType>;
|
|
549
1611
|
|
|
550
1612
|
/**
|
|
551
|
-
|
|
1613
|
+
Sends a [signal](https://nodejs.org/api/os.html#signal-constants) to the subprocess. The default signal is the `killSignal` option. `killSignal` defaults to `SIGTERM`, which terminates the subprocess.
|
|
1614
|
+
|
|
1615
|
+
This returns `false` when the signal could not be sent, for example when the subprocess has already exited.
|
|
1616
|
+
|
|
1617
|
+
When an error is passed as argument, it is set to the subprocess' `error.cause`. The subprocess is then terminated with the default signal. This does not emit the [`error` event](https://nodejs.org/api/child_process.html#event-error).
|
|
1618
|
+
|
|
1619
|
+
[More info.](https://nodejs.org/api/child_process.html#subprocesskillsignal)
|
|
552
1620
|
*/
|
|
553
|
-
kill(signal?:
|
|
1621
|
+
kill(signal?: keyof SignalConstants | number, error?: Error): boolean;
|
|
1622
|
+
kill(error?: Error): boolean;
|
|
554
1623
|
|
|
555
1624
|
/**
|
|
556
|
-
|
|
1625
|
+
Subprocesses are [async iterables](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/asyncIterator). They iterate over each output line.
|
|
557
1626
|
*/
|
|
558
|
-
|
|
1627
|
+
[Symbol.asyncIterator](): SubprocessAsyncIterable<undefined, OptionsType['encoding']>;
|
|
559
1628
|
|
|
560
1629
|
/**
|
|
561
|
-
|
|
562
|
-
- Another `execa()` return value
|
|
563
|
-
- A writable stream
|
|
564
|
-
- A file path string
|
|
565
|
-
|
|
566
|
-
If the `target` is another `execa()` return value, it is returned. Otherwise, the original `execa()` return value is returned. This allows chaining `pipeStdout()` then `await`ing the final result.
|
|
567
|
-
|
|
568
|
-
The `stdout` option] must be kept as `pipe`, its default value.
|
|
1630
|
+
Same as `subprocess[Symbol.asyncIterator]` except options can be provided.
|
|
569
1631
|
*/
|
|
570
|
-
|
|
571
|
-
pipeStdout?(target: Writable | string): ExecaChildProcess<StdoutStderrType>;
|
|
1632
|
+
iterable<IterableOptions extends ReadableOptions = {}>(readableOptions?: IterableOptions): SubprocessAsyncIterable<IterableOptions['binary'], OptionsType['encoding']>;
|
|
572
1633
|
|
|
573
1634
|
/**
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
The `stderr` option must be kept as `pipe`, its default value.
|
|
1635
|
+
Converts the subprocess to a readable stream.
|
|
577
1636
|
*/
|
|
578
|
-
|
|
579
|
-
pipeStderr?(target: Writable | string): ExecaChildProcess<StdoutStderrType>;
|
|
1637
|
+
readable(readableOptions?: ReadableOptions): Readable;
|
|
580
1638
|
|
|
581
1639
|
/**
|
|
582
|
-
|
|
1640
|
+
Converts the subprocess to a writable stream.
|
|
1641
|
+
*/
|
|
1642
|
+
writable(writableOptions?: WritableOptions): Writable;
|
|
583
1643
|
|
|
584
|
-
|
|
1644
|
+
/**
|
|
1645
|
+
Converts the subprocess to a duplex stream.
|
|
585
1646
|
*/
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
1647
|
+
duplex(duplexOptions?: DuplexOptions): Duplex;
|
|
1648
|
+
}
|
|
1649
|
+
& IpcMethods<HasIpc<OptionsType>, OptionsType['serialization']>
|
|
1650
|
+
& PipableSubprocess;
|
|
589
1651
|
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
1652
|
+
/**
|
|
1653
|
+
[`child_process` instance](https://nodejs.org/api/child_process.html#child_process_class_childprocess) with additional methods and properties.
|
|
1654
|
+
*/
|
|
1655
|
+
type Subprocess<OptionsType extends Options = Options> =
|
|
1656
|
+
& Omit<ChildProcess, keyof ExecaCustomSubprocess<OptionsType>>
|
|
1657
|
+
& ExecaCustomSubprocess<OptionsType>;
|
|
1658
|
+
|
|
1659
|
+
/**
|
|
1660
|
+
The return value of all asynchronous methods is both:
|
|
1661
|
+
- the subprocess.
|
|
1662
|
+
- a `Promise` either resolving with its successful `result`, or rejecting with its `error`.
|
|
1663
|
+
*/
|
|
1664
|
+
type ResultPromise<OptionsType extends Options = Options> =
|
|
1665
|
+
& Subprocess<OptionsType>
|
|
1666
|
+
& Promise<Result$1<OptionsType>>;
|
|
593
1667
|
|
|
594
|
-
type ExecuteCommandOptions =
|
|
1668
|
+
type ExecuteCommandOptions = Omit<Options, 'cancelSignal'> & {
|
|
595
1669
|
command: string;
|
|
596
1670
|
args?: string[];
|
|
597
1671
|
cwd?: string;
|
|
598
1672
|
ignoreError?: boolean;
|
|
599
|
-
env?: Record<string,
|
|
1673
|
+
env?: Record<string, string>;
|
|
1674
|
+
signal?: AbortSignal;
|
|
600
1675
|
};
|
|
601
1676
|
|
|
602
1677
|
type PackageJsonWithDepsAndDevDeps = PackageJson$1 & Required<Pick<PackageJson$1, 'dependencies' | 'devDependencies'>>;
|
|
@@ -620,6 +1695,10 @@ declare enum PackageManagerName {
|
|
|
620
1695
|
PNPM = "pnpm",
|
|
621
1696
|
BUN = "bun"
|
|
622
1697
|
}
|
|
1698
|
+
declare const indentSymbol: unique symbol;
|
|
1699
|
+
type PackageJsonWithIndent = PackageJsonWithDepsAndDevDeps & {
|
|
1700
|
+
[indentSymbol]?: any;
|
|
1701
|
+
};
|
|
623
1702
|
interface JsPackageManagerOptions {
|
|
624
1703
|
cwd?: string;
|
|
625
1704
|
configDir?: string;
|
|
@@ -649,7 +1728,7 @@ declare abstract class JsPackageManager {
|
|
|
649
1728
|
/** Cache for installed version results to avoid repeated file system calls. */
|
|
650
1729
|
static readonly installedVersionCache: Map<string, string | null>;
|
|
651
1730
|
/** Cache for package.json files to avoid repeated file system calls. */
|
|
652
|
-
static readonly packageJsonCache: Map<string,
|
|
1731
|
+
static readonly packageJsonCache: Map<string, PackageJsonWithIndent>;
|
|
653
1732
|
constructor(options?: JsPackageManagerOptions);
|
|
654
1733
|
/** Runs arbitrary package scripts (as a string for display). */
|
|
655
1734
|
abstract getRunCommand(command: string): string;
|
|
@@ -665,7 +1744,7 @@ declare abstract class JsPackageManager {
|
|
|
665
1744
|
force?: boolean;
|
|
666
1745
|
}): Promise<void>;
|
|
667
1746
|
/** Read the `package.json` file available in the provided directory */
|
|
668
|
-
static getPackageJson(packageJsonPath: string):
|
|
1747
|
+
static getPackageJson(packageJsonPath: string): PackageJsonWithIndent;
|
|
669
1748
|
writePackageJson(packageJson: PackageJson$1, directory?: string): void;
|
|
670
1749
|
getAllDependencies(): Record<string, string>;
|
|
671
1750
|
isDependencyInstalled(dependency: string): boolean;
|
|
@@ -695,7 +1774,7 @@ declare abstract class JsPackageManager {
|
|
|
695
1774
|
type: 'dependencies' | 'devDependencies';
|
|
696
1775
|
writeOutputToFile?: boolean;
|
|
697
1776
|
packageJsonInfo?: PackageJsonInfo;
|
|
698
|
-
}, dependencies: string[]): Promise<void |
|
|
1777
|
+
}, dependencies: string[]): Promise<void | ResultPromise>;
|
|
699
1778
|
/**
|
|
700
1779
|
* Removing dependencies from the package.json file, which is found first starting from the
|
|
701
1780
|
* instance root. The method does not run a package manager install like `npm install`.
|
|
@@ -774,8 +1853,8 @@ declare abstract class JsPackageManager {
|
|
|
774
1853
|
addPackageResolutions(versions: Record<string, string>): void;
|
|
775
1854
|
protected abstract runInstall(options?: {
|
|
776
1855
|
force?: boolean;
|
|
777
|
-
}):
|
|
778
|
-
protected abstract runAddDeps(dependencies: string[], installAsDevDependencies: boolean, writeOutputToFile?: boolean):
|
|
1856
|
+
}): ResultPromise;
|
|
1857
|
+
protected abstract runAddDeps(dependencies: string[], installAsDevDependencies: boolean, writeOutputToFile?: boolean): ResultPromise;
|
|
779
1858
|
protected abstract getResolutions(packageJson: PackageJson$1, versions: Record<string, string>): Record<string, any>;
|
|
780
1859
|
/**
|
|
781
1860
|
* Get the latest or all versions of the input package available on npmjs.com
|
|
@@ -785,10 +1864,10 @@ declare abstract class JsPackageManager {
|
|
|
785
1864
|
*/
|
|
786
1865
|
protected abstract runGetVersions<T extends boolean>(packageName: string, fetchAllVersions: T): Promise<T extends true ? string[] : string>;
|
|
787
1866
|
abstract getRegistryURL(): Promise<string | undefined>;
|
|
788
|
-
abstract runInternalCommand(command: string, args: string[], cwd?: string, stdio?: 'inherit' | 'pipe' | 'ignore'):
|
|
1867
|
+
abstract runInternalCommand(command: string, args: string[], cwd?: string, stdio?: 'inherit' | 'pipe' | 'ignore'): ResultPromise;
|
|
789
1868
|
abstract runPackageCommand(options: Omit<ExecuteCommandOptions, 'command'> & {
|
|
790
1869
|
args: string[];
|
|
791
|
-
}):
|
|
1870
|
+
}): ResultPromise;
|
|
792
1871
|
abstract findInstallations(pattern?: string[]): Promise<InstallationMetadata | undefined>;
|
|
793
1872
|
abstract findInstallations(pattern?: string[], options?: {
|
|
794
1873
|
depth: number;
|
|
@@ -3179,6 +4258,7 @@ declare class AddonVitestService {
|
|
|
3179
4258
|
yes?: boolean;
|
|
3180
4259
|
}): Promise<{
|
|
3181
4260
|
errors: string[];
|
|
4261
|
+
result: 'installed' | 'skipped' | 'aborted' | 'failed';
|
|
3182
4262
|
}>;
|
|
3183
4263
|
/**
|
|
3184
4264
|
* Validate full compatibility for @storybook/addon-vitest
|