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

node-version-cli

v1.1.4

Published

Conditionally pass arguments on the command line depending on the current version of node.

Downloads

50

Readme

node-version-cli Build Status

Conditionally pass arguments on the command line depending on the current version of node.

Install

$ npm install --global node-version-cli

Usage

Example: only use the babel compiler if running node <4.0.0

$ mocha $(node-version --lt-4.0.0 --compilers js:babel/register)

Version Conditions

  • --gte-0.2.0: greater than or equal to 0.2.0
  • --lte-3.0.0: less than or equal to 3.0.0
  • --gt-0.5.0: greater than 0.5.0
  • --lt-0.6.0: less than 0.6.0
  • --eq-1.0.0: exactly equal too 1.0.0

Output

Any argument not matching the Version Condition pattern described above is considered to be an output argument.

In general the pattern is:

node-version condition1 condition2 outputA outputB condition3 outputC

The program outputs the following:

  • If only conditions 1 and 2 are satisfied: outputA outputB
  • If only condition 3 is satisfied: outputC
  • If all conditions are satisfied: outputA outputB outputC
  • If only 1 or 2 or none are satisfied: <empty output>

Failure Conditions and Exit Codes

If the final arguments are Version Conditions (i.e. conditions not followed byOutput), failure to satisfy the conditions will cause a VersionConditionError to be thrown and the process to exit with a non-zero error code.

You can use this with the bash || operator to skip commands for some versions.

node-version --lt-3.0.0 || node-version --gte-4.0.0 || npm run node-3-only-tests

Note that using || means the following command runs only when the conditions fail. Running only when the conditions pass is doable, but a bit more convoluted. It is often easier to just invert your condition and stick to using ||.

Command Substitution

When combined with Command Substitution this becomes a powerful construct for controlling how bash scripts behave.

The original intended use was disabling the babel compiler for mocha tests running in newer versions of node (which already support some ES6 features).

$ mocha $(node-version --lt-4.0.0 --compilers js:babel/register)

The stack trace is often obfuscated when using the babel compiler (the line numbers won't match up).

Getting rid of babel improves performance, and gives nice stack traces on Node 4+. This scripts allows you to continue running your CI tests against old versions of Node.

License

MIT © James Talmage