MCPcopy Index your code
hub / github.com/changesets/changesets / writeChangeset

Function writeChangeset

packages/write/src/index.ts:18–60  ·  view source on GitHub ↗
(
  changeset: Changeset,
  rootDir: string,
  options?: { prettier?: boolean }
)

Source from the content-addressed store, hash-verified

16}
17
18async function writeChangeset(
19 changeset: Changeset,
20 rootDir: string,
21 options?: { prettier?: boolean }
22): Promise<string> {
23 const { summary, releases } = changeset;
24
25 const changesetBase = path.resolve(rootDir, ".changeset");
26
27 // Worth understanding that the ID merely needs to be a unique hash to avoid git conflicts
28 // experimenting with human readable ids to make finding changesets easier
29 const changesetID = humanId({
30 separator: "-",
31 capitalize: false,
32 });
33
34 const prettierInstance =
35 options?.prettier !== false ? getPrettierInstance(rootDir) : undefined;
36 const newChangesetPath = path.resolve(changesetBase, `${changesetID}.md`);
37
38 // NOTE: The quotation marks in here are really important even though they are
39 // not spec for yaml. This is because package names can contain special
40 // characters that will otherwise break the parsing step
41 const changesetContents = `---
42${releases.map((release) => `"${release.name}": ${release.type}`).join("\n")}
43---
44
45${summary}
46 `;
47
48 await fs.outputFile(
49 newChangesetPath,
50 prettierInstance
51 ? // Prettier v3 returns a promise
52 await prettierInstance.format(changesetContents, {
53 ...(await prettierInstance.resolveConfig(newChangesetPath)),
54 parser: "markdown",
55 })
56 : changesetContents
57 );
58
59 return changesetID;
60}
61
62export default writeChangeset;

Callers 9

index.test.tsFile · 0.85
run.test.tsFile · 0.85
writeChangesetsFunction · 0.85
version.test.tsFile · 0.85
addFunction · 0.85
status.tsFile · 0.85
index.test.tsFile · 0.85
writeChangesetsFunction · 0.85
index.test.tsFile · 0.85

Calls 1

getPrettierInstanceFunction · 0.70

Tested by 2

writeChangesetsFunction · 0.68
writeChangesetsFunction · 0.68