Skip to content

Commit

Permalink
Fixed an issue with failing to parse changesets containing a complete…
Browse files Browse the repository at this point in the history
…ly empty summary (#740)

* fix changeset parser fail when summary is empty

* following up on PR review

* Update packages/parse/src/index.test.ts

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

* Update packages/parse/src/index.test.ts

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

* add changeset

* Update packages/parse/src/index.test.ts

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

* Update .changeset/light-cats-flow.md

Co-authored-by: Mateusz Burzyński <mateuszburzynski@gmail.com>
  • Loading branch information
akphi and Andarist committed Jan 24, 2022
1 parent 1be201f commit 957e39c
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .changeset/light-cats-flow.md
@@ -0,0 +1,6 @@
---
"@changesets/cli": patch
"@changesets/parse": patch
---

Fixed an issue with failing to parse changesets containing a completely empty summary.
29 changes: 29 additions & 0 deletions packages/parse/src/index.test.ts
Expand Up @@ -136,6 +136,28 @@ describe("parsing a changeset", () => {
summary: expectedSummary
});
});
it("should be fine if the summary body is completely empty and there is no trailing whitespace", () => {
const changesetMd = outdent`---
"cool-package": minor
---`;

const changeset = parse(changesetMd);
expect(changeset).toEqual({
releases: [{ name: "cool-package", type: "minor" }],
summary: ""
});
});
it("should be fine if there is no summary body and the frontmatter has some trailing whitespace", () => {
const changesetMd = outdent`---
"cool-package": minor
--- `;

const changeset = parse(changesetMd);
expect(changeset).toEqual({
releases: [{ name: "cool-package", type: "minor" }],
summary: ""
});
});
it("should be fine if the changeset is empty", () => {
const changesetMd = outdent`---
---
Expand All @@ -148,6 +170,13 @@ describe("parsing a changeset", () => {
summary: ""
});
});
it("should be fine if the changeset is empty and without any trailing whitespace", () => {
const changeset = parse(`---\n---`);
expect(changeset).toEqual({
releases: [],
summary: ""
});
});
it("should be fine if the frontmatter is followed by a whitespace on the same line", () => {
const changesetMd = outdent`---
"cool-package": minor
Expand Down
2 changes: 1 addition & 1 deletion packages/parse/src/index.ts
@@ -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|$)[^]*)/;

export default function parseChangesetFile(
contents: string
Expand Down

0 comments on commit 957e39c

Please sign in to comment.