fix(nuxt): allow scanning metadata from 2+ files at same path (#29969)

This commit is contained in:
Daniel Roe 2024-11-19 12:00:57 +00:00 committed by GitHub
parent da9218da84
commit e87f6d3057
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -77,8 +77,8 @@ export async function resolvePagesRoutes (): Promise<NuxtPage[]> {
} else {
const augmentedPages = await augmentPages(pages, nuxt.vfs)
await nuxt.callHook('pages:extend', pages)
await augmentPages(pages, nuxt.vfs, augmentedPages)
augmentedPages.clear()
await augmentPages(pages, nuxt.vfs, { pagesToSkip: augmentedPages })
augmentedPages?.clear()
}
await nuxt.callHook('pages:resolved', pages)
@ -155,9 +155,14 @@ export function generateRoutesFromFiles (files: ScannedFile[], options: Generate
return prepareRoutes(routes)
}
export async function augmentPages (routes: NuxtPage[], vfs: Record<string, string>, augmentedPages = new Set<string>()) {
interface AugmentPagesContext {
pagesToSkip?: Set<string>
augmentedPages?: Set<string>
}
export async function augmentPages (routes: NuxtPage[], vfs: Record<string, string>, ctx: AugmentPagesContext = {}) {
ctx.augmentedPages ??= new Set()
for (const route of routes) {
if (route.file && !augmentedPages.has(route.file)) {
if (route.file && !ctx.pagesToSkip?.has(route.file)) {
const fileContent = route.file in vfs ? vfs[route.file]! : fs.readFileSync(await resolvePath(route.file), 'utf-8')
const routeMeta = await getRouteMeta(fileContent, route.file)
if (route.meta) {
@ -165,14 +170,14 @@ export async function augmentPages (routes: NuxtPage[], vfs: Record<string, stri
}
Object.assign(route, routeMeta)
augmentedPages.add(route.file)
ctx.augmentedPages.add(route.file)
}
if (route.children && route.children.length > 0) {
await augmentPages(route.children, vfs, augmentedPages)
await augmentPages(route.children, vfs, ctx)
}
}
return augmentedPages
return ctx.augmentedPages
}
const SFC_SCRIPT_RE = /<script(?<attrs>[^>]*)>(?<content>[\s\S]*?)<\/script[^>]*>/gi