summaryrefslogtreecommitdiff
path: root/ext/node/polyfills/internal/child_process.ts
diff options
context:
space:
mode:
authorDivy Srivastava <dj.srivastava23@gmail.com>2024-06-07 22:51:32 +0530
committerGitHub <noreply@github.com>2024-06-07 22:51:32 +0530
commit3735a1a54225a058914f4356c2d271bb12fab6a7 (patch)
treeb7c21736a0f2daa1ac659d8a82e34f572c7c7ae9 /ext/node/polyfills/internal/child_process.ts
parented20102713dd3269629b8e329f62d081be506430 (diff)
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
Diffstat (limited to 'ext/node/polyfills/internal/child_process.ts')
-rw-r--r--ext/node/polyfills/internal/child_process.ts19
1 files changed, 14 insertions, 5 deletions
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;