From 97855edd0922b2bcc7fa19bb3ed1349e3cbd333e Mon Sep 17 00:00:00 2001 From: Superchupu <53496941+SuperchupuDev@users.noreply.github.com> Date: Sun, 21 Jul 2024 11:15:10 +0000 Subject: [PATCH 1/4] fix: expand directories if provided as entry --- src/index.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index a00102d3..5591e0f0 100644 --- a/src/index.ts +++ b/src/index.ts @@ -119,7 +119,17 @@ const normalizeOptions = async ( } if (Array.isArray(entry)) { - const matcher = picomatch(entry, { windows: process.platform === 'win32' }) + // using a directory as entry should match all files inside it + const expandedEntries = entry.map((pattern) => { + if (!pattern.endsWith('**')) { + return path.join(pattern, '**') + } + return pattern + }) + const matcher = picomatch(expandedEntries, { + dot: true, + windows: process.platform === 'win32', + }) options.entry = await new fdir() .withRelativePaths() .filter((file) => matcher(file)) From 8ccce455a80a0ddae02f532b21cd505f8c1791ad Mon Sep 17 00:00:00 2001 From: Superchupu <53496941+SuperchupuDev@users.noreply.github.com> Date: Sun, 21 Jul 2024 11:18:56 +0000 Subject: [PATCH 2/4] chore: add test --- test/index.test.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/test/index.test.ts b/test/index.test.ts index 5b07554f..d2f771c4 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -901,3 +901,19 @@ test('generate sourcemap with --treeshake', async () => { }), ) }) + +test('should not throw when having directories as entry', async () => { + const sourceCode = 'export const h = "h"' + + expect( + run( + getTestName(), + { + 'src/input.ts': sourceCode, + }, + { + entry: ['src'], + }, + ), + ).resolves +}) From 692e84601c95c30872098239c8ef5a167d0d19b7 Mon Sep 17 00:00:00 2001 From: Superchupu <53496941+SuperchupuDev@users.noreply.github.com> Date: Sun, 21 Jul 2024 11:32:29 +0000 Subject: [PATCH 3/4] fix: make fix not break windows --- src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 5591e0f0..1101a051 100644 --- a/src/index.ts +++ b/src/index.ts @@ -122,7 +122,7 @@ const normalizeOptions = async ( // using a directory as entry should match all files inside it const expandedEntries = entry.map((pattern) => { if (!pattern.endsWith('**')) { - return path.join(pattern, '**') + return `${pattern}/**` } return pattern }) From 3dcdaf3d22bbe87b3fa88f91ec7632dbfc520640 Mon Sep 17 00:00:00 2001 From: Superchupu <53496941+SuperchupuDev@users.noreply.github.com> Date: Sun, 21 Jul 2024 16:42:27 +0000 Subject: [PATCH 4/4] fix: apply special ignore logic for entries --- src/index.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 1101a051..ce59651a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -126,7 +126,17 @@ const normalizeOptions = async ( } return pattern }) - const matcher = picomatch(expandedEntries, { + const matchPatterns: string[] = [] + const ignorePatterns: string[] = [] + for (const pattern of expandedEntries) { + if (pattern.startsWith('!') && pattern[1] !== '(') { + ignorePatterns.push(pattern.slice(1)) + } else { + matchPatterns.push(pattern) + } + } + const matcher = picomatch(matchPatterns, { + ignore: ignorePatterns, dot: true, windows: process.platform === 'win32', })