From 085e00a4af9f92054cf31d39834d009009b758fd Mon Sep 17 00:00:00 2001 From: "Grigorii K. Shartsev" Date: Mon, 29 Apr 2024 18:26:54 +0200 Subject: [PATCH 1/7] feat: add `usePwsh` for PowerShell v7+ Signed-off-by: Grigorii K. Shartsev --- src/core.ts | 7 +++++++ src/globals.ts | 1 + test/index.test.js | 2 ++ 3 files changed, 10 insertions(+) diff --git a/src/core.ts b/src/core.ts index 907f511cc2..b0928bd40b 100644 --- a/src/core.ts +++ b/src/core.ts @@ -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;' diff --git a/src/globals.ts b/src/globals.ts index 5c85d97755..f3bd7ede29 100644 --- a/src/globals.ts +++ b/src/globals.ts @@ -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 diff --git a/test/index.test.js b/test/index.test.js index 20b4fe3d82..c5c9f0339f 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -22,6 +22,7 @@ import { cd, syncProcessCwd, usePowerShell, + usePwsh, useBash, kill, ProcessOutput, @@ -69,6 +70,7 @@ describe('index', () => { assert(defaults) assert(within) assert(usePowerShell) + assert(usePwsh) assert(useBash) // goods From 2b6b9bb8d7ed986b80469566813ece1f54b46cb7 Mon Sep 17 00:00:00 2001 From: "Grigorii K. Shartsev" Date: Mon, 29 Apr 2024 18:27:23 +0200 Subject: [PATCH 2/7] test: add usePwsh smoke test Signed-off-by: Grigorii K. Shartsev --- test/smoke/win32.test.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/smoke/win32.test.js b/test/smoke/win32.test.js index 1b2c760a61..207845a541 100644 --- a/test/smoke/win32.test.js +++ b/test/smoke/win32.test.js @@ -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. @@ -38,4 +41,13 @@ _describe('win32', () => { assert.match(p.stdout, /Windows 'rulez!'/) }) }) + + _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'!/) + }) + }) }) From 7aa436c97926df694969a0cea3e992767713a0d2 Mon Sep 17 00:00:00 2001 From: "Grigorii K. Shartsev" Date: Mon, 29 Apr 2024 22:30:58 +0200 Subject: [PATCH 3/7] test: add `usePwsh` unit test Signed-off-by: Grigorii K. Shartsev --- test/core.test.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/test/core.test.js b/test/core.test.js index d850617d47..7de0863636 100644 --- a/test/core.test.js +++ b/test/core.test.js @@ -18,7 +18,7 @@ import { inspect } from 'node:util' import { basename } from 'node:path' import { Readable, Writable } from 'node:stream' import { Socket } from 'node:net' -import { ProcessPromise, ProcessOutput } from '../build/index.js' +import { ProcessPromise, ProcessOutput, quotePowerShell } from '../build/index.js' import '../build/globals.js' describe('core', () => { @@ -583,4 +583,15 @@ describe('core', () => { } assert.ok(ok, 'Expected failure!') }) + + test('usePwsh() sets proper defaults', () => { + const originalWhichSync = which.sync + which.sync = bin => bin === 'pwsh' ? 'pwsh' : originalWhichSync(bin) + usePwsh() + assert.equal($.shell, 'pwsh') + assert.equal($.prefix, '') + assert.equal($.postfix, '; exit $LastExitCode') + assert.equal($.quote, quotePowerShell) + which.sync = originalWhichSync + }) }) From 25dc9b70874d451036a92210993933542e84ace3 Mon Sep 17 00:00:00 2001 From: "Grigorii K. Shartsev" Date: Tue, 30 Apr 2024 11:08:50 +0200 Subject: [PATCH 4/7] fixup! test: add usePwsh smoke test Signed-off-by: Grigorii K. Shartsev --- test/smoke/win32.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/smoke/win32.test.js b/test/smoke/win32.test.js index 207845a541..025604b84f 100644 --- a/test/smoke/win32.test.js +++ b/test/smoke/win32.test.js @@ -14,8 +14,8 @@ import assert from 'node:assert' import { test, describe } from 'node:test' -import which from 'which' import '../../build/globals.js' +import { which } from '../../build/vendor.js' const _describe = process.platform === 'win32' ? describe : describe.skip From 83d5c900fd429734a1cc64466caf2571e9bb9900 Mon Sep 17 00:00:00 2001 From: "Grigorii K. Shartsev" Date: Tue, 30 Apr 2024 11:09:16 +0200 Subject: [PATCH 5/7] fixup! test: add `usePwsh` unit test Signed-off-by: Grigorii K. Shartsev --- test/core.test.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/core.test.js b/test/core.test.js index 7de0863636..40bf27c8a5 100644 --- a/test/core.test.js +++ b/test/core.test.js @@ -18,7 +18,7 @@ import { inspect } from 'node:util' import { basename } from 'node:path' import { Readable, Writable } from 'node:stream' import { Socket } from 'node:net' -import { ProcessPromise, ProcessOutput, quotePowerShell } from '../build/index.js' +import { ProcessPromise, ProcessOutput } from '../build/index.js' import '../build/globals.js' describe('core', () => { @@ -593,5 +593,6 @@ describe('core', () => { assert.equal($.postfix, '; exit $LastExitCode') assert.equal($.quote, quotePowerShell) which.sync = originalWhichSync + useBash() }) }) From 0209e1a965182511cb7c8f4d5411dfdd92598c59 Mon Sep 17 00:00:00 2001 From: "Grigorii K. Shartsev" Date: Tue, 30 Apr 2024 12:10:45 +0200 Subject: [PATCH 6/7] fixup! test: add `usePwsh` unit test Signed-off-by: Grigorii K. Shartsev --- test/core.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/core.test.js b/test/core.test.js index 40bf27c8a5..8fd08c4903 100644 --- a/test/core.test.js +++ b/test/core.test.js @@ -586,7 +586,7 @@ describe('core', () => { test('usePwsh() sets proper defaults', () => { const originalWhichSync = which.sync - which.sync = bin => bin === 'pwsh' ? 'pwsh' : originalWhichSync(bin) + which.sync = (bin) => (bin === 'pwsh' ? 'pwsh' : originalWhichSync(bin)) usePwsh() assert.equal($.shell, 'pwsh') assert.equal($.prefix, '') From 866ebdb179c0e13be9e5af8cdbe66bda160e0213 Mon Sep 17 00:00:00 2001 From: "Grigorii K. Shartsev" Date: Tue, 30 Apr 2024 14:38:33 +0200 Subject: [PATCH 7/7] fixup! test: add usePwsh smoke test Signed-off-by: Grigorii K. Shartsev --- test/smoke/win32.test.js | 1 - 1 file changed, 1 deletion(-) diff --git a/test/smoke/win32.test.js b/test/smoke/win32.test.js index 025604b84f..20cfff3e7b 100644 --- a/test/smoke/win32.test.js +++ b/test/smoke/win32.test.js @@ -15,7 +15,6 @@ import assert from 'node:assert' import { test, describe } from 'node:test' import '../../build/globals.js' -import { which } from '../../build/vendor.js' const _describe = process.platform === 'win32' ? describe : describe.skip