Skip to content

Commit 957e39c

Browse files
akphiAndarist
andauthored
Fixed an issue with failing to parse changesets containing a completely 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>
1 parent 1be201f commit 957e39c

3 files changed

Lines changed: 36 additions & 1 deletion

File tree

.changeset/light-cats-flow.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@changesets/cli": patch
3+
"@changesets/parse": patch
4+
---
5+
6+
Fixed an issue with failing to parse changesets containing a completely empty summary.

packages/parse/src/index.test.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,28 @@ describe("parsing a changeset", () => {
136136
summary: expectedSummary
137137
});
138138
});
139+
it("should be fine if the summary body is completely empty and there is no trailing whitespace", () => {
140+
const changesetMd = outdent`---
141+
"cool-package": minor
142+
---`;
143+
144+
const changeset = parse(changesetMd);
145+
expect(changeset).toEqual({
146+
releases: [{ name: "cool-package", type: "minor" }],
147+
summary: ""
148+
});
149+
});
150+
it("should be fine if there is no summary body and the frontmatter has some trailing whitespace", () => {
151+
const changesetMd = outdent`---
152+
"cool-package": minor
153+
--- `;
154+
155+
const changeset = parse(changesetMd);
156+
expect(changeset).toEqual({
157+
releases: [{ name: "cool-package", type: "minor" }],
158+
summary: ""
159+
});
160+
});
139161
it("should be fine if the changeset is empty", () => {
140162
const changesetMd = outdent`---
141163
---
@@ -148,6 +170,13 @@ describe("parsing a changeset", () => {
148170
summary: ""
149171
});
150172
});
173+
it("should be fine if the changeset is empty and without any trailing whitespace", () => {
174+
const changeset = parse(`---\n---`);
175+
expect(changeset).toEqual({
176+
releases: [],
177+
summary: ""
178+
});
179+
});
151180
it("should be fine if the frontmatter is followed by a whitespace on the same line", () => {
152181
const changesetMd = outdent`---
153182
"cool-package": minor

packages/parse/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import yaml from "js-yaml";
22
import { Release, VersionType } from "@changesets/types";
33

4-
const mdRegex = /\s*---([^]*?)\n\s*---\s*\n([^]*)/;
4+
const mdRegex = /\s*---([^]*?)\n\s*---(\s*(?:\n|$)[^]*)/;
55

66
export default function parseChangesetFile(
77
contents: string

0 commit comments

Comments
 (0)