From 9118965505342ebf5d2d7deafa184759b6cfcb53 Mon Sep 17 00:00:00 2001 From: Lucie <25330882+lihbr@users.noreply.github.com> Date: Fri, 21 Jun 2024 00:20:49 +0200 Subject: [PATCH] feat(kit): add new `isNuxtMajorVersion` compatibility util (#27579) --- packages/kit/src/compatibility.ts | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/packages/kit/src/compatibility.ts b/packages/kit/src/compatibility.ts index b554493f7d..51042f1463 100644 --- a/packages/kit/src/compatibility.ts +++ b/packages/kit/src/compatibility.ts @@ -98,19 +98,26 @@ export async function hasNuxtCompatibility (constraints: NuxtCompatibility, nuxt } /** - * Check if current nuxt instance is version 2 legacy + * Check if current Nuxt instance is of specified major version */ -export function isNuxt2 (nuxt: Nuxt = useNuxt()) { +export function isNuxtMajorVersion (majorVersion: 2 | 3 | 4, nuxt: Nuxt = useNuxt()) { const version = getNuxtVersion(nuxt) - return version[0] === '2' && version[1] === '.' + + return version[0] === majorVersion.toString() && version[1] === '.' } /** - * Check if current nuxt instance is version 3 + * @deprecated Use `isNuxtMajorVersion(2, nuxt)` instead. This may be removed in \@nuxt/kit v5 or a future major version. + */ +export function isNuxt2 (nuxt: Nuxt = useNuxt()) { + return isNuxtMajorVersion(2, nuxt) +} + +/** + * @deprecated Use `isNuxtMajorVersion(3, nuxt)` instead. This may be removed in \@nuxt/kit v5 or a future major version. */ export function isNuxt3 (nuxt: Nuxt = useNuxt()) { - const version = getNuxtVersion(nuxt) - return version[0] === '3' && version[1] === '.' + return isNuxtMajorVersion(3, nuxt) } /**