bump()
Compute and write the new versions from Node.js, and get the bumped packages.
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:
| Option | Description |
|---|---|
type | BumpReleaseType: 'release' (default) computes the bump from the commits, or 'major', 'minor', 'patch', 'prerelease', 'premajor', 'preminor', 'prepatch' |
preid | Prerelease identifier: 'beta', 'rc'... |
suffix | With a prerelease type, replaces the last number of the version |
canary | Writes a canary version, {nextVersion}-0.canary-{sha} (preid replaces canary) |
force | Bumps the packages even without a commit triggering a bump |
yes | Confirms 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 |
clean | false bumps with uncommitted changes |
dependencyTypes | Overrides bump.dependencyTypes |
privatePackages | Overrides monorepo.privatePackages |
capZeroMajor | Overrides bump.capZeroMajor |
outOfRangePeers | Overrides 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 theiroldVersionandnewVersion;oldVersion,newVersion,fromTag,rootPackage: the root version before and after, and the previous release tag (unifiedandselectivemodes);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:bumpedPackageslists the packages of every group,newVersionis the one of theunified/selectivegroup.
See BumpResultTruthy and GroupBumpResult.
Examples
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:
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.
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, orbump.yes: truein the config or the profile, the versions are confirmed in advance:onConfirmis not called. falsecancels the run as a refused prompt: aRelizyCancelError,cancelled: truein 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 aRelizyCancelError.