summaryrefslogtreecommitdiff
path: root/cli/tsc/dts/lib.deno.ns.d.ts
diff options
context:
space:
mode:
authorBartek Iwańczuk <biwanczuk@gmail.com>2023-02-13 19:25:00 +0100
committerGitHub <noreply@github.com>2023-02-13 19:25:00 +0100
commitf917d2e2c10e0a94e564a9016217e7ce27c8bbee (patch)
treedc13ab3e0acf5d28874c881ad4ea62f2a103bdff /cli/tsc/dts/lib.deno.ns.d.ts
parent9e3d433249b9259e3a04b4f68563a41455ac7efc (diff)
feat: Stabilize Deno.Command API (#17628)
This commit stabilizes "Deno.Command" API with all its related APIs. "--unstable" flag is no longer required to use this API.
Diffstat (limited to 'cli/tsc/dts/lib.deno.ns.d.ts')
-rw-r--r--cli/tsc/dts/lib.deno.ns.d.ts212
1 files changed, 212 insertions, 0 deletions
diff --git a/cli/tsc/dts/lib.deno.ns.d.ts b/cli/tsc/dts/lib.deno.ns.d.ts
index d81e4afcd..93e1b54a6 100644
--- a/cli/tsc/dts/lib.deno.ns.d.ts
+++ b/cli/tsc/dts/lib.deno.ns.d.ts
@@ -3958,6 +3958,218 @@ declare namespace Deno {
*/
export function run<T extends RunOptions = RunOptions>(opt: T): Process<T>;
+ /** Create a child process.
+ *
+ * If any stdio options are not set to `"piped"`, accessing the corresponding
+ * field on the `Command` or its `CommandOutput` will throw a `TypeError`.
+ *
+ * If `stdin` is set to `"piped"`, the `stdin` {@linkcode WritableStream}
+ * needs to be closed manually.
+ *
+ * @example Spawn a subprocess and pipe the output to a file
+ *
+ * ```ts
+ * const command = new Deno.Command(Deno.execPath(), {
+ * args: [
+ * "eval",
+ * "console.log('Hello World')",
+ * ],
+ * stdin: "piped",
+ * });
+ * const child = command.spawn();
+ *
+ * // open a file and pipe the subprocess output to it.
+ * child.stdout.pipeTo(Deno.openSync("output").writable);
+ *
+ * // manually close stdin
+ * child.stdin.close();
+ * const status = await child.status;
+ * ```
+ *
+ * @example Spawn a subprocess and collect its output
+ *
+ * ```ts
+ * const command = new Deno.Command(Deno.execPath(), {
+ * args: [
+ * "eval",
+ * "console.log('hello'); console.error('world')",
+ * ],
+ * });
+ * const { code, stdout, stderr } = await command.output();
+ * console.assert(code === 0);
+ * console.assert("hello\n" === new TextDecoder().decode(stdout));
+ * console.assert("world\n" === new TextDecoder().decode(stderr));
+ * ```
+ *
+ * @example Spawn a subprocess and collect its output synchronously
+ *
+ * ```ts
+ * const command = new Deno.Command(Deno.execPath(), {
+ * args: [
+ * "eval",
+ * "console.log('hello'); console.error('world')",
+ * ],
+ * });
+ * const { code, stdout, stderr } = command.outputSync();
+ * console.assert(code === 0);
+ * console.assert("hello\n" === new TextDecoder().decode(stdout));
+ * console.assert("world\n" === new TextDecoder().decode(stderr));
+ * ```
+ *
+ * @category Sub Process
+ */
+ export class Command {
+ constructor(command: string | URL, options?: CommandOptions);
+ /**
+ * Executes the {@linkcode Deno.Command}, waiting for it to finish and
+ * collecting all of its output.
+ * If `spawn()` was called, calling this function will collect the remaining
+ * output.
+ *
+ * Will throw an error if `stdin: "piped"` is set.
+ *
+ * If options `stdout` or `stderr` are not set to `"piped"`, accessing the
+ * corresponding field on {@linkcode Deno.CommandOutput} will throw a `TypeError`.
+ */
+ output(): Promise<CommandOutput>;
+ /**
+ * Synchronously executes the {@linkcode Deno.Command}, waiting for it to
+ * finish and collecting all of its output.
+ *
+ * Will throw an error if `stdin: "piped"` is set.
+ *
+ * If options `stdout` or `stderr` are not set to `"piped"`, accessing the
+ * corresponding field on {@linkcode Deno.CommandOutput} will throw a `TypeError`.
+ */
+ outputSync(): CommandOutput;
+ /**
+ * Spawns a streamable subprocess, allowing to use the other methods.
+ */
+ spawn(): ChildProcess;
+ }
+
+ /**
+ * The interface for handling a child process returned from
+ * {@linkcode Deno.Command.spawn}.
+ *
+ * @category Sub Process
+ */
+ export class ChildProcess {
+ get stdin(): WritableStream<Uint8Array>;
+ get stdout(): ReadableStream<Uint8Array>;
+ get stderr(): ReadableStream<Uint8Array>;
+ readonly pid: number;
+ /** Get the status of the child. */
+ readonly status: Promise<CommandStatus>;
+
+ /** Waits for the child to exit completely, returning all its output and
+ * status. */
+ output(): Promise<CommandOutput>;
+ /** Kills the process with given {@linkcode Deno.Signal}.
+ *
+ * @param [signo="SIGTERM"]
+ */
+ kill(signo?: Signal): void;
+
+ /** Ensure that the status of the child process prevents the Deno process
+ * from exiting. */
+ ref(): void;
+ /** Ensure that the status of the child process does not block the Deno
+ * process from exiting. */
+ unref(): void;
+ }
+
+ /**
+ * Options which can be set when calling {@linkcode Deno.Command}.
+ *
+ * @category Sub Process
+ */
+ export interface CommandOptions {
+ /** Arguments to pass to the process. */
+ args?: string[];
+ /**
+ * The working directory of the process.
+ *
+ * If not specified, the `cwd` of the parent process is used.
+ */
+ cwd?: string | URL;
+ /**
+ * Clear environmental variables from parent process.
+ *
+ * Doesn't guarantee that only `env` variables are present, as the OS may
+ * set environmental variables for processes.
+ *
+ * @default {false}
+ */
+ clearEnv?: boolean;
+ /** Environmental variables to pass to the subprocess. */
+ env?: Record<string, string>;
+ /**
+ * Sets the child process’s user ID. This translates to a setuid call in the
+ * child process. Failure in the set uid call will cause the spawn to fail.
+ */
+ uid?: number;
+ /** Similar to `uid`, but sets the group ID of the child process. */
+ gid?: number;
+ /**
+ * An {@linkcode AbortSignal} that allows closing the process using the
+ * corresponding {@linkcode AbortController} by sending the process a
+ * SIGTERM signal.
+ *
+ * Not supported in {@linkcode Deno.Command.outputSync}.
+ */
+ signal?: AbortSignal;
+
+ /** How `stdin` of the spawned process should be handled.
+ *
+ * Defaults to `"inherit"` for `output` & `outputSync`,
+ * and `"inherit"` for `spawn`. */
+ stdin?: "piped" | "inherit" | "null";
+ /** How `stdout` of the spawned process should be handled.
+ *
+ * Defaults to `"piped"` for `output` & `outputSync`,
+ * and `"inherit"` for `spawn`. */
+ stdout?: "piped" | "inherit" | "null";
+ /** How `stderr` of the spawned process should be handled.
+ *
+ * Defaults to `"piped"` for `output` & `outputSync`,
+ * and `"inherit"` for `spawn`. */
+ stderr?: "piped" | "inherit" | "null";
+
+ /** Skips quoting and escaping of the arguments on windows. This option
+ * is ignored on non-windows platforms.
+ *
+ * @default {false} */
+ windowsRawArguments?: boolean;
+ }
+
+ /**
+ * @category Sub Process
+ */
+ export interface CommandStatus {
+ /** If the child process exits with a 0 status code, `success` will be set
+ * to `true`, otherwise `false`. */
+ success: boolean;
+ /** The exit code of the child process. */
+ code: number;
+ /** The signal associated with the child process. */
+ signal: Signal | null;
+ }
+
+ /**
+ * The interface returned from calling {@linkcode Command.output} or
+ * {@linkcode Command.outputSync} which represents the result of spawning the
+ * child process.
+ *
+ * @category Sub Process
+ */
+ export interface CommandOutput extends CommandStatus {
+ /** The buffered output from the child process' `stdout`. */
+ readonly stdout: Uint8Array;
+ /** The buffered output from the child process' `stderr`. */
+ readonly stderr: Uint8Array;
+ }
+
/** Option which can be specified when performing {@linkcode Deno.inspect}.
*
* @category Console and Debugging */