scanner package provides the primary logic for scanning directories, detecting heavy dependency folders, and cleaning them up. It supports concurrent scanning, interactive selection, and optional reinstallation.
Overview
The scanner module is the heart of Pumu’s functionality, offering three main operations:- Sweep: Find and delete heavy dependency folders
- Repair: Detect broken dependencies and repair them
- Refresh: Clean and reinstall dependencies for the current directory
Types
TargetFolder
Represents a detected heavy dependency folder with its calculated size.Functions
SweepDir
Scans a root directory for heavy dependency folders and optionally deletes them.The root directory to scan for heavy dependency folders
If true, only lists folders without deleting them (list-only mode)
If true, automatically reinstalls dependencies after deletion
If true, skips interactive selection and processes all found folders
Returns an error if scanning fails, nil on success
How it works
- Recursively scans the directory tree for known dependency folders
- Calculates sizes concurrently (max 20 parallel operations)
- Presents an interactive selection UI (unless
noSelectis true) - Deletes selected folders concurrently
- Optionally reinstalls dependencies if
reinstallis true
Example usage
RepairDir
Scans for projects with broken dependencies and automatically repairs them.The root directory to scan for projects
If true, shows detailed output including healthy projects
Returns an error if scanning fails, nil on success
How it works
- Finds all projects by detecting package managers
- Runs health checks on each project using
pkg.CheckHealth() - For unhealthy projects:
- Displays detected issues
- Removes the dependency folder (node_modules, target, .venv, etc.)
- Reinstalls dependencies
- Reports summary of repaired projects
Example usage
RefreshCurrentDir
Detects the package manager in the current directory, removes dependencies, and reinstalls them.Returns an error if detection fails, removal fails, or installation fails
How it works
- Detects package manager in current directory (
.) - Returns error if no package manager detected
- Removes the appropriate dependency folder (node_modules, target, .venv)
- Reinstalls dependencies using the detected package manager
- Reports duration and success
Example usage
Example output
Internal Functions
findTargetFolders
Recursively walks the directory tree to find deletable target folders.node_modules(JavaScript/TypeScript)target(Rust).next(Next.js).svelte-kit(SvelteKit).venv(Python)dist(build output)build(build output)
calculateFolderSizes
Calculates sizes for all target folders concurrently.selectFolders
Presents an interactive multi-select UI for choosing folders.nil if user cancels, otherwise returns the filtered list of selected folders.