MCPcopy Create free account
hub / github.com/remix-run/react-router / parseChangeset

Function parseChangeset

scripts/changes/migrate-changesets.ts:53–86  ·  view source on GitHub ↗
(content: string)

Source from the content-addressed store, hash-verified

51}
52
53function parseChangeset(content: string): ParsedChangeset | null {
54 // Changeset files start and end frontmatter with "---"
55 if (!content.startsWith("---")) {
56 return null;
57 }
58
59 let closingIndex = content.indexOf("\n---", 3);
60 if (closingIndex === -1) {
61 return null;
62 }
63
64 let frontmatter = content.slice(3, closingIndex).trim();
65 let description = content.slice(closingIndex + 4).trim();
66
67 let packages = new Map<string, string>();
68
69 for (let line of frontmatter.split("\n")) {
70 line = line.trim();
71 if (!line) continue;
72
73 // Lines look like: "package-name": bump
74 // The package name may be quoted with double quotes.
75 let match = line.match(/^"([^"]+)":\s*(\S+)$/);
76 if (!match) {
77 console.warn(` ⚠️ Could not parse frontmatter line: ${line}`);
78 continue;
79 }
80
81 let [, packageName, bump] = match;
82 packages.set(packageName, bump);
83 }
84
85 return { packages, description };
86}
87
88/**
89 * Returns a markdown link to the PR or commit that introduced the given file.

Callers 1

mainFunction · 0.85

Calls 1

setMethod · 0.65

Tested by

no test coverage detected