Skip to content

Commit 15adebf

Browse files
committed
CR1
1 parent cb8b808 commit 15adebf

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

lib/internal/fs/glob.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class Cache {
4444
#statsCache = new SafeMap();
4545
#readdirCache = new SafeMap();
4646

47-
stats(path) {
47+
statSync(path) {
4848
if (this.#statsCache.has(path)) {
4949
return this.#statsCache.get(path);
5050
}
@@ -57,13 +57,13 @@ class Cache {
5757
this.#statsCache.set(path, val);
5858
return val;
5959
}
60-
readdir(path) {
60+
readdirSync(path) {
6161
if (this.#readdirCache.has(path)) {
6262
return this.#readdirCache.get(path);
6363
}
6464
let val;
6565
try {
66-
val = readdirSync(path, { withFileTypes: true });
66+
val = readdirSync(path, { __proto__: null, withFileTypes: true });
6767
ArrayPrototypeForEach(val, (dirent) => this.#statsCache.set(join(path, dirent.name), dirent));
6868
} catch {
6969
val = [];
@@ -87,7 +87,7 @@ class Cache {
8787

8888
}
8989

90-
function glob(patterns, options = kEmptyObject) {
90+
function globSync(patterns, options = kEmptyObject) {
9191
validateObject(options, 'options');
9292
const root = options.cwd ?? '.';
9393
const { exclude } = options;
@@ -123,7 +123,7 @@ function glob(patterns, options = kEmptyObject) {
123123

124124
if (typeof currentPattern === 'string') {
125125
const entryPath = join(path, currentPattern);
126-
if (isLast && cache.stats(resolve(root, entryPath))) {
126+
if (isLast && cache.statSync(resolve(root, entryPath))) {
127127
// last path
128128
results.add(entryPath);
129129
} else if (!isLast) {
@@ -134,11 +134,11 @@ function glob(patterns, options = kEmptyObject) {
134134
}
135135

136136
const fullpath = resolve(root, path);
137-
const stat = cache.stats(fullpath);
137+
const stat = cache.statSync(fullpath);
138138
const isDirectory = stat?.isDirectory() || (followSymlinks !== false && stat?.isSymbolicLink());
139139

140140
if (isDirectory && isRegExp(currentPattern)) {
141-
const entries = cache.readdir(fullpath);
141+
const entries = cache.readdirSync(fullpath);
142142
for (const entry of entries) {
143143
const entryPath = join(path, entry.name);
144144
if (cache.seen(pattern, index, entryPath)) {
@@ -154,7 +154,7 @@ function glob(patterns, options = kEmptyObject) {
154154
}
155155

156156
if (currentPattern === GLOBSTAR && isDirectory) {
157-
const entries = cache.readdir(fullpath);
157+
const entries = cache.readdirSync(fullpath);
158158
for (const entry of entries) {
159159
if (entry.name[0] === '.' || (exclude && exclude(entry.name))) {
160160
continue;
@@ -197,6 +197,7 @@ function glob(patterns, options = kEmptyObject) {
197197
}
198198

199199
module.exports = {
200-
glob,
200+
__proto__: null,
201+
globSync,
201202
lazyMinimatch,
202203
};

lib/internal/test_runner/runner.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ const {
5757
countCompletedTest,
5858
kDefaultPattern,
5959
} = require('internal/test_runner/utils');
60-
const { glob } = require('internal/fs/glob');
60+
const { globSync } = require('internal/fs/glob');
6161
const { once } = require('events');
6262
const {
6363
triggerUncaughtException,
@@ -75,7 +75,11 @@ function createTestFileList() {
7575
const cwd = process.cwd();
7676
const hasUserSuppliedPattern = process.argv.length > 1;
7777
const patterns = hasUserSuppliedPattern ? ArrayPrototypeSlice(process.argv, 1) : [kDefaultPattern];
78-
const { results, matchers } = glob(patterns, { __proto__: null, cwd, exclude: (name) => name === 'node_modules' });
78+
const { results, matchers } = globSync(patterns, {
79+
__proto__: null,
80+
cwd,
81+
exclude: (name) => name === 'node_modules',
82+
});
7983

8084
if (hasUserSuppliedPattern && results.size === 0 && ArrayPrototypeEvery(matchers, (m) => !m.hasMagic())) {
8185
console.error(`Could not find '${ArrayPrototypeJoin(patterns, ', ')}'`);

0 commit comments

Comments
 (0)