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: match least-nested files first when inferring entry #108

Merged
merged 2 commits into from Sep 1, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 4 additions & 1 deletion 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 Expand Up @@ -114,7 +117,7 @@ export function inferEntries (pkg: PackageJson, sourceFiles: string[]): InferEnt

if (isDir) {
entry.outDir = outputSlug
;(entry as MkdistBuildEntry).format = output.type
; (entry as MkdistBuildEntry).format = output.type
danielroe marked this conversation as resolved.
Show resolved Hide resolved
}
}

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