Skip to content

inthepocket/npm-license-scraper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

64 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

NPM license scraper by In The Pocket

πŸ“œ Dead simple license scraper with zero dependencies

npm License: MIT

Introduction

npm-license-scraper will scan your package.json and node_modules to generate a JSON or TypeScript file including the licenses of all open source packages that are being used.

Usage

$ npm i -D @inthepocket/npm-license-scraper

# Via npx
$ npx npm-license-scraper

# Directly
$ node node_modules/.bin/npm-license-scraper

Options

  • --export [filename]: Export to a file. Use a .ts extension to generate a typed TypeScript file with as const. (default ./licenses.json)
  • --includeDev: Include dev dependencies in output (default false)
  • --exclude [package|package,package,package]: Ignore certain packages from the check (e.g submodules, monorepo or private packages)

JSON output (default)

By default, the tool exports a JSON array with the following shape:

[
  {
    "package": "react",
    "version": "18.0.0",
    "license": "MIT",
    "url": "https://reactjs.org/",
    "isValid": true
  },
  {
    "package": "react-native",
    "version": "0.69.3",
    "license": "MIT",
    "url": "https://npmjs.com/package/react-native",
    "isValid": true
  }
]

TypeScript output

When exporting with a .ts extension (--export=licenses.ts), the output is a fully typed TypeScript module using as const:

// Auto-generated by npm-license-scraper
export const licenses = [
  {
    package: "react",
    version: "18.0.0",
    license: "MIT",
    url: "https://reactjs.org/",
    isValid: true,
  },
] as const;

export type License = (typeof licenses)[number];

This gives you full autocomplete and type inference when consuming the generated file β€” all values are literal types rather than widened to string or boolean.

About

πŸ“œ Dead simple license scraper for npm packages (with zero real dependencies)

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Packages

 
 
 

Contributors