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

license-compliance

v3.0.1

Published

License compliance checker

Downloads

11,951

Readme

GitHub Actions Vulnerabilities Quality Gate Status Coverage

npm version Node.js License

License Compliance

Analyzes installed packages allowing to verify compliance with allowed licenses.

Installation

npm install --save-dev license-compliance

Examples

Getting a summary of all installed packages (production and development).

$ license-compliance

Licenses
├─ MIT: 366
├─ ISC: 46
├─ BSD-3-Clause: 11
├─ BSD-2-Clause: 9
├─ Apache-2.0: 6
├─ (MIT OR CC0-1.0): 3
├─ UNKNOWN: 3
└─ (BSD-2-Clause OR MIT OR Apache-2.0): 1

Verify compliance by providing list of allowed licenses.

$ license-compliance --production --allow "MIT;ISC"

Packages
├─ [email protected]
│  ├─ Licenses: CC-BY-3.0
│  └─ Path: node_modules/spdx-exceptions
└─ [email protected]
   ├─ Licenses: CC0-1.0
   └─ Path: node_modules/spdx-license-ids

If there are non compliant packages, it exits with code 1, and outputs the non compliant packages.

$ license-compliance --production --allow "MIT;ISC;CC-BY-3.0;CC0-1.0"

If all packages are compliant, it exits with code 0 and no additional output.

Find which packages have a specific license.

$ license-compliance --production --report detailed --query "MIT"

Packages
├─ @babel/[email protected]
│  ├─ Licenses: MIT
│  ├─ License file: node_modules/@babel/code-frame/LICENSE
│  ├─ Path: node_modules/@babel/code-frame
│  └─ Repository: https://github.com/babel/babel
└─ @babel/[email protected]
   ├─ Licenses: MIT
   ├─ License file: node_modules/@babel/helper-validator-identifier/LICENSE
   ├─ Path: node_modules/@babel/helper-validator-identifier
   └─ Repository: https://github.com/babel/babel

Options

  • -p, --production Analyzes only production dependencies.
  • -d, --development Analyzes only development dependencies.
  • -t, --direct Analyzes only direct dependencies (depth = 1).
  • -f, --format <format> Report format, csv, text, json, or xunit (default = "text").
  • -r, --report <report> Report type, summary or detailed (default = "summary").
  • -a, --allow <licenses> Semicolon separated list of allowed licenses.
  • -e, --exclude <packages> Semicolon separated list of package names to be excluded from the analysis. Regex expressions are supported.
  • -q, --query <licenses> Semicolon separated list of licenses.
  • -h, --help Display help for command

<licenses> must conform to SPDX specifications.

Excluding Packages

In some scenarios there might be the need to exclude certain packages from the analysis. Let's say there is no license information for some scoped packages (@the-project), but they are under an approved license for your project. Also, there is a very specific package under the same condition (some-package).

--exclude "/^@the-project/;some-package"

This will:

  • Exclude all packages that match the regular expression /^@the-project/. Regular expressions must start and end with "/".
  • Exclude a package named some-package.

As Part of Your CI

package.json

{
    "scripts": {
        "license-compliance": "license-compliance --production --allow=\"MIT;ISC\""
    }
}

Add it to the CI pipeline.

script: / run: / etc
npm run license-compliance

Sharable Configurations

Sharable configurations allow you to publish your compliance rules and share them across multiple projects. A sharable configuration is an npm package that exports a module.

  1. Create an npm package with an index.js file and export an object containing your settings. For example:
module.exports = {
    allow: ["MIT", "ISC"],
    exclude: [/^@acme/],
    format: "text",
    production: true,
    report: "summary",
};
  1. Install the npm package in your solution(s).
  2. Add a configuration file .license-compliancerc.js to the root of your project.
module.exports = {
    extends: "{name of your package with the configuration rules}",
};

The configuration file .license-compliancerc.js can also include other properties besides extends, allowing you to override the settings from the installed shared package. The command line in the CI will override any configuration; CLI > Inline > Shared configuration package.

License

MIT