Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions ext/node/ops/node_cli_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,17 @@ pub fn op_node_translate_cli_args(
script_in_npm_package: bool,
wrap_eval: bool,
) -> Result<TranslatedArgs, CliParserError> {
// If no args, return early with run -A -
// If no args, return early with run -A --ext=cjs -
// `-` tells Deno to read from stdin, matching Node.js behavior where
// `node` with no args reads and executes piped stdin.
// `node` with no args reads and executes piped stdin as CommonJS.
if args.is_empty() {
return Ok(TranslatedArgs {
deno_args: vec!["run".to_string(), "-A".to_string(), "-".to_string()],
deno_args: vec![
"run".to_string(),
"-A".to_string(),
"--ext=cjs".to_string(),
"-".to_string(),
],
node_options: vec![],
ca_stores: None,
use_openssl_ca: false,
Expand Down
11 changes: 8 additions & 3 deletions ext/node/polyfills/internal/child_process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -959,6 +959,9 @@ function streamHandleFd(stream) {
if (handle && typeof handle.fd === "number" && handle.fd >= 0) {
return handle.fd;
}
if (typeof stream.fd === "number" && stream.fd >= 0) {
return stream.fd;
}
return -1;
}

Expand Down Expand Up @@ -997,9 +1000,11 @@ function toDenoStdio(
// another child's stdin shares the underlying OS pipe.
const fd = streamHandleFd(pipe);
if (fd >= 0) {
pipe[kChildStdioUsedAsInput] = true;
pipe.pause();
pipe._handle?.readStop?.();
if (typeof pipe.pause === "function") {
pipe[kChildStdioUsedAsInput] = true;
pipe.pause();
pipe._handle?.readStop?.();
}
return fd;
}
// For streams without a usable fd, create a pipe and set up JS-level
Expand Down
10 changes: 10 additions & 0 deletions tests/unit_node/child_process_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1050,6 +1050,16 @@ Deno.test(function spawnSyncStdioUndefined() {
assertEquals(ret.stderr.toString("utf-8").trim(), "world");
});

Deno.test(function spawnSyncProcessStdioUsesFileDescriptors() {
const ret = spawnSync(Deno.execPath(), ["eval", ""], {
stdio: [process.stdin, process.stdout, process.stderr],
});

assertEquals(ret.status, 0);
assertEquals(ret.stdout, null);
assertEquals(ret.stderr, null);
});

Deno.test(function spawnSyncExitNonZero() {
const ret = spawnSync(
`"${Deno.execPath()}" eval "Deno.exit(22)"`,
Expand Down
Loading