Yarn Package Manager Cheatsheet
Quick reference for Yarn: installation, dependency management, scripts, workspaces, cache, and CLI commands.
| Feature | Description | Example | Category |
|---|---|---|---|
| Install All | Install all dependencies | yarn # or yarn install | Installation |
| Add Package | Add new dependency | yarn add lodash yarn add react@17.0.2 | Installation |
| Add Dev Dependency | Add development dependency | yarn add -D jest yarn add --dev typescript | Installation |
| Add Peer Dependency | Add peer dependency | yarn add -P react | Installation |
| Add Optional Dependency | Add optional dependency | yarn add -O package-name | Installation |
| Global Install | Install package globally | yarn global add create-react-app yarn global add typescript | Installation |
| Remove Package | Remove dependency | yarn remove lodash yarn remove react react-dom | Dependencies |
| Upgrade Package | Upgrade specific package | yarn upgrade lodash yarn upgrade react@latest | Dependencies |
| Upgrade Interactive | Interactive upgrade prompt | yarn upgrade-interactive yarn upgrade-interactive --latest | Dependencies |
| Update Lockfile | Regenerate yarn.lock | yarn install --force yarn install --frozen-lockfile | Dependencies |
| Deduplicate | Remove duplicate dependencies | yarn dedupe | Dependencies |
| Run Script | Execute package.json script | yarn run build yarn run test | Scripts |
| Run Shorthand | Run script without "run" | yarn build yarn test yarn start | Scripts |
| Run with Args | Pass arguments to scripts | yarn test --watch yarn build --production | Scripts |
| List Scripts | Show available scripts | yarn run | Scripts |
| List Dependencies | Show dependency tree | yarn list yarn list --depth=0 | Info |
| Show Package Info | Display package information | yarn info lodash yarn info react versions | Info |
| Why Package | Explain why package is installed | yarn why lodash yarn why webpack | Info |
| Check Updates | Check for outdated packages | yarn outdated | Info |
| Audit | Check for security vulnerabilities | yarn audit yarn audit --level moderate | Info |
| Licenses | List package licenses | yarn licenses list | Info |
| Workspace Setup | Define workspaces in package.json | { "workspaces": [ "packages/*", "apps/*" ] } | Workspaces |
| Workspace Command | Run command in specific workspace | yarn workspace package-a add lodash yarn workspace my-app test | Workspaces |
| Workspace Info | Show workspace information | yarn workspaces info | Workspaces |
| Run in All Workspaces | Execute in all workspaces | yarn workspaces run test yarn workspaces run build | Workspaces |
| Clean Cache | Clear Yarn cache | yarn cache clean yarn cache clean lodash | Cache |
| Cache Directory | Show cache location | yarn cache dir | Cache |
| Cache List | List cached packages | yarn cache list yarn cache list --pattern lodash | Cache |
| Init Project | Initialize new project | yarn init yarn init -y | Installation |
| Link Package | Symlink local package | yarn link yarn link package-name | Dependencies |
| Unlink Package | Remove symlinked package | yarn unlink yarn unlink package-name | Dependencies |
| Version | Update package version | yarn version --patch yarn version --minor yarn version --major | Dependencies |
| Publish | Publish package to registry | yarn publish yarn publish --new-version 1.0.1 | Dependencies |
| Check Integrity | Verify package integrity | yarn check yarn check --integrity | Info |
| Config | Manage Yarn configuration | yarn config get registry yarn config set registry https://registry.npmjs.org | Info |