-
-
Notifications
You must be signed in to change notification settings - Fork 221
Closed
Description
The intent of the generateDTS function to read history and merge is ambiguous, and the code is very old.
version:
unplugin-auto-import:^0.19.0
vite: ^6.0.4
config:
AutoImport({
dirs: [
resolve(__dirname, './src/utils/**')
],
dts: './src/auto-imports.d.ts',
})error:
const uid66: typeof import('./utils/html')['uid66']
const uid6611: typeof import('./utils/html')['uid6611']
const uid661122: typeof import('./utils/html')['uid661122']generateDTS:
unplugin-auto-import/src/core/ctx.ts
Lines 130 to 161 in e5cc63f
| async function generateDTS(file: string) { | |
| await importsPromise | |
| const dir = dirname(file) | |
| const originalContent = existsSync(file) ? await fs.readFile(file, 'utf-8') : '' | |
| const originalDTS = parseDTS(originalContent) | |
| let currentContent = await unimport.generateTypeDeclarations({ | |
| resolvePath: (i) => { | |
| if (i.from.startsWith('.') || isAbsolute(i.from)) { | |
| const related = slash(relative(dir, i.from).replace(/\.ts(x)?$/, '')) | |
| return !related.startsWith('.') | |
| ? `./${related}` | |
| : related | |
| } | |
| return i.from | |
| }, | |
| }) | |
| const currentDTS = parseDTS(currentContent)! | |
| if (options.vueTemplate) { | |
| currentContent = currentContent.replace( | |
| componentCustomPropertiesReg, | |
| $1 => `interface GlobalComponents {}\n ${$1}`, | |
| ) | |
| } | |
| if (originalDTS) { | |
| Object.keys(currentDTS).forEach((key) => { | |
| 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 |
Metadata
Metadata
Assignees
Labels
No labels