From 99c960fb05dafbf059a96e932a0f5df94421a68f Mon Sep 17 00:00:00 2001 From: Harlan Wilton Date: Wed, 17 Aug 2022 23:45:45 +1000 Subject: [PATCH] fix(nuxi): properly detect hash and tag for upgrade changelog (#6708) --- packages/nuxi/src/commands/upgrade.ts | 6 +++--- packages/nuxi/src/utils/nuxt.ts | 10 ++++++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/packages/nuxi/src/commands/upgrade.ts b/packages/nuxi/src/commands/upgrade.ts index 34465f82cf..2a39cb3e70 100644 --- a/packages/nuxi/src/commands/upgrade.ts +++ b/packages/nuxi/src/commands/upgrade.ts @@ -4,7 +4,7 @@ import { resolve } from 'pathe' import { readPackageJSON } from 'pkg-types' import { getPackageManager, packageManagerLocks } from '../utils/packageManagers' import { rmRecursive, touchFile } from '../utils/fs' -import { cleanupNuxtDirs } from '../utils/nuxt' +import { cleanupNuxtDirs, nuxtVersionToGitIdentifier } from '../utils/nuxt' import { defineNuxtCommand } from './index' async function getNuxtVersion (path: string): Promise { @@ -64,8 +64,8 @@ export default defineNuxtCommand({ consola.success('You\'re already using the latest version of nuxt.') } else { consola.success('Successfully upgraded nuxt from', currentVersion, 'to', upgradedVersion) - const commitA = currentVersion.split('.').pop() - const commitB = upgradedVersion.split('.').pop() + const commitA = nuxtVersionToGitIdentifier(currentVersion) + const commitB = nuxtVersionToGitIdentifier(upgradedVersion) if (commitA && commitB) { consola.info('Changelog:', `https://github.com/nuxt/framework/compare/${commitA}...${commitB}`) } diff --git a/packages/nuxi/src/utils/nuxt.ts b/packages/nuxi/src/utils/nuxt.ts index 12f7c452c0..d24a7c8951 100644 --- a/packages/nuxi/src/utils/nuxt.ts +++ b/packages/nuxi/src/utils/nuxt.ts @@ -27,6 +27,16 @@ export async function cleanupNuxtDirs (rootDir: string) { ].map(dir => resolve(rootDir, dir))) } +export function nuxtVersionToGitIdentifier (version: string) { + // match the git identifier in the release, for example: 3.0.0-rc.8-27677607.a3a8706 + const id = /\.([0-9a-f]{7})$/.exec(version) + if (id?.[1]) { + return id[1] + } + // match github tag, for example 3.0.0-rc.8 + return `v${version}` +} + export function resolveNuxtManifest (nuxt: Nuxt): NuxtProjectManifest { const manifest: NuxtProjectManifest = { _hash: null,