perf(kit): deduplicate layers before resolving config (#27582)

This commit is contained in:
Daniel Roe 2024-06-13 12:51:00 +01:00 committed by GitHub
parent c2f2627b99
commit d195930aae
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -42,10 +42,15 @@ export async function loadNuxtConfig (opts: LoadNuxtConfigOptions): Promise<Nuxt
nuxtConfig._nuxtConfigFiles = [configFile] nuxtConfig._nuxtConfigFiles = [configFile]
const _layers: ConfigLayer<NuxtConfig, ConfigLayerMeta>[] = [] const _layers: ConfigLayer<NuxtConfig, ConfigLayerMeta>[] = []
const processedLayers = new Set<string>()
for (const layer of layers) { for (const layer of layers) {
// Resolve `rootDir` & `srcDir` of layers // Resolve `rootDir` & `srcDir` of layers
layer.config = layer.config || {} layer.config = layer.config || {}
layer.config.rootDir = layer.config.rootDir ?? layer.cwd layer.config.rootDir = layer.config.rootDir ?? layer.cwd!
// Only process/resolve layers once
if (processedLayers.has(layer.config.rootDir)) { continue }
processedLayers.add(layer.config.rootDir)
// Normalise layer directories // Normalise layer directories
layer.config = await applyDefaults(layerSchema, layer.config as NuxtConfig & Record<string, JSValue>) as unknown as NuxtConfig layer.config = await applyDefaults(layerSchema, layer.config as NuxtConfig & Record<string, JSValue>) as unknown as NuxtConfig