mirror of
https://github.com/pnpm/pnpm.git
synced 2026-07-25 15:07:06 -04:00
fix(env): fail with a meaningful error when no pnpm home dir is found (#6134)
close #6095 close #3865
This commit is contained in:
6
.changeset/shy-drinks-beam.md
Normal file
6
.changeset/shy-drinks-beam.md
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
"@pnpm/plugin-commands-env": patch
|
||||
"pnpm": patch
|
||||
---
|
||||
|
||||
`pnpm env -g` should fail with a meaningful error message if pnpm cannot find the pnpm home directory, which is the directory into which Node.js is installed.
|
||||
5
env/plugin-commands-env/src/env.ts
vendored
5
env/plugin-commands-env/src/env.ts
vendored
@@ -87,6 +87,11 @@ export async function handler (opts: NvmNodeCommandOptions, params: string[]) {
|
||||
hint: help(),
|
||||
})
|
||||
}
|
||||
if (opts.global && !opts.bin) {
|
||||
throw new PnpmError('CANNOT_MANAGE_NODE', 'Unable to manage Node.js because pnpm was not installed using the standalon installation script', {
|
||||
hint: 'If you want to manage Node.js with pnpm, you need to remove any Node.js that was installed by other tools, then install pnpm using one of the standalone scripts that are provided on the installation page: https://pnpm.io/installation',
|
||||
})
|
||||
}
|
||||
switch (params[0]) {
|
||||
case 'use': {
|
||||
return envUse(opts, params.slice(1))
|
||||
|
||||
14
env/plugin-commands-env/test/env.test.ts
vendored
14
env/plugin-commands-env/test/env.test.ts
vendored
@@ -265,3 +265,17 @@ describe('env list', () => {
|
||||
expect(versions.every(version => semver.satisfies(version, '16'))).toBeTruthy()
|
||||
})
|
||||
})
|
||||
|
||||
test('fail if there is no global bin directory', async () => {
|
||||
tempDir()
|
||||
|
||||
await expect(
|
||||
env.handler({
|
||||
// @ts-expect-error
|
||||
bin: undefined,
|
||||
global: true,
|
||||
pnpmHomeDir: process.cwd(),
|
||||
rawConfig: {},
|
||||
}, ['use', 'lts'])
|
||||
).rejects.toEqual(new PnpmError('CANNOT_MANAGE_NODE', 'Unable to manage Node.js because pnpm was not installed using the standalon installation script'))
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user