|
| 1 | +# Syncpack |
| 2 | + |
| 3 | +> Syncpack is a command-line tool for synchronising dependency versions across JavaScript monorepos. It finds mismatches, enforces version policies, updates outdated dependencies from npm, and formats package.json files. |
| 4 | + |
| 5 | +Used by: AWS, Cloudflare, DataDog, Electron, GoDaddy, LiveStore, Lottie, Microsoft, PostHog, Qwik, Raycast, Salesforce, TopTal, Vercel, VoltAgent, WooCommerce and others. |
| 6 | + |
| 7 | +Things to remember when helping users with Syncpack: |
| 8 | + |
| 9 | +- By default, the highest semver version wins when there are mismatches |
| 10 | +- Version groups are checked in order of first match wins, so put specific rules before general ones |
| 11 | +- Peer dependencies often cause "false positive" mismatches because they use broad ranges like `>=6.0.0 <9.0.0` while devDependencies use exact versions like `8.53.0`—use version groups with `isIgnored` to handle this |
| 12 | +- All commands support filtering: `--dependencies` (glob pattern), `--dependency-types` (prod, dev, peer, etc.), `--specifier-types` (exact, range, tag, etc.) |
| 13 | +- Syncpack auto-detects workspace packages from npm/yarn/pnpm/lerna config |
| 14 | +- After running `fix` or `update`, run your package manager to update the lockfile |
| 15 | + |
| 16 | +## Commands |
| 17 | + |
| 18 | +- [list](https://jamiemason.github.io/syncpack/command/list/): Show all dependencies and their versions. Use `--sort count` to find most-used dependencies. Use `--show all` to see every location. |
| 19 | +- [lint](https://jamiemason.github.io/syncpack/command/lint/): Check for mismatches without modifying files. Exits 1 if issues found. Use in CI. |
| 20 | +- [fix](https://jamiemason.github.io/syncpack/command/fix/): Write fixes for version mismatches. |
| 21 | +- [update](https://jamiemason.github.io/syncpack/command/update/): Check npm registry for newer versions. Use `--target patch` for safe updates, `--target latest` for major bumps. |
| 22 | +- [format](https://jamiemason.github.io/syncpack/command/format/): Sort and format package.json files. Use `--check` in CI. |
| 23 | +- [json](https://jamiemason.github.io/syncpack/command/json/): Export dependency data as JSON. Pipe to `jq` for analysis or scripting. |
| 24 | + |
| 25 | +## Configuration |
| 26 | + |
| 27 | +Create `.syncpackrc` (JSON) at monorepo root. Most users only need `versionGroups`. |
| 28 | + |
| 29 | +The complete schema for all configuration options is available at: https://raw.githubusercontent.com/JamieMason/syncpack/refs/heads/main/npm/syncpack.ts |
| 30 | + |
| 31 | +## Incremental Adoption Strategy |
| 32 | + |
| 33 | +A good approach for adopting syncpack in an existing monorepo is to start with everything ignored, then incrementally opt-in packages: |
| 34 | + |
| 35 | +```json |
| 36 | +{ |
| 37 | + "versionGroups": [ |
| 38 | + { |
| 39 | + "label": "Enforce consistency for react", |
| 40 | + "dependencies": ["react", "react-dom"], |
| 41 | + "dependencyTypes": ["dev", "prod"] |
| 42 | + }, |
| 43 | + { |
| 44 | + "label": "Ignore everything else until we're ready", |
| 45 | + "isIgnored": true |
| 46 | + } |
| 47 | + ] |
| 48 | +} |
| 49 | +``` |
| 50 | + |
| 51 | +The catch-all `isIgnored` group at the end lets you adopt syncpack gradually without being overwhelmed by mismatches across your entire monorepo. |
| 52 | + |
| 53 | +## Common Patterns |
| 54 | + |
| 55 | +**Use workspace:\* for packages developed in this monorepo:** |
| 56 | + |
| 57 | +```json |
| 58 | +{ |
| 59 | + "versionGroups": [ |
| 60 | + { |
| 61 | + "label": "Use workspace:* for packages developed in this monorepo", |
| 62 | + "dependencies": ["$LOCAL"], |
| 63 | + "dependencyTypes": ["dev", "prod"], |
| 64 | + "pinVersion": "workspace:*" |
| 65 | + } |
| 66 | + ] |
| 67 | +} |
| 68 | +``` |
| 69 | + |
| 70 | +`$LOCAL` is a special keyword that matches all packages developed in your monorepo. |
| 71 | + |
| 72 | +**Ignore peer dependencies initially:** |
| 73 | + |
| 74 | +```json |
| 75 | +{ |
| 76 | + "versionGroups": [ |
| 77 | + { |
| 78 | + "label": "Ignore peer dependencies", |
| 79 | + "dependencyTypes": ["peer"], |
| 80 | + "isIgnored": true |
| 81 | + } |
| 82 | + ] |
| 83 | +} |
| 84 | +``` |
| 85 | + |
| 86 | +**Pin a dependency to a specific version everywhere:** |
| 87 | + |
| 88 | +```json |
| 89 | +{ |
| 90 | + "versionGroups": [ |
| 91 | + { |
| 92 | + "label": "Pin @types/node to 18.14.2", |
| 93 | + "dependencies": ["@types/node"], |
| 94 | + "pinVersion": "18.14.2" |
| 95 | + } |
| 96 | + ] |
| 97 | +} |
| 98 | +``` |
| 99 | + |
| 100 | +**Ban a dependency from being used:** |
| 101 | + |
| 102 | +```json |
| 103 | +{ |
| 104 | + "versionGroups": [ |
| 105 | + { |
| 106 | + "label": "Use date-fns instead of moment", |
| 107 | + "dependencies": ["moment"], |
| 108 | + "isBanned": true |
| 109 | + } |
| 110 | + ] |
| 111 | +} |
| 112 | +``` |
| 113 | + |
| 114 | +**Use one package as the source of truth for a dependency's version:** |
| 115 | + |
| 116 | +```json |
| 117 | +{ |
| 118 | + "versionGroups": [ |
| 119 | + { |
| 120 | + "label": "Use whatever version of react that mobile-app uses", |
| 121 | + "dependencies": ["react", "react-dom"], |
| 122 | + "snapTo": ["mobile-app"] |
| 123 | + } |
| 124 | + ] |
| 125 | +} |
| 126 | +``` |
| 127 | + |
| 128 | +**Enforce a specific semver range format:** |
| 129 | + |
| 130 | +```json |
| 131 | +{ |
| 132 | + "semverGroups": [ |
| 133 | + { |
| 134 | + "label": "Use ~ for devDependencies", |
| 135 | + "dependencyTypes": ["dev"], |
| 136 | + "range": "~" |
| 137 | + }, |
| 138 | + { |
| 139 | + "label": "Use exact versions for prod dependencies", |
| 140 | + "dependencyTypes": ["prod"], |
| 141 | + "range": "" |
| 142 | + } |
| 143 | + ] |
| 144 | +} |
| 145 | +``` |
| 146 | + |
| 147 | +## Docs |
| 148 | + |
| 149 | +- [Getting Started](https://jamiemason.github.io/syncpack/): Installation and first commands |
| 150 | +- [Peer Dependencies Guide](https://jamiemason.github.io/syncpack/guide/peer-dependencies/): Why peer deps cause mismatches and how to handle them |
| 151 | +- [Version Groups](https://jamiemason.github.io/syncpack/config/version-groups/): Create partitions with different versioning policies |
| 152 | +- [Semver Groups](https://jamiemason.github.io/syncpack/config/semver-groups/): Control semver range format (^, ~, exact) |
| 153 | + |
| 154 | +## Optional |
| 155 | + |
| 156 | +- [All Config Options](https://jamiemason.github.io/syncpack/config/syncpackrc/): Complete configuration reference |
| 157 | +- [Status Codes](https://jamiemason.github.io/syncpack/reference/status-codes/): What each lint status means |
| 158 | +- [Dependency Types](https://jamiemason.github.io/syncpack/reference/dependency-types/): All supported dependency type names |
| 159 | +- [Glossary](https://jamiemason.github.io/syncpack/glossary/): Terminology definitions |
0 commit comments