lib: add JSDoc typings for child_process

Added JSDoc typings for the `child_process` lib module.

PR-URL: https://github.com/nodejs/node/pull/38222
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michael Dawson <midawson@redhat.com>
This commit is contained in:
Voltrex 2021-04-13 05:31:10 +04:30 committed by Richard Lau
parent 04032fa1a3
commit 2bc2a232af
No known key found for this signature in database
GPG Key ID: C43CEC45C17AB93C

View File

@ -74,6 +74,28 @@ const {
const MAX_BUFFER = 1024 * 1024; const MAX_BUFFER = 1024 * 1024;
/**
* Spawns a new Node.js process + fork.
* @param {string} modulePath
* @param {string[]} [args]
* @param {{
* cwd?: string;
* detached?: boolean;
* env?: Object;
* execPath?: string;
* execArgv?: string[];
* gid?: number;
* serialization?: string;
* signal?: AbortSignal;
* killSignal?: string | number;
* silent?: boolean;
* stdio?: Array | string;
* uid?: number;
* windowsVerbatimArguments?: boolean;
* timeout?: number;
* }} [options]
* @returns {ChildProcess}
*/
function fork(modulePath /* , args, options */) { function fork(modulePath /* , args, options */) {
validateString(modulePath, 'modulePath'); validateString(modulePath, 'modulePath');
@ -161,7 +183,29 @@ function normalizeExecArgs(command, options, callback) {
}; };
} }
/**
* Spawns a shell executing the given command.
* @param {string} command
* @param {{
* cmd?: string;
* env?: Object;
* encoding?: string;
* shell?: string;
* signal?: AbortSignal;
* timeout?: number;
* maxBuffer?: number;
* killSignal?: string | number;
* uid?: number;
* gid?: number;
* windowsHide?: boolean;
* }} [options]
* @param {(
* error?: Error,
* stdout?: string | Buffer,
* stderr?: string | Buffer
* ) => any} [callback]
* @returns {ChildProcess}
*/
function exec(command, options, callback) { function exec(command, options, callback) {
const opts = normalizeExecArgs(command, options, callback); const opts = normalizeExecArgs(command, options, callback);
return module.exports.execFile(opts.file, return module.exports.execFile(opts.file,
@ -197,6 +241,31 @@ ObjectDefineProperty(exec, promisify.custom, {
value: customPromiseExecFunction(exec) value: customPromiseExecFunction(exec)
}); });
/**
* Spawns the specified file as a shell.
* @param {string} file
* @param {string[]} [args]
* @param {{
* cwd?: string;
* env?: Object;
* encoding?: string;
* timeout?: number;
* maxBuffer?: number;
* killSignal?: string | number;
* uid?: number;
* gid?: number;
* windowsHide?: boolean;
* windowsVerbatimArguments?: boolean;
* shell?: boolean | string;
* signal?: AbortSignal;
* }} [options]
* @param {(
* error?: Error,
* stdout?: string | Buffer,
* stderr?: string | Buffer
* ) => any} [callback]
* @returns {ChildProcess}
*/
function execFile(file /* , args, options, callback */) { function execFile(file /* , args, options, callback */) {
let args = []; let args = [];
let callback; let callback;
@ -567,6 +636,28 @@ function normalizeSpawnArguments(file, args, options) {
} }
/**
* Spawns a new process using the given `file`.
* @param {string} file
* @param {string[]} [args]
* @param {{
* cwd?: string;
* env?: Object;
* argv0?: string;
* stdio?: Array | string;
* detached?: boolean;
* uid?: number;
* gid?: number;
* serialization?: string;
* shell?: boolean | string;
* windowsVerbatimArguments?: boolean;
* windowsHide?: boolean;
* signal?: AbortSignal;
* timeout?: number;
* killSignal?: string | number;
* }} [options]
* @returns {ChildProcess}
*/
function spawn(file, args, options) { function spawn(file, args, options) {
const child = new ChildProcess(); const child = new ChildProcess();
@ -577,6 +668,36 @@ function spawn(file, args, options) {
return child; return child;
} }
/**
* Spawns a new process synchronously using the given `file`.
* @param {string} file
* @param {string[]} [args]
* @param {{
* cwd?: string;
* input?: string | Buffer | TypedArray | DataView;
* argv0?: string;
* stdio?: string | Array;
* env?: Object;
* uid?: number;
* gid?: number;
* timeout?: number;
* killSignal?: string | number;
* maxBuffer?: number;
* encoding?: string;
* shell?: boolean | string;
* windowsVerbatimArguments?: boolean;
* windowsHide?: boolean;
* }} [options]
* @returns {{
* pid: number;
* output: Array;
* stdout: Buffer | string;
* stderr: Buffer | string;
* status: number | null;
* signal: string | null;
* error: Error;
* }}
*/
function spawnSync(file, args, options) { function spawnSync(file, args, options) {
options = { options = {
maxBuffer: MAX_BUFFER, maxBuffer: MAX_BUFFER,
@ -643,7 +764,26 @@ function checkExecSyncError(ret, args, cmd) {
return err; return err;
} }
/**
* Spawns a file as a shell synchronously.
* @param {string} command
* @param {string[]} [args]
* @param {{
* cwd?: string;
* input?: string | Buffer | TypedArray | DataView;
* stdio?: string | Array;
* env?: Object;
* uid?: number;
* gid?: number;
* timeout?: number;
* killSignal?: string | number;
* maxBuffer?: number;
* encoding?: string;
* windowsHide?: boolean;
* shell?: boolean | string;
* }} [options]
* @returns {Buffer | string}
*/
function execFileSync(command, args, options) { function execFileSync(command, args, options) {
options = normalizeSpawnArguments(command, args, options); options = normalizeSpawnArguments(command, args, options);
@ -661,7 +801,25 @@ function execFileSync(command, args, options) {
return ret.stdout; return ret.stdout;
} }
/**
* Spawns a shell executing the given `command` synchronously.
* @param {string} command
* @param {{
* cwd?: string;
* input?: string | Buffer | TypedArray | DataView;
* stdio?: string | Array;
* env?: Object;
* shell?: string;
* uid?: number;
* gid?: number;
* timeout?: number;
* killSignal?: string | number;
* maxBuffer?: number;
* encoding?: string;
* windowsHide?: boolean;
* }} [options]
* @returns {Buffer | string}
*/
function execSync(command, options) { function execSync(command, options) {
const opts = normalizeExecArgs(command, options, null); const opts = normalizeExecArgs(command, options, null);
const inheritStderr = !opts.options.stdio; const inheritStderr = !opts.options.stdio;