mirror of
https://github.com/nuxt/nuxt.git
synced 2025-02-25 10:08:29 +00:00
fix(nuxt): set nuxt.options.pages
to detected configuration (#31101)
This commit is contained in:
parent
69c740383c
commit
cb80715c1a
@ -47,11 +47,12 @@ export default defineNuxtModule({
|
|||||||
configKey: 'pages',
|
configKey: 'pages',
|
||||||
},
|
},
|
||||||
defaults: nuxt => ({
|
defaults: nuxt => ({
|
||||||
enabled: undefined as undefined | boolean,
|
enabled: typeof nuxt.options.pages === 'boolean' ? nuxt.options.pages : undefined as undefined | boolean,
|
||||||
pattern: `**/*{${nuxt.options.extensions.join(',')}}` as string | string[],
|
pattern: `**/*{${nuxt.options.extensions.join(',')}}` as string | string[],
|
||||||
}),
|
}),
|
||||||
async setup (_options, nuxt) {
|
async setup (_options, nuxt) {
|
||||||
const options = typeof _options === 'boolean' ? { enabled: _options, pattern: `**/*{${nuxt.options.extensions.join(',')}}` } : _options
|
const options = typeof _options === 'boolean' ? { enabled: _options ?? nuxt.options.pages, pattern: `**/*{${nuxt.options.extensions.join(',')}}` } : { ..._options }
|
||||||
|
options.pattern = Array.isArray(options.pattern) ? [...new Set(options.pattern)] : options.pattern
|
||||||
|
|
||||||
const useExperimentalTypedPages = nuxt.options.experimental.typedPages
|
const useExperimentalTypedPages = nuxt.options.experimental.typedPages
|
||||||
const builtInRouterOptions = await findPath(resolve(runtimeDir, 'router.options')) || resolve(runtimeDir, 'router.options')
|
const builtInRouterOptions = await findPath(resolve(runtimeDir, 'router.options')) || resolve(runtimeDir, 'router.options')
|
||||||
@ -95,6 +96,7 @@ export default defineNuxtModule({
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
options.enabled = await isPagesEnabled()
|
options.enabled = await isPagesEnabled()
|
||||||
|
nuxt.options.pages = options
|
||||||
|
|
||||||
if (nuxt.options.dev && options.enabled) {
|
if (nuxt.options.dev && options.enabled) {
|
||||||
// Add plugin to check if pages are enabled without NuxtPage being instantiated
|
// Add plugin to check if pages are enabled without NuxtPage being instantiated
|
||||||
|
@ -4,6 +4,7 @@ import { normalize } from 'pathe'
|
|||||||
import { withoutTrailingSlash } from 'ufo'
|
import { withoutTrailingSlash } from 'ufo'
|
||||||
import { logger, tryUseNuxt, useNuxt } from '@nuxt/kit'
|
import { logger, tryUseNuxt, useNuxt } from '@nuxt/kit'
|
||||||
import { loadNuxt } from '../src'
|
import { loadNuxt } from '../src'
|
||||||
|
import type { NuxtConfig } from '../schema'
|
||||||
|
|
||||||
const repoRoot = withoutTrailingSlash(normalize(fileURLToPath(new URL('../../../', import.meta.url))))
|
const repoRoot = withoutTrailingSlash(normalize(fileURLToPath(new URL('../../../', import.meta.url))))
|
||||||
|
|
||||||
@ -107,3 +108,21 @@ describe('loadNuxt', () => {
|
|||||||
expect(loggerWarn).not.toHaveBeenCalled()
|
expect(loggerWarn).not.toHaveBeenCalled()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const pagesDetectionTests: [test: string, overrides: NuxtConfig, result: NuxtConfig['pages']][] = [
|
||||||
|
['pages dir', {}, { enabled: true }],
|
||||||
|
['pages dir empty', { dir: { pages: 'empty-dir' } }, { enabled: false }],
|
||||||
|
['user config', { pages: false }, { enabled: false }],
|
||||||
|
['user config', { pages: { enabled: false } }, { enabled: false }],
|
||||||
|
['user config', { pages: { enabled: true, pattern: '**/*{.vue}' } }, { enabled: true, pattern: '**/*{.vue}' }],
|
||||||
|
]
|
||||||
|
|
||||||
|
const pagesFixtureDir = withoutTrailingSlash(normalize(fileURLToPath(new URL('./pages-fixture', import.meta.url))))
|
||||||
|
describe('pages detection', () => {
|
||||||
|
it.each(pagesDetectionTests)('%s `%s`', async (_, overrides, result) => {
|
||||||
|
const nuxt = await loadNuxt({ cwd: pagesFixtureDir, overrides, ready: true })
|
||||||
|
// @ts-expect-error should resolve to object?
|
||||||
|
expect(nuxt.options.pages).toMatchObject(result)
|
||||||
|
await nuxt.close()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
1
packages/nuxt/test/pages-fixture/nuxt.config.ts
Normal file
1
packages/nuxt/test/pages-fixture/nuxt.config.ts
Normal file
@ -0,0 +1 @@
|
|||||||
|
export default defineNuxtConfig({})
|
3
packages/nuxt/test/pages-fixture/pages/index.vue
Normal file
3
packages/nuxt/test/pages-fixture/pages/index.vue
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
<template>
|
||||||
|
<div />
|
||||||
|
</template>
|
Loading…
Reference in New Issue
Block a user