mirror of
https://github.com/nuxt/nuxt.git
synced 2025-01-22 11:22:43 +00:00
perf(kit): run components compat check synchronously (#30685)
This commit is contained in:
parent
4cce6bf8d5
commit
7cceb25c16
@ -14,6 +14,11 @@ const builderMap = {
|
||||
'@nuxt/webpack-builder': 'webpack',
|
||||
}
|
||||
|
||||
export function checkNuxtVersion (version: string, nuxt: Nuxt = useNuxt()) {
|
||||
const nuxtVersion = getNuxtVersion(nuxt)
|
||||
return satisfies(normalizeSemanticVersion(nuxtVersion), version, { includePrerelease: true })
|
||||
}
|
||||
|
||||
/**
|
||||
* Check version constraints and return incompatibility issues as an array
|
||||
*/
|
||||
@ -23,7 +28,7 @@ export async function checkNuxtCompatibility (constraints: NuxtCompatibility, nu
|
||||
// Nuxt version check
|
||||
if (constraints.nuxt) {
|
||||
const nuxtVersion = getNuxtVersion(nuxt)
|
||||
if (!satisfies(normalizeSemanticVersion(nuxtVersion), constraints.nuxt, { includePrerelease: true })) {
|
||||
if (!checkNuxtVersion(constraints.nuxt, nuxt)) {
|
||||
issues.push({
|
||||
name: 'nuxt',
|
||||
message: `Nuxt version \`${constraints.nuxt}\` is required but currently using \`${nuxtVersion}\``,
|
||||
|
@ -1,16 +1,18 @@
|
||||
import { kebabCase, pascalCase } from 'scule'
|
||||
import type { Component, ComponentsDir } from '@nuxt/schema'
|
||||
import { useNuxt } from './context'
|
||||
import { assertNuxtCompatibility } from './compatibility'
|
||||
import { checkNuxtVersion } from './compatibility'
|
||||
import { logger } from './logger'
|
||||
import { MODE_RE } from './utils'
|
||||
|
||||
/**
|
||||
* Register a directory to be scanned for components and imported only when used.
|
||||
*/
|
||||
export async function addComponentsDir (dir: ComponentsDir, opts: { prepend?: boolean } = {}) {
|
||||
export function addComponentsDir (dir: ComponentsDir, opts: { prepend?: boolean } = {}) {
|
||||
const nuxt = useNuxt()
|
||||
await assertNuxtCompatibility({ nuxt: '>=2.13' }, nuxt)
|
||||
if (!checkNuxtVersion('>=2.13', nuxt)) {
|
||||
throw new Error(`\`addComponentsDir\` requires Nuxt 2.13 or higher.`)
|
||||
}
|
||||
nuxt.options.components ||= []
|
||||
dir.priority ||= 0
|
||||
nuxt.hook('components:dirs', (dirs) => { dirs[opts.prepend ? 'unshift' : 'push'](dir) })
|
||||
@ -23,9 +25,12 @@ export type AddComponentOptions = { name: string, filePath: string } & Partial<E
|
||||
/**
|
||||
* Register a component by its name and filePath.
|
||||
*/
|
||||
export async function addComponent (opts: AddComponentOptions) {
|
||||
export function addComponent (opts: AddComponentOptions) {
|
||||
const nuxt = useNuxt()
|
||||
await assertNuxtCompatibility({ nuxt: '>=2.13' }, nuxt)
|
||||
if (!checkNuxtVersion('>=2.13', nuxt)) {
|
||||
throw new Error(`\`addComponent\` requires Nuxt 2.13 or higher.`)
|
||||
}
|
||||
|
||||
nuxt.options.components ||= []
|
||||
|
||||
if (!opts.mode) {
|
||||
|
Loading…
Reference in New Issue
Block a user