npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

dep-cleaner

v1.2.3

Published

Easily detect and automatically uninstall unused npm dependencies with a single command!

Downloads

2

Readme

🧹 Cleanup Unused Dependencies

Easily detect and automatically uninstall unused npm dependencies with a single command!

💡 Based on Depcheck

This utility is built upon the foundation provided by depcheck. depcheck is a tool for analyzing the dependencies in a project to see: how each dependency is used, which dependencies are useless, and which dependencies are missing from package.json.

Our tool extends the capabilities of depcheck by automating the cleanup process and integrating with multiple package managers for a smoother user experience.

🚀 Features

  • 🕵️‍♂️ Detect Unused Dependencies: The tool scans your project and identifies unused npm dependencies.
  • 📦 Fastest Package Manager: Utilizes the quickest available package manager, prioritizing bun, pnpm, yarn, and npm.
  • 🤖 Display Mode: Option to only display unused dependencies without uninstalling them.
  • Interactive Cleanup: Offers an interactive mode to select which unused dependencies to uninstall.
  • 🚫 Skip Confirmation: Speed up the cleanup process by bypassing user confirmation using the --no-confirm flag.

🛠 Installation

Using npm:

npm install -g dep-cleaner

Using yarn:

yarn global add dep-cleaner

Using pnpm:

pnpm add -g dep-cleaner

Using bun:

bun add global dep-cleaner

📖 Usage

To detect and uninstall unused dependencies:

dep-cleaner

To only display the unused dependencies without uninstalling:

dep-cleaner --show-only

To uninstall unused dependencies without confirmation:

dep-cleaner --no-confirm

🤖 Automation Integration

To maximize the benefits of dep-cleaner, it's highly recommended to integrate it into your project's automation workflow. This ensures that unused dependencies are consistently identified and removed, keeping your project lean and efficient.

Continuous Integration (CI):

Integrate dep-cleaner into your CI pipeline to automatically check for unused dependencies during every build. This way, you'll be alerted if any unused dependencies exist before deploying or releasing your code.

Example for a CI script:

# Install dep-cleaner
npm install -g dep-cleaner

# Run dep-cleaner
dep-cleaner

Git Hooks:

Using tools like Husky, you can add pre-commit or pre-push hooks that run dep-cleaner to ensure no unused dependencies are committed to the repository.

Example using Husky:

  1. Install Husky:
npm install husky --save-dev
  1. Add a pre-push hook:
"husky": {
    "hooks": {
        "pre-push": "dep-cleaner"
    }
}

This ensures that before every push to the repository, dep-cleaner runs and cleans up any unused dependencies.

Recommendations:

  • Continuous Integration (CI): For teams or larger projects, integrating into the CI pipeline ensures a clean codebase during every build.

  • Development Environment: For individual developers, using Git hooks ensures the local codebase remains clean during development.

By making dep-cleaner a part of your regular development and deployment process, you ensure a leaner, more efficient, and less error-prone codebase.

🔧 Configuration

By default, the script uses the fastest detected package manager. Ensure you have at least one of the supported package managers (bun, pnpm, yarn, npm) installed.

🤝 Contributing

Pull requests are welcome! For major changes, please open an issue first to discuss what you'd like to change.

📜 License

MIT