From c2638595b3ab67209cd69a9a3c423c978a4c54f4 Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Tue, 22 Oct 2024 14:22:42 +0100 Subject: [PATCH] fix(upgrade): handle aborted nightly channel selection --- src/commands/upgrade.ts | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/commands/upgrade.ts b/src/commands/upgrade.ts index 9c7a979d..a2e297b4 100644 --- a/src/commands/upgrade.ts +++ b/src/commands/upgrade.ts @@ -44,8 +44,13 @@ function hasPnpmWorkspaceFile(cwd: string): boolean { return existsSync(pnpmWorkspaceFilePath) } +const nuxtVersionTags = { + '3.x': '3x', + '4.x': 'latest', +} + async function getNightlyVersion(packageNames: string[]): Promise<{ npmPackages: string[], nuxtVersion: string }> { - const nuxtVersion = await consola.prompt( + const result = await consola.prompt( 'Which nightly Nuxt release channel do you want to install? (3.x or 4.x)', { type: 'select', @@ -54,11 +59,9 @@ async function getNightlyVersion(packageNames: string[]): Promise<{ npmPackages: }, ) as '3.x' | '4.x' - const versions = { - '3.x': '3x', - '4.x': 'latest', - } - const npmPackages = packageNames.map(p => `${p}@npm:${p}-nightly@${versions[nuxtVersion]}`) + const nuxtVersion = typeof result === 'string' ? result : '3.x' + + const npmPackages = packageNames.map(p => `${p}@npm:${p}-nightly@${nuxtVersionTags[nuxtVersion]}`) return { npmPackages, nuxtVersion } }