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

Function add

packages/cli/src/commands/add/index.ts:19–150  ·  view source on GitHub ↗
(
  cwd: string,
  {
    empty,
    open,
    since,
    message,
  }: { empty?: boolean; open?: boolean; since?: string; message?: string },
  config: Config
)

Source from the content-addressed store, hash-verified

17import printConfirmationMessage from "./messages";
18
19export default async function add(
20 cwd: string,
21 {
22 empty,
23 open,
24 since,
25 message,
26 }: { empty?: boolean; open?: boolean; since?: string; message?: string },
27 config: Config
28): Promise<void> {
29 const packages = await getPackages(cwd);
30 if (packages.packages.length === 0) {
31 error(
32 `No packages found. You might have ${packages.tool} workspaces configured but no packages yet?`
33 );
34 throw new ExitError(1);
35 }
36
37 const versionablePackages = packages.packages.filter(
38 (pkg) =>
39 !shouldSkipPackage(pkg, {
40 ignore: config.ignore,
41 allowPrivatePackages: config.privatePackages.version,
42 })
43 );
44
45 if (versionablePackages.length === 0) {
46 error("No versionable packages found");
47 error('- Ensure the packages to version are not in the "ignore" config');
48 error('- Ensure that relevant package.json files have the "version" field');
49 throw new ExitError(1);
50 }
51
52 const changesetBase = path.resolve(cwd, ".changeset");
53
54 let newChangeset: Awaited<ReturnType<typeof createChangeset>>;
55 if (empty) {
56 newChangeset = {
57 confirmed: true,
58 releases: [],
59 summary: message ?? "",
60 };
61 } else {
62 let changedPackagesNames: string[] = [];
63 try {
64 changedPackagesNames = (
65 await getVersionableChangedPackages(config, {
66 cwd,
67 ref: since,
68 })
69 ).map((pkg) => pkg.packageJson.name);
70 } catch (e: any) {
71 // NOTE: Getting the changed packages is best effort as it's only being used for easier selection
72 // in the CLI. So if any error happens while we try to do so, we only log a warning and continue
73 const branch = since ?? config.baseBranch;
74 warn(
75 `Failed to find changed packages from the "${branch}" ${
76 since ? "ref" : "base branch"

Callers 1

runFunction · 0.50

Calls 11

errorFunction · 0.90
shouldSkipPackageFunction · 0.90
warnFunction · 0.90
getCommitFunctionsFunction · 0.90
logFunction · 0.90
infoFunction · 0.90
createChangesetFunction · 0.85
printConfirmationMessageFunction · 0.85
writeChangesetFunction · 0.85
getAddMessageFunction · 0.85

Tested by

no test coverage detected