runscript
Version:
Run script easy!
39 lines (38 loc) • 1.51 kB
TypeScript
import { type SpawnOptions } from 'node:child_process';
import { type Writable } from 'node:stream';
export interface Options extends SpawnOptions {
stdout?: Writable;
stderr?: Writable;
}
export interface ExtraOptions {
timeout?: number;
}
export interface Stdio {
stdout: Buffer | null;
stderr: Buffer | null;
}
export interface StdError extends Error {
stdio: Stdio;
}
export declare class RunScriptError extends Error {
stdio: Stdio;
exitcode: number | null;
constructor(message: string, stdio: Stdio, exitcode: number | null, options?: ErrorOptions);
}
export declare class RunScriptTimeoutError extends Error {
stdio: Stdio;
timeout: number;
constructor(message: string, stdio: Stdio, timeout: number, options?: ErrorOptions);
}
/**
* Run shell script in child process
* Support OSX, Linux and Windows
* @param {String} script - full script string, like `git clone https://github.com/node-modules/runscript.git`
* @param {Object} [options] - spawn options
* @see https://nodejs.org/api/child_process.html#child_process_child_process_spawn_command_args_options
* @param {Object} [extraOptions] - extra options for running
* - {Number} [extraOptions.timeout] - child process running timeout
* @return {Object} stdio object, will contains stdio.stdout and stdio.stderr buffer.
*/
export declare function runScript(script: string, options?: Options, extraOptions?: ExtraOptions): Promise<Stdio>;
export declare const runscript: typeof runScript;