Skip to content

Fix a bug where packages that shouldn't get released get patch releases when the pre mode is exit - #382

Merged
emmatown merged 5 commits into
changesets:masterfrom
Feiyang1:fei-fix
Jun 4, 2020
Merged

emmatown merged 5 commits into
changesets:masterfrom
Feiyang1:fei-fix

Conversation

@Feiyang1

@Feiyang1 Feiyang1 commented Jun 1, 2020

Copy link
Copy Markdown
Contributor

Fix a bug where packages that shouldn't get released get patch releases when the pre mode is exit

@changeset-bot

changeset-bot Bot commented Jun 1, 2020 •

Copy link
Copy Markdown

🦋 Changeset is good to go

Latest commit: 82f89d0

We got this.

This PR includes changesets to release 1 package
Name Type
@changesets/assemble-release-plan Patch

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

@emmatown
emmatown self-requested a review June 1, 2020 22:41
if (updatedPreState.mode === "exit") {
for (let pkg of packages.packages) {
if (preVersions.get(pkg.packageJson.name) !== -1) {
if (preVersions.get(pkg.packageJson.name)) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
if (preVersions.get(pkg.packageJson.name)) {
if (preVersions.get(pkg.packageJson.name) !== 0) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

@Feiyang1 Feiyang1 Jun 2, 2020 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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"

@Andarist Andarist Jun 2, 2020 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, that makes sense. Thanks for the detailed explanation! I have updated the PR according to your request and added an integration test. PTAL.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mitchellhamilton This is a great visual~ explanation of this behavior. Could probably make its way to some FAQ section for pre mode.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@emmatown emmatown left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants