feat(kit): add new isNuxtMajorVersion compatibility util (#27579)

This commit is contained in:
Lucie 2024-06-21 00:20:49 +02:00 committed by GitHub
parent a4fc866d1c
commit 2475ee81cc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -81,19 +81,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) 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()) { export function isNuxt3 (nuxt: Nuxt = useNuxt()) {
const version = getNuxtVersion(nuxt) return isNuxtMajorVersion(3, nuxt)
return version[0] === '3' && version[1] === '.'
} }
/** /**