mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-26 07:32:01 +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: 'nuxt-config-schema' })
|
||||||
ctx.references.push({ path: 'schema/nuxt.schema.d.ts' })
|
ctx.references.push({ path: 'schema/nuxt.schema.d.ts' })
|
||||||
if (nuxt.options._prepare) {
|
if (nuxt.options._prepare) {
|
||||||
await nuxt.hooks.callHook('schema:beforeWrite', schema)
|
|
||||||
await writeSchema(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
|
// Write schema after build to allow further modifications
|
||||||
nuxt.hooks.hook('build:done', async () => {
|
nuxt.hooks.hook('build:done', () => writeSchema(schema))
|
||||||
await nuxt.hooks.callHook('schema:beforeWrite', schema)
|
|
||||||
await writeSchema(schema)
|
|
||||||
await nuxt.hooks.callHook('schema:written')
|
|
||||||
})
|
|
||||||
|
|
||||||
// Watch for schema changes in development mode
|
// Watch for schema changes in development mode
|
||||||
if (nuxt.options.dev) {
|
if (nuxt.options.dev) {
|
||||||
@ -72,9 +66,7 @@ export default defineNuxtModule({
|
|||||||
})
|
})
|
||||||
const onChange = debounce(async () => {
|
const onChange = debounce(async () => {
|
||||||
schema = await resolveSchema()
|
schema = await resolveSchema()
|
||||||
await nuxt.hooks.callHook('schema:beforeWrite', schema)
|
|
||||||
await writeSchema(schema)
|
await writeSchema(schema)
|
||||||
await nuxt.hooks.callHook('schema:written')
|
|
||||||
})
|
})
|
||||||
watcher.on('all', onChange)
|
watcher.on('all', onChange)
|
||||||
nuxt.hook('close', () => watcher.close())
|
nuxt.hook('close', () => watcher.close())
|
||||||
@ -126,6 +118,7 @@ export default defineNuxtModule({
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function writeSchema (schema: Schema) {
|
async function writeSchema (schema: Schema) {
|
||||||
|
await nuxt.hooks.callHook('schema:beforeWrite', schema)
|
||||||
// Write it to build dir
|
// Write it to build dir
|
||||||
await mkdir(resolve(nuxt.options.buildDir, 'schema'), { recursive: true })
|
await mkdir(resolve(nuxt.options.buildDir, 'schema'), { recursive: true })
|
||||||
await writeFile(
|
await writeFile(
|
||||||
@ -161,6 +154,7 @@ declare module 'nuxt/schema' {
|
|||||||
'schema/nuxt.schema.d.ts'
|
'schema/nuxt.schema.d.ts'
|
||||||
)
|
)
|
||||||
await writeFile(typesPath, types, 'utf8')
|
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)}
|
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 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>> = {
|
type MergedAppConfig<Resolved extends Record<string, any>, Custom extends Record<string, any>> = {
|
||||||
[K in keyof Resolved]: K extends keyof Custom
|
[K in keyof Resolved]: K extends keyof Custom
|
||||||
? Custom[K] extends Record<string, any>
|
? Custom[K] extends Record<string, any>
|
||||||
? Resolved[K] extends Record<string, any>
|
? IsAny<Custom[K]> extends true
|
||||||
? MergedAppConfig<Resolved[K], Custom[K]>
|
? 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>
|
||||||
: Exclude<Custom[K], undefined>
|
: Resolved[K]
|
||||||
: Resolved[K]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
declare module 'nuxt/schema' {
|
declare module 'nuxt/schema' {
|
||||||
|
Loading…
Reference in New Issue
Block a user