镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 22 additions & 9 deletions lib/internal/fs/glob.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,30 @@ function lazyMinimatch() {
const isWindows = process.platform === 'win32';
const isOSX = process.platform === 'darwin';

/**
* @param {string} path
* @returns {Promise<DirentFromStats|null>}
*/
async function getDirent(path) {
return new DirentFromStats(basename(path), await lstat(path), path);
let stat;
try {
stat = await lstat(path);
} catch {
return null;
}
return new DirentFromStats(basename(path), stat, path);
}

/**
* @param {string} path
* @returns {DirentFromStats|null}
*/
function getDirentSync(path) {
return new DirentFromStats(basename(path), lstatSync(path), path);
const stat = lstatSync(path, { throwIfNoEntry: false });
if (stat === undefined) {
return null;
}
return new DirentFromStats(basename(path), stat, path);
}

class Cache {
Expand All @@ -56,7 +74,7 @@ class Cache {
if (cached) {
return cached;
}
const promise = PromisePrototypeThen(getDirent(path), null, () => null);
const promise = getDirent(path);
this.#statsCache.set(path, promise);
return promise;
}
Expand All @@ -65,12 +83,7 @@ class Cache {
if (cached) {
return cached;
}
let val;
try {
val = getDirentSync(path);
} catch {
val = null;
}
const val = getDirentSync(path);
this.#statsCache.set(path, val);
return val;
}
Expand Down