Skip to content

Commit

Permalink
child_process: add support for URL to cp.fork
Browse files Browse the repository at this point in the history
PR-URL: #41225
Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
aduh95 authored and danielleadams committed Feb 1, 2022
1 parent c021b38 commit 15e5d7a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
11 changes: 9 additions & 2 deletions doc/api/child_process.md
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,14 @@ controller.abort();
<!-- YAML
added: v0.5.0
changes:
- version: v16.4.0
- version:
- REPLACEME
pr-url: https://github.com/nodejs/node/pull/41225
description: The `modulePath` parameter can be a WHATWG `URL` object using
`file:` protocol.
- version:
- v16.4.0
- v14.18.0
pr-url: https://github.com/nodejs/node/pull/38862
description: The `cwd` option can be a WHATWG `URL` object using
`file:` protocol.
Expand All @@ -411,7 +418,7 @@ changes:
description: The `stdio` option is supported now.
-->

* `modulePath` {string} The module to run in the child.
* `modulePath` {string|URL} The module to run in the child.
* `args` {string\[]} List of string arguments.
* `options` {Object}
* `cwd` {string|URL} Current working directory of the child process.
Expand Down
4 changes: 2 additions & 2 deletions lib/child_process.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ const MAX_BUFFER = 1024 * 1024;

/**
* Spawns a new Node.js process + fork.
* @param {string} modulePath
* @param {string|URL} modulePath
* @param {string[]} [args]
* @param {{
* cwd?: string;
Expand All @@ -112,7 +112,7 @@ const MAX_BUFFER = 1024 * 1024;
* @returns {ChildProcess}
*/
function fork(modulePath /* , args, options */) {
validateString(modulePath, 'modulePath');
modulePath = getValidatedPath(modulePath, 'modulePath');

// Get options and args arguments.
let execArgv;
Expand Down
11 changes: 11 additions & 0 deletions test/parallel/test-child-process-fork-url.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { mustCall } from '../common/index.mjs';
import { fork } from 'child_process';

if (process.argv[2] === 'child') {
process.disconnect();
} else {
const child = fork(new URL(import.meta.url), ['child']);

child.on('disconnect', mustCall());
child.once('exit', mustCall());
}

0 comments on commit 15e5d7a

Please sign in to comment.