Skip to content

Commit

Permalink
fix: match least-nested files first when inferring entry (#108)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe committed Sep 1, 2022
1 parent 27bda7c commit 40f21fa
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/auto.ts
Expand Up @@ -46,6 +46,9 @@ export const autoPreset = definePreset(() => {
export function inferEntries (pkg: PackageJson, sourceFiles: string[]): InferEntriesResult {
const warnings = []

// Sort files so least-nested files are first
sourceFiles.sort((a, b) => a.split('/').length - b.split('/').length)

// Come up with a list of all output files & their formats
const outputs = extractExportFilenames(pkg.exports)

Expand Down
10 changes: 10 additions & 0 deletions test/auto.test.ts
Expand Up @@ -12,6 +12,16 @@ describe('inferEntries', () => {
})
})

it('handles nested indexes', () => {
const result = inferEntries({ module: 'dist/index.mjs' }, ['src/', 'src/event/index.ts', 'src/index.ts'])
expect(result).to.deep.equal({
cjs: false,
dts: false,
entries: [{ input: 'src/index' }],
warnings: []
})
})

it('handles binary outputs', () => {
expect(inferEntries({ bin: 'dist/cli.cjs' }, ['src/', 'src/cli.ts'])).to.deep.equal({
cjs: true,
Expand Down

0 comments on commit 40f21fa

Please sign in to comment.