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

nvm-shield

v1.0.6

Published

Shield your application from incorrect Node.js versions by verifying against a .nvmrc or by comparing package-locks in your CI process.

Downloads

18

Readme

nvm-shield

NVM-Shield acts as a barrier between you and Node, preventing you from running your applications or pushing improperly installed packages to your project on the wrong version.

There are two places you can use the application at the moment:

  • as a prestart test in your package.json
  • as a command in your CI process

Examples

Verify against your .nvmrc

Use the "nvm-shield" package as a pre-start script with no arguments. This will test your .nvmrc against the current Node version.

Example package.json

"scripts": {
    "prestart": "nvm-shield",
    "start": "react-scripts start",
    ...
}

Verify against a specific version

Supply a specific version to test your current Node version against.

Example package.json

"scripts": {
    "prestart": "nvm-shield --version=12.13.1",
    "start": "react-scripts start",
    ...
}

Verify against a specific major version

Specify a major release to compare your version of Node against. In the example, we're looking for a major version of 12, which will match 12.13.1, 12.x.x

Example package.json

"scripts": {
    "prestart": "nvm-shield --version=12 --compare=major",
    "start": "react-scripts start",
    ...
}

Verify against a specific minor version

Specify a minor release to compare your version of Node against. In the example, we're looking for a major version of 12.13, which will match 12.13.1, 12.13.x

Example package.json

"scripts": {
    "prestart": "nvm-shield --version=12.13 --compare=minor",
    "start": "react-scripts start",
    ...
}

Use it in your CI process!

Using the --ci flag you can check for changes in the package-lock during your CI process. If changes are detected the process is terminated and the build fails.

An integration with CircleCI might look like the following:

Example package.json

"scripts": {
  "nvm-shield-ci": "nvm-shield --ci",
  ...
}

Example config.yml

jobs:
  build_and_test:
    docker:
      - image: circleci/node:12.13.1-browsers
    steps:
      - checkout
      - run: npm i
      - run: npm run nvm-shield-ci
      - run: npm run lint
      - run: npm test
      - run: npm run build:integration

Use it as a Husky pre-push hook!

Using Husky you can prevent incorrect versions of packages being installed before they even hit the CI/CD process and before they reach your projects repository.

Using the same --ci flag as mentioned in the CircleCI sample integration you can use NVM-Shield as a pre-push hook.

An integration with Husky might look like the following:

Example package.json

"scripts": {
  "nvm-shield": "nvm-shield",
  "nvm-shield-ci": "nvm-shield --ci",
  ...
},
"husky": {
  "hooks": {
    "pre-push": "npm run nvm-shield && npm i && npm run nvm-shield-ci"
  }
},

This could also be extended to be used as a pre-commit hook as well to ensure proper versions are being used when committing:

Example package.json

"scripts": {
  "nvm-shield": "nvm-shield",
  ...
},
"husky": {
  "hooks": {
    "pre-commit": "npm run nvm-shield"
  }
},

Parameters

NVM-Shield allows the following parameters to be passed into it followed by an = (except the CI commands):

  • No Parameters: tests .nvmrc against current Node version
  • --version: specify a specific version to test against (can be used with --compare)
  • --compare: accepts major, minor, or patch to compare against
  • --ci: used after npm i in your CI process

Licensed under MIT TL;DR Legal