Automatic Detection
Better PM detects the package manager by searching for lock files in your project:Detection Process
1
Search upward for lock files
Better PM searches from your current directory upward to the home directory or filesystem root using the
findUpward utility.2
Select the first match
The first lock file found determines the package manager. Lock files are checked in priority order: pnpm → bun → npm.
3
Store the lock directory
The directory containing the lock file becomes the
lockDir, which Better PM uses as the monorepo root for all operations.The
findUpward function stops at the home directory to prevent searching the entire filesystem, ensuring fast detection even in nested directories.Workspace Detection
Each package manager has a different way of defining workspaces:- pnpm uses a dedicated
pnpm-workspace.yamlfile - bun and npm use the
workspacesfield inpackage.json
Command Mapping
Better PM translates unified commands into package manager-specific syntax:Install Commands
- pnpm:
-F <package> - bun:
--filter <package> - npm:
-w <package>
Add Commands
- pnpm:
pnpm add - bun:
bun add - npm:
npm install
Remove Commands
- pnpm:
pnpm remove - bun:
bun remove - npm:
npm uninstall
Package Manager Service Interface
All package managers implement thePackageManagerService interface, ensuring consistent behavior:
Workspace Package Enumeration
Better PM lists workspace packages by reading workspace configuration and enumerating directories:enumerateWorkspacePackages function handles glob patterns like packages/* and apps/*, reading the package.json name from each discovered directory (see src/pm/package-manager-service.ts:64-115).
Benefits of Abstraction
One Command to Learn
Use
pm i, pm add, pm remove regardless of the package manager. No need to remember if your project uses pnpm, bun, or npm.Project Portability
Switch package managers by changing the lock file. Better PM adapts automatically without requiring workflow changes.
Team Consistency
Everyone on the team uses the same commands, even if they work across multiple projects with different package managers.
Simplified CI/CD
Write CI scripts once using
pm commands that work across all your repositories, regardless of package manager.