Smart dependency analyzer and optimizer for Node.js projects - Slash your bundle size, eliminate duplicates, and optimize your dependency tree with zero configuration.
Are duplicate dependencies bloating your node_modules folder? Is your bundle size out of control? dep-optimizer is your go-to CLI tool for keeping your Node.js projects lean, fast, and optimized.
- Bloated bundles: Duplicate packages waste disk space and slow down installations
- Conflicting versions: Different dependencies pulling in incompatible versions of the same package
- Hidden costs: You don't know which duplicates are costing you the most space
- Manual detective work: Finding and fixing duplicates is tedious and error-prone
dep-optimizer automatically scans your entire dependency tree, identifies duplicates, calculates wasted space, and provides actionable recommendations to consolidate your dependencies.
- π Deep Scanning: Recursively analyzes your entire
node_modulestree - π― Duplicate Detection: Identifies all duplicate packages across different versions
- πΎ Space Analysis: Calculates exact wasted space from duplicate dependencies
- π€ Smart Consolidation: Detects which duplicates can be safely consolidated using semver
- π Beautiful Reports: Color-coded, easy-to-read CLI output
- β‘ Lightning Fast: Optimized scanning with minimal overhead
- π οΈ Zero Config: Works out of the box with any Node.js project
- π JSON Export: Machine-readable output for CI/CD integration
- π¨ Rich CLI: Multiple commands for different use cases
npm install -g dep-optimizernpm install --save-dev dep-optimizernpx dep-optimizer analyzeNavigate to your Node.js project and run:
# Full analysis (scan + duplicates)
dep-optimizer analyze
# Just scan dependencies
dep-optimizer scan
# Find duplicate dependencies
dep-optimizer duplicates
# Check a specific package
dep-optimizer check lodashGet a complete overview of your dependencies and duplicates:
dep-optimizer analyzeOutput:
π¦ Dependency Scan Results
Total packages: 842
Total size: 156.43 MB
Scanned paths: 842
π Duplicate Package Analysis
Found 12 duplicate packages
Total wasted space: 8.54 MB
3 packages can be consolidated
lodash
ββββββββββββββββββββββββββββββββββββββββββββββββββ
Versions found: 3
Total instances: 5
Wasted space: 3.21 MB
β Can consolidate to version 4.17.21
View all installed dependencies and their sizes:
dep-optimizer scanAnalyze only duplicate dependencies:
dep-optimizer duplicatesAdvanced options:
# Show file paths for each duplicate
dep-optimizer duplicates --show-paths
# Only show duplicates wasting more than 1MB
dep-optimizer duplicates --min-waste 1048576
# Verbose output
dep-optimizer duplicates --verbose
# JSON output for automation
dep-optimizer duplicates --jsonInspect a single package for duplicates:
dep-optimizer check reactOutput:
Found 2 versions of react:
- 17.0.2 (1 instances)
- 18.2.0 (1 instances)
β Can consolidate to version 18.2.0
| Command | Description | Options |
|---|---|---|
analyze |
Complete analysis: scan + duplicates | -p, --path, -v, --verbose, --json, --show-paths |
scan |
Scan all dependencies | -p, --path, -v, --verbose, --json |
duplicates |
Find duplicate dependencies | -p, --path, -v, --verbose, --json, --show-paths, --min-waste |
check <package> |
Check specific package for duplicates | -p, --path, -v, --verbose, --json, --show-paths |
-p, --path <path>: Specify project path (default: current directory)-v, --verbose: Enable verbose output--json: Output results in JSON format--show-paths: Display file paths for each version--min-waste <bytes>: Minimum wasted space threshold
dep-optimizer duplicates --min-waste 1000000This shows only duplicates wasting over 1MB of space.
dep-optimizer analyze --path /path/to/project# Export to JSON and parse in your CI pipeline
dep-optimizer duplicates --json > duplicates-report.json
# Fail CI if duplicates waste more than 10MB
dep-optimizer duplicates --json | jq '.totalWastedSpace > 10485760' | grep -q true && exit 1dep-optimizer check axios --show-paths --verbose- Scanning: Recursively walks through
node_modulesand reads allpackage.jsonfiles - Analysis: Groups packages by name and identifies multiple versions
- Size Calculation: Computes actual disk space used by each package
- Semver Check: Uses semantic versioning to determine if versions can be consolidated
- Reporting: Generates beautiful, actionable reports
Review the consolidation recommendations and update your package.json to use compatible version ranges:
{
"dependencies": {
"lodash": "^4.17.21" // Use latest compatible version
}
}Run npm's built-in deduplication:
npm dedupeCheck that duplicates are gone:
dep-optimizer duplicates# Run tests
npm test
# Run tests with coverage
npm run test:coverage
# Watch mode
npm run test:watch# Clone the repository
git clone https://github.com/yourusername/dep-optimizer.git
# Install dependencies
npm install
# Build the project
npm run build
# Run in development mode
npm run dev
# Run linter
npm run lintπ Duplicate Package Analysis
Found 8 duplicate packages
Total wasted space: 12.34 MB
5 packages can be consolidated
lodash
ββββββββββββββββββββββββββββββββββββββββββββββββββ
Versions found: 3
Total instances: 7
Wasted space: 4.12 MB
β Can consolidate to version 4.17.21
Versions:
4.17.19 (2 instances, 1.37 MB)
4.17.20 (3 instances, 1.38 MB)
4.17.21 (2 instances, 1.37 MB)
π Summary
Total duplicate packages: 8
Potential space savings: 12.34 MB
Auto-consolidatable packages: 5
π‘ Recommendation:
Update your package.json to use compatible version ranges for the consolidatable packages.
Run "npm dedupe" after updating to remove duplicates.
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Built with TypeScript for type safety
- Powered by Commander.js for CLI
- Colored output with Chalk
- Semver analysis with node-semver
Found a bug? Have a feature request? Open an issue!
See CHANGELOG.md for a list of changes.
Made with β€οΈ for the Node.js community
If dep-optimizer saved you disk space and made your life easier, please give it a β on GitHub!