Skip to content

Commit 2bc2a23

Browse files
VoltrexKeyvarichardlau
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 <[email protected]> Reviewed-By: Michael Dawson <[email protected]>
1 parent 04032fa commit 2bc2a23

File tree

1 file changed

+161
-3
lines changed

1 file changed

+161
-3
lines changed

lib/child_process.js

Lines changed: 161 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,28 @@ const {
7474

7575
const MAX_BUFFER = 1024 * 1024;
7676

77+
/**
78+
* Spawns a new Node.js process + fork.
79+
* @param {string} modulePath
80+
* @param {string[]} [args]
81+
* @param {{
82+
* cwd?: string;
83+
* detached?: boolean;
84+
* env?: Object;
85+
* execPath?: string;
86+
* execArgv?: string[];
87+
* gid?: number;
88+
* serialization?: string;
89+
* signal?: AbortSignal;
90+
* killSignal?: string | number;
91+
* silent?: boolean;
92+
* stdio?: Array | string;
93+
* uid?: number;
94+
* windowsVerbatimArguments?: boolean;
95+
* timeout?: number;
96+
* }} [options]
97+
* @returns {ChildProcess}
98+
*/
7799
function fork(modulePath /* , args, options */) {
78100
validateString(modulePath, 'modulePath');
79101

@@ -161,7 +183,29 @@ function normalizeExecArgs(command, options, callback) {
161183
};
162184
}
163185

164-
186+
/**
187+
* Spawns a shell executing the given command.
188+
* @param {string} command
189+
* @param {{
190+
* cmd?: string;
191+
* env?: Object;
192+
* encoding?: string;
193+
* shell?: string;
194+
* signal?: AbortSignal;
195+
* timeout?: number;
196+
* maxBuffer?: number;
197+
* killSignal?: string | number;
198+
* uid?: number;
199+
* gid?: number;
200+
* windowsHide?: boolean;
201+
* }} [options]
202+
* @param {(
203+
* error?: Error,
204+
* stdout?: string | Buffer,
205+
* stderr?: string | Buffer
206+
* ) => any} [callback]
207+
* @returns {ChildProcess}
208+
*/
165209
function exec(command, options, callback) {
166210
const opts = normalizeExecArgs(command, options, callback);
167211
return module.exports.execFile(opts.file,
@@ -197,6 +241,31 @@ ObjectDefineProperty(exec, promisify.custom, {
197241
value: customPromiseExecFunction(exec)
198242
});
199243

244+
/**
245+
* Spawns the specified file as a shell.
246+
* @param {string} file
247+
* @param {string[]} [args]
248+
* @param {{
249+
* cwd?: string;
250+
* env?: Object;
251+
* encoding?: string;
252+
* timeout?: number;
253+
* maxBuffer?: number;
254+
* killSignal?: string | number;
255+
* uid?: number;
256+
* gid?: number;
257+
* windowsHide?: boolean;
258+
* windowsVerbatimArguments?: boolean;
259+
* shell?: boolean | string;
260+
* signal?: AbortSignal;
261+
* }} [options]
262+
* @param {(
263+
* error?: Error,
264+
* stdout?: string | Buffer,
265+
* stderr?: string | Buffer
266+
* ) => any} [callback]
267+
* @returns {ChildProcess}
268+
*/
200269
function execFile(file /* , args, options, callback */) {
201270
let args = [];
202271
let callback;
@@ -567,6 +636,28 @@ function normalizeSpawnArguments(file, args, options) {
567636
}
568637

569638

639+
/**
640+
* Spawns a new process using the given `file`.
641+
* @param {string} file
642+
* @param {string[]} [args]
643+
* @param {{
644+
* cwd?: string;
645+
* env?: Object;
646+
* argv0?: string;
647+
* stdio?: Array | string;
648+
* detached?: boolean;
649+
* uid?: number;
650+
* gid?: number;
651+
* serialization?: string;
652+
* shell?: boolean | string;
653+
* windowsVerbatimArguments?: boolean;
654+
* windowsHide?: boolean;
655+
* signal?: AbortSignal;
656+
* timeout?: number;
657+
* killSignal?: string | number;
658+
* }} [options]
659+
* @returns {ChildProcess}
660+
*/
570661
function spawn(file, args, options) {
571662
const child = new ChildProcess();
572663

@@ -577,6 +668,36 @@ function spawn(file, args, options) {
577668
return child;
578669
}
579670

671+
/**
672+
* Spawns a new process synchronously using the given `file`.
673+
* @param {string} file
674+
* @param {string[]} [args]
675+
* @param {{
676+
* cwd?: string;
677+
* input?: string | Buffer | TypedArray | DataView;
678+
* argv0?: string;
679+
* stdio?: string | Array;
680+
* env?: Object;
681+
* uid?: number;
682+
* gid?: number;
683+
* timeout?: number;
684+
* killSignal?: string | number;
685+
* maxBuffer?: number;
686+
* encoding?: string;
687+
* shell?: boolean | string;
688+
* windowsVerbatimArguments?: boolean;
689+
* windowsHide?: boolean;
690+
* }} [options]
691+
* @returns {{
692+
* pid: number;
693+
* output: Array;
694+
* stdout: Buffer | string;
695+
* stderr: Buffer | string;
696+
* status: number | null;
697+
* signal: string | null;
698+
* error: Error;
699+
* }}
700+
*/
580701
function spawnSync(file, args, options) {
581702
options = {
582703
maxBuffer: MAX_BUFFER,
@@ -643,7 +764,26 @@ function checkExecSyncError(ret, args, cmd) {
643764
return err;
644765
}
645766

646-
767+
/**
768+
* Spawns a file as a shell synchronously.
769+
* @param {string} command
770+
* @param {string[]} [args]
771+
* @param {{
772+
* cwd?: string;
773+
* input?: string | Buffer | TypedArray | DataView;
774+
* stdio?: string | Array;
775+
* env?: Object;
776+
* uid?: number;
777+
* gid?: number;
778+
* timeout?: number;
779+
* killSignal?: string | number;
780+
* maxBuffer?: number;
781+
* encoding?: string;
782+
* windowsHide?: boolean;
783+
* shell?: boolean | string;
784+
* }} [options]
785+
* @returns {Buffer | string}
786+
*/
647787
function execFileSync(command, args, options) {
648788
options = normalizeSpawnArguments(command, args, options);
649789

@@ -661,7 +801,25 @@ function execFileSync(command, args, options) {
661801
return ret.stdout;
662802
}
663803

664-
804+
/**
805+
* Spawns a shell executing the given `command` synchronously.
806+
* @param {string} command
807+
* @param {{
808+
* cwd?: string;
809+
* input?: string | Buffer | TypedArray | DataView;
810+
* stdio?: string | Array;
811+
* env?: Object;
812+
* shell?: string;
813+
* uid?: number;
814+
* gid?: number;
815+
* timeout?: number;
816+
* killSignal?: string | number;
817+
* maxBuffer?: number;
818+
* encoding?: string;
819+
* windowsHide?: boolean;
820+
* }} [options]
821+
* @returns {Buffer | string}
822+
*/
665823
function execSync(command, options) {
666824
const opts = normalizeExecArgs(command, options, null);
667825
const inheritStderr = !opts.options.stdio;

0 commit comments

Comments
 (0)