Skip to content
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 changeset parser fail when summary is empty #740

Merged
merged 8 commits into from
Jan 24, 2022

Conversation

akphi
Copy link
Contributor

@akphi akphi commented Jan 23, 2022

Fix changesets/action#138

@Andarist Could you do me a favor to upgrade changeset-action to use the latest parser when we merge this PR? Thank you so much!

@changeset-bot
Copy link

changeset-bot bot commented Jan 23, 2022

🦋 Changeset detected

Latest commit: 2ff6345

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@changesets/cli Patch
@changesets/parse 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

@codesandbox-ci
Copy link

codesandbox-ci bot commented Jan 23, 2022

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit ba5dcff:

Sandbox Source
Vanilla Configuration

@@ -148,6 +148,17 @@ describe("parsing a changeset", () => {
summary: ""
});
});
it("should be fine if the changeset only contains frontmatter", () => {
Copy link
Member

Choose a reason for hiding this comment

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

This is a somewhat different test case that was originally reported. The reported case was about an empty summary but it had some releases declared in the frontmatter. I believe that it's worth adding tests for both of those cases.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

---
`;

const changeset = parse(changesetMd);
Copy link
Member

Choose a reason for hiding this comment

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

outdent removes a trailing newline by default and all but it feels a little bit implicit here. I would prefer if we could do this explicitly here:

Suggested change
const changeset = parse(changesetMd);
const changeset = parse('---\n---');

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I totally overlooked that you have outdent. Updated!

@@ -1,7 +1,7 @@
import yaml from "js-yaml";
import { Release, VersionType } from "@changesets/types";

const mdRegex = /\s*---([^]*?)\n\s*---\s*\n([^]*)/;
const mdRegex = /\s*---([^]*?)\n\s*---(?:\s*\n([^]*))?$/;
Copy link
Member

Choose a reason for hiding this comment

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

This version of the regexp doesn't allow for a valid~ input like "---\n--- "

We can fix this with:

Suggested change
const mdRegex = /\s*---([^]*?)\n\s*---(?:\s*\n([^]*))?$/;
const mdRegex = /\s*---([^]*?)\n\s*---(\s*(?:\n|$)[^]*)/;

By using this suggestion we can also revert the change in the summary declaration as this regexp doesn't use an optional capturing group so it will always end up using an empty string for a roughSummary match.

Copy link
Contributor Author

@akphi akphi Jan 24, 2022

Choose a reason for hiding this comment

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

Very nice catch! This is updated now. Also added a test for the case you mentioned

Co-authored-by: Mateusz Burzyński <mateuszburzynski@gmail.com>
Co-authored-by: Mateusz Burzyński <mateuszburzynski@gmail.com>
@Andarist
Copy link
Member

@akphi could you also add a changeset for this change?

@Andarist Could you do me a favor to upgrade changeset-action to use the latest parser when we merge this PR? Thank you so much!

Sure thing.

@akphi
Copy link
Contributor Author

akphi commented Jan 24, 2022

@akphi could you also add a changeset for this change?

Done!

@Andarist Andarist merged commit 957e39c into changesets:main Jan 24, 2022
@akphi akphi deleted the fix-empty-summary branch January 24, 2022 08:30
@github-actions github-actions bot mentioned this pull request Jan 24, 2022
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.

Bug: Changeset file with empty content will fail
2 participants