fix(update): cancelling interactive update

This commit is contained in:
Zoltan Kochan
2022-06-19 15:07:17 +03:00
parent 2a34b21ced
commit 949e84ba8f
2 changed files with 14 additions and 0 deletions

View File

@@ -0,0 +1,6 @@
---
"@pnpm/plugin-commands-installation": patch
"pnpm": patch
---
Don't crash when `pnpm update --interactive` is cancelled with Ctrl+c.

View File

@@ -6,6 +6,7 @@ import {
import { CompletionFunc } from '@pnpm/command'
import { FILTERING, OPTIONS, UNIVERSAL_OPTIONS } from '@pnpm/common-cli-options-help'
import { types as allTypes } from '@pnpm/config'
import { globalInfo } from '@pnpm/logger'
import matcher from '@pnpm/matcher'
import { outdatedDepsOfProjects } from '@pnpm/outdated'
import { prompt } from 'enquirer'
@@ -236,6 +237,13 @@ async function interactiveUpdate (
k () {
return this.up()
},
cancel () {
// By default, canceling the prompt via Ctrl+c throws an empty string.
// The custom cancel function prevents that behavior.
// Otherwise, pnpm CLI would print an error and confuse users.
// See related issue: https://github.com/enquirer/enquirer/issues/225
globalInfo('Update canceled')
},
} as any) as any // eslint-disable-line @typescript-eslint/no-explicit-any
return update(updateDependencies, opts)
}