Skip to content

Commit

Permalink
chore: update
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Sep 4, 2023
1 parent 74e03e0 commit c411e26
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,15 +132,16 @@ export function createUnimport (opts: Partial<UnimportOptions>) {
return dts
}

async function scanImportsFromFile (filepath: string) {
const additions = await scanExports(filepath)
async function scanImportsFromFile (filepath: string, includeTypes = true) {
const additions = await scanExports(filepath, includeTypes)
await modifyDynamicImports(imports => imports.filter(i => i.from !== filepath).concat(additions))
return additions
}

async function scanImportsFromDir (dirs = ctx.options.dirs || [], options = ctx.options.dirsScanOptions) {
const files = await scanFilesFromDir(dirs, options)
return (await Promise.all(files.map(scanImportsFromFile))).flat()
const includeTypes = options?.types ?? true
return (await Promise.all(files.map(dir => scanImportsFromFile(dir, includeTypes)))).flat()
}

async function injectImportsWithContext (code: string | MagicString, id?: string, options?: InjectImportsOptions) {
Expand Down
4 changes: 4 additions & 0 deletions test/dts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ test('dts', async () => {
export type { Ref, ComputedRef } from 'vue'
// @ts-ignore
export type { JQuery } from 'jquery'
// @ts-ignore
export type { CustomType1, CustomInterface1 } from '<root>/playground/composables/index.ts'
// @ts-ignore
export type { CustomType2 } from '<root>/playground/composables/nested/bar/sub/index.ts'
}"
`)
})

0 comments on commit c411e26

Please sign in to comment.