🚨 Active Supply Chain Attack:node-ipc Package Compromised.Learn More
Socket
Book a DemoSign in
Socket

@changesets/parse

Package Overview
Dependencies
Maintainers
2
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@changesets/parse - npm Package Compare versions

Comparing version
1.0.0-next.3
to
1.0.0-next.4
+11
dist/index.d.mts
import { Release } from "@changesets/types";
//#region src/index.d.ts
declare function parseChangesetFile(contents: string): {
summary: string;
releases: Release[];
};
/** @deprecated Use named export `parseChangesetFile` instead */
declare const parseChangesetFileDefault: typeof parseChangesetFile;
//#endregion
export { parseChangesetFileDefault as default, parseChangesetFile };
import yaml from "js-yaml";
//#region src/index.ts
const mdRegex = /\s*---([^]*?)\n\s*---(\s*(?:\n|$)[^]*)/;
const EXAMPLE_FORMAT = `---\n"package-name": patch\n---`;
const validVersionTypes = [
"major",
"minor",
"patch",
"none"
];
function truncate(s, max = 200) {
return s.length > max ? s.slice(0, max) + "..." : s;
}
function validateReleases(releases, contents) {
for (const release of releases) {
if (typeof release.name !== "string" || release.name.trim() === "") throw new Error(`could not parse changeset - invalid package name in frontmatter.\nExpected a non-empty string for package name, but got: ${JSON.stringify(release.name)}\nChangeset contents:\n${truncate(contents)}`);
if (typeof release.type !== "string") throw new Error(`could not parse changeset - invalid release type for package "${release.name}".\nExpected a string for release type, but got: ${typeof release.type}\nChangeset contents:\n${truncate(contents)}`);
if (!validVersionTypes.includes(release.type)) throw new Error(`could not parse changeset - invalid version type ${JSON.stringify(release.type)} for package "${release.name}".\nValid version types are: ${validVersionTypes.join(", ")}\nChangeset contents:\n${truncate(contents)}`);
}
}
function parseChangesetFile(contents) {
const trimmedContents = contents.trim();
if (!trimmedContents) throw new Error(`could not parse changeset - file is empty.
Changesets must have frontmatter with package names and version types.
Example:\n${EXAMPLE_FORMAT}\n\nYour changeset summary here.`);
const execResult = mdRegex.exec(contents);
if (!execResult) throw new Error(`could not parse changeset - missing or invalid frontmatter.
Changesets must start with frontmatter delimited by "---".
Example:\n${EXAMPLE_FORMAT}\n\nYour changeset summary here.\nReceived content:\n${truncate(trimmedContents)}`);
const [, roughReleases, roughSummary] = execResult;
const summary = roughSummary.trim();
let releases;
let yamlStuff;
try {
yamlStuff = yaml.load(roughReleases);
} catch (e) {
throw new Error(`could not parse changeset - invalid YAML in frontmatter.
The frontmatter between the "---" delimiters must be valid YAML.
YAML error: ${e instanceof Error ? e.message : String(e)}\nFrontmatter content:\n${roughReleases}`, { cause: e });
}
if (yamlStuff) {
if (typeof yamlStuff !== "object" || Array.isArray(yamlStuff)) throw new Error(`could not parse changeset - frontmatter must be an object mapping package names to version types.\nExpected format:\n${EXAMPLE_FORMAT}\nReceived:\n${roughReleases}`);
releases = Object.entries(yamlStuff).map(([name, type]) => ({
name,
type
}));
} else releases = [];
validateReleases(releases, contents);
return {
releases,
summary
};
}
/** @deprecated Use named export `parseChangesetFile` instead */
const parseChangesetFileDefault = parseChangesetFile;
//#endregion
export { parseChangesetFileDefault as default, parseChangesetFile };
import { defineConfig } from "tsdown/config";
import { baseConfig } from "../../tsdown.config.ts";
export default defineConfig(baseConfig);
+7
-0
# @changesets/parse
## 1.0.0-next.4
### Patch Changes
- Updated dependencies [[`062530b`](https://github.com/changesets/changesets/commit/062530b825d53abc9d8934f3a50cc61ff3ff82b8)]:
- @changesets/types@7.0.0-next.4
## 1.0.0-next.3

@@ -4,0 +11,0 @@

+9
-5
{
"name": "@changesets/parse",
"version": "1.0.0-next.3",
"version": "1.0.0-next.4",
"description": "Parse a changeset file's contents into a usable json object",
"license": "MIT",
"repository": {
"type": "git",
"url": "git+https://github.com/changesets/changesets.git",
"directory": "packages/parse"
},
"type": "module",
"exports": {
".": "./dist/changesets-parse.js",
".": "./dist/index.mjs",
"./package.json": "./package.json"
},
"license": "MIT",
"repository": "https://github.com/changesets/changesets/tree/main/packages/parse",
"dependencies": {
"js-yaml": "^4.1.1",
"@changesets/types": "^7.0.0-next.3"
"@changesets/types": "^7.0.0-next.4"
},

@@ -16,0 +20,0 @@ "devDependencies": {

import { outdent } from "outdent";
import { describe, expect, it } from "vitest";
import parse from "./index.ts";
import { parseChangesetFile as parse } from "./index.ts";

@@ -5,0 +5,0 @@ describe("parsing a changeset", () => {

export * from "./declarations/src/index.js";
export { default } from "./declarations/src/index.js";
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2hhbmdlc2V0cy1wYXJzZS5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi9kZWNsYXJhdGlvbnMvc3JjL2luZGV4LmQudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEifQ==
import yaml from 'js-yaml';
const mdRegex = /\s*---([^]*?)\n\s*---(\s*(?:\n|$)[^]*)/;
const EXAMPLE_FORMAT = `---\n"package-name": patch\n---`;
const validVersionTypes = ["major", "minor", "patch", "none"];
function truncate(s, max = 200) {
return s.length > max ? s.slice(0, max) + "..." : s;
}
function validateReleases(releases, contents) {
for (const release of releases) {
if (typeof release.name !== "string" || release.name.trim() === "") {
throw new Error(`could not parse changeset - invalid package name in frontmatter.\n` + `Expected a non-empty string for package name, but got: ${JSON.stringify(release.name)}\n` + `Changeset contents:\n${truncate(contents)}`);
}
if (typeof release.type !== "string") {
throw new Error(`could not parse changeset - invalid release type for package "${release.name}".\n` + `Expected a string for release type, but got: ${typeof release.type}\n` + `Changeset contents:\n${truncate(contents)}`);
}
if (!validVersionTypes.includes(release.type)) {
throw new Error(`could not parse changeset - invalid version type ${JSON.stringify(release.type)} for package "${release.name}".\n` + `Valid version types are: ${validVersionTypes.join(", ")}\n` + `Changeset contents:\n${truncate(contents)}`);
}
}
}
function parseChangesetFile(contents) {
const trimmedContents = contents.trim();
if (!trimmedContents) {
throw new Error(`could not parse changeset - file is empty.\n` + `Changesets must have frontmatter with package names and version types.\n` + `Example:\n${EXAMPLE_FORMAT}\n\nYour changeset summary here.`);
}
const execResult = mdRegex.exec(contents);
if (!execResult) {
throw new Error(`could not parse changeset - missing or invalid frontmatter.\n` + `Changesets must start with frontmatter delimited by "---".\n` + `Example:\n${EXAMPLE_FORMAT}\n\nYour changeset summary here.\n` + `Received content:\n${truncate(trimmedContents)}`);
}
const [, roughReleases, roughSummary] = execResult;
const summary = roughSummary.trim();
let releases;
let yamlStuff;
try {
yamlStuff = yaml.load(roughReleases);
} catch (e) {
throw new Error(`could not parse changeset - invalid YAML in frontmatter.\n` + `The frontmatter between the "---" delimiters must be valid YAML.\n` + `YAML error: ${e instanceof Error ? e.message : String(e)}\n` + `Frontmatter content:\n${roughReleases}`, {
cause: e
});
}
if (yamlStuff) {
if (typeof yamlStuff !== "object" || Array.isArray(yamlStuff)) {
throw new Error(`could not parse changeset - frontmatter must be an object mapping package names to version types.\n` + `Expected format:\n${EXAMPLE_FORMAT}\n` + `Received:\n${roughReleases}`);
}
releases = Object.entries(yamlStuff).map(([name, type]) => ({
name,
type
}));
} else {
releases = [];
}
validateReleases(releases, contents);
return {
releases,
summary
};
}
/** @deprecated Use named export `parseChangesetFile` instead */
const parseChangesetFileDefault = parseChangesetFile;
export { parseChangesetFileDefault as default, parseChangesetFile };
import type { Release } from "@changesets/types";
export declare function parseChangesetFile(contents: string): {
summary: string;
releases: Release[];
};
/** @deprecated Use named export `parseChangesetFile` instead */
declare const parseChangesetFileDefault: typeof parseChangesetFile;
export default parseChangesetFileDefault;