A modern, powerful CLI tool for cleaning build artifacts, dependencies, and caches from JavaScript/TypeScript projects.
Tired of manually deleting node_modules, dist, and cache folders? Purgo automates the cleanup process with a single command, helping you reclaim disk space and ensure a clean slate for your builds.
Features β’ Installation β’ Quick Start β’ Configuration β’ Examples
- π Blazing Fast - Built with Bun and optimized TypeScript
- π― Highly Configurable - Multiple configuration formats supported
- π Extensible - Pre/post-clean hooks system
- π§ Smart Detection - Removes only top-level directories intelligently
- π¨ Modern UI - Colorful, interactive terminal interface
- π Safe Operations - Confirmation required before deletion with dry-run mode
- π¦ Framework Aware - Built-in targets for popular frameworks
- β‘ Instant Setup - No configuration needed to get started
bun install -g purgo-cli
# or
npm install -g purgo-clibun install purgo-cli --save-dev
# or
npm install purgo-cli --save-devFor one-off or scripted use, it's best to run Purgo with bunx or npx. This ensures you are always using the latest version without adding it to your project's dependencies.
# Preview what will be deleted
bunx purgo-cli clean --dry-run
# Execute the cleanup
bunx purgo-cli clean
# or
npx purgo-cli cleanTip: Using
bunxornpxavoids potential conflicts with locally installed package versions.
purgo-cli cleanpurgo-cli clean --dry-runpurgo-cli clean --reinstallNote on Package Manager Precedence: When using
--reinstall, Purgo determines which package manager to use with the following priority:
- Invoked Runner: If you run
purgo-cliwithbunx,npx,yarn dlx, orpnpm dlx, it will usebun,npm,yarn, orpnpm, respectively.- Lockfile: If the runner can't be determined, it will check for a lockfile in your project, prioritizing
bun.lockb>pnpm-lock.yaml>yarn.lock>package-lock.json.
purgo-cli clean --path ./packages/my-apppurgo-cli clean --targets "node_modules,dist,.next,coverage"purgo supports multiple configuration formats via cosmiconfig:
purgo.config.js/purgo.config.tspurgo.config.json.purgorc.purgorc.json.purgorc.jspurgofield inpackage.json
Create a .purgorc.json in your project root:
{
"targets": ["node_modules", "dist", "build", "coverage"],
"ignore": ["**/important-data/**"],
"hooks": {
"preClean": "echo 'Starting cleanup...'",
"postClean": "echo 'Cleanup completed!'"
}
}| Field | Type | Description | Example |
|---|---|---|---|
targets |
string[] |
Directories/files to remove | ["node_modules", "dist"] |
ignore |
string[] |
Glob patterns to exclude | ["**/keep/**"] |
extends |
string | string[] |
Base config(s) to inherit | "./base.json" |
hooks.preClean |
string |
Run before cleanup | "npm run backup" |
hooks.postClean |
string |
Run after cleanup | "bun install" |
Create team-wide or shared configurations:
{
"extends": "./examples/shared-config.json",
"targets": ["custom-target"],
"ignore": ["**/data/**"]
}Set system-wide defaults at ~/.config/purgo/config.json or use a custom path:
purgo-cli clean --config /path/to/global-config.jsonBrowse the examples/ folder for pre-configured setups:
| Config | Best For | Key Features |
|---|---|---|
| basic-config.json | General projects | All default targets, simple hooks |
| nextjs-config.json | Next.js apps | .next, out, env files, auto-rebuild |
| react-vite-config.json | React + Vite | Vite cache, optimized for React |
| monorepo-config.json | Monorepos | Recursive patterns, workspace protection |
| ci-cd-config.json | CI/CD pipelines | Aggressive cleanup, removes OS files |
| development-config.json | Development | Preserves .env.local, quick cleanup |
| shared-config.json | Team base | Minimal setup for extending |
# Download an example directly
curl -o .purgorc.json https://raw.githubusercontent.com/andrebpessoa/purgo-cli/main/examples/basic-config.json
# Or for Next.js
curl -o .purgorc.json https://raw.githubusercontent.com/andrebpessoa/purgo-cli/main/examples/nextjs-config.jsonNext.js Project:
curl -o .purgorc.json https://raw.githubusercontent.com/andrebpessoa/purgo-cli/main/examples/nextjs-config.json
purgo-cli clean --reinstallMonorepo Cleanup:
curl -o .purgorc.json https://raw.githubusercontent.com/andrebpessoa/purgo-cli/main/examples/monorepo-config.json
purgo-cli clean --reinstallNote: The
monorepo-config.jsonuses recursive glob patterns (**/node_modules,**/dist) to automatically find and clean all packages in your workspace - no loops needed!
CI/CD Integration:
# In your CI pipeline
curl -o .purgorc.json https://raw.githubusercontent.com/andrebpessoa/purgo-cli/main/examples/ci-cd-config.json
bunx purgo-cli clean --dry-run # Preview
bunx purgo-cli clean # ExecuteExecute commands before and after cleanup:
{
"hooks": {
"preClean": "npm run backup-data",
"postClean": "npm run setup && npm run build"
}
}Hooks run in the project root directory and inherit the shell environment.
| Option | Alias | Description |
|---|---|---|
--dry-run |
-d |
List what would be deleted without deleting |
--path <path> |
-p |
Root directory to search from |
--reinstall |
-r |
Reinstall dependencies after cleanup (auto-detects npm/yarn/pnpm/bun) |
--targets <list> |
-t |
Comma-separated list of targets to clean |
--config <file> |
-c |
Path to global configuration file |
--force |
-f |
Skip confirmation prompt (useful for CI/CD) |
--verbose |
-v |
Show detailed output including retry attempts |
--quiet |
-q |
Suppress all non-essential output |
Effortlessly create your configuration file with our interactive setup wizard.
Usage:
purgo-cli initWhat it does:
- Prompts you to select targets and ignore patterns
- Optionally sets
preClean/postCleanhooks - Lets you choose where to save:
.purgorc.jsonorpackage.json(in thepurgofield)
Examples:
# Save to .purgorc.json in the current directory
purgo-cli init --path .
# Add the "purgo" field inside package.json
purgo-cli init --path ./my-appWhen no targets are specified, Purgo cleans:
node_modules- Dependenciesdist- Build outputbuild- Build artifactscoverage- Test coverage reports.turbo- Turborepo cache.next- Next.js build files.svelte-kit- SvelteKit build files
Note: Lock files (
package-lock.json,yarn.lock,pnpm-lock.yaml,bun.lockb,bun.lock) are not included in default targets to prevent accidental deletion. If you need to clean lock files, specify them explicitly:purgo-cli clean --targets "node_modules,dist,package-lock.json"
import { cleanProject } from 'purgo-cli';
await cleanProject({
rootDir: process.cwd(),
dryRun: false,
reinstall: true,
targets: ['node_modules', 'dist'],
configPath: './purgo.config.json'
});# Try with sudo (not recommended) or check file permissions
sudo purgo-cli clean# Install globally
bun install -g purgo-cli
# or use npx/bunx
bunx purgo-cli clean# This is normal - Purgo calculates sizes asynchronously
# Large dirs might show "calculating..." briefly# Ensure commands are available in PATH
# Use absolute paths if needed
"preClean": "/usr/local/bin/backup-script.sh"Enable verbose logging:
DEBUG=purgo-cli:* purgo-cli cleanWe welcome contributions! Please follow these steps:
-
Fork the repository
-
Create a feature branch
git checkout -b feature/amazing-feature
-
Make your changes
-
Add tests for new functionality
-
Ensure tests pass
bun test -
Update documentation if needed
-
Commit your changes
git commit -m 'Add amazing feature' -
Push to your branch
git push origin feature/amazing-feature
-
Open a Pull Request
# Clone the repo
git clone https://github.com/andrebpessoa/purgo-cli.git
cd purgo-cli
# Install dependencies
bun install
# Run tests
bun test
# Build the project
bun run build
# Test locally
bun run cli --help- Built with Bun - The fast JavaScript runtime
- Configuration powered by cosmiconfig
- UI components from ora and chalk
MIT Β© AndrΓ© Pessoa