@tothalex/cloud 0.0.40

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.
@@ -0,0 +1,447 @@
1
+ declare module "child_process" {
2
+ import { EventEmitter } from "events";
3
+ import {
4
+ DefaultReadableStream as Readable,
5
+ DefaultWritableStream as Writable,
6
+ } from "stream";
7
+
8
+ /**
9
+ * Instances of the `ChildProcess` represent spawned child processes.
10
+ *
11
+ * Instances of `ChildProcess` are not intended to be created directly. Rather,
12
+ * use the {@link spawn} method to create instances of `ChildProcess`.
13
+ */
14
+ class ChildProcess extends EventEmitter {
15
+ /**
16
+ * A `Writable Stream` that represents the child process's `stdin`.
17
+ *
18
+ * If a child process waits to read all of its input, the child will not continue
19
+ * until this stream has been closed via `end()`.
20
+ *
21
+ * If the child was spawned with `stdio[0]` set to anything other than `'pipe'`,
22
+ * then this will be `null`.
23
+ *
24
+ * `subprocess.stdin` is an alias for `subprocess.stdio[0]`. Both properties will
25
+ * refer to the same value.
26
+ *
27
+ * The `subprocess.stdin` property can be `null` or `undefined` if the child process could not be successfully spawned.
28
+ */
29
+ stdin: Writable | null;
30
+
31
+ /**
32
+ * A `Readable Stream` that represents the child process's `stdout`.
33
+ *
34
+ * If the child was spawned with `stdio[1]` set to anything other than `'pipe'`,
35
+ * then this will be `null`.
36
+ *
37
+ * `subprocess.stdout` is an alias for `subprocess.stdio[1]`. Both properties will
38
+ * refer to the same value.
39
+ *
40
+ * ```js
41
+ * const { spawn } = require('child_process');
42
+ *
43
+ * const subprocess = spawn('ls');
44
+ *
45
+ * subprocess.stdout.on('data', (data) => {
46
+ * console.log(`Received chunk ${data}`);
47
+ * });
48
+ * ```
49
+ *
50
+ * The `subprocess.stdout` property can be `null` or `undefined` if the child process could not be successfully spawned.
51
+ */
52
+ stdout: Readable | null;
53
+
54
+ /**
55
+ * A `Readable Stream` that represents the child process's `stderr`.
56
+ *
57
+ * If the child was spawned with `stdio[2]` set to anything other than `'pipe'`,
58
+ * then this will be `null`.
59
+ *
60
+ * `subprocess.stderr` is an alias for `subprocess.stdio[2]`. Both properties will
61
+ * refer to the same value.
62
+ *
63
+ * The `subprocess.stderr` property can be `null` or `undefined` if the child process could not be successfully spawned.
64
+ */
65
+ stderr: Readable | null;
66
+
67
+ /**
68
+ * Returns the process identifier (PID) of the child process. If the child process
69
+ * fails to spawn due to errors, then the value is `undefined` and `error` is
70
+ * emitted.
71
+ *
72
+ * ```js
73
+ * const { spawn } = require('child_process');
74
+ * const grep = spawn('grep', ['ssh']);
75
+ *
76
+ * console.log(`Spawned child pid: ${grep.pid}`);
77
+ * grep.stdin.end();
78
+ * ```
79
+ */
80
+ readonly pid?: number | undefined;
81
+
82
+ /**
83
+ * The `subprocess.kill()` method sends a signal to the child process. If no
84
+ * argument is given, the process will be sent the `'SIGTERM'` signal. See [`signal(7)`](http://man7.org/linux/man-pages/man7/signal.7.html) for a list of available signals. This function
85
+ * returns `true` if [`kill(2)`](http://man7.org/linux/man-pages/man2/kill.2.html) succeeds, and `false` otherwise.
86
+ *
87
+ * ```js
88
+ * const { spawn } = require('child_process');
89
+ * const grep = spawn('grep', ['ssh']);
90
+ *
91
+ * grep.on('close', (code, signal) => {
92
+ * console.log(
93
+ * `child process terminated due to receipt of signal ${signal}`);
94
+ * });
95
+ *
96
+ * // Send SIGHUP to process.
97
+ * grep.kill('SIGHUP');
98
+ * ```
99
+ *
100
+ * The `ChildProcess` object may emit an `'error'` event if the signal
101
+ * cannot be delivered. Sending a signal to a child process that has already exited
102
+ * is not an error but may have unforeseen consequences. Specifically, if the
103
+ * process identifier (PID) has been reassigned to another process, the signal will
104
+ * be delivered to that process instead which can have unexpected results.
105
+ *
106
+ * While the function is called `kill`, the signal delivered to the child process
107
+ * may not actually terminate the process.
108
+ *
109
+ * See [`kill(2)`](http://man7.org/linux/man-pages/man2/kill.2.html) for reference.
110
+ *
111
+ * On Windows, where POSIX signals do not exist, the `signal` argument will be
112
+ * ignored, and the process will be killed forcefully and abruptly (similar to `'SIGKILL'`).
113
+ * See `Signal Events` for more details.
114
+ *
115
+ * On Linux, child processes of child processes will not be terminated
116
+ * when attempting to kill their parent. This is likely to happen when running a
117
+ * new process in a shell or with the use of the `shell` option of `ChildProcess`:
118
+ *
119
+ * ```js
120
+ * 'use strict';
121
+ * const { spawn } = require('child_process');
122
+ *
123
+ * const subprocess = spawn(
124
+ * 'sh',
125
+ * [
126
+ * '-c',
127
+ * `node -e "setInterval(() => {
128
+ * console.log(process.pid, 'is alive')
129
+ * }, 500);"`,
130
+ * ], {
131
+ * stdio: ['inherit', 'inherit', 'inherit'],
132
+ * },
133
+ * );
134
+ *
135
+ * setTimeout(() => {
136
+ * subprocess.kill(); // Does not terminate the Node.js process in the shell.
137
+ * }, 2000);
138
+ * ```
139
+ */
140
+ kill(signal?: QuickJS.Signals | number): boolean;
141
+
142
+ /**
143
+ * Calls {@link ChildProcess.kill} with `'SIGTERM'`.
144
+ */
145
+ [Symbol.dispose](): void;
146
+
147
+ /**
148
+ * events.EventEmitter
149
+ * 1. close
150
+ * 2. error
151
+ * 3. exit
152
+ */
153
+ addListener(event: string, listener: (...args: any[]) => void): this;
154
+ addListener(
155
+ event: "close",
156
+ listener: (code: number | null, signal: QuickJS.Signals | null) => void
157
+ ): this;
158
+ addListener(event: "error", listener: (err: Error) => void): this;
159
+ addListener(
160
+ event: "exit",
161
+ listener: (code: number | null, signal: QuickJS.Signals | null) => void
162
+ ): this;
163
+ emit(event: string | symbol, ...args: any[]): boolean;
164
+ emit(
165
+ event: "close",
166
+ code: number | null,
167
+ signal: QuickJS.Signals | null
168
+ ): boolean;
169
+ emit(event: "error", err: Error): boolean;
170
+ emit(
171
+ event: "exit",
172
+ code: number | null,
173
+ signal: QuickJS.Signals | null
174
+ ): boolean;
175
+ on(event: string, listener: (...args: any[]) => void): this;
176
+ on(
177
+ event: "close",
178
+ listener: (code: number | null, signal: QuickJS.Signals | null) => void
179
+ ): this;
180
+ on(event: "error", listener: (err: Error) => void): this;
181
+ on(
182
+ event: "exit",
183
+ listener: (code: number | null, signal: QuickJS.Signals | null) => void
184
+ ): this;
185
+ once(event: string, listener: (...args: any[]) => void): this;
186
+ once(
187
+ event: "close",
188
+ listener: (code: number | null, signal: QuickJS.Signals | null) => void
189
+ ): this;
190
+ once(event: "error", listener: (err: Error) => void): this;
191
+ once(
192
+ event: "exit",
193
+ listener: (code: number | null, signal: QuickJS.Signals | null) => void
194
+ ): this;
195
+ prependListener(event: string, listener: (...args: any[]) => void): this;
196
+ prependListener(
197
+ event: "close",
198
+ listener: (code: number | null, signal: QuickJS.Signals | null) => void
199
+ ): this;
200
+ prependListener(event: "error", listener: (err: Error) => void): this;
201
+ prependListener(
202
+ event: "exit",
203
+ listener: (code: number | null, signal: QuickJS.Signals | null) => void
204
+ ): this;
205
+ prependOnceListener(
206
+ event: string,
207
+ listener: (...args: any[]) => void
208
+ ): this;
209
+ prependOnceListener(
210
+ event: "close",
211
+ listener: (code: number | null, signal: QuickJS.Signals | null) => void
212
+ ): this;
213
+ prependOnceListener(event: "error", listener: (err: Error) => void): this;
214
+ prependOnceListener(
215
+ event: "exit",
216
+ listener: (code: number | null, signal: QuickJS.Signals | null) => void
217
+ ): this;
218
+ }
219
+ // return this object when stdio option is undefined or not specified
220
+ interface ChildProcessWithoutNullStreams extends ChildProcess {
221
+ stdin: Writable;
222
+ stdout: Readable;
223
+ stderr: Readable;
224
+ }
225
+ // return this object when stdio option is a tuple of 3
226
+ interface ChildProcessByStdio<
227
+ I extends null | Writable,
228
+ O extends null | Readable,
229
+ E extends null | Readable,
230
+ > extends ChildProcess {
231
+ stdin: I;
232
+ stdout: O;
233
+ stderr: E;
234
+ }
235
+
236
+ type IOType = "pipe" | "ignore" | "inherit";
237
+ type StdioOptions = IOType | Array<IOType | number | null | undefined>;
238
+
239
+ interface ProcessEnvOptions {
240
+ uid?: number | undefined;
241
+ gid?: number | undefined;
242
+ cwd?: string | undefined;
243
+ }
244
+ interface SpawnOptions extends ProcessEnvOptions {
245
+ /**
246
+ * Can be set to 'pipe', 'inherit', or 'ignore', or an array of these strings.
247
+ * If passed as an array, the first element is used for `stdin`, the second for
248
+ * `stdout`, and the third for `stderr`.
249
+ *
250
+ * @default 'pipe'
251
+ */
252
+ stdio?: StdioOptions | undefined;
253
+ shell?: boolean | string | undefined;
254
+ windowsVerbatimArguments?: boolean | undefined;
255
+ }
256
+ interface SpawnOptionsWithoutStdio extends SpawnOptions {
257
+ stdio?: StdioPipeNamed | StdioPipe[] | undefined;
258
+ }
259
+ type StdioNull = "inherit" | "ignore";
260
+ type StdioPipeNamed = "pipe";
261
+ type StdioPipe = undefined | null | StdioPipeNamed;
262
+ interface SpawnOptionsWithStdioTuple<
263
+ Stdin extends StdioNull | StdioPipe,
264
+ Stdout extends StdioNull | StdioPipe,
265
+ Stderr extends StdioNull | StdioPipe,
266
+ > extends SpawnOptions {
267
+ stdio: [Stdin, Stdout, Stderr];
268
+ }
269
+
270
+ /**
271
+ * The `child_process.spawn()` method spawns a new process using the given `command`, with command-line arguments in `args`.
272
+ * If omitted, `args` defaults to an empty array.
273
+ *
274
+ * **If the `shell` option is enabled, do not pass unsanitized user input to this**
275
+ * **function. Any input containing shell metacharacters may be used to trigger**
276
+ * **arbitrary command execution.**
277
+ *
278
+ * A third argument may be used to specify additional options.
279
+ *
280
+ * Use `cwd` to specify the working directory from which the process is spawned.
281
+ * If not given, the default is to inherit the current working directory. If given,
282
+ * but the path does not exist, the child process emits an `ENOENT` error
283
+ * and exits immediately. `ENOENT` is also emitted when the command
284
+ * does not exist.
285
+ *
286
+ * Example of running `ls -lh /usr`, capturing `stdout`, `stderr`, and the
287
+ * exit code:
288
+ *
289
+ * ```js
290
+ * const { spawn } = require('child_process');
291
+ * const ls = spawn('ls', ['-lh', '/usr']);
292
+ *
293
+ * ls.stdout.on('data', (data) => {
294
+ * console.log(`stdout: ${data}`);
295
+ * });
296
+ *
297
+ * ls.stderr.on('data', (data) => {
298
+ * console.error(`stderr: ${data}`);
299
+ * });
300
+ *
301
+ * ls.on('close', (code) => {
302
+ * console.log(`child process exited with code ${code}`);
303
+ * });
304
+ * ```
305
+ *
306
+ * Example: A very elaborate way to run `ps ax | grep ssh`
307
+ *
308
+ * ```js
309
+ * const { spawn } = require('child_process');
310
+ * const ps = spawn('ps', ['ax']);
311
+ * const grep = spawn('grep', ['ssh']);
312
+ *
313
+ * ps.stdout.on('data', (data) => {
314
+ * grep.stdin.write(data);
315
+ * });
316
+ *
317
+ * ps.stderr.on('data', (data) => {
318
+ * console.error(`ps stderr: ${data}`);
319
+ * });
320
+ *
321
+ * ps.on('close', (code) => {
322
+ * if (code !== 0) {
323
+ * console.log(`ps process exited with code ${code}`);
324
+ * }
325
+ * grep.stdin.end();
326
+ * });
327
+ *
328
+ * grep.stdout.on('data', (data) => {
329
+ * console.log(data.toString());
330
+ * });
331
+ *
332
+ * grep.stderr.on('data', (data) => {
333
+ * console.error(`grep stderr: ${data}`);
334
+ * });
335
+ *
336
+ * grep.on('close', (code) => {
337
+ * if (code !== 0) {
338
+ * console.log(`grep process exited with code ${code}`);
339
+ * }
340
+ * });
341
+ * ```
342
+ *
343
+ * Example of checking for failed `spawn`:
344
+ *
345
+ * ```js
346
+ * const { spawn } = require('child_process');
347
+ * const subprocess = spawn('bad_command');
348
+ *
349
+ * subprocess.on('error', (err) => {
350
+ * console.error('Failed to start subprocess.');
351
+ * });
352
+ * ```
353
+ *
354
+ * Certain platforms (macOS, Linux) will use the value of `argv[0]` for the process
355
+ * title while others (Windows, SunOS) will use `command`.
356
+ * @param command The command to run.
357
+ * @param args List of string arguments.
358
+ */
359
+ function spawn(
360
+ command: string,
361
+ options?: SpawnOptionsWithoutStdio
362
+ ): ChildProcessWithoutNullStreams;
363
+ function spawn(
364
+ command: string,
365
+ options: SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioPipe>
366
+ ): ChildProcessByStdio<Writable, Readable, Readable>;
367
+ function spawn(
368
+ command: string,
369
+ options: SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioNull>
370
+ ): ChildProcessByStdio<Writable, Readable, null>;
371
+ function spawn(
372
+ command: string,
373
+ options: SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioPipe>
374
+ ): ChildProcessByStdio<Writable, null, Readable>;
375
+ function spawn(
376
+ command: string,
377
+ options: SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioPipe>
378
+ ): ChildProcessByStdio<null, Readable, Readable>;
379
+ function spawn(
380
+ command: string,
381
+ options: SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioNull>
382
+ ): ChildProcessByStdio<Writable, null, null>;
383
+ function spawn(
384
+ command: string,
385
+ options: SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioNull>
386
+ ): ChildProcessByStdio<null, Readable, null>;
387
+ function spawn(
388
+ command: string,
389
+ options: SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioPipe>
390
+ ): ChildProcessByStdio<null, null, Readable>;
391
+ function spawn(
392
+ command: string,
393
+ options: SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioNull>
394
+ ): ChildProcessByStdio<null, null, null>;
395
+ function spawn(command: string, options: SpawnOptions): ChildProcess;
396
+ // overloads of spawn with 'args'
397
+ function spawn(
398
+ command: string,
399
+ args?: readonly string[],
400
+ options?: SpawnOptionsWithoutStdio
401
+ ): ChildProcessWithoutNullStreams;
402
+ function spawn(
403
+ command: string,
404
+ args: readonly string[],
405
+ options: SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioPipe>
406
+ ): ChildProcessByStdio<Writable, Readable, Readable>;
407
+ function spawn(
408
+ command: string,
409
+ args: readonly string[],
410
+ options: SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioNull>
411
+ ): ChildProcessByStdio<Writable, Readable, null>;
412
+ function spawn(
413
+ command: string,
414
+ args: readonly string[],
415
+ options: SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioPipe>
416
+ ): ChildProcessByStdio<Writable, null, Readable>;
417
+ function spawn(
418
+ command: string,
419
+ args: readonly string[],
420
+ options: SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioPipe>
421
+ ): ChildProcessByStdio<null, Readable, Readable>;
422
+ function spawn(
423
+ command: string,
424
+ args: readonly string[],
425
+ options: SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioNull>
426
+ ): ChildProcessByStdio<Writable, null, null>;
427
+ function spawn(
428
+ command: string,
429
+ args: readonly string[],
430
+ options: SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioNull>
431
+ ): ChildProcessByStdio<null, Readable, null>;
432
+ function spawn(
433
+ command: string,
434
+ args: readonly string[],
435
+ options: SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioPipe>
436
+ ): ChildProcessByStdio<null, null, Readable>;
437
+ function spawn(
438
+ command: string,
439
+ args: readonly string[],
440
+ options: SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioNull>
441
+ ): ChildProcessByStdio<null, null, null>;
442
+ function spawn(
443
+ command: string,
444
+ args: readonly string[],
445
+ options: SpawnOptions
446
+ ): ChildProcess;
447
+ }