import { ChildProcess, IOType } from 'child_process'; import child_process from 'child_process'; import Stream, { Pipe, Readable, Writable } from 'stream'; type StdioElement = IOType | Stream | number | null | undefined; type StdioOptions = IOType | [StdioElement, StdioElement, StdioElement, ...Array] | Array; interface IOOptions { silent?: boolean; stdio?: StdioOptions; encoding?: BufferEncoding | 'buffer' | null; maxBuffer?: number; } type ChunkTypeHelper = MaxBuffer extends number ? Encoding extends BufferEncoding ? string : Buffer : Encoding extends BufferEncoding ? string : Encoding extends 'buffer' ? Buffer : undefined; type ChunkType = ChunkTypeHelper<'maxBuffer' extends keyof Options ? Options['maxBuffer'] : undefined, 'encoding' extends keyof Options ? Options['encoding'] : undefined>; type IsPipeHelper = Stdio extends unknown[] ? Stdio[Fd] extends infer Value ? Value extends 'pipe' | 'overlapped' ? true : false : false : Stdio extends null | undefined | 'pipe' | 'overlapped' ? true : Stdio extends null | undefined ? Silent extends true ? false : true : false; type IsPipe = IsPipeHelper<'stdio' extends keyof Options ? Options['stdio'] : undefined, 'silent' extends keyof Options ? Options['silent'] : undefined, Fd>; type Contains = A extends [infer Head, ...infer Tail] ? Head extends T ? true : Contains : false; export interface ChildProcessResult { stdout: IsPipe extends true ? ChunkType : undefined; stderr: IsPipe extends true ? ChunkType : undefined; code: number | null; signal: string | null; killed: boolean; } type StdioStreams = { [K in keyof Stdio]: Stdio[K] extends 'pipe' | 'overlapped' ? K extends 0 | '0' ? Writable : Readable : null }; export interface ChildProcessPromise extends ChildProcess, Promise> { stdin: IsPipe extends true ? Writable : null; stdout: IsPipe extends true ? Readable : null; stderr: IsPipe extends true ? Readable : null; readonly channel: Options['stdio'] extends infer Stdio ? Contains extends true ? Pipe : undefined : undefined; readonly stdio: Options['stdio'] extends infer Stdio ? Stdio extends unknown[] ? StdioStreams : Stdio extends null | undefined | 'pipe' | 'overlapped' ? [Writable, Readable, Readable, undefined, undefined] : [null, null, null, undefined, undefined] : [null, null, null, undefined, undefined]; } interface PromisifyChildProcessBaseOptions extends IOOptions { killSignal?: NodeJS.Signals | number; } export declare function promisifyChildProcess(child: ChildProcess, options?: Options): ChildProcessPromise; export interface SpawnOptions extends child_process.SpawnOptions { stdio?: StdioOptions; encoding?: BufferEncoding; maxBuffer?: number; } export declare function spawn(command: string, args: readonly string[], options?: Options): ChildProcessPromise; export declare function spawn(command: string, options?: Options): ChildProcessPromise; export interface ForkOptions extends child_process.ForkOptions { stdio?: StdioOptions; encoding?: BufferEncoding; maxBuffer?: number; } export declare function fork(module: string, args: Array, options?: Options): ChildProcessPromise; export declare function fork(module: string, options?: Options): ChildProcessPromise; export interface ExecOptions extends child_process.ExecOptions { encoding?: BufferEncoding | 'buffer'; } export declare const exec: (command: string, options?: Options) => ChildProcessPromise; export interface ExecFileOptions extends child_process.ExecFileOptions { encoding?: BufferEncoding | 'buffer'; } export declare const execFile: { (file: string, args: readonly string[], options?: Options): ChildProcessPromise; (file: string, options?: Options): ChildProcessPromise; }; export declare function isChildProcessError(error: unknown): error is Error & { code: number | null; signal: NodeJS.Signals | null; killed: boolean; stdout?: string | Buffer; stderr?: string | Buffer; }; export {}; //# sourceMappingURL=index.d.ts.map