Skip to content

Commit 5514305

Browse files
VoltrexKeyvadanielleadams
authored andcommitted
lib: add JSDoc typings for child_process
Added JSDoc typings for the `child_process` lib module. PR-URL: #38222 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michael Dawson <midawson@redhat.com>
1 parent dce256b commit 5514305

File tree

1 file changed

+161
-4
lines changed

1 file changed

+161
-4
lines changed

lib/child_process.js

+161-4
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,28 @@ const {
8989

9090
const MAX_BUFFER = 1024 * 1024;
9191

92+
/**
93+
* Spawns a new Node.js process + fork.
94+
* @param {string} modulePath
95+
* @param {string[]} [args]
96+
* @param {{
97+
* cwd?: string;
98+
* detached?: boolean;
99+
* env?: Object;
100+
* execPath?: string;
101+
* execArgv?: string[];
102+
* gid?: number;
103+
* serialization?: string;
104+
* signal?: AbortSignal;
105+
* killSignal?: string | number;
106+
* silent?: boolean;
107+
* stdio?: Array | string;
108+
* uid?: number;
109+
* windowsVerbatimArguments?: boolean;
110+
* timeout?: number;
111+
* }} [options]
112+
* @returns {ChildProcess}
113+
*/
92114
function fork(modulePath /* , args, options */) {
93115
validateString(modulePath, 'modulePath');
94116

@@ -176,7 +198,29 @@ function normalizeExecArgs(command, options, callback) {
176198
};
177199
}
178200

179-
201+
/**
202+
* Spawns a shell executing the given command.
203+
* @param {string} command
204+
* @param {{
205+
* cmd?: string;
206+
* env?: Object;
207+
* encoding?: string;
208+
* shell?: string;
209+
* signal?: AbortSignal;
210+
* timeout?: number;
211+
* maxBuffer?: number;
212+
* killSignal?: string | number;
213+
* uid?: number;
214+
* gid?: number;
215+
* windowsHide?: boolean;
216+
* }} [options]
217+
* @param {(
218+
* error?: Error,
219+
* stdout?: string | Buffer,
220+
* stderr?: string | Buffer
221+
* ) => any} [callback]
222+
* @returns {ChildProcess}
223+
*/
180224
function exec(command, options, callback) {
181225
const opts = normalizeExecArgs(command, options, callback);
182226
return module.exports.execFile(opts.file,
@@ -207,6 +251,31 @@ ObjectDefineProperty(exec, promisify.custom, {
207251
value: customPromiseExecFunction(exec)
208252
});
209253

254+
/**
255+
* Spawns the specified file as a shell.
256+
* @param {string} file
257+
* @param {string[]} [args]
258+
* @param {{
259+
* cwd?: string;
260+
* env?: Object;
261+
* encoding?: string;
262+
* timeout?: number;
263+
* maxBuffer?: number;
264+
* killSignal?: string | number;
265+
* uid?: number;
266+
* gid?: number;
267+
* windowsHide?: boolean;
268+
* windowsVerbatimArguments?: boolean;
269+
* shell?: boolean | string;
270+
* signal?: AbortSignal;
271+
* }} [options]
272+
* @param {(
273+
* error?: Error,
274+
* stdout?: string | Buffer,
275+
* stderr?: string | Buffer
276+
* ) => any} [callback]
277+
* @returns {ChildProcess}
278+
*/
210279
function execFile(file /* , args, options, callback */) {
211280
let args = [];
212281
let callback;
@@ -596,7 +665,28 @@ function abortChildProcess(child, killSignal) {
596665
}
597666
}
598667

599-
668+
/**
669+
* Spawns a new process using the given `file`.
670+
* @param {string} file
671+
* @param {string[]} [args]
672+
* @param {{
673+
* cwd?: string;
674+
* env?: Object;
675+
* argv0?: string;
676+
* stdio?: Array | string;
677+
* detached?: boolean;
678+
* uid?: number;
679+
* gid?: number;
680+
* serialization?: string;
681+
* shell?: boolean | string;
682+
* windowsVerbatimArguments?: boolean;
683+
* windowsHide?: boolean;
684+
* signal?: AbortSignal;
685+
* timeout?: number;
686+
* killSignal?: string | number;
687+
* }} [options]
688+
* @returns {ChildProcess}
689+
*/
600690
function spawn(file, args, options) {
601691
options = normalizeSpawnArguments(file, args, options);
602692
validateTimeout(options.timeout);
@@ -645,6 +735,36 @@ function spawn(file, args, options) {
645735
return child;
646736
}
647737

738+
/**
739+
* Spawns a new process synchronously using the given `file`.
740+
* @param {string} file
741+
* @param {string[]} [args]
742+
* @param {{
743+
* cwd?: string;
744+
* input?: string | Buffer | TypedArray | DataView;
745+
* argv0?: string;
746+
* stdio?: string | Array;
747+
* env?: Object;
748+
* uid?: number;
749+
* gid?: number;
750+
* timeout?: number;
751+
* killSignal?: string | number;
752+
* maxBuffer?: number;
753+
* encoding?: string;
754+
* shell?: boolean | string;
755+
* windowsVerbatimArguments?: boolean;
756+
* windowsHide?: boolean;
757+
* }} [options]
758+
* @returns {{
759+
* pid: number;
760+
* output: Array;
761+
* stdout: Buffer | string;
762+
* stderr: Buffer | string;
763+
* status: number | null;
764+
* signal: string | null;
765+
* error: Error;
766+
* }}
767+
*/
648768
function spawnSync(file, args, options) {
649769
options = {
650770
maxBuffer: MAX_BUFFER,
@@ -711,7 +831,26 @@ function checkExecSyncError(ret, args, cmd) {
711831
return err;
712832
}
713833

714-
834+
/**
835+
* Spawns a file as a shell synchronously.
836+
* @param {string} command
837+
* @param {string[]} [args]
838+
* @param {{
839+
* cwd?: string;
840+
* input?: string | Buffer | TypedArray | DataView;
841+
* stdio?: string | Array;
842+
* env?: Object;
843+
* uid?: number;
844+
* gid?: number;
845+
* timeout?: number;
846+
* killSignal?: string | number;
847+
* maxBuffer?: number;
848+
* encoding?: string;
849+
* windowsHide?: boolean;
850+
* shell?: boolean | string;
851+
* }} [options]
852+
* @returns {Buffer | string}
853+
*/
715854
function execFileSync(command, args, options) {
716855
options = normalizeSpawnArguments(command, args, options);
717856

@@ -730,7 +869,25 @@ function execFileSync(command, args, options) {
730869
return ret.stdout;
731870
}
732871

733-
872+
/**
873+
* Spawns a shell executing the given `command` synchronously.
874+
* @param {string} command
875+
* @param {{
876+
* cwd?: string;
877+
* input?: string | Buffer | TypedArray | DataView;
878+
* stdio?: string | Array;
879+
* env?: Object;
880+
* shell?: string;
881+
* uid?: number;
882+
* gid?: number;
883+
* timeout?: number;
884+
* killSignal?: string | number;
885+
* maxBuffer?: number;
886+
* encoding?: string;
887+
* windowsHide?: boolean;
888+
* }} [options]
889+
* @returns {Buffer | string}
890+
*/
734891
function execSync(command, options) {
735892
const opts = normalizeExecArgs(command, options, null);
736893
const inheritStderr = !opts.options.stdio;

0 commit comments

Comments
 (0)