fix(plugin-version): align suggestStrategy base with stableVersion-aware applyStrategy#7110
Open
KimHyeongRae0 wants to merge 1 commit intoyarnpkg:masterfrom
Conversation
…are applyStrategy When a workspace has a prerelease `version` shadowed by a `stableVersion`, `yarn version <semver>` would suggest a strategy against the prerelease base (`1.3.1-alpha`) but apply it against the stable base (`1.2.1`), producing an unexpected patch bump (`1.2.2`) instead of honoring the literal target (`1.3.1`). Mirror the stableVersion-aware base in the suggest step so both paths agree on which version to bump from; when no strategy fits, the literal semver arg is preserved (applyStrategy already short-circuits on `semver.valid(strategy)`). Fixes yarnpkg#7025
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What's the problem this PR addresses?
Closes #7025.
When a workspace has a prerelease
versionshadowed by astableVersion, runningyarn version <semver>against a literal target bumps the wrong way. Exact repro from the issue:```json
{
"name": "test-version",
"version": "1.3.1-alpha",
"stableVersion": "1.2.1"
}
```
```
$ yarn version 1.3.1
➤ YN0000: test-version@workspace:.: Bumped to 1.2.2 ← wrong; should be 1.3.1
```
Root cause is a base-version divergence between two internal paths:
packages/plugin-version/sources/commands/version.tspicked a release strategy by callingsuggestStrategy(workspace.manifest.version, this.strategy). Withversion="1.3.1-alpha"and arg"1.3.1",semver.inc("1.3.1-alpha", "patch") === "1.3.1"matched, so the suggestion came back aspatch.packages/plugin-version/sources/versionUtils.ts(insideresolveVersionFiles) deliberately bases the bump onworkspace.manifest.raw.stableVersion ?? workspace.manifest.version, per the existing comment "If there's astableVersionfield, then we assume thatversioncontains a prerelease version and that we need to base the version bump relative to the latest stable instead." WithstableVersion="1.2.1",semver.inc("1.2.1", "patch") === "1.2.2"— hence the wrong bump.The two paths disagreed on which version to treat as the base.
How did you fix it?
Mirror the
stableVersion-aware base in the suggest step so both paths agree on the baseline:```ts
// packages/plugin-version/sources/commands/version.ts
const baseVersion = workspace.manifest.raw.stableVersion ?? workspace.manifest.version;
const suggestedStrategy = versionUtils.suggestStrategy(baseVersion, this.strategy);
```
When no pre-defined strategy matches the stable base (as in the #7025 case), the literal semver argument is preserved —
applyStrategyalready short-circuits onsemver.valid(strategy)and returns it verbatim.For the #7025 scenario this restores the expected flow:
baseVersion = "1.2.1", no strategy fits →releaseStrategy = "1.3.1"(literal).applyStrategy(..., "1.3.1")→"1.3.1". Post-bumpapplyReleasesremoves the now-obsoletestableVersionfield becausesemver.prerelease("1.3.1") === null.A regression test is added under
packages/acceptance-tests/pkg-tests-specs/sources/commands/version.test.tscovering the exact repro. All existing tests in that file (20 pre-existing + the new one) pass. Changeset shape follows #6879 (the most recentplugin-version-scoped PR):@yarnpkg/cli: patch+@yarnpkg/plugin-version: patch.Checklist