Skip to content

Commit

Permalink
CR1
Browse files Browse the repository at this point in the history
  • Loading branch information
MoLow committed Apr 22, 2023
1 parent cb8b808 commit 15adebf
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
19 changes: 10 additions & 9 deletions lib/internal/fs/glob.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class Cache {
#statsCache = new SafeMap();
#readdirCache = new SafeMap();

stats(path) {
statSync(path) {
if (this.#statsCache.has(path)) {
return this.#statsCache.get(path);
}
Expand All @@ -57,13 +57,13 @@ class Cache {
this.#statsCache.set(path, val);
return val;
}
readdir(path) {
readdirSync(path) {
if (this.#readdirCache.has(path)) {
return this.#readdirCache.get(path);
}
let val;
try {
val = readdirSync(path, { withFileTypes: true });
val = readdirSync(path, { __proto__: null, withFileTypes: true });
ArrayPrototypeForEach(val, (dirent) => this.#statsCache.set(join(path, dirent.name), dirent));
} catch {
val = [];
Expand All @@ -87,7 +87,7 @@ class Cache {

}

function glob(patterns, options = kEmptyObject) {
function globSync(patterns, options = kEmptyObject) {
validateObject(options, 'options');
const root = options.cwd ?? '.';
const { exclude } = options;
Expand Down Expand Up @@ -123,7 +123,7 @@ function glob(patterns, options = kEmptyObject) {

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

const fullpath = resolve(root, path);
const stat = cache.stats(fullpath);
const stat = cache.statSync(fullpath);
const isDirectory = stat?.isDirectory() || (followSymlinks !== false && stat?.isSymbolicLink());

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

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

module.exports = {
glob,
__proto__: null,
globSync,
lazyMinimatch,
};
8 changes: 6 additions & 2 deletions lib/internal/test_runner/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const {
countCompletedTest,
kDefaultPattern,
} = require('internal/test_runner/utils');
const { glob } = require('internal/fs/glob');
const { globSync } = require('internal/fs/glob');
const { once } = require('events');
const {
triggerUncaughtException,
Expand All @@ -75,7 +75,11 @@ function createTestFileList() {
const cwd = process.cwd();
const hasUserSuppliedPattern = process.argv.length > 1;
const patterns = hasUserSuppliedPattern ? ArrayPrototypeSlice(process.argv, 1) : [kDefaultPattern];
const { results, matchers } = glob(patterns, { __proto__: null, cwd, exclude: (name) => name === 'node_modules' });
const { results, matchers } = globSync(patterns, {
__proto__: null,
cwd,
exclude: (name) => name === 'node_modules',
});

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

0 comments on commit 15adebf

Please sign in to comment.