fix(node): Create additional pipes for child processes (#25016)

Linux/macos only currently.

Part of https://github.com/denoland/deno/issues/23524 (fixes it on
platforms other than windows).
Part of #16899  (fixes it on platforms other than windows).

After this PR, playwright is functional on mac/linux.
This commit is contained in:
Nathan Whitaker 2024-08-15 09:38:46 -07:00 committed by GitHub
parent 7ca95fc999
commit 8749d651fb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
17 changed files with 785 additions and 304 deletions

View file

@ -168,7 +168,7 @@ function run({
const illegalConstructorKey = Symbol("illegalConstructorKey");
function spawnChildInner(opFn, command, apiName, {
function spawnChildInner(command, apiName, {
args = [],
cwd = undefined,
clearEnv = false,
@ -181,8 +181,9 @@ function spawnChildInner(opFn, command, apiName, {
signal = undefined,
windowsRawArguments = false,
ipc = -1,
extraStdio = [],
} = { __proto__: null }) {
const child = opFn({
const child = op_spawn_child({
cmd: pathFromURL(command),
args: ArrayPrototypeMap(args, String),
cwd: pathFromURL(cwd),
@ -195,6 +196,7 @@ function spawnChildInner(opFn, command, apiName, {
stderr,
windowsRawArguments,
ipc,
extraStdio,
}, apiName);
return new ChildProcess(illegalConstructorKey, {
...child,
@ -204,7 +206,6 @@ function spawnChildInner(opFn, command, apiName, {
function spawnChild(command, options = { __proto__: null }) {
return spawnChildInner(
op_spawn_child,
command,
"Deno.Command().spawn()",
options,
@ -221,16 +222,19 @@ function collectOutput(readableStream) {
return readableStreamCollectIntoUint8Array(readableStream);
}
const _pipeFd = Symbol("[[pipeFd]]");
const _ipcPipeRid = Symbol("[[ipcPipeRid]]");
const _extraPipeRids = Symbol("[[_extraPipeRids]]");
internals.getPipeFd = (process) => process[_pipeFd];
internals.getIpcPipeRid = (process) => process[_ipcPipeRid];
internals.getExtraPipeRids = (process) => process[_extraPipeRids];
class ChildProcess {
#rid;
#waitPromise;
#waitComplete = false;
[_pipeFd];
[_ipcPipeRid];
[_extraPipeRids];
#pid;
get pid() {
@ -268,7 +272,8 @@ class ChildProcess {
stdinRid,
stdoutRid,
stderrRid,
pipeFd, // internal
ipcPipeRid, // internal
extraPipeRids,
} = null) {
if (key !== illegalConstructorKey) {
throw new TypeError("Illegal constructor.");
@ -276,7 +281,8 @@ class ChildProcess {
this.#rid = rid;
this.#pid = pid;
this[_pipeFd] = pipeFd;
this[_ipcPipeRid] = ipcPipeRid;
this[_extraPipeRids] = extraPipeRids;
if (stdinRid !== null) {
this.#stdin = writableStreamForRid(stdinRid);
@ -380,7 +386,6 @@ function spawn(command, options) {
);
}
return spawnChildInner(
op_spawn_child,
command,
"Deno.Command().output()",
options,
@ -417,6 +422,7 @@ function spawnSync(command, {
stdout,
stderr,
windowsRawArguments,
extraStdio: [],
});
return {
success: result.status.success,