@types/node 16.18.87 → 16.18.88

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.
Files changed (55) hide show
  1. node v16.18/README.md +1 -1
  2. node v16.18/package.json +3 -10
  3. node v16.18/ts4.8/assert/strict.d.ts +0 -8
  4. node v16.18/ts4.8/assert.d.ts +0 -986
  5. node v16.18/ts4.8/async_hooks.d.ts +0 -501
  6. node v16.18/ts4.8/buffer.d.ts +0 -2266
  7. node v16.18/ts4.8/child_process.d.ts +0 -1536
  8. node v16.18/ts4.8/cluster.d.ts +0 -436
  9. node v16.18/ts4.8/console.d.ts +0 -412
  10. node v16.18/ts4.8/constants.d.ts +0 -19
  11. node v16.18/ts4.8/crypto.d.ts +0 -4346
  12. node v16.18/ts4.8/dgram.d.ts +0 -591
  13. node v16.18/ts4.8/diagnostics_channel.d.ts +0 -191
  14. node v16.18/ts4.8/dns/promises.d.ts +0 -372
  15. node v16.18/ts4.8/dns.d.ts +0 -796
  16. node v16.18/ts4.8/dom-events.d.ts +0 -122
  17. node v16.18/ts4.8/domain.d.ts +0 -170
  18. node v16.18/ts4.8/events.d.ts +0 -714
  19. node v16.18/ts4.8/fs/promises.d.ts +0 -1124
  20. node v16.18/ts4.8/fs.d.ts +0 -4030
  21. node v16.18/ts4.8/globals.d.ts +0 -291
  22. node v16.18/ts4.8/globals.global.d.ts +0 -1
  23. node v16.18/ts4.8/http.d.ts +0 -1586
  24. node v16.18/ts4.8/http2.d.ts +0 -2353
  25. node v16.18/ts4.8/https.d.ts +0 -534
  26. node v16.18/ts4.8/index.d.ts +0 -86
  27. node v16.18/ts4.8/inspector.d.ts +0 -2743
  28. node v16.18/ts4.8/module.d.ts +0 -221
  29. node v16.18/ts4.8/net.d.ts +0 -858
  30. node v16.18/ts4.8/os.d.ts +0 -455
  31. node v16.18/ts4.8/path.d.ts +0 -191
  32. node v16.18/ts4.8/perf_hooks.d.ts +0 -603
  33. node v16.18/ts4.8/process.d.ts +0 -1525
  34. node v16.18/ts4.8/punycode.d.ts +0 -117
  35. node v16.18/ts4.8/querystring.d.ts +0 -141
  36. node v16.18/ts4.8/readline.d.ts +0 -553
  37. node v16.18/ts4.8/repl.d.ts +0 -430
  38. node v16.18/ts4.8/stream/consumers.d.ts +0 -12
  39. node v16.18/ts4.8/stream/promises.d.ts +0 -83
  40. node v16.18/ts4.8/stream/web.d.ts +0 -392
  41. node v16.18/ts4.8/stream.d.ts +0 -1494
  42. node v16.18/ts4.8/string_decoder.d.ts +0 -67
  43. node v16.18/ts4.8/test.d.ts +0 -190
  44. node v16.18/ts4.8/timers/promises.d.ts +0 -93
  45. node v16.18/ts4.8/timers.d.ts +0 -109
  46. node v16.18/ts4.8/tls.d.ts +0 -1099
  47. node v16.18/ts4.8/trace_events.d.ts +0 -161
  48. node v16.18/ts4.8/tty.d.ts +0 -204
  49. node v16.18/ts4.8/url.d.ts +0 -885
  50. node v16.18/ts4.8/util.d.ts +0 -1689
  51. node v16.18/ts4.8/v8.d.ts +0 -626
  52. node v16.18/ts4.8/vm.d.ts +0 -507
  53. node v16.18/ts4.8/wasi.d.ts +0 -158
  54. node v16.18/ts4.8/worker_threads.d.ts +0 -649
  55. node v16.18/ts4.8/zlib.d.ts +0 -517
@@ -1,1536 +0,0 @@
1
- /**
2
- * The `child_process` module provides the ability to spawn subprocesses in
3
- * a manner that is similar, but not identical, to [`popen(3)`](http://man7.org/linux/man-pages/man3/popen.3.html). This capability
4
- * is primarily provided by the {@link spawn} function:
5
- *
6
- * ```js
7
- * const { spawn } = require('child_process');
8
- * const ls = spawn('ls', ['-lh', '/usr']);
9
- *
10
- * ls.stdout.on('data', (data) => {
11
- * console.log(`stdout: ${data}`);
12
- * });
13
- *
14
- * ls.stderr.on('data', (data) => {
15
- * console.error(`stderr: ${data}`);
16
- * });
17
- *
18
- * ls.on('close', (code) => {
19
- * console.log(`child process exited with code ${code}`);
20
- * });
21
- * ```
22
- *
23
- * By default, pipes for `stdin`, `stdout`, and `stderr` are established between
24
- * the parent Node.js process and the spawned subprocess. These pipes have
25
- * limited (and platform-specific) capacity. If the subprocess writes to
26
- * stdout in excess of that limit without the output being captured, the
27
- * subprocess blocks waiting for the pipe buffer to accept more data. This is
28
- * identical to the behavior of pipes in the shell. Use the `{ stdio: 'ignore' }`option if the output will not be consumed.
29
- *
30
- * The command lookup is performed using the `options.env.PATH` environment
31
- * variable if it is in the `options` object. Otherwise, `process.env.PATH` is
32
- * used.
33
- *
34
- * On Windows, environment variables are case-insensitive. Node.js
35
- * lexicographically sorts the `env` keys and uses the first one that
36
- * case-insensitively matches. Only first (in lexicographic order) entry will be
37
- * passed to the subprocess. This might lead to issues on Windows when passing
38
- * objects to the `env` option that have multiple variants of the same key, such as`PATH` and `Path`.
39
- *
40
- * The {@link spawn} method spawns the child process asynchronously,
41
- * without blocking the Node.js event loop. The {@link spawnSync} function provides equivalent functionality in a synchronous manner that blocks
42
- * the event loop until the spawned process either exits or is terminated.
43
- *
44
- * For convenience, the `child_process` module provides a handful of synchronous
45
- * and asynchronous alternatives to {@link spawn} and {@link spawnSync}. Each of these alternatives are implemented on
46
- * top of {@link spawn} or {@link spawnSync}.
47
- *
48
- * * {@link exec}: spawns a shell and runs a command within that
49
- * shell, passing the `stdout` and `stderr` to a callback function when
50
- * complete.
51
- * * {@link execFile}: similar to {@link exec} except
52
- * that it spawns the command directly without first spawning a shell by
53
- * default.
54
- * * {@link fork}: spawns a new Node.js process and invokes a
55
- * specified module with an IPC communication channel established that allows
56
- * sending messages between parent and child.
57
- * * {@link execSync}: a synchronous version of {@link exec} that will block the Node.js event loop.
58
- * * {@link execFileSync}: a synchronous version of {@link execFile} that will block the Node.js event loop.
59
- *
60
- * For certain use cases, such as automating shell scripts, the `synchronous counterparts` may be more convenient. In many cases, however,
61
- * the synchronous methods can have significant impact on performance due to
62
- * stalling the event loop while spawned processes complete.
63
- * @see [source](https://github.com/nodejs/node/blob/v16.9.0/lib/child_process.js)
64
- */
65
- declare module "child_process" {
66
- import { ObjectEncodingOptions } from "node:fs";
67
- import { Abortable, EventEmitter } from "node:events";
68
- import * as net from "node:net";
69
- import { Pipe, Readable, Stream, Writable } from "node:stream";
70
- import { URL } from "node:url";
71
- type Serializable = string | object | number | boolean | bigint;
72
- type SendHandle = net.Socket | net.Server;
73
- /**
74
- * Instances of the `ChildProcess` represent spawned child processes.
75
- *
76
- * Instances of `ChildProcess` are not intended to be created directly. Rather,
77
- * use the {@link spawn}, {@link exec},{@link execFile}, or {@link fork} methods to create
78
- * instances of `ChildProcess`.
79
- * @since v2.2.0
80
- */
81
- class ChildProcess extends EventEmitter {
82
- /**
83
- * A `Writable Stream` that represents the child process's `stdin`.
84
- *
85
- * If a child process waits to read all of its input, the child will not continue
86
- * until this stream has been closed via `end()`.
87
- *
88
- * If the child was spawned with `stdio[0]` set to anything other than `'pipe'`,
89
- * then this will be `null`.
90
- *
91
- * `subprocess.stdin` is an alias for `subprocess.stdio[0]`. Both properties will
92
- * refer to the same value.
93
- *
94
- * The `subprocess.stdin` property can be `undefined` if the child process could
95
- * not be successfully spawned.
96
- * @since v0.1.90
97
- */
98
- stdin: Writable | null;
99
- /**
100
- * A `Readable Stream` that represents the child process's `stdout`.
101
- *
102
- * If the child was spawned with `stdio[1]` set to anything other than `'pipe'`,
103
- * then this will be `null`.
104
- *
105
- * `subprocess.stdout` is an alias for `subprocess.stdio[1]`. Both properties will
106
- * refer to the same value.
107
- *
108
- * ```js
109
- * const { spawn } = require('child_process');
110
- *
111
- * const subprocess = spawn('ls');
112
- *
113
- * subprocess.stdout.on('data', (data) => {
114
- * console.log(`Received chunk ${data}`);
115
- * });
116
- * ```
117
- *
118
- * The `subprocess.stdout` property can be `null` if the child process could
119
- * not be successfully spawned.
120
- * @since v0.1.90
121
- */
122
- stdout: Readable | null;
123
- /**
124
- * A `Readable Stream` that represents the child process's `stderr`.
125
- *
126
- * If the child was spawned with `stdio[2]` set to anything other than `'pipe'`,
127
- * then this will be `null`.
128
- *
129
- * `subprocess.stderr` is an alias for `subprocess.stdio[2]`. Both properties will
130
- * refer to the same value.
131
- *
132
- * The `subprocess.stderr` property can be `null` if the child process could
133
- * not be successfully spawned.
134
- * @since v0.1.90
135
- */
136
- stderr: Readable | null;
137
- /**
138
- * The `subprocess.channel` property is a reference to the child's IPC channel. If
139
- * no IPC channel currently exists, this property is `undefined`.
140
- * @since v7.1.0
141
- */
142
- readonly channel?: Pipe | null | undefined;
143
- /**
144
- * A sparse array of pipes to the child process, corresponding with positions in
145
- * the `stdio` option passed to {@link spawn} that have been set
146
- * to the value `'pipe'`. `subprocess.stdio[0]`, `subprocess.stdio[1]`, and`subprocess.stdio[2]` are also available as `subprocess.stdin`,`subprocess.stdout`, and `subprocess.stderr`,
147
- * respectively.
148
- *
149
- * In the following example, only the child's fd `1` (stdout) is configured as a
150
- * pipe, so only the parent's `subprocess.stdio[1]` is a stream, all other values
151
- * in the array are `null`.
152
- *
153
- * ```js
154
- * const assert = require('assert');
155
- * const fs = require('fs');
156
- * const child_process = require('child_process');
157
- *
158
- * const subprocess = child_process.spawn('ls', {
159
- * stdio: [
160
- * 0, // Use parent's stdin for child.
161
- * 'pipe', // Pipe child's stdout to parent.
162
- * fs.openSync('err.out', 'w'), // Direct child's stderr to a file.
163
- * ]
164
- * });
165
- *
166
- * assert.strictEqual(subprocess.stdio[0], null);
167
- * assert.strictEqual(subprocess.stdio[0], subprocess.stdin);
168
- *
169
- * assert(subprocess.stdout);
170
- * assert.strictEqual(subprocess.stdio[1], subprocess.stdout);
171
- *
172
- * assert.strictEqual(subprocess.stdio[2], null);
173
- * assert.strictEqual(subprocess.stdio[2], subprocess.stderr);
174
- * ```
175
- *
176
- * The `subprocess.stdio` property can be `undefined` if the child process could
177
- * not be successfully spawned.
178
- * @since v0.7.10
179
- */
180
- readonly stdio: [
181
- Writable | null,
182
- // stdin
183
- Readable | null,
184
- // stdout
185
- Readable | null,
186
- // stderr
187
- Readable | Writable | null | undefined,
188
- // extra
189
- Readable | Writable | null | undefined, // extra
190
- ];
191
- /**
192
- * The `subprocess.killed` property indicates whether the child process
193
- * successfully received a signal from `subprocess.kill()`. The `killed` property
194
- * does not indicate that the child process has been terminated.
195
- * @since v0.5.10
196
- */
197
- readonly killed: boolean;
198
- /**
199
- * Returns the process identifier (PID) of the child process. If the child process
200
- * fails to spawn due to errors, then the value is `undefined` and `error` is
201
- * emitted.
202
- *
203
- * ```js
204
- * const { spawn } = require('child_process');
205
- * const grep = spawn('grep', ['ssh']);
206
- *
207
- * console.log(`Spawned child pid: ${grep.pid}`);
208
- * grep.stdin.end();
209
- * ```
210
- * @since v0.1.90
211
- */
212
- readonly pid?: number | undefined;
213
- /**
214
- * The `subprocess.connected` property indicates whether it is still possible to
215
- * send and receive messages from a child process. When `subprocess.connected` is`false`, it is no longer possible to send or receive messages.
216
- * @since v0.7.2
217
- */
218
- readonly connected: boolean;
219
- /**
220
- * The `subprocess.exitCode` property indicates the exit code of the child process.
221
- * If the child process is still running, the field will be `null`.
222
- */
223
- readonly exitCode: number | null;
224
- /**
225
- * The `subprocess.signalCode` property indicates the signal received by
226
- * the child process if any, else `null`.
227
- */
228
- readonly signalCode: NodeJS.Signals | null;
229
- /**
230
- * The `subprocess.spawnargs` property represents the full list of command-line
231
- * arguments the child process was launched with.
232
- */
233
- readonly spawnargs: string[];
234
- /**
235
- * The `subprocess.spawnfile` property indicates the executable file name of
236
- * the child process that is launched.
237
- *
238
- * For {@link fork}, its value will be equal to `process.execPath`.
239
- * For {@link spawn}, its value will be the name of
240
- * the executable file.
241
- * For {@link exec}, its value will be the name of the shell
242
- * in which the child process is launched.
243
- */
244
- readonly spawnfile: string;
245
- /**
246
- * The `subprocess.kill()` method sends a signal to the child process. If no
247
- * 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
248
- * returns `true` if [`kill(2)`](http://man7.org/linux/man-pages/man2/kill.2.html) succeeds, and `false` otherwise.
249
- *
250
- * ```js
251
- * const { spawn } = require('child_process');
252
- * const grep = spawn('grep', ['ssh']);
253
- *
254
- * grep.on('close', (code, signal) => {
255
- * console.log(
256
- * `child process terminated due to receipt of signal ${signal}`);
257
- * });
258
- *
259
- * // Send SIGHUP to process.
260
- * grep.kill('SIGHUP');
261
- * ```
262
- *
263
- * The `ChildProcess` object may emit an `'error'` event if the signal
264
- * cannot be delivered. Sending a signal to a child process that has already exited
265
- * is not an error but may have unforeseen consequences. Specifically, if the
266
- * process identifier (PID) has been reassigned to another process, the signal will
267
- * be delivered to that process instead which can have unexpected results.
268
- *
269
- * While the function is called `kill`, the signal delivered to the child process
270
- * may not actually terminate the process.
271
- *
272
- * See [`kill(2)`](http://man7.org/linux/man-pages/man2/kill.2.html) for reference.
273
- *
274
- * On Windows, where POSIX signals do not exist, the `signal` argument will be
275
- * ignored, and the process will be killed forcefully and abruptly (similar to`'SIGKILL'`).
276
- * See `Signal Events` for more details.
277
- *
278
- * On Linux, child processes of child processes will not be terminated
279
- * when attempting to kill their parent. This is likely to happen when running a
280
- * new process in a shell or with the use of the `shell` option of `ChildProcess`:
281
- *
282
- * ```js
283
- * 'use strict';
284
- * const { spawn } = require('child_process');
285
- *
286
- * const subprocess = spawn(
287
- * 'sh',
288
- * [
289
- * '-c',
290
- * `node -e "setInterval(() => {
291
- * console.log(process.pid, 'is alive')
292
- * }, 500);"`,
293
- * ], {
294
- * stdio: ['inherit', 'inherit', 'inherit']
295
- * }
296
- * );
297
- *
298
- * setTimeout(() => {
299
- * subprocess.kill(); // Does not terminate the Node.js process in the shell.
300
- * }, 2000);
301
- * ```
302
- * @since v0.1.90
303
- */
304
- kill(signal?: NodeJS.Signals | number): boolean;
305
- /**
306
- * When an IPC channel has been established between the parent and child (
307
- * i.e. when using {@link fork}), the `subprocess.send()` method can
308
- * be used to send messages to the child process. When the child process is a
309
- * Node.js instance, these messages can be received via the `'message'` event.
310
- *
311
- * The message goes through serialization and parsing. The resulting
312
- * message might not be the same as what is originally sent.
313
- *
314
- * For example, in the parent script:
315
- *
316
- * ```js
317
- * const cp = require('child_process');
318
- * const n = cp.fork(`${__dirname}/sub.js`);
319
- *
320
- * n.on('message', (m) => {
321
- * console.log('PARENT got message:', m);
322
- * });
323
- *
324
- * // Causes the child to print: CHILD got message: { hello: 'world' }
325
- * n.send({ hello: 'world' });
326
- * ```
327
- *
328
- * And then the child script, `'sub.js'` might look like this:
329
- *
330
- * ```js
331
- * process.on('message', (m) => {
332
- * console.log('CHILD got message:', m);
333
- * });
334
- *
335
- * // Causes the parent to print: PARENT got message: { foo: 'bar', baz: null }
336
- * process.send({ foo: 'bar', baz: NaN });
337
- * ```
338
- *
339
- * Child Node.js processes will have a `process.send()` method of their own
340
- * that allows the child to send messages back to the parent.
341
- *
342
- * There is a special case when sending a `{cmd: 'NODE_foo'}` message. Messages
343
- * containing a `NODE_` prefix in the `cmd` property are reserved for use within
344
- * Node.js core and will not be emitted in the child's `'message'` event. Rather, such messages are emitted using the`'internalMessage'` event and are consumed internally by Node.js.
345
- * Applications should avoid using such messages or listening for`'internalMessage'` events as it is subject to change without notice.
346
- *
347
- * The optional `sendHandle` argument that may be passed to `subprocess.send()` is
348
- * for passing a TCP server or socket object to the child process. The child will
349
- * receive the object as the second argument passed to the callback function
350
- * registered on the `'message'` event. Any data that is received
351
- * and buffered in the socket will not be sent to the child.
352
- *
353
- * The optional `callback` is a function that is invoked after the message is
354
- * sent but before the child may have received it. The function is called with a
355
- * single argument: `null` on success, or an `Error` object on failure.
356
- *
357
- * If no `callback` function is provided and the message cannot be sent, an`'error'` event will be emitted by the `ChildProcess` object. This can
358
- * happen, for instance, when the child process has already exited.
359
- *
360
- * `subprocess.send()` will return `false` if the channel has closed or when the
361
- * backlog of unsent messages exceeds a threshold that makes it unwise to send
362
- * more. Otherwise, the method returns `true`. The `callback` function can be
363
- * used to implement flow control.
364
- *
365
- * #### Example: sending a server object
366
- *
367
- * The `sendHandle` argument can be used, for instance, to pass the handle of
368
- * a TCP server object to the child process as illustrated in the example below:
369
- *
370
- * ```js
371
- * const subprocess = require('child_process').fork('subprocess.js');
372
- *
373
- * // Open up the server object and send the handle.
374
- * const server = require('net').createServer();
375
- * server.on('connection', (socket) => {
376
- * socket.end('handled by parent');
377
- * });
378
- * server.listen(1337, () => {
379
- * subprocess.send('server', server);
380
- * });
381
- * ```
382
- *
383
- * The child would then receive the server object as:
384
- *
385
- * ```js
386
- * process.on('message', (m, server) => {
387
- * if (m === 'server') {
388
- * server.on('connection', (socket) => {
389
- * socket.end('handled by child');
390
- * });
391
- * }
392
- * });
393
- * ```
394
- *
395
- * Once the server is now shared between the parent and child, some connections
396
- * can be handled by the parent and some by the child.
397
- *
398
- * While the example above uses a server created using the `net` module, `dgram`module servers use exactly the same workflow with the exceptions of listening on
399
- * a `'message'` event instead of `'connection'` and using `server.bind()` instead
400
- * of `server.listen()`. This is, however, currently only supported on Unix
401
- * platforms.
402
- *
403
- * #### Example: sending a socket object
404
- *
405
- * Similarly, the `sendHandler` argument can be used to pass the handle of a
406
- * socket to the child process. The example below spawns two children that each
407
- * handle connections with "normal" or "special" priority:
408
- *
409
- * ```js
410
- * const { fork } = require('child_process');
411
- * const normal = fork('subprocess.js', ['normal']);
412
- * const special = fork('subprocess.js', ['special']);
413
- *
414
- * // Open up the server and send sockets to child. Use pauseOnConnect to prevent
415
- * // the sockets from being read before they are sent to the child process.
416
- * const server = require('net').createServer({ pauseOnConnect: true });
417
- * server.on('connection', (socket) => {
418
- *
419
- * // If this is special priority...
420
- * if (socket.remoteAddress === '74.125.127.100') {
421
- * special.send('socket', socket);
422
- * return;
423
- * }
424
- * // This is normal priority.
425
- * normal.send('socket', socket);
426
- * });
427
- * server.listen(1337);
428
- * ```
429
- *
430
- * The `subprocess.js` would receive the socket handle as the second argument
431
- * passed to the event callback function:
432
- *
433
- * ```js
434
- * process.on('message', (m, socket) => {
435
- * if (m === 'socket') {
436
- * if (socket) {
437
- * // Check that the client socket exists.
438
- * // It is possible for the socket to be closed between the time it is
439
- * // sent and the time it is received in the child process.
440
- * socket.end(`Request handled with ${process.argv[2]} priority`);
441
- * }
442
- * }
443
- * });
444
- * ```
445
- *
446
- * Do not use `.maxConnections` on a socket that has been passed to a subprocess.
447
- * The parent cannot track when the socket is destroyed.
448
- *
449
- * Any `'message'` handlers in the subprocess should verify that `socket` exists,
450
- * as the connection may have been closed during the time it takes to send the
451
- * connection to the child.
452
- * @since v0.5.9
453
- * @param options The `options` argument, if present, is an object used to parameterize the sending of certain types of handles. `options` supports the following properties:
454
- */
455
- send(message: Serializable, callback?: (error: Error | null) => void): boolean;
456
- send(message: Serializable, sendHandle?: SendHandle, callback?: (error: Error | null) => void): boolean;
457
- send(
458
- message: Serializable,
459
- sendHandle?: SendHandle,
460
- options?: MessageOptions,
461
- callback?: (error: Error | null) => void,
462
- ): boolean;
463
- /**
464
- * Closes the IPC channel between parent and child, allowing the child to exit
465
- * gracefully once there are no other connections keeping it alive. After calling
466
- * this method the `subprocess.connected` and `process.connected` properties in
467
- * both the parent and child (respectively) will be set to `false`, and it will be
468
- * no longer possible to pass messages between the processes.
469
- *
470
- * The `'disconnect'` event will be emitted when there are no messages in the
471
- * process of being received. This will most often be triggered immediately after
472
- * calling `subprocess.disconnect()`.
473
- *
474
- * When the child process is a Node.js instance (e.g. spawned using {@link fork}), the `process.disconnect()` method can be invoked
475
- * within the child process to close the IPC channel as well.
476
- * @since v0.7.2
477
- */
478
- disconnect(): void;
479
- /**
480
- * By default, the parent will wait for the detached child to exit. To prevent the
481
- * parent from waiting for a given `subprocess` to exit, use the`subprocess.unref()` method. Doing so will cause the parent's event loop to not
482
- * include the child in its reference count, allowing the parent to exit
483
- * independently of the child, unless there is an established IPC channel between
484
- * the child and the parent.
485
- *
486
- * ```js
487
- * const { spawn } = require('child_process');
488
- *
489
- * const subprocess = spawn(process.argv[0], ['child_program.js'], {
490
- * detached: true,
491
- * stdio: 'ignore'
492
- * });
493
- *
494
- * subprocess.unref();
495
- * ```
496
- * @since v0.7.10
497
- */
498
- unref(): void;
499
- /**
500
- * Calling `subprocess.ref()` after making a call to `subprocess.unref()` will
501
- * restore the removed reference count for the child process, forcing the parent
502
- * to wait for the child to exit before exiting itself.
503
- *
504
- * ```js
505
- * const { spawn } = require('child_process');
506
- *
507
- * const subprocess = spawn(process.argv[0], ['child_program.js'], {
508
- * detached: true,
509
- * stdio: 'ignore'
510
- * });
511
- *
512
- * subprocess.unref();
513
- * subprocess.ref();
514
- * ```
515
- * @since v0.7.10
516
- */
517
- ref(): void;
518
- /**
519
- * events.EventEmitter
520
- * 1. close
521
- * 2. disconnect
522
- * 3. error
523
- * 4. exit
524
- * 5. message
525
- * 6. spawn
526
- */
527
- addListener(event: string, listener: (...args: any[]) => void): this;
528
- addListener(event: "close", listener: (code: number | null, signal: NodeJS.Signals | null) => void): this;
529
- addListener(event: "disconnect", listener: () => void): this;
530
- addListener(event: "error", listener: (err: Error) => void): this;
531
- addListener(event: "exit", listener: (code: number | null, signal: NodeJS.Signals | null) => void): this;
532
- addListener(event: "message", listener: (message: Serializable, sendHandle: SendHandle) => void): this;
533
- addListener(event: "spawn", listener: () => void): this;
534
- emit(event: string | symbol, ...args: any[]): boolean;
535
- emit(event: "close", code: number | null, signal: NodeJS.Signals | null): boolean;
536
- emit(event: "disconnect"): boolean;
537
- emit(event: "error", err: Error): boolean;
538
- emit(event: "exit", code: number | null, signal: NodeJS.Signals | null): boolean;
539
- emit(event: "message", message: Serializable, sendHandle: SendHandle): boolean;
540
- emit(event: "spawn", listener: () => void): boolean;
541
- on(event: string, listener: (...args: any[]) => void): this;
542
- on(event: "close", listener: (code: number | null, signal: NodeJS.Signals | null) => void): this;
543
- on(event: "disconnect", listener: () => void): this;
544
- on(event: "error", listener: (err: Error) => void): this;
545
- on(event: "exit", listener: (code: number | null, signal: NodeJS.Signals | null) => void): this;
546
- on(event: "message", listener: (message: Serializable, sendHandle: SendHandle) => void): this;
547
- on(event: "spawn", listener: () => void): this;
548
- once(event: string, listener: (...args: any[]) => void): this;
549
- once(event: "close", listener: (code: number | null, signal: NodeJS.Signals | null) => void): this;
550
- once(event: "disconnect", listener: () => void): this;
551
- once(event: "error", listener: (err: Error) => void): this;
552
- once(event: "exit", listener: (code: number | null, signal: NodeJS.Signals | null) => void): this;
553
- once(event: "message", listener: (message: Serializable, sendHandle: SendHandle) => void): this;
554
- once(event: "spawn", listener: () => void): this;
555
- prependListener(event: string, listener: (...args: any[]) => void): this;
556
- prependListener(event: "close", listener: (code: number | null, signal: NodeJS.Signals | null) => void): this;
557
- prependListener(event: "disconnect", listener: () => void): this;
558
- prependListener(event: "error", listener: (err: Error) => void): this;
559
- prependListener(event: "exit", listener: (code: number | null, signal: NodeJS.Signals | null) => void): this;
560
- prependListener(event: "message", listener: (message: Serializable, sendHandle: SendHandle) => void): this;
561
- prependListener(event: "spawn", listener: () => void): this;
562
- prependOnceListener(event: string, listener: (...args: any[]) => void): this;
563
- prependOnceListener(
564
- event: "close",
565
- listener: (code: number | null, signal: NodeJS.Signals | null) => void,
566
- ): this;
567
- prependOnceListener(event: "disconnect", listener: () => void): this;
568
- prependOnceListener(event: "error", listener: (err: Error) => void): this;
569
- prependOnceListener(
570
- event: "exit",
571
- listener: (code: number | null, signal: NodeJS.Signals | null) => void,
572
- ): this;
573
- prependOnceListener(event: "message", listener: (message: Serializable, sendHandle: SendHandle) => void): this;
574
- prependOnceListener(event: "spawn", listener: () => void): this;
575
- }
576
- // return this object when stdio option is undefined or not specified
577
- interface ChildProcessWithoutNullStreams extends ChildProcess {
578
- stdin: Writable;
579
- stdout: Readable;
580
- stderr: Readable;
581
- readonly stdio: [
582
- Writable,
583
- Readable,
584
- Readable,
585
- // stderr
586
- Readable | Writable | null | undefined,
587
- // extra, no modification
588
- Readable | Writable | null | undefined, // extra, no modification
589
- ];
590
- }
591
- // return this object when stdio option is a tuple of 3
592
- interface ChildProcessByStdio<I extends null | Writable, O extends null | Readable, E extends null | Readable>
593
- extends ChildProcess
594
- {
595
- stdin: I;
596
- stdout: O;
597
- stderr: E;
598
- readonly stdio: [
599
- I,
600
- O,
601
- E,
602
- Readable | Writable | null | undefined,
603
- // extra, no modification
604
- Readable | Writable | null | undefined, // extra, no modification
605
- ];
606
- }
607
- interface MessageOptions {
608
- keepOpen?: boolean | undefined;
609
- }
610
- type IOType = "overlapped" | "pipe" | "ignore" | "inherit";
611
- type StdioOptions = IOType | Array<IOType | "ipc" | Stream | number | null | undefined>;
612
- type SerializationType = "json" | "advanced";
613
- interface MessagingOptions extends Abortable {
614
- /**
615
- * Specify the kind of serialization used for sending messages between processes.
616
- * @default 'json'
617
- */
618
- serialization?: SerializationType | undefined;
619
- /**
620
- * The signal value to be used when the spawned process will be killed by the abort signal.
621
- * @default 'SIGTERM'
622
- */
623
- killSignal?: NodeJS.Signals | number | undefined;
624
- /**
625
- * In milliseconds the maximum amount of time the process is allowed to run.
626
- */
627
- timeout?: number | undefined;
628
- }
629
- interface ProcessEnvOptions {
630
- uid?: number | undefined;
631
- gid?: number | undefined;
632
- cwd?: string | URL | undefined;
633
- env?: NodeJS.ProcessEnv | undefined;
634
- }
635
- interface CommonOptions extends ProcessEnvOptions {
636
- /**
637
- * @default false
638
- */
639
- windowsHide?: boolean | undefined;
640
- /**
641
- * @default 0
642
- */
643
- timeout?: number | undefined;
644
- }
645
- interface CommonSpawnOptions extends CommonOptions, MessagingOptions, Abortable {
646
- argv0?: string | undefined;
647
- /**
648
- * Can be set to 'pipe', 'inherit', 'overlapped', or 'ignore', or an array of these strings.
649
- * If passed as an array, the first element is used for `stdin`, the second for
650
- * `stdout`, and the third for `stderr`. A fourth element can be used to
651
- * specify the `stdio` behavior beyond the standard streams. See
652
- * {@link ChildProcess.stdio} for more information.
653
- *
654
- * @default 'pipe'
655
- */
656
- stdio?: StdioOptions | undefined;
657
- shell?: boolean | string | undefined;
658
- windowsVerbatimArguments?: boolean | undefined;
659
- }
660
- interface SpawnOptions extends CommonSpawnOptions {
661
- detached?: boolean | undefined;
662
- }
663
- interface SpawnOptionsWithoutStdio extends SpawnOptions {
664
- stdio?: StdioPipeNamed | StdioPipe[] | undefined;
665
- }
666
- type StdioNull = "inherit" | "ignore" | Stream;
667
- type StdioPipeNamed = "pipe" | "overlapped";
668
- type StdioPipe = undefined | null | StdioPipeNamed;
669
- interface SpawnOptionsWithStdioTuple<
670
- Stdin extends StdioNull | StdioPipe,
671
- Stdout extends StdioNull | StdioPipe,
672
- Stderr extends StdioNull | StdioPipe,
673
- > extends SpawnOptions {
674
- stdio: [Stdin, Stdout, Stderr];
675
- }
676
- /**
677
- * The `child_process.spawn()` method spawns a new process using the given`command`, with command-line arguments in `args`. If omitted, `args` defaults
678
- * to an empty array.
679
- *
680
- * **If the `shell` option is enabled, do not pass unsanitized user input to this**
681
- * **function. Any input containing shell metacharacters may be used to trigger**
682
- * **arbitrary command execution.**
683
- *
684
- * A third argument may be used to specify additional options, with these defaults:
685
- *
686
- * ```js
687
- * const defaults = {
688
- * cwd: undefined,
689
- * env: process.env
690
- * };
691
- * ```
692
- *
693
- * Use `cwd` to specify the working directory from which the process is spawned.
694
- * If not given, the default is to inherit the current working directory. If given,
695
- * but the path does not exist, the child process emits an `ENOENT` error
696
- * and exits immediately. `ENOENT` is also emitted when the command
697
- * does not exist.
698
- *
699
- * Use `env` to specify environment variables that will be visible to the new
700
- * process, the default is `process.env`.
701
- *
702
- * `undefined` values in `env` will be ignored.
703
- *
704
- * Example of running `ls -lh /usr`, capturing `stdout`, `stderr`, and the
705
- * exit code:
706
- *
707
- * ```js
708
- * const { spawn } = require('child_process');
709
- * const ls = spawn('ls', ['-lh', '/usr']);
710
- *
711
- * ls.stdout.on('data', (data) => {
712
- * console.log(`stdout: ${data}`);
713
- * });
714
- *
715
- * ls.stderr.on('data', (data) => {
716
- * console.error(`stderr: ${data}`);
717
- * });
718
- *
719
- * ls.on('close', (code) => {
720
- * console.log(`child process exited with code ${code}`);
721
- * });
722
- * ```
723
- *
724
- * Example: A very elaborate way to run `ps ax | grep ssh`
725
- *
726
- * ```js
727
- * const { spawn } = require('child_process');
728
- * const ps = spawn('ps', ['ax']);
729
- * const grep = spawn('grep', ['ssh']);
730
- *
731
- * ps.stdout.on('data', (data) => {
732
- * grep.stdin.write(data);
733
- * });
734
- *
735
- * ps.stderr.on('data', (data) => {
736
- * console.error(`ps stderr: ${data}`);
737
- * });
738
- *
739
- * ps.on('close', (code) => {
740
- * if (code !== 0) {
741
- * console.log(`ps process exited with code ${code}`);
742
- * }
743
- * grep.stdin.end();
744
- * });
745
- *
746
- * grep.stdout.on('data', (data) => {
747
- * console.log(data.toString());
748
- * });
749
- *
750
- * grep.stderr.on('data', (data) => {
751
- * console.error(`grep stderr: ${data}`);
752
- * });
753
- *
754
- * grep.on('close', (code) => {
755
- * if (code !== 0) {
756
- * console.log(`grep process exited with code ${code}`);
757
- * }
758
- * });
759
- * ```
760
- *
761
- * Example of checking for failed `spawn`:
762
- *
763
- * ```js
764
- * const { spawn } = require('child_process');
765
- * const subprocess = spawn('bad_command');
766
- *
767
- * subprocess.on('error', (err) => {
768
- * console.error('Failed to start subprocess.');
769
- * });
770
- * ```
771
- *
772
- * Certain platforms (macOS, Linux) will use the value of `argv[0]` for the process
773
- * title while others (Windows, SunOS) will use `command`.
774
- *
775
- * Node.js currently overwrites `argv[0]` with `process.execPath` on startup, so`process.argv[0]` in a Node.js child process will not match the `argv0`parameter passed to `spawn` from the parent,
776
- * retrieve it with the`process.argv0` property instead.
777
- *
778
- * If the `signal` option is enabled, calling `.abort()` on the corresponding`AbortController` is similar to calling `.kill()` on the child process except
779
- * the error passed to the callback will be an `AbortError`:
780
- *
781
- * ```js
782
- * const { spawn } = require('child_process');
783
- * const controller = new AbortController();
784
- * const { signal } = controller;
785
- * const grep = spawn('grep', ['ssh'], { signal });
786
- * grep.on('error', (err) => {
787
- * // This will be called with err being an AbortError if the controller aborts
788
- * });
789
- * controller.abort(); // Stops the child process
790
- * ```
791
- * @since v0.1.90
792
- * @param command The command to run.
793
- * @param args List of string arguments.
794
- */
795
- function spawn(command: string, options?: SpawnOptionsWithoutStdio): ChildProcessWithoutNullStreams;
796
- function spawn(
797
- command: string,
798
- options: SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioPipe>,
799
- ): ChildProcessByStdio<Writable, Readable, Readable>;
800
- function spawn(
801
- command: string,
802
- options: SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioNull>,
803
- ): ChildProcessByStdio<Writable, Readable, null>;
804
- function spawn(
805
- command: string,
806
- options: SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioPipe>,
807
- ): ChildProcessByStdio<Writable, null, Readable>;
808
- function spawn(
809
- command: string,
810
- options: SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioPipe>,
811
- ): ChildProcessByStdio<null, Readable, Readable>;
812
- function spawn(
813
- command: string,
814
- options: SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioNull>,
815
- ): ChildProcessByStdio<Writable, null, null>;
816
- function spawn(
817
- command: string,
818
- options: SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioNull>,
819
- ): ChildProcessByStdio<null, Readable, null>;
820
- function spawn(
821
- command: string,
822
- options: SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioPipe>,
823
- ): ChildProcessByStdio<null, null, Readable>;
824
- function spawn(
825
- command: string,
826
- options: SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioNull>,
827
- ): ChildProcessByStdio<null, null, null>;
828
- function spawn(command: string, options: SpawnOptions): ChildProcess;
829
- // overloads of spawn with 'args'
830
- function spawn(
831
- command: string,
832
- args?: readonly string[],
833
- options?: SpawnOptionsWithoutStdio,
834
- ): ChildProcessWithoutNullStreams;
835
- function spawn(
836
- command: string,
837
- args: readonly string[],
838
- options: SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioPipe>,
839
- ): ChildProcessByStdio<Writable, Readable, Readable>;
840
- function spawn(
841
- command: string,
842
- args: readonly string[],
843
- options: SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioNull>,
844
- ): ChildProcessByStdio<Writable, Readable, null>;
845
- function spawn(
846
- command: string,
847
- args: readonly string[],
848
- options: SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioPipe>,
849
- ): ChildProcessByStdio<Writable, null, Readable>;
850
- function spawn(
851
- command: string,
852
- args: readonly string[],
853
- options: SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioPipe>,
854
- ): ChildProcessByStdio<null, Readable, Readable>;
855
- function spawn(
856
- command: string,
857
- args: readonly string[],
858
- options: SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioNull>,
859
- ): ChildProcessByStdio<Writable, null, null>;
860
- function spawn(
861
- command: string,
862
- args: readonly string[],
863
- options: SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioNull>,
864
- ): ChildProcessByStdio<null, Readable, null>;
865
- function spawn(
866
- command: string,
867
- args: readonly string[],
868
- options: SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioPipe>,
869
- ): ChildProcessByStdio<null, null, Readable>;
870
- function spawn(
871
- command: string,
872
- args: readonly string[],
873
- options: SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioNull>,
874
- ): ChildProcessByStdio<null, null, null>;
875
- function spawn(command: string, args: readonly string[], options: SpawnOptions): ChildProcess;
876
- interface ExecOptions extends CommonOptions {
877
- shell?: string | undefined;
878
- signal?: AbortSignal | undefined;
879
- maxBuffer?: number | undefined;
880
- killSignal?: NodeJS.Signals | number | undefined;
881
- }
882
- interface ExecOptionsWithStringEncoding extends ExecOptions {
883
- encoding: BufferEncoding;
884
- }
885
- interface ExecOptionsWithBufferEncoding extends ExecOptions {
886
- encoding: BufferEncoding | null; // specify `null`.
887
- }
888
- interface ExecException extends Error {
889
- cmd?: string | undefined;
890
- killed?: boolean | undefined;
891
- code?: number | undefined;
892
- signal?: NodeJS.Signals | undefined;
893
- }
894
- /**
895
- * Spawns a shell then executes the `command` within that shell, buffering any
896
- * generated output. The `command` string passed to the exec function is processed
897
- * directly by the shell and special characters (vary based on [shell](https://en.wikipedia.org/wiki/List_of_command-line_interpreters))
898
- * need to be dealt with accordingly:
899
- *
900
- * ```js
901
- * const { exec } = require('child_process');
902
- *
903
- * exec('"/path/to/test file/test.sh" arg1 arg2');
904
- * // Double quotes are used so that the space in the path is not interpreted as
905
- * // a delimiter of multiple arguments.
906
- *
907
- * exec('echo "The \\$HOME variable is $HOME"');
908
- * // The $HOME variable is escaped in the first instance, but not in the second.
909
- * ```
910
- *
911
- * **Never pass unsanitized user input to this function. Any input containing shell**
912
- * **metacharacters may be used to trigger arbitrary command execution.**
913
- *
914
- * If a `callback` function is provided, it is called with the arguments`(error, stdout, stderr)`. On success, `error` will be `null`. On error,`error` will be an instance of `Error`. The
915
- * `error.code` property will be
916
- * the exit code of the process. By convention, any exit code other than `0`indicates an error. `error.signal` will be the signal that terminated the
917
- * process.
918
- *
919
- * The `stdout` and `stderr` arguments passed to the callback will contain the
920
- * stdout and stderr output of the child process. By default, Node.js will decode
921
- * the output as UTF-8 and pass strings to the callback. The `encoding` option
922
- * can be used to specify the character encoding used to decode the stdout and
923
- * stderr output. If `encoding` is `'buffer'`, or an unrecognized character
924
- * encoding, `Buffer` objects will be passed to the callback instead.
925
- *
926
- * ```js
927
- * const { exec } = require('child_process');
928
- * exec('cat *.js missing_file | wc -l', (error, stdout, stderr) => {
929
- * if (error) {
930
- * console.error(`exec error: ${error}`);
931
- * return;
932
- * }
933
- * console.log(`stdout: ${stdout}`);
934
- * console.error(`stderr: ${stderr}`);
935
- * });
936
- * ```
937
- *
938
- * If `timeout` is greater than `0`, the parent will send the signal
939
- * identified by the `killSignal` property (the default is `'SIGTERM'`) if the
940
- * child runs longer than `timeout` milliseconds.
941
- *
942
- * Unlike the [`exec(3)`](http://man7.org/linux/man-pages/man3/exec.3.html) POSIX system call, `child_process.exec()` does not replace
943
- * the existing process and uses a shell to execute the command.
944
- *
945
- * If this method is invoked as its `util.promisify()` ed version, it returns
946
- * a `Promise` for an `Object` with `stdout` and `stderr` properties. The returned`ChildProcess` instance is attached to the `Promise` as a `child` property. In
947
- * case of an error (including any error resulting in an exit code other than 0), a
948
- * rejected promise is returned, with the same `error` object given in the
949
- * callback, but with two additional properties `stdout` and `stderr`.
950
- *
951
- * ```js
952
- * const util = require('util');
953
- * const exec = util.promisify(require('child_process').exec);
954
- *
955
- * async function lsExample() {
956
- * const { stdout, stderr } = await exec('ls');
957
- * console.log('stdout:', stdout);
958
- * console.error('stderr:', stderr);
959
- * }
960
- * lsExample();
961
- * ```
962
- *
963
- * If the `signal` option is enabled, calling `.abort()` on the corresponding`AbortController` is similar to calling `.kill()` on the child process except
964
- * the error passed to the callback will be an `AbortError`:
965
- *
966
- * ```js
967
- * const { exec } = require('child_process');
968
- * const controller = new AbortController();
969
- * const { signal } = controller;
970
- * const child = exec('grep ssh', { signal }, (error) => {
971
- * console.log(error); // an AbortError
972
- * });
973
- * controller.abort();
974
- * ```
975
- * @since v0.1.90
976
- * @param command The command to run, with space-separated arguments.
977
- * @param callback called with the output when process terminates.
978
- */
979
- function exec(
980
- command: string,
981
- callback?: (error: ExecException | null, stdout: string, stderr: string) => void,
982
- ): ChildProcess;
983
- // `options` with `"buffer"` or `null` for `encoding` means stdout/stderr are definitely `Buffer`.
984
- function exec(
985
- command: string,
986
- options: {
987
- encoding: "buffer" | null;
988
- } & ExecOptions,
989
- callback?: (error: ExecException | null, stdout: Buffer, stderr: Buffer) => void,
990
- ): ChildProcess;
991
- // `options` with well known `encoding` means stdout/stderr are definitely `string`.
992
- function exec(
993
- command: string,
994
- options: {
995
- encoding: BufferEncoding;
996
- } & ExecOptions,
997
- callback?: (error: ExecException | null, stdout: string, stderr: string) => void,
998
- ): ChildProcess;
999
- // `options` with an `encoding` whose type is `string` means stdout/stderr could either be `Buffer` or `string`.
1000
- // There is no guarantee the `encoding` is unknown as `string` is a superset of `BufferEncoding`.
1001
- function exec(
1002
- command: string,
1003
- options: {
1004
- encoding: BufferEncoding;
1005
- } & ExecOptions,
1006
- callback?: (error: ExecException | null, stdout: string | Buffer, stderr: string | Buffer) => void,
1007
- ): ChildProcess;
1008
- // `options` without an `encoding` means stdout/stderr are definitely `string`.
1009
- function exec(
1010
- command: string,
1011
- options: ExecOptions,
1012
- callback?: (error: ExecException | null, stdout: string, stderr: string) => void,
1013
- ): ChildProcess;
1014
- // fallback if nothing else matches. Worst case is always `string | Buffer`.
1015
- function exec(
1016
- command: string,
1017
- options: (ObjectEncodingOptions & ExecOptions) | undefined | null,
1018
- callback?: (error: ExecException | null, stdout: string | Buffer, stderr: string | Buffer) => void,
1019
- ): ChildProcess;
1020
- interface PromiseWithChild<T> extends Promise<T> {
1021
- child: ChildProcess;
1022
- }
1023
- namespace exec {
1024
- function __promisify__(command: string): PromiseWithChild<{
1025
- stdout: string;
1026
- stderr: string;
1027
- }>;
1028
- function __promisify__(
1029
- command: string,
1030
- options: {
1031
- encoding: "buffer" | null;
1032
- } & ExecOptions,
1033
- ): PromiseWithChild<{
1034
- stdout: Buffer;
1035
- stderr: Buffer;
1036
- }>;
1037
- function __promisify__(
1038
- command: string,
1039
- options: {
1040
- encoding: BufferEncoding;
1041
- } & ExecOptions,
1042
- ): PromiseWithChild<{
1043
- stdout: string;
1044
- stderr: string;
1045
- }>;
1046
- function __promisify__(
1047
- command: string,
1048
- options: ExecOptions,
1049
- ): PromiseWithChild<{
1050
- stdout: string;
1051
- stderr: string;
1052
- }>;
1053
- function __promisify__(
1054
- command: string,
1055
- options?: (ObjectEncodingOptions & ExecOptions) | null,
1056
- ): PromiseWithChild<{
1057
- stdout: string | Buffer;
1058
- stderr: string | Buffer;
1059
- }>;
1060
- }
1061
- interface ExecFileOptions extends CommonOptions, Abortable {
1062
- maxBuffer?: number | undefined;
1063
- killSignal?: NodeJS.Signals | number | undefined;
1064
- windowsVerbatimArguments?: boolean | undefined;
1065
- shell?: boolean | string | undefined;
1066
- signal?: AbortSignal | undefined;
1067
- }
1068
- interface ExecFileOptionsWithStringEncoding extends ExecFileOptions {
1069
- encoding: BufferEncoding;
1070
- }
1071
- interface ExecFileOptionsWithBufferEncoding extends ExecFileOptions {
1072
- encoding: "buffer" | null;
1073
- }
1074
- interface ExecFileOptionsWithOtherEncoding extends ExecFileOptions {
1075
- encoding: BufferEncoding;
1076
- }
1077
- type ExecFileException =
1078
- & Omit<ExecException, "code">
1079
- & Omit<NodeJS.ErrnoException, "code">
1080
- & { code?: string | number | undefined | null };
1081
- /**
1082
- * The `child_process.execFile()` function is similar to {@link exec} except that it does not spawn a shell by default. Rather, the specified
1083
- * executable `file` is spawned directly as a new process making it slightly more
1084
- * efficient than {@link exec}.
1085
- *
1086
- * The same options as {@link exec} are supported. Since a shell is
1087
- * not spawned, behaviors such as I/O redirection and file globbing are not
1088
- * supported.
1089
- *
1090
- * ```js
1091
- * const { execFile } = require('child_process');
1092
- * const child = execFile('node', ['--version'], (error, stdout, stderr) => {
1093
- * if (error) {
1094
- * throw error;
1095
- * }
1096
- * console.log(stdout);
1097
- * });
1098
- * ```
1099
- *
1100
- * The `stdout` and `stderr` arguments passed to the callback will contain the
1101
- * stdout and stderr output of the child process. By default, Node.js will decode
1102
- * the output as UTF-8 and pass strings to the callback. The `encoding` option
1103
- * can be used to specify the character encoding used to decode the stdout and
1104
- * stderr output. If `encoding` is `'buffer'`, or an unrecognized character
1105
- * encoding, `Buffer` objects will be passed to the callback instead.
1106
- *
1107
- * If this method is invoked as its `util.promisify()` ed version, it returns
1108
- * a `Promise` for an `Object` with `stdout` and `stderr` properties. The returned`ChildProcess` instance is attached to the `Promise` as a `child` property. In
1109
- * case of an error (including any error resulting in an exit code other than 0), a
1110
- * rejected promise is returned, with the same `error` object given in the
1111
- * callback, but with two additional properties `stdout` and `stderr`.
1112
- *
1113
- * ```js
1114
- * const util = require('util');
1115
- * const execFile = util.promisify(require('child_process').execFile);
1116
- * async function getVersion() {
1117
- * const { stdout } = await execFile('node', ['--version']);
1118
- * console.log(stdout);
1119
- * }
1120
- * getVersion();
1121
- * ```
1122
- *
1123
- * **If the `shell` option is enabled, do not pass unsanitized user input to this**
1124
- * **function. Any input containing shell metacharacters may be used to trigger**
1125
- * **arbitrary command execution.**
1126
- *
1127
- * If the `signal` option is enabled, calling `.abort()` on the corresponding`AbortController` is similar to calling `.kill()` on the child process except
1128
- * the error passed to the callback will be an `AbortError`:
1129
- *
1130
- * ```js
1131
- * const { execFile } = require('child_process');
1132
- * const controller = new AbortController();
1133
- * const { signal } = controller;
1134
- * const child = execFile('node', ['--version'], { signal }, (error) => {
1135
- * console.log(error); // an AbortError
1136
- * });
1137
- * controller.abort();
1138
- * ```
1139
- * @since v0.1.91
1140
- * @param file The name or path of the executable file to run.
1141
- * @param args List of string arguments.
1142
- * @param callback Called with the output when process terminates.
1143
- */
1144
- function execFile(file: string): ChildProcess;
1145
- function execFile(
1146
- file: string,
1147
- options: (ObjectEncodingOptions & ExecFileOptions) | undefined | null,
1148
- ): ChildProcess;
1149
- function execFile(file: string, args?: readonly string[] | null): ChildProcess;
1150
- function execFile(
1151
- file: string,
1152
- args: readonly string[] | undefined | null,
1153
- options: (ObjectEncodingOptions & ExecFileOptions) | undefined | null,
1154
- ): ChildProcess;
1155
- // no `options` definitely means stdout/stderr are `string`.
1156
- function execFile(
1157
- file: string,
1158
- callback: (error: ExecFileException | null, stdout: string, stderr: string) => void,
1159
- ): ChildProcess;
1160
- function execFile(
1161
- file: string,
1162
- args: readonly string[] | undefined | null,
1163
- callback: (error: ExecFileException | null, stdout: string, stderr: string) => void,
1164
- ): ChildProcess;
1165
- // `options` with `"buffer"` or `null` for `encoding` means stdout/stderr are definitely `Buffer`.
1166
- function execFile(
1167
- file: string,
1168
- options: ExecFileOptionsWithBufferEncoding,
1169
- callback: (error: ExecFileException | null, stdout: Buffer, stderr: Buffer) => void,
1170
- ): ChildProcess;
1171
- function execFile(
1172
- file: string,
1173
- args: readonly string[] | undefined | null,
1174
- options: ExecFileOptionsWithBufferEncoding,
1175
- callback: (error: ExecFileException | null, stdout: Buffer, stderr: Buffer) => void,
1176
- ): ChildProcess;
1177
- // `options` with well known `encoding` means stdout/stderr are definitely `string`.
1178
- function execFile(
1179
- file: string,
1180
- options: ExecFileOptionsWithStringEncoding,
1181
- callback: (error: ExecFileException | null, stdout: string, stderr: string) => void,
1182
- ): ChildProcess;
1183
- function execFile(
1184
- file: string,
1185
- args: readonly string[] | undefined | null,
1186
- options: ExecFileOptionsWithStringEncoding,
1187
- callback: (error: ExecFileException | null, stdout: string, stderr: string) => void,
1188
- ): ChildProcess;
1189
- // `options` with an `encoding` whose type is `string` means stdout/stderr could either be `Buffer` or `string`.
1190
- // There is no guarantee the `encoding` is unknown as `string` is a superset of `BufferEncoding`.
1191
- function execFile(
1192
- file: string,
1193
- options: ExecFileOptionsWithOtherEncoding,
1194
- callback: (error: ExecFileException | null, stdout: string | Buffer, stderr: string | Buffer) => void,
1195
- ): ChildProcess;
1196
- function execFile(
1197
- file: string,
1198
- args: readonly string[] | undefined | null,
1199
- options: ExecFileOptionsWithOtherEncoding,
1200
- callback: (error: ExecFileException | null, stdout: string | Buffer, stderr: string | Buffer) => void,
1201
- ): ChildProcess;
1202
- // `options` without an `encoding` means stdout/stderr are definitely `string`.
1203
- function execFile(
1204
- file: string,
1205
- options: ExecFileOptions,
1206
- callback: (error: ExecFileException | null, stdout: string, stderr: string) => void,
1207
- ): ChildProcess;
1208
- function execFile(
1209
- file: string,
1210
- args: readonly string[] | undefined | null,
1211
- options: ExecFileOptions,
1212
- callback: (error: ExecFileException | null, stdout: string, stderr: string) => void,
1213
- ): ChildProcess;
1214
- // fallback if nothing else matches. Worst case is always `string | Buffer`.
1215
- function execFile(
1216
- file: string,
1217
- options: (ObjectEncodingOptions & ExecFileOptions) | undefined | null,
1218
- callback:
1219
- | ((error: ExecFileException | null, stdout: string | Buffer, stderr: string | Buffer) => void)
1220
- | undefined
1221
- | null,
1222
- ): ChildProcess;
1223
- function execFile(
1224
- file: string,
1225
- args: readonly string[] | undefined | null,
1226
- options: (ObjectEncodingOptions & ExecFileOptions) | undefined | null,
1227
- callback:
1228
- | ((error: ExecFileException | null, stdout: string | Buffer, stderr: string | Buffer) => void)
1229
- | undefined
1230
- | null,
1231
- ): ChildProcess;
1232
- namespace execFile {
1233
- function __promisify__(file: string): PromiseWithChild<{
1234
- stdout: string;
1235
- stderr: string;
1236
- }>;
1237
- function __promisify__(
1238
- file: string,
1239
- args: readonly string[] | undefined | null,
1240
- ): PromiseWithChild<{
1241
- stdout: string;
1242
- stderr: string;
1243
- }>;
1244
- function __promisify__(
1245
- file: string,
1246
- options: ExecFileOptionsWithBufferEncoding,
1247
- ): PromiseWithChild<{
1248
- stdout: Buffer;
1249
- stderr: Buffer;
1250
- }>;
1251
- function __promisify__(
1252
- file: string,
1253
- args: readonly string[] | undefined | null,
1254
- options: ExecFileOptionsWithBufferEncoding,
1255
- ): PromiseWithChild<{
1256
- stdout: Buffer;
1257
- stderr: Buffer;
1258
- }>;
1259
- function __promisify__(
1260
- file: string,
1261
- options: ExecFileOptionsWithStringEncoding,
1262
- ): PromiseWithChild<{
1263
- stdout: string;
1264
- stderr: string;
1265
- }>;
1266
- function __promisify__(
1267
- file: string,
1268
- args: readonly string[] | undefined | null,
1269
- options: ExecFileOptionsWithStringEncoding,
1270
- ): PromiseWithChild<{
1271
- stdout: string;
1272
- stderr: string;
1273
- }>;
1274
- function __promisify__(
1275
- file: string,
1276
- options: ExecFileOptionsWithOtherEncoding,
1277
- ): PromiseWithChild<{
1278
- stdout: string | Buffer;
1279
- stderr: string | Buffer;
1280
- }>;
1281
- function __promisify__(
1282
- file: string,
1283
- args: readonly string[] | undefined | null,
1284
- options: ExecFileOptionsWithOtherEncoding,
1285
- ): PromiseWithChild<{
1286
- stdout: string | Buffer;
1287
- stderr: string | Buffer;
1288
- }>;
1289
- function __promisify__(
1290
- file: string,
1291
- options: ExecFileOptions,
1292
- ): PromiseWithChild<{
1293
- stdout: string;
1294
- stderr: string;
1295
- }>;
1296
- function __promisify__(
1297
- file: string,
1298
- args: readonly string[] | undefined | null,
1299
- options: ExecFileOptions,
1300
- ): PromiseWithChild<{
1301
- stdout: string;
1302
- stderr: string;
1303
- }>;
1304
- function __promisify__(
1305
- file: string,
1306
- options: (ObjectEncodingOptions & ExecFileOptions) | undefined | null,
1307
- ): PromiseWithChild<{
1308
- stdout: string | Buffer;
1309
- stderr: string | Buffer;
1310
- }>;
1311
- function __promisify__(
1312
- file: string,
1313
- args: readonly string[] | undefined | null,
1314
- options: (ObjectEncodingOptions & ExecFileOptions) | undefined | null,
1315
- ): PromiseWithChild<{
1316
- stdout: string | Buffer;
1317
- stderr: string | Buffer;
1318
- }>;
1319
- }
1320
- interface ForkOptions extends ProcessEnvOptions, MessagingOptions, Abortable {
1321
- execPath?: string | undefined;
1322
- execArgv?: string[] | undefined;
1323
- silent?: boolean | undefined;
1324
- /**
1325
- * Can be set to 'pipe', 'inherit', 'overlapped', or 'ignore', or an array of these strings.
1326
- * If passed as an array, the first element is used for `stdin`, the second for
1327
- * `stdout`, and the third for `stderr`. A fourth element can be used to
1328
- * specify the `stdio` behavior beyond the standard streams. See
1329
- * {@link ChildProcess.stdio} for more information.
1330
- *
1331
- * @default 'pipe'
1332
- */
1333
- stdio?: StdioOptions | undefined;
1334
- detached?: boolean | undefined;
1335
- windowsVerbatimArguments?: boolean | undefined;
1336
- }
1337
- /**
1338
- * The `child_process.fork()` method is a special case of {@link spawn} used specifically to spawn new Node.js processes.
1339
- * Like {@link spawn}, a `ChildProcess` object is returned. The
1340
- * returned `ChildProcess` will have an additional communication channel
1341
- * built-in that allows messages to be passed back and forth between the parent and
1342
- * child. See `subprocess.send()` for details.
1343
- *
1344
- * Keep in mind that spawned Node.js child processes are
1345
- * independent of the parent with exception of the IPC communication channel
1346
- * that is established between the two. Each process has its own memory, with
1347
- * their own V8 instances. Because of the additional resource allocations
1348
- * required, spawning a large number of child Node.js processes is not
1349
- * recommended.
1350
- *
1351
- * By default, `child_process.fork()` will spawn new Node.js instances using the `process.execPath` of the parent process. The `execPath` property in the`options` object allows for an alternative
1352
- * execution path to be used.
1353
- *
1354
- * Node.js processes launched with a custom `execPath` will communicate with the
1355
- * parent process using the file descriptor (fd) identified using the
1356
- * environment variable `NODE_CHANNEL_FD` on the child process.
1357
- *
1358
- * Unlike the [`fork(2)`](http://man7.org/linux/man-pages/man2/fork.2.html) POSIX system call, `child_process.fork()` does not clone the
1359
- * current process.
1360
- *
1361
- * The `shell` option available in {@link spawn} is not supported by`child_process.fork()` and will be ignored if set.
1362
- *
1363
- * If the `signal` option is enabled, calling `.abort()` on the corresponding`AbortController` is similar to calling `.kill()` on the child process except
1364
- * the error passed to the callback will be an `AbortError`:
1365
- *
1366
- * ```js
1367
- * if (process.argv[2] === 'child') {
1368
- * setTimeout(() => {
1369
- * console.log(`Hello from ${process.argv[2]}!`);
1370
- * }, 1_000);
1371
- * } else {
1372
- * const { fork } = require('child_process');
1373
- * const controller = new AbortController();
1374
- * const { signal } = controller;
1375
- * const child = fork(__filename, ['child'], { signal });
1376
- * child.on('error', (err) => {
1377
- * // This will be called with err being an AbortError if the controller aborts
1378
- * });
1379
- * controller.abort(); // Stops the child process
1380
- * }
1381
- * ```
1382
- * @since v0.5.0
1383
- * @param modulePath The module to run in the child.
1384
- * @param args List of string arguments.
1385
- */
1386
- function fork(modulePath: string, options?: ForkOptions): ChildProcess;
1387
- function fork(modulePath: string, args?: readonly string[], options?: ForkOptions): ChildProcess;
1388
- interface SpawnSyncOptions extends CommonSpawnOptions {
1389
- input?: string | NodeJS.ArrayBufferView | undefined;
1390
- maxBuffer?: number | undefined;
1391
- encoding?: BufferEncoding | "buffer" | null | undefined;
1392
- }
1393
- interface SpawnSyncOptionsWithStringEncoding extends SpawnSyncOptions {
1394
- encoding: BufferEncoding;
1395
- }
1396
- interface SpawnSyncOptionsWithBufferEncoding extends SpawnSyncOptions {
1397
- encoding?: "buffer" | null | undefined;
1398
- }
1399
- interface SpawnSyncReturns<T> {
1400
- pid: number;
1401
- output: Array<T | null>;
1402
- stdout: T;
1403
- stderr: T;
1404
- status: number | null;
1405
- signal: NodeJS.Signals | null;
1406
- error?: Error | undefined;
1407
- }
1408
- /**
1409
- * The `child_process.spawnSync()` method is generally identical to {@link spawn} with the exception that the function will not return
1410
- * until the child process has fully closed. When a timeout has been encountered
1411
- * and `killSignal` is sent, the method won't return until the process has
1412
- * completely exited. If the process intercepts and handles the `SIGTERM` signal
1413
- * and doesn't exit, the parent process will wait until the child process has
1414
- * exited.
1415
- *
1416
- * **If the `shell` option is enabled, do not pass unsanitized user input to this**
1417
- * **function. Any input containing shell metacharacters may be used to trigger**
1418
- * **arbitrary command execution.**
1419
- * @since v0.11.12
1420
- * @param command The command to run.
1421
- * @param args List of string arguments.
1422
- */
1423
- function spawnSync(command: string): SpawnSyncReturns<Buffer>;
1424
- function spawnSync(command: string, options: SpawnSyncOptionsWithStringEncoding): SpawnSyncReturns<string>;
1425
- function spawnSync(command: string, options: SpawnSyncOptionsWithBufferEncoding): SpawnSyncReturns<Buffer>;
1426
- function spawnSync(command: string, options?: SpawnSyncOptions): SpawnSyncReturns<string | Buffer>;
1427
- function spawnSync(command: string, args: readonly string[]): SpawnSyncReturns<Buffer>;
1428
- function spawnSync(
1429
- command: string,
1430
- args: readonly string[],
1431
- options: SpawnSyncOptionsWithStringEncoding,
1432
- ): SpawnSyncReturns<string>;
1433
- function spawnSync(
1434
- command: string,
1435
- args: readonly string[],
1436
- options: SpawnSyncOptionsWithBufferEncoding,
1437
- ): SpawnSyncReturns<Buffer>;
1438
- function spawnSync(
1439
- command: string,
1440
- args?: readonly string[],
1441
- options?: SpawnSyncOptions,
1442
- ): SpawnSyncReturns<string | Buffer>;
1443
- interface CommonExecOptions extends CommonOptions {
1444
- input?: string | NodeJS.ArrayBufferView | undefined;
1445
- /**
1446
- * Can be set to 'pipe', 'inherit', 'overlapped', or 'ignore', or an array of these strings.
1447
- * If passed as an array, the first element is used for `stdin`, the second for
1448
- * `stdout`, and the third for `stderr`. A fourth element can be used to
1449
- * specify the `stdio` behavior beyond the standard streams. See
1450
- * {@link ChildProcess.stdio} for more information.
1451
- *
1452
- * @default 'pipe'
1453
- */
1454
- stdio?: StdioOptions | undefined;
1455
- killSignal?: NodeJS.Signals | number | undefined;
1456
- maxBuffer?: number | undefined;
1457
- encoding?: BufferEncoding | "buffer" | null | undefined;
1458
- }
1459
- interface ExecSyncOptions extends CommonExecOptions {
1460
- shell?: string | undefined;
1461
- }
1462
- interface ExecSyncOptionsWithStringEncoding extends ExecSyncOptions {
1463
- encoding: BufferEncoding;
1464
- }
1465
- interface ExecSyncOptionsWithBufferEncoding extends ExecSyncOptions {
1466
- encoding?: "buffer" | null | undefined;
1467
- }
1468
- /**
1469
- * The `child_process.execSync()` method is generally identical to {@link exec} with the exception that the method will not return
1470
- * until the child process has fully closed. When a timeout has been encountered
1471
- * and `killSignal` is sent, the method won't return until the process has
1472
- * completely exited. If the child process intercepts and handles the `SIGTERM`signal and doesn't exit, the parent process will wait until the child process
1473
- * has exited.
1474
- *
1475
- * If the process times out or has a non-zero exit code, this method will throw.
1476
- * The `Error` object will contain the entire result from {@link spawnSync}.
1477
- *
1478
- * **Never pass unsanitized user input to this function. Any input containing shell**
1479
- * **metacharacters may be used to trigger arbitrary command execution.**
1480
- * @since v0.11.12
1481
- * @param command The command to run.
1482
- * @return The stdout from the command.
1483
- */
1484
- function execSync(command: string): Buffer;
1485
- function execSync(command: string, options: ExecSyncOptionsWithStringEncoding): string;
1486
- function execSync(command: string, options: ExecSyncOptionsWithBufferEncoding): Buffer;
1487
- function execSync(command: string, options?: ExecSyncOptions): string | Buffer;
1488
- interface ExecFileSyncOptions extends CommonExecOptions {
1489
- shell?: boolean | string | undefined;
1490
- }
1491
- interface ExecFileSyncOptionsWithStringEncoding extends ExecFileSyncOptions {
1492
- encoding: BufferEncoding;
1493
- }
1494
- interface ExecFileSyncOptionsWithBufferEncoding extends ExecFileSyncOptions {
1495
- encoding?: "buffer" | null; // specify `null`.
1496
- }
1497
- /**
1498
- * The `child_process.execFileSync()` method is generally identical to {@link execFile} with the exception that the method will not
1499
- * return until the child process has fully closed. When a timeout has been
1500
- * encountered and `killSignal` is sent, the method won't return until the process
1501
- * has completely exited.
1502
- *
1503
- * If the child process intercepts and handles the `SIGTERM` signal and
1504
- * does not exit, the parent process will still wait until the child process has
1505
- * exited.
1506
- *
1507
- * If the process times out or has a non-zero exit code, this method will throw an `Error` that will include the full result of the underlying {@link spawnSync}.
1508
- *
1509
- * **If the `shell` option is enabled, do not pass unsanitized user input to this**
1510
- * **function. Any input containing shell metacharacters may be used to trigger**
1511
- * **arbitrary command execution.**
1512
- * @since v0.11.12
1513
- * @param file The name or path of the executable file to run.
1514
- * @param args List of string arguments.
1515
- * @return The stdout from the command.
1516
- */
1517
- function execFileSync(file: string): Buffer;
1518
- function execFileSync(file: string, options: ExecFileSyncOptionsWithStringEncoding): string;
1519
- function execFileSync(file: string, options: ExecFileSyncOptionsWithBufferEncoding): Buffer;
1520
- function execFileSync(file: string, options?: ExecFileSyncOptions): string | Buffer;
1521
- function execFileSync(file: string, args: readonly string[]): Buffer;
1522
- function execFileSync(
1523
- file: string,
1524
- args: readonly string[],
1525
- options: ExecFileSyncOptionsWithStringEncoding,
1526
- ): string;
1527
- function execFileSync(
1528
- file: string,
1529
- args: readonly string[],
1530
- options: ExecFileSyncOptionsWithBufferEncoding,
1531
- ): Buffer;
1532
- function execFileSync(file: string, args?: readonly string[], options?: ExecFileSyncOptions): string | Buffer;
1533
- }
1534
- declare module "node:child_process" {
1535
- export * from "child_process";
1536
- }