Skip to content

Commit 15e5d7a

Browse files
aduh95danielleadams
authored andcommitted
child_process: add support for URL to cp.fork
PR-URL: #41225 Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent c021b38 commit 15e5d7a

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

doc/api/child_process.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,14 @@ controller.abort();
385385
<!-- YAML
386386
added: v0.5.0
387387
changes:
388-
- version: v16.4.0
388+
- version:
389+
- REPLACEME
390+
pr-url: https://github.com/nodejs/node/pull/41225
391+
description: The `modulePath` parameter can be a WHATWG `URL` object using
392+
`file:` protocol.
393+
- version:
394+
- v16.4.0
395+
- v14.18.0
389396
pr-url: https://github.com/nodejs/node/pull/38862
390397
description: The `cwd` option can be a WHATWG `URL` object using
391398
`file:` protocol.
@@ -411,7 +418,7 @@ changes:
411418
description: The `stdio` option is supported now.
412419
-->
413420

414-
* `modulePath` {string} The module to run in the child.
421+
* `modulePath` {string|URL} The module to run in the child.
415422
* `args` {string\[]} List of string arguments.
416423
* `options` {Object}
417424
* `cwd` {string|URL} Current working directory of the child process.

lib/child_process.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ const MAX_BUFFER = 1024 * 1024;
9191

9292
/**
9393
* Spawns a new Node.js process + fork.
94-
* @param {string} modulePath
94+
* @param {string|URL} modulePath
9595
* @param {string[]} [args]
9696
* @param {{
9797
* cwd?: string;
@@ -112,7 +112,7 @@ const MAX_BUFFER = 1024 * 1024;
112112
* @returns {ChildProcess}
113113
*/
114114
function fork(modulePath /* , args, options */) {
115-
validateString(modulePath, 'modulePath');
115+
modulePath = getValidatedPath(modulePath, 'modulePath');
116116

117117
// Get options and args arguments.
118118
let execArgv;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { mustCall } from '../common/index.mjs';
2+
import { fork } from 'child_process';
3+
4+
if (process.argv[2] === 'child') {
5+
process.disconnect();
6+
} else {
7+
const child = fork(new URL(import.meta.url), ['child']);
8+
9+
child.on('disconnect', mustCall());
10+
child.once('exit', mustCall());
11+
}

0 commit comments

Comments
 (0)