mirror of
https://github.com/pnpm/pnpm.git
synced 2025-12-24 23:58:07 -05:00
fix: global update should not fail if no packages are found (#8829)
ref #7898
This commit is contained in:
6
.changeset/old-kings-wait.md
Normal file
6
.changeset/old-kings-wait.md
Normal 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).
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user