8000 fix(build): do not export default as a type · nuxt/module-builder@d29337c · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Commit d29337c

Browse files
committed
fix(build): do not export default as a type
resolves #291
1 parent ced56f6 commit d29337c

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

src/commands/build.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -186,11 +186,11 @@ async function writeTypes(distDir: string) {
186186
// Read generated module types
187187
const moduleTypesFile = resolve(distDir, 'module.d.ts')
188188
const moduleTypes = await fsp.readFile(moduleTypesFile, 'utf8').catch(() => '')
189-
const typeExports = findExports(
189+
const moduleReExports = findExports(
190190
// Replace `export { type Foo }` with `export { Foo }`
191191
moduleTypes
192192
.replace(/export\s*\{.*?\}/gs, match =>
193-
match.replace(/\btype\b/g, ''),
193+
match.replace(/\b(type|interface)\b/g, ''),
194194
),
195195
)
196196
const isStub = moduleTypes.includes('export *')
@@ -201,7 +201,7 @@ async function writeTypes(distDir: string) {
201201
const schemaImports: string[] = []
202202
const moduleExports: string[] = []
203203

204-
const hasTypeExport = (name: string) => isStub || typeExports.find(exp => exp.names.includes(name))
204+
const hasTypeExport = (name: string) => isStub || moduleReExports.find(exp => exp.names.includes(name))
205205

206206
if (!hasTypeExport('ModuleOptions')) {
207207
schemaImports.push('NuxtModule')
@@ -243,7 +243,7 @@ ${appShims.length ? `declare module '#app' {\n${appShims.join('\n')}\n}\n` : ''}
243243
${schemaShims.length ? `declare module '@nuxt/schema' {\n${schemaShims.join('\n')}\n}\n` : ''}
244244
${schemaShims.length ? `declare module 'nuxt/schema' {\n${schemaShims.join('\n')}\n}\n` : ''}
245245
${moduleExports.length ? `\n${moduleExports.join('\n')}` : ''}
246-
${typeExports[0] ? `\nexport type { ${typeExports[0].names.join(', ')} } from './module'` : ''}
246+
${moduleReExports[0] ? `\nexport { ${moduleReExports[0].names.map(n => (n === 'default' ? '' : 'type ') + n).join(', ')} } from './module'` : ''}
247247
`.trim().replace(/[\n\r]{3,}/g, '\n\n') + '\n'
248248

249249
await fsp.writeFile(dtsFile, dtsContents, 'utf8')

test/build.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ describe('module builder', () => {
7777
interface PublicRuntimeConfig extends ModulePublicRuntimeConfig {}
7878
}
7979
80-
export type { ModuleHooks, ModuleOptions, ModulePublicRuntimeConfig, ModuleRuntimeConfig, ModuleRuntimeHooks, default } from './module'
80+
export { type ModuleHooks, type ModuleOptions, type ModulePublicRuntimeConfig, type ModuleRuntimeConfig, type ModuleRuntimeHooks, default } from './module'
8181
"
8282
`)
8383
})
@@ -107,7 +107,7 @@ describe('module builder', () => {
107107
108108
export type ModuleOptions = typeof Module extends NuxtModule<infer O> ? Partial<O> : Record<string, any>
109109
110-
export type { ModuleHooks, ModulePublicRuntimeConfig, ModuleRuntimeConfig, ModuleRuntimeHooks, default } from './module'
110+
export { type ModuleHooks, type ModulePublicRuntimeConfig, type ModuleRuntimeConfig, type ModuleRuntimeHooks, default } from './module'
111111
"
112112
`)
113113
})

0 commit comments

Comments
 (0)
0