@rap2hpoutre/sync-yarn-lock
v1.0.2
Published
Sync package.json versions with yarn.lock - Modern replacement for syncyarnlock, supporting Yarn 4
Maintainers
Readme
sync-yarn-lock
🔒 Sync your
package.jsonversions withyarn.lock— Modern replacement forsyncyarnlock, built for Yarn 4 (Berry)
Why?
When you run yarn add or yarn upgrade, Yarn updates your yarn.lock with exact versions, but leaves package.json with version ranges (like ^1.0.0). This can cause confusion about what's actually installed.
sync-yarn-lock updates your package.json to reflect the exact versions from your lockfile, making your dependencies explicit and reproducible.
vs. syncyarnlock
| Feature | sync-yarn-lock | syncyarnlock | | ------------------------ | -------------- | --------------------- | | Yarn 4 (Berry) support | ✅ | ❌ | | Yarn 1 (Classic) support | ❌ | ✅ | | Actively maintained | ✅ | ❌ (last update 2019) | | Zero dependencies | ✅ | ❌ | | Dry-run mode | ✅ | ❌ |
Installation
Using npx (recommended)
npx @rap2hpoutre/sync-yarn-lockGlobal installation
npm install -g @rap2hpoutre/sync-yarn-lock
# or
yarn global add @rap2hpoutre/sync-yarn-lockUsage
# Sync versions (modifies package.json)
npx @rap2hpoutre/sync-yarn-lock
# Preview changes without modifying files
npx @rap2hpoutre/sync-yarn-lock --dry-run
# Silent mode (only show errors)
npx @rap2hpoutre/sync-yarn-lock --silentOptions
| Option | Alias | Description |
| ----------- | ----- | ------------------------------ |
| --help | -h | Show help message |
| --version | -v | Show version number |
| --dry-run | -d | Preview changes without saving |
| --silent | -s | Only output errors |
Example
Before:
{
"dependencies": {
"react": "^18.0.0",
"react-dom": "^18.0.0"
}
}After running npx sync-yarn-lock:
{
"dependencies": {
"react": "18.2.0",
"react-dom": "18.2.0"
}
}How it works
- Reads your
package.jsondependencies - For each dependency, queries
yarn info <package> --jsonto get the resolved version fromyarn.lock - Updates
package.jsonwith the exact versions - Reports all changes made
Requirements
- Node.js >= 18
- Yarn 4 (Berry) - must be available in PATH
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
MIT © rap2hpoutre
