From 758c76af58f9e9d41ab41f37d89f196b1140a4bc Mon Sep 17 00:00:00 2001 From: Victor Lin Date: Tue, 4 Feb 2020 12:44:26 -0800 Subject: [PATCH] skip checks in lstat callback --- packages/jest-haste-map/src/crawlers/node.ts | 21 ++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/packages/jest-haste-map/src/crawlers/node.ts b/packages/jest-haste-map/src/crawlers/node.ts index 833f51f80f14..0bcb0fcd82db 100644 --- a/packages/jest-haste-map/src/crawlers/node.ts +++ b/packages/jest-haste-map/src/crawlers/node.ts @@ -61,17 +61,26 @@ function find( } } + // If we made it here and had dirent support, we know that + // this is a normal file and can skip some checks in the lstat callback below + let passedFiletypeChecks = typeof entry !== 'string'; + activeCalls++; fs.lstat(file, (err, stat) => { activeCalls--; - // This logic is unnecessary for node > v10.10, but leaving it in - // since we need it for backwards-compatibility still. - if (!err && stat && !stat.isSymbolicLink()) { - if (stat.isDirectory()) { - search(file); - } else { + if (!err && stat) { + if (!passedFiletypeChecks) { + if (stat.isSymbolicLink()) { + // do nothing + } else if (stat.isDirectory()) { + search(file); + } else { + passedFiletypeChecks = true; + } + } + if (passedFiletypeChecks) { const ext = path.extname(file).substr(1); if (extensions.indexOf(ext) !== -1) { result.push([file, stat.mtime.getTime(), stat.size]);