Skip to content

bump() ​

Compute and write the new versions from Node.js, and get the bumped packages.

ts
function bump(options?: Partial<BumpOptions>): Promise<BumpResult>

bump() runs relizy bump: it checks the working directory, computes the new versions, asks to confirm them (unless yes), and writes them to the package.json files.

Options ​

The flags of relizy bump, camelCased, and the shared options:

OptionDescription
typeBumpReleaseType: 'release' (default) computes the bump from the commits, or 'major', 'minor', 'patch', 'prerelease', 'premajor', 'preminor', 'prepatch'
preidPrerelease identifier: 'beta', 'rc'...
suffixWith a prerelease type, replaces the last number of the version
canaryWrites a canary version, {nextVersion}-0.canary-{sha} (preid replaces canary)
forceBumps the packages even without a commit triggering a bump
yesConfirms the new versions without asking (default false). Without an interactive terminal, bump() throws unless true or onConfirm
onConfirm(plan: ConfirmPlan) => boolean | Promise<boolean>: validates the versions instead of the prompt, once computed and before anything is written. false cancels as a refused prompt (a RelizyCancelError), an error it throws fails the run. Not called with yes nor bump.yes. See below
cleanfalse bumps with uncommitted changes
dependencyTypesOverrides bump.dependencyTypes
privatePackagesOverrides monorepo.privatePackages
capZeroMajorOverrides bump.capZeroMajor
outOfRangePeersOverrides bump.outOfRangePeers

See BumpOptions for the types.

Result ​

BumpResult is { bumped: false } when no commit triggers a bump. Otherwise, bumped is true and the result has:

  • bumpedPackages: the bumped packages, with their oldVersion and newVersion;
  • oldVersion, newVersion, fromTag, rootPackage: the root version before and after, and the previous release tag (unified and selective modes);
  • groups: with version groups, the result of each group that bumped (GroupBumpResult: name, title, versionMode, and the fields above). The other fields then aggregate them: bumpedPackages lists the packages of every group, newVersion is the one of the unified/selective group.

See BumpResultTruthy and GroupBumpResult.

Examples ​

ts
import { bump } from 'relizy'

const result = await bump({ yes: true })

if (result.bumped) {
  for (const pkg of result.bumpedPackages) {
    console.log(`${pkg.name}: ${pkg.oldVersion} -> ${pkg.newVersion}`)
  }
}

Preview the versions without writing them:

ts
const preview = await bump({ type: 'minor', dryRun: true, yes: true })

The result is the bumpResult option of changelog(), publish(), providerRelease() and social().

Confirm from an Application ​

An application asking in its own interface validates the versions with onConfirm, at the moment of the prompt: the versions are computed, nothing is written yet.

ts
import { bump, isRelizyCancelError } from 'relizy'

try {
  await bump({
    onConfirm: plan => askInTheApp(plan.packages.map(pkg => `${pkg.name} ${pkg.oldVersion} -> ${pkg.newVersion}`)),
  })
}
catch (error) {
  if (!isRelizyCancelError(error)) {
    throw error
  }
  // Refused: nothing was written
}

ConfirmPlan holds command (bump, or release for the bump of a release), dryRun, profile, canary, and packages: { name, path, private, oldVersion, newVersion, tag?, group?, reason? } for every package of every version group, with the git tag the release creates (none for relizy bump, which creates no tag, nor without the release commit or release.gitTag).

  • With yes, or bump.yes: true in the config or the profile, the versions are confirmed in advance: onConfirm is not called.
  • false cancels the run as a refused prompt: a RelizyCancelError, cancelled: true in the events, nothing written.
  • An error thrown by onConfirm (or a rejected promise) fails the run with this error as is: a failure, not a cancellation (cancelled: false), nothing written. To cancel from the application, throw a RelizyCancelError.

See Also ​