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: add usePwsh helper for PowerShell v7+ #790

Merged
merged 7 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,13 @@ export function usePowerShell() {
$.quote = quotePowerShell
}

export function usePwsh() {
$.shell = which.sync('pwsh')
$.prefix = ''
$.postfix = '; exit $LastExitCode'
$.quote = quotePowerShell
}

export function useBash() {
$.shell = which.sync('bash')
$.prefix = 'set -euo pipefail;'
Expand Down
1 change: 1 addition & 0 deletions src/globals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ declare global {
var quotePowerShell: typeof _.quotePowerShell
var retry: typeof _.retry
var usePowerShell: typeof _.usePowerShell
var usePwsh: typeof _.usePwsh
var useBash: typeof _.useBash
var sleep: typeof _.sleep
var spinner: typeof _.spinner
Expand Down
2 changes: 2 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
cd,
syncProcessCwd,
usePowerShell,
usePwsh,
useBash,
kill,
ProcessOutput,
Expand Down Expand Up @@ -69,6 +70,7 @@ describe('index', () => {
assert(defaults)
assert(within)
assert(usePowerShell)
assert(usePwsh)
assert(useBash)

// goods
Expand Down
12 changes: 12 additions & 0 deletions test/smoke/win32.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,13 @@

import assert from 'node:assert'
import { test, describe } from 'node:test'
import which from 'which'
import '../../build/globals.js'

const _describe = process.platform === 'win32' ? describe : describe.skip

const _testPwsh = which.sync('pwsh', { nothrow: true }) ? test : test.skip

_describe('win32', () => {
test('should work with windows-specific commands', async () => {
const p = await $`echo $0` // Bash is first by default.
Expand All @@ -38,4 +41,13 @@ _describe('win32', () => {
assert.match(p.stdout, /Windows 'rulez!'/)
})
})

ShGKme marked this conversation as resolved.
Show resolved Hide resolved
_testPwsh('should work with pwsh when it is available', async () => {
await within(async () => {
usePwsh()
assert.match($.shell, /pwsh/i)
const p = await $`echo 'Hello,' && echo ${`new 'PowerShell'!`}`
assert.match(p.stdout, /Hello,\s+new 'PowerShell'!/)
})
})
})
Loading