Skip to content

fix changeset parser fail when summary is empty#740

Merged
Andarist merged 8 commits intochangesets:mainfrom
akphi:fix-empty-summary
Jan 24, 2022
Merged

fix changeset parser fail when summary is empty#740
Andarist merged 8 commits intochangesets:mainfrom
akphi:fix-empty-summary

Conversation

@akphi
Copy link
Copy Markdown

@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
Copy Markdown

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
Copy Markdown

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

summary: ""
});
});
it("should be fine if the changeset only contains frontmatter", () => {
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.

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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!

import { Release, VersionType } from "@changesets/types";

const mdRegex = /\s*---([^]*?)\n\s*---\s*\n([^]*)/;
const mdRegex = /\s*---([^]*?)\n\s*---(?:\s*\n([^]*))?$/;
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.

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
Copy Markdown
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
Copy Markdown
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 and others added 3 commits January 24, 2022 15:26
@akphi
Copy link
Copy Markdown
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