Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
wipe-node-cache
Advanced tools
Keep your cache clear – as my mom always says.
wipeNodeCache – cleans, clears and wipes all old dirty modules from node.js internal require.cache.
Useful for testing purposes when you need to freshly require a module. Or two. Or just keep all modules fresh, for example for proxyquire.
$ npm install --save wipe-node-cache
wipe.all();
wipe.allButNodeModules();
wipe(stubs, resolver, waveCallback); // see API below
Little example
//or, you can
// foo.js
var i = 0;
module.exports = function () {
return ++i;
};
var wipe = require('wipe-node-cache');
require('./foo')();
//=> 1
require('./foo')();
//=> 2
wipe(null, function(){return true;}); // will wipe everythinh
require('./foo')();
//=> 1 . Module is fresh now
But this is simply, and stupid way. We can do it better!
Foreach module in system wipe will call filterCallback with 2 arguments – object1 and moduleName(absolute)) And you shall return true, if you want to wipe this module.
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. And you can decide - purge it, or not.
(see examples in source)
function resolver(stubs, fileName, module) {
return !fileName.indexOf('node_modules') > 0
}
// wipe everything, except node_modules
wipe(null, resolver, function (moduleName) {
return !resolver(null, moduleName);
});
// create custom resolver
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.indexOf(i) > 0) {
return stubs[i];
}
}
}
// wipe anything from helpers, and app.js.
// but keep hands off everything else, for example – node_modules and core during bubbling.
wipe({
'helpers/*': true,
'App.js': true
}, resolver, function (moduleName) {
return !(moduleName.indexOf('node_modules') > 0) && !(moduleName.indexOf('core') > 0)
});
Wiping everying is bad idea, wiping node_modules is bad idea, you should wipe only your own things, or even just selected ones.
FAQs
Wipes node.js cache in a controlled way.
The npm package wipe-node-cache receives a total of 45,125 weekly downloads. As such, wipe-node-cache popularity was classified as popular.
We found that wipe-node-cache demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.