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

wipe-node-cache

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

wipe-node-cache - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

examples/list.js

9

examples/pure.js

@@ -1,3 +0,3 @@

var path = require('path'),
wipe = require("../index");
var path = require('path');
var wipe = require("../index");

@@ -14,2 +14,5 @@

return !resolver(null, moduleName);
});
});
wipe.allButNodeModules();
wipe.all();

@@ -14,2 +14,5 @@ var Module = require('module');

* @param {Function} [waveCallback] function(moduleName) which shall return false, if parent module must not be wiped.
*
* @name wipeCache
* @function
*/

@@ -56,2 +59,58 @@ function wipeCache(stubs, resolver, waveCallback) {

/**
* Wipes everything
* @name wipeCache.all
* @function
*/
wipeCache.all = function () {
var returnTrue = function () {
return true;
};
wipeCache(null, returnTrue, returnTrue);
};
/**
* Wipes everything except node_modules
* @name wipeCache.allButNodeModules
* @function
*/
wipeCache.allButNodeModules = function () {
function resolver(stubs, fileName, module) {
return !fileName.indexOf('node_modules') > 0
}
// wipe everything, except node_modules
wipeCache(null, resolver, function (moduleName) {
return !resolver(null, moduleName);
});
};
/**
* Wipes modules by list of matches
* @param {String[]} matches - list of expressions
* @name wipeCache.match
* @function
*/
wipeCache.match = function (matches) {
function resolver(stubs, fileName, module) {
var dirname = module ? path.dirname(module) : '';
var requireName = fileName;
if (dirname) {
requireName = fileName.charAt(0) == '.' ? path.normalize(dirname + '/' + fileName) : fileName;
}
for (var i in stubs) {
if (requireName.match(stubs[i])) {
return stubs[i];
}
}
}
wipeCache(matches, resolver, function () {
return true;
});
};
module.exports = wipeCache;
{
"name": "wipe-node-cache",
"version": "1.0.1",
"version": "1.0.2",
"description": "Wipes node.js cache in a controled way.",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -17,2 +17,11 @@ **Keep your cache clear** – as my mom always says.

```js
wipe.all();
wipe.allButNodeModules();
wipe(stubs, resolver, waveCallback); // see API below
```
Little example
```js
//or, you can
// foo.js

@@ -34,3 +43,3 @@ var i = 0;

wipe(null, function(){return true;})
wipe(null, function(){return true;}); // will wipe everythinh

@@ -50,3 +59,3 @@ require('./foo')();

After first pass wipe will enter bubbling stage, and will wipe all modules, which use first ones.
After first pass wipe will enter bubbling stage, and will wipe all modules, which use already wiped ones.
Each time _bubbleCallback_ will be called with 1 argument - moduleName.

@@ -70,2 +79,4 @@ And you can decide - purge it, or not.

```js
// create custom resolver
function resolver(stubs, fileName, module) {

@@ -86,3 +97,3 @@ var dirname = module ? path.dirname(module) : '';

// wipe anything from helpers, and app.js.
// but keep hands off node_modules and core during bubbling.
// but keep hands off everything else, for example – node_modules and core during bubbling.
wipe({

@@ -96,4 +107,6 @@ 'helpers/*': true,

Wiping everying is bad idea, wiping node_modules is bad idea, you should wipe only your own things, or even just selected ones.
## Related
- [proxyquire](https://github.com/thlorenz/proxyquire) - Usefull testing tool, but with bad caching politics.

@@ -62,2 +62,44 @@ /*jshint asi:true*/

it('should reset everything', function () {
//wipe all
wipe(null, function () {
return true
});
var a = require('./src/a.js');
assert.equal(a.fn(), 1);
var a1 = require('./src/a.js');
assert.equal(a1.fn(), 2);
assert.equal(a.b_fn(), 1);
wipe.all();
assert.equal(a.b_fn(), 2);
var b = require('./src/b.js');
assert.equal(b.fn(), 1);
});
it('should reset by list', function () {
//wipe all
wipe(null, function () {
return true
});
var a = require('./src/a.js');
assert.equal(a.fn(), 1);
var a1 = require('./src/a.js');
assert.equal(a1.fn(), 2);
assert.equal(a.b_fn(), 1);
wipe.match([
/wipeNodeCache\/test\/src/
]);
assert.equal(a.b_fn(), 2);
var b = require('./src/b.js');
assert.equal(b.fn(), 1);
});
if (1) {

@@ -64,0 +106,0 @@ it('should reset deep module module', function () {

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