@j-o-r/sh 1.1.28 → 1.1.29

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/types/SH.d.ts CHANGED
@@ -3,196 +3,189 @@ export type ArgsObject = {
3
3
  };
4
4
  export type RejectCallback = Function;
5
5
  export type ResolveCallback = Function;
6
+ export type SHOptions = import("./SHDispatch.js").SHOptions;
7
+ export type AbortableInput = {
8
+ /**
9
+ * - Promise that resolves to user input or void if aborted.
10
+ */
11
+ input: Promise<string | void>;
12
+ /**
13
+ * - Function to abort input collection.
14
+ */
15
+ abort: () => void;
16
+ };
17
+ export type ExpBackoffGenerator = Object;
6
18
  /**
7
- * Creates a new SHDispatch object that represents a command to be executed.
19
+ * Template tag for building and executing shell commands.
20
+ *
21
+ * Returns an {@link SHDispatch} instance for configuration (.options()) and execution (.run(), .runSync()).
22
+ *
23
+ * Interpolation rules:
24
+ * - Arrays: Elements trimmed, newlines/tabs escaped, shell-special chars single-quoted with '\'' escape.
25
+ * - Other values: String(value) inserted as-is (NOT auto-escaped; use {@link bashEscape} for safety).
26
+ *
27
+ * SH acts as both template tag and options setter: `SH.timeout = 5000; SH`cmd``
28
+ *
29
+ * @param {TemplateStringsArray} pieces - String literals from template.
30
+ * @param {...unknown[]} args - Values to interpolate.
31
+ * @returns {SHDispatch} Command dispatcher.
32
+ * @throws {Error} If pieces contain undefined.
33
+ * @example
34
+ * const cmd = SH`echo ${'Hello'}`;
35
+ * await cmd.run(); // Executes: echo Hello
36
+ *
37
+ * // Array interpolation
38
+ * SH`ls ${['-la', '/']}`.run(); // ls '-la' '/'
8
39
  */
9
- export type Shell = Function;
40
+ export const SH: any;
10
41
  /**
11
- * A template-tag that returns an SHDispatch.
42
+ * Changes the current working directory.
43
+ *
44
+ * @param {string} dir - Path to new directory.
45
+ * @example
46
+ * cd('/tmp');
12
47
  */
13
- export type SHTag = (pieces: TemplateStringsArray, ...args: unknown[]) => SHDispatch;
14
- /**
15
- * A template-tag that returns an SHDispatch.
16
- * @typedef {(pieces: TemplateStringsArray, ...args: unknown[]) => SHDispatch} SHTag
17
- */
48
+ export function cd(dir: string): void;
18
49
  /**
19
- * SH template tag
20
- *
21
- * Interpolation rules:
22
- * - Arrays: each element is String(x).trim(), with newlines/carriage returns/tabs escaped; if an element contains shell metacharacters or spaces, it is wrapped in single-quotes and internal single-quotes are escaped as '\''.
23
- * - Non-array values: currently coerced with String(value) and inserted as-is (NOT shell-escaped). Be careful when interpolating untrusted input.
24
- *
25
- * @type {Shell & SHTag & defaultOptions}
26
- * Returns an SHDispatch that can be configured via .options() and executed with .run() / .runSync().
27
- * @returns {SHDispatch}
28
- */
29
- export const SH: Shell & SHTag & import("./SHDispatch.js").SHOptions;
50
+ * Sleeps for a specified duration.
51
+ *
52
+ * @param {string|number} duration - Duration as '5s', '100ms', or ms number.
53
+ * @returns {Promise<void>}
54
+ * @example
55
+ * await sleep('2s');
56
+ */
57
+ export function sleep(duration: string | number): Promise<void>;
30
58
  /**
31
- * Change working directory
32
- * @param {string} dir
33
- */
34
- export function cd(dir: string): void;
59
+ * Retries an async function up to N times with optional delays.
60
+ *
61
+ * Delay can be fixed ('1s'), generator (expBackoff()), or none.
62
+ *
63
+ * @param {number} count - Number of attempts.
64
+ * @param {string|number|ExpBackoffGenerator|Function} delayOrFn - Delay or callback if no separate fn.
65
+ * @param {Function} [fn] - Callback to retry (if delayOrFn not function).
66
+ * @returns {Promise<any>} Successful result.
67
+ * @throws {Error} Last error if all attempts fail.
68
+ * @example
69
+ * await retry(3, '1s', () => SH`curl http://unreliable`.run());
70
+ * await retry(3, expBackoff(), () => flakyOp());
71
+ */
72
+ export function retry(count: number, a: any, b: any): Promise<any>;
35
73
  /**
36
- * This function pauses or "sleeps" code execution for a specified duration.
37
- * @param {string|number} duration - The duration to pause execution for, e.g., '100ms' or '3s'.
38
- *
39
- * @example
40
- *
41
- * await sleep('5s');
42
- */
43
- export function sleep(duration: string | number): Promise<any>;
44
- /**
45
- * Retries a given asynchronous function a specified number of times with optional delays between attempts.
46
- *
47
- * @param {number} count - The number of retry attempts.
48
- * @param {string|number|expBackoff|Function} a - Either a delay duration as a string, a delay generator object, or the callback function.
49
- * @param {Function} [b] - The callback function to retry, required if `a` is not a function.
50
- * @returns {Promise<*>} - The result of the callback function if it succeeds within the retry attempts.
51
- * @throws {Error} - The last error encountered if all retry attempts fail.
52
- *
53
- * @example
54
- * // Retry a command 3 times
55
- * const p = await retry(3, () => SH`curl -s https://flipwrsi`);
56
- *
57
- * // Retry a command 3 times with an interval of 1 second between each try
58
- * const p = await retry(3, '1s', () => SH`curl -s https://flipwrsi`);
59
- *
60
- * // Retry a command 3 times with irregular intervals using exponential backoff
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>}
74
+ * Reads entire stdin as UTF-8 string. Resolves to empty string if TTY (no pipe).
75
+ *
76
+ * @returns {Promise<string|undefined>} Stdin content or undefined if TTY.
77
+ * @example
78
+ * const input = await readIn(); // Use in piped scripts
73
79
  */
74
80
  export function readIn(): Promise<string | undefined>;
75
81
  /**
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
- };
82
+ * Prompts user for input on stdin with custom prompt.
83
+ *
84
+ * Supports aborting input collection.
85
+ *
86
+ * @param {string} prompt - Prompt text to display.
87
+ * @returns {AbortableInput} Object with input Promise and abort function.
88
+ * @example
89
+ * const {input, abort} = userIn('Enter name: ');
90
+ * const name = await input;
91
+ * // abort(); // Cancel anytime
92
+ */
93
+ export function userIn(prompt: string): AbortableInput;
89
94
  /**
90
- * Create a async/sync context in new execution callstack
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.
95
+ * Executes a callback in a new async context (fresh callstack).
96
+ *
97
+ * Useful for parallel operations without nesting.
98
+ *
99
+ * @param {() => Promise<any>} callback - Async function to execute.
100
+ * @returns {Promise<any>} Result of callback.
101
+ * @example
102
+ * const results = await within(async () => {
103
+ * return Promise.all([SH`sleep 1; echo 1`.run(), sleep(2)]);
104
+ * });
105
+ */
106
+ export function within(callback: () => Promise<any>): Promise<any>;
107
+ /**
108
+ * Generator for exponential backoff delays with jitter.
106
109
  *
107
110
  * @generator
108
- * @param {string} [max='60s'] - The maximum backoff time in a human-readable format (e.g., '60s' for 60 seconds).
109
- * @param {string} [rand='100ms'] - The maximum random jitter time in a human-readable format (e.g., '100ms' for 100 milliseconds).
110
- * @yields {number} The backoff time in milliseconds.
111
+ * @param {string} [max='60s'] - Max backoff duration.
112
+ * @param {string} [rand='100ms'] - Max jitter.
113
+ * @yields {number} Next backoff ms.
114
+ * @example
115
+ * const backoff = expBackoff();
116
+ * await sleep(backoff.next().value);
111
117
  */
112
118
  export function expBackoff(max?: string, rand?: string): Generator<number, void, unknown>;
113
119
  /**
114
- * Parses command-line arguments into an object.
115
- *
116
- * The function recognizes arguments that start with two dashes (`--`) or one dash (`-`) as keys,
117
- * and the subsequent value (if not another key) as the corresponding value.
118
- * If a key does not have a value, it defaults to `true`.
119
- * All unrecognized arguments are collected in an array under the `_` property.
120
- *
121
- * @param {string[]} [args] - An array of command-line arguments (process.argv.slice(2)).
122
- * @returns {ArgsObject} An object where:
123
- * - If args is not passed, process.argv.slice(2) will be the default
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]
120
+ * Parses CLI arguments into an object.
121
+ *
122
+ * Supports --key value, -k value (no shorts grouped).
123
+ * Bares go to _[]. Duplicates error. No = syntax.
124
+ *
125
+ * Defaults to process.argv.slice(2).
126
+ *
127
+ * @param {string[]} [args=process.argv.slice(2)] - Args array.
141
128
  * @returns {ArgsObject}
129
+ * @throws {Error} On invalid/dupe args.
130
+ * @example
131
+ * parseArgs(['--port', '8080', 'file.txt']); // { port: '8080', _: ['file.txt'] }
142
132
  */
143
133
  export function parseArgs(args?: string[]): ArgsObject;
144
134
  /**
145
- * @typedef {Object.<string, string>} ArgsObject
146
- * @property {string} [key: string] - Any string key maps to a string value
147
- * @property {string[]} _ - Array of strings, unnamed parameters
148
- * @description Parsed parameters result.
149
- */
150
- /**
151
- * @typedef {Function} RejectCallback
152
- * @param {Error} error - The error object passed to the callback.
153
- */
154
- /**
155
- * @typedef {Function} ResolveCallback
156
- * @param {any} [param] - Optional callback any value
157
- */
158
- /**
159
- * Creates a new SHDispatch object that represents a command to be executed.
160
- *
161
- * @typedef {Function} Shell
162
- * @property {function(Array, ...*): ProcessPromise} execute - The function to execute the command.
163
- *
164
- * @param {Array} pieces - An array of string literals from a template literal.
165
- * @param {...*} args - The values to be interpolated into the string literals.
166
- * @returns {SHDispatch} Trigger for the command.
167
- * @throws {Error} Throws an error if any of the string literals in `pieces` is undefined.
168
- *
169
- * @example
170
- * const command = await SH`echo 'Hello, world!'`.run();
171
- */
172
- /**
173
- * Determine a javascript type
174
- *
175
- * @param {any} fn - Any let type
176
- * @returns {string} The "real" object / typeof name
177
- */
135
+ * @typedef {Object.<string, string>} ArgsObject
136
+ * @property {string[]} _ - Array of strings, unnamed parameters
137
+ * @property {string} [key: string] - Any string key maps to a string value
138
+ * @description Parsed parameters result.
139
+ */
140
+ /**
141
+ * @typedef {Function} RejectCallback
142
+ * @param {Error} error - The error object passed to the callback.
143
+ */
144
+ /**
145
+ * @typedef {Function} ResolveCallback
146
+ * @param {any} [param] - Optional callback any value
147
+ */
148
+ /**
149
+ * @typedef {import('./SHDispatch.js').SHOptions} SHOptions
150
+ */
151
+ /**
152
+ * @typedef {Object} AbortableInput
153
+ * @property {Promise<string|void>} input - Promise that resolves to user input or void if aborted.
154
+ * @property {() => void} abort - Function to abort input collection.
155
+ */
156
+ /**
157
+ * @typedef {Object} ExpBackoffGenerator
158
+ * @generator
159
+ * @yields {number} Backoff time in ms.
160
+ */
161
+ /**
162
+ * Utility to determine the JavaScript type of a value.
163
+ *
164
+ * @param {any} fn - Any value to inspect.
165
+ * @returns {string} The "real" object type name (e.g., 'Array', 'Promise') or primitive typeof.
166
+ * @example
167
+ * jsType([]); // 'Array'
168
+ * jsType(Promise.resolve()); // 'Promise'
169
+ */
178
170
  export function jsType(fn: any): string;
179
171
  /**
180
- * 'Code Safe' has own prop
181
- *
182
- * @param {any} o - object to examine
183
- * @param {string} p - property to look for
184
- * @returns {boolean}
185
- */
172
+ * Checks if an object has a specific own property (code-safe).
173
+ *
174
+ * @param {any} o - Object to examine.
175
+ * @param {string} p - Property name to check.
176
+ * @returns {boolean} True if the object has the own property.
177
+ */
186
178
  export function hasProp(o: any, p: string): boolean;
187
179
  import Test from './Test.js';
188
180
  import assert from 'node:assert';
189
181
  import AsyncTracker from './AsyncTracker.js';
190
182
  /**
191
- * bash escape a string suitable as an argument on the commandline
192
- * for javascript code
193
- * @param {string} x
194
- * @returns {string}
195
- */
183
+ * Escapes a string for safe use as a bash command-line argument.
184
+ *
185
+ * Handles quotes, backticks, $, newlines, etc.
186
+ *
187
+ * @param {string} x - Input string to escape.
188
+ * @returns {string} Bash-escaped string.
189
+ */
196
190
  export function bashEscape(x: string): string;
197
- import SHDispatch from './SHDispatch.js';
198
191
  export { Test, assert, AsyncTracker };
@@ -1,113 +1,90 @@
1
1
  export default SHDispatch;
2
2
  export type SpawnSyncResponse = {
3
3
  /**
4
- * - Exit code of the child process (null if terminated by signal).
4
+ * - Exit code (null if signal).
5
5
  */
6
6
  status: number | null;
7
7
  /**
8
- * - Name of the terminating signal, if any.
8
+ * - Terminating signal.
9
9
  */
10
10
  signal: string | null;
11
11
  /**
12
- * - [stdin, stdout, stderr] per Node's SpawnSyncReturns.
12
+ * - [stdin, stdout, stderr].
13
13
  */
14
14
  output: (string | Buffer | null)[];
15
15
  /**
16
- * - PID of the spawned process.
16
+ * - Process ID.
17
17
  */
18
18
  pid: number;
19
19
  /**
20
- * - Stdout collected (type depends on encoding option).
20
+ * - Captured stdout.
21
21
  */
22
22
  stdout: string | Buffer | null;
23
23
  /**
24
- * - Stderr collected (type depends on encoding option).
24
+ * - Captured stderr.
25
25
  */
26
26
  stderr: string | Buffer | null;
27
27
  };
28
- export type SHOptions = {
29
- /**
30
- * - Current working directory of the child process.
31
- */
32
- cwd?: string | undefined;
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;
45
- /**
46
- * - Sets the user identity of the process.
47
- */
48
- uid?: number | undefined;
49
- /**
50
- * - Sets the group identity of the process.
51
- */
52
- gid?: number | undefined;
53
- /**
54
- * - Child's stdio configuration.
55
- */
56
- stdio?: number | "pipe" | "ignore" | "inherit" | StdioOption[] | undefined;
57
- /**
58
- * - If string or true, runs the command via that shell ('bash' if true).
59
- */
60
- shell?: string | boolean | undefined;
61
- /**
62
- * - Milliseconds before sending SIGTERM (0 = no timeout).
63
- */
64
- timeout?: number | undefined;
65
- /**
66
- * - Optional stdin payload for spawnSync. Use .run(payload) for async.
67
- */
68
- input?: string | Uint8Array<ArrayBufferLike> | Buffer<ArrayBufferLike> | undefined;
69
- };
70
28
  export type StdioOption = ("pipe" | "ignore" | "inherit" | number);
71
29
  export type StdioOptions = Array<StdioOption> | StdioOption;
72
30
  /**
73
- * SHOptions — effective defaults and semantics used by SHDispatch/SHExecute
31
+ * High-level command dispatcher.
32
+ *
33
+ * Created by {@link SH`cmd`}; chain `.options()` then `.run()`.
74
34
  *
75
- * Defaults:
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.
35
+ * Delegates to {@link SHExecute} for exec/timeout/buffer/kill.
82
36
  *
83
- * Notes:
84
- * - The prefix (see options(prefix)) is only applied when a shell is used; it is ignored in no-shell mode.
85
- * - Each call to options() resets to the defaults and merges the provided options; it does not accumulate from prior calls.
37
+ * @example
38
+ * const dispatch = SH`ls -la`.options({ timeout: '2s' });
39
+ * const out = await dispatch.run();
86
40
  */
87
41
  declare class SHDispatch {
88
42
  /**
89
- * @param {string} cmd - cmd to execute
90
- * @param {SHOptions} options
91
- * @param {string} [prefix] - command prefix e.g (default) '/usr/bin/env'
92
- */
93
- constructor(cmd: string, options: SHOptions, prefix?: string);
43
+ * @param {string} cmd - Command string.
44
+ * @param {Partial<typeof SHOptions>} [options] - Initial options.
45
+ * @param {string} [prefix] - Shell prefix (e.g., 'set -euo pipefail').
46
+ * @throws {Error} Invalid/empty cmd.
47
+ */
48
+ constructor(cmd: string, options?: Partial<typeof SHOptions>, prefix?: string);
94
49
  /**
95
- * @param {SHOptions} [options]
96
- * @param {string} [prefix] - command prefix e.g (default) '/usr/bin/env'
97
- * @returns {SHDispatch}
98
- */
99
- options(options?: SHOptions, prefix?: string): SHDispatch;
50
+ * Updates options/prefix; resets to defaults + user overrides (non-cumulative).
51
+ *
52
+ * Strings for `stdio` → array fill.
53
+ *
54
+ * @param {Partial<typeof SHOptions>} [options] - New options.
55
+ * @param {string} [prefix] - New prefix.
56
+ * @returns {SHDispatch} Self for chaining.
57
+ */
58
+ options(options?: Partial<typeof SHOptions>, prefix?: string): SHDispatch;
100
59
  /**
101
- * @param {string} [payload]
102
- * @returns {Promise<string>}
103
- */
60
+ * Async run: Captures stdout; rejects on error/timeout.
61
+ *
62
+ * @param {string} [payload] - Stdin payload.
63
+ * @returns {Promise<string>} Stdout.
64
+ */
104
65
  run(payload?: string): Promise<string>;
105
66
  /**
106
- * Works for terminal screen takeovers like editors
107
- * @param {string} [payload]
108
- * @returns {import('child_process').SpawnSyncReturns}
109
- */
110
- runSync(payload?: string): import("child_process").SpawnSyncReturns<any>;
111
- kill(signal?: string): Promise<number[]>;
67
+ * Sync run: Full Node SpawnSyncReturns.
68
+ *
69
+ * Good for TTY takeovers (e.g., vim).
70
+ *
71
+ * @param {string} [payload] - Stdin payload.
72
+ * @returns {import('child_process').SpawnSyncReturns<Buffer>}
73
+ */
74
+ runSync(payload?: string): import("child_process").SpawnSyncReturns<Buffer>;
75
+ /**
76
+ * Kills running process + children.
77
+ *
78
+ * @param {number | string} [signal='SIGTERM'] - Signal.
79
+ * @returns {Promise<number[]>} Killed PIDs.
80
+ */
81
+ kill(signal?: number | string): Promise<number[]>;
112
82
  #private;
113
83
  }
84
+ declare namespace SHOptions {
85
+ let cwd: string;
86
+ let env: NodeJS.ProcessEnv;
87
+ let shell: string;
88
+ let stdio: string[];
89
+ let timeout: number;
90
+ }
@@ -1,39 +1,60 @@
1
1
  export default SHExecute;
2
+ export type SHExecuteOptions = any & {
3
+ maxBuffer?: number;
4
+ };
2
5
  /**
3
- * SHExecute
4
- * Low-level process runner used by SHDispatch.
6
+ * @typedef {import('../SH.js').SHOptions & { maxBuffer?: number }} SHExecuteOptions
7
+ * @description Extended options for SHExecute: adds `maxBuffer` (bytes per stream, default 1MB).
8
+ */
9
+ /**
10
+ * Low-level process executor for shell commands.
11
+ *
12
+ * Used internally by {@link SHDispatch}.
13
+ *
14
+ * Key features:
15
+ * - **Shell mode**: If `options.shell` is string/true, runs `${prefix}; ${command}` via shell ('bash' default).
16
+ * - **No-shell mode**: Uses `/usr/bin/env -S ${command}` for direct exec (ignores prefix).
17
+ * - **Rolling timeout**: `options.timeout` (ms/'2s'); resets on stdout/stderr data. SIGTERM on expiry.
18
+ * - **Buffering**: Captures stdout/stderr up to `maxBuffer` (1MB default); appends truncation markers.
19
+ * - **Payload**: `run(payload)` writes string to stdin (forces pipe).
20
+ * - **Detached**: If `options.detached`, resolves early (~1s) and unrefs.
21
+ * - **Kill**: Terminates process + children via pgrep.
5
22
  *
6
- * Features:
7
- * - Optional shell execution: if options.shell is a string (e.g., 'bash') or true, runs `${prefix}; ${command}` via that shell; otherwise runs without a shell using `/usr/bin/env -S`.
8
- * - Timeout: options.timeout may be a number (ms) or string like '1500ms' or '2s'. On timeout, run() rejects with a descriptive error.
9
- * - Buffering: Captures stdout/stderr up to maxBuffer bytes per stream (default 40 MiB). Appends "[stdout truncated]" / "[stderr truncated]" markers if exceeded.
10
- * - Payload: Passing a payload writes it to stdin and forces stdin to be a pipe.
11
- * - Detached mode: If options.detached is true, run() resolves to '' after ~1s and unrefs the process.
12
- * - Kill support: kill(signal) attempts to terminate the process (and some children) and causes run() to reject with "Process killed (forced).".
23
+ * @example
24
+ * const exec = new SHExecute('ls', 'set -euo pipefail', { timeout: '5s' });
25
+ * const out = await exec.run();
13
26
  */
14
27
  declare class SHExecute {
15
28
  /**
16
- * @param {string} command - linux command to be executed
17
- * @param {string} prefix - command prefix (shell prelude, e.g. 'set -euo pipefail')
18
- * @param {import('child_process').SpawnOptions & { maxBuffer?: number }} options
29
+ * @param {string} command - Command to execute.
30
+ * @param {string} prefix - Shell prelude (e.g., 'set -euo pipefail'); ignored in no-shell.
31
+ * @param {SHExecuteOptions} [options] - Spawn options + maxBuffer/timeout.
19
32
  */
20
- constructor(command: string, prefix: string, options?: import("child_process").SpawnOptions & {
21
- maxBuffer?: number;
22
- });
33
+ constructor(command: string, prefix: string, options?: SHExecuteOptions);
23
34
  /**
24
- * @param {string} [payload] - data to write
25
- * @returns {import('child_process').SpawnSyncReturns}
35
+ * Synchronous execution.
36
+ *
37
+ * @param {string} [payload] - Stdin data (forces pipe).
38
+ * @returns {import('child_process').SpawnSyncReturns<Buffer>}
39
+ * @throws {Error} Invalid payload type.
26
40
  */
27
- runSync(payload?: string): import("child_process").SpawnSyncReturns<any>;
41
+ runSync(payload?: string): import("child_process").SpawnSyncReturns<Buffer>;
28
42
  /**
29
- * @param {string} [payload] - data to write
30
- * @returns {Promise<string>}
43
+ * Asynchronous execution with buffering/timeout/kill.
44
+ *
45
+ * Resolves stdout (trimmed) on success; rejects on error/timeout/kill.
46
+ *
47
+ * @param {string} [payload] - Stdin data (forces pipe).
48
+ * @returns {Promise<string>} Trimmed UTF-8 stdout (+ truncation marker if exceeded).
49
+ * @throws {Error} Command failure (incl. code, stderr), timeout, kill, spawn error.
31
50
  */
32
51
  run(payload?: string): Promise<string>;
33
52
  /**
34
- * Kill this process and possible child processes
35
- * @param {number | string} signal - kill signal
36
- * @returns {Promise<number[]>}
53
+ * Terminates process and its children (via pgrep).
54
+ *
55
+ * @param {number | string} [signal='SIGTERM'] - Signal to send.
56
+ * @returns {Promise<number[]>} Killed PIDs.
57
+ * @throws {Error} No process/PID.
37
58
  */
38
59
  kill(signal?: number | string): Promise<number[]>;
39
60
  #private;