Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

decache

Package Overview
Dependencies
Maintainers
2
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

decache - npm Package Compare versions

Comparing version 3.1.0 to 4.0.0

55

decache.js
var path = require('path'); // if module is locally defined we path.resolve it
var find = require('find'); // https://www.npmjs.com/package/find
require.getRootDir = function () {
var keys = Object.keys(require.cache);
var parent = keys[0]; // the module that required decache
/* istanbul ignore else */
if(parent.indexOf('node_modules') > -1) {
var end = parent.indexOf('node_modules');
parent = parent.substring(0, end);
} else {
parent = path.resolve(path.normalize(parent +'../../..')); // resolve up!
}
return parent;
}
require.find = function (moduleName) {
var parent = require.getRootDir();
// a locally defined module
if(moduleName.indexOf('/') > -1) {
// console.log("BEFORE: "+moduleName);
var last = moduleName.lastIndexOf('/');
// strip everything before the forward slash
moduleName = moduleName.substring(last, moduleName.length).replace('/', '');
// console.log('AFTER: '+moduleName);
var mod;
var ext = path.extname(moduleName);
if(ext === '') {
mod = moduleName + '\.js'; // append .js to file type by default
}
else {
mod = moduleName.replace(ext, '\\' + ext); // escape extension for regex
}
var re = new RegExp(mod,"g"); // regex to use when finding the file
var files = find.fileSync(re, parent);
var file;
var keys = Object.keys(require.cache);
for (var i = 0; i < files.length; i++) {
var f = files[i];
if(keys.indexOf(f) > -1) { // won't this *always* be true?
file = f;
break;
}
}
return file;
} else {
return moduleName;
if (moduleName[0] === '.') {
moduleName = path.resolve(path.dirname(module.parent.filename), moduleName);
}
}
try {
return require.resolve(moduleName);
} catch (e) {
return;
}
};

@@ -53,0 +14,0 @@ /**

20

package.json
{
"name": "decache",
"version": "3.1.0",
"version": "4.0.0",
"description": "decache (Delete Cache) lets you delete modules from node.js require() cache; useful when testing your modules/projects.",

@@ -9,4 +9,3 @@ "main": "decache.js",

"test": "./node_modules/.bin/istanbul cover ./node_modules/tape/bin/tape ./test/*.js",
"coverage": "./node_modules/.bin/istanbul cover ./node_modules/tape/bin/tape ./test/*.js && ./node_modules/.bin/istanbul check-coverage --statements 100 --functions 100 --lines 100 --branches 100",
"jshint": "./node_modules/jshint/bin/jshint -c .jshintrc --exclude-path .gitignore ."
"coverage": "./node_modules/.bin/istanbul cover ./node_modules/tape/bin/tape ./test/*.js && ./node_modules/.bin/istanbul check-coverage --statements 100 --functions 100 --lines 100 --branches 100"
},

@@ -25,3 +24,3 @@ "repository": {

],
"author": "@besarthoxhaj & @nelsonic (with help from StackOverflow)",
"author": "@besarthoxhaj, @jupiter & @nelsonic (with help from StackOverflow)",
"license": "MIT",

@@ -36,15 +35,10 @@ "bugs": {

"devDependencies": {
"istanbul": "^0.4.2",
"jshint": "^2.9.1",
"pre-commit": "^1.1.2",
"istanbul": "^0.4.4",
"pre-commit": "^1.1.3",
"tap-spec": "^4.1.1",
"tape": "^4.4.0"
"tape": "^4.6.0"
},
"pre-commit": [
"jshint",
"coverage"
],
"dependencies": {
"find": "^0.2.4"
}
]
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc