Skip to content

Version: Reimplement yarn version and yarn version apply - #7218

Merged
arcanis merged 18 commits into
masterfrom
clemyan/version-refactor
Jul 28, 2026
Merged

Version: Reimplement yarn version and yarn version apply#7218
arcanis merged 18 commits into
masterfrom
clemyan/version-refactor

Conversation

@clemyan

@clemyan clemyan commented Jul 11, 2026

Copy link
Copy Markdown
Member

What's the problem this PR addresses?

The yarn version family of commands has a number of unintuitive behaviors. The most prominent ones are:

  • Immediate mode in a git repo requires history because it is implemented as a yarn version --deferred + yarn version apply
  • For dealing with prereleases, it uses a relatively less-known stableVersion field in addition to the version field which interacts unintuitively with some workflows. In particular, deferring a semver strategy resolves a named strategy against version, which yarn version apply applies to stableVersion

Fixes #3868
Fixes #4014
Fixes #4328
Fixes #5224
Fixes #6810
Fixes #6857
Fixes #6860
Fixes #6970
Fixes #7025

Closes #7110 (supercedes)

How did you fix it?

Reimplemented the yarn version and yarn version apply commands.

Now the bumping logic resides in yarn version --immediate. Instead of yarn version --immediate being implemented as yarn version --deferred + yarn version apply, now yarn version apply is implemented as yarn version --immediate decline. This alleviates the git history requirement of yarn version --immediate

The prerelease bumping logic is also refactored to be more predictable and can be calculated from a single version, without relying on storing an additional stableVersion. Simply put, if the current version is 1.2.0-3, prepatch and preminor both bump it to 1.2.0-4 and premajor bump it to 2.0.0-0. prerelease is effectively same as prepatch.

Now that stableVersion is not needed, yarn version --immediate and yarn version apply will remove them from any bumped workspaces.

(Our own release pipeline also writes the stableVersion field but I don't know if there is a purpose. So I have left them alone for now)

The --prerelease flag also have some bug fixed. For example, when applying a prerelease bump to 1.2.3-alpha.1 with prerelease pattern beta.%n, you'd end up with 1.2.3-alpha.1-beta.1...

Also, given how easily "bumping" to a version lower than the current one can happen accidentally due to how prereleases work, there is also now a check to stop that and a --force flag to suppress that check.

The command documentation has been rewritten and many tests have been added to rigorously document these behavior.

Checklist

  • I have set the packages that need to be released for my changes to be effective.
  • I will check that all automated PR checks pass before the PR gets reviewed.

@clemyan
clemyan force-pushed the clemyan/version-refactor branch from 9592c8c to 322c5c9 Compare July 11, 2026 15:53
@clemyan

clemyan commented Jul 11, 2026

Copy link
Copy Markdown
Member Author

Force pushed to rebase over a merge conflict

@clemyan
clemyan force-pushed the clemyan/version-refactor branch from 322c5c9 to 4fdbac7 Compare July 11, 2026 18:12
@clemyan
clemyan marked this pull request as ready for review July 17, 2026 16:36
@clemyan

clemyan commented Jul 17, 2026

Copy link
Copy Markdown
Member Author

Looks like DefinitelyTyped/DefinitelyTyped#75230 isn't moving along. I'll mark this as ready. We can upgrade @types/semver if and when a new version of is released.

@arcanis
arcanis merged commit bb3e95f into master Jul 28, 2026
29 checks passed
@arcanis
arcanis deleted the clemyan/version-refactor branch July 28, 2026 21:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment