fix(setup): update the current shell, not the preferred one (#4701)

ref #4658
This commit is contained in:
Zoltan Kochan
2022-05-09 17:06:52 +03:00
committed by GitHub
parent 7c9362d3dc
commit 71c7ed9980
2 changed files with 14 additions and 1 deletions

View File

@@ -0,0 +1,6 @@
---
"@pnpm/plugin-commands-setup": patch
"pnpm": patch
---
`pnpm setup` should update the config of the current shell, not the preferred shell.

View File

@@ -50,7 +50,7 @@ export async function handler (
pnpmHomeDir: string
}
) {
const currentShell = typeof process.env.SHELL === 'string' ? path.basename(process.env.SHELL) : null
const currentShell = detectCurrentShell()
const execPath = getExecPath()
if (execPath.match(/\.[cm]?js$/) == null) {
copyCli(execPath, opts.pnpmHomeDir)
@@ -61,6 +61,13 @@ export async function handler (
Setup complete. Open a new terminal to start using pnpm.`
}
function detectCurrentShell () {
if (process.env.ZSH_VERSION) return 'zsh'
if (process.env.BASH_VERSION) return 'bash'
if (process.env.FISH_VERSION) return 'fish'
return typeof process.env.SHELL === 'string' ? path.basename(process.env.SHELL) : null
}
async function updateShell (currentShell: string | null, pnpmHomeDir: string): Promise<string> {
switch (currentShell) {
case 'bash': {