4 of 6 standards met
Due to v8 stack traces only going so many deep by default, modules deep enough in the dependency tree such that clear has been called >~8 times do not get cleared. This is because resolve/parentModule relies on the v8 stack trace. It seems to me we don't need to resolve moduleId when calling it recursively from within clear, since children are absolute paths. I've copied this module into our project and fixed as so:
Hey we've been using this module a bit, and I've encountered an issue with it. It seems you don't filter out native module, and as per nodejs documentation this causes bad behavior when re-requiring code later on. This documentation as been added there : https://github.com/nodejs/node/commit/5c14d695d2c1f924cf06af6ae896027569993a5c To reproduce, clear-module and reimport any library that internally uses a native library ( '.node' file ) I'm getting an when requiring it back and more specifically when the codes tries to call a function (that's within the .node )
Summary Fixes #18 — clear-module doesn't skip native modules. Problem clear-module currently removes native modules ( files) from . Re-requiring these after deletion causes , per the Node.js documentation linked in #18. Solution Skip files early in — just return without attempting to delete them from the cache. This matches the documented Node.js behavior. Testing Existing tests pass. This change is purely additive — it only adds an early return for native modules, no behavior change for JS modules.
When clearing a module, certain child modules seem to be skipped. This seems to be because the array is mutated with an -call inside the next recursive call to , skipping certain indices in the outer -loop over children. Making a new array fixes the issue. Looking at the test , before using , is executed. I am not sure if this is part of the expected usage of the function, but the test fails if it is removed. If you swap the order of the imports in , the test succeeds. I chose to split the commits into three so that you may first review the failing test, and then consider how the fix should look.
Repository: sindresorhus/clear-module. Description: Clear a module from the cache Stars: 184, Forks: 18. Primary language: JavaScript. Languages: JavaScript (98.6%), TypeScript (1.4%). License: MIT. Open PRs: 0, open issues: 3. Last activity: 1mo ago. Community health: 71%. Top contributors: sindresorhus, omrilotan, BendingBender, mrchief, Richienb, sondregj.