From 1dd4843b62085a2aeb3134573adf9a7c47c154e2 Mon Sep 17 00:00:00 2001 From: Leo Kettmeir Date: Mon, 28 Nov 2022 12:33:51 +0100 Subject: feat(unstable): rework Deno.Command (#16812) Refactors the `Deno.Command` class to not handle any state, but only being an intermediary to calling its methods, and as such any methods and properties besides `output`, `outputSync` & `spawn` have been removed. Interracting with a `spawn`ed subprocess now works by using the methods and properties on the returned class of the `spawn` method. --- cli/tsc/diagnostics.rs | 1 + cli/tsc/dts/lib.deno.unstable.d.ts | 36 ++++++++++++++++++++++++------------ 2 files changed, 25 insertions(+), 12 deletions(-) (limited to 'cli/tsc') diff --git a/cli/tsc/diagnostics.rs b/cli/tsc/diagnostics.rs index 05502dca4..4413398c2 100644 --- a/cli/tsc/diagnostics.rs +++ b/cli/tsc/diagnostics.rs @@ -31,6 +31,7 @@ const UNSTABLE_DENO_PROPS: &[&str] = &[ "umask", "spawnChild", "Child", + "ChildProcess", "spawn", "spawnSync", "SpawnOptions", diff --git a/cli/tsc/dts/lib.deno.unstable.d.ts b/cli/tsc/dts/lib.deno.unstable.d.ts index eaa40abc5..ce609736b 100644 --- a/cli/tsc/dts/lib.deno.unstable.d.ts +++ b/cli/tsc/dts/lib.deno.unstable.d.ts @@ -1639,14 +1639,14 @@ declare namespace Deno { * ], * stdin: "piped", * }); - * command.spawn(); + * const child = command.spawn(); * * // open a file and pipe the subprocess output to it. - * command.stdout.pipeTo(Deno.openSync("output").writable); + * child.stdout.pipeTo(Deno.openSync("output").writable); * * // manually close stdin - * command.stdin.close(); - * const status = await command.status; + * child.stdin.close(); + * const status = await child.status; * ``` * * ```ts @@ -1678,13 +1678,6 @@ declare namespace Deno { * @category Sub Process */ export class Command { - get stdin(): WritableStream; - get stdout(): ReadableStream; - get stderr(): ReadableStream; - readonly pid: number; - /** Get the status of the child process. */ - readonly status: Promise; - constructor(command: string | URL, options?: CommandOptions); /** * Executes the {@linkcode Deno.Command}, waiting for it to finish and @@ -1711,8 +1704,27 @@ declare namespace Deno { /** * Spawns a streamable subprocess, allowing to use the other methods. */ - spawn(): void; + spawn(): ChildProcess; + } + + /** **UNSTABLE**: New API, yet to be vetted. + * + * The interface for handling a child process returned from + * {@linkcode Deno.Command.spawn}. + * + * @category Sub Process + */ + export class ChildProcess { + get stdin(): WritableStream; + get stdout(): ReadableStream; + get stderr(): ReadableStream; + readonly pid: number; + /** Get the status of the child. */ + readonly status: Promise; + /** Waits for the child to exit completely, returning all its output and + * status. */ + output(): Promise; /** Kills the process with given {@linkcode Deno.Signal}. Defaults to * `"SIGTERM"`. */ kill(signo?: Signal): void; -- cgit v1.2.3