Skip to content

Commit eeba924

Browse files
committed
fix: dts generation dedup
1 parent 4991c80 commit eeba924

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/core/declaration.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { notNullish, slash } from '@antfu/utils'
44
import { Context } from './context'
55

66
export function parseDeclaration(code: string): Record<string, string> {
7+
if (!code)
8+
return {}
79
return Object.fromEntries(Array.from(code.matchAll(/(?<!\/\/)\s+\s+['"]?(.+?)['"]?:\s(.+?)\n/g)).map(i => [i[1], i[2]]))
810
}
911

@@ -34,9 +36,9 @@ export async function generateDeclaration(ctx: Context, root: string, filepath:
3436
if (!Object.keys(imports).length)
3537
return
3638

37-
const originalImports = existsSync(filepath)
38-
? parseDeclaration(await fs.readFile(filepath, 'utf-8'))
39-
: {}
39+
const originalContent = existsSync(filepath) ? await fs.readFile(filepath, 'utf-8') : ''
40+
41+
const originalImports = parseDeclaration(originalContent)
4042

4143
const lines = Object.entries({
4244
...originalImports,
@@ -61,5 +63,7 @@ declare module 'vue' {
6163
6264
export { }
6365
`
64-
await fs.writeFile(filepath, code, 'utf-8')
66+
67+
if (code !== originalContent)
68+
await fs.writeFile(filepath, code, 'utf-8')
6569
}

0 commit comments

Comments
 (0)