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|@#.#.#]>
TODO | command | swpm | npm | yarn | yarn (berry) | pnpm | bun |
---|---|---|---|---|---|---|---|
[ ] | clean cache | npm cache clean |
yarn cache clean |
yarn cache clean |
N/A | bun pm cache rm |
|
[x] | install from package.json |
swpm install |
npm install |
yarn [install] |
yarn [install] |
pnpm install |
bun install |
[x] | don't read or generate a lockfile | swpm install --package-lock |
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 | |||
[x] | lockfile is not updated | swpm install --frozen |
npm ci |
yarn install --frozen-lockfile |
yarn install --immutable |
pnpm install --frozen-lockfile |
bun install --frozen-lockfile |
[x] | add package | swpm add <package> [--global] |
npm install <package> [--global] |
yarn [global] add <package> |
yarn [global] add <package> |
pnpm add <package> [--global] |
bun add <package> [--global] |
[x] | add package as dependencies |
swpm add <package> |
npm install <package> |
yarn add <package> |
yarn add <package> |
pnpm add <package> |
bun add <package> |
[x] | add package as devDependencies |
swpm add <package> --save-dev |
npm install <package> --save-dev |
yarn add <package> --dev |
yarn add <package> --dev |
pnpm add <package> --save-dev |
bun add <package> --dev |
[x] | add package as optionalDependencies |
swpm add <package> --save-optional |
npm install <package> --save-optional |
yarn add <package> --optional |
yarn add <package> --optional |
pnpm add <package> --save-optional |
bun add <package> --optional |
[x] | add package as peerDependencies |
swpm add <package> --save-peer |
npm install <package> --save-peer |
yarn add <package> --peer |
yarn add <package> --peer |
pnpm add <package> --save-peer |
N/A |
[x] | add exact version | swpm add <package> --save-exact |
npm install <package> --save-exact |
yarn add <package> --exact |
yarn add <package> --exact |
pnpm add <package> --save-exact |
bun add <package> --exact |
[x] | remove package | swpm remove [<package>] [--global] |
npm uninstall <package> [--global] |
yarn [global] remove <package> |
yarn [global] remove <package> |
pnpm uninstall <package> [--global] |
bun remove [<package>] [--global] |
[x] | remove package as dependencies |
swpm remove <package> |
npm uninstall <package> |
yarn remove <package> |
yarn remove <package> |
pnpm uninstall <package> |
bun remove <package> |
[x] | remove package as devDependencies |
swpm remove <package> --save-dev |
npm uninstall <package> --save-dev |
yarn remove <package> --dev |
yarn remove <package> --dev |
pnpm uninstall <package> --save-dev |
bun remove <package> --dev |
[x] | remove package as optionalDependencies |
swpm remove <package> --save-optional |
npm uninstall <package> --save-optional |
yarn remove <package> --optional |
yarn remove <package> --optional |
pnpm uninstall <package> --save-optional |
bun remove <package> --optional |
[x] | remove package as peerDependencies |
swpm remove <package> --save-peer |
npm uninstall <package> --save-peer |
yarn remove <package> --peer |
yarn remove <package> --peer |
pnpm uninstall <package> --save-peer |
N/A |
[x] | update package (no package.json ) |
swpm update [<package>] [--global] |
npm update [<package>] [--global] |
yarn [global] upgrade [<package>] |
yarn [global] semver up [<package>] |
pnpm update [<package>] [--global] |
N/A |
[x] | upgrade package on package.json |
swpm upgrade <package> [--global] |
npm add <package>@latest [--global] |
yarn [global] upgrade <package> --latest |
yarn [global] up <package> |
pnpm update <package> --latest [--global] |
N/A |
[x] | upgrade interactive | swpm interactive |
N/A | yarn upgrade-interactive |
yarn upgrade-interactive |
pnpm upgrade --interactive |
N/A |
[ ] | list all package at the top level | npm list --depth 0 [--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] |
Use the same command structure between package managers.
TODO | command | swpm | npm | yarn | yarn (berry) | pnpm | bun |
---|---|---|---|---|---|---|---|
[x] | init or create | swpm init |
npm init |
yarn init |
yarn init |
pnpm init |
bun init |
[x] | login/logout | swpm <login|logout> |
npm <login|logout> |
yarn <login|logout> |
yarn <login|logout> |
pnpm <login|logout> |
TBA |
[x] | run scripts | swpm run <script> |
npm run <script> |
yarn run <script> |
yarn run <script> |
pnpm [run] <script> |
bun run <script> |
[x] | run test | swpm test |
npm test |
yarn test |
yarn test |
pnpm test |
bun test |
[x] | crate bundle package | swpm build |
npm build |
yarn build |
yarn build |
pnpm build |
bun build |
[x] | publish | swpm publish |
npm publish |
yarn publish |
yarn npm publish |
pnpm publish |
TBA |
[x] | unpublish | swpm unpublish <package>[@#.#.#] |
npm unpublish <package>[@#.#.#] |
yarn unpublish <package>[@#.#.#] |
yarn unpublish <package>[@#.#.#] |
pnpm unpublish <package>[@#.#.#] |
TBA |
[x] | deprecate | swpm deprecate <package>[@#.#.#] <message> |
npm deprecate <package>[@#.#.#] <message> |
yarn deprecate <package>[@#.#.#] <message> |
yarn deprecate <package>[@#.#.#] <message> |
pnpm deprecate <package>[@#.#.#] <message> |
TBA |
[x] | config list | swpm config list |
npm config list |
yarn config list |
yarn config list |
pnpm config list |
TBA |
[x] | config --save-default as default |
swpm config set save-exact true |
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 |
[x] | config ~ as default instead ^ |
swpm config set save-prefix '~' |
npm config set save-prefix '~' |
yarn config set save-prefix '~' |
yarn config set save-prefix '~' |
pnpm config set save-prefix '~' |
TBA |
[x] | list outdated packages | swpm outdated [<package>] [--global] |
npm outdated [<package>] [--global] |
yarn [global] [<package>] outdated |
yarn [global] [<package>] upgrade-interactive |
pnpm outdated [<package>] [--global] |
TBA |
[x] | link local package | swpm link |
npm link [<folder>] |
yarn link [<folder>] |
yarn link [<folder>] |
pnpm link [<folder>] |
bun link [<folder>] |
[x] | unlink local package | swpm unlink |
npm unlink [<folder|package> --no-save] |
yarn unlink [<folder|package>] |
yarn unlink [<folder|package>] |
pnpm unlink [<folder|package>] |
bun unlink [<folder|package>] |
Run a command without installing it.
TODO | command | swpx | npm | yarn | yarn (berry) | pnpm | bun |
---|---|---|---|---|---|---|---|
[x] | run package | swpx <package> |
npx <package> |
yarn dlx <package> |
yarn dlx <package> |
pnpm dlx <package> |
bunx <package> |