-
Notifications
You must be signed in to change notification settings - Fork 491
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix a bug with prereleases where a package would not be bumped with the highest bump type of all changesets from previous prereleases within the same prerelease run #263
Conversation
…he highest bump type of all changesets from previous prereleases within the same prerelease run
🦋 Changeset is good to goLatest commit: 28da376 We got this. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Codecov Report
@@ Coverage Diff @@
## master #263 +/- ##
==========================================
+ Coverage 80.04% 80.06% +0.01%
==========================================
Files 45 45
Lines 1203 1204 +1
Branches 277 278 +1
==========================================
+ Hits 963 964 +1
Misses 229 229
Partials 11 11
Continue to review full report at Codecov.
|
@@ -2834,6 +2834,15 @@ get-value@^2.0.3, get-value@^2.0.6: | |||
resolved "https://registry.yarnpkg.com/get-value/-/get-value-2.0.6.tgz#dc15ca1c672387ca76bd37ac0a395ba2042a2c28" | |||
integrity sha1-3BXKHGcjh8p2vTesCjlbogQqLCg= | |||
|
|||
get-workspaces@^0.5.0: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems like this shouldn't land in yarn.lock?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's probably because of Manypkg, it's pretty much fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
interesting - I would expect no change if @manypkg/cli
relies on get-workspaces
(which it does), seems like on master there is no get-workspaces
entry in yarn.lock, which seems incorrect? unless master yarn.lock got corrupted somehow?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would guess that this is the first time that the yarn.lock was updated since the last release so that's why there's no get-workspaces entry in the yarn.lock in master.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even with that - yarn should always use "external" version if a dependency relies on it, shouldnt it? So this entry should be there all along, it's not safe to reuse workspace version in such situation.
It ain't much of a problem, this just has surprised me and I wonder why this has happened out loud 😅
@@ -62,6 +64,36 @@ function assembleReleasePlan( | |||
// flattened down to one release per package, having a reference back to their | |||
// changesets, and with a calculated new versions | |||
let releases = flattenReleases(changesets, workspaces); | |||
|
|||
// for every release in pre mode, we want versions to be bumped to the highest bump type |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if I understand the problem correctly, but from what I understand this was caused by the fact that new changesets (the one not added to pre.json
yet) could have only lower release types than what was already released before (so what was already added to pre.json
before).
If that's the case then I'm wondering - why this had not affected Emotion? We had to have such situation there, I've often~ released only patches when in pre mode.
Also - shouldn't really package.json#version
be accounted for as well, rather than just changesets? It's of course not advised to handle stuff manually once you start using changesets, but this could happen and this logic here could lead to unexpected results?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're understanding the problem correctly.
If that's the case then I'm wondering - why this had not affected Emotion? We had to have such situation there, I've often~ released only patches when in pre mode.
Good point, I just looked into it a bit and it looks like it's because of linked and I have a hunch that it'll cause a bug so I'll look into it more soon.
Also - shouldn't really
package.json#version
be accounted for as well, rather than just changesets? It's of course not advised to handle stuff manually once you start using changesets, but this could happen and this logic here could lead to unexpected results?
Yeah, that could be a possibility for confusion but what would accounting for package.json#version
mean? For example, if you had a package with 1.0.0
and someone bumped the major to 2.0.0-next.0
manually and we have a minor changeset to apply, what should the new version be? What if they bumped it to 3.0.0-next.0
instead? How do we know when to bump and when we've already bumped to a level? I think the right answer here is what we're doing where we store the version before the prereleases and apply the highest bump type to that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, I guess there is really no good answer to this because we can think of weird cases for both approaches so we really shouldn't be worried much about manual changes to versions as this just has to be strongly discouraged
one additional thing that comes to my mind - technically with the given approach it's possible to "revert" the scope of changes (by publishing a major prerelease and removing that changeset later), which seems reasonable - but also somewhat dangerous for future releases? i think it really isnt much of a real-life scenario so I wouldnt be bothered with it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
one additional thing that comes to my mind - technically with the given approach it's possible to "revert" the scope of changes (by publishing a major prerelease and removing that changeset later), which seems reasonable - but also somewhat dangerous for future releases? i think it really isnt much of a real-life scenario so I wouldnt be bothered with it
Yeah, that's true. I agree that it's not a concern.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If that's the case then I'm wondering - why this had not affected Emotion? We had to have such situation there, I've often~ released only patches when in pre mode.
I actually was wondering this myself when I hit the issue.
Also - shouldn't really package.json#version be accounted for as well, rather than just changesets? It's of course not advised to handle stuff manually once you start using changesets, but this could happen and this logic here could lead to unexpected results?
From an explaining how version calculation happens, not taking package.json into account is much easier to explain. Pre-release semver is calculated using both released and unreleased changesets rather than just released changesets
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this comment could be simplified.
When calculating pre-release versions, the highest version bump of released changesets also need to be applied to the initial pre-release version otherwise calculated version number can be lower than the last released version of the package.
.changeset/dirty-coins-enjoy.md
Outdated
"@changesets/cli": patch | ||
--- | ||
|
||
Fix a bug with prereleases where a package would not be bumped with the highest bump type of all changesets from previous prereleases within the same prerelease run |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This message is a little bit confusing to me, I had to really focus to understand this and I'm still unsure if I got this correctly. Especially the last part is confusing for me (in relation to what is being written before) - "within the same prerelease run" is vague and hard to tell what does it mean in this context.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this instead?
Fixed a bug in version calculation where only the unreleased pre-release changesets were taken into account when calculating the semver, not previously released changesets.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks for fixing this issue. Dropped a few comments on as well
@@ -586,4 +586,52 @@ describe("pre", () => { | |||
} | |||
]); | |||
}); | |||
it("should use the highest bump type for between all prereleases for every prerelease", async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice tests, really easy to read 👍
@@ -62,6 +64,36 @@ function assembleReleasePlan( | |||
// flattened down to one release per package, having a reference back to their | |||
// changesets, and with a calculated new versions | |||
let releases = flattenReleases(changesets, workspaces); | |||
|
|||
// for every release in pre mode, we want versions to be bumped to the highest bump type |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If that's the case then I'm wondering - why this had not affected Emotion? We had to have such situation there, I've often~ released only patches when in pre mode.
I actually was wondering this myself when I hit the issue.
Also - shouldn't really package.json#version be accounted for as well, rather than just changesets? It's of course not advised to handle stuff manually once you start using changesets, but this could happen and this logic here could lead to unexpected results?
From an explaining how version calculation happens, not taking package.json into account is much easier to explain. Pre-release semver is calculated using both released and unreleased changesets rather than just released changesets
@@ -62,6 +64,36 @@ function assembleReleasePlan( | |||
// flattened down to one release per package, having a reference back to their | |||
// changesets, and with a calculated new versions | |||
let releases = flattenReleases(changesets, workspaces); | |||
|
|||
// for every release in pre mode, we want versions to be bumped to the highest bump type |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this comment could be simplified.
When calculating pre-release versions, the highest version bump of released changesets also need to be applied to the initial pre-release version otherwise calculated version number can be lower than the last released version of the package.
// we don't want to add any new releases, we only want to update ones that will already happen | ||
// because if they're not being released, the version will already have been bumped with the highest bump type | ||
if (updatedPreState !== undefined && updatedPreState.mode !== "exit") { | ||
let releasesFromUnfilteredChangesets = flattenReleases( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this function return released AND unreleased changesets?
If it only contains released then the opposite issue could occur when the released were only a minor bump but the major contains a major?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It contains released and unreleased.
I "fixed" the "bug" that meant that this bug didn't affect Emotion. I say those things in quotation marks because the bugs were mostly covered up by the slightly confusing nature of |
Closes #244