Comparing version 4.4.1 to 4.5.0
@@ -28,19 +28,19 @@ var path = require('path'); // if module is locally defined we path.resolve it | ||
moduleName = require.find(moduleName); | ||
moduleName = require.find(moduleName); | ||
if(!moduleName) {return;} | ||
if(!moduleName) { return; } | ||
// Run over the cache looking for the files | ||
// loaded by the specified module name | ||
require.searchCache(moduleName, function (mod) { | ||
delete require.cache[mod.id]; | ||
}); | ||
// Run over the cache looking for the files | ||
// loaded by the specified module name | ||
require.searchCache(moduleName, function (mod) { | ||
delete require.cache[mod.id]; | ||
}); | ||
// Remove cached paths to the module. | ||
// Thanks to @bentael for pointing this out. | ||
Object.keys(module.constructor._pathCache).forEach(function(cacheKey) { | ||
if (cacheKey.indexOf(moduleName)>0) { | ||
delete module.constructor._pathCache[cacheKey]; | ||
} | ||
}); | ||
// Remove cached paths to the module. | ||
// Thanks to @bentael for pointing this out. | ||
Object.keys(module.constructor._pathCache).forEach(function (cacheKey) { | ||
if (cacheKey.indexOf(moduleName) > -1) { | ||
delete module.constructor._pathCache[cacheKey]; | ||
} | ||
}); | ||
}; | ||
@@ -53,30 +53,30 @@ | ||
require.searchCache = function (moduleName, callback) { | ||
// Resolve the module identified by the specified name | ||
var mod = require.resolve(moduleName); | ||
var visited = {}; | ||
// Resolve the module identified by the specified name | ||
var mod = require.resolve(moduleName); | ||
var visited = {}; | ||
// Check if the module has been resolved and found within | ||
// the cache no else so #ignore else http://git.io/vtgMI | ||
/* istanbul ignore else */ | ||
if (mod && ((mod = require.cache[mod]) !== undefined)) { | ||
// Recursively go over the results | ||
(function run(current) { | ||
visited[current.id] = true; | ||
// Go over each of the module's children and | ||
// run over it | ||
current.children.forEach(function (child) { | ||
// ignore .node files, decachine native modules throws a | ||
// "module did not self-register" error on second require | ||
if (path.extname(child.filename) !== '.node' && !visited[child.id]) { | ||
run(child); | ||
} | ||
}); | ||
// Check if the module has been resolved and found within | ||
// the cache no else so #ignore else http://git.io/vtgMI | ||
/* istanbul ignore else */ | ||
if (mod && ((mod = require.cache[mod]) !== undefined)) { | ||
// Recursively go over the results | ||
(function run(current) { | ||
visited[current.id] = true; | ||
// Go over each of the module's children and | ||
// run over it | ||
current.children.forEach(function (child) { | ||
// ignore .node files, decachine native modules throws a | ||
// "module did not self-register" error on second require | ||
if (path.extname(child.filename) !== '.node' && !visited[child.id]) { | ||
run(child); | ||
} | ||
}); | ||
// Call the specified callback providing the | ||
// found module | ||
callback(current); | ||
})(mod); | ||
} | ||
// Call the specified callback providing the | ||
// found module | ||
callback(current); | ||
})(mod); | ||
} | ||
}; | ||
module.exports = require.decache; |
{ | ||
"name": "decache", | ||
"version": "4.4.1", | ||
"version": "4.5.0", | ||
"description": "decache (Delete Cache) lets you delete modules from node.js require() cache; useful when testing your modules/projects.", | ||
@@ -23,3 +23,3 @@ "main": "decache.js", | ||
], | ||
"author": "@besarthoxhaj, @jupiter & @nelsonic (with help from StackOverflow)", | ||
"author": "https://github.com/dwyl/decache/graphs/contributors", | ||
"license": "MIT", | ||
@@ -34,7 +34,7 @@ "bugs": { | ||
"devDependencies": { | ||
"istanbul": "^0.4.4", | ||
"istanbul": "^0.4.5", | ||
"modern-syslog": "~1.1.4", | ||
"pre-commit": "^1.1.3", | ||
"tap-spec": "^4.1.1", | ||
"tape": "^4.6.0" | ||
"pre-commit": "^1.2.2", | ||
"tap-spec": "^5.0.0", | ||
"tape": "^4.9.1" | ||
}, | ||
@@ -41,0 +41,0 @@ "pre-commit": [ |
@@ -1,9 +0,13 @@ | ||
# decache | ||
# `decache` | ||
[![Build Status](https://travis-ci.org/dwyl/decache.svg)](https://travis-ci.org/dwyl/decache) | ||
[![codecov.io](https://codecov.io/github/dwyl/decache/coverage.svg?branch=master)](https://codecov.io/github/dwyl/decache?branch=master) | ||
[![Code Climate](https://codeclimate.com/github/dwyl/decache/badges/gpa.svg)](https://codeclimate.com/github/dwyl/decache) | ||
[![Dependency Status](https://david-dm.org/dwyl/decache.svg)](https://david-dm.org/dwyl/decache) | ||
[![devDependency Status](https://david-dm.org/dwyl/decache/dev-status.svg)](https://david-dm.org/dwyl/decache#info=devDependencies) | ||
Delete a module from node.js' `require.cache` so you can freshly `require` it again. | ||
[![Build Status](https://img.shields.io/travis/dwyl/decache/master.svg?style=flat-square)](https://travis-ci.org/dwyl/decache) | ||
[![codecov.io](https://img.shields.io/codecov/c/github/dwyl/decache/master.svg?style=flat-square)](http://codecov.io/github/dwyl/decache?branch=master) | ||
[![Code Climate maintainability](https://img.shields.io/codeclimate/maintainability/dwyl/decache.svg?style=flat-square)](https://github.com/dwyl/decache) | ||
[![Dependencies Status](https://david-dm.org/dwyl/decache/status.svg?style=flat-square)](https://david-dm.org/dwyl/decache) | ||
[![devDependencies Status](https://david-dm.org/dwyl/decache/dev-status.svg?style=flat-square)](https://david-dm.org/dwyl/decache?type=dev) | ||
[![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat-square)](https://github.com/dwyl/decache/issues) | ||
[![HitCount](http://hits.dwyl.io/dwyl/decache.svg)](http://hits.dwyl.io/dwyl/decache) | ||
In node.js when you `require()` a module, node stores a cached version of the | ||
@@ -27,3 +31,3 @@ module, so that all subsequent calls to `require()` do not have to reload | ||
### install | ||
### install | ||
@@ -30,0 +34,0 @@ Install the module from npm: |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
9664
69