clear-module
Advanced tools
+17
-5
@@ -12,2 +12,4 @@ 'use strict'; | ||
| const isNativeModule = filePath => path.extname(filePath) === '.node'; | ||
| const clear = moduleId => { | ||
@@ -24,2 +26,6 @@ if (typeof moduleId !== 'string') { | ||
| if (isNativeModule(filePath)) { | ||
| return; | ||
| } | ||
| // Delete itself from module parent | ||
@@ -50,6 +56,6 @@ if (require.cache[filePath] && require.cache[filePath].parent) { | ||
| clear.all = () => { | ||
| const directory = path.dirname(parentModule(__filename)); | ||
| for (const moduleId of Object.keys(require.cache)) { | ||
| delete require.cache[resolveFrom(directory, moduleId)]; | ||
| for (const filePath of Object.keys(require.cache)) { | ||
| if (!isNativeModule(filePath)) { | ||
| delete require.cache[filePath]; | ||
| } | ||
| } | ||
@@ -71,5 +77,11 @@ }; | ||
| delete require.cache[resolve(moduleId)]; | ||
| const filePath = resolve(moduleId); | ||
| if (!filePath || isNativeModule(filePath)) { | ||
| return; | ||
| } | ||
| delete require.cache[filePath]; | ||
| }; | ||
| module.exports = clear; |
+4
-2
| { | ||
| "name": "clear-module", | ||
| "version": "4.1.2", | ||
| "version": "4.1.3", | ||
| "description": "Clear a module from the cache", | ||
@@ -13,2 +13,3 @@ "license": "MIT", | ||
| }, | ||
| "sideEffects": false, | ||
| "engines": { | ||
@@ -18,3 +19,4 @@ "node": ">=8" | ||
| "scripts": { | ||
| "test": "xo && ava && tsd" | ||
| "//test": "xo && ava && tsd", | ||
| "test": "ava" | ||
| }, | ||
@@ -21,0 +23,0 @@ "files": [ |
+2
-2
@@ -9,5 +9,5 @@ # clear-module | ||
| ```sh | ||
| npm install clear-module | ||
| ``` | ||
| $ npm install clear-module | ||
| ``` | ||
@@ -14,0 +14,0 @@ ## Usage |
6269
3.4%103
9.57%