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

depngn

v0.6.0

Published

Determine the compatibility of your packages with a given Node version

Downloads

194

Readme

depngn (short for dependency engine)

A CLI tool to find out if your dependencies support a given version of node. It fetches the engines field of your dependencies' package.json file and, if it's present, determines whether or not the version of node satisfies the range of supported versions.

CLI

Usage

npx depngn <node-version> [options]

# examples
npx depngn 10.0.0

npx depngn 14.17.6 --reporter=json

Node Version

depngn will accept any single value version of node as an argument (ie, not a range). If no version is given, it will attempt to determine your current node version and use that.

Options

depngn supports these options:

  • --help
  • --cwd
  • --reporter
  • --reportDir
  • --reportFileName

--cwd

Specify the path where you want the check to be performed

--reporter

These are the valid values for --reporter:

  • terminal (default): It will output a table to the terminal.
  • html: It will generate an HTML file named compat.html to the directory the command is executed in.
  • json: It will write a file named compat.json to the directory the command is executed in. It uses the following format:
[package_name]: {
  compatible: boolean // whether or not this package will work with the given Node version
  range: string // the range of supported Node versions
}

--reportDir

This allows you to specify the path where you want the report to be generated. If no path is specified, it will default to the current working directory.

--reportFileName

This allows you to specify the name of the report file. If no name is specified, it will default to compat.

A Note on The Engines Field

The engines field in package.json is optional and many libraries don't include it. If that's the case, the output for that package will be:

{
  compatible: undefined,
  range: 'n/a'
}

Standalone Package

You can also import depngn as a standalone function to use in your own CLI tools. It takes an object as an argument:

interface Options {
  version: string;
  cwd: string | undefined;
}

And it returns a promise that resolves to:

type DepngnReturn = Record<string, CompatData>;

interface CompatData {
  compatible: boolean | 'invalid' | undefined;
  range: string;
}

Usage

import { depngn } from 'depngn';

const generateReport = async () => {
  return await depngn({ version: '10.0.0' });
};

There's also a chance there is an engines field specified in the package, but the range is invalid in some way. Since RegEx for SemVer can be tricky, we return the following, if that's the case:

{
  compatible: 'invalid',
  range: '1 .2 . 0not-a-valid-range'
}

Report module

You can import report (the function that generates a report file when using CLI) as a standalone function to use in your tools to create reports exactly when you need them. It takes two arguments - the first is a result of the depngn function, and the second is an object with options:

interface CliOptions {
  version: string;
  cwd: string | undefined;
  reporter: 'terminal' | 'html' | 'json' | undefined;
  reportDir: string | undefined;
  reportFileName: string | undefined;
}

It returns a promise that resolves as a report file of the given type (html, json) or prints the result to the console if the report is not provided or is terminal.

Usage

import { report } from 'depngn/report';

const createReport = async () => {
  const desiredVersion = '10.0.0';
  const result = await depngn({ version: desiredVersion });
  await report(result, { version: desiredVersion, reportDir: './dependencies-reports', reportFileName: 'depngn' });
};

Supported Package Managers

For now, this package supports npm and yarn. If you want support for your favorite package manager, feel free to open a PR!

Development

In order to start contributing to depngn, you can follow these steps: CONTRIBUTING.md

CHANGELOG

If you want to see what changed between versions: CHANGELOG.md

Possible future features

  • Support the ability to sort and/or filter output
  • Ignore irrelevant dependencies (ie, @types/<package>)
  • Support all node versions (pretty sure this should work going back to node version 10, but if we wrote our own versions of some dependencies, we could support further back. the main offender is table (>=10.0.0), but a lot of modern cli table packages seem to only support node 10 or 12 and above).
  • Support attempting to determine support for dependencies that don't include engines field (not sure if it's worth it, since we'd have to fetch the engines of the dependency's dependencies and make an educated guess on what the supported version range is)
  • Support pnpm