Skip to content

Commit

Permalink
feat(runtime/command): make stdin default to inherit for spawn() (#17334
Browse files Browse the repository at this point in the history
)

Closes #17230
  • Loading branch information
crowlKats authored Jan 24, 2023
1 parent 654e177 commit cadeaae
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
18 changes: 18 additions & 0 deletions cli/tests/unit/command_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,24 @@ Deno.test(
},
);

Deno.test(
{ permissions: { run: true, read: true } },
async function commandStdinPiped() {
const command = new Deno.Command(Deno.execPath(), {
args: ["info"],
stdout: "null",
stderr: "null",
});
const child = command.spawn();

assertThrows(() => child.stdin, TypeError, "stdin is not piped");
assertThrows(() => child.stdout, TypeError, "stdout is not piped");
assertThrows(() => child.stderr, TypeError, "stderr is not piped");

await child.status;
},
);

Deno.test(
{ permissions: { run: true, read: true } },
async function commandStdoutPiped() {
Expand Down
7 changes: 4 additions & 3 deletions cli/tsc/dts/lib.deno.unstable.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ declare namespace Deno {
type NativeVoidType = "void";

/** **UNSTABLE**: New API, yet to be vetted.
*
*
* The native struct type for interfacing with foreign functions.
*
*
*/
type NativeStructType = { readonly struct: readonly NativeType[] };

Expand Down Expand Up @@ -1640,7 +1640,8 @@ declare namespace Deno {

/** How `stdin` of the spawned process should be handled.
*
* Defaults to `"null"`. */
* Defaults to `"inherit"` for `output` & `outputSync`,
* and `"inherit"` for `spawn`. */
stdin?: "piped" | "inherit" | "null";
/** How `stdout` of the spawned process should be handled.
*
Expand Down
1 change: 1 addition & 0 deletions runtime/js/40_spawn.js
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@
...(this.#options ?? {}),
stdout: this.#options?.stdout ?? "inherit",
stderr: this.#options?.stderr ?? "inherit",
stdin: this.#options?.stdin ?? "inherit",
};
return spawnChild(this.#command, options);
}
Expand Down

0 comments on commit cadeaae

Please sign in to comment.