or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

file-operations.mdformatting.mdindex.mdscanning.md
tile.json

tessl/npm-license-checker

Check license info for a package and its dependencies

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/license-checker@25.0.x

To install, run

npx @tessl/cli install tessl/npm-license-checker@25.0.0

index.mddocs/

License Checker

License Checker is a comprehensive CLI tool and Node.js library for analyzing license information across package dependency trees. It recursively scans node_modules directories, extracts license data from package.json files and license files, and provides flexible output formats including JSON, CSV, and tree-view display.

Package Information

  • Package Name: license-checker
  • Package Type: npm
  • Language: Node.js
  • Installation: npm install -g license-checker (CLI) or npm install license-checker (library)

Core Imports

const checker = require("license-checker");

For ES modules:

import * as checker from "license-checker";

Basic Usage

const checker = require("license-checker");

// Scan current directory for licenses
checker.init({
  start: process.cwd()
}, function(err, packages) {
  if (err) {
    console.error(err);
  } else {
    console.log(packages);
  }
});

CLI usage:

# Basic scan of current directory
license-checker

# Scan specific directory
license-checker --start /path/to/project

# Output as JSON
license-checker --json --out licenses.json

# Only production dependencies
license-checker --production

Architecture

License Checker is built around several key components:

  • Core Engine: Main scanning and analysis logic that traverses dependency trees using read-installed
  • License Detection: Pattern-based license identification supporting SPDX expressions and common license text recognition
  • Output Formatters: Multiple output formats (tree, JSON, CSV, markdown, summary) for different use cases
  • CLI Interface: Command-line tool with comprehensive options for filtering, formatting, and validation
  • File Discovery: Intelligent license file detection with precedence ordering (LICENSE, LICENCE, COPYING, README)

Capabilities

License Scanning

Core license analysis functionality that scans package dependency trees and extracts comprehensive license information from multiple sources including package.json files and license files.

function init(options: ScanOptions, callback: (err: Error | null, data: LicenseData) => void): void;

interface ScanOptions {
  start?: string;                    // Directory to start scanning from
  production?: boolean;              // Only scan production dependencies
  development?: boolean;             // Only scan development dependencies  
  unknown?: boolean;                 // Report guessed licenses as unknown
  onlyunknown?: boolean;            // Only list packages with unknown licenses
  direct?: boolean;                  // Only scan direct dependencies (not transitive)
  customFormat?: CustomFormat;       // Custom output format specification
  customPath?: string;               // Path to custom format JSON file
  exclude?: string;                  // Comma-separated licenses to exclude
  failOn?: string;                   // Semicolon-separated licenses to fail on
  onlyAllow?: string;               // Semicolon-separated allowed licenses only
  packages?: string;                 // Semicolon-separated specific packages to include
  excludePackages?: string;         // Semicolon-separated packages to exclude
  excludePrivatePackages?: boolean; // Exclude private packages
  relativeLicensePath?: boolean;    // Use relative paths for license files
  color?: boolean;                  // Enable colored output
}

interface LicenseData {
  [packageKey: string]: PackageInfo;
}

interface PackageInfo {
  licenses: string | string[];       // License identifier(s)
  repository?: string;               // Repository URL
  publisher?: string;                // Package author/publisher
  email?: string;                    // Author email
  url?: string;                      // Author or package URL
  path?: string;                     // Local package path
  licenseFile?: string;             // Path to license file
  licenseText?: string;             // License file content
  copyright?: string;               // Extracted copyright information
  noticeFile?: string;              // Path to NOTICE file
  private?: boolean;                // Whether package is private
}

License Scanning

Output Formatting

Flexible output formatting system supporting multiple formats for different integration needs including programmatic consumption, reporting, and human-readable display.

function asTree(data: LicenseData): string;
function asSummary(data: LicenseData): string;
function asCSV(data: LicenseData, customFormat?: CustomFormat, csvComponentPrefix?: string): string;
function asMarkDown(data: LicenseData, customFormat?: CustomFormat): string;
function print(data: LicenseData): void;

interface CustomFormat {
  [fieldName: string]: string | boolean;
}

Output Formatting

File Operations

License file extraction and JSON parsing utilities for advanced license management workflows.

function asFiles(data: LicenseData, outDir: string): void;
function parseJson(jsonPath: string): object | Error;

File Operations

Command Line Interface

Comprehensive CLI tool for license analysis with flexible output options and validation controls.

# Basic usage
license-checker [options]

# Common options:
--start <path>              # Starting directory (default: current directory)
--production                # Production dependencies only
--development               # Development dependencies only
--json                      # JSON output format
--csv                       # CSV output format
--markdown                  # Markdown output format
--summary                   # License usage summary
--out <file>                # Write output to file
--unknown                   # Report guessed licenses as unknown
--onlyunknown              # Show only unknown licenses
--direct                    # Direct dependencies only
--exclude <licenses>        # Exclude specific licenses (comma-separated)
--failOn <licenses>         # Fail on specific licenses (semicolon-separated)
--onlyAllow <licenses>      # Only allow specific licenses (semicolon-separated)
--packages <packages>       # Include specific packages (semicolon-separated) 
--excludePackages <packages> # Exclude specific packages (semicolon-separated)
--excludePrivatePackages    # Exclude private packages
--relativeLicensePath       # Use relative license file paths
--customPath <file>         # Custom format specification file
--csvComponentPrefix <prefix> # CSV component column prefix
--files <dir>               # Extract license files to directory

Usage Examples:

# Basic scan of current directory
license-checker

# Scan specific directory with JSON output
license-checker --start ./my-project --json --out licenses.json

# Production dependencies only
license-checker --production --summary

# Fail on GPL licenses
license-checker --failOn "GPL-2.0;GPL-3.0;LGPL-2.1"

# Only allow specific licenses
license-checker --onlyAllow "MIT;Apache-2.0;BSD-3-Clause"

# Generate compliance report
license-checker --csv --out report.csv --files ./extracted-licenses

# Custom format with markdown output
license-checker --customPath ./format.json --markdown --out README-licenses.md

Types

interface ScanOptions {
  start?: string;                    // Starting directory path
  production?: boolean;              // Production dependencies only
  development?: boolean;             // Development dependencies only
  unknown?: boolean;                 // Report guessed licenses as unknown
  onlyunknown?: boolean;            // Show only unknown licenses
  direct?: boolean;                  // Direct dependencies only
  customFormat?: CustomFormat;       // Custom output format
  customPath?: string;               // Path to custom format file
  exclude?: string;                  // Licenses to exclude (comma-separated)
  failOn?: string;                   // Licenses to fail on (semicolon-separated)
  onlyAllow?: string;               // Only allowed licenses (semicolon-separated)
  packages?: string;                 // Specific packages to include
  excludePackages?: string;         // Packages to exclude
  excludePrivatePackages?: boolean; // Exclude private packages
  relativeLicensePath?: boolean;    // Use relative license file paths
  color?: boolean;                  // Enable colored output
}

interface PackageInfo {
  licenses: string | string[];       // License identifiers
  repository?: string;               // Repository URL
  publisher?: string;                // Package publisher
  email?: string;                    // Publisher email
  url?: string;                      // Publisher/package URL
  path?: string;                     // Package path
  licenseFile?: string;             // License file path
  licenseText?: string;             // License content
  copyright?: string;               // Copyright information
  noticeFile?: string;              // Notice file path
  private?: boolean;                // Private package flag
}

interface LicenseData {
  [packageName: string]: PackageInfo;
}

interface CustomFormat {
  [fieldName: string]: string | boolean;
}