Skip to content

Commit

Permalink
feat: configurable maxBuffer spawn option (#337)
Browse files Browse the repository at this point in the history
* feat: add default spawn properties override: `timeout`, `killSignal` and `maxBuffer`

* refactor: store spawn opts as `$` own values

* revert: rm spawn timeout option
  • Loading branch information
antongolub committed Mar 13, 2022
1 parent 450917a commit 15d500d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,11 @@ Or use a CLI argument: `--shell=/bin/bash`

Specifies a `spawn` api. Defaults to `require('child_process').spawn`.

#### `$.maxBuffer`

Specifies the largest number of bytes allowed on stdout or stderr.
Defaults to `200 * 1024 * 1024` (200 MiB).

#### `$.prefix`

Specifies the command that will be prefixed to all commands run.
Expand Down
1 change: 1 addition & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ interface $ {
prefix: string
quote: (input: string) => string
spawn: typeof spawn
maxBuffer?: number | undefined
}

export interface ProcessPromise<T> extends Promise<T> {
Expand Down
6 changes: 3 additions & 3 deletions index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export function registerGlobals() {
}

export function $(pieces, ...args) {
let {verbose, shell, prefix} = $
let {verbose, shell, prefix, spawn, maxBuffer = 200 * 1024 * 1024 /* 200 MiB*/} = $
let __from = (new Error().stack.split(/^\s*at\s/m)[2]).trim()

let cmd = pieces[0], i = 0
Expand All @@ -80,12 +80,12 @@ export function $(pieces, ...args) {
printCmd(cmd)
}

let child = $.spawn(prefix + cmd, {
let child = spawn(prefix + cmd, {
cwd: process.cwd(),
shell: typeof shell === 'string' ? shell : true,
stdio: [promise._inheritStdin ? 'inherit' : 'pipe', 'pipe', 'pipe'],
windowsHide: true,
maxBuffer: 200 * 1024 * 1024, // 200 MiB
maxBuffer,
})

child.on('close', (code, signal) => {
Expand Down

0 comments on commit 15d500d

Please sign in to comment.