Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: dir export with trailing comma #235

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/core/ctx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ export function createContext(options: Options = {}, root = process.cwd()) {
async function scanDirs() {
if (dirs?.length) {
await unimport.modifyDynamicImports(async (imports) => {
const exports = await scanDirExports(dirs) as ImportExtended[]
exports.forEach(i => i.__source = 'dir')
const rawExports = await scanDirExports(dirs) as ImportExtended[]
const exports = rawExports.filter(i => i.name !== '' && (i.__source = 'dir'))
return [
...imports.filter((i: ImportExtended) => i.__source !== 'dir'),
...exports,
Expand Down
9 changes: 9 additions & 0 deletions test/__snapshots__/transform.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
// Vitest Snapshot v1

exports[`directories-export > trailing comma 1`] = `
"// Generated by 'unplugin-auto-import'
export {}
declare global {
const a: typeof import('./export')['a']
}
"
`;

exports[`transform > comments.ts 1`] = `
"import { ref, computed } from 'vue';
/* import { ref } from 'vue' */
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/dir-export-with-comma/export.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { a, } from "test";
16 changes: 16 additions & 0 deletions test/transform.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,19 @@ describe('transform-vue-macro', async () => {
})
}
})

describe('directories-export', async () => {
const dirPath = 'test/fixtures/dir-export-with-comma'
const fileName = 'auto-imports.d.ts'
const filePath = `${dirPath}/${fileName}`
const ctx = createContext({
dts: filePath,
dirs: [dirPath],
})
await ctx.scanDirs()

it('trailing comma', async () => {
const fixture = await fs.readFile(filePath, 'utf-8')
expect(fixture).toMatchSnapshot()
})
})