recursive-uncache
Advanced tools
Comparing version 0.0.1 to 0.1.0
{ | ||
"name": "recursive-uncache", | ||
"description": "recursively uncache required files", | ||
"version": "0.0.1", | ||
"version": "0.1.0", | ||
"homepage": "https://github.com/paulpflug/", | ||
@@ -24,3 +24,3 @@ "author": { | ||
"devDependencies": { | ||
"coffee-script": "^1.12.4" | ||
"coffeescript": "^2.0.0-alpha1" | ||
}, | ||
@@ -27,0 +27,0 @@ "keywords": [ |
@@ -19,3 +19,3 @@ # recursive-uncache | ||
uncache(module,base=".") // module must be a absolute path | ||
uncache(module,base=".",verbose=false) // module must be a absolute path | ||
// example with chokidar | ||
@@ -22,0 +22,0 @@ chokidar.watch(["./src"],{ignoreInitial: true}) |
(function() { | ||
module.exports = function(filepath, base) { | ||
module.exports = function(filepath, base = ".", verbose) { | ||
var id, mod, ref, results; | ||
if (base == null) { | ||
base = "."; | ||
} | ||
if ((mod = require.cache[filepath]) != null) { | ||
delete require.cache[filepath]; | ||
console.log("deleted cache for " + filepath); | ||
if (verbose) { | ||
console.log(`deleted cache for ${filepath}`); | ||
} | ||
results = []; | ||
while ((id = (ref = mod.parent) != null ? ref.id : void 0) !== base) { | ||
delete require.cache[id]; | ||
console.log("deleted cache for " + id); | ||
if (verbose) { | ||
console.log(`deleted cache for ${id}`); | ||
} | ||
results.push(mod = mod.parent); | ||
@@ -15,0 +16,0 @@ } |
2187
20