Skip to content

Commit

Permalink
fix: purge
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait committed Mar 7, 2024
1 parent 074e44f commit 0334416
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 10 deletions.
32 changes: 23 additions & 9 deletions lib/CachedInputFileSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ class CacheBackend {
}

/**
* @param {string | string[] | Set<string>} [what] what to purge
* @param {string | Buffer | URL | number | (string | URL | Buffer | number)[] | Set<string | URL | Buffer | number>} [what] what to purge
*/
purge(what) {
if (!what) {
Expand All @@ -361,9 +361,15 @@ class CacheBackend {
}
this._enterIdleMode();
}
} else if (typeof what === "string") {
} else if (
typeof what === "string" ||
Buffer.isBuffer(what) ||
what instanceof URL ||
typeof what === "number"
) {
const strWhat = typeof what !== "string" ? what.toString() : what;
for (let [key, data] of this._data) {
if (key.startsWith(what)) {
if (key.startsWith(strWhat)) {
this._data.delete(key);
data.level.delete(key);
}
Expand All @@ -374,7 +380,8 @@ class CacheBackend {
} else {
for (let [key, data] of this._data) {
for (const item of what) {
if (key.startsWith(item)) {
const strItem = typeof item !== "string" ? item.toString() : item;
if (key.startsWith(strItem)) {
this._data.delete(key);
data.level.delete(key);
break;
Expand All @@ -388,17 +395,24 @@ class CacheBackend {
}

/**
* @param {string | string[] | Set<string>} [what] what to purge
* @param {string | Buffer | URL | number | (string | URL | Buffer | number)[] | Set<string | URL | Buffer | number>} [what] what to purge
*/
purgeParent(what) {
if (!what) {
this.purge();
} else if (typeof what === "string") {
this.purge(dirname(what));
} else if (
typeof what === "string" ||
Buffer.isBuffer(what) ||
what instanceof URL ||
typeof what === "number"
) {
const strWhat = typeof what !== "string" ? what.toString() : what;
this.purge(dirname(strWhat));
} else {
const set = new Set();
for (const item of what) {
set.add(dirname(item));
const strItem = typeof item !== "string" ? item.toString() : item;
set.add(dirname(strItem));
}
this.purge(set);
}
Expand Down Expand Up @@ -636,7 +650,7 @@ module.exports = class CachedInputFileSystem {
}

/**
* @param {string|string[]|Set<string>} [what] what to purge
* @param {string | Buffer | URL | number | (string | URL | Buffer | number)[] | Set<string | URL | Buffer | number>} [what] what to purge
*/
purge(what) {
this._statBackend.purge(what);
Expand Down
10 changes: 9 additions & 1 deletion types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,15 @@ declare class CachedInputFileSystem {
readlinkSync: ReadlinkSync;
realpath?: RealPath;
realpathSync?: RealPathSync;
purge(what?: string | Set<string> | string[]): void;
purge(
what?:
| string
| number
| Buffer
| URL_url
| (string | number | Buffer | URL_url)[]
| Set<string | number | Buffer | URL_url>
): void;
}
declare class CloneBasenamePlugin {
constructor(
Expand Down

0 comments on commit 0334416

Please sign in to comment.