mirror of
https://github.com/nuxt/nuxt.git
synced 2025-01-18 09:25:54 +00:00
perf(nuxt): avoid checking fs for existence of scanned pages (#30581)
This commit is contained in:
parent
047a7be59e
commit
31077aeb83
@ -68,7 +68,10 @@ export async function resolvePagesRoutes (nuxt = useNuxt()): Promise<NuxtPage[]>
|
|||||||
return pages
|
return pages
|
||||||
}
|
}
|
||||||
|
|
||||||
const augmentCtx = { extraExtractionKeys: nuxt.options.experimental.extraPageMetaExtractionKeys }
|
const augmentCtx = {
|
||||||
|
extraExtractionKeys: nuxt.options.experimental.extraPageMetaExtractionKeys,
|
||||||
|
fullyResolvedPaths: new Set(scannedFiles.map(file => file.absolutePath)),
|
||||||
|
}
|
||||||
if (shouldAugment === 'after-resolve') {
|
if (shouldAugment === 'after-resolve') {
|
||||||
await nuxt.callHook('pages:extend', pages)
|
await nuxt.callHook('pages:extend', pages)
|
||||||
await augmentPages(pages, nuxt.vfs, augmentCtx)
|
await augmentPages(pages, nuxt.vfs, augmentCtx)
|
||||||
@ -154,6 +157,7 @@ export function generateRoutesFromFiles (files: ScannedFile[], options: Generate
|
|||||||
}
|
}
|
||||||
|
|
||||||
interface AugmentPagesContext {
|
interface AugmentPagesContext {
|
||||||
|
fullyResolvedPaths?: Set<string>
|
||||||
pagesToSkip?: Set<string>
|
pagesToSkip?: Set<string>
|
||||||
augmentedPages?: Set<string>
|
augmentedPages?: Set<string>
|
||||||
extraExtractionKeys?: string[]
|
extraExtractionKeys?: string[]
|
||||||
@ -163,7 +167,9 @@ export async function augmentPages (routes: NuxtPage[], vfs: Record<string, stri
|
|||||||
ctx.augmentedPages ??= new Set()
|
ctx.augmentedPages ??= new Set()
|
||||||
for (const route of routes) {
|
for (const route of routes) {
|
||||||
if (route.file && !ctx.pagesToSkip?.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 fileContent = route.file in vfs
|
||||||
|
? vfs[route.file]!
|
||||||
|
: fs.readFileSync(ctx.fullyResolvedPaths?.has(route.file) ? route.file : await resolvePath(route.file), 'utf-8')
|
||||||
const routeMeta = await getRouteMeta(fileContent, route.file, ctx.extraExtractionKeys)
|
const routeMeta = await getRouteMeta(fileContent, route.file, ctx.extraExtractionKeys)
|
||||||
if (route.meta) {
|
if (route.meta) {
|
||||||
routeMeta.meta = { ...routeMeta.meta, ...route.meta }
|
routeMeta.meta = { ...routeMeta.meta, ...route.meta }
|
||||||
|
Loading…
Reference in New Issue
Block a user