/// import { ChildProcess, SpawnOptions } from "child_process"; import * as spawn from "cross-spawn"; export { spawn }; /** * Interface for a writable log that provides a function to write to the log. */ export interface WritableLog { /** * Some implementations expose their log as a string. * Others may not, as it could be too long etc. */ log?: string; /** Function that write to the log. */ write(what: string): void; } /** * Type that can react to the exit of a spawned child process, after * Node has terminated without reporting an error. * This is necessary only for commands that can return * a non-zero exit code on success. * @return whether this result should be considered an error. */ export declare type ErrorFinder = (code: number, signal: string, log: WritableLog) => boolean; /** * Default ErrorFinder that regards return code 0 as success * @param {number} code * @return {boolean} * @constructor */ export declare const SuccessIsReturn0ErrorFinder: ErrorFinder; /** * Result returned by spawnAndWatch after running a child process. */ export interface ChildProcessResult { /** Will be true if the ErrorFinder returns true. */ error: boolean; /** Exit code of process. It may be null or undefined if the process was killed. */ code: number; /** Optional message returned by process. */ message?: string; /** The Node.js child_process.ChildProcess created by spawnAndwatch. */ childProcess: ChildProcess; } /** * spawnAndWatch specific options. */ export interface SpawnWatchOptions { /** * If your command can return zero on failure or non-zero on * success, you can override the default behavior of determining * success or failure using this option. For example, if your * command returns zero for certain types of errors, you can scan * the log content from the command to determine if an error * occurs. */ errorFinder: ErrorFinder; /** * Set to true if ANSI escape codes should be stripped from the * output before sending it to the log. */ stripAnsi: boolean; /** * Amount of time in milliseconds to wait for process to exit. If * it does not exit in the allotted time, it is kill */ timeout: number; /** * Set to true if you want the command line sent to the * Writablelog provided to spawnAndWatch. */ logCommand: boolean; } /** * Spawn a process, log its output, and wait for it to exit, * asynchronously. It is spawned using cross-spawn. * * @param {SpawnCommand} spawnCommand command to run * @param options standard spawn options * @param log log to write output to * @param {Partial} spOpts * @return {Promise} */ export declare function spawnAndWatch(spawnCommand: SpawnCommand, options: SpawnOptions, log: WritableLog, spOpts?: Partial): Promise; /** * The first two arguments to Node spawn */ export interface SpawnCommand { command: string; args?: string[]; options?: any; } /** * toString for a SpawnCommand. Used for logging. * @param {SpawnCommand} sc * @return {string} */ export declare function stringifySpawnCommand(sc: SpawnCommand): string; /** * Convenience function to create a spawn command from a sentence such * as "npm run compile" Does not respect quoted arguments. Use * spawnAndWatch passing it the command and argument array if your * command arguments have spaces, etc. * * @param {string} sentence command and argument string * @param options * @return {SpawnCommand} */ export declare function asSpawnCommand(sentence: string, options?: SpawnOptions): SpawnCommand; /** * Kill the child process and wait for it to shut down. This can take * a while as child processes may have shut down hooks. On win32, * tree-kill is used and the Promise is rejected if the process(es) do(es) * not exit within `wait` milliseconds. On other platforms, first the * child process is sent the default signal, SIGTERM. After `wait` * milliseconds, it is sent SIGKILL. After another `wait` * milliseconds, an error is thrown. * * @param {module:child_process.ChildProcess} childProcess * @param wait the number of milliseconds to wait before sending SIGKILL and * then erroring, default is 30000 ms * @return {Promise} */ export declare function poisonAndWait(childProcess: ChildProcess, wait?: number): Promise; /** * Cross-platform kill. On win32, tree-kill is used and signal is * ignored since win32 does not support different signals. On other * platforms, ChildProcess.kill(signal) is used. * * @param cp child process to kill * @param signal optional signal, Node.js default is used if not provided */ export declare function crossKill(cp: ChildProcess, signal?: string): void;