How Context Detection Works
When you runpm i, Better PM analyzes your current directory to determine the monorepo context:
Find the nearest package.json
Better PM searches upward from your current directory using
findUpward('package.json') to locate the nearest package definition.Determine context type
Better PM compares the package.json location with the lock file directory to determine if you’re in:
- A package directory: When the package.json is in a subdirectory of the lock file location
- The root directory: When the package.json is at the same level as the lock file
Auto-Scoping from Package Directories
When you runpm i from inside a workspace package, Better PM automatically filters the install to that package:
How Auto-Filtering Works
Better PM builds a filtered install command based on the package manager:pnpm uses the
... suffix (e.g., @myapp/web...) which installs the package and all its dependencies.bun and npm resolve the full dependency graph of workspace packages by reading package.json files and following workspace: protocol dependencies.Root Directory Warnings
When you runpm i at the monorepo root, Better PM protects you from accidentally installing all packages:
Safety Features
Workspace Package List
The warning displays a formatted tree of all workspace packages using the
formatWorkspaceTree function, helping you understand the scope of what would be installed.Confirmation Prompt
In interactive environments, Better PM prompts for confirmation before proceeding with a full install. The prompt can be bypassed with the
-y or --sure flag.Filter Flag Usage
You can manually specify which packages to install using the-F or --filter flag:
How Filters Override Auto-Scoping
When filters are provided, they take precedence over context detection:Context Type Reference
Better PM uses two context types internally:- root: You’re at the monorepo root or in a directory without a package.json
- package: You’re inside a workspace package directory