If you want to get rid off all those different commands on each package manager I higly recommened to install SWPM and say good bye to package manager confussion. It will do all the commands translation for you.
This is a cheat sheet that you can use as a handy reference for npm, yarn, pnpm and bun commands.
Note:
<package>
follow this structure<package[@latest|@#.#.#]>
Package Commands
command | npm | yarn | yarn (berry) | pnpm | bun |
---|---|---|---|---|---|
clean cache | npm cache clean |
yarn cache clean |
yarn cache clean |
N/A | bun pm cache rm |
install from package.json
|
npm install |
yarn [install] |
yarn [install] |
pnpm install |
bun install |
don't read or generate a lockfile | npm install --no-package-lock |
yarn install --no-lockfile |
yarn install --no-lockfile |
N/A | bun install --no-save |
don't generate a lockfile | yarn install --pure-lockfile |
yarn install --pure-lockfile |
N/A | ||
lockfile is not updated | npm ci |
yarn install --frozen-lockfile |
yarn install --immutable |
pnpm install --frozen-lockfile |
bun install --frozen-lockfile |
add package | npm install <package> [--location=global] |
yarn [global] add <package> |
yarn [global] add <package> |
pnpm add <package> [--global] |
bun add <package> [--global] |
add package as dependencies
|
npm install <package> |
yarn add <package> |
yarn add <package> |
pnpm add <package> |
bun add <package> |
add package as devDependencies
|
npm install <package> --save-dev |
yarn add <package> --dev |
yarn add <package> --dev |
pnpm add <package> --save-dev |
bun add <package> --dev |
add package as optionalDependencies
|
npm install <package> --save-optional |
yarn add <package> --optional |
yarn add <package> --optional |
pnpm add <package> --save-optional |
bun add <package> --optional |
add package as peerDependencies
|
npm install <package> --save-peer |
yarn add <package> --peer |
yarn add <package> --peer |
pnpm add <package> --save-peer |
N/A |
add exact version | npm install <package> --save-exact |
yarn add <package> --exact |
yarn add <package> --exact |
pnpm add <package> --save-exact |
bun add <package> --exact |
remove package | npm uninstall <package> [--location=global] |
yarn [global] remove <package> |
yarn [global] remove <package> |
pnpm uninstall <package> [--global] |
bun remove [<package>] [--global] |
remove package as dependencies
|
npm uninstall <package> |
yarn remove <package> |
yarn remove <package> |
pnpm uninstall <package> |
bun remove <package> |
remove package as devDependencies
|
npm uninstall <package> --save-dev |
yarn remove <package> --dev |
yarn remove <package> --dev |
pnpm uninstall <package> --save-dev |
bun remove <package> --dev |
remove package as optionalDependencies
|
npm uninstall <package> --save-optional |
yarn remove <package> --optional |
yarn remove <package> --optional |
pnpm uninstall <package> --save-optional |
bun remove <package> --optional |
remove package as peerDependencies
|
npm uninstall <package> --save-peer |
yarn remove <package> --peer |
yarn remove <package> --peer |
pnpm uninstall <package> --save-peer |
N/A |
update package (no package.json ) |
npm update [<package>] [--location=global] |
yarn [global] upgrade [<package>] |
yarn [global] semver up [<package>] |
pnpm update [<package>] [--global] |
N/A |
upgrade package on package.json
|
npm install <package>@latest [--location=global] |
yarn [global] upgrade <package> --latest |
yarn [global] up <package> |
pnpm update <package> --latest [--global] |
N/A |
upgrade interactive | N/A | yarn upgrade-interactive |
yarn upgrade-interactive |
pnpm update --interactive |
N/A |
list all package at the top level | npm list --depth 0 [--location=global] |
yarn [global] list --depth 0 |
yarn [global] list --depth 0 |
pnpm list --depth 0 [--global] |
bun pm ls |
audit vulnerable dependencies | npm audit [fix] |
yarn audit |
yarn audit |
pnpm audit [--fix] |
Shared Commands
Use the same command structure between package managers.
command | npm | yarn | yarn (berry) | pnpm | bun |
---|---|---|---|---|---|
init or create | npm init |
yarn init |
yarn init |
pnpm init |
bun init |
login/logout | npm <login or logout> |
yarn <login or logout> |
yarn <login or logout> |
pnpm <login or logout> |
TBA |
run scripts | npm run <script> |
yarn run <script> |
yarn run <script> |
pnpm [run] <script> |
bun run <script> |
run test | npm test |
yarn test |
yarn test |
pnpm test |
bun test |
crate bundle package | npm build |
yarn build |
yarn build |
pnpm build |
bun build |
publish | npm publish |
yarn publish |
yarn npm publish |
pnpm publish |
TBA |
unpublish | npm unpublish <package>[@#.#.#] |
yarn unpublish <package>[@#.#.#] |
yarn unpublish <package>[@#.#.#] |
pnpm unpublish <package>[@#.#.#] |
TBA |
deprecate | npm deprecate <package>[@#.#.#] <message> |
yarn deprecate <package>[@#.#.#] <message> |
yarn deprecate <package>[@#.#.#] <message> |
pnpm deprecate <package>[@#.#.#] <message> |
TBA |
config list | npm config list |
yarn config list |
yarn config list |
pnpm config list |
TBA |
config --save-default as default |
npm config set save-exact true |
yarn config set save-exact true |
yarn config set save-exact true |
pnpm config set save-exact true |
TBA |
config ~ as default instead ^
|
npm config set save-prefix '~' |
yarn config set save-prefix '~' |
yarn config set save-prefix '~' |
pnpm config set save-prefix '~' |
TBA |
list outdated packages | npm outdated [<package>] [--location=global] |
yarn [global] [<package>] outdated |
yarn [global] [<package>] upgrade-interactive |
pnpm outdated [<package>] [--global] |
TBA |
link local package | npm link [<folder>] |
yarn link [<folder>] |
yarn link [<folder>] |
pnpm link [<folder>] |
bun link [<folder>] |
unlink local package | `npm unlink [<folder\ | package> --no-save]` | `yarn unlink [<folder\ | package>]` | `yarn unlink [<folder\ |
Run Remotely
Run a command without installing it.
command | npm | yarn | yarn (berry) | pnpm | bun |
---|---|---|---|---|---|
run package | {% raw %}npx <package>
|
yarn dlx <package> |
yarn dlx <package> |
pnpm dlx <package> |
bunx <package> |
CLI documentation
Source
Contributions are welcome.
deinsoftware / swpm
Switch Package Manager - Say goodbye to Package Manager confusion
Switch Package Manager
Menu
Getting Started
When switching between JavaScript projects, it's often easy to forget which package manager should be used. JavaScript package managers aren't quite compatible either and each one resolves dependencies differently, so accidentally installing with npm
could cause a yarn
(classic or berry), pnpm
or bun
project to break.
swpm
is a CLI that intends to solve this problem by unifying the most used commands for the most common Node Package Managers into one. It will recognize the Package Manager used on the project and automatically will translate those commands.
This is an example of how #swpm works. The same command, no matter the package manager used on the project.
Note:
We will start with most used command, then other commands will be added gradually.
Track the command progress implementation on CHEATSHEET.Progress…
That’s All Folks!
Happy Coding 🖖
Latest comments (2)
SWPM FTW!
Hey! It's really handy thanks for sharing :)