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
Manage multiple package.json files, such as in Lerna Monorepos and Yarn Workspaces
![Maintainability](https://api.codeclimate.com/v1/badges/516439365fdd0e3c6526/maintainability)
Table of Contents
🌩 Installation
npm install --global syncpack
🕵🏾♀️ Resolving Packages
package.json files are resolved in this order of precendence:
- If
--source
glob patterns are provided, use those. - If using Yarn Workspaces, read
workspaces
from ./package.json
. - If using Lerna, read
packages
from ./lerna.json
. - Default to
'package.json'
and 'packages/*/package.json'
.
📝 Commands
fix-mismatches
Ensure that multiple packages requiring the same dependency define the same version, so that every package requires eg. react@16.4.2
, instead of a combination of react@16.4.2
, react@0.15.9
, and react@16.0.0
.
Options
-s, --source [pattern] glob pattern for package.json files to read from
-p, --prod include dependencies
-d, --dev include devDependencies
-P, --peer include peerDependencies
-i, --indent [value] override indentation. defaults to " "
-h, --help output usage information
Examples
syncpack fix-mismatches
syncpack fix-mismatches --source "apps/*/package.json"
syncpack fix-mismatches --source "apps/*/package.json" --source "core/*/package.json"
syncpack fix-mismatches --filter "^package_name$"
syncpack fix-mismatches --dev
syncpack fix-mismatches --dev --peer
syncpack fix-mismatches --indent " "
format
Organise package.json files according to a conventional format, where fields appear in a predictable order and nested fields are ordered alphabetically. Shorthand properties are used where available, such as the "repository"
and "bugs"
fields.
Options
-s, --source [pattern] glob pattern for package.json files to read from
-i, --indent [value] override indentation. defaults to " "
-h, --help output usage information
Examples
syncpack format
syncpack format --source "apps/*/package.json"
syncpack format --source "apps/*/package.json" --source "core/*/package.json"
syncpack format --indent " "
list
List all dependencies required by your packages.
Options
-s, --source [pattern] glob pattern for package.json files to read from
-p, --prod include dependencies
-d, --dev include devDependencies
-P, --peer include peerDependencies
-h, --help output usage information
Examples
syncpack list
syncpack list --source "apps/*/package.json"
syncpack list --source "apps/*/package.json" --source "core/*/package.json"
syncpack list --dev
syncpack list --dev --peer
list-mismatches
List dependencies which are required by multiple packages, where the version is not the same across every package.
Options
-s, --source [pattern] glob pattern for package.json files to read from
-p, --prod include dependencies
-d, --dev include devDependencies
-P, --peer include peerDependencies
-h, --help output usage information
Examples
syncpack list-mismatches
syncpack list-mismatches --source "apps/*/package.json"
syncpack list-mismatches --source "apps/*/package.json" --source "core/*/package.json"
syncpack list-mismatches --dev
syncpack list-mismatches --dev --peer
set-semver-ranges
Ensure dependency versions used within "dependencies"
, "devDependencies"
, and "peerDependencies"
follow a consistent format.
Options
-r, --semver-range <range> <, <=, "", ~, ^, >=, >, or *. defaults to ""
-s, --source [pattern] glob pattern for package.json files to read from
-p, --prod include dependencies
-d, --dev include devDependencies
-P, --peer include peerDependencies
-i, --indent [value] override indentation. defaults to " "
-h, --help output usage information
Examples
syncpack set-semver-ranges
syncpack set-semver-ranges --source "apps/*/package.json"
syncpack set-semver-ranges --source "apps/*/package.json" --source "core/*/package.json"
syncpack set-semver-ranges --semver-range ~
syncpack set-semver-ranges --dev --semver-range ~
syncpack set-semver-ranges --dev --peer --semver-range ~
syncpack set-semver-ranges --indent " "
Supported Ranges
< <1.4.2
<= <=1.4.2
"" 1.4.2
~ ~1.4.2
^ ^1.4.2
>= >=1.4.2
> >1.4.2
* *
🙋🏿♀️ Getting Help
Get help with issues by creating a Bug Report or discuss ideas by opening a Feature Request.
👀 Other Projects
If you find my Open Source projects useful, please share them ❤️
🤓 Author
I'm Jamie Mason from Leeds in England, I began Web Design and Development in 1999 and have been Contracting and offering Consultancy as Fold Left Ltd since 2012. Who I've worked with includes Sky Sports, Sky Bet, Sky Poker, The Premier League, William Hill, Shell, Betfair, and Football Clubs including Leeds United, Spurs, West Ham, Arsenal, and more.