Skip to content

Commit 0334416

Browse files
fix: purge
1 parent 074e44f commit 0334416

File tree

2 files changed

+32
-10
lines changed

2 files changed

+32
-10
lines changed

lib/CachedInputFileSystem.js

+23-9
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ class CacheBackend {
350350
}
351351

352352
/**
353-
* @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
354354
*/
355355
purge(what) {
356356
if (!what) {
@@ -361,9 +361,15 @@ class CacheBackend {
361361
}
362362
this._enterIdleMode();
363363
}
364-
} 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;
365371
for (let [key, data] of this._data) {
366-
if (key.startsWith(what)) {
372+
if (key.startsWith(strWhat)) {
367373
this._data.delete(key);
368374
data.level.delete(key);
369375
}
@@ -374,7 +380,8 @@ class CacheBackend {
374380
} else {
375381
for (let [key, data] of this._data) {
376382
for (const item of what) {
377-
if (key.startsWith(item)) {
383+
const strItem = typeof item !== "string" ? item.toString() : item;
384+
if (key.startsWith(strItem)) {
378385
this._data.delete(key);
379386
data.level.delete(key);
380387
break;
@@ -388,17 +395,24 @@ class CacheBackend {
388395
}
389396

390397
/**
391-
* @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
392399
*/
393400
purgeParent(what) {
394401
if (!what) {
395402
this.purge();
396-
} else if (typeof what === "string") {
397-
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));
398411
} else {
399412
const set = new Set();
400413
for (const item of what) {
401-
set.add(dirname(item));
414+
const strItem = typeof item !== "string" ? item.toString() : item;
415+
set.add(dirname(strItem));
402416
}
403417
this.purge(set);
404418
}
@@ -636,7 +650,7 @@ module.exports = class CachedInputFileSystem {
636650
}
637651

638652
/**
639-
* @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
640654
*/
641655
purge(what) {
642656
this._statBackend.purge(what);

types.d.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,15 @@ declare class CachedInputFileSystem {
7575
readlinkSync: ReadlinkSync;
7676
realpath?: RealPath;
7777
realpathSync?: RealPathSync;
78-
purge(what?: string | Set<string> | string[]): void;
78+
purge(
79+
what?:
80+
| string
81+
| number
82+
| Buffer
83+
| URL_url
84+
| (string | number | Buffer | URL_url)[]
85+
| Set<string | number | Buffer | URL_url>
86+
): void;
7987
}
8088
declare class CloneBasenamePlugin {
8189
constructor(

0 commit comments

Comments
 (0)