With --json, bump prints the result of the run as JSON on stdout. stdout holds nothing else, so a script can parse it. The log goes to stderr. The JS API returns the same object from version().
Example
A repository in independent mode, with a change in @acme/core. @acme/cli depends on @acme/core, and app has it as a dev dependency:
$ bump minor --json
BUMP @acme/core 1.2.0 → 1.3.0 (changed)
BUMP @acme/cli 0.4.1 → 0.4.2 (dependent)
EDIT app devDependencies["@acme/core"] ^1.2.0 → ^1.3.0
EDIT @acme/cli dependencies["@acme/core"] ^1.2.0 → ^1.3.0
DONE Committed ea30534 release: @acme/core@1.3.0, @acme/cli@0.4.2
Tagged @acme/core@1.3.0, @acme/cli@0.4.2
{
"dryrun": false,
"type": "minor",
"commit": "ea305347daa95a8f08fed770a40dea8d1d26aa1c",
"message": "release: @acme/core@1.3.0, @acme/cli@0.4.2",
"units": [
{
"name": "@acme/core",
"type": "minor",
"tag": "@acme/core@1.3.0",
"from": "1.2.0",
"to": "1.3.0",
"reason": "changed",
"packages": [
{
"name": "@acme/core",
"ecosystem": "npm",
"dir": "packages/core",
"publish": true
}
]
},
{
"name": "@acme/cli",
"type": "patch",
"tag": "@acme/cli@0.4.2",
"from": "0.4.1",
"to": "0.4.2",
"reason": "dependent",
"packages": [
{
"name": "@acme/cli",
"ecosystem": "npm",
"dir": "packages/cli",
"publish": true
}
]
}
],
"ranges": [
{
"file": "packages/app/package.json",
"package": "app",
"dependency": "@acme/core",
"field": "devDependencies",
"from": "^1.2.0",
"to": "^1.3.0"
},
{
"file": "packages/cli/package.json",
"package": "@acme/cli",
"dependency": "@acme/core",
"field": "dependencies",
"from": "^1.2.0",
"to": "^1.3.0"
}
],
"files": [
"packages/app/package.json",
"packages/cli/package.json",
"packages/core/package.json"
]
}The first six lines are the log on stderr. The JSON is on stdout. To keep only the JSON in a terminal, send stderr away, or add --quiet:
bump minor --json 2>/dev/null
bump minor --json --quietWith --quiet, warnings still go to stderr.
Fields
| Field | Type | Description |
|---|---|---|
dryrun |
boolean | true with --dryrun. |
type |
string | The type that you gave, such as "minor", or "exact" for an exact version. |
commit |
string or null |
The full SHA of the release commit. null for a dry run, and when nothing is released. |
message |
string or null |
The subject of the release commit. For a dry run, the subject that bump would use. null when nothing is released. |
units |
array | The released units, in release order. Empty when nothing is released. |
ranges |
array | Every range edit, in the order of the log. |
files |
string[] | Every file that bump wrote, sorted. For a dry run, every file that it would write, and each npm lockfile that it would run a command for, changed or not. |
There is no prerelease field. A version with a - part, such as 1.3.0-next.0, is a prerelease.
All paths are relative to the top level of the git repository, and use /.
units[]
| Field | Type | Description |
|---|---|---|
name |
string or null |
The group name or the package name. null in lockstep mode. |
type |
string | The type that bump applied to this unit. A dependent gets patch, prepatch, or prerelease, not the type that you gave. "exact" for an exact version. See Dependents. |
tag |
string | The new tag. |
from |
string | The current version. |
to |
string | The new version. |
reason |
string | Why bump selected the unit: target, first, adopted, changed, all, or dependent. See Reasons. |
packages |
array | The members, in release order. |
units[].packages[]
| Field | Type | Description |
|---|---|---|
name |
string | The package name. |
ecosystem |
string | "npm" for a package.json, "cargo" for a Cargo.toml. |
dir |
string | The package directory. The root is ".". |
publish |
boolean | false for an npm package with "private": true, and for a crate with publish = false or publish = []. Else true. |
bump does not publish. Use publish to decide which packages your script publishes.
ranges[]
| Field | Type | Description |
|---|---|---|
file |
string | The manifest that holds the range. |
package |
string or null |
The package that lists the dependency. null for [workspace.dependencies] in a Cargo.toml. |
dependency |
string | The name of the dependency. |
field |
string | The npm field, such as "dependencies", or the Cargo table, such as "dependencies", "workspace.dependencies", or "target.'cfg(unix)'.dependencies". |
from |
string | The old range. |
to |
string | The new range. |
files
files holds the manifests, a tracked Cargo.lock, and each npm lockfile whose text changed. See Lockfiles.
Lockstep mode
In lockstep mode, the one unit has no name:
$ bump minor --json 2>/dev/null
{
"dryrun": false,
"type": "minor",
"commit": "591da6b520986edc6ed70272acbe363d591adcf8",
"message": "v1.3.0",
"units": [
{
"name": null,
"type": "minor",
"tag": "v1.3.0",
"from": "1.2.0",
"to": "1.3.0",
"reason": "changed",
"packages": [
{
"name": "app",
"ecosystem": "npm",
"dir": ".",
"publish": true
}
]
}
],
"ranges": [],
"files": [
"package.json"
]
}Dry run
With --dryrun, dryrun is true and commit is null. message and files show what a release would do. bump does not run the lockfile commands in a dry run, so files lists each npm lockfile that bump would run a command for, changed or not. A release lists only the npm lockfiles whose text changed. This repository tracks a package-lock.json:
$ bump minor --dryrun --json 2>/dev/null
{
"dryrun": true,
"type": "minor",
"commit": null,
"message": "release: @acme/core@1.3.0, @acme/cli@0.4.2",
"units": [
{
"name": "@acme/core",
"type": "minor",
"tag": "@acme/core@1.3.0",
"from": "1.2.0",
"to": "1.3.0",
"reason": "changed",
"packages": [
{
"name": "@acme/core",
"ecosystem": "npm",
"dir": "packages/core",
"publish": true
}
]
},
{
"name": "@acme/cli",
"type": "patch",
"tag": "@acme/cli@0.4.2",
"from": "0.4.1",
"to": "0.4.2",
"reason": "dependent",
"packages": [
{
"name": "@acme/cli",
"ecosystem": "npm",
"dir": "packages/cli",
"publish": true
}
]
}
],
"ranges": [
{
"file": "packages/app/package.json",
"package": "app",
"dependency": "@acme/core",
"field": "devDependencies",
"from": "^1.2.0",
"to": "^1.3.0"
},
{
"file": "packages/cli/package.json",
"package": "@acme/cli",
"dependency": "@acme/core",
"field": "dependencies",
"from": "^1.2.0",
"to": "^1.3.0"
}
],
"files": [
"package-lock.json",
"packages/app/package.json",
"packages/cli/package.json",
"packages/core/package.json"
]
}Nothing to release
When no unit changed, commit and message are null, and the arrays are empty. The exit code is 0:
$ bump minor --json
DONE Nothing to release
{
"dryrun": false,
"type": "minor",
"commit": null,
"message": null,
"units": [],
"ranges": [],
"files": []
}The DONE line is on stderr.
Errors
With --json, an error prints a FAIL block on stderr, and nothing on stdout. The exit code is 1:
$ bump patch @acme/nope --json
FAIL Unknown targets: "@acme/nope"So a script can check the exit code before it parses stdout:
if result=$(bump minor --json --quiet); then
echo "$result" | jq -r '.units[].tag'
fi