pkg-lens
v0.1.2
Published
Zero-config CLI to detect and visualize dependency bloat in JS projects
Downloads
13
Maintainers
Readme
pkg-lens
Zero-config CLI to detect dependency bloat, dependency drift, and offline supply-chain risk in JavaScript/TypeScript projects.
npx pkg-lensNo installation required. Within seconds you'll see which packages are bloated, how many lines of code they contribute, what they can be replaced with, and how your dependency tree changed over time.
Why
JavaScript dependency trees carry significant dead weight:
- The average npm package pulls in 85+ sub-dependencies
- Many packages still ship compatibility layers for engines nobody uses
- Hundreds of micro-packages exist as 3–20 line wrappers around native APIs
- Ponyfills for features natively available since 2017–2019 are still widely installed
- Every unnecessary package is a security supply chain risk
Existing tools like knip, e18e CLI, and bundlephobia solve adjacent problems — but none combine LOC counting + bloat classification + local tree analysis in one place.
Features
- Zero config — runs with no flags, auto-detects package manager and project root
- LOC counting — counts actual lines of JavaScript/TypeScript per package
- Bloat classification — categorizes packages as stale ponyfills, micro-packages, legacy compat, or duplicates
- Replacement suggestions — cross-references the e18e module-replacements dataset
- Dependency chains — traces who pulled in each flagged package
- Git drift analysis — compares dependency changes against another branch
- Dependency blame — finds the commits that introduced or changed a package
- Branch auditing — checks dependency drift across active local branches
- Offline supply-chain risk scan — reports declared maintainer identities, single/missing-maintainer packages, and likely private-scope registry gaps
- Offline-first — works from your lockfile,
node_modules, and Git history; no registry lookups - Lean — under 10 direct dependencies (it would be embarrassing for a bloat-detection tool to have 200)
Usage
# Scan current directory for dependency bloat
npx pkg-lens
# Scan a specific project
npx pkg-lens --dir /path/to/project
# Output as JSON (for piping or CI)
npx pkg-lens --json
# Filter by bloat type
npx pkg-lens --only ponyfill # only stale ponyfills
npx pkg-lens --only micro # only micro-packages
npx pkg-lens --only compat # only legacy compat
npx pkg-lens --only duplicate # only duplicates
# Minimum LOC threshold
npx pkg-lens --min-loc 5 # only packages above 5 LOC
# Include offline security metrics with the default scan
npx pkg-lens --security
# Run only the offline supply-chain risk audit
npx pkg-lens security
npx pkg-lens security --json
# Compare current dependency tree against another branch
npx pkg-lens compare main
npx pkg-lens compare HEAD
# Find who introduced or changed a dependency
npx pkg-lens blame picocolors
# Audit dependency drift across active local branches
npx pkg-lens branches
# Launch browser UI (coming in v0.2.0)
npx pkg-lens --uiCommands
| Command | What it does | Notes |
|---|---|---|
| pkg-lens / pkg-lens scan | Runs the default bloat scan | Supports --json, --only, --min-loc, --security |
| pkg-lens security / pkg-lens sec | Runs the offline supply-chain risk audit | Requires node_modules |
| pkg-lens compare [branch] | Compares current lockfile against another branch | Requires Git and a committed lockfile on the target branch |
| pkg-lens blame <package> | Searches lockfile history for package changes | Requires Git history for the lockfile |
| pkg-lens branches | Audits dependency drift across recent local branches | Reads lockfiles from local branch history |
Output: Bloat Scan
pkg-lens v0.1.0 — analyzing: my-app (847 packages)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
STALE PONYFILLS 12 packages · ~18k LOC removable
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
globalthis 18 LOC → globalThis (native since 2019)
↳ your-app → babel-preset-env → es-abstract → globalthis
object.entries 32 LOC → Object.entries() (native since 2017)
↳ your-app → eslint-plugin-react → object.entries
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
MICRO-PACKAGES 34 packages · could be inlined
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
shebang-regex 3 LOC single consumer: shebang-command
path-key 9 LOC single consumer: npm-run-path
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
847 packages scanned · 46 flagged · 761 cleanOutput: Security Audit
pkg-lens — SUPPLY CHAIN SECURITY AUDIT
Project: my-app (693 total dependencies analyzed)
Supply Chain Surface Area:
• 185 unique maintainer identities are declared by installed packages.
• 688 packages have one or no declared maintainer identities.
Dependency Confusion Checks:
✔ All custom scoped packages are correctly configured in .npmrc or match public scopes.
Single/Missing-Maintainer Packages:
@emotion/[email protected]
@mui/[email protected]
... and moreThe security audit is intentionally offline and conservative. It inspects installed package metadata, local .npmrc, package.json, and lockfiles. It does not query npm or claim to replace a vulnerability database scanner.
Bloat Types
| Type | Description | Example |
|---|---|---|
| Stale Ponyfill | Native replacement exists | globalthis → globalThis |
| Micro-Package | Under 20 LOC, could be inlined | path-key, shebang-regex |
| Legacy Compat | Supports very old engines | has, hasown, es-abstract |
| Duplicate | Multiple versions in tree | is-wsl v2.2.0 and v3.1.0 |
How It Works
- Scans
node_modules— walks all.js,.mjs,.cjs,.tsfiles per package - Counts LOC — non-empty, non-comment lines only
- Parses your lockfile — supports npm, pnpm, and yarn formats
- Classifies bloat — cross-references against the e18e module-replacements dataset
- Traces dep chains — shows exactly who pulled in each flagged package
- Reads Git history — powers
compare,blame, andbrancheswithout shell interpolation - Audits installed package metadata — powers offline supply-chain risk reporting
Comparison
| Tool | What it does | What it misses | |---|---|---| | pkg-lens | LOC + bloat type + dep chains + replacements | — | | knip | Finds unused deps/exports | No bloat classification, no LOC | | e18e CLI | Flags replaceable direct deps | CLI only, no visualization, no LOC | | bundlephobia | Shows bundle KB per package | Not local tree, no bloat typing | | depcheck | Finds unused deps | Archived, no bloat analysis |
Requirements
- Node.js 18+
- A project with
node_modulesinstalled - A lockfile (
package-lock.json,pnpm-lock.yaml, oryarn.lock) for dependency chain info - Git installed and a committed lockfile for
compare,blame, andbranches
Roadmap
- v0.2.0 — Interactive browser UI with sortable tables, filters, and dependency graph visualization
- Future — CI/CD integration mode, config file for ignoring packages, richer vulnerability database integrations
License
MIT
