Skip to content

Commit

Permalink
fix: handle undefined env.SHELL (#657)
Browse files Browse the repository at this point in the history
* fix: test _shell function

* fix: allow for undefined env.SHELL for nix
  • Loading branch information
peternhale committed Mar 13, 2023
1 parent 0497ace commit 71fc49f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import {CompletableOptionFlag, Arg} from '../interfaces/parser'
import {stdout} from '../cli-ux/stream'
import {Performance} from '../performance'
import {settings} from '../settings'
import {userInfo as osUserInfo} from 'node:os'
import {sep} from 'node:path'

// eslint-disable-next-line new-cap
const debug = Debug()
Expand Down Expand Up @@ -550,7 +552,8 @@ export class Config implements IConfig {

protected _shell(): string {
let shellPath
const {SHELL, COMSPEC} = process.env
const COMSPEC = process.env.COMSPEC
const SHELL = process.env.SHELL ?? osUserInfo().shell?.split(sep)?.pop()
if (SHELL) {
shellPath = SHELL.split('/')
} else if (this.windows && COMSPEC) {
Expand Down
14 changes: 14 additions & 0 deletions test/config/config.shell.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import {expect} from 'chai'
import {Config} from '../../src'
import {userInfo as osUserInfo} from 'node:os'
import {sep} from 'node:path'

const getShell = () => osUserInfo().shell?.split(sep)?.pop() || 'unknown'

describe('config shell', () => {
it('has a default shell', () => {
const config = new Config({root: '/tmp'})
// @ts-ignore
expect(config._shell()).to.equal(getShell(), `SHELL: ${process.env.SHELL} COMSPEC: ${process.env.COMSPEC}`)
})
})

0 comments on commit 71fc49f

Please sign in to comment.