Repository navigation
Fix a bug where packages that shouldn't get released get patch releases when the pre mode is exit - #382
Conversation
🦋 Changeset is good to goLatest commit: 82f89d0 We got this. This PR includes changesets to release 1 package
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 |
| if (updatedPreState.mode === "exit") { | ||
| for (let pkg of packages.packages) { | ||
| if (preVersions.get(pkg.packageJson.name) !== -1) { | ||
| if (preVersions.get(pkg.packageJson.name)) { |
There was a problem hiding this comment.
I know this doesn't affect the behavior but it was hard for me to understand why this fixes something and what this is actually checking and this makes that more clear.
| if (preVersions.get(pkg.packageJson.name)) { | |
| if (preVersions.get(pkg.packageJson.name) !== 0) { |
There was a problem hiding this comment.
I took another look at this and now I'm even more confused.
We only call preVersions.set within updatedPreState.mode !== "exit" block here:
https://github.com/atlassian/changesets/blob/64a9017aefa6b6444d83cf7802cca8e8404fb697/packages/assemble-release-plan/src/index.ts#L85
but this checks happens within updatedPreState.mode === "exit" block here:
https://github.com/atlassian/changesets/blob/64a9017aefa6b6444d83cf7802cca8e8404fb697/packages/assemble-release-plan/src/index.ts#L129
I suspect this might be a constant condition and this whole thing is bugged. Or have I missed something?
There was a problem hiding this comment.
@mitchellhamilton I don't think !== 0 works. preVersions.get() returns undefined if there is no match. I think we only want to execute the block if there is a match, but undefined !== 0 will evaluate to true, the same issue as undefined !== -1.
I could be wrong, because I don't really understand the purpose of this block. What @Andarist pointed out above confuses me too. @mitchellhamilton, do you have any insight?
There was a problem hiding this comment.
I suspect this might be a constant condition and this whole thing is bugged. Or have I missed something?
Yep (this is why I wanted to have a deeper look at it)
The point of this block is to make sure that any packages that were released while in pre mode will be (note that this wouldn't happen normally because when exiting pre mode, we essentially take the versions of packages before pre mode and apply the changesets to them but some packages will be bumped in pre mode but not in the normal process because semver ranges are different with prerelease versions so we need to do a patch bump to those)
I think the fix is to check !== 0 and move the bit that sets the preVersions outside of the block that checks updatedPreState.mode !== "exit"
There was a problem hiding this comment.
but some packages will be bumped in pre mode but not in the normal process because semver ranges are different with prerelease versions so we need to do a patch bump to those)
Could you elaborate on this one? It's a little bit convoluted and I don't think I understand this part.
btw. as we have established this is bugged now - I believe there is a missing test case that should be added (Im not sure what it is just yet, as I still don't understand this part of the code in full)
There was a problem hiding this comment.
Ah, that makes sense. Thanks for the detailed explanation! I have updated the PR according to your request and added an integration test. PTAL.
There was a problem hiding this comment.
@mitchellhamilton This is a great visual~ explanation of this behavior. Could probably make its way to some FAQ section for pre mode.
There was a problem hiding this comment.
just a question out of my curiosity - why one of the tests has been added as an integration test and the other one is more of a unit test?
There was a problem hiding this comment.
@Andarist I didn't think too much about it, so there is no particular reason. Is there any convention on when should integration test be added vs unit test, or both? I can certainly make another PR to add missing tests.
There was a problem hiding this comment.
My personal preference is to only implement integrations tests or unit tests for a particular package (treating it as a unit), so not implementing tests for particular files that have not been exposed as part of a public interface of a package.
I'm not sure what exact convention is used here, throughout the repository, and I don't really need you to adjust any of those added tests here. I was just curious why have you chosen one over another as I don't see anyone suggesting usage one over another to you. This kind of thing just always draws my curiosity - that's why I've asked 😅 I like to understand different perspectives.
Fix a bug where packages that shouldn't get released get patch releases when the pre mode is exit