in packages/jest-haste-map/src/crawlers/node.ts [69:124]
function search(directory: string): void {
activeCalls++;
fs.readdir(directory, {withFileTypes: true}, (err, entries) => {
activeCalls--;
if (err) {
if (activeCalls === 0) {
callback(result);
}
return;
}
entries.forEach(entry => {
const file = path.join(directory, entry.name);
if (ignore(file)) {
return;
}
if (entry.isSymbolicLink()) {
return;
}
if (entry.isDirectory()) {
search(file);
return;
}
activeCalls++;
const stat = enableSymlinks ? fs.stat : fs.lstat;
stat(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 {
const ext = path.extname(file).substr(1);
if (extensions.indexOf(ext) !== -1) {
result.push([file, stat.mtime.getTime(), stat.size]);
}
}
}
if (activeCalls === 0) {
callback(result);
}
});
});
if (activeCalls === 0) {
callback(result);
}
});
}