@mwpryer/pm
v0.3.1
Published
Unified CLI for npm/pnpm/bun
Readme
pm
Unified CLI for npm, pnpm, and bun.
Why
Every package manager has its own CLI with different commands, flags, and quirks. Switching between projects means remembering which incantation to use.
pm detects your project's package manager and translates a single set of commands automatically, so you only need to learn one CLI.
Install
npm i -g @mwpryer/pmCommands
| Command | Description |
| ------- | ----------------------------------- |
| ni | Install dependencies / add packages |
| nr | Run scripts |
| nun | Uninstall packages |
| nci | Clean install (frozen lockfile) |
| nup | Upgrade packages |
| ndd | Deduplicate dependencies |
| nlx | Execute packages |
| na | Agent passthrough |
ni - install
| Usage | npm | pnpm | bun |
| -------------- | ------------------ | -------------------------- | ------------------------------- |
| ni | npm i | pnpm i | bun install |
| ni zod | npm i zod | pnpm add zod | bun add zod |
| ni -D vitest | npm i -D vitest | pnpm add -D vitest | bun add -d vitest |
| ni -g tsx | npm i -g tsx | pnpm add -g tsx | bun add -g tsx |
| ni --frozen | npm ci | pnpm i --frozen-lockfile | bun install --frozen-lockfile |
| ni -P | npm i --omit=dev | pnpm i --production | bun install --production |
| ni zod -w ui | npm i zod -w ui | pnpm add zod --filter ui | bun add zod --cwd packages/ui |
nr - run
| Usage | npm | pnpm | bun |
| -------------------- | ----------------------------------------- | ---------------------------- | ---------------------------- |
| nr | npm run start | pnpm run start | bun run start |
| nr dev | npm run dev | pnpm run dev | bun run dev |
| nr dev --port 3000 | npm run dev -- --port 3000 | pnpm run dev --port 3000 | bun run dev --port 3000 |
| nr - | Rerun last script | Rerun last script | Rerun last script |
| nr build -w ui | npm run -w ui build | pnpm --filter ui run build | bun run --filter ui build |
| nr build -r | npm run --workspaces --if-present build | pnpm -r run build | bun run --workspaces build |
-w <pkg> targets a single workspace package and -r runs across all of them. Both work from any directory in the monorepo.
nun - uninstall
| Usage | npm | pnpm | bun |
| --------------- | ------------------------- | ----------------------------- | ---------------------------------- |
| nun zod | npm uninstall zod | pnpm remove zod | bun remove zod |
| nun -g tsx | npm uninstall -g tsx | pnpm remove --global tsx | bun remove -g tsx |
| nun zod -w ui | npm uninstall zod -w ui | pnpm remove zod --filter ui | bun remove zod --cwd packages/ui |
nci - clean install
Runs a frozen install if a lockfile exists, otherwise falls back to a regular install.
| Usage | npm | pnpm | bun |
| ------------------- | -------- | -------------------------- | ------------------------------- |
| nci (lockfile) | npm ci | pnpm i --frozen-lockfile | bun install --frozen-lockfile |
| nci (no lockfile) | npm i | pnpm i | bun install |
nup - upgrade
| Usage | npm | pnpm | bun |
| --------- | ---------------- | ----------------- | ---------------- |
| nup | npm update | pnpm update | bun update |
| nup zod | npm update zod | pnpm update zod | bun update zod |
| nup -i | N/A | pnpm update -i | bun update -i |
ndd - dedupe
| Usage | npm | pnpm | bun |
| -------- | ---------------------- | --------------------- | --- |
| ndd | npm dedupe | pnpm dedupe | N/A |
| ndd -c | npm dedupe --dry-run | pnpm dedupe --check | N/A |
nlx - execute
| Usage | npm | pnpm | bun |
| ------------ | ------------ | ----------------- | -------------- |
| nlx vitest | npx vitest | pnpm dlx vitest | bun x vitest |
na - agent
Passes arguments directly to the detected package manager.
| Usage | npm | pnpm | bun |
| --------------- | ---------------- | ----------------- | ---------------- |
| na info react | npm info react | pnpm info react | bun info react |
Detection
pm detects the package manager in the following order:
- Lockfiles:
bun.lockorbun.lockb,pnpm-lock.yamlorpnpm-workspace.yaml,package-lock.json - The
packageManagerfield inpackage.json - The
defaultAgentsetting from the config file
Configuration
Config file: ~/.pmrc.json
{
"defaultAgent": "npm",
"globalAgent": "npm"
}| Option | Description | Default |
| -------------- | ------------------------------- | ------- |
| defaultAgent | Fallback when no PM is detected | npm |
| globalAgent | PM used for -g operations | npm |
Environment variables
| Variable | Description |
| ------------------ | ------------------------ |
| PM_DEFAULT_AGENT | Overrides defaultAgent |
| PM_GLOBAL_AGENT | Overrides globalAgent |
| PM_CONFIG_FILE | Custom config file path |
Environment variables take priority over the config file.
Other features
pm has a few extras:
- append
?to any command to print it without running it, for exampleni zod ? - pass
-C <dir>to run the command in another directory, for exampleni -C packages/core - run
nr -to rerun the last script
Credits
Inspired by @antfu/ni.
