Socket
Socket
Sign inDemoInstall

stealthy-require

Package Overview
Dependencies
0
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.1.0 to 1.0.0

50

lib/index.js
'use strict';
var forEach = require('lodash/forEach'),
assign = require('lodash/assign');
function forEach(obj, callback) {
for ( var key in obj ) {
if (!Object.prototype.hasOwnProperty.call(obj, key)) {
continue;
}
callback(key);
}
}
module.exports = function stealthyRequire$init(require) {
function clearCache() {
forEach(require.cache, function (cachedModule, resolvedPath) {
if (resolvedPath.match(/\.node$/) === null) {
delete require.cache[resolvedPath];
}
});
function assign(target, source) {
var keys = [];
forEach(source, function (key) {
keys.push(key);
});
for ( var i = 0; i < keys.length; i+=1 ) {
target[keys[i]] = source[keys[i]];
}
return target;
}
return function stealthyRequire$exec(path) {
function clearCache(requireCache) {
forEach(requireCache, function (resolvedPath) {
if (resolvedPath.match(/\.node$/) === null) {
delete requireCache[resolvedPath];
}
});
}
var temp = assign({}, require.cache);
clearCache();
module.exports = function (requireCache, callback) {
var freshModule = require(path);
var temp = assign({}, requireCache);
clearCache(requireCache);
clearCache();
assign(require.cache, temp);
var freshModule = callback();
return freshModule;
clearCache(requireCache);
assign(requireCache, temp);
};
return freshModule;
};
{
"name": "stealthy-require",
"version": "0.1.0",
"version": "1.0.0",
"description": "The closest you can get to require something with bypassing the require cache",

@@ -14,3 +14,6 @@ "keywords": [

"scripts": {
"test": "./node_modules/.bin/gulp ci"
"test": "./node_modules/.bin/gulp ci",
"test-publish": "./node_modules/.bin/gulp ci-no-cov",
"publish-please": "publish-please",
"prepublish": "publish-please guard"
},

@@ -30,17 +33,19 @@ "repository": {

},
"dependencies": {
"lodash": "^4.13.1"
},
"dependencies": {},
"devDependencies": {
"bcrypt": "^0.8.6",
"chai": "^3.5.0",
"chalk": "^1.1.3",
"gulp": "^3.9.1",
"gulp-coveralls": "^0.1.4",
"gulp-eslint": "^2.0.0",
"gulp-istanbul": "^0.10.4",
"gulp-mocha": "^2.2.0",
"rimraf": "^2.5.2",
"run-sequence": "^1.2.1"
"bcrypt": "~0.8.7",
"browserify": "~13.0.1",
"chai": "~3.5.0",
"chalk": "~1.1.3",
"gulp": "~3.9.1",
"gulp-coveralls": "~0.1.4",
"gulp-eslint": "~2.1.0",
"gulp-istanbul": "~1.0.0",
"gulp-mocha": "~2.2.0",
"mkdirp": "~0.5.1",
"publish-please": "~2.1.4",
"rimraf": "~2.5.3",
"run-sequence": "~1.2.2",
"webpack": "~1.13.1"
}
}

@@ -37,5 +37,7 @@ # Stealthy-Require

``` js
var stealthyRequire = require('stealthy-require')(require);
var stealthyRequire = require('stealthy-require');
var requestFresh = stealthyRequire('request');
var requestFresh = stealthyRequire(require.cache, function () {
return require('request');
});
```

@@ -45,2 +47,14 @@

## Usage with Module Bundlers
- [Webpack](https://webpack.github.io) works out-of-the-box like described in the [Usage section](#usage) above.
- [Browserify](http://browserify.org) does not expose `require.cache`. However, as of `browserify@13.0.1` the cache is passed as the 6th argument to CommonJS modules. Thus you can pass this argument instead:
``` js
// Tweak for Browserify - using arguments[5] instead of require.cache
var requestFresh = stealthyRequire(arguments[5], function () {
return require('request');
});
```
## Contributing

@@ -62,2 +76,5 @@

- v1.0.0 (2016-07-18)
- **Breaking Change:** API completely changed. Please read the [Usage section](#usage) again.
- Redesigned library to support module bundlers like [Webpack](https://webpack.github.io) and [Browserify](http://browserify.org)
- v0.1.0 (2016-05-26)

@@ -64,0 +81,0 @@ - Initial version

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc