Skip to content
This repository was archived by the owner on Apr 21, 2025. It is now read-only.

Commit 1b1cd59

Browse files
committed
feat: add support for exports with patterns
1 parent 8a67946 commit 1b1cd59

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/core/build/index.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ export const build = async (
7272
logRollupConfig(pkg, rollupConfig)
7373

7474
await runInParallel(pkg.folderExports, folder => {
75-
const { 1: distDir = folder } = folder.match(/^(.*[^*/])[*/]*$/) || []
75+
const { 1: distDir = folder, 3: ext } =
76+
folder.match(/^([^*]+[^*/])[*/]+(\.([a-z]+))?$/) || []
7677
const sourceFolder = pkg.resolveEntrypointFolder(distDir)
7778
if (!sourceFolder) return
7879

@@ -84,6 +85,9 @@ export const build = async (
8485
srcDir,
8586
distDir: distDir.slice(2),
8687
rootDir: pkg.options.rootDir,
88+
ext: ['mjs', 'ts', 'js'].includes(ext)
89+
? (ext as 'mjs' | 'ts' | 'js')
90+
: undefined,
8791
...pkg.options.mkdist,
8892
})
8993
})

src/core/package/index.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,9 @@ export class Package {
423423
`./${this.pkg.main}`,
424424
`./${this.pkg.module}`,
425425
`./${this.pkg.browser}`,
426-
].includes(item) && !/[./*]$/.test(item)
426+
].includes(item) &&
427+
!item.endsWith('/') &&
428+
!item.includes('*')
427429

428430
if (!exports) return []
429431
if (typeof exports === 'string') return [exports].filter(filterExports)
@@ -435,7 +437,7 @@ export class Package {
435437
get folderExports(): string[] {
436438
const { exports } = this.pkg
437439

438-
const filterExports = (item: string) => /[a-z]\/\*$/.test(item)
440+
const filterExports = (item: string) => /[a-z]\/\*(\.[a-z]*)?$/.test(item)
439441

440442
if (!exports) return []
441443
if (typeof exports === 'string') return [exports].filter(filterExports)

0 commit comments

Comments
 (0)