Skip to content

Commit fa5c772

Browse files
authored
fix(build): declare ModuleOptions in correct place (#283)
1 parent 84f6828 commit fa5c772

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

src/commands/build.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -211,16 +211,20 @@ async function writeTypes(distDir: string, meta: ModuleMeta, getOptions: () => P
211211
const appShims: string[] = []
212212
const schemaShims: string[] = []
213213
const moduleImports: string[] = []
214+
const moduleDeclarations: string[] = []
214215

215216
const hasTypeExport = (name: string) => isStub || typeExports.find(exp => exp.names.includes(name))
216217

217-
if (meta.configKey && hasTypeExport('ModuleOptions')) {
218-
moduleImports.push('ModuleOptions')
218+
if (meta.configKey) {
219219
schemaShims.push(` interface NuxtConfig { ['${meta.configKey}']?: Partial<ModuleOptions> }`)
220220
schemaShims.push(` interface NuxtOptions { ['${meta.configKey}']?: ModuleOptions }`)
221-
}
222-
else if (meta.configKey) {
223-
schemaShims.push(` ${generateTypes(await resolveSchema(await getOptions() as InputObject), { interfaceName: 'ModuleOptions' })}`)
221+
222+
if (hasTypeExport('ModuleOptions')) {
223+
moduleImports.push('ModuleOptions')
224+
}
225+
else {
226+
moduleDeclarations.push(` ${generateTypes(await resolveSchema(await getOptions() as InputObject), { interfaceName: 'ModuleOptions' })}`)
227+
}
224228
}
225229
if (hasTypeExport('ModuleHooks')) {
226230
moduleImports.push('ModuleHooks')
@@ -250,6 +254,7 @@ async function writeTypes(distDir: string, meta: ModuleMeta, getOptions: () => P
250254
const dtsContents = `
251255
import type { ${moduleImports.join(', ')} } from './module'
252256
257+
${moduleDeclarations.join('\n')}
253258
${appShims.length ? `declare module '#app' {\n${appShims.join('\n')}\n}\n` : ''}
254259
${schemaShims.length ? `declare module '@nuxt/schema' {\n${schemaShims.join('\n')}\n}\n` : ''}
255260
${schemaShims.length ? `declare module 'nuxt/schema' {\n${schemaShims.join('\n')}\n}\n` : ''}

test/build.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ describe('module builder', () => {
5050
"
5151
import type { ModuleOptions, ModuleHooks, ModuleRuntimeHooks, ModuleRuntimeConfig, ModulePublicRuntimeConfig } from './module'
5252
53+
5354
declare module '#app' {
5455
interface RuntimeNuxtHooks extends ModuleRuntimeHooks {}
5556
}

0 commit comments

Comments
 (0)