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