From ffc0aa474af6c8d78747ffcff46036b6c8504200 Mon Sep 17 00:00:00 2001 From: Mike Donnalley Date: Mon, 8 Jul 2024 10:29:49 -0600 Subject: [PATCH 1/6] fix: correctly identify powershell --- src/config/config.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/config/config.ts b/src/config/config.ts index cf462431..8d702115 100644 --- a/src/config/config.ts +++ b/src/config/config.ts @@ -663,6 +663,10 @@ export class Config implements IConfig { const SHELL = process.env.SHELL ?? osUserInfo().shell?.split(sep)?.pop() if (SHELL) { shellPath = SHELL.split('/') + } else if (this.windows && process.title.toLowerCase().includes('powershell')) { + shellPath = ['pwsh'] + } else if (this.windows && process.title.toLowerCase().includes('command prompt')) { + shellPath = ['cmd.exe'] } else if (this.windows && COMSPEC) { shellPath = COMSPEC.split(/\\|\//) } else { From f2dd977518f3219bfa1acc8a4632c799f5dd33a3 Mon Sep 17 00:00:00 2001 From: Mike Donnalley Date: Mon, 8 Jul 2024 12:24:36 -0600 Subject: [PATCH 2/6] fix: check for powershell on non-windows os --- src/config/config.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/config/config.ts b/src/config/config.ts index 8d702115..76fc3286 100644 --- a/src/config/config.ts +++ b/src/config/config.ts @@ -659,12 +659,17 @@ export class Config implements IConfig { protected _shell(): string { let shellPath - const {COMSPEC} = process.env + const {COMSPEC, PSModulePath} = process.env const SHELL = process.env.SHELL ?? osUserInfo().shell?.split(sep)?.pop() if (SHELL) { shellPath = SHELL.split('/') + } else if (!this.windows && PSModulePath) { + // PSModulePath is always set in powershell, regardless of the OS + // We can't use this on windows though since both powershell and cmd.exe set it + // https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_environment_variables?view=powershell-7.4 + shellPath = ['powershell'] } else if (this.windows && process.title.toLowerCase().includes('powershell')) { - shellPath = ['pwsh'] + shellPath = ['powershell'] } else if (this.windows && process.title.toLowerCase().includes('command prompt')) { shellPath = ['cmd.exe'] } else if (this.windows && COMSPEC) { From e86ab39dce35a04f00b4a07d272080b6d3966e9a Mon Sep 17 00:00:00 2001 From: Mike Donnalley Date: Mon, 8 Jul 2024 13:11:27 -0600 Subject: [PATCH 3/6] test: windows shell test --- test/config/config.shell.test.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/config/config.shell.test.ts b/test/config/config.shell.test.ts index cb8ce96e..e589433d 100644 --- a/test/config/config.shell.test.ts +++ b/test/config/config.shell.test.ts @@ -4,7 +4,8 @@ import {sep} from 'node:path' import {Config} from '../../src' -const getShell = () => osUserInfo().shell?.split(sep)?.pop() || 'unknown' +const getShell = () => + osUserInfo().shell?.split(sep)?.pop() || process.platform === 'win32' ? 'powershell' : 'unknown' describe('config shell', () => { it('has a default shell', () => { From 67d72c61d7dcc6d86d2af28a158567a8e45f7bd0 Mon Sep 17 00:00:00 2001 From: Mike Donnalley Date: Mon, 8 Jul 2024 13:26:21 -0600 Subject: [PATCH 4/6] test: windows shell test --- test/config/config.shell.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/config/config.shell.test.ts b/test/config/config.shell.test.ts index e589433d..61d3337f 100644 --- a/test/config/config.shell.test.ts +++ b/test/config/config.shell.test.ts @@ -5,7 +5,7 @@ import {sep} from 'node:path' import {Config} from '../../src' const getShell = () => - osUserInfo().shell?.split(sep)?.pop() || process.platform === 'win32' ? 'powershell' : 'unknown' + osUserInfo().shell?.split(sep)?.pop() || (process.platform === 'win32' ? 'powershell' : 'unknown') describe('config shell', () => { it('has a default shell', () => { From 60cbf8acc16977db9f3b6948e5b794e0823f654e Mon Sep 17 00:00:00 2001 From: Mike Donnalley Date: Mon, 8 Jul 2024 13:37:06 -0600 Subject: [PATCH 5/6] chore: remove mac/linux powershell check --- src/config/config.ts | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/config/config.ts b/src/config/config.ts index 76fc3286..f21b1198 100644 --- a/src/config/config.ts +++ b/src/config/config.ts @@ -659,15 +659,10 @@ export class Config implements IConfig { protected _shell(): string { let shellPath - const {COMSPEC, PSModulePath} = process.env + const {COMSPEC} = process.env const SHELL = process.env.SHELL ?? osUserInfo().shell?.split(sep)?.pop() if (SHELL) { shellPath = SHELL.split('/') - } else if (!this.windows && PSModulePath) { - // PSModulePath is always set in powershell, regardless of the OS - // We can't use this on windows though since both powershell and cmd.exe set it - // https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_environment_variables?view=powershell-7.4 - shellPath = ['powershell'] } else if (this.windows && process.title.toLowerCase().includes('powershell')) { shellPath = ['powershell'] } else if (this.windows && process.title.toLowerCase().includes('command prompt')) { From c1aed1cea00240d898dfc04760a11e88c16006d2 Mon Sep 17 00:00:00 2001 From: Cristian Dominguez Date: Mon, 8 Jul 2024 19:03:43 -0300 Subject: [PATCH 6/6] test: load config --- test/config/config.shell.test.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/test/config/config.shell.test.ts b/test/config/config.shell.test.ts index 61d3337f..fcda9f02 100644 --- a/test/config/config.shell.test.ts +++ b/test/config/config.shell.test.ts @@ -8,8 +8,18 @@ const getShell = () => osUserInfo().shell?.split(sep)?.pop() || (process.platform === 'win32' ? 'powershell' : 'unknown') describe('config shell', () => { - it('has a default shell', () => { - const config = new Config({root: '/tmp'}) + it('has a default shell', async () => { + const config = new Config({ + root: '/tmp', + pjson: { + name: 'test-cli', + version: '0.0.1', + oclif: { + bin: 'test-cli', + }, + }, + }) + await config.load() // @ts-expect-error because _shell is private expect(config._shell()).to.equal(getShell(), `SHELL: ${process.env.SHELL} COMSPEC: ${process.env.COMSPEC}`) })