Skip to content

chiefmikey/depsweep

DepSweep

Enterprise-grade dependency analysis with environmental impact reporting

npm version License: MIT Node.js Version Test Coverage

DepSweep is a production-ready CLI tool that identifies unused dependencies in Node.js projects and calculates their environmental impact. Designed for enterprise use and high-traffic open source projects.

Features

  • Dependency Analysis: Identifies unused dependencies across JavaScript, TypeScript, JSX, and TSX files using AST parsing
  • Environmental Impact Reporting: Calculates carbon savings, energy consumption, and water usage based on scientific research
  • Safe Cleanup: Protected dependencies prevent breaking changes
  • Performance Optimized: Fast analysis with memory optimization and parallel processing
  • Flexible Configuration: Customizable ignore patterns and safe dependencies
  • Professional Output: Structured tables and progress indicators
  • Enterprise Ready: Comprehensive error handling, rate limiting, and security features

Quick Start

Installation

npm install -g depsweep

Basic Usage

# Analyze dependencies and measure environmental impact
depsweep --measure-impact --dry-run

# Run with verbose output for detailed information
depsweep --measure-impact --dry-run --verbose

# Get help
depsweep --help

Usage Examples

Basic Analysis

# Analyze current project
depsweep --measure-impact --dry-run

Advanced Configuration

# Ignore specific directories
depsweep --measure-impact --ignore "tests/**,docs/**" --dry-run

# Protect specific dependencies
depsweep --measure-impact --safe "lodash,moment" --dry-run

# Aggressive cleanup (removes protected dependencies)
depsweep --measure-impact --aggressive --dry-run

# Combine multiple options
depsweep --measure-impact --aggressive --safe "express" --ignore "src/**,tests/**" --verbose

Environmental Impact

DepSweep calculates the environmental impact of removing unused dependencies using scientifically validated methodologies:

  • Carbon Savings: CO2 equivalent reduction (kg CO2e)
  • Energy Savings: Reduced data center energy consumption (kWh)
  • Water Savings: Reduced cooling water usage (liters)
  • Tree Equivalents: Trees that would need to be planted to offset carbon
  • Car Miles: Equivalent miles driven to produce the same CO2

Example Output

Environmental Impact Analysis

Total Environmental Impact
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Metric                  β”‚ Value              β”‚ Impact                            β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ Carbon Savings          β”‚ 0.492 kg CO2e      β”‚ Equivalent to 0.02 trees/year     β”‚
β”‚                         β”‚                    β”‚ trees planted                     β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ Energy Savings          β”‚ 1.273 kWh          β”‚ Reduced data center energy        β”‚
β”‚                         β”‚                    β”‚ consumption                       β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ Water Savings           β”‚ 2.4 L              β”‚ Reduced data center cooling needs β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ Car Miles Equivalent    β”‚ 1.3 miles          β”‚ CO2 savings equivalent to driving β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ Efficiency Gain         β”‚ 18.5%              β”‚ Improved build and runtime        β”‚
β”‚                         β”‚                    β”‚ performance                       β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Safety Features

Protected Dependencies

DepSweep automatically protects critical dependencies:

  • Runtime Dependencies: express, react, vue, angular
  • Build Tools: webpack, typescript, babel
  • Testing Frameworks: jest, mocha, cypress
  • Code Quality: eslint, prettier, husky

Safe Dependencies

Protect specific packages from removal:

depsweep --safe "lodash,moment,axios" --measure-impact --dry-run

Dry Run Mode

Always test before making changes:

depsweep --measure-impact --dry-run  # Safe - no changes made
depsweep --measure-impact            # Actually removes dependencies

Configuration Options

Option Short Description
--measure-impact -m Calculate environmental impact
--dry-run -d Run without making changes
--verbose -v Display detailed information
--aggressive -a Allow removal of protected dependencies
--safe <deps> -s Dependencies that will not be removed
--ignore <paths> -i Patterns to ignore during scanning
--no-progress -n Disable progress bar
--version Display version information
--help -h Display help information

Advanced Usage

Ignore Patterns

# Ignore multiple directories
depsweep --ignore "src/**,tests/**,docs/**" --measure-impact --dry-run

# Ignore specific file types
depsweep --ignore "*.test.js,*.spec.js" --measure-impact --dry-run

Workspace Support

DepSweep automatically detects and analyzes:

  • Monorepos with workspaces
  • Lerna projects
  • Yarn workspaces
  • pnpm workspaces

GitHub Actions - Analyze Any Repository

DepSweep includes a GitHub Actions workflow that allows you to analyze any repository or npm package without cloning it locally. Results are automatically posted as a comment on your issue and the issue is closed.

Using Issue Template (Recommended)

  1. Go to the Issues tab in the DepSweep repository
  2. Click New Issue
  3. Select Analyze Repository template
  4. Fill in the form:
    • Repository URL or Package Name: Enter either:
      • A GitHub repository URL: https://github.com/user/repo
      • An npm package name: express, lodash, etc.
    • Branch (optional): Branch to analyze for GitHub repos (default: main)
    • Ignore Patterns (optional): Comma-separated patterns to ignore
    • Verbose output (optional): Check for detailed output
  5. Click Submit new issue

The workflow will automatically:

  • Clone the repository (if GitHub URL) or install the package
  • Run DepSweep analysis with environmental impact reporting
  • Generate a comprehensive report
  • Post results as a comment on the issue
  • Close the issue automatically
  • Upload detailed report as a downloadable artifact

Using Workflow Dispatch (Advanced)

For manual workflow execution:

  1. Go to the Actions tab
  2. Select Analyze Repository workflow
  3. Click Run workflow
  4. Enter repository URL or package name
  5. Configure options and run

Note: The issue template method is recommended as it provides better tracking and automatic result posting.

Performance Optimization

  • Memory Efficient: Uses optimized caching and memory management
  • Concurrent Processing: Parallel file analysis for faster results
  • Smart Caching: Caches dependency analysis results

Supported Project Types

  • Node.js: Express, Koa, Fastify applications
  • React: Create React App, Next.js, Gatsby
  • Vue: Vue CLI, Nuxt.js
  • Angular: Angular CLI applications
  • TypeScript: Pure TypeScript projects
  • Monorepos: Lerna, Yarn workspaces, pnpm workspaces

Testing

# Run all tests
npm test

# Run with coverage
npm run test:coverage

# Run specific test suites
npm run test:unit
npm run test:e2e

Performance

DepSweep is optimized for performance:

  • Memory Usage: 25-44MB for large projects
  • Processing Speed: 1-2 seconds for complex projects
  • Concurrent Operations: Parallel file processing
  • Smart Caching: Reduces redundant operations

Contributing

We welcome contributions! Please see our Contributing Guide for details.

Development Setup

# Clone the repository
git clone https://github.com/yourusername/depsweep.git
cd depsweep

# Install dependencies
npm install

# Build the project
npm run build

# Run tests
npm test

# Link for local development
npm link

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

  • Environmental impact calculations based on peer-reviewed research from IEA, EPA, USDA, and other scientific organizations
  • Built with enterprise-grade security and reliability standards
  • Thanks to all contributors and the open-source community

Support


DepSweep - Optimizing dependencies, reducing waste, building sustainably

About

Automated dependency cleanup and impact analysis report

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Sponsor this project

  •  

Packages

 
 
 

Contributors