From d2ef3145f64bece25f5719cc26664fc6055677e7 Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Wed, 28 Aug 2024 22:19:20 +0100 Subject: [PATCH] fix(nuxt): augment `NuxtOptions` as well as config (#28747) --- packages/nuxt/src/core/templates.ts | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/packages/nuxt/src/core/templates.ts b/packages/nuxt/src/core/templates.ts index f4f5d4da8e..b02f650485 100644 --- a/packages/nuxt/src/core/templates.ts +++ b/packages/nuxt/src/core/templates.ts @@ -191,7 +191,7 @@ export const schemaTemplate: NuxtTemplate = { } } - const moduleOptionsInterface = (jsdocTags: boolean) => [ + const moduleOptionsInterface = (options: { addJSDocTags: boolean, unresolved: boolean }) => [ ...modules.flatMap(([configKey, importName, mod]) => { let link: string | undefined @@ -221,30 +221,32 @@ export const schemaTemplate: NuxtTemplate = { return [ ` /**`, ` * Configuration for \`${importName}\``, - ...jsdocTags && link - ? [ - ` * @see ${link}`, - ] - : [], + ...options.addJSDocTags && link ? [` * @see ${link}`] : [], ` */`, - ` [${configKey}]?: typeof ${genDynamicImport(importName, { wrapper: false })}.default extends NuxtModule ? Partial : Record`, + ` [${configKey}]${options.unresolved ? '?' : ''}: typeof ${genDynamicImport(importName, { wrapper: false })}.default extends NuxtModule ? ${options.unresolved ? 'Partial' : 'O'} : Record`, ] }), - modules.length > 0 ? ` modules?: (undefined | null | false | NuxtModule | string | [NuxtModule | string, Record] | ${modules.map(([configKey, importName, mod]) => `[${genString(mod.meta?.rawPath || importName)}, Exclude]`).join(' | ')})[],` : '', + modules.length > 0 && options.unresolved ? ` modules?: (undefined | null | false | NuxtModule | string | [NuxtModule | string, Record] | ${modules.map(([configKey, importName, mod]) => `[${genString(mod.meta?.rawPath || importName)}, Exclude]`).join(' | ')})[],` : '', ].filter(Boolean) return [ 'import { NuxtModule, RuntimeConfig } from \'@nuxt/schema\'', 'declare module \'@nuxt/schema\' {', + ' interface NuxtOptions {', + ...moduleOptionsInterface({ addJSDocTags: false, unresolved: false }), + ' }', ' interface NuxtConfig {', // TypeScript will duplicate the jsdoc tags if we augment it twice // So here we only generate tags for `nuxt/schema` - ...moduleOptionsInterface(false), + ...moduleOptionsInterface({ addJSDocTags: false, unresolved: true }), ' }', '}', 'declare module \'nuxt/schema\' {', + ' interface NuxtOptions {', + ...moduleOptionsInterface({ addJSDocTags: true, unresolved: false }), + ' }', ' interface NuxtConfig {', - ...moduleOptionsInterface(true), + ...moduleOptionsInterface({ addJSDocTags: true, unresolved: true }), ' }', generateTypes(await resolveSchema(privateRuntimeConfig as Record), {