Skip to content

Commit

Permalink
fix: correctly generate declaration for custom SFC
Browse files Browse the repository at this point in the history
fix #394
  • Loading branch information
qmhc committed Nov 12, 2024
1 parent 35574d4 commit acf627d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
16 changes: 16 additions & 0 deletions examples/vue/components/CustomSFC.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<script lang="ts" setup></script>

<template>
<div>test</div>
</template>

<i18n lang="json">
{
"zh-cn": {
"test": "test"
},
"en": {
"test": "test"
}
}
</i18n>
4 changes: 3 additions & 1 deletion examples/vue/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import NoDirectExport from '@/components/NoDirectExport.vue'

import OutsideTsProps from '@/components/outside-ts-props'
import GenericProps from '@/components/GenericProps.vue'
import CustomSFC from '@/components/CustomSFC.vue'

import JsSetup from '../components/JsSetup.vue'
import CssVar from '../components/CssVar.vue'
Expand Down Expand Up @@ -47,7 +48,8 @@ export {
JsSetup,
CssVar,
OutsideTsProps,
GenericProps
GenericProps,
CustomSFC
}

export default DefaultImport
10 changes: 7 additions & 3 deletions src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ export function dtsPlugin(options: PluginOptions = {}): import('vite').Plugin {

const rootFiles = new Set<string>()
const outputFiles = new Map<string, string>()
const transformedFiles = new Set<string>()

const setOutputFile = (path: string, content: string) => {
outputFiles.set(path, content)
Expand Down Expand Up @@ -394,22 +395,23 @@ export function dtsPlugin(options: PluginOptions = {}): import('vite').Plugin {

async transform(code, id) {
let resolver: Resolver | undefined
id = normalizePath(id)
id = normalizePath(id).split('?')[0]

if (
!host ||
!program ||
!filter(id) ||
(!(resolver = resolvers.find(r => r.supports(id))) && !tjsRE.test(id))
(!(resolver = resolvers.find(r => r.supports(id))) && !tjsRE.test(id)) ||
transformedFiles.has(id)
) {
return
}

const startTime = Date.now()
const outDir = outDirs[0]

id = id.split('?')[0]
rootFiles.delete(id)
transformedFiles.add(id)

if (resolver) {
const result = await resolver.transform({
Expand Down Expand Up @@ -487,6 +489,8 @@ export function dtsPlugin(options: PluginOptions = {}): import('vite').Plugin {
},

async writeBundle() {
transformedFiles.clear()

if (!host || !program || bundled) return

bundled = true
Expand Down

0 comments on commit acf627d

Please sign in to comment.