Skip to content

Commit 84b68bb

Browse files
sxzzTheAlexLichter
andcommitted
feat: support globs for noExternal / inlineOnly / exports.exclude
Co-authored-by: Alexander Lichter <github@lichter.io>
1 parent fd141bc commit 84b68bb

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

src/features/pkg/exports.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -298,13 +298,13 @@ describe.concurrent('generateExports', () => {
298298
`)
299299
})
300300

301-
test('exclude via filename', async ({ expect }) => {
301+
test('exclude via glob', async ({ expect }) => {
302302
const results = generateExports(
303303
FAKE_PACKAGE_JSON,
304304
{
305305
es: [genChunk('index.js'), genChunk('foo.js'), genChunk('abc/bar.js')],
306306
},
307-
{ exclude: ['abc/bar.js'] },
307+
{ exclude: ['**/bar.js'] },
308308
)
309309

310310
await expect(results).resolves.toMatchInlineSnapshot(`
@@ -326,7 +326,7 @@ describe.concurrent('generateExports', () => {
326326
const results = generateExports(
327327
FAKE_PACKAGE_JSON,
328328
{ es: [genChunk('foo.js'), genChunk('abc/bar.js')] },
329-
{ exclude: ['abc/bar.js', /foo/] },
329+
{ exclude: ['**/bar.js', /foo/] },
330330
)
331331

332332
await expect(results).resolves.toMatchInlineSnapshot(`

src/features/pkg/exports.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ export interface ExportsOptions {
2727
all?: boolean
2828

2929
/**
30-
* Define filenames or RegExp patterns to exclude files from exports.
30+
* Define globs or RegExp patterns to exclude files from exports.
3131
* This is useful for excluding files that should not be part of the package exports,
3232
* such as bin files or internal utilities.
3333
*
3434
* @example
3535
* ```js
36-
* exclude: ['foo.ts', /\.spec\.ts$/, /internal/]
36+
* exclude: ['**\/*.test.ts', '**\/*.spec.ts', /internal/]
3737
* ```
3838
*/
3939
exclude?: (RegExp | string)[]

src/utils/general.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import picomatch from 'picomatch'
2+
13
export function toArray<T>(
24
val: T | T[] | null | undefined,
35
defaultValue?: T,
@@ -57,7 +59,7 @@ export function matchPattern(
5759
pattern.lastIndex = 0
5860
return pattern.test(id)
5961
}
60-
return id === pattern
62+
return id === pattern || picomatch(pattern)(id)
6163
})
6264
}
6365

0 commit comments

Comments
 (0)