Skip to content

Commit

Permalink
chore: fix folder barrel with extName
Browse files Browse the repository at this point in the history
  • Loading branch information
stijnvanhulle committed Dec 6, 2023
1 parent dae9e13 commit 0f99965
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion examples/advanced/src/gen/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ export * as clients from './clients/axios'
export * as hooks from './clients/hooks'
export * as swrHooks from './clients/swr'
export * as faker from './mocks'
export type * from './models/ts'
export type * from './models/ts/index.js'
export * as msw from './msw'
export * as zod from './zod'
16 changes: 14 additions & 2 deletions packages/core/src/FileManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,9 +280,21 @@ export class FileManager {
}

const exportPath = output.path.startsWith('./') ? trimExtName(output.path) : `./${trimExtName(output.path)}`
const mode = FileManager.getMode(output.path)
const barrelManager = new BarrelManager({ extName: output.extName, ...options })
const files = barrelManager.getIndexes(resolve(root, output.path))

function getPath() {
if (output.extName) {
if (mode === 'directory') {
return `${exportPath}/index${output.extName}`
}
return `${exportPath}${output.extName}`
}

return exportPath
}

if (!files) {
return undefined
}
Expand All @@ -296,11 +308,11 @@ export class FileManager {
? {
name: output.exportAs,
asAlias: true,
path: output.extName ? `${exportPath}${output.extName}` : exportPath,
path: getPath(),
isTypeOnly: options.isTypeOnly,
}
: {
path: output.extName ? `${exportPath}${output.extName}` : exportPath,
path: getPath(),
isTypeOnly: options.isTypeOnly,
},
],
Expand Down

0 comments on commit 0f99965

Please sign in to comment.