MCPcopy
hub / github.com/changesets/changesets / version

Function version

packages/cli/src/commands/version/index.ts:25–119  ·  view source on GitHub ↗
(
  cwd: string,
  options: {
    snapshot?: string | boolean;
  },
  config: Config
)

Source from the content-addressed store, hash-verified

23);
24
25export default async function version(
26 cwd: string,
27 options: {
28 snapshot?: string | boolean;
29 },
30 config: Config
31) {
32 const releaseConfig = {
33 ...config,
34 // Disable committing when in snapshot mode
35 commit: options.snapshot ? false : config.commit,
36 };
37 const [changesets, preState] = await Promise.all([
38 readChangesets(cwd),
39 readPreState(cwd),
40 removeEmptyFolders(path.resolve(cwd, ".changeset")),
41 ]);
42
43 if (preState?.mode === "pre") {
44 warn(importantSeparator);
45 if (options.snapshot !== undefined) {
46 error("Snapshot release is not allowed in pre mode");
47 log("To resolve this exit the pre mode by running `changeset pre exit`");
48 throw new ExitError(1);
49 } else {
50 warn("You are in prerelease mode");
51 warn(
52 "If you meant to do a normal release you should revert these changes and run `changeset pre exit`"
53 );
54 warn("You can then run `changeset version` again to do a normal release");
55 }
56 warn(importantEnd);
57 }
58
59 if (
60 changesets.length === 0 &&
61 (preState === undefined || preState.mode !== "exit")
62 ) {
63 warn("No unreleased changesets found, exiting.");
64 return;
65 }
66
67 let packages = await getPackages(cwd);
68
69 let releasePlan = assembleReleasePlan(
70 changesets,
71 packages,
72 releaseConfig,
73 preState,
74 options.snapshot
75 ? {
76 tag: options.snapshot === true ? undefined : options.snapshot,
77 commit: config.snapshot.prereleaseTemplate?.includes("{commit}")
78 ? await getCurrentCommitId({ cwd })
79 : undefined,
80 }
81 : undefined
82 );

Callers 2

runFunction · 0.85
version.test.tsFile · 0.85

Calls 10

readPreStateFunction · 0.90
removeEmptyFoldersFunction · 0.90
warnFunction · 0.90
errorFunction · 0.90
logFunction · 0.90
getCurrentCommitIdFunction · 0.90
getCommitFunctionsFunction · 0.90
assembleReleasePlanFunction · 0.85
applyReleasePlanFunction · 0.85
getVersionMessageFunction · 0.85

Tested by

no test coverage detected