fix(nuxt): pass nuxt instance to resolvePagesRoutes

This commit is contained in:
Daniel Roe 2024-12-29 23:18:55 +00:00
parent 8e2ca5bdc2
commit e4a372e12c
No known key found for this signature in database
GPG Key ID: CBC814C393D93268
2 changed files with 4 additions and 6 deletions

View File

@ -75,7 +75,7 @@ export default defineNuxtModule({
return true
}
const pages = await resolvePagesRoutes()
const pages = await resolvePagesRoutes(nuxt)
if (pages.length) {
if (nuxt.apps.default) {
nuxt.apps.default.pages = pages
@ -93,7 +93,7 @@ export default defineNuxtModule({
}
nuxt.hook('app:templates', async (app) => {
app.pages = await resolvePagesRoutes()
app.pages = await resolvePagesRoutes(nuxt)
if (!nuxt.options.ssr && app.pages.some(p => p.mode === 'server')) {
logger.warn('Using server pages with `ssr: false` is not supported with auto-detected component islands. Set `experimental.componentIslands` to `true`.')
@ -173,7 +173,7 @@ export default defineNuxtModule({
logs: nuxt.options.debug,
async beforeWriteFiles (rootPage) {
rootPage.children.forEach(child => child.delete())
const pages = nuxt.apps.default?.pages || await resolvePagesRoutes()
const pages = nuxt.apps.default?.pages || await resolvePagesRoutes(nuxt)
if (nuxt.apps.default) {
nuxt.apps.default.pages = pages
}

View File

@ -42,9 +42,7 @@ interface ScannedFile {
absolutePath: string
}
export async function resolvePagesRoutes (): Promise<NuxtPage[]> {
const nuxt = useNuxt()
export async function resolvePagesRoutes (nuxt = useNuxt()): Promise<NuxtPage[]> {
const pagesDirs = nuxt.options._layers.map(
layer => resolve(layer.config.srcDir, (layer.config.rootDir === nuxt.options.rootDir ? nuxt.options : layer.config).dir?.pages || 'pages'),
)