Skip to content

Commit

Permalink
fix: dts reg error (#381)
Browse files Browse the repository at this point in the history
  • Loading branch information
lishaobos committed May 22, 2023
1 parent 79fbed3 commit f5c5595
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/core/ctx.ts
Expand Up @@ -112,7 +112,7 @@ ${dts}`.trim()}\n`
originalDTS[key] = currentDTS[key]
})
const dtsList = Object.keys(originalDTS).sort().map(k => ` ${k}: ${originalDTS[k]}`)
return currentContent.replace(dtsReg, `declare global {\n${dtsList.join('\n')}\n}`)
return currentContent.replace(dtsReg, () => `declare global {\n${dtsList.join('\n')}\n}`)
}

return currentContent
Expand Down Expand Up @@ -166,13 +166,13 @@ ${dts}`.trim()}\n`
async function scanDirs() {
if (dirs?.length) {
await unimport.modifyDynamicImports(async (imports) => {
const exports = await scanDirExports(dirs, {
const exports_ = await scanDirExports(dirs, {
filePatterns: ['*.{tsx,jsx,ts,js,mjs,cjs,mts,cts}'],
}) as ImportExtended[]
exports.forEach(i => i.__source = 'dir')
exports_.forEach(i => i.__source = 'dir')
return modifyDefaultExportsAlias([
...imports.filter((i: ImportExtended) => i.__source !== 'dir'),
...exports,
...exports_,
], options)
})
}
Expand Down
1 change: 1 addition & 0 deletions test/dts.increase.test.ts
Expand Up @@ -14,4 +14,5 @@ it('dts', async () => {
const dtsContent = await ctx.generateDTS(dts)
expect(dtsContent).toContain('AAA')
expect(dtsContent).toContain('BBB')
expect(dtsContent).toContain('$$')
})
2 changes: 2 additions & 0 deletions test/tmp/dts.increase.d.ts
Expand Up @@ -4,6 +4,8 @@
// Generated by unplugin-auto-import
export {}
declare global {
const $$: typeof import('vue/macros')['$$']
const $: typeof import('vue/macros')['$']
const AAA: typeof import('xxx/es')['AAA']
const BBB: typeof import('xxx/es')['BBB']
}
Expand Down

0 comments on commit f5c5595

Please sign in to comment.