@j-o-r/sh
Version:
Execute shell commands on Linux-based systems from javascript
91 lines (90 loc) • 2.63 kB
TypeScript
export default SHDispatch;
export type SpawnSyncResponse = {
/**
* - Exit code (null if signal).
*/
status: number | null;
/**
* - Terminating signal.
*/
signal: string | null;
/**
* - [stdin, stdout, stderr].
*/
output: (string | Buffer | null)[];
/**
* - Process ID.
*/
pid: number;
/**
* - Captured stdout.
*/
stdout: string | Buffer | null;
/**
* - Captured stderr.
*/
stderr: string | Buffer | null;
};
export type StdioOption = ("pipe" | "ignore" | "inherit" | number);
export type StdioOptions = Array<StdioOption> | StdioOption;
/**
* High-level command dispatcher.
*
* Created by {@link SH`cmd`}; chain `.options()` then `.run()`.
*
* Delegates to {@link SHExecute} for exec/timeout/buffer/kill.
*
* @example
* const dispatch = SH`ls -la`.options({ timeout: '2s' });
* const out = await dispatch.run();
*/
declare class SHDispatch {
/**
* @param {string} cmd - Command string.
* @param {Partial<typeof SHOptions>} [options] - Initial options.
* @param {string} [prefix] - Shell prefix (e.g., 'set -euo pipefail').
* @throws {Error} Invalid/empty cmd.
*/
constructor(cmd: string, options?: Partial<typeof SHOptions>, prefix?: string);
/**
* Updates options/prefix; resets to defaults + user overrides (non-cumulative).
*
* Strings for `stdio` → array fill.
*
* @param {Partial<typeof SHOptions>} [options] - New options.
* @param {string} [prefix] - New prefix.
* @returns {SHDispatch} Self for chaining.
*/
options(options?: Partial<typeof SHOptions>, prefix?: string): SHDispatch;
/**
* Async run: Captures stdout; rejects on error/timeout.
*
* @param {string} [payload] - Stdin payload.
* @returns {Promise<string>} Stdout.
*/
run(payload?: string): Promise<string>;
/**
* Sync run: Full Node SpawnSyncReturns.
*
* Good for TTY takeovers (e.g., vim).
*
* @param {string} [payload] - Stdin payload.
* @returns {import('child_process').SpawnSyncReturns<Buffer>}
*/
runSync(payload?: string): import("child_process").SpawnSyncReturns<Buffer>;
/**
* Kills running process + children.
*
* @param {number | string} [signal='SIGTERM'] - Signal.
* @returns {Promise<number[]>} Killed PIDs.
*/
kill(signal?: number | string): Promise<number[]>;
#private;
}
declare namespace SHOptions {
let cwd: string;
let env: NodeJS.ProcessEnv;
let shell: string;
let stdio: string[];
let timeout: number;
}