mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-22 13:45:18 +00:00
fix(nuxt): ignore schema types that eval to any (#19835)
This commit is contained in:
parent
fc7867fb0e
commit
9d8c230132
@ -42,9 +42,7 @@ export default defineNuxtModule({
|
||||
ctx.references.push({ path: 'nuxt-config-schema' })
|
||||
ctx.references.push({ path: 'schema/nuxt.schema.d.ts' })
|
||||
if (nuxt.options._prepare) {
|
||||
await nuxt.hooks.callHook('schema:beforeWrite', schema)
|
||||
await writeSchema(schema)
|
||||
await nuxt.hooks.callHook('schema:written')
|
||||
}
|
||||
})
|
||||
|
||||
@ -55,11 +53,7 @@ export default defineNuxtModule({
|
||||
})
|
||||
|
||||
// Write schema after build to allow further modifications
|
||||
nuxt.hooks.hook('build:done', async () => {
|
||||
await nuxt.hooks.callHook('schema:beforeWrite', schema)
|
||||
await writeSchema(schema)
|
||||
await nuxt.hooks.callHook('schema:written')
|
||||
})
|
||||
nuxt.hooks.hook('build:done', () => writeSchema(schema))
|
||||
|
||||
// Watch for schema changes in development mode
|
||||
if (nuxt.options.dev) {
|
||||
@ -72,9 +66,7 @@ export default defineNuxtModule({
|
||||
})
|
||||
const onChange = debounce(async () => {
|
||||
schema = await resolveSchema()
|
||||
await nuxt.hooks.callHook('schema:beforeWrite', schema)
|
||||
await writeSchema(schema)
|
||||
await nuxt.hooks.callHook('schema:written')
|
||||
})
|
||||
watcher.on('all', onChange)
|
||||
nuxt.hook('close', () => watcher.close())
|
||||
@ -126,6 +118,7 @@ export default defineNuxtModule({
|
||||
}
|
||||
|
||||
async function writeSchema (schema: Schema) {
|
||||
await nuxt.hooks.callHook('schema:beforeWrite', schema)
|
||||
// Write it to build dir
|
||||
await mkdir(resolve(nuxt.options.buildDir, 'schema'), { recursive: true })
|
||||
await writeFile(
|
||||
@ -161,6 +154,7 @@ declare module 'nuxt/schema' {
|
||||
'schema/nuxt.schema.d.ts'
|
||||
)
|
||||
await writeFile(typesPath, types, 'utf8')
|
||||
await nuxt.hooks.callHook('schema:written')
|
||||
}
|
||||
}
|
||||
})
|
||||
|
@ -204,15 +204,18 @@ ${app.configs.map((id: string, index: number) => `import ${`cfg${index}`} from $
|
||||
|
||||
declare const inlineConfig = ${JSON.stringify(nuxt.options.appConfig, null, 2)}
|
||||
type ResolvedAppConfig = Defu<typeof inlineConfig, [${app.configs.map((_id: string, index: number) => `typeof cfg${index}`).join(', ')}]>
|
||||
type IsAny<T> = 0 extends 1 & T ? true : false
|
||||
|
||||
type MergedAppConfig<Resolved extends Record<string, any>, Custom extends Record<string, any>> = {
|
||||
[K in keyof Resolved]: K extends keyof Custom
|
||||
? Custom[K] extends Record<string, any>
|
||||
? Resolved[K] extends Record<string, any>
|
||||
? MergedAppConfig<Resolved[K], Custom[K]>
|
||||
? IsAny<Custom[K]> extends true
|
||||
? Resolved[K]
|
||||
: Resolved[K] extends Record<string, any>
|
||||
? MergedAppConfig<Resolved[K], Custom[K]>
|
||||
: Exclude<Custom[K], undefined>
|
||||
: Exclude<Custom[K], undefined>
|
||||
: Exclude<Custom[K], undefined>
|
||||
: Resolved[K]
|
||||
: Resolved[K]
|
||||
}
|
||||
|
||||
declare module 'nuxt/schema' {
|
||||
|
Loading…
Reference in New Issue
Block a user