Socket
Book a DemoInstallSign in
Socket

wipe-webpack-cache

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

wipe-webpack-cache

Wipes webpack cache in a controled way.

2.1.0
latest
Source
npmnpm
Version published
Weekly downloads
57K
0.67%
Maintainers
1
Weekly downloads
 
Created
Source

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.

Install

$ npm install --save wipe-node-cache
$ npm install --save wipe-webpack-cache

Usage

This library requires some extra API from webpack to work:

  • NamedModulesPlugin - to have names for files
  • HotModuleReplacementPlugin - to have parents information
// 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;})

require('./foo')();
//=> 1 . Module is fresh now

But this is simply, and stupid way. We can do it better!

API

wipe(object1, filterCallback, bubbleCallback)

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 first ones. Each time bubbleCallback will be called with 1 argument - moduleName. And you can decide - purge it, or not.

Examples

(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);
});
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 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)
});
  • proxyquire - Usefull testing tool, but with bad caching politics.

Keywords

webpack

FAQs

Package last updated on 09 Nov 2018

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.