Skip to main content
One of Better PM’s most convenient features is paste-friendly command parsing. You can copy installation commands from documentation and paste them directly into pm add, regardless of which package manager the docs assume you’re using.

The Problem

You’re reading a library’s README and see:
But your project uses pnpm. You have to mentally translate:
  • npm installpnpm add
  • Extract the package name
  • Remember to add -D if it was --save-dev
With Better PM, just paste the whole command:
Better PM automatically detects it’s a pasted command and does the right thing.

How It Works

The paste detection logic is in src/lib/parse-pm-command.ts and handles the pm add command in src/commands/add.ts.
1

Detect pasted commands

When you pass a string to pm add, it checks if:
  1. The argument contains spaces (indicating a full command)
  2. The first token is a package manager name (npm, pnpm, or bun)
  3. The second token is an install subcommand (install, add, or i)
From parse-pm-command.ts
2

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 (-D or --save-dev): true
From parse-pm-command.ts
3

Build the correct command

Better PM then builds the installation command using your project’s package manager:
From add.ts
If your project uses pnpm and you pasted npm install -D foo, Better PM runs:

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

Copy from README:
Paste into Better PM:
Better PM runs (assuming your project uses pnpm):

Real-World Workflows

Copying from GitHub READMEs

1

Find the installation section

Navigate to a library’s README on GitHub:
From a typical README
npm install framer-motion
Output:

Copying from Documentation Sites

Many docs show multiple package manager options:
Example from docs
pnpm:

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:
Better PM throws an error:
From parse-pm-command.ts:40-43
This prevents accidentally running pm add without packages, which would fail.

Mixed Flags

If the pasted command has both -D from the paste AND you pass -D explicitly:
Both flags are recognized:
From parse-pm-command.ts:46
Result: 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

Not supported:
  • yarn commands: yarn add pkg is not detected (yarn not in PM_NAMES)
  • npm shorthands with flags: npm i -g pkg (global installs not supported by Better PM)
  • Complex flags: --legacy-peer-deps, --force, etc. are ignored
  • Version specifiers in paste: npm install [email protected] (the @1.2.3 becomes part of package name, which may fail)
For these cases, extract the package name manually:

Why This Feature Exists

From the README:
Copied a command from a README? Just paste it:
pm detects pasted npm install, pnpm add, bun add (and their shorthands like npm i) and extracts the packages and -D flag automatically.
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.

Source Code Deep Dive

The implementation is remarkably concise:
src/lib/parse-pm-command.ts (complete file)
Key insights:
  • Simple string splitting: Uses split(/\s+/) to tokenize
  • Negative filter: Packages are tokens that don’t start with -
  • Boolean flags: Checks for -D or --save-dev explicitly
  • Fall-through: If not a pasted command, returns args unchanged

Testing

You can test the parsing logic directly:
Check the output to see which command Better PM actually runs.