Skip to content

Commit

Permalink
Cleanup temporal module from a cache, fixes thlorenz#174
Browse files Browse the repository at this point in the history
  • Loading branch information
theKashey authored Apr 21, 2021
1 parent 6bade44 commit f784968
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/proxyquire.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,13 @@ Proxyquire.prototype._disableModuleCache = function (path, module) {

// Return a function that will undo what we just did
return function () {
const currentModule = Module._cache[id];
const currentModuleParent = currentModule.parent;
// remove reference to a temporal module from a parent
if (currentModuleParent && currentModuleParent.children) {
currentModuleParent.children = currentModuleParent.children.filter(m => m !== currentModule)
}
// restore cache entry
if (cached) {
Module._cache[id] = cached
} else {
Expand Down

0 comments on commit f784968

Please sign in to comment.