UNPKG

2.49 kBTypeScriptView Raw
1/// <reference types="node" />
2import { ChildProcess, SpawnOptions } from "child_process";
3export interface WritableLog {
4 /**
5 * Some implementations expose their log as a string.
6 * Others may not, as it could be too long etc.
7 */
8 log?: string;
9 write(what: string): void;
10}
11/**
12 * Type that can react to the exit of a spawned child process, after
13 * Node has terminated without reporting an error.
14 * This is necessary only for commands that can return
15 * a non-zero exit code on success.
16 * @return whether this result should be considered an error.
17 */
18export declare type ErrorFinder = (code: number, signal: string, log: WritableLog) => boolean;
19/**
20 * Default ErrorFinder that regards return code 0 as success
21 * @param {number} code
22 * @return {boolean}
23 * @constructor
24 */
25export declare const SuccessIsReturn0ErrorFinder: ErrorFinder;
26export interface ChildProcessResult {
27 error: boolean;
28 code: number;
29 message?: string;
30 childProcess: ChildProcess;
31}
32export interface SpawnWatchOptions {
33 errorFinder: ErrorFinder;
34 stripAnsi: boolean;
35 timeout: number;
36 logCommand: boolean;
37}
38/**
39 * Spawn a process and watch
40 * @param {SpawnCommand} spawnCommand
41 * @param options options
42 * @param {ProgressLog} log
43 * @param {Partial<SpawnWatchOptions>} spOpts
44 * @return {Promise<ChildProcessResult>}
45 */
46export declare function spawnAndWatch(spawnCommand: SpawnCommand, options: SpawnOptions, log: WritableLog, spOpts?: Partial<SpawnWatchOptions>): Promise<ChildProcessResult>;
47/**
48 * The first two arguments to Node spawn
49 */
50export interface SpawnCommand {
51 command: string;
52 args?: string[];
53 options?: any;
54}
55/**
56 * toString for a SpawnCommand. Used for logging.
57 * @param {SpawnCommand} sc
58 * @return {string}
59 */
60export declare function stringifySpawnCommand(sc: SpawnCommand): string;
61/**
62 * Convenient function to create a spawn command from a sentence such as "npm run compile"
63 * Does not respect quoted arguments
64 * @param {string} sentence
65 * @param options
66 * @return {SpawnCommand}
67 */
68export declare function asSpawnCommand(sentence: string, options?: SpawnOptions): SpawnCommand;
69/**
70 * Kill the child process and wait for it to shut down. This can take a while as child processes
71 * may have shut down hooks.
72 * @param {module:child_process.ChildProcess} childProcess
73 * @return {Promise<any>}
74 */
75export declare function poisonAndWait(childProcess: ChildProcess): Promise<any>;
76//# sourceMappingURL=spawned.d.ts.map
\No newline at end of file