diff --git a/docs/upgrade.md b/docs/upgrade.md index 5595c52b1..64f7537fa 100644 --- a/docs/upgrade.md +++ b/docs/upgrade.md @@ -10,13 +10,13 @@ links: ```bash [Terminal] -npx nuxt upgrade [ROOTDIR] [--cwd=] [--logLevel=] [--dedupe] [-f, --force] [-ch, --channel=] +npx nuxt upgrade [ROOTDIR] [--cwd=] [--logLevel=] [--dedupe] [-f, --force] [-ch, --channel=] ``` The `upgrade` command upgrades Nuxt to the latest version. It updates the version in your [`package.json`](/docs/directory-structure/package), reinstalls dependencies with your package manager and removes the build cache. -`--channel` picks what to upgrade to: `stable` for the latest release, `v3` or `v4` to stay on a major, and `nightly`, `v3-nightly` or `v4-nightly` for the nightly release channel. +`--channel` picks what to upgrade to: `stable` for the latest release, `v4` to stay on a major, and `nightly`, `v4-nightly` or `v5-nightly` for the nightly release channel. `--force` recreates the lockfile and `node_modules` from scratch, and `--dedupe` deduplicates dependencies afterwards where the package manager supports it. @@ -33,11 +33,11 @@ A dependency pinned to a pnpm catalog (`"nuxt": "catalog:"`) is upgraded in `pnp ## Options -| Option | Default | Description | -|--------------------------------------------------------------------|----------|-----------------------------------------------------| -| `--cwd=` | | Specify the root directory of your Nuxt project | -| `--logLevel=` | | Specify build-time log level | -| `--dedupe` | | Dedupe dependencies after upgrading | -| `-f, --force` | | Force upgrade to recreate lockfile and node_modules | -| `-ch, --channel=` | `stable` | Specify a channel to install from | +| Option | Default | Description | +|----------------------------------------------------------------|----------|-----------------------------------------------------| +| `--cwd=` | | Specify the root directory of your Nuxt project | +| `--logLevel=` | | Specify build-time log level | +| `--dedupe` | | Dedupe dependencies after upgrading | +| `-f, --force` | | Force upgrade to recreate lockfile and node_modules | +| `-ch, --channel=` | `stable` | Specify a channel to install from | diff --git a/packages/nuxt-cli/src/commands/upgrade.ts b/packages/nuxt-cli/src/commands/upgrade.ts index 3ae567c73..9a671670e 100644 --- a/packages/nuxt-cli/src/commands/upgrade.ts +++ b/packages/nuxt-cli/src/commands/upgrade.ts @@ -95,7 +95,8 @@ export async function resolveCatalogSpecifier(spec: InstallSpec, current?: strin const nuxtVersionTags = { '3.x': '3x', - '4.x': 'latest', + '4.x': '4x', + '5.x': '5x', } type NuxtVersionTag = keyof typeof nuxtVersionTags @@ -108,8 +109,8 @@ async function getNightlyVersion(packageNames: string[]): Promise<{ npmPackages: const nuxtVersion = await select({ message: 'Which nightly Nuxt release channel do you want to install?', options: [ - { value: '3.x' as const, label: '3.x' }, { value: '4.x' as const, label: '4.x' }, + { value: '5.x' as const, label: '5.x' }, ], initialValue: '4.x' as const, }) @@ -130,12 +131,14 @@ async function getRequiredNewVersion(packageNames: string[], channel: string): P return getNightlyVersion(packageNames) case 'v3': return { npmPackages: packageNames.map(p => `${p}@3`), nuxtVersion: '3.x' } - case 'v3-nightly': - return { npmPackages: packageNames.map(p => getNightlyDependency(p, '3.x')), nuxtVersion: '3.x' } case 'v4': return { npmPackages: packageNames.map(p => `${p}@4`), nuxtVersion: '4.x' } + case 'v3-nightly': + return { npmPackages: packageNames.map(p => getNightlyDependency(p, '3.x')), nuxtVersion: '3.x' } case 'v4-nightly': return { npmPackages: packageNames.map(p => getNightlyDependency(p, '4.x')), nuxtVersion: '4.x' } + case 'v5-nightly': + return { npmPackages: packageNames.map(p => getNightlyDependency(p, '5.x')), nuxtVersion: '5.x' } case 'stable': default: return { npmPackages: packageNames.map(p => `${p}@latest`), nuxtVersion: '4.x' } @@ -164,7 +167,8 @@ export default defineCommand({ alias: 'ch', default: 'stable', description: 'Specify a channel to install from', - options: ['stable', 'nightly', 'v3', 'v4', 'v4-nightly', 'v3-nightly'], + options: ['stable', 'nightly', 'v3', 'v4', 'v3-nightly', 'v4-nightly', 'v5-nightly'], + valueHint: 'stable|nightly|v4|v4-nightly|v5-nightly', }, }, async run(ctx) { diff --git a/packages/nuxt-cli/test/unit/commands/upgrade-run.spec.ts b/packages/nuxt-cli/test/unit/commands/upgrade-run.spec.ts index 1463b3e67..5fc6c9b64 100644 --- a/packages/nuxt-cli/test/unit/commands/upgrade-run.spec.ts +++ b/packages/nuxt-cli/test/unit/commands/upgrade-run.spec.ts @@ -142,6 +142,27 @@ describe('upgrade install', () => { expect(runInstall).toHaveBeenCalledWith(expect.objectContaining({ dependencies: ['nuxt@3'] })) }) + it.each([ + ['v3-nightly', '3x'], + ['v4-nightly', '4x'], + ['v5-nightly', '5x'], + ])('should install the %s channel from the %s nightly dist-tag', async (channel, tag) => { + await runUpgrade([`--channel=${channel}`]) + + expect(runInstall).toHaveBeenCalledWith(expect.objectContaining({ dependencies: [`nuxt@npm:nuxt-nightly@${tag}`] })) + }) + + it.each([ + ['4.x', '4x'], + ['5.x', '5x'], + ])('should install the %s nightly picked from the prompt', async (answer, tag) => { + answers.select.push(answer) + + await runUpgrade(['--channel=nightly']) + + expect(runInstall).toHaveBeenCalledWith(expect.objectContaining({ dependencies: [`nuxt@npm:nuxt-nightly@${tag}`] })) + }) + it('should upgrade the core packages the project depends on', async () => { await writeProject({ 'package.json': JSON.stringify({ name: 'app', devDependencies: { 'nuxt': '^4.0.0', '@nuxt/kit': '^4.0.0' } }) }) diff --git a/packages/nuxt-cli/test/unit/help.spec.ts b/packages/nuxt-cli/test/unit/help.spec.ts index 5180522c8..92a463d5b 100644 --- a/packages/nuxt-cli/test/unit/help.spec.ts +++ b/packages/nuxt-cli/test/unit/help.spec.ts @@ -468,10 +468,10 @@ describe('help', () => { OPTIONS - --logLevel= Specify build-time log level - --dedupe Dedupe dependencies after upgrading - -f, --force Force upgrade to recreate lockfile and node_modules - -ch, --channel= Specify a channel to install from (Default: stable) + --logLevel= Specify build-time log level + --dedupe Dedupe dependencies after upgrading + -f, --force Force upgrade to recreate lockfile and node_modules + -ch, --channel= Specify a channel to install from (Default: stable) " `) })