1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213/// <reference types="node" />
/// <reference types="fs-extra" />
import { Buffer } from 'node:buffer';
import cp, { type ChildProcess, type IOType, type StdioOptions } from 'node:child_process';
import { type Encoding } from 'node:crypto';
import { EventEmitter } from 'node:events';
import { type Readable, type Writable } from 'node:stream';
import { inspect } from 'node:util';
import { Fail } from './error.js';
import { log } from './log.js';
import { type TSpawnStore } from './vendor-core.js';
import { type Duration, quote } from './util.js';
export { bus } from './internals.js';
export { default as path } from 'node:path';
export * as os from 'node:os';
export { Fail } from './error.js';
export { log, type LogEntry } from './log.js';
export { chalk, which, ps } from './vendor-core.js';
export { type Duration, quote, quotePowerShell } from './util.js';
declare const CWD: unique symbol;
declare const SYNC: unique symbol;
declare const SHOT: unique symbol;
export interface Options {
[CWD]: string;
[SYNC]: boolean;
cwd?: string;
ac?: AbortController;
signal?: AbortSignal;
input?: string | Buffer | Readable | ProcessOutput | ProcessPromise;
timeout?: Duration;
timeoutSignal?: NodeJS.Signals;
stdio: StdioOptions;
verbose: boolean;
sync: boolean;
env: NodeJS.ProcessEnv;
shell: string | true;
nothrow: boolean;
prefix?: string;
postfix?: string;
quote?: typeof quote;
quiet: boolean;
detached: boolean;
preferLocal: boolean | string | string[];
spawn: typeof cp.spawn;
spawnSync: typeof cp.spawnSync;
store?: TSpawnStore;
log: typeof log;
kill: typeof kill;
killSignal?: NodeJS.Signals;
halt?: boolean;
delimiter?: string | RegExp;
}
type Snapshot = Options & {
from: string;
pieces: TemplateStringsArray;
args: string[];
cmd: string;
ee: EventEmitter;
ac: AbortController;
};
export declare const defaults: Options;
export declare function within<R>(callback: () => R): R;
export interface Shell<S = false, R = S extends true ? ProcessOutput : ProcessPromise> {
(pieces: TemplateStringsArray, ...args: any[]): R;
<O extends Partial<Options> = Partial<Options>, R = O extends {
sync: true;
} ? Shell<true> : Shell>(opts: O): R;
sync: {
(pieces: TemplateStringsArray, ...args: any[]): ProcessOutput;
(opts: Partial<Omit<Options, 'sync'>>): Shell<true>;
};
}
export type $ = Shell & Options;
export declare const $: $;
type ProcessStage = 'initial' | 'halted' | 'running' | 'fulfilled' | 'rejected';
type Resolve = (out: ProcessOutput) => void;
type Reject = (error: ProcessOutput | Error) => void;
type PromiseCallback = {
(resolve: Resolve, reject: Reject): void;
[SHOT]?: Snapshot;
};
type PromisifiedStream<D extends Writable = Writable> = D & PromiseLike<ProcessOutput & D> & {
run(): void;
};
type PipeAcceptor = Writable | ProcessPromise;
type PipeMethod = {
(dest: TemplateStringsArray, ...args: any[]): ProcessPromise;
(file: string): PromisifiedStream;
<D extends Writable>(dest: D): PromisifiedStream<D>;
<D extends ProcessPromise>(dest: D): D;
};
export declare class ProcessPromise extends Promise<ProcessOutput> {
private _stage;
private _id;
private _snapshot;
private _timeoutId?;
private _piped;
private _stdin;
private _zurk;
private _output;
private _resolve;
private _reject;
constructor(executor: PromiseCallback);
private build;
run(): this;
private _breakerData?;
private break;
private finalize;
abort(reason?: string): void;
kill(signal?: NodeJS.Signals | null): Promise<void>;
stdio(stdin: IOType | StdioOptions, stdout?: IOType, stderr?: IOType): this;
nothrow(v?: boolean): this;
quiet(v?: boolean): this;
verbose(v?: boolean): this;
timeout(d?: Duration, signal?: NodeJS.Signals | undefined): this;
/**
* @deprecated Use $({halt: true})`cmd` instead.
*/
halt(): this;
get id(): string;
get pid(): number | undefined;
get cmd(): string;
get fullCmd(): string;
get child(): ChildProcess | undefined;
get stdin(): Writable;
get stdout(): Readable;
get stderr(): Readable;
get exitCode(): Promise<number | null>;
get signal(): AbortSignal;
get ac(): AbortController;
get output(): ProcessOutput | null;
get stage(): ProcessStage;
get sync(): boolean;
get [Symbol.toStringTag](): string;
[Symbol.toPrimitive](): string;
json<T = any>(): Promise<T>;
text(encoding?: Encoding): Promise<string>;
lines(delimiter?: Options['delimiter']): Promise<string[]>;
buffer(): Promise<Buffer>;
blob(type?: string): Promise<Blob>;
isQuiet(): boolean;
isVerbose(): boolean;
isNothrow(): boolean;
isHalted(): boolean;
private isSettled;
private isRunning;
get pipe(): PipeMethod & {
[key in keyof TSpawnStore]: PipeMethod;
};
unpipe(to?: PipeAcceptor): this;
private _pipe;
private static bus;
private static promisifyStream;
then<R = ProcessOutput, E = ProcessOutput>(onfulfilled?: ((value: ProcessOutput) => PromiseLike<R> | R) | undefined | null, onrejected?: ((reason: ProcessOutput) => PromiseLike<E> | E) | undefined | null): Promise<R | E>;
catch<T = ProcessOutput>(onrejected?: ((reason: ProcessOutput) => PromiseLike<T> | T) | undefined | null): Promise<ProcessOutput | T>;
[Symbol.asyncIterator](): AsyncIterator<string>;
private writable;
private emit;
private on;
private once;
private write;
private end;
private removeListener;
private static disarm;
}
type ProcessDto = {
code: number | null;
signal: NodeJS.Signals | null;
duration: number;
error: any;
from: string;
store: TSpawnStore;
delimiter?: string | RegExp;
};
export declare class ProcessOutput extends Error {
private readonly _dto;
cause: Error | null;
message: string;
stdout: string;
stderr: string;
stdall: string;
constructor(dto: ProcessDto);
constructor(code?: number | null, signal?: NodeJS.Signals | null, stdout?: string, stderr?: string, stdall?: string, message?: string, duration?: number);
get exitCode(): number | null;
get signal(): NodeJS.Signals | null;
get duration(): number;
get [Symbol.toStringTag](): string;
get ok(): boolean;
json<T = any>(): T;
buffer(): Buffer;
blob(type?: string): Blob;
text(encoding?: Encoding): string;
lines(delimiter?: string | RegExp): string[];
toString(): string;
valueOf(): string;
[Symbol.toPrimitive](): string;
[Symbol.iterator](dlmtr?: Options['delimiter']): Iterator<string>;
[inspect.custom](): string;
static getExitMessage: typeof Fail.formatExitMessage;
static getErrorMessage: typeof Fail.formatErrorMessage;
static getErrorDetails: typeof Fail.formatErrorDetails;
static getExitCodeInfo: typeof Fail.getExitCodeInfo;
static fromError(error: Error): ProcessOutput;
}
export declare const useBash: () => void;
export declare const usePwsh: () => void;
export declare const usePowerShell: () => void;
export declare function syncProcessCwd(flag?: boolean): void;
export declare function cd(dir: string | ProcessOutput): void;
export declare function kill(pid: number | `${number}`, signal?: NodeJS.Signals): Promise<void>;
export declare function resolveDefaults(defs?: Options, prefix?: string, env?: NodeJS.ProcessEnv, allowed?: Set<string>): Options;