fix: global update should not fail if no packages are found (#8829)

ref #7898
This commit is contained in:
Zoltan Kochan
2024-12-04 10:47:38 +01:00
committed by GitHub
parent a724295578
commit b8bda0ac40
3 changed files with 21 additions and 0 deletions

View File

@@ -0,0 +1,6 @@
---
"@pnpm/plugin-commands-installation": patch
"pnpm": patch
---
`pnpm update --global` should not crash if there are no any global packages installed [#7898](https://github.com/pnpm/pnpm/issues/7898).

View File

@@ -171,6 +171,9 @@ export async function handler (
opts: UpdateCommandOptions,
params: string[] = []
): Promise<string | undefined> {
if (opts.global && opts.rootProjectManifest == null) {
return 'No global packages found'
}
if (opts.interactive) {
return interactiveUpdate(params, opts)
}

View File

@@ -7,6 +7,7 @@ import isWindows from 'is-windows'
import {
addDistTag,
execPnpm,
execPnpmSync,
} from '../utils'
test('global installation', async () => {
@@ -102,3 +103,14 @@ test('global update to latest', async () => {
const { default: isPositive } = await import(path.join(globalPrefix, 'node_modules/is-positive/package.json'))
expect(isPositive.version).toBe('3.1.0')
})
test('global update should not crash if there are no global packages', async () => {
prepare()
const global = path.resolve('..', 'global')
const pnpmHome = path.join(global, 'pnpm')
fs.mkdirSync(global)
const env = { [PATH_NAME]: pnpmHome, PNPM_HOME: pnpmHome, XDG_DATA_HOME: global }
expect(execPnpmSync(['update', '--global'], { env }).status).toBe(0)
})