src/exec
Portable subprocess helper built on child_process.spawn and line streaming.
Each stdio fd defaults to "inherit". spawn streams output
line-by-line into ExecResult.stdoutLines
/ ExecResult.stderrLines; its stdout / stderr getters join those lines.
spawnSync keeps the captured string; its stdout / stderr getters read
that string directly (line arrays split lazily on read).
Omitted trim (default) applies adaptive normalization: spawnSync drops
at most one trailing empty line / newline spawnSync adds; spawn does
not (readline never emits that extra line). trim: true strips all leading/
trailing whitespace in both modes; trim: false leaves output unchanged.
This module owns subprocess execution policy for Node and Bun packages. Reuse
it instead of wrapping child_process locally when callers need consistent
argv parsing, stdio capture, line callbacks, cancellation, and exit checking.
Examples
Section titled “Examples”Capture command output
const { stdout } = await exec("git", ["rev-parse", "--show-toplevel"], { stdout: "capture", stderr: "ignore", stdin: "ignore",});Stream and capture together
await exec("pnpm", ["install"], { stdout: [(line) => console.log(line), "capture"], check: true,});Synchronous capture (no line callbacks)
const { stdout } = execSync("git", ["rev-parse", "--show-toplevel"], { stdout: "capture", stderr: "ignore", stdin: "ignore",});Interfaces
Section titled “Interfaces”Type Aliases
Section titled “Type Aliases”- ChildProcessResult
- ExecOptions
- ExecResult
- ExecStdio
- LineHandler
- SpawnArgs
- StdioOption
- SyncExecOptions
- SyncExecStdio