Side-by-side commands, scripts, versioning and workspaces.
Install
| npm |
pnpm |
Description |
npm install |
pnpm install |
Install all dependencies |
npm ci |
pnpm install --frozen-lockfile |
Clean install from lockfile (CI) |
npm install <pkg> |
pnpm add <pkg> |
Add dependency |
npm install -D <pkg> |
pnpm add -D <pkg> |
Add dev dependency |
npm install -g <pkg> |
pnpm add -g <pkg> |
Install globally |
npm uninstall <pkg> |
pnpm remove <pkg> |
Remove dependency |
Update and inspect
| npm |
pnpm |
Description |
npm outdated |
pnpm outdated |
Show outdated packages |
npm update |
pnpm update |
Update within ranges |
| — |
pnpm update --latest |
Update past ranges |
npm ls <pkg> |
pnpm why <pkg> |
Why is a package installed |
npm audit |
pnpm audit |
Security audit |
npm view <pkg> versions |
pnpm view <pkg> versions |
Published versions |
Run
| npm |
pnpm |
Description |
npm run dev |
pnpm dev |
Run a script |
npm run build -- --watch |
pnpm build --watch |
Pass arguments |
npx <cmd> |
pnpm dlx <cmd> |
Run package without installing |
npm exec <bin> |
pnpm exec <bin> |
Run a local binary |
npm create vite@latest |
pnpm create vite |
Scaffold a project |
Version ranges
| Range |
Allows |
Example for 1.2.3 |
^1.2.3 |
Minor and patch |
>=1.2.3 <2.0.0 |
~1.2.3 |
Patch only |
>=1.2.3 <1.3.0 |
1.2.3 |
Exact |
1.2.3 |
>=1.2.0 |
Any newer |
— |
* / latest |
Anything |
— |
Semver: MAJOR.MINOR.PATCH. Breaking, feature, fix.
package.json scripts
{
"scripts": {
"dev": "astro dev",
"build": "astro build",
"prebuild": "pnpm lint",
"lint": "eslint .",
"test": "vitest"
}
}
pre<name> and post<name> scripts run automatically around <name>.
Publishing
| Command |
Description |
npm login |
Log in to registry |
npm version patch |
Bump version and tag (minor, major) |
npm publish --access public |
Publish package |
npm pack --dry-run |
Preview published files |
pnpm workspaces
# pnpm-workspace.yaml
packages:
- "apps/*"
- "packages/*"
| Command |
Description |
pnpm -r build |
Run in all packages |
pnpm --filter web dev |
Run in one package |
pnpm --filter web add zod |
Add dependency to one package |
pnpm add @repo/ui --workspace |
Link a local package |
pnpm -w add -D typescript |
Add to the workspace root |
Housekeeping
| npm |
pnpm |
Description |
npm cache clean --force |
pnpm store prune |
Clean cache/store |
npm config list |
pnpm config list |
Show config |
npm init -y |
pnpm init |
New package.json |