Skip to content

Commit

Permalink
fix(env): update aliases and error catching
Browse files Browse the repository at this point in the history
- Add `rm, un, uninstall` aliases to the `remove` command
- Update CLI help message
- Ignore only `ENOENT` errors
  • Loading branch information
mark-omarov committed Aug 27, 2022
1 parent f621290 commit 31e4d25
Showing 1 changed file with 32 additions and 9 deletions.
41 changes: 32 additions & 9 deletions packages/plugin-commands-env/src/env.ts
Expand Up @@ -25,13 +25,27 @@ export const commandNames = ['env']

export function help () {
return renderHelp({
description: 'Install and use the specified version of Node.js. The npm CLI bundled with the given Node.js version gets installed as well.',
description: 'Manage Node.js versions.',
descriptionLists: [
{
title: 'Commands',
list: [
{
description: 'Installs the specified version of Node.JS. The npm CLI bundled with the given Node.js version gets installed as well.',
name: 'use',
},
{
description: 'Uninstalls the specified version of Node.JS.',
name: 'remove\nuninstall',
shortAlias: 'rm,\nun',
},
],
},
{
title: 'Options',
list: [
{
description: 'Installs and uninstalls Node.js globally',
description: 'Manages Node.js versions globally',
name: '--global',
shortAlias: '-g',
},
Expand All @@ -46,11 +60,11 @@ export function help () {
'pnpm env use --global argon',
'pnpm env use --global latest',
'pnpm env use --global rc/16',
'pnpm env uninstall --global 16',
'pnpm env uninstall --global lts',
'pnpm env uninstall --global argon',
'pnpm env uninstall --global latest',
'pnpm env uninstall --global rc/16',
'pnpm env remove --global 16',
'pnpm env remove --global lts',
'pnpm env remove --global argon',
'pnpm env remove --global latest',
'pnpm env remove --global rc/16',
],
})
}
Expand Down Expand Up @@ -103,7 +117,10 @@ export async function handler (opts: NvmNodeCommandOptions, params: string[]) {
return `Node.js ${nodeVersion as string} is activated
${dest} -> ${src}`
}
case 'uninstall': {
case 'remove':
case 'rm':
case 'uninstall':
case 'un': {
if (!opts.global) {
throw new PnpmError('NOT_IMPLEMENTED_YET', '"pnpm env use <version>" can only be used with the "--global" option currently')
}
Expand Down Expand Up @@ -137,7 +154,13 @@ export async function handler (opts: NvmNodeCommandOptions, params: string[]) {
fs.unlink(nodePath),
fs.unlink(npmPath),
fs.unlink(npxPath),
])
]).catch(err => {
const { code = '' } = err

if (code.toLowerCase() !== 'enoent') {
throw err
}
})
}

const [processMajorVersion, processMinorVersion] = process.versions.node.split('.')
Expand Down

0 comments on commit 31e4d25

Please sign in to comment.