nm-sweep
v1.1.1
Published
Remove node_modules from inactive Node.js repositories using Git commit history
Maintainers
Readme
nm-sweep
A cross-platform CLI tool to remove node_modules from inactive Node.js repositories using Git commit history.
Features
- Accurate inactivity detection using Git commit timestamps
- Monorepo support (npm workspaces, pnpm workspaces)
- Interactive selection or automatic cleanup
- Dry-run mode for safe preview
- Disk space estimation
- Cross-platform compatible (Windows, macOS, Linux)
Installation
npm install -g nm-sweepOr use npx without installation:
npx nm-sweepUsage
Basic Usage
Scan the current directory:
nm-sweepOptions
| Option | Alias | Default | Description |
|--------|-------|---------|-------------|
| --dir <path> | -d | current directory | Directory to scan |
| --months <number> | -m | 3 | Inactivity threshold in months |
| --dry-run | | false | Preview deletions without executing |
| --yes | -y | false | Skip confirmation prompt |
Examples
Scan a specific directory:
nm-sweep --dir /path/to/projectsUse 6-month inactivity threshold:
nm-sweep --months 6Preview what would be deleted:
nm-sweep --dry-runDelete all inactive node_modules without prompting:
nm-sweep --yesCombine options:
nm-sweep --dir ~/projects --months 6 --dry-runHow It Works
- Scan: Recursively scans the specified directory for Git repositories
- Validate: Checks each repository for
package.json(valid Node.js project) - Detect: Identifies monorepos via
workspacesfield orpnpm-workspace.yaml - Analyze: Gets the last commit timestamp using Git
- Filter: Filters repositories inactive beyond the threshold
- Discover: Finds all
node_modulesdirectories (root + workspace packages) - Select: Allows interactive selection or uses all inactive repos
- Delete: Removes selected
node_modulesdirectories
Requirements
- Node.js 14.14.0 or higher
- Git must be installed and available in PATH
License
MIT
