UNPKG

5.97 kBTypeScriptView Raw
1/// <reference types="node" />
2import { SpawnOptions, SpawnSyncOptions, SpawnSyncReturns } from "child_process";
3import * as spawn from "cross-spawn";
4export { spawn };
5/**
6 * Convert child process into an informative string.
7 *
8 * @param cmd Command being run.
9 * @param args Arguments to command.
10 * @param opts Standard child_process.SpawnOptions.
11 */
12export declare function childProcessString(cmd: string, args?: string[], opts?: SpawnOptions): string;
13/**
14 * Cross-platform kill a process and all its children using tree-kill.
15 * On win32, signal is ignored since win32 does not support different
16 * signals.
17 *
18 * @param pid ID of process to kill.
19 * @param signal optional signal name or number, Node.js default is used if not provided
20 */
21export declare function killProcess(pid: number, signal?: string | number): void;
22/**
23 * Interface for a writable log that provides a function to write to
24 * the log.
25 */
26export interface WritableLog {
27 /**
28 * The content already written to the log. This is optional as
29 * some implementations may choose to not expose their log as a
30 * string as it could be too long.
31 */
32 log?: string;
33 /**
34 * Set to true if ANSI escape characters should be stripped from
35 * the data before writing to log.
36 */
37 stripAnsi?: boolean;
38 /** Function that appends to the log. */
39 write(what: string): void;
40}
41/**
42 * Add logging to standard SpawnSyncoptions. If no `encoding` is
43 * provided, it is set to "buffer" if `log` is defined and "utf8"
44 * otherwise.
45 */
46export interface SpawnPromiseOptions extends SpawnSyncOptions {
47 /**
48 * Optional logger to write stdout and stderr to. If this is
49 * provided, the encoding for it is taken from the `encoding`
50 * option property and that property is set to "bufffer". If no
51 * `encoding` is defined, the default encoding for the log is
52 * "utf8".
53 */
54 log?: WritableLog;
55 /**
56 * Set to true if you want the command line sent to the
57 * Writablelog provided to spawnPromise. Set to false if the
58 * command or its arguments contain sensitive information.
59 */
60 logCommand?: boolean;
61}
62export interface SpawnPromiseReturns extends SpawnSyncReturns<string> {
63 /** Stringified command. */
64 cmdString: string;
65}
66/**
67 * Call cross-spawn and return a Promise of its result. The result
68 * has the same shape as the object returned by
69 * `child_process.spawnSync()`, which means errors are not thrown but
70 * returned in the `error` property of the returned object. If your
71 * command will produce lots of output, provide a log to write it to.
72 *
73 * @param cmd Command to run. If it is just an executable name, paths
74 * with be searched, batch and command files will be checked,
75 * etc. See cross-spawn documentation for details.
76 * @param args Arguments to command.
77 * @param opts Standard child_process.SpawnOptions plus a few specific
78 * to this implementation.
79 * @return a Promise that provides information on the child process and
80 * its execution result. If an error occurs, the `error` property
81 * of [[SpawnPromiseReturns]] will be populated.
82 */
83export declare function spawnPromise(cmd: string, args?: string[], opts?: SpawnPromiseOptions): Promise<SpawnPromiseReturns>;
84/**
85 * Standard output and standard error from executing a child process.
86 * No code or signal is provided because if you receive this value,
87 * the child process completed successfully, i.e., exited normally
88 * with a status of 0.
89 */
90export interface ExecPromiseResult {
91 /** Child process standard output. */
92 stdout: string;
93 /** Child process standard error. */
94 stderr: string;
95}
96/**
97 * Error thrown when a command cannot be executed, the command is
98 * killed by a signal, or returns a non-zero exit status.
99 */
100export declare class ExecPromiseError extends Error implements ExecPromiseResult {
101 /** Message describing reason for failure. */
102 message: string;
103 /** Command PID. */
104 pid: number;
105 /** stdio */
106 output: string[];
107 /** Child process standard output. */
108 stdout: string;
109 /** Child process standard error. */
110 stderr: string;
111 /** Child process exit status. */
112 status: number;
113 /** Signal that killed the process, if any. */
114 signal: string;
115 /** Create an ExecError from a SpawnSyncReturns<string> */
116 static fromSpawnReturns(r: SpawnSyncReturns<string>): ExecPromiseError;
117 constructor(
118 /** Message describing reason for failure. */
119 message: string,
120 /** Command PID. */
121 pid: number,
122 /** stdio */
123 output: string[],
124 /** Child process standard output. */
125 stdout: string,
126 /** Child process standard error. */
127 stderr: string,
128 /** Child process exit status. */
129 status: number,
130 /** Signal that killed the process, if any. */
131 signal: string);
132}
133/**
134 * Run a child process using cross-spawn, capturing and returning
135 * stdout and stderr, like exec, in a promise. If an error occurs,
136 * the process is killed by a signal, or the process exits with a
137 * non-zero status, the Promise is rejected. Any provided `stdio`
138 * option is ignored, being overwritten with `["pipe","pipe","pipe"]`.
139 * Like with child_process.exec, this is not a good choice if the
140 * command produces a large amount of data on stdout or stderr.
141 *
142 * @param cmd name of command, can be a shell script or MS Windows
143 * .bat or .cmd
144 * @param args command arguments
145 * @param opts standard child_process.SpawnOptions
146 * @return Promise resolving to exec-like callback arguments having
147 * stdout and stderr properties. If an error occurs, exits
148 * with a non-zero status, and killed with a signal, the
149 * Promise is rejected with an [[ExecPromiseError]].
150 */
151export declare function execPromise(cmd: string, args?: string[], opts?: SpawnSyncOptions): Promise<ExecPromiseResult>;
152//# sourceMappingURL=child_process.d.ts.map
\No newline at end of file