npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

wipe-webpack-cache

v2.1.0

Published

Wipes webpack cache in a controled way.

Downloads

211,713

Readme

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)
});

Related

  • proxyquire - Usefull testing tool, but with bad caching politics.