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

nm-cache

v1.2.0

Published

Have you ever been in the situation where someone asks you to `git checkout` their branch, and you hesitate?

Downloads

10

Readme

nm-cache

Have you ever been in the situation where someone asks you to git checkout their branch, and you hesitate?

If you have, and if it is because you're not interested in helping others, this package won't be of use to you. You're probably a jerk, and that's not a software problem.

However, if you hesitate because your project's dependencies change often, and npm install takes forever, nm-cache might be able to help!

The project may also be of use if you need to test a project between multiple versions of Node. If you use something like nodenv or nvm, you'll need to globally install nm-cache for each Node version, but there should be no other constraints.

Use

  • npm install -g nm-cache
  • Enjoy!

Note: nm-cache requires a POSIX-compatible environment to work. OSX and most Linux flavors should work out-of-the-box. Windows 10 with its new Ubuntu mode might work too, although it hasn't been tested.

Common workflow

Let's say you want to checkout someone else's branch, but you don't want to wait forever. Here's what you would do:

nm-cache save
git checkout other-branch
nm-cache restore || (npm install && nm-cache save)

# Do all the things...

git checkout original-branch
nm-cache restore

Or maybe your project.json changes relatively often, but you don't want to check it manually every time you pull down the latest master:

git pull origin master
git diff-tree -r --name-only --no-commit-id HEAD@{1} HEAD | \
    grep --quiet "package.json" && \
    npm install && \
    nm-cache save

If you want this to be automated, make it into a post-merge git hook.

Options

Usage: nm-cache <command> [options]

  This utility helps you stash particular versions of your node_modules
  directories with minimal overhead.  Later you can restore them.

  This can be useful when, for example, you switch between branches that have
  different dependencies or versions, or if you need to switch between Node
  run-time versions.

Commands:
  save     Save a snapshot of your current node_modules.
  restore  Restore a saved snapshot, anchored to package.json
  check    Exit with 0 if already cached, exit with 1 otherwise.

Options:
  --package-json  `package.json` to use as node_modules anchor point (optional).
  --force         Overwrite pre-existing node_modules cache (optional).
  --hash          Indicates which cached directory to restore (optional).
  --help          Show help                                            [boolean]

Under the Hood

You may notice that nm-cache is relatively quick about its business. This is because it does not make copies of your node_modules subdirectories. Instead, it creates a directory structure that matches your existing node_modules and hard-links the files.

One side benefit of this approach is that there will only ever be one physical copy of each snapshot stored on disk, including the node_modules directory itself. Of course, multiple snapshots with partially-identical contents will not be de-duplicated, as that would require some tight integration with npm or a heavy hash-every-file approach like git.

You may also notice that nm-cache doesn't require that you specify any unique identifier for your snapshot. This is because, by default, it will create a hash of your package.json file and use this to uniquely identify the snapshot when they're saved.

Similarly, when you're restoring, it'll hash your package.json and look to see whether a snapshot has already been made. If so, you won't have to npm install again!