pm add, regardless of which package manager the docs assume you’re using.
The Problem
You’re reading a library’s README and see:npm install→pnpm add- Extract the package name
- Remember to add
-Dif it was--save-dev
How It Works
The paste detection logic is insrc/lib/parse-pm-command.ts and handles the pm add command in src/commands/add.ts.
Detect pasted commands
When you pass a string to
pm add, it checks if:- The argument contains spaces (indicating a full command)
- The first token is a package manager name (
npm,pnpm, orbun) - The second token is an install subcommand (
install,add, ori)
From parse-pm-command.ts
Extract packages and flags
If it’s a pasted command, Better PM:
- Splits the command by whitespace:
"npm install -D foo bar"→['npm', 'install', '-D', 'foo', 'bar'] - Extracts package names (tokens without
-prefix):['foo', 'bar'] - Detects dev flag (
-Dor--save-dev):true
From parse-pm-command.ts
Supported Formats
Better PM recognizes these package manager commands:npm
pnpm
bun
Valid Package Manager Names
From parse-pm-command.ts:1
Valid Subcommands
From parse-pm-command.ts:2
Examples
- Basic Usage
- Dev Dependencies
- Multiple Packages
- Scoped Packages
Copy from README:Paste into Better PM:Better PM runs (assuming your project uses pnpm):
Real-World Workflows
Copying from GitHub READMEs
Copying from Documentation Sites
Many docs show multiple package manager options:Example from docs
Copying from Stack Overflow
Stack Overflow answers often include full commands:To fix this, install the missing peer dependency:Just paste it:
Edge Cases
Empty Package List
If you paste a command without package names:From parse-pm-command.ts:40-43
pm add without packages, which would fail.
Mixed Flags
If the pasted command has both-D from the paste AND you pass -D explicitly:
From parse-pm-command.ts:46
dev = true || true = true (no duplication, just ensures dev mode).
Non-Pasted Commands
If you pass arguments without spaces (normal usage), Better PM skips parsing:From parse-pm-command.ts:26-32
Limitations
Why This Feature Exists
From the README:Copied a command from a README? Just paste it:This feature eliminates the mental overhead of translating between package managers when reading documentation, making Better PM truly package manager agnostic from the developer’s perspective.pmdetects pastednpm install,pnpm add,bun add(and their shorthands likenpm i) and extracts the packages and-Dflag automatically.
Source Code Deep Dive
The implementation is remarkably concise:src/lib/parse-pm-command.ts (complete file)
- Simple string splitting: Uses
split(/\s+/)to tokenize - Negative filter: Packages are tokens that don’t start with
- - Boolean flags: Checks for
-Dor--save-devexplicitly - Fall-through: If not a pasted command, returns args unchanged