Skip to content

Commit d40f14b

Browse files
BTBManantfu
andauthored
fix: add GlobalComponents dts (#469)
Co-authored-by: Anthony Fu <anthonyfu117@hotmail.com>
1 parent 135f082 commit d40f14b

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

src/core/ctx.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ ${dts}`.trim()}\n`
114114
const multilineCommentsRE = /\/\*.*?\*\//gms
115115
const singlelineCommentsRE = /\/\/.*$/gm
116116
const dtsReg = /declare\s+global\s*{(.*?)[\n\r]}/s
117+
const componentCustomPropertiesReg = /interface\s+ComponentCustomProperties\s*{(.*?)[\n\r]}/gs
117118
function parseDTS(dts: string) {
118119
dts = dts
119120
.replace(multilineCommentsRE, '')
@@ -131,7 +132,7 @@ ${dts}`.trim()}\n`
131132
const dir = dirname(file)
132133
const originalContent = existsSync(file) ? await fs.readFile(file, 'utf-8') : ''
133134
const originalDTS = parseDTS(originalContent)
134-
const currentContent = await unimport.generateTypeDeclarations({
135+
let currentContent = await unimport.generateTypeDeclarations({
135136
resolvePath: (i) => {
136137
if (i.from.startsWith('.') || isAbsolute(i.from)) {
137138
const related = slash(relative(dir, i.from).replace(/\.ts(x)?$/, ''))
@@ -143,6 +144,12 @@ ${dts}`.trim()}\n`
143144
},
144145
})
145146
const currentDTS = parseDTS(currentContent)!
147+
if (options.vueTemplate) {
148+
currentContent = currentContent.replace(
149+
componentCustomPropertiesReg,
150+
$1 => `interface GlobalComponents {}\n ${$1}`,
151+
)
152+
}
146153
if (originalDTS) {
147154
Object.keys(currentDTS).forEach((key) => {
148155
originalDTS[key] = currentDTS[key]

0 commit comments

Comments
 (0)