Skip to content
This documentation is for v14 and up, the docs for v13 are archived.

Value Groups

Value groups keep values in package.json files which are not versions, such as author, license, repository or scripts, the same across your packages. Each group selects packages by name and gives them values. They are checked by format --check and written by format.

Examples

.syncpackrc.json
{
"valueGroups": [
{
"label": "Every package has the same author, license and build script, and no prepublish script",
"values": {
"author": "Jo Bloggs <jo@example.com>",
"license": "MIT",
"scripts": {
"build": "tsc",
"prepublish": null
}
}
},
{
"label": "Apps build with Vite instead, and are never published",
"packages": ["@my-repo/app-*"],
"values": {
"private": true,
"scripts.build": "vite build"
}
}
]
}

Any other scripts each package has are left alone.

How groups are applied

Unlike other groups, a package is not limited to the first value group it matches. Every value group which matches a package is applied to it, in the order they are written. When two groups give a value to the same property, the group written last wins.

This means you can write broad defaults first and follow them with more specific groups for some packages.

A package without a name is never given values by a value group.

Values are expected as the rest of format would leave them: when sortExports, sortAz, formatBugs or formatRepository would change a value, the changed value is the one expected.

Properties

label Optional

A short name or description of the group, for your own reference.

packages Optional

  • An array of strings which should match the name properties of your package.json files.
  • If omitted, the default behaviour is to match every package.
  • Negated names are also supported, so a value of ["!my-client", "!my-server"] would assign everything except the packages my-client and my-server to this group.
  • The strings can be any combination of exact matches or glob patterns:
Examples of valid values
// ✅ match any package name
packages: ["**"]
// ✅ match any package name with this scope
packages: ["@my-repo/**"]
// ✅ match specific packages by name
packages: ["my-server", "my-client"]
// ✅ match all packages except negated ones
packages: ["!my-server", "!@my-repo/**"]
// ❌ no mixing of specific and negated packages
packages: ["my-client", "!@my-repo/**"]
// ❌ not file system paths, name properties of package.json files
packages: ["packages/my-client"]
// ❌ not file system globs, name properties of package.json files
packages: ["packages/**"]
Where this pattern is matched against
{
"name": "HERE",
"version": "1.0.2"
}

strategy Optional

How the group gives each of its values to a package. Defaults to "merge".

  • "merge" deeply merges each value into what the package has. Objects are merged key by key, so any keys the group does not mention are left alone. Arrays, strings, numbers and booleans replace what was there.
  • "replace" makes each value exactly what the package has, removing any keys of an object which the group does not mention. Each removed key is reported as PropertyIsNotInValueGroup, and severity decides whether format --check treats it as an error or a warning. The keys of an object are also put in the order the group writes them, unless format sorts them afterwards.
Given this package.json
{
"scripts": {
"build": "babel",
"lint": "eslint"
}
}
This merge group...
{
"values": {
"scripts": {
"build": "tsc"
}
}
}
...would result in
{
"scripts": {
"build": "tsc",
"lint": "eslint"
}
}
This replace group...
{
"strategy": "replace",
"values": {
"scripts": {
"build": "tsc"
}
}
}
...would result in
{
"scripts": {
"build": "tsc"
}
}

severity Optional

How format --check treats a property which a "replace" group removes because it does not list it. format removes the property whatever its severity.

.syncpackrc.json
{
"valueGroups": [
{
"label": "Remove scripts we do not use, but do not fail CI over them",
"strategy": "replace",
"severity": {
"PropertyIsNotInValueGroup": "warn"
},
"values": {
"scripts": {
"build": "tsc",
"test": "vitest"
}
}
}
]
}
ValueEffect on format --check
"fix"Default. Show as error; exits 1.
"warn"Show as warning; does not affect exit code.
"error"Show as error; exits 1.

strict does not change it. When more than one value group removes the property, the severity of the last of them is used.

Permitted keys:

values Required

An object of the values each matched package must have, written as you would write them in package.json.

  • A value of null means the property must not exist, and format will remove it. When that leaves an object with nothing in it, such as scripts once its only script is removed, the empty object is removed too. An object which was already empty is left alone.
  • Merging an object into a property which is not an object, such as { "repository": { "directory": "packages/a" } } into "repository": "User/repo", replaces it.
  • A key of values can be a dotted path to a nested property, such as "scripts.build". This lets a later group change one nested property without repeating the rest.
  • To use a dot within a key, write a backslash before it. In JSON a backslash is itself written as \\, so "scripts.build\\.esm" means the build.esm property of scripts. A backslash within a key is written \\\\.
  • Only the keys of values itself are dotted paths. Keys of the objects within it are used exactly as written, so { "exports": { "./utils.js": "./dist/utils.js" } } needs no backslashes.
Examples of valid values
// ✅ the author property
"values": {
"author": "Jo Bloggs"
}
// ✅ the build script, leaving other scripts alone
"values": {
"scripts.build": "tsc"
}
// ✅ the same thing, written as an object
"values": {
"scripts": {
"build": "tsc"
}
}
// ✅ no "private" property
"values": {
"private": null
}
// ✅ the "build.esm" script
"values": {
"scripts.build\\.esm": "tsc -p tsconfig.esm.json"
}
// ❌ an empty key
"values": {
"scripts..build": "tsc"
}
// ❌ a backslash not followed by "." or "\"
"values": {
"scripts.build\\esm": "tsc"
}
// ❌ an empty key within a value
"values": {
"exports": {
"": "./index.js"
}
}

Status codes

When a package does not have the values its value groups give it, format --check reports one of these for each property, with the value it has and the value it should have:

Status codeMeaning
PropertyDiffersFromValueGroupThe property is missing or does not have the value it is given.
PropertyIsBannedByValueGroupThe property exists, but a value group gives it the value null.
PropertyIsNotInValueGroupThe property is within an object a "replace" group gives, but the group does not list it.

Config errors

These mistakes in valueGroups stop syncpack with an error instead of being ignored:

  • A group without values, or with an empty values object.
  • A key of values, or of any object within a value, which is an empty string, or a dotted path with an empty key such as "scripts..build".
  • A backslash in a key of values which is not followed by . or \.
  • A key of severity other than PropertyIsNotInValueGroup.
  • A property other than label, packages, severity, strategy and values. Value groups select packages by name, so dependencies, dependencyTypes, specifierTypes and isIgnored are not supported. Use a negated pattern in packages, such as ["!my-package"], to leave a package out.