yarn version — Yarn CLI reference
Change versions of workspaces
yarn version
Change versions of workspaces
This command will bump the version of the current workspace, according to the given strategy:
-
If it is a valid semver, it will be used as the new version (build metadata is stripped).
-
The
major,minor, andpatchstrategies will bump to the next semver-major, semver-minor, or semver-patch version, respectively. A prerelease of the corresponding level is bumped to its stable version (1.2.0-3becomes1.2.0withminor). -
The
prepatchstrategy will only increment the prerelease identifier if the current version is already a prerelease of a semver-patch or higher level bump. Otherwise, the new version is calculated by adding prerelease identifier(s) to the next semver-patch version. -
The
preminorandpremajorstrategies work similarly toprepatch, but for semver-minor and semver-major versions, respectively. -
The
prereleasestrategy will only increment the prerelease identifier if the current version is already a prerelease. Otherwise, it is equivalent toprepatch. -
The
declinestrategy will not bump versions at all. It is mostly for use with deferred versioning.
By default, the version bump will only apply to the current workspace. If --all is set, the version bump will be applied to all workspaces in the project. Note that the ranges that other workspaces use to depend on the bumped workspaces aren’t updated; use the workspace:^ / workspace:~ ranges if you need them to follow the version bumps.
If --dry-run is set, the command will print the new versions the workspace(s) would be bumped to (or the strategies that would be recorded) without actually changing anything.
Attempting to bump a workspace to a lower version than its current one will throw an error unless --force is set. Note that when using deferred versioning, --force is needed twice: once when recording the deferred version bump, and again when applying it.
Prerelease identifiers#
By default, incrementing an existing prerelease identifier will increment the last numeric component, and -0 will be used when adding a prerelease identifier to a non-prerelease version.
The --prerelease option can be used to specify a prerelease pattern to use. In the pattern, %n can be used to specify an incrementing numeric component. When incrementing an existing prerelease identifier, it will be matched against the pattern. If the pattern matches, all components matched by %n will be incremented. If the pattern doesn’t match, or if a prerelease identifier is being added to a non-prerelease version, the %n components will be set to 1. If the --prerelease option is set without a value, the default pattern of rc.%n will be used.
The prerelease pattern is also applied to the major, minor, and patch strategies (so yarn version patch --prerelease=alpha.0 turns 1.0.32 into 1.0.33-alpha.0), but not to explicit versions. When --prerelease is set, the deferred records of the bumped workspaces are kept so that a later stable bump can still consume them.
Immediate vs deferred versioning#
By default, the version bump will be applied immediately. If the --deferred flag or the preferDeferredVersions configuration option is set, deferred versioning will be used instead: the version bump will only be recorded, and can be applied in the future by running yarn version apply. The --immediate flag can be used to force immediate mode even if preferDeferredVersions is set.
An immediate version bump can be applied to workspaces for which deferred records exist. However, attempting to bump to a version that is lower than the recorded deferred bump will throw an error unless --force is set. After the immediate bump, deferred records for the bumped workspace(s) will be consumed.
Record the release strategy only
Bump the version immediately
Bump the version of all workspaces
Specify a prerelease pattern to use when computing the new versions
Print version(s)/record(s) without actually bumping versions or recording deferred releases
Bypass the check for bumping to a lower version than the current/deferred one
Format the output as an NDJSON stream
Examples#
Immediately bump the version to the next major
Prepare the version to be bumped to the next major
Bump the version to the first release candidate of the next minor
Print the versions all the workspaces would be bumped to, without changing anything