From 3735a1a54225a058914f4356c2d271bb12fab6a7 Mon Sep 17 00:00:00 2001 From: Divy Srivastava Date: Fri, 7 Jun 2024 22:51:32 +0530 Subject: fix(ext/node): support stdin child_process IPC & fd stdout/stderr (#24106) Add supports for "ipc" and fd options in child_process spawn API. Internal changes: Adds a hidden rid and "ipc_for_internal_use" option to Deno.Command. Used by `node:child_process` Example: ```js const out = fs.openSync("./logfile.txt", 'a') const proc = spawn(process.execPath, ["./main.mjs", "child"], { stdio: ["ipc", out, "inherit"] }); ``` Ref #16753 --- ext/node/polyfills/internal/child_process.ts | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'ext/node/polyfills/internal') diff --git a/ext/node/polyfills/internal/child_process.ts b/ext/node/polyfills/internal/child_process.ts index b6137e0d1..cabae63ee 100644 --- a/ext/node/polyfills/internal/child_process.ts +++ b/ext/node/polyfills/internal/child_process.ts @@ -362,17 +362,25 @@ export class ChildProcess extends EventEmitter { } } -const supportedNodeStdioTypes: NodeStdio[] = ["pipe", "ignore", "inherit"]; +const supportedNodeStdioTypes: NodeStdio[] = [ + "pipe", + "ignore", + "inherit", + "ipc", +]; function toDenoStdio( pipe: NodeStdio | number | Stream | null | undefined, ): DenoStdio { if (pipe instanceof Stream) { return "inherit"; } + if (typeof pipe === "number") { + /* Assume it's a rid returned by fs APIs */ + return pipe; + } if ( - !supportedNodeStdioTypes.includes(pipe as NodeStdio) || - typeof pipe === "number" + !supportedNodeStdioTypes.includes(pipe as NodeStdio) ) { notImplemented(`toDenoStdio pipe=${typeof pipe} (${pipe})`); } @@ -385,6 +393,8 @@ function toDenoStdio( return "null"; case "inherit": return "inherit"; + case "ipc": + return "ipc_for_internal_use"; default: notImplemented(`toDenoStdio pipe=${typeof pipe} (${pipe})`); } @@ -1083,8 +1093,7 @@ function toDenoArgs(args: string[]): string[] { if (useRunArgs) { // -A is not ideal, but needed to propagate permissions. - // --unstable is needed for Node compat. - denoArgs.unshift("run", "-A", "--unstable"); + denoArgs.unshift("run", "-A"); } return denoArgs; -- cgit v1.2.3