Skip to content

rename or delete functions, will also exist in DTS #548

@eed-cn

Description

@eed-cn

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:

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions