Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
pnpm 10.x reference skill covering workspaces, catalogs, patches, peer deps, overrides, and CI/CD caching strategies.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/features-catalogs.md
1---2name: pnpm-catalogs3description: Centralized dependency version management for workspaces4---56# pnpm Catalogs78Catalogs provide a centralized way to manage dependency versions across a workspace. Define versions once, use everywhere.910## Basic Usage1112Define a catalog in `pnpm-workspace.yaml`:1314```yaml15packages:16- 'packages/*'1718catalog:19react: ^18.2.020react-dom: ^18.2.021typescript: ~5.3.022vite: ^5.0.023```2425Reference in `package.json` with `catalog:`:2627```json28{29"dependencies": {30"react": "catalog:",31"react-dom": "catalog:"32},33"devDependencies": {34"typescript": "catalog:",35"vite": "catalog:"36}37}38```3940`catalog:` is shorthand for `catalog:default`. The `catalog:` protocol is valid in `package.json` `dependencies`, `devDependencies`, `peerDependencies`, and `optionalDependencies`, plus in `overrides` inside `pnpm-workspace.yaml`. It also works on the CLI: `pnpm add react@catalog:` and `pnx shx@catalog:`.4142## Named Catalogs4344Create multiple catalogs for different scenarios:4546```yaml47packages:48- 'packages/*'4950# Default catalog51catalog:52lodash: ^4.17.215354# Named catalogs55catalogs:56react17:57react: ^17.0.258react-dom: ^17.0.25960react18:61react: ^18.2.062react-dom: ^18.2.06364testing:65vitest: ^1.0.066"@testing-library/react": ^14.0.067```6869Reference named catalogs:7071```json72{73"dependencies": {74"react": "catalog:react18",75"react-dom": "catalog:react18"76},77"devDependencies": {78"vitest": "catalog:testing"79}80}81```8283## Keeping overrides in sync with a catalog8485Reference a catalog from `overrides` so the version lives in exactly one place:8687```yaml title="pnpm-workspace.yaml"88catalog:89foo: ^1.0.09091overrides:92foo: 'catalog:' # or catalog:<name>93```9495## Settings9697```yaml title="pnpm-workspace.yaml"98# How `pnpm add` interacts with the default catalog (v10.12+)99catalogMode: manual # manual (default) | prefer | strict100# strict: only catalog versions allowed; prefer: fall back if no match101cleanupUnusedCatalogs: true # remove unused catalog entries on install (v10.15+)102```103104## Benefits1051061. **Single source of truth**: Update version in one place1072. **Consistency**: All packages use the same version1083. **Easy upgrades**: Change version once, affects entire workspace1094. **Fewer merge conflicts**: package.json files stay untouched on upgrades110111## Catalog vs Overrides112113| Feature | Catalogs | Overrides |114|---------|----------|-----------|115| Purpose | Define versions for direct dependencies | Force versions for any dependency |116| Scope | Direct dependencies only | All dependencies (including transitive) |117| Usage | `"pkg": "catalog:"` | Applied automatically |118| Opt-in | Explicit per package.json | Global to workspace |119120## Publishing with Catalogs121122When publishing, `catalog:` references are replaced with actual versions:123124```json125// Before publish (source)126{127"dependencies": {128"react": "catalog:"129}130}131132// After publish (published package)133{134"dependencies": {135"react": "^18.2.0"136}137}138```139140## Migration from Overrides141142If you're using overrides for version consistency:143144```yaml145# Before (using overrides)146overrides:147react: ^18.2.0148react-dom: ^18.2.0149```150151Migrate to catalogs for cleaner dependency management:152153```yaml154# After (using catalogs)155catalog:156react: ^18.2.0157react-dom: ^18.2.0158```159160Then update package.json files to use `catalog:`. To migrate an existing workspace automatically:161162```bash163pnpx codemod pnpm/catalog164```165166## Best Practices1671681. **Use default catalog** for commonly shared dependencies1692. **Use named catalogs** for version variants (e.g., different React versions)1703. **Keep catalog minimal** - only include shared dependencies1714. **Combine with workspace protocol** for internal packages172173```yaml174catalog:175# External shared dependencies176lodash: ^4.17.21177zod: ^3.22.0178179# Internal packages use workspace: protocol instead180# "dependencies": { "@myorg/utils": "workspace:^" }181```182183<!--184Source references:185- https://pnpm.io/catalogs186-->187