Skip to content

Commit 2890dfd

Browse files
authored
perf: precompile picomatch matchers once per scan (#535)
1 parent 53a9666 commit 2890dfd

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

src/node/scan-dirs.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,8 @@ export async function scanFilesFromDir(dir: ScanDir | ScanDir[], options?: ScanD
132132

133133
const fileFilter = options?.fileFilter || (() => true)
134134

135-
const indexOfDirs = (file: string) => dirGlobs.findIndex(glob => pm.isMatch(file, glob))
135+
const dirMatchers = dirGlobs.map(glob => pm(glob))
136+
const indexOfDirs = (file: string) => dirMatchers.findIndex(match => match(file))
136137
const fileSortByDirs = files.reduce((acc, file) => {
137138
const index = indexOfDirs(file)
138139
if (acc[index])
@@ -150,7 +151,8 @@ export async function scanDirExports(dirs: (string | ScanDir)[], options?: ScanD
150151
const files = await scanFilesFromDir(normalizedDirs, options)
151152

152153
const includeTypesDirs = normalizedDirs.filter(dir => !dir.glob.startsWith('!') && dir.types)
153-
const isIncludeTypes = (file: string) => includeTypesDirs.some(dir => pm.isMatch(file, dir.glob))
154+
const includeTypesMatchers = includeTypesDirs.map(dir => pm(dir.glob))
155+
const isIncludeTypes = (file: string) => includeTypesMatchers.some(match => match(file))
154156

155157
const imports = (await Promise.all(files.map(file => scanExports(file, isIncludeTypes(file))))).flat()
156158
const deduped = dedupeDtsExports(imports)

0 commit comments

Comments
 (0)