Commit ca3bb18

Anton Medvedev <anton@medv.io>
2022-10-07 22:19:00
Always try bash first
1 parent 4883e84
src/globals.ts
@@ -35,6 +35,8 @@ declare global {
   var path: typeof _.path
   var question: typeof _.question
   var quiet: typeof _.quiet
+  var quote: typeof _.quote
+  var quotePowerShell: typeof _.quotePowerShell
   var sleep: typeof _.sleep
   var stdin: typeof _.stdin
   var which: typeof _.which
src/index.ts
@@ -43,7 +43,7 @@ export {
   YAML,
 } from './goods.js'
 
-export { Duration } from './util.js'
+export { Duration, quote, quotePowerShell } from './util.js'
 
 /**
  *  @deprecated Use $.nothrow() instead.
test/win32.test.js
@@ -22,13 +22,23 @@ $.verbose = false
 
 if (process.platform === 'win32') {
   test('should work with windows-specific commands', async () => {
-    const p = await $`get-host`
-    assert.match(p.stdout, /PowerShell/)
+    const p = await $`echo $0` // Bash is first by default.
+    assert.match(p.stdout, /bash/)
+    await within(async () => {
+      $.shell = which.sync('powershell.exe')
+      $.quote = quotePowerShell
+      const p = await $`get-host`
+      assert.match(p.stdout, /PowerShell/)
+    })
   })
 
   test('quotePowerShell works', async () => {
-    const p = await $`echo ${`Windows 'rulez!'`}`
-    assert.match(p.stdout, /Windows 'rulez!'/)
+    await within(async () => {
+      $.shell = which.sync('powershell.exe')
+      $.quote = quotePowerShell
+      const p = await $`echo ${`Windows 'rulez!'`}`
+      assert.match(p.stdout, /Windows 'rulez!'/)
+    })
   })
 }
 
test-d/globals.test-d.ts
@@ -23,3 +23,6 @@ expectType<ProcessPromise>(p)
 let o = await p
 assert(o instanceof ProcessOutput)
 expectType<ProcessOutput>(o)
+
+expectType<string>(quote('foo'))
+expectType<string>(quotePowerShell('foo'))