mirror of
https://github.com/smogon/pokemon-showdown.git
synced 2026-09-14 20:25:36 -05:00
Utils: Ensure require cache clearing is exhaustive
Previously, this was limited by a depth check that always got hit, meaning it never fully properly cleaned out the module tree (most likely due to the fact the uncacheModuleTree call would loop around to the same module through recursion, meaning mod.children never got deleted, so it never stopped looping). This commit fixes that.
This commit is contained in:
11
lib/utils.ts
11
lib/utils.ts
@@ -314,13 +314,12 @@ export function clearRequireCache(options: {exclude?: string[]} = {}) {
|
||||
}
|
||||
}
|
||||
|
||||
export function uncacheModuleTree(mod: NodeJS.Module, excludes: string[], depth = 0) {
|
||||
depth++;
|
||||
if (depth >= 10) return;
|
||||
if (!mod.children || excludes.some(p => mod.filename.includes(p))) return;
|
||||
for (const child of mod.children) {
|
||||
export function uncacheModuleTree(mod: NodeJS.Module, excludes: string[]) {
|
||||
if (!mod.children?.length || excludes.some(p => mod.filename.includes(p))) return;
|
||||
for (const [i, child] of mod.children.entries()) {
|
||||
if (excludes.some(p => child.filename.includes(p))) continue;
|
||||
uncacheModuleTree(child, excludes, depth);
|
||||
mod.children?.splice(i, 1);
|
||||
uncacheModuleTree(child, excludes);
|
||||
}
|
||||
delete (mod as any).children;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user