dependency-usage-analyzer
v1.0.1
Published
Analyze Node.js project dependencies to find unused, undeclared, and risky packages.
Maintainers
Readme
Dependency Usage Analyzer (DUA)
A production-ready CLI tool to analyze Node.js project dependencies. It detects unused, undeclared, and risky packages to help you optimize your project's security and performance.
Features
- Unused Dependency Detection: Finds packages listed in
package.jsonbut never imported in your code. - Undeclared Dependency Detection: Finds packages imported in your code but missing from
package.json. - Risk Assessment: Checks for deprecated packages and assigns a basic risk score.
- Size Analysis: Calculates the disk size of each dependency in
node_modules. - Support for JS/TS: Works with JavaScript, TypeScript, JSX, and TSX files.
How It Helps
- Reduce Bundle Size: Identify and remove unused dependencies to make your application lighter and faster.
- Improve Security: Detect deprecated or risky packages that might introduce vulnerabilities.
- Clean Up Codebase: Find undeclared dependencies that might break your build in different environments.
- Save Time: Automate the manual process of checking imports vs package.json.
Installation
You can install it globally or run it directly with npx.
# Install globally
npm install -g dependency-usage-analyzer
# OR run directly with npx (Recommended)
npx dependency-usage-analyzerStep-by-Step Guide
Open your terminal and navigate to the root directory of your Node.js project (where your
package.jsonis located).cd /path/to/your/projectRun the analyzer. You can simply run:
npx dependency-usage-analyzerView the Report. The tool will scan your files and output a table showing:
- Which packages are used vs unused.
- The size of each package on disk.
- Deprecation warnings or risk status.
Take Action:
- Uninstall unused packages:
npm uninstall <package-name> - Install undeclared packages:
npm install <package-name> - Replace deprecated packages: Look for modern alternatives.
- Uninstall unused packages:
Advanced Usage
- Output as JSON (for CI/CD pipelines):
npx dependency-usage-analyzer --json - Fail on Unused (strict mode for CI):
npx dependency-usage-analyzer --fail-on-unused - Skip Metadata Fetching (offline mode or faster run):
npx dependency-usage-analyzer --no-enrich
Example Output
Starting dependency analysis...
Fetching package metadata...
Calculating package sizes...
┌──────────────────────┬──────┬──────┬──────────┬──────────┐
│ Package │ Type │ Used │ Size │ Status │
├──────────────────────┼──────┼──────┼──────────┼──────────┤
│ react │ Prod │ Yes │ 2.5 MB │ OK │
│ lodash │ Prod │ No │ 4.1 MB │ Unused │
│ request │ Prod │ Yes │ 1.2 MB │ Deprecated │
└──────────────────────┴──────┴──────┴──────────┴──────────┘
Summary:
Total Dependencies: 3
Unused: 1
Undeclared: 0Development
- Clone the repository.
- Install dependencies:
npm install - Build the project:
npm run build - Run the CLI locally:
node bin/dua.js
Author & Connect
Built by Devesh Kumar Thakur
Connect with me:
- 🐙 GitHub: DeveshKumarThakur
- 💼 LinkedIn: kumardeveshthakur
- 🌐 Linktree: kumardeveshthakur
If you find this SDK helpful, feel free to ⭐ star the repository and connect!
License
ISC
