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

@smarlhens/npm-check-engines

v0.13.0

Published

Node.JS engines constraint checker written in TypeScript.

Downloads

29

Readme

NPM check engines

CodeQL GitHub CI node-current (scoped) GitHub license code style: prettier Conventional Commits

npm-check-engines upgrades your package.json node engines constraint to the most restrictive used by your dependencies.


Table of Contents


Prerequisites

  • Node.JS version ^16.14.0 || ^18.0.0

Installation

Install globally:

npm install -g @smarlhens/npm-check-engines

Or run with npx:

npx @smarlhens/npm-check-engines

Usage

CLI

Show the most restrictive constraint (opinionated) of the node engine for the project in the current directory based on the npm package-lock.json file:

$ nce
✔ Computed engines range constraints:

 node  *  →  ^14.17.0 || ^16.10.0 || >=17.0.0

Run nce -u to upgrade package.json.

Upgrade a project's package.json file:

$ nce -u
✔ Computed engines range constraints:

 node  *  →  ^14.17.0 || ^16.10.0 || >=17.0.0

Node

import { checkEnginesFromString, validatePackageJson, validatePackageLock } from '@smarlhens/npm-check-engines';

let packageJsonString = ''; // load content of package.json as stringified JSON
let packageLockString = ''; // load content of package-lock.json as stringified JSON

validatePackageJson({ packageJsonString }); // can throw Errors if unexpected format
validatePackageLock({ packageLockString }); // can throw Errors if unexpected format

// packageJson is the content of your package.json with updated engines
// packageLock is the content of your package-lock.json with updated engines of the root project in packages
// enginesRangeToSet contains changes if you want to display them
const { enginesRangeToSet, packageJson, packageLock } = checkEnginesFromString({
  packageJsonString,
  packageLockString,
});
console.log(packageJson);
console.log(packageLock);
console.log(
  enginesRangeToSet
    .map(({ engine, range, rangeToSet }) => `${engine} range "${range}" replaced by "${rangeToSet}"`)
    .join('\n'),
);

CLI Options

Usage: nce [options]

Options:
  -q, --quiet    Enable quiet mode.                                             [boolean] [default: false]
  -d, --debug    Enable debug mode. Can be used with environment variable DEBUG=nce.
                                                                                [boolean] [default: false]
  -v, --verbose  A little more detailed than the default output.                [boolean] [default: false]
  -e, --engines  Select engines to check. Default will check all engines defined.                  [array]
  -u, --update   Update engines in package.json and package-lock.json.          [boolean] [default: false]
      --enableEngineStrict  Enable engine strict.                               [boolean] [default: false]
      --help     Show help                                                                       [boolean]
      --version  Show version number                                                             [boolean]

Examples:
  nce                 Check package-lock.json file in current working directory.

© 2023 Samuel MARLHENS

Debug

$ DEBUG=* nce -d
[STARTED] Checking npm package engines range constraints in package-lock.json...
[STARTED] Reading package-lock.json...
[SUCCESS] Reading package-lock.json...
[STARTED] Reading package.json...
[SUCCESS] Reading package.json...
[STARTED] Validating package-lock.json...
[SUCCESS] Validating package-lock.json...
[STARTED] Validating package.json...
[SUCCESS] Validating package.json...
[STARTED] Compute engines range constraints...
  nce:node Package  has no constraints for current engine +0ms
  nce:node Final computed engine range constraint: * +1ms
  nce:node Package  has no engines +0ms
  nce:node Compare: * and >=6.9.0 +1ms
  nce:node Range >=6.9.0 is a subset of * +1ms
  nce:node New most restrictive range: >=6.9.0 +0ms
  nce:node Compare: >=6.9.0 and >=12.22.0 +0ms
  nce:node Range >=12.22.0 is a subset of >=6.9.0 +0ms
  nce:node New most restrictive range: >=12.22.0 +0ms
  nce:node Ignored range: * +0ms
  nce:node Compare: >=12.22.0 and >=7.0.0 +1ms
  nce:node Range >=12.22.0 is a subset of >=7.0.0 +0ms
  nce:node Package node_modules/noengines has no engines +0ms
  nce:node Compare: >=12.22.0 and >=12.13.0 <13.0.0-0||>=14.15.0 <15.0.0-0||>=16.10.0 <17.0.0-0||>=17.0.0 +1ms
  nce:node Applying minimal version 12.22.0 to both ranges. +0ms
  nce:node Compare: >=12.22.0 and >=12.22.0 <13.0.0-0||>=14.15.0 <15.0.0-0||>=16.10.0 <17.0.0-0||>=17.0.0 +1ms
  nce:node Range >=12.22.0 <13.0.0-0||>=14.15.0 <15.0.0-0||>=16.10.0 <17.0.0-0||>=17.0.0 is a subset of >=12.22.0 +0ms
  nce:node New most restrictive range: >=12.22.0 <13.0.0-0||>=14.15.0 <15.0.0-0||>=16.10.0 <17.0.0-0||>=17.0.0 +0ms
  nce:node Compare: >=12.22.0 <13.0.0-0||>=14.15.0 <15.0.0-0||>=16.10.0 <17.0.0-0||>=17.0.0 and >=16.0.0||>=14.17.0 <15.0.0-0 +1ms
  nce:node Applying minimal version 14.17.0 to both ranges. +0ms
  nce:node Compare: >=14.17.0 <15.0.0-0||>=16.10.0 <17.0.0-0||>=17.0.0 and >=14.17.0 <15.0.0-0||>=16.0.0 +0ms
  nce:node Range >=14.17.0 <15.0.0-0||>=16.10.0 <17.0.0-0||>=17.0.0 is a subset of >=14.17.0 <15.0.0-0||>=16.0.0 +0ms
  nce:node New most restrictive range: >=14.17.0 <15.0.0-0||>=16.10.0 <17.0.0-0||>=17.0.0 +1ms
  nce:node Final computed engine range constraint: >=14.17.0 <15.0.0-0||>=16.10.0 <17.0.0-0||>=17.0.0 +0ms
  nce:npm Package  has no constraints for current engine +0ms
  nce:npm Final computed engine range constraint: * +0ms
  nce:npm Package  has no engines +0ms
  nce:npm Package node_modules/foo has no constraints for current engine +0ms
  nce:npm Compare: * and >=6.0.0 +1ms
  nce:npm Range >=6.0.0 is a subset of * +0ms
  nce:npm New most restrictive range: >=6.0.0 +0ms
  nce:npm Package node_modules/all has no constraints for current engine +0ms
  nce:npm Package node_modules/arr has no constraints for current engine +0ms
  nce:npm Package node_modules/noengines has no engines +0ms
  nce:npm Package node_modules/complex1 has no constraints for current engine +0ms
  nce:npm Package node_modules/complex2 has no constraints for current engine +0ms
  nce:npm Final computed engine range constraint: >=6.0.0 +0ms
  nce:yarn Package  has no constraints for current engine +0ms
  nce:yarn Final computed engine range constraint: * +0ms
  nce:yarn Package  has no engines +0ms
  nce:yarn Package node_modules/foo has no constraints for current engine +1ms
  nce:yarn Compare: * and >=1.22.4 <2.0.0-0 +0ms
  nce:yarn Range >=1.22.4 <2.0.0-0 is a subset of * +0ms
  nce:yarn New most restrictive range: >=1.22.4 <2.0.0-0 +0ms
  nce:yarn Package node_modules/all has no constraints for current engine +0ms
  nce:yarn Package node_modules/arr has no constraints for current engine +0ms
  nce:yarn Package node_modules/noengines has no engines +0ms
  nce:yarn Package node_modules/complex1 has no constraints for current engine +0ms
  nce:yarn Package node_modules/complex2 has no constraints for current engine +0ms
  nce:yarn Final computed engine range constraint: >=1.22.4 <2.0.0-0 +0ms
[SUCCESS] Compute engines range constraints...
[STARTED] Output computed engines range constraints...
  nce:node Simplified computed engine range constraint: ^14.17.0 || ^16.10.0 || >=17.0.0 +0ms
  nce:npm Simplified computed engine range constraint: >=6.0.0 +0ms
  nce:yarn Simplified computed engine range constraint: ^1.22.4 +0ms
[TITLE] Computed engines range constraints:
[TITLE]
[TITLE]  node  *  →  ^14.17.0 || ^16.10.0 || >=17.0.0
[TITLE]  npm   *  →  >=6.0.0
[TITLE]  yarn  *  →  ^1.22.4
[TITLE]
[TITLE] Run nce -d -u to upgrade package.json.
[SUCCESS] Output computed engines range constraints...
[STARTED] Enabling engine-strict using .npmrc...
[SKIPPED] Enabling engine-strict is disabled by default.
[STARTED] Updating package.json...
[SKIPPED] Update is disabled by default.
[SUCCESS] Computed engines range constraints:
[SUCCESS]
[SUCCESS]  node  *  →  ^14.17.0 || ^16.10.0 || >=17.0.0
[SUCCESS]  npm   *  →  >=6.0.0
[SUCCESS]  yarn  *  →  ^1.22.4
[SUCCESS]
[SUCCESS] Run nce -d -u to upgrade package.json.

Thanks

This project is heavily inspired by the following awesome project: npm-check-updates.