@@ -44,7 +44,7 @@ class Cache {
44
44
#statsCache = new SafeMap ( ) ;
45
45
#readdirCache = new SafeMap ( ) ;
46
46
47
- stats ( path ) {
47
+ statSync ( path ) {
48
48
if ( this . #statsCache. has ( path ) ) {
49
49
return this . #statsCache. get ( path ) ;
50
50
}
@@ -57,13 +57,13 @@ class Cache {
57
57
this . #statsCache. set ( path , val ) ;
58
58
return val ;
59
59
}
60
- readdir ( path ) {
60
+ readdirSync ( path ) {
61
61
if ( this . #readdirCache. has ( path ) ) {
62
62
return this . #readdirCache. get ( path ) ;
63
63
}
64
64
let val ;
65
65
try {
66
- val = readdirSync ( path , { withFileTypes : true } ) ;
66
+ val = readdirSync ( path , { __proto__ : null , withFileTypes : true } ) ;
67
67
ArrayPrototypeForEach ( val , ( dirent ) => this . #statsCache. set ( join ( path , dirent . name ) , dirent ) ) ;
68
68
} catch {
69
69
val = [ ] ;
@@ -87,7 +87,7 @@ class Cache {
87
87
88
88
}
89
89
90
- function glob ( patterns , options = kEmptyObject ) {
90
+ function globSync ( patterns , options = kEmptyObject ) {
91
91
validateObject ( options , 'options' ) ;
92
92
const root = options . cwd ?? '.' ;
93
93
const { exclude } = options ;
@@ -123,7 +123,7 @@ function glob(patterns, options = kEmptyObject) {
123
123
124
124
if ( typeof currentPattern === 'string' ) {
125
125
const entryPath = join ( path , currentPattern ) ;
126
- if ( isLast && cache . stats ( resolve ( root , entryPath ) ) ) {
126
+ if ( isLast && cache . statSync ( resolve ( root , entryPath ) ) ) {
127
127
// last path
128
128
results . add ( entryPath ) ;
129
129
} else if ( ! isLast ) {
@@ -134,11 +134,11 @@ function glob(patterns, options = kEmptyObject) {
134
134
}
135
135
136
136
const fullpath = resolve ( root , path ) ;
137
- const stat = cache . stats ( fullpath ) ;
137
+ const stat = cache . statSync ( fullpath ) ;
138
138
const isDirectory = stat ?. isDirectory ( ) || ( followSymlinks !== false && stat ?. isSymbolicLink ( ) ) ;
139
139
140
140
if ( isDirectory && isRegExp ( currentPattern ) ) {
141
- const entries = cache . readdir ( fullpath ) ;
141
+ const entries = cache . readdirSync ( fullpath ) ;
142
142
for ( const entry of entries ) {
143
143
const entryPath = join ( path , entry . name ) ;
144
144
if ( cache . seen ( pattern , index , entryPath ) ) {
@@ -154,7 +154,7 @@ function glob(patterns, options = kEmptyObject) {
154
154
}
155
155
156
156
if ( currentPattern === GLOBSTAR && isDirectory ) {
157
- const entries = cache . readdir ( fullpath ) ;
157
+ const entries = cache . readdirSync ( fullpath ) ;
158
158
for ( const entry of entries ) {
159
159
if ( entry . name [ 0 ] === '.' || ( exclude && exclude ( entry . name ) ) ) {
160
160
continue ;
@@ -197,6 +197,7 @@ function glob(patterns, options = kEmptyObject) {
197
197
}
198
198
199
199
module . exports = {
200
- glob,
200
+ __proto__ : null ,
201
+ globSync,
201
202
lazyMinimatch,
202
203
} ;
0 commit comments