detector module provides intelligent package manager detection by analyzing lock files and manifest files in project directories.
Overview
Detector uses a priority-based approach to identify which package manager a project uses. This is critical for:- Determining the correct install command
- Identifying the appropriate dependency folder to clean
- Running ecosystem-specific health checks
Types
PackageManager
Represents the type of package manager detected in a project.Constants
Supported Package Managers
Functions
DetectManager
Identifies the package manager used in a directory by checking for lock files and manifests.The directory path to check for package manager files
Returns the detected package manager, or
Unknown if none foundDetection Priority
The function checks for lock files in order of specificity:- Bun -
bun.lockb,bun.lock - Pnpm -
pnpm-lock.yaml - Yarn -
yarn.lock - Npm -
package-lock.json - Deno -
deno.json,deno.jsonc - Cargo -
Cargo.toml - Go -
go.mod - Pip -
requirements.txt,pyproject.toml
Example usage
Detection Logic
JavaScript Ecosystem
For JavaScript/TypeScript projects, detection follows modern tooling preferences:- Bun has highest priority (fastest, modern)
- Pnpm second (efficient disk usage)
- Yarn third (popular in monorepos)
- Npm last (fallback, most common)
Why Lock Files?
Lock files are preferred over manifest files (package.json, Cargo.toml) because:
- They indicate which package manager was actually used
- They’re generated automatically by the respective tool
- They avoid ambiguity (many projects have
package.jsonbut use different managers)
Cross-ecosystem Support
Helper Functions
fileExists
Internal helper to check if a file exists and is not a directory.DetectManager to verify lock file presence.
Usage Patterns
Pattern 1: Detecting Before Operations
Pattern 2: Filtering Projects
Pattern 3: Display to User
Extension
To add support for a new package manager:- Add a new constant to
PackageManagertype - Update the
managersmap inDetectManagerwith lock file patterns - Update corresponding functions in
installer.go,checker.go, andanalyzer.go