@infodb/licscan
v0.12.0
Published
License and Copyright Scanner for package.json and pyproject.toml
Maintainers
Readme
licscan
License and Copyright Scanner for package.json and pyproject.toml
Overview
licscan is a command-line tool that scans your project dependencies and extracts license and copyright information from:
- npm packages (via
package.json) - Python packages (via
pyproject.toml)
This tool helps you maintain compliance by providing a clear view of all licenses and copyrights in your dependencies.
Features
- Scan npm dependencies from
package.json - Scan Python dependencies from
pyproject.toml - Package manager support: npm, pnpm, yarn
- Automatic Python environment detection (uv, Poetry, venv, system)
- Extract license information from package metadata
- Extract copyright information from LICENSE files
- Dependency tracking: Shows which packages depend on each dependency and dependency paths from root
- Support for multiple output formats: text, JSON, CSV, Markdown
- Include or exclude dev dependencies
- Export results to file
- Large project support: Handles projects with hundreds of dependencies
Installation
npm install -g @infodb/licscan
# or use with npx
npx @infodb/licscan [path]Usage
Basic Usage
Scan current directory:
licscan
# or
licscan scanScan specific directory:
licscan /path/to/project
# or
licscan scan /path/to/projectOptions
-d, --include-dev- Include dev dependencies (default: false)-f, --format <format>- Output format:text,json,csv, ormarkdown(default: text)-o, --output <file>- Write output to file instead of stdout--npm-only- Scan only npm dependencies (package.json)--python-only- Scan only Python dependencies (pyproject.toml)
Examples
Include dev dependencies:
licscan -dExport to JSON:
licscan -f json -o licenses.jsonExport to CSV with dev dependencies:
licscan -d -f csv -o licenses.csvExport to Markdown:
licscan -f markdown -o licenses.mdScan only npm dependencies:
licscan --npm-onlyScan only Python dependencies:
licscan --python-onlyScan Python project:
licscan /path/to/python/project -f jsonScan npm dependencies from a monorepo project (that has both package.json and pyproject.toml):
licscan /path/to/monorepo --npm-only -f json -o npm-licenses.jsonOutput Formats
Text (default)
Human-readable format with package details:
================================================================================
NPM PACKAGES (3)
================================================================================
Package: [email protected]
License: MIT
Author: TJ Holowaychuk
Homepage: https://github.com/tj/commander.js
Repository: git+https://github.com/tj/commander.js.git
Dependency path: my-project → commander
Copyright:
Copyright (c) 2011 TJ Holowaychuk <[email protected]>
--------------------------------------------------------------------------------
...JSON
Machine-readable JSON format with dependency tracking:
[
{
"type": "npm",
"packages": [
{
"name": "commander",
"version": "11.1.0",
"license": "MIT",
"copyright": "Copyright (c) 2011 TJ Holowaychuk <[email protected]>",
"author": "TJ Holowaychuk",
"repository": "git+https://github.com/tj/commander.js.git",
"homepage": "https://github.com/tj/commander.js",
"requiredBy": ["my-project"],
"dependencyPaths": [["my-project", "commander"]]
}
]
}
]CSV
Spreadsheet-compatible format with dependency information:
Type,Name,Version,License,Author,Homepage,Repository,RequiredBy,DependencyPath,Copyright
npm,commander,11.1.0,MIT,TJ Holowaychuk,https://github.com/tj/commander.js,git+https://github.com/tj/commander.js.git,my-project,my-project → commander,Copyright (c) 2011 TJ Holowaychuk <[email protected]>Markdown
Documentation-friendly format with table of contents and sorted packages:
# License Report
## Table of Contents
### NPM Packages
- [[email protected]](#commander-11-1-0) - MIT
- [[email protected]](#express-4-18-0) - MIT
### Python Packages
- [[email protected]](#requests-2-31-0) - Apache-2.0
---
## NPM Packages
### [email protected]
- **License:** MIT
- **Author:** TJ Holowaychuk
- **Homepage:** https://github.com/tj/commander.js
- **Repository:** git+https://github.com/tj/commander.js.git
- **Dependency path:** my-project → commander
**Copyright:**
\```
Copyright (c) 2011 TJ Holowaychuk <[email protected]>
\```How It Works
For npm packages (package.json):
- Reads
package.jsonto get the packages defined in dependencies (entry points) - Detects package manager (npm, pnpm, or yarn)
- Runs
pnpm list --prod/npm list/yarn listto build full dependency graph - Extracts all packages reachable from the defined dependencies (includes transitive dependencies)
- For each package (direct and transitive), reads package.json and LICENSE files
- Extracts license information from package metadata
- Extracts copyright information from LICENSE files
- Calculates dependency paths from root to each package
- Compiles all information with dependency tracking into structured output
Note: The tool scans packages defined in package.json and all their transitive dependencies. For example, if package.json defines react, the output will include react, loose-envify (dependency of react), js-tokens (dependency of loose-envify), etc.
For Python packages (pyproject.toml):
- Reads
pyproject.toml(supports both Poetry and PEP 621 formats) - Extracts the packages defined in dependencies (entry points)
- Detects Python environment:
- Checks for
uv.lock(uv projects) - Checks for
poetry.lock(Poetry projects) - Checks for
VIRTUAL_ENVenvironment variable (venv) - Checks for common venv directories (
venv,.venv,env,.env) - Falls back to system Python
- Checks for
- Uses
pip showto build full dependency graph and track relationships - Extracts all packages reachable from the defined dependencies (includes transitive dependencies)
- For each package, attempts to locate and read LICENSE files using Python's
importlib.metadata - Calculates dependency paths from root project to each package
- Uses appropriate command prefix (
uv run,poetry run, or system) - Compiles all information with dependency tracking into structured output
Note: The tool scans packages defined in pyproject.toml and all their transitive dependencies. For example, if pyproject.toml defines graphql-py, the output will include graphql-py and ply (dependency of graphql-py).
Development
Setup
cd licscan
npm installBuild
npm run buildDevelopment Mode
npm run devThis will watch for file changes and rebuild automatically.
Test
npm run testProject Structure
licscan/
├── package.json
├── tsconfig.json
├── README.md
├── bin/
│ └── cli.js # CLI entry point
└── src/
├── index.ts # Main CLI setup
├── commands/
│ └── scan.ts # Scan command implementation
├── templates/
│ └── licenses.md.hbs # Handlebars template for Markdown output
└── utils/
├── logger.ts # Logging utility
├── package-parser.ts # npm package parser with dependency graph
└── pyproject-parser.ts # Python package parser with dependency graphLimitations
- For Python packages, packages must be installed in the detected environment (venv, Poetry, uv, or system)
- Python environment detection automatically supports:
- uv projects: Detects
uv.lockand usesuv run pip show - Poetry projects: Detects
poetry.lockand usespoetry run pip show - venv environments: Detects
VIRTUAL_ENVor common venv directories - System Python: Falls back when no virtual environment is detected
- uv projects: Detects
- Copyright extraction depends on the presence of LICENSE files and may not work for all packages
- Some packages may not have proper license metadata
- For very large projects (500+ dependencies), the tool automatically limits dependency depth to 50 levels if the output exceeds buffer limits
License
MIT
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
