///
import cp, { ChildProcess } from "child_process";
import { Server, Socket } from "net";
interface ReadableStreamLike {
pipe(destination: any, options?: any): any;
unpipe(destination: any): any;
pause(): any;
}
/**
* Interface representing a parent process.
*
* This interface is compatible with the global variable `process`.
*/
interface ProcessLike {
pid: number;
stdout: any;
stderr: any;
stdin: ReadableStreamLike;
exit(code?: number): any;
kill(pid: number, signal?: string | number): any;
on(signal: NodeJS.Signals, listener: NodeJS.SignalsListener): any;
on(event: "message", listener: (message: any, sendHandle: Socket | Server) => void): any;
on(event: "exit", listener: NodeJS.ExitListener): any;
removeListener(signal: NodeJS.Signals, listener: NodeJS.SignalsListener): any;
removeListener(event: "message", listener: (message: any, sendHandle: Socket | Server) => void): any;
removeListener(event: "exit", listener: NodeJS.ExitListener): any;
send?(message: any, sendHandle?: any): void;
}
/**
* This function closes the parent process like the child process:
* - If the child was killed by a signal, it kills the parent with this signal.
* - If the child has exited, it exits the parent with the same return code.
*/
interface CloseFn {
(): void;
code: number | null;
signal: NodeJS.Signals | null;
}
/**
* Proxies `child` through `parent`.
*
* Any signal, IPC message or stream IO on the parent will be passed to the
* child.
* The returned promise is resolved once the child is closed.
* The value is a close function to close the parent process the same way as
* the child was closed.
*
* @param parent Parent process.
* @param child Child process.
* @return Close function to close the parent function like the child process.
*/
declare function proxy(parent: ProcessLike, child: cp.ChildProcess): Promise;
/**
* Spawn options, with additional values specific to `foreground-child`.
*
* Note: The default value for `stdio` is `inherit` (as opposed to `pipe` in
* Node's `spawn`).
*/
interface SpawnOptions extends cp.SpawnOptions {
/**
* Parent process to use.
*
* Default: `process` (global variable).
*/
parent?: ProcessLike;
/**
* Spawn function to use.
*
* You can supply your own spawn function.
* For example, you can use `cross-spawn` or a `spawn-wrap` function.
*
* Default: `require("child_process").spawn`
*/
spawn?: typeof cp.spawn;
}
interface SpawnResult {
/**
* Proxied child process
*/
child: ChildProcess;
/**
* Promise resolved once the child is closed.
*
* The value is a "close function" that closes the parent process the same
* way as the child was closed.
*/
close: Promise;
}
/**
* Spawns a new proxied child process.
*
* IO, IPC and signals from the parent process are forwarded to the child process.
* By default, it uses the global `process` variable as the parent, effectively
* moving control to the child process.
*
* @param file File to spawn
* @param args Process arguments
* @param options Spawn options. The options are similar to the ones of Node's
* `spawn` function, with additional options specific to `foreground-child`.
* See [[SpawnOptions]]. The default value for `stdio` is `inherit` (as opposed
* to `pipe` in Node's `spawn`).
* @return The proxied child process and a promise for the close function.
*/
declare function spawn(file: string, args?: ReadonlyArray, options?: SpawnOptions): SpawnResult;
/**
* @internal
*/
declare type CloseHandler = (done: CloseFn) => any;
declare function foregroundChild(program: string | ReadonlyArray, cb?: CloseHandler): cp.ChildProcess;
declare function foregroundChild(program: string, args: ReadonlyArray, cb?: CloseHandler): cp.ChildProcess;
declare function foregroundChild(program: string, arg1: string, cb?: CloseHandler): cp.ChildProcess;
declare function foregroundChild(program: string, arg1: string, arg2: string, cb?: CloseHandler): cp.ChildProcess;
declare function foregroundChild(program: string, arg1: string, arg2: string, arg3: string, cb?: CloseHandler): cp.ChildProcess;
declare function foregroundChild(program: string, arg1: string, arg2: string, arg3: string, arg4: string, cb?: CloseHandler): cp.ChildProcess;
export { CloseHandler, CloseFn, ProcessLike, ReadableStreamLike, SpawnOptions, SpawnResult, foregroundChild as compat, proxy, spawn, };