1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-28 16:20:57 -05:00

fix(ext/node): support stdin: "inherit" in node:child_process (#23110)

Fixes https://github.com/denoland/deno/issues/23051
This commit is contained in:
Divy Srivastava 2024-03-28 19:44:42 +05:30 committed by GitHub
parent de0b230078
commit bca0fe1cde
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 34 additions and 1 deletions

View file

@ -866,7 +866,7 @@ export function spawnSync(
windowsVerbatimArguments = false, windowsVerbatimArguments = false,
} = options; } = options;
const [ const [
_stdin_ = "pipe", // TODO(bartlomieju): use this? stdin_ = "pipe",
stdout_ = "pipe", stdout_ = "pipe",
stderr_ = "pipe", stderr_ = "pipe",
_channel, // TODO(kt3k): handle this correctly _channel, // TODO(kt3k): handle this correctly
@ -881,6 +881,7 @@ export function spawnSync(
env: mapValues(env, (value) => value.toString()), env: mapValues(env, (value) => value.toString()),
stdout: toDenoStdio(stdout_), stdout: toDenoStdio(stdout_),
stderr: toDenoStdio(stderr_), stderr: toDenoStdio(stderr_),
stdin: stdin_ == "inherit" ? "inherit" : "null",
uid, uid,
gid, gid,
windowsRawArguments: windowsVerbatimArguments, windowsRawArguments: windowsVerbatimArguments,

View file

@ -823,3 +823,35 @@ Deno.test(function spawnCommandNullStdioArray() {
assertEquals(ret.status, 0); assertEquals(ret.status, 0);
}); });
Deno.test(
function stdinInherit() {
const script = `
function timeoutPromise(promise, timeout) {
return new Promise((resolve, reject) => {
const timeoutId = setTimeout(() => {
Deno.exit(69);
}, timeout);
promise.then((value) => {
clearTimeout(timeoutId);
resolve(value);
}, (reason) => {
clearTimeout(timeoutId);
reject(reason);
});
});
}
await timeoutPromise(Deno.stdin.read(new Uint8Array(1)), 100)
`;
const output = spawnSync(Deno.execPath(), ["eval", script], {
stdio: "inherit",
});
// We want to timeout to occur because the stdin isn't 'null'
assertEquals(output.status, 69);
assertEquals(output.stdout, null);
assertEquals(output.stderr, null);
},
);