Commit 73aee91

Anton Golub <mailbox@antongolub.ru>
2022-03-11 14:52:57
feat: provide configurable `spawn` (#333)
* feat: make spawn configurable * docs: mention $.spawn
1 parent 08b5ca0
index.d.ts
@@ -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'
@@ -30,6 +30,7 @@ interface $ {
   shell: string
   prefix: string
   quote: (input: string) => string
+  spawn: typeof spawn
 }
 
 export interface ProcessPromise<T> extends Promise<T> {
index.mjs
@@ -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'],
@@ -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}`))
README.md
@@ -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.