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

@nodenv/nodenv-package-rehash

v1.4.0

Published

Never run nodenv rehash again

Downloads

7

Readme

Build Status

nodenv-package-rehash

Never run nodenv rehash again. This nodenv plugin automatically runs nodenv rehash every time you install or uninstall a global package.

Installation

After installation, you should have a nodenv package-hooks subcommand, and the package-rehash hook should be included in the output of nodenv hooks install.

Then you may install the hooks for your existing nodenv versions. (This will be done automatically for any node you install henceforth.)

nodenv package-hooks install --all

install via git (recommended)

Install the plugin:

git clone https://github.com/nodenv/nodenv-package-rehash.git "$(nodenv root)"/plugins/nodenv-package-rehash

install via homebrew

brew install nodenv/nodenv/nodenv-package-rehash

install via npm

npm i -g @nodenv/nodenv-package-rehash

This method is not recommended, because of the likelihood that the nodenv plugin gets installed under a node being managed by nodenv. If using this method, it is highly recommended to install the plugin into your system node.

Also note, this package requires a package level npm postinstall hook to ensure the nodenv-install hook is found by nodenv hooks install. If you install this package with lifecycle hooks disabled, you will need to do this manually either by a one-time symlink:

ln -s "$(npm -g prefix)/lib/node_modules/@nodenv/nodenv-package-rehash/etc/nodenv.d/install/install-pkg-hooks.bash" "$(nodenv root)/nodenv.d/install/package-rehash.bash

or by configuring NODENV_HOOK_PATH in your shell startup:

export NODENV_HOOK_PATH=$(npm -g prefix)/lib/node_modules/@nodenv/nodenv-package-rehash/etc/nodenv.d/:$NODENV_HOOK_PATH

Configuration (optional)

With this plugin, rehashing will happen on-demand (when global npm modules are installed/uninstalled). You can take advantage of this and remove nodenv's automatic hashing upon shell initialization. In your shell startup file (.bash_profile, .bashrc, or .zshrc), add the --no-rehash flag to the nodenv init - invocation:

eval "$(nodenv init - --no-rehash)"

This will speed up your shell initialization since nodenv will no longer need to rehash on every startup.

Usage

  1. npm install -g a package that provides executables.
  2. Marvel at how you no longer need to type nodenv rehash.

Subcommands

Three sub commands are available for manual hook management.

  1. nodenv package-hooks list [ --all | <version-name>... ]

    Lists any hooks installed for the given version(s)

  2. nodenv package-hooks install [ --all | <version-name>... ]

    Installs postinstall/postuninstall rehash hooks for the given version(s)

  3. nodenv package-hooks uninstall [ --all | <version-name>... ]

    Uninstalls postinstall/postuninstall rehash hooks for the given version(s)

All three sub commands accept similar arguments:

  1. no arg: applies the command only to the currently active node version
  2. version-name: a whitespace-separate list of 1 or more explicit versions (e.g. 0.10.24)
  3. --all: applies the command to all installed versions

How It Works

nodenv-package-rehash consists of two parts: an npm postinstall (and postuninstall) hook script and a nodenv plugin.

The npm script hooks into npm's postinstall and postuninstall lifecycle events (corresponding to npm install -g and npm uninstall -g) to run nodenv rehash, ensuring newly installed package executables are visible to nodenv.

The nodenv plugin is responsible for installing the npm hook script. It relies on nodenv's install hook to copy the npm hook script into node's global node_modules/.hooks/.

For users who install this plugin via npm, there is also a package postinstall hook which will install the nodenv-install hook into the NODENV_HOOK_PATH.

Caveats

Automatic rehashing after installation of global packages does not work with versions of npm ^5.1.0 || ~6.0.1. If you use one of the affected versions of npm, you will need to run nodenv rehash manually after installing global packages. It is recommended to upgrade to a version of npm 6.1.0 or later (or stay on a version prior to 5.1.0).

npm version 5.1.0 broke global package hooks (npm/cli@e084987) and they remained broken until 6.1.0 (npm/npm-lifecycle#13). Node versions 8.2.0 through 10.2.1 (inclusive) ship with affected versions of npm.

Credits

Inspired by Joshua Peek's rbenv-gem-rehash.