What is syncpack?
Syncpack is a tool for managing multiple package.json files in a monorepo or multi-package repository. It helps ensure consistency across dependencies, scripts, and other configurations.
What are syncpack's main functionalities?
List Dependencies
Lists all dependencies across multiple package.json files, helping you identify inconsistencies.
const { list } = require('syncpack');
list();
Fix Versions
Fixes version mismatches across multiple package.json files, ensuring all packages use the same version of a dependency.
const { fix } = require('syncpack');
fix();
Set Version
Sets a specific version for a dependency across all package.json files.
const { set } = require('syncpack');
set('react', '17.0.2');
Format
Formats all package.json files to ensure a consistent style.
const { format } = require('syncpack');
format();
Other packages similar to syncpack
lerna
Lerna is a tool for managing JavaScript projects with multiple packages. It optimizes the workflow around managing multi-package repositories with git and npm. Compared to Syncpack, Lerna offers more comprehensive features for managing monorepos, including versioning and publishing.
yarn
Yarn is a package manager that doubles down as a project manager. It offers workspaces that can manage multiple packages within a single repository. While Syncpack focuses on consistency across package.json files, Yarn provides a broader set of features for dependency management and project workflows.
pnpm
pnpm is a fast, disk space-efficient package manager. It also supports workspaces for managing multiple packages in a monorepo. Compared to Syncpack, pnpm is more focused on performance and efficient storage, while Syncpack is specialized in ensuring consistency across package.json files.
syncpack
![Follow fold_left on Twitter](https://img.shields.io/twitter/follow/fold_left.svg?style=social&label=Follow)
Synchronises the contents of multiple package.json
files, such as packages/*/package.json
in
Lerna Monorepos.
Contents
Installation
npm install --global syncpack
Usage
Usage: syncpack [options] [command]
Options:
-V, --version output the version number
-h, --help output usage information
Commands:
sync-versions synchronise dependency versions between packages
copy-values <keys...> copy values from eg. ./package.json to ./packages/*/package.json
help [cmd] display help for [cmd]
sync-versions
Usage: syncpack sync-versions [options]
Options:
-p, --packages <glob> location of packages. defaults to ./packages/*/package.json
-h, --help output usage information
Imagine the packages guybrush
, herman
, and elaine
all have react
as a dependency, but
versions '15.4.0'
, '15.5.4'
, and '15.6.1'
respectively.
/Users/foldleft/Dev/monorepo/packages/
├── guybrush
│ └── package.json
├── herman
│ └── package.json
└── elaine
└── package.json
To update each package.json
to use version '15.6.1'
of react
in dependencies
,
devDependencies
, and peerDependencies
(as needed) you can run
syncpack sync-versions
copy-values
Usage: syncpack copy-values [options] <keys...>
Options:
-p, --packages <glob> location of packages. defaults to ./packages/*/package.json
-s, --source <glob> location of source. defaults to ./package.json
-h, --help output usage information
Imagine the packages carla
and murray
were previously hosted at their own repositories, but are
now part of your new Monorepo.
/Users/foldleft/Dev/monorepo/packages/
├── carla
│ └── package.json
└── murray
└── package.json
With the following contents
"bugs": "https://github.com/Scumm/carla/issues",
"homepage": "https://github.com/Scumm/carla#readme",
"repository": "Scumm/carla",
"bugs": "https://github.com/Scumm/murray/issues",
"homepage": "https://github.com/Scumm/murray#readme",
"repository": "Scumm/murray",
To copy these fields from your Monorepo's package.json
to each of its packages, you can run
syncpack copy-values bugs homepage repository
to copy the value of those properties, leaving them like so
"bugs": "https://github.com/Scumm/monorepo/issues",
"homepage": "https://github.com/Scumm/monorepo#readme",
"repository": "Scumm/monorepo",
to copy deeply nested values, pass the path to the key as follows
syncpack copy-values scripts.test