Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup temporal module from a cache, fixes #174 #261

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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