How Better PM Detects Monorepos
Better PM uses lockfile detection to identify your package manager and workspace root. It searches upward from your current directory to find:pnpm-lock.yamlfor pnpm workspacesbun.lockorbun.lockbfor bun workspacespackage-lock.jsonfor npm workspaces
The detection logic is in
src/pm/detect.ts and uses the findUpward utility to traverse the filesystem from your current working directory up to your home directory.Supported Workspace Configurations
- pnpm
- bun
- npm
Better PM reads your The CLI parses this file line-by-line to extract glob patterns, then enumerates all matching packages.
pnpm-workspace.yaml file to discover workspace packages:pnpm-workspace.yaml
Context-Aware Installation
Better PM changes behavior based on where you run commands:Inside a workspace package
When you run How it works:
pm i from within a workspace package directory, Better PM automatically scopes the install to that package only:- Searches upward for the nearest
package.json - Compares its directory with the lockfile directory
- If they differ and the package is within the monorepo, applies a filter
- For pnpm: uses
-F @myapp/web...(includes transitive workspace deps) - For bun/npm: resolves all workspace dependencies recursively
Targeted Package Installation
Install specific workspace packages from anywhere in your monorepo:-F flag (alias for --filter) works consistently across all package managers:
- pnpm: maps to
pnpm -F <pkg> install - bun: maps to
bun install --filter <pkg> - npm: maps to
npm install -w <pkg>
Workspace Navigation
Quickly navigate between workspace packages usingpm cd:
The
pm cd command requires shell integration to work. Without it, pm cd only prints the directory path.Example Monorepo Workflow
Here’s a complete example of working with a typical monorepo:Best Practices
Always use pm i from package directories
Always use pm i from package directories
When working within a package, let Better PM automatically scope your installs:Good:Avoid:
Use -y in CI environments
Use -y in CI environments
Continuous integration should never prompt interactively:The
.github/workflows/ci.yml
-y flag (alias for --sure) confirms root-level installs without prompting.Leverage workspace dependency resolution
Leverage workspace dependency resolution
Better PM automatically includes workspace dependencies when installing:If
@myapp/web depends on @myapp/ui, running pm i from apps/web/ will install both packages.For pnpm, this uses the ... suffix: -F @myapp/web...
For bun/npm, dependencies are resolved recursively via collectWorkspaceDependencies.Organize packages by type
Organize packages by type
Structure your workspace for clarity:This makes
pm pls output more readable and helps with workspace organization.Common Issues
Advanced Configuration
Filter Patterns
Better PM passes filter values directly to your package manager, so you can use their native patterns:Package Manager Detection Order
Lockfiles are checked in this priority:pnpm-lock.yaml→ pnpmbun.lock→ bunbun.lockb→ bunpackage-lock.json→ npm
Workspace Dependency Resolution
For bun and npm, Better PM recursively resolves workspace dependencies by:- Reading all workspace package
package.jsonfiles - Building a dependency graph of workspace packages
- Including all transitive workspace dependencies in the filter