@j-o-r/sh 1.1.28 → 1.1.31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +145 -151
- package/TODO.md +8 -0
- package/lib/AsyncTracker.js +126 -107
- package/lib/SH.js +281 -224
- package/lib/SHDispatch.js +122 -94
- package/lib/SHExecute.js +83 -41
- package/lib/Test.js +153 -123
- package/package.json +2 -2
- package/types/AsyncTracker.d.ts +65 -31
- package/types/SH.d.ts +190 -168
- package/types/SHDispatch.d.ts +81 -66
- package/types/SHExecute.d.ts +44 -23
- package/types/Test.d.ts +66 -30
package/types/SH.d.ts
CHANGED
|
@@ -1,198 +1,220 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parsed command-line arguments.
|
|
3
|
+
*
|
|
4
|
+
* Named options map to their string value, or `true` when no value is supplied.
|
|
5
|
+
* Bare positional arguments are collected in `_`.
|
|
6
|
+
*/
|
|
1
7
|
export type ArgsObject = {
|
|
2
|
-
|
|
8
|
+
_: string[];
|
|
9
|
+
} & {
|
|
10
|
+
[x: string]: string | true | string[];
|
|
3
11
|
};
|
|
4
12
|
export type RejectCallback = Function;
|
|
5
13
|
export type ResolveCallback = Function;
|
|
14
|
+
export type SHOptions = import("./SHDispatch.js").SHOptions;
|
|
15
|
+
export type AbortableInput = {
|
|
16
|
+
/**
|
|
17
|
+
* - Promise that resolves to user input or void if aborted.
|
|
18
|
+
*/
|
|
19
|
+
input: Promise<string | void>;
|
|
20
|
+
/**
|
|
21
|
+
* - Function to abort input collection.
|
|
22
|
+
*/
|
|
23
|
+
abort: () => void;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Generator-like object that yields retry delay durations.
|
|
27
|
+
*/
|
|
28
|
+
export type ExpBackoffGenerator = Iterator<number | string>;
|
|
6
29
|
/**
|
|
7
|
-
*
|
|
30
|
+
* Template tag for building and executing shell commands.
|
|
31
|
+
*
|
|
32
|
+
* Returns an {@link SHDispatch} instance for configuration (.options()) and execution (.run(), .runSync()).
|
|
33
|
+
*
|
|
34
|
+
* Interpolation rules are raw-by-default:
|
|
35
|
+
* - Arrays: Each element is converted with `String(value)` and joined with one space.
|
|
36
|
+
* - Other values: `String(value)` is inserted directly into the shell source.
|
|
37
|
+
*
|
|
38
|
+
* Raw interpolation allows trusted shell fragments such as pipes, redirects, and
|
|
39
|
+
* command separators. It is not safe for untrusted input. Wrap untrusted values
|
|
40
|
+
* with {@link bashEscape} before interpolating them.
|
|
41
|
+
*
|
|
42
|
+
* SH acts as both template tag and options setter: `SH.timeout = 5000; SH`cmd``
|
|
43
|
+
*
|
|
44
|
+
* @param {TemplateStringsArray} pieces - String literals from template.
|
|
45
|
+
* @param {...unknown[]} args - Values to interpolate.
|
|
46
|
+
* @returns {SHDispatch} Command dispatcher.
|
|
47
|
+
* @throws {Error} If pieces contain undefined.
|
|
48
|
+
* @example
|
|
49
|
+
* const cmd = SH`echo ${'Hello'}`;
|
|
50
|
+
* await cmd.run(); // Executes: echo Hello
|
|
51
|
+
*
|
|
52
|
+
* // Array interpolation is raw and joins with spaces
|
|
53
|
+
* SH`ls ${['-la', '/']}`.run(); // Executes: ls -la /
|
|
54
|
+
*
|
|
55
|
+
* // Quote untrusted values explicitly
|
|
56
|
+
* SH`printf '%s\n' ${bashEscape('semi; colon')}`.run();
|
|
8
57
|
*/
|
|
9
|
-
export
|
|
58
|
+
export const SH: any;
|
|
10
59
|
/**
|
|
11
|
-
*
|
|
60
|
+
* Changes the current working directory.
|
|
61
|
+
*
|
|
62
|
+
* @param {string} dir - Path to new directory.
|
|
63
|
+
* @example
|
|
64
|
+
* cd('/tmp');
|
|
12
65
|
*/
|
|
13
|
-
export
|
|
66
|
+
export function cd(dir: string): void;
|
|
14
67
|
/**
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
|
|
68
|
+
* Sleeps for a specified duration.
|
|
69
|
+
*
|
|
70
|
+
* @param {string|number} duration - Duration as '5s', '100ms', or ms number.
|
|
71
|
+
* @returns {Promise<void>}
|
|
72
|
+
* @example
|
|
73
|
+
* await sleep('2s');
|
|
74
|
+
*/
|
|
75
|
+
export function sleep(duration: string | number): Promise<void>;
|
|
18
76
|
/**
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
* @
|
|
26
|
-
*
|
|
27
|
-
* @
|
|
28
|
-
|
|
29
|
-
|
|
77
|
+
* Retries an async function up to N times with optional delays.
|
|
78
|
+
*
|
|
79
|
+
* Delay can be fixed ('1s'), generator-like (expBackoff()), or none.
|
|
80
|
+
*
|
|
81
|
+
* @param {number} count - Positive integer number of attempts.
|
|
82
|
+
* @param {string|number|ExpBackoffGenerator|Function} delayOrCallback - Delay, delay generator, or callback if no separate callback is supplied.
|
|
83
|
+
* @param {Function} [callback] - Callback to retry when a delay is supplied.
|
|
84
|
+
* @returns {Promise<any>} Successful result.
|
|
85
|
+
* @throws {Error} If arguments are invalid, or the last callback error if all attempts fail.
|
|
86
|
+
* @example
|
|
87
|
+
* await retry(3, '1s', () => SH`curl http://unreliable`.run());
|
|
88
|
+
* await retry(3, expBackoff(), () => flakyOp());
|
|
89
|
+
*/
|
|
90
|
+
export function retry(count: number, delayOrCallback: string | number | ExpBackoffGenerator | Function, callback?: Function): Promise<any>;
|
|
30
91
|
/**
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
|
|
34
|
-
|
|
92
|
+
* Reads entire stdin as UTF-8 string. Resolves to empty string if TTY (no pipe).
|
|
93
|
+
*
|
|
94
|
+
* @returns {Promise<string>} Stdin content, or an empty string if TTY.
|
|
95
|
+
* @example
|
|
96
|
+
* const input = await readIn(); // Use in piped scripts
|
|
97
|
+
*/
|
|
98
|
+
export function readIn(): Promise<string>;
|
|
35
99
|
/**
|
|
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
|
-
* const p = await retry(3, expBackoff(), () => SH`curl -s https://flipwrsi`);
|
|
62
|
-
*/
|
|
63
|
-
export function retry(count: number, a: string | number | typeof expBackoff | Function, b?: Function): Promise<any>;
|
|
64
|
-
/**
|
|
65
|
-
* This function reads the standard input (stdin) from the current process.
|
|
66
|
-
* @returns {Promise<string>}
|
|
67
|
-
* @example
|
|
68
|
-
* const content = await readIn();
|
|
69
|
-
*/
|
|
70
|
-
/**
|
|
71
|
-
* Read entire stdin as UTF-8. If stdin is a TTY, resolves to an empty string.
|
|
72
|
-
* @returns {Promise<string|undefined>}
|
|
73
|
-
*/
|
|
74
|
-
export function readIn(): Promise<string | undefined>;
|
|
75
|
-
/**
|
|
76
|
-
* Get user input from the command line (stdin)
|
|
77
|
-
* void when input has been aborted
|
|
78
|
-
* @param {string} prompt - prompt or question
|
|
79
|
-
* @returns {{input: Promise<string|void>, abort: function(): void}}
|
|
80
|
-
* @example
|
|
81
|
-
* const user = userIn('Question: ');
|
|
82
|
-
* const content = await user.input
|
|
83
|
-
* // user.abort()
|
|
84
|
-
*/
|
|
85
|
-
export function userIn(prompt: string): {
|
|
86
|
-
input: Promise<string | void>;
|
|
87
|
-
abort: () => void;
|
|
88
|
-
};
|
|
100
|
+
* Prompts user for input on stdin with custom prompt.
|
|
101
|
+
*
|
|
102
|
+
* Supports aborting input collection.
|
|
103
|
+
*
|
|
104
|
+
* @param {string} prompt - Prompt text to display.
|
|
105
|
+
* @returns {AbortableInput} Object with input Promise and abort function.
|
|
106
|
+
* @example
|
|
107
|
+
* const {input, abort} = userIn('Enter name: ');
|
|
108
|
+
* const name = await input;
|
|
109
|
+
* // abort(); // Cancel anytime
|
|
110
|
+
*/
|
|
111
|
+
export function userIn(prompt: string): AbortableInput;
|
|
112
|
+
/**
|
|
113
|
+
* Executes a callback in a new async context (fresh callstack).
|
|
114
|
+
*
|
|
115
|
+
* Useful for parallel operations without nesting.
|
|
116
|
+
*
|
|
117
|
+
* @param {() => Promise<any>} callback - Async function to execute.
|
|
118
|
+
* @returns {Promise<any>} Result of callback.
|
|
119
|
+
* @example
|
|
120
|
+
* const results = await within(async () => {
|
|
121
|
+
* return Promise.all([SH`sleep 1; echo 1`.run(), sleep(2)]);
|
|
122
|
+
* });
|
|
123
|
+
*/
|
|
124
|
+
export function within(callback: () => Promise<any>): Promise<any>;
|
|
89
125
|
/**
|
|
90
|
-
*
|
|
91
|
-
* @param {function} callback - async/sync function
|
|
92
|
-
* @example
|
|
93
|
-
* const p = within(async () => {
|
|
94
|
-
* const res = await Promise.all([
|
|
95
|
-
* SH`sleep 1; echo 1`.run(),
|
|
96
|
-
* SH`sleep 2; echo 2`.run(),
|
|
97
|
-
* sleep(2),
|
|
98
|
-
* SH`sleep 3; echo 3`.run()
|
|
99
|
-
* ]);
|
|
100
|
-
* return 'res';
|
|
101
|
-
* });
|
|
102
|
-
*/
|
|
103
|
-
export function within(callback: Function): Promise<any>;
|
|
104
|
-
/**
|
|
105
|
-
* Generates an exponential backoff time with a random jitter.
|
|
126
|
+
* Generator for exponential backoff delays with jitter.
|
|
106
127
|
*
|
|
107
128
|
* @generator
|
|
108
|
-
* @param {string} [max='60s'] -
|
|
109
|
-
* @param {string} [rand='100ms'] -
|
|
110
|
-
* @yields {number}
|
|
129
|
+
* @param {string} [max='60s'] - Max backoff duration.
|
|
130
|
+
* @param {string} [rand='100ms'] - Max jitter.
|
|
131
|
+
* @yields {number} Next backoff ms.
|
|
132
|
+
* @example
|
|
133
|
+
* const backoff = expBackoff();
|
|
134
|
+
* await sleep(backoff.next().value);
|
|
111
135
|
*/
|
|
112
136
|
export function expBackoff(max?: string, rand?: string): Generator<number, void, unknown>;
|
|
113
137
|
/**
|
|
114
|
-
* Parses
|
|
115
|
-
*
|
|
116
|
-
*
|
|
117
|
-
*
|
|
118
|
-
*
|
|
119
|
-
*
|
|
120
|
-
*
|
|
121
|
-
*
|
|
122
|
-
*
|
|
123
|
-
*
|
|
124
|
-
* - Each key corresponds to an argument that starts with `--` or `-`,
|
|
125
|
-
* - The value is either the next argument or `true` if no value is provided,
|
|
126
|
-
* - The `_` property contains an array of unbound arguments.
|
|
127
|
-
*/
|
|
128
|
-
/**
|
|
129
|
-
* Parse command-line args into an object.
|
|
130
|
-
*
|
|
131
|
-
* Supported:
|
|
132
|
-
* - --key value, -k value (no grouped short flags)
|
|
133
|
-
* - Bare values collected under `_.`
|
|
134
|
-
* - Duplicate keys throw an error; keys without a following value become true.
|
|
135
|
-
*
|
|
136
|
-
* Not supported:
|
|
137
|
-
* - --key=value syntax
|
|
138
|
-
* - Grouped short flags like -abc
|
|
139
|
-
*
|
|
140
|
-
* @param {string[]} [args]
|
|
138
|
+
* Parses CLI arguments into an object.
|
|
139
|
+
*
|
|
140
|
+
* Supports --key value, -k value (no shorts grouped).
|
|
141
|
+
* Bares go to _[]. Duplicates error. No = syntax.
|
|
142
|
+
* Negative number tokens such as -1, -0.5, and -1e3 are parsed as values or
|
|
143
|
+
* positionals, not options.
|
|
144
|
+
*
|
|
145
|
+
* Defaults to process.argv.slice(2).
|
|
146
|
+
*
|
|
147
|
+
* @param {string[]} [args=process.argv.slice(2)] - Args array.
|
|
141
148
|
* @returns {ArgsObject}
|
|
149
|
+
* @throws {Error} On invalid/dupe args.
|
|
150
|
+
* @example
|
|
151
|
+
* parseArgs(['--port', '8080', 'file.txt']); // { port: '8080', _: ['file.txt'] }
|
|
152
|
+
* parseArgs(['--n', '-1']); // { n: '-1', _: [] }
|
|
142
153
|
*/
|
|
143
154
|
export function parseArgs(args?: string[]): ArgsObject;
|
|
144
155
|
/**
|
|
145
|
-
*
|
|
146
|
-
*
|
|
147
|
-
*
|
|
148
|
-
*
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
* @typedef {
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
* @
|
|
165
|
-
* @
|
|
166
|
-
* @
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
*
|
|
170
|
-
*
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
*
|
|
175
|
-
*
|
|
176
|
-
* @
|
|
177
|
-
|
|
156
|
+
* Parsed command-line arguments.
|
|
157
|
+
*
|
|
158
|
+
* Named options map to their string value, or `true` when no value is supplied.
|
|
159
|
+
* Bare positional arguments are collected in `_`.
|
|
160
|
+
*
|
|
161
|
+
* @typedef {{_: string[]} & Object.<string, string|true|string[]>} ArgsObject
|
|
162
|
+
*/
|
|
163
|
+
/**
|
|
164
|
+
* @typedef {Function} RejectCallback
|
|
165
|
+
* @param {Error} error - The error object passed to the callback.
|
|
166
|
+
*/
|
|
167
|
+
/**
|
|
168
|
+
* @typedef {Function} ResolveCallback
|
|
169
|
+
* @param {any} [param] - Optional callback any value
|
|
170
|
+
*/
|
|
171
|
+
/**
|
|
172
|
+
* @typedef {import('./SHDispatch.js').SHOptions} SHOptions
|
|
173
|
+
*/
|
|
174
|
+
/**
|
|
175
|
+
* @typedef {Object} AbortableInput
|
|
176
|
+
* @property {Promise<string|void>} input - Promise that resolves to user input or void if aborted.
|
|
177
|
+
* @property {() => void} abort - Function to abort input collection.
|
|
178
|
+
*/
|
|
179
|
+
/**
|
|
180
|
+
* Generator-like object that yields retry delay durations.
|
|
181
|
+
*
|
|
182
|
+
* @typedef {Iterator<number|string>} ExpBackoffGenerator
|
|
183
|
+
*/
|
|
184
|
+
/**
|
|
185
|
+
* Utility to determine the JavaScript type of a value.
|
|
186
|
+
*
|
|
187
|
+
* @param {any} fn - Any value to inspect.
|
|
188
|
+
* @returns {string} The "real" object type name (e.g., 'Array', 'Promise') or primitive typeof.
|
|
189
|
+
* @example
|
|
190
|
+
* jsType([]); // 'Array'
|
|
191
|
+
* jsType(Promise.resolve()); // 'Promise'
|
|
192
|
+
*/
|
|
178
193
|
export function jsType(fn: any): string;
|
|
179
194
|
/**
|
|
180
|
-
*
|
|
181
|
-
*
|
|
182
|
-
* @param {any} o -
|
|
183
|
-
* @param {string} p -
|
|
184
|
-
* @returns {boolean}
|
|
185
|
-
*/
|
|
195
|
+
* Checks if an object has a specific own property (code-safe).
|
|
196
|
+
*
|
|
197
|
+
* @param {any} o - Object to examine.
|
|
198
|
+
* @param {string} p - Property name to check.
|
|
199
|
+
* @returns {boolean} True if the object has the own property.
|
|
200
|
+
*/
|
|
186
201
|
export function hasProp(o: any, p: string): boolean;
|
|
187
202
|
import Test from './Test.js';
|
|
188
203
|
import assert from 'node:assert';
|
|
189
204
|
import AsyncTracker from './AsyncTracker.js';
|
|
190
205
|
/**
|
|
191
|
-
*
|
|
192
|
-
*
|
|
193
|
-
*
|
|
194
|
-
*
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
206
|
+
* Quotes a value as one POSIX shell argument.
|
|
207
|
+
*
|
|
208
|
+
* The `SH` template tag interpolates values as raw shell source by default. Use
|
|
209
|
+
* this helper when a JavaScript value must be passed as data instead of shell
|
|
210
|
+
* syntax. The returned string is single-quoted and preserves the exact string
|
|
211
|
+
* value, including leading/trailing whitespace, empty strings, quotes,
|
|
212
|
+
* semicolons, glob characters, tabs, and newlines.
|
|
213
|
+
*
|
|
214
|
+
* @param {unknown} x - Value to quote as a single shell argument.
|
|
215
|
+
* @returns {string} POSIX-shell-quoted argument string.
|
|
216
|
+
* @example
|
|
217
|
+
* await SH`printf '%s\n' ${bashEscape(userInput)}`.run();
|
|
218
|
+
*/
|
|
219
|
+
export function bashEscape(x: unknown): string;
|
|
198
220
|
export { Test, assert, AsyncTracker };
|
package/types/SHDispatch.d.ts
CHANGED
|
@@ -1,113 +1,128 @@
|
|
|
1
1
|
export default SHDispatch;
|
|
2
2
|
export type SpawnSyncResponse = {
|
|
3
3
|
/**
|
|
4
|
-
* - Exit code
|
|
4
|
+
* - Exit code (null if signal).
|
|
5
5
|
*/
|
|
6
6
|
status: number | null;
|
|
7
7
|
/**
|
|
8
|
-
* -
|
|
8
|
+
* - Terminating signal.
|
|
9
9
|
*/
|
|
10
10
|
signal: string | null;
|
|
11
11
|
/**
|
|
12
|
-
* - [stdin, stdout, stderr]
|
|
12
|
+
* - [stdin, stdout, stderr].
|
|
13
13
|
*/
|
|
14
14
|
output: (string | Buffer | null)[];
|
|
15
15
|
/**
|
|
16
|
-
* -
|
|
16
|
+
* - Process ID.
|
|
17
17
|
*/
|
|
18
18
|
pid: number;
|
|
19
19
|
/**
|
|
20
|
-
* -
|
|
20
|
+
* - Captured stdout.
|
|
21
21
|
*/
|
|
22
22
|
stdout: string | Buffer | null;
|
|
23
23
|
/**
|
|
24
|
-
* -
|
|
24
|
+
* - Captured stderr.
|
|
25
25
|
*/
|
|
26
26
|
stderr: string | Buffer | null;
|
|
27
27
|
};
|
|
28
|
+
export type StdioOption = ("pipe" | "ignore" | "inherit" | number);
|
|
29
|
+
export type StdioOptions = Array<StdioOption> | StdioOption;
|
|
30
|
+
/**
|
|
31
|
+
* Core options for SH/SHDispatch.
|
|
32
|
+
*
|
|
33
|
+
* Defaults (merged from global SH):
|
|
34
|
+
* - `cwd`: `process.cwd()`
|
|
35
|
+
* - `env`: `process.env`
|
|
36
|
+
* - `shell`: `'bash'` (string/true → shell; false → no-shell `/usr/bin/env -S`)
|
|
37
|
+
* - `stdio`: `['inherit', 'pipe', 'pipe']`
|
|
38
|
+
* - `timeout`: `0` (no timeout; rolling on data)
|
|
39
|
+
* - `maxBuffer`: `512000` (500 kb per stream in SHExecute)
|
|
40
|
+
*
|
|
41
|
+
* Prefix (`.options(undefined, prefix)`) only for shell mode.
|
|
42
|
+
*/
|
|
28
43
|
export type SHOptions = {
|
|
29
44
|
/**
|
|
30
|
-
* -
|
|
45
|
+
* - Working directory for spawned commands.
|
|
31
46
|
*/
|
|
32
|
-
cwd
|
|
33
|
-
/**
|
|
34
|
-
* - Environment key-value pairs.
|
|
35
|
-
*/
|
|
36
|
-
env?: Object | undefined;
|
|
37
|
-
/**
|
|
38
|
-
* - Explicitly set the value of `argv[0]` sent to the child process.
|
|
39
|
-
*/
|
|
40
|
-
argv0?: string | undefined;
|
|
41
|
-
/**
|
|
42
|
-
* - If true, the child will be a process group leader.
|
|
43
|
-
*/
|
|
44
|
-
detached?: boolean | undefined;
|
|
47
|
+
cwd: string;
|
|
45
48
|
/**
|
|
46
|
-
* -
|
|
49
|
+
* - Environment for spawned commands.
|
|
47
50
|
*/
|
|
48
|
-
|
|
51
|
+
env: NodeJS.ProcessEnv;
|
|
49
52
|
/**
|
|
50
|
-
* -
|
|
53
|
+
* - Shell executable, true for bash, or false for no-shell mode.
|
|
51
54
|
*/
|
|
52
|
-
|
|
55
|
+
shell: string | boolean;
|
|
53
56
|
/**
|
|
54
|
-
* -
|
|
57
|
+
* - Stdio config passed to child_process.
|
|
55
58
|
*/
|
|
56
|
-
stdio
|
|
59
|
+
stdio: StdioOptions;
|
|
57
60
|
/**
|
|
58
|
-
* -
|
|
61
|
+
* - Rolling timeout in ms or duration string; 0 disables timeout.
|
|
59
62
|
*/
|
|
60
|
-
|
|
63
|
+
timeout: number | string;
|
|
61
64
|
/**
|
|
62
|
-
* -
|
|
65
|
+
* - Maximum buffered bytes per stdout/stderr stream.
|
|
63
66
|
*/
|
|
64
|
-
|
|
67
|
+
maxBuffer?: number | undefined;
|
|
65
68
|
/**
|
|
66
|
-
* -
|
|
69
|
+
* - Run process detached and resolve early.
|
|
67
70
|
*/
|
|
68
|
-
|
|
71
|
+
detached?: boolean | undefined;
|
|
69
72
|
};
|
|
70
|
-
export type StdioOption = ("pipe" | "ignore" | "inherit" | number);
|
|
71
|
-
export type StdioOptions = Array<StdioOption> | StdioOption;
|
|
72
73
|
/**
|
|
73
|
-
*
|
|
74
|
+
* High-level command dispatcher.
|
|
74
75
|
*
|
|
75
|
-
*
|
|
76
|
-
* - cwd: process.cwd()
|
|
77
|
-
* - env: process.env
|
|
78
|
-
* - shell: 'bash' (string). If a string, that shell is used. If true, 'bash' is used. If false/undefined, no shell is used.
|
|
79
|
-
* - stdio: ['inherit', 'pipe', 'pipe'] — inherit stdin, capture stdout/stderr
|
|
80
|
-
* - timeout: 0 — no timeout
|
|
81
|
-
* - maxBuffer?: number — optional (bytes per stream). Passed through to SHExecute.
|
|
76
|
+
* Created by {@link SH`cmd`}; chain `.options()` then `.run()`.
|
|
82
77
|
*
|
|
83
|
-
*
|
|
84
|
-
*
|
|
85
|
-
*
|
|
78
|
+
* Delegates to {@link SHExecute} for exec/timeout/buffer/kill.
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* const dispatch = SH`ls -la`.options({ timeout: '2s' });
|
|
82
|
+
* const out = await dispatch.run();
|
|
86
83
|
*/
|
|
87
84
|
declare class SHDispatch {
|
|
88
85
|
/**
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
86
|
+
* @param {string} cmd - Command string.
|
|
87
|
+
* @param {Partial<SHOptions>} [options] - Initial options.
|
|
88
|
+
* @param {string} [prefix] - Shell prefix (e.g., 'set -euo pipefail').
|
|
89
|
+
* @throws {Error} Invalid/empty cmd.
|
|
90
|
+
*/
|
|
91
|
+
constructor(cmd: string, options?: Partial<SHOptions>, prefix?: string);
|
|
92
|
+
/**
|
|
93
|
+
* Updates options/prefix by merging into the dispatch instance's current options.
|
|
94
|
+
*
|
|
95
|
+
* This preserves global `SH.*` defaults captured when the command was created
|
|
96
|
+
* and only overrides options explicitly supplied for this command. Strings for
|
|
97
|
+
* `stdio` are expanded to `[value, value, value]`.
|
|
98
|
+
*
|
|
99
|
+
* @param {Partial<SHOptions>} [options] - New options.
|
|
100
|
+
* @param {string} [prefix] - New prefix.
|
|
101
|
+
* @returns {SHDispatch} Self for chaining.
|
|
102
|
+
*/
|
|
103
|
+
options(options?: Partial<SHOptions>, prefix?: string): SHDispatch;
|
|
104
|
+
/**
|
|
105
|
+
* Async run: Captures stdout; rejects on error/timeout.
|
|
106
|
+
*
|
|
107
|
+
* @param {string} [payload] - Stdin payload.
|
|
108
|
+
* @returns {Promise<string>} Stdout.
|
|
109
|
+
*/
|
|
104
110
|
run(payload?: string): Promise<string>;
|
|
105
111
|
/**
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
+
* Sync run: Full Node SpawnSyncReturns.
|
|
113
|
+
*
|
|
114
|
+
* Good for TTY takeovers (e.g., vim).
|
|
115
|
+
*
|
|
116
|
+
* @param {string} [payload] - Stdin payload.
|
|
117
|
+
* @returns {import('child_process').SpawnSyncReturns<Buffer>}
|
|
118
|
+
*/
|
|
119
|
+
runSync(payload?: string): import("child_process").SpawnSyncReturns<Buffer>;
|
|
120
|
+
/**
|
|
121
|
+
* Kills running process + children.
|
|
122
|
+
*
|
|
123
|
+
* @param {number | string} [signal='SIGTERM'] - Signal.
|
|
124
|
+
* @returns {Promise<number[]>} Killed PIDs.
|
|
125
|
+
*/
|
|
126
|
+
kill(signal?: number | string): Promise<number[]>;
|
|
112
127
|
#private;
|
|
113
128
|
}
|