@changesets/parse
Advanced tools
Comparing version 0.2.1 to 0.3.0
# @changesets/parse | ||
## 0.3.0 | ||
### Minor Changes | ||
- [`8dce96f`](https://github.com/atlassian/changesets/commit/8dce96f8aec43f82b35e65f54b06cbeed3275885) [#187](https://github.com/atlassian/changesets/pull/187) Thanks [@gardnerjack](https://github.com/gardnerjack)! - Added --empty flag to the add command for empty changeset files. New tests for adding, writing, parsing, and reading empty changesets. | ||
## 0.2.1 | ||
@@ -4,0 +10,0 @@ |
@@ -9,3 +9,3 @@ 'use strict'; | ||
const mdRegex = /\s*---([^]+?)\n\s*---\n([^]+)/; | ||
const mdRegex = /\s*---([^]*?)\n\s*---\n([^]*)/; | ||
function parseChangesetFile(contents) { | ||
@@ -24,6 +24,11 @@ const execResult = mdRegex.exec(contents); | ||
const yamlStuff = yaml.safeLoad(roughReleases); | ||
releases = Object.entries(yamlStuff).map(([name, type]) => ({ | ||
name, | ||
type | ||
})); | ||
if (yamlStuff) { | ||
releases = Object.entries(yamlStuff).map(([name, type]) => ({ | ||
name, | ||
type | ||
})); | ||
} else { | ||
releases = []; | ||
} | ||
} catch (e) { | ||
@@ -30,0 +35,0 @@ throw new Error(`could not parse changeset - invalid frontmatter: ${contents}`); |
@@ -13,3 +13,3 @@ "use strict"; | ||
const mdRegex = /\s*---([^]+?)\n\s*---\n([^]+)/; | ||
const mdRegex = /\s*---([^]*?)\n\s*---\n([^]*)/; | ||
@@ -22,6 +22,6 @@ function parseChangesetFile(contents) { | ||
const yamlStuff = yaml.safeLoad(roughReleases); | ||
releases = Object.entries(yamlStuff).map(([name, type]) => ({ | ||
releases = yamlStuff ? Object.entries(yamlStuff).map(([name, type]) => ({ | ||
name: name, | ||
type: type | ||
})); | ||
})) : []; | ||
} catch (e) { | ||
@@ -28,0 +28,0 @@ throw new Error(`could not parse changeset - invalid frontmatter: ${contents}`); |
import yaml from 'js-yaml'; | ||
const mdRegex = /\s*---([^]+?)\n\s*---\n([^]+)/; | ||
const mdRegex = /\s*---([^]*?)\n\s*---\n([^]*)/; | ||
function parseChangesetFile(contents) { | ||
@@ -17,6 +17,11 @@ const execResult = mdRegex.exec(contents); | ||
const yamlStuff = yaml.safeLoad(roughReleases); | ||
releases = Object.entries(yamlStuff).map(([name, type]) => ({ | ||
name, | ||
type | ||
})); | ||
if (yamlStuff) { | ||
releases = Object.entries(yamlStuff).map(([name, type]) => ({ | ||
name, | ||
type | ||
})); | ||
} else { | ||
releases = []; | ||
} | ||
} catch (e) { | ||
@@ -23,0 +28,0 @@ throw new Error(`could not parse changeset - invalid frontmatter: ${contents}`); |
{ | ||
"name": "@changesets/parse", | ||
"version": "0.2.1", | ||
"version": "0.3.0", | ||
"description": "Parse a changeset file's contents into a usable json object", | ||
@@ -5,0 +5,0 @@ "main": "dist/parse.cjs.js", |
@@ -7,3 +7,3 @@ import outdent from "outdent"; | ||
it("should parse a changeset", () => { | ||
let changesetMd = outdent`--- | ||
const changesetMd = outdent`--- | ||
"cool-package": minor | ||
@@ -15,3 +15,3 @@ --- | ||
let changeset = parse(changesetMd); | ||
const changeset = parse(changesetMd); | ||
expect(changeset).toEqual({ | ||
@@ -23,3 +23,3 @@ releases: [{ name: "cool-package", type: "minor" }], | ||
it("should parse major, minor, and patch changes", () => { | ||
let changesetMd = outdent`--- | ||
const changesetMd = outdent`--- | ||
"cool-package": minor | ||
@@ -33,3 +33,3 @@ "cool-package2": major | ||
let changeset = parse(changesetMd); | ||
const changeset = parse(changesetMd); | ||
expect(changeset).toEqual({ | ||
@@ -45,3 +45,3 @@ releases: [ | ||
it("should parse a changeset with a scoped package", () => { | ||
let changesetMd = outdent`--- | ||
const changesetMd = outdent`--- | ||
"@cool/package": minor | ||
@@ -53,3 +53,3 @@ --- | ||
let changeset = parse(changesetMd); | ||
const changeset = parse(changesetMd); | ||
expect(changeset).toEqual({ | ||
@@ -61,3 +61,3 @@ releases: [{ name: "@cool/package", type: "minor" }], | ||
it("should parse a changeset with multiline summary", () => { | ||
let expectedSummary = outdent`Let us go then you and I, | ||
const expectedSummary = outdent`Let us go then you and I, | ||
When the evening is spread out against the sky | ||
@@ -68,3 +68,3 @@ Like a patient, etherized upon a table. | ||
let changesetMd = outdent`--- | ||
const changesetMd = outdent`--- | ||
"cool-package": minor | ||
@@ -80,3 +80,3 @@ --- | ||
let changeset = parse(changesetMd); | ||
const changeset = parse(changesetMd); | ||
expect(changeset).toEqual({ | ||
@@ -88,21 +88,21 @@ releases: [{ name: "cool-package", type: "minor" }], | ||
it("should parse a changeset with multiple packages and multiline summary", () => { | ||
let expectedSummary = outdent`Let us go then you and I, | ||
When the evening is spread out against the sky | ||
Like a patient, etherized upon a table. | ||
- The Lovesong of J Alfred Prufrock, T. S. Eliot`; | ||
const expectedSummary = outdent`Let us go then you and I, | ||
When the evening is spread out against the sky | ||
Like a patient, etherized upon a table. | ||
let changesetMd = outdent`--- | ||
"cool-package": minor | ||
"best-package": patch | ||
--- | ||
Let us go then you and I, | ||
When the evening is spread out against the sky | ||
Like a patient, etherized upon a table. | ||
- The Lovesong of J Alfred Prufrock, T. S. Eliot | ||
`; | ||
- The Lovesong of J Alfred Prufrock, T. S. Eliot`; | ||
let changeset = parse(changesetMd); | ||
const changesetMd = outdent`--- | ||
"cool-package": minor | ||
"best-package": patch | ||
--- | ||
Let us go then you and I, | ||
When the evening is spread out against the sky | ||
Like a patient, etherized upon a table. | ||
- The Lovesong of J Alfred Prufrock, T. S. Eliot | ||
`; | ||
const changeset = parse(changesetMd); | ||
expect(changeset).toEqual({ | ||
@@ -117,3 +117,3 @@ releases: [ | ||
it("should be fine if a packageName includes ---", () => { | ||
let changesetMd = outdent`--- | ||
const changesetMd = outdent`--- | ||
"cool---package": minor | ||
@@ -125,3 +125,3 @@ --- | ||
let changeset = parse(changesetMd); | ||
const changeset = parse(changesetMd); | ||
expect(changeset).toEqual({ | ||
@@ -133,6 +133,6 @@ releases: [{ name: "cool---package", type: "minor" }], | ||
it("should be fine if the summary body includes ---", () => { | ||
let expectedSummary = outdent`--- | ||
const expectedSummary = outdent`--- | ||
Nice simple summary---that has this`; | ||
let changesetMd = outdent`--- | ||
const changesetMd = outdent`--- | ||
"cool-package": minor | ||
@@ -146,3 +146,3 @@ --- | ||
let changeset = parse(changesetMd); | ||
const changeset = parse(changesetMd); | ||
expect(changeset).toEqual({ | ||
@@ -153,2 +153,14 @@ releases: [{ name: "cool-package", type: "minor" }], | ||
}); | ||
it("should be fine if the changeset is empty", () => { | ||
const changesetMd = outdent`--- | ||
--- | ||
`; | ||
const changeset = parse(changesetMd); | ||
expect(changeset).toEqual({ | ||
releases: [], | ||
summary: "" | ||
}); | ||
}); | ||
}); |
import yaml from "js-yaml"; | ||
import { Release, VersionType } from "@changesets/types"; | ||
const mdRegex = /\s*---([^]+?)\n\s*---\n([^]+)/; | ||
const mdRegex = /\s*---([^]*?)\n\s*---\n([^]*)/; | ||
@@ -26,6 +26,10 @@ export default function parseChangesetFile( | ||
); | ||
releases = Object.entries(yamlStuff).map(([name, type]) => ({ | ||
name, | ||
type | ||
})); | ||
if (yamlStuff) { | ||
releases = Object.entries(yamlStuff).map(([name, type]) => ({ | ||
name, | ||
type | ||
})); | ||
} else { | ||
releases = []; | ||
} | ||
} catch (e) { | ||
@@ -32,0 +36,0 @@ throw new Error( |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
11446
274