-
-
Notifications
You must be signed in to change notification settings - Fork 227
/
subprocess.d.ts
132 lines (103 loc) · 5.15 KB
/
subprocess.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
import type {ChildProcess} from 'node:child_process';
import type {Readable, Writable, Duplex} from 'node:stream';
import type {StdioOptionsArray} from '../stdio/type';
import type {Options} from '../arguments/options';
import type {Result} from '../return/result';
import type {PipableSubprocess} from '../pipe';
import type {
ReadableOptions,
WritableOptions,
DuplexOptions,
SubprocessAsyncIterable,
} from '../convert';
import type {SubprocessStdioStream} from './stdout';
import type {SubprocessStdioArray} from './stdio';
import type {SubprocessAll} from './all';
type HasIpc<OptionsType extends Options> = OptionsType['ipc'] extends true
? true
: OptionsType['stdio'] extends StdioOptionsArray
? 'ipc' extends OptionsType['stdio'][number] ? true : false
: false;
type ExecaCustomSubprocess<OptionsType extends Options = Options> = {
/**
Process identifier ([PID](https://en.wikipedia.org/wiki/Process_identifier)).
This is `undefined` if the subprocess failed to spawn.
*/
pid?: number;
/**
Send a `message` to the subprocess. The type of `message` depends on the `serialization` option.
The subprocess receives it as a [`message` event](https://nodejs.org/api/process.html#event-message).
This returns `true` on success.
This requires the `ipc` option to be `true`.
[More info.](https://nodejs.org/api/child_process.html#subprocesssendmessage-sendhandle-options-callback)
*/
send: HasIpc<OptionsType> extends true ? ChildProcess['send'] : undefined;
/**
The subprocess [`stdin`](https://en.wikipedia.org/wiki/Standard_streams#Standard_input_(stdin)) as a stream.
This is `null` if the `stdin` option is set to `'inherit'`, `'ignore'`, `Readable` or `integer`.
*/
stdin: SubprocessStdioStream<'0', OptionsType>;
/**
The subprocess [`stdout`](https://en.wikipedia.org/wiki/Standard_streams#Standard_output_(stdout)) as a stream.
This is `null` if the `stdout` option is set to `'inherit'`, `'ignore'`, `Writable` or `integer`, or if the `buffer` option is `false`.
*/
stdout: SubprocessStdioStream<'1', OptionsType>;
/**
The subprocess [`stderr`](https://en.wikipedia.org/wiki/Standard_streams#Standard_error_(stderr)) as a stream.
This is `null` if the `stderr` option is set to `'inherit'`, `'ignore'`, `Writable` or `integer`, or if the `buffer` option is `false`.
*/
stderr: SubprocessStdioStream<'2', OptionsType>;
/**
Stream combining/interleaving `subprocess.stdout` and `subprocess.stderr`.
This requires the `all` option to be `true`.
This is `undefined` if `stdout` and `stderr` options are set to `'inherit'`, `'ignore'`, `Writable` or `integer`, or if the `buffer` option is `false`.
*/
all: SubprocessAll<OptionsType>;
/**
The subprocess `stdin`, `stdout`, `stderr` and other files descriptors as an array of streams.
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`.
*/
stdio: SubprocessStdioArray<OptionsType>;
/**
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.
This returns `false` when the signal could not be sent, for example when the subprocess has already exited.
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).
[More info.](https://nodejs.org/api/child_process.html#subprocesskillsignal)
*/
kill(signal?: NodeJS.Signals | number, error?: Error): boolean;
kill(error?: Error): boolean;
/**
Subprocesses are [async iterables](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/asyncIterator). They iterate over each output line.
*/
[Symbol.asyncIterator](): SubprocessAsyncIterable<undefined, OptionsType['encoding']>;
/**
Same as `subprocess[Symbol.asyncIterator]` except options can be provided.
*/
iterable<IterableOptions extends ReadableOptions = {}>(readableOptions?: IterableOptions): SubprocessAsyncIterable<IterableOptions['binary'], OptionsType['encoding']>;
/**
Converts the subprocess to a readable stream.
*/
readable(readableOptions?: ReadableOptions): Readable;
/**
Converts the subprocess to a writable stream.
*/
writable(writableOptions?: WritableOptions): Writable;
/**
Converts the subprocess to a duplex stream.
*/
duplex(duplexOptions?: DuplexOptions): Duplex;
} & PipableSubprocess;
/**
[`child_process` instance](https://nodejs.org/api/child_process.html#child_process_class_childprocess) with additional methods and properties.
*/
export type Subprocess<OptionsType extends Options = Options> =
& Omit<ChildProcess, keyof ExecaCustomSubprocess<OptionsType>>
& ExecaCustomSubprocess<OptionsType>;
/**
The return value of all asynchronous methods is both:
- the subprocess.
- a `Promise` either resolving with its successful `result`, or rejecting with its `error`.
*/
export type ResultPromise<OptionsType extends Options = Options> =
& Subprocess<OptionsType>
& Promise<Result<OptionsType>>;