fix(nuxt): pass nuxt instance to resolvePagesRoutes

This commit is contained in:
Daniel Roe 2024-12-29 23:18:55 +00:00
parent e70ef00e55
commit 2b49c5b936
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 return true
} }
const pages = await resolvePagesRoutes() const pages = await resolvePagesRoutes(nuxt)
if (pages.length) { if (pages.length) {
if (nuxt.apps.default) { if (nuxt.apps.default) {
nuxt.apps.default.pages = pages nuxt.apps.default.pages = pages
@ -93,7 +93,7 @@ export default defineNuxtModule({
} }
nuxt.hook('app:templates', async (app) => { 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')) { 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`.') logger.warn('Using server pages with `ssr: false` is not supported with auto-detected component islands. Set `experimental.componentIslands` to `true`.')
@ -178,7 +178,7 @@ export default defineNuxtModule({
logs: nuxt.options.debug, logs: nuxt.options.debug,
async beforeWriteFiles (rootPage) { async beforeWriteFiles (rootPage) {
rootPage.children.forEach(child => child.delete()) 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) { if (nuxt.apps.default) {
nuxt.apps.default.pages = pages nuxt.apps.default.pages = pages
} }

View File

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