diff --git a/packages/nuxt/src/core/schema.ts b/packages/nuxt/src/core/schema.ts index ea569c833e..ba86a510e2 100644 --- a/packages/nuxt/src/core/schema.ts +++ b/packages/nuxt/src/core/schema.ts @@ -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') } } }) diff --git a/packages/nuxt/src/core/templates.ts b/packages/nuxt/src/core/templates.ts index bef450ed9f..1d30448b83 100644 --- a/packages/nuxt/src/core/templates.ts +++ b/packages/nuxt/src/core/templates.ts @@ -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 cfg${index}`).join(', ')}]> +type IsAny = 0 extends 1 & T ? true : false type MergedAppConfig, Custom extends Record> = { [K in keyof Resolved]: K extends keyof Custom ? Custom[K] extends Record - ? Resolved[K] extends Record - ? MergedAppConfig + ? IsAny extends true + ? Resolved[K] + : Resolved[K] extends Record + ? MergedAppConfig + : Exclude : Exclude - : Exclude - : Resolved[K] + : Resolved[K] } declare module 'nuxt/schema' {