Repository: atlassian/changesets
Pull request #462 (2020-09-30 19:06:00)

Fixed an issue with failing to parse changesets containing Windows newlines
I believe that it fixes https://github.com/atlassian/changesets/issues/461

changeset-bot[bot]: ###  🦋  Changeset detected

Latest commit: 804c7f57b1c0eef3934ef3ebec297607216e0d68

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

<details><summary>This PR includes changesets to release 1 package</summary>

  | Name              | Type  |
| ----------------- | ----- |
| @changesets/parse | Patch |

</details>

Not sure what this means? [Click here  to learn what changesets are](https://github.com/changesets/changesets/blob/master/docs/adding-a-changeset.md).

[Click here if you're a maintainer who wants to add another changeset to this PR](https://github.com/atlassian/changesets/new/fix/windows-parse?filename=.changeset/wild-crews-call.md&value=---%0A%22%40changesets%2Fparse%22%3A%20patch%0A---%0A%0AFixed%20an%20issue%20with%20failing%20to%20parse%20changesets%20containing%20Windows%20newlines%0A)



Patch:
diff --git a/.changeset/thin-lobsters-lick.md b/.changeset/thin-lobsters-lick.md
new file mode 100644
index 0000000..8d5991a
--- /dev/null
+++ b/.changeset/thin-lobsters-lick.md
@@ -0,0 +1,5 @@
+---
+"@changesets/parse": patch
+---
+
+Fixed an issue with failing to parse changesets containing Windows newlines.
diff --git a/packages/parse/src/index.ts b/packages/parse/src/index.ts
index 3710de2..56c74a2 100644
--- a/packages/parse/src/index.ts
+++ b/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*---\n([^]*)/;
+const mdRegex = /\s*---([^]*?)\n\s*---\s*\n([^]*)/;
 
 export default function parseChangesetFile(
   contents: string


Test patch:
diff --git a/packages/parse/src/index.test.ts b/packages/parse/src/index.test.ts
index 4f57fbd..a9b530f 100644
--- a/packages/parse/src/index.test.ts
+++ b/packages/parse/src/index.test.ts
@@ -148,4 +148,56 @@ describe("parsing a changeset", () => {
       summary: ""
     });
   });
+  it("should be fine if the frontmatter is followed by a whitespace on the same line", () => {
+    const changesetMd = outdent`---
+    "cool-package": minor
+    ---${
+      "  " /* this prevents auto-formatters from removing the trailing whitespace */
+    }
+
+    Nice simple summary
+    `;
+
+    const changeset = parse(changesetMd);
+    expect(changeset).toEqual({
+      releases: [{ name: "cool-package", type: "minor" }],
+      summary: "Nice simple summary"
+    });
+  });
+  it("should be fine when md contains Windows new lines", () => {
+    const changesetMd = outdent`---
+    "cool-package": minor
+    "best-package": patch
+    ---
+
+    Nice simple summary
+    `
+      .split("\n")
+      .join("\r\n");
+
+    const changeset = parse(changesetMd);
+    expect(changeset).toEqual({
+      releases: [
+        { name: "cool-package", type: "minor" },
+        { name: "best-package", type: "patch" }
+      ],
+      summary: "Nice simple summary"
+    });
+  });
+  it("should throw if the frontmatter is followed by non-whitespace characters on the same line", () => {
+    const changesetMd = outdent`---
+    "cool-package": minor
+    ---  fail
+
+    Nice simple summary
+    `;
+
+    expect(() => parse(changesetMd)).toThrowErrorMatchingInlineSnapshot(`
+"could not parse changeset - invalid frontmatter: ---
+\\"cool-package\\": minor
+---  fail
+
+Nice simple summary"
+`);
+  });
 });