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

monkey-dont

v1.0.0

Published

A monkey-patch to stop monkey-patching

Downloads

2

Readme

monkey-dont

A monkey-patch to prevent monkey-patching.

This is a first try, largely un-tested, and probably buggy. Use at your own risk.

It works by rewriting Node's internal _load method to modify modules' exports in one of three ways:

  1. clone - Causes require to return a deep copy of module.exports.
  2. freeze - Causes require to recursively apply Object.freeze on module.exports before returning it.
  3. uncache - Causes require to delete the module from require.cache and re-load it the module's main .js file.

To deep-clone every module:

require('monkey-dont').monkey('clone');

To deep-freeze every module:

require('monkey-dont').monkey('freeze');

To un-cache every module, except built-ins, which can't be un-cached:

require('monkey-dont').monkey('uncache');

To uncache all modules by default but freeze the built-ins:

require('monkey-dont').monkey({
  all: 'uncache',
  builtin: 'freeze',
});

To clone fs and path, freeze the remaining built-ins, and un-cache the remaining non-built-ins:

require('monkey-dont').monkey({
  all: 'uncache',
  builtin: 'freeze',
  byname: {
    'fs': 'clone',
    'path': 'clone',
  },
});

To do all the above, except freeze the module foo instead of uncaching it:

require('monkey-dont').monkey({
  all: 'uncache',
  builtin: 'freeze',
  byname: {
    'fs': 'clone',
    'path': 'clone',
    'foo': 'freeze',
  },
});

To make the patch removable, keep the monkey-dont export instead of immediately calling monkey on it. Then call its unmonkey method to remove the patch.

(Note: This can't retroactively undo any cloning, freezing, and uncaching already done; it just returns require to its normal behavior. Future requires will return un-cloned, cached originals, but already-frozen modules will remain frozen on future requires.)

const md = require('monkey-dont');
md.monkey({
  // ...snip...
});
// ...snip...
md.unmonkey();