From 52af4f07e08a92e60ff75929776ff9c64bcd3308 Mon Sep 17 00:00:00 2001 From: barak igal Date: Wed, 14 Jun 2023 10:12:22 +0300 Subject: [PATCH] refactor: avoid calling stat manually on each entry (#2568) --- packages/node/src/find-files.ts | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/packages/node/src/find-files.ts b/packages/node/src/find-files.ts index 7994e1c9f..5de3e3a4a 100644 --- a/packages/node/src/find-files.ts +++ b/packages/node/src/find-files.ts @@ -17,16 +17,15 @@ export function findFiles( while (folders.length) { const current = folders.pop()!; try { - fs.readdirSync(current).forEach((item: string) => { - if (blacklist.has(item)) { + fs.readdirSync(current, { withFileTypes: true }).forEach((item) => { + if (blacklist.has(item.name)) { return; } - const itemFullPath = join(current, item); + const itemFullPath = join(current, item.name); try { - const status = fs.statSync(itemFullPath); - if (status.isDirectory()) { + if (item.isDirectory()) { folders.push(itemFullPath); - } else if (status.isFile() && itemFullPath.endsWith(ext)) { + } else if (item.isFile() && itemFullPath.endsWith(ext)) { result.add( useRelative ? relative(rootDirectory, itemFullPath) : itemFullPath );