@@ -72,16 +72,28 @@ class OperationMergerBackend {
7272
7373 this . provide = this . _provider
7474 ? /**
75- * @param {string } path path
76- * @param {any } options options
77- * @param {function } callback callback
75+ * @param {PathLike | PathOrFileDescriptor } path path
76+ * @param {object | FileSystemCallback< any> | undefined } options options
77+ * @param {FileSystemCallback<any>= } callback callback
7878 * @returns {any } result
7979 */
8080 ( path , options , callback ) => {
8181 if ( typeof options === "function" ) {
82- callback = options ;
82+ callback = /** @type { FileSystemCallback<any> } */ ( options ) ;
8383 options = undefined ;
8484 }
85+ if (
86+ typeof path !== "string" &&
87+ ! Buffer . isBuffer ( path ) &&
88+ ! ( path instanceof URL ) &&
89+ typeof path !== "number"
90+ ) {
91+ /** @type {Function } */
92+ ( callback ) (
93+ new TypeError ( "path must be a string, Buffer, URL or number" )
94+ ) ;
95+ return ;
96+ }
8597 if ( options ) {
8698 return /** @type {Function } */ ( this . _provider ) . call (
8799 this . _providerContext ,
@@ -90,10 +102,6 @@ class OperationMergerBackend {
90102 callback
91103 ) ;
92104 }
93- if ( typeof path !== "string" ) {
94- callback ( new TypeError ( "path must be a string" ) ) ;
95- return ;
96- }
97105 let callbacks = this . _activeAsyncOperations . get ( path ) ;
98106 if ( callbacks ) {
99107 callbacks . push ( callback ) ;
@@ -116,8 +124,8 @@ class OperationMergerBackend {
116124 : null ;
117125 this . provideSync = this . _syncProvider
118126 ? /**
119- * @param {string } path path
120- * @param {any } options options
127+ * @param {PathLike | PathOrFileDescriptor } path path
128+ * @param {object= } options options
121129 * @returns {any } result
122130 */
123131 ( path , options ) => {
@@ -213,10 +221,16 @@ class CacheBackend {
213221 callback = options ;
214222 options = undefined ;
215223 }
216- if ( typeof path !== "string" ) {
217- callback ( new TypeError ( "path must be a string" ) ) ;
224+ if (
225+ typeof path !== "string" &&
226+ ! Buffer . isBuffer ( path ) &&
227+ ! ( path instanceof URL ) &&
228+ typeof path !== "number"
229+ ) {
230+ callback ( new TypeError ( "path must be a string, Buffer, URL or number" ) ) ;
218231 return ;
219232 }
233+ const strPath = typeof path !== "string" ? path . toString ( ) : path ;
220234 if ( options ) {
221235 return /** @type {Function } */ ( this . _provider ) . call (
222236 this . _providerContext ,
@@ -232,19 +246,19 @@ class CacheBackend {
232246 }
233247
234248 // Check in cache
235- let cacheEntry = this . _data . get ( path ) ;
249+ let cacheEntry = this . _data . get ( strPath ) ;
236250 if ( cacheEntry !== undefined ) {
237251 if ( cacheEntry . err ) return nextTick ( callback , cacheEntry . err ) ;
238252 return nextTick ( callback , null , cacheEntry . result ) ;
239253 }
240254
241255 // Check if there is already the same operation running
242- let callbacks = this . _activeAsyncOperations . get ( path ) ;
256+ let callbacks = this . _activeAsyncOperations . get ( strPath ) ;
243257 if ( callbacks !== undefined ) {
244258 callbacks . push ( callback ) ;
245259 return ;
246260 }
247- this . _activeAsyncOperations . set ( path , ( callbacks = [ callback ] ) ) ;
261+ this . _activeAsyncOperations . set ( strPath , ( callbacks = [ callback ] ) ) ;
248262
249263 // Run the operation
250264 /** @type {Function } */
@@ -256,8 +270,8 @@ class CacheBackend {
256270 * @param {any } [result] result
257271 */
258272 ( err , result ) => {
259- this . _activeAsyncOperations . delete ( path ) ;
260- this . _storeResult ( path , err , result ) ;
273+ this . _activeAsyncOperations . delete ( strPath ) ;
274+ this . _storeResult ( strPath , err , result ) ;
261275
262276 // Enter async mode if not yet done
263277 this . _enterAsyncMode ( ) ;
@@ -277,9 +291,15 @@ class CacheBackend {
277291 * @returns {any } result
278292 */
279293 provideSync ( path , options ) {
280- if ( typeof path !== "string" ) {
294+ if (
295+ typeof path !== "string" &&
296+ ! Buffer . isBuffer ( path ) &&
297+ ! ( path instanceof URL ) &&
298+ typeof path !== "number"
299+ ) {
281300 throw new TypeError ( "path must be a string" ) ;
282301 }
302+ const strPath = typeof path !== "string" ? path . toString ( ) : path ;
283303 if ( options ) {
284304 return /** @type {Function } */ ( this . _syncProvider ) . call (
285305 this . _providerContext ,
@@ -294,16 +314,16 @@ class CacheBackend {
294314 }
295315
296316 // Check in cache
297- let cacheEntry = this . _data . get ( path ) ;
317+ let cacheEntry = this . _data . get ( strPath ) ;
298318 if ( cacheEntry !== undefined ) {
299319 if ( cacheEntry . err ) throw cacheEntry . err ;
300320 return cacheEntry . result ;
301321 }
302322
303323 // Get all active async operations
304324 // This sync operation will also complete them
305- const callbacks = this . _activeAsyncOperations . get ( path ) ;
306- this . _activeAsyncOperations . delete ( path ) ;
325+ const callbacks = this . _activeAsyncOperations . get ( strPath ) ;
326+ this . _activeAsyncOperations . delete ( strPath ) ;
307327
308328 // Run the operation
309329 // When in idle mode, we will enter sync mode
@@ -314,14 +334,14 @@ class CacheBackend {
314334 path
315335 ) ;
316336 } catch ( err ) {
317- this . _storeResult ( path , /** @type {Error } */ ( err ) , undefined ) ;
337+ this . _storeResult ( strPath , /** @type {Error } */ ( err ) , undefined ) ;
318338 this . _enterSyncModeWhenIdle ( ) ;
319339 if ( callbacks ) {
320340 runCallbacks ( callbacks , /** @type {Error } */ ( err ) , undefined ) ;
321341 }
322342 throw err ;
323343 }
324- this . _storeResult ( path , null , result ) ;
344+ this . _storeResult ( strPath , null , result ) ;
325345 this . _enterSyncModeWhenIdle ( ) ;
326346 if ( callbacks ) {
327347 runCallbacks ( callbacks , null , result ) ;
@@ -330,7 +350,7 @@ class CacheBackend {
330350 }
331351
332352 /**
333- * @param {string | string[] | Set<string> } [what] what to purge
353+ * @param {string | Buffer | URL | number | ( string | URL | Buffer | number) [] | Set<string | URL | Buffer | number > } [what] what to purge
334354 */
335355 purge ( what ) {
336356 if ( ! what ) {
@@ -341,9 +361,15 @@ class CacheBackend {
341361 }
342362 this . _enterIdleMode ( ) ;
343363 }
344- } else if ( typeof what === "string" ) {
364+ } else if (
365+ typeof what === "string" ||
366+ Buffer . isBuffer ( what ) ||
367+ what instanceof URL ||
368+ typeof what === "number"
369+ ) {
370+ const strWhat = typeof what !== "string" ? what . toString ( ) : what ;
345371 for ( let [ key , data ] of this . _data ) {
346- if ( key . startsWith ( what ) ) {
372+ if ( key . startsWith ( strWhat ) ) {
347373 this . _data . delete ( key ) ;
348374 data . level . delete ( key ) ;
349375 }
@@ -354,7 +380,8 @@ class CacheBackend {
354380 } else {
355381 for ( let [ key , data ] of this . _data ) {
356382 for ( const item of what ) {
357- if ( key . startsWith ( item ) ) {
383+ const strItem = typeof item !== "string" ? item . toString ( ) : item ;
384+ if ( key . startsWith ( strItem ) ) {
358385 this . _data . delete ( key ) ;
359386 data . level . delete ( key ) ;
360387 break ;
@@ -368,17 +395,24 @@ class CacheBackend {
368395 }
369396
370397 /**
371- * @param {string| string[]| Set<string> } [what] what to purge
398+ * @param {string | Buffer | URL | number | ( string | URL | Buffer | number)[] | Set<string | URL | Buffer | number > } [what] what to purge
372399 */
373400 purgeParent ( what ) {
374401 if ( ! what ) {
375402 this . purge ( ) ;
376- } else if ( typeof what === "string" ) {
377- this . purge ( dirname ( what ) ) ;
403+ } else if (
404+ typeof what === "string" ||
405+ Buffer . isBuffer ( what ) ||
406+ what instanceof URL ||
407+ typeof what === "number"
408+ ) {
409+ const strWhat = typeof what !== "string" ? what . toString ( ) : what ;
410+ this . purge ( dirname ( strWhat ) ) ;
378411 } else {
379412 const set = new Set ( ) ;
380413 for ( const item of what ) {
381- set . add ( dirname ( item ) ) ;
414+ const strItem = typeof item !== "string" ? item . toString ( ) : item ;
415+ set . add ( dirname ( strItem ) ) ;
382416 }
383417 this . purge ( set ) ;
384418 }
@@ -616,7 +650,7 @@ module.exports = class CachedInputFileSystem {
616650 }
617651
618652 /**
619- * @param {string| string[]| Set<string> } [what] what to purge
653+ * @param {string | Buffer | URL | number | ( string | URL | Buffer | number)[] | Set<string | URL | Buffer | number > } [what] what to purge
620654 */
621655 purge ( what ) {
622656 this . _statBackend . purge ( what ) ;
0 commit comments