Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: provide configurable spawn #333

Merged
merged 2 commits into from
Mar 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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