Skip to content

Commit

Permalink
feat: provide configurable spawn (#333)
Browse files Browse the repository at this point in the history
* feat: make spawn configurable

* docs: mention $.spawn
  • Loading branch information
antongolub committed Mar 11, 2022
1 parent 08b5ca0 commit 73aee91
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,10 @@ $.shell = '/usr/bin/bash'

Or use a CLI argument: `--shell=/bin/bash`

#### `$.spanw`

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

#### `$.prefix`

Specifies the command that will be prefixed to all commands run.
Expand Down
3 changes: 2 additions & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import {ChildProcess} from 'child_process'
import {ChildProcess, spawn} from 'child_process'
import {Readable, Writable} from 'stream'
import * as _fs from 'fs-extra'
import * as _globby from 'globby'
Expand All @@ -30,6 +30,7 @@ interface $ {
shell: string
prefix: string
quote: (input: string) => string
spawn: typeof spawn
}

export interface ProcessPromise<T> extends Promise<T> {
Expand Down
3 changes: 2 additions & 1 deletion index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ 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'],
Expand Down Expand Up @@ -142,6 +142,7 @@ if (typeof argv.prefix === 'string') {
$.prefix = argv.prefix
}
$.quote = quote
$.spawn = spawn

export function cd(path) {
if ($.verbose) console.log('$', colorize(`cd ${path}`))
Expand Down

0 comments on commit 73aee91

Please sign in to comment.