Skip to content

Commit

Permalink
skip checks in lstat callback
Browse files Browse the repository at this point in the history
  • Loading branch information
Victor Lin committed Feb 4, 2020
1 parent f077a64 commit 758c76a
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions packages/jest-haste-map/src/crawlers/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down

0 comments on commit 758c76a

Please sign in to comment.