diff --git a/src/index.ts b/src/index.ts index a00102d3..ce59651a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -119,7 +119,27 @@ 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 `${pattern}/**` + } + return pattern + }) + 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', + }) options.entry = await new fdir() .withRelativePaths() .filter((file) => matcher(file)) 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 +})