How Changsets reads config.json internally

thinkthroo

thinkThroo

Posted on November 22, 2024

How Changsets reads config.json internally

When you initialise Changesets via the CLI using init command, this command sets up the .changeset folder. It generates a readme and a config file. The config file includes the default options, as well as comments

on what these options represent.

The default config.json generated by init command looks like below:

{
 "commit": false,
 "updateInternalDependencies": "patch",
 "linked": [],
 "access": "restricted",
 "baseBranch": "master",
 "ignore": [],
 "changelog": "@changesets/cli/changelog"
}
Enter fullscreen mode Exit fullscreen mode

Read more about config.json here.

Now that we understand what a config.json is for in using Changesets, let’s look at how CLI package reads this config.json.

In the run function, this try catch block is found:

try {
 config = await read(cwd, packages);
} catch (e) {
 let oldConfigExists = await fs.pathExists(
 path.resolve(cwd, ".changeset/config.js")
 );
Enter fullscreen mode Exit fullscreen mode

read function is part of another package named config.

Image description

As you can see from the above image, fs.readJSON is used in combination with path.join that combines cwd + .changesets + “config.json”

Image description

parse accepts this config.json read as its first argument and this parse function is a really long function that performs additional operations using this json and packages (second argument).

About us:

At Thinkthroo, we study large open source projects and provide architectural guides. We have developed reusable Components, built with tailwind, that you can use in your project. We offer Next.js, React and Node development services.

Book a meeting with us to discuss your project.

Image description

References:

  1. https://github.com/changesets/changesets/blob/main/packages/cli/src/run.ts#L29

  2. https://github.com/changesets/changesets/blob/main/packages/cli/src/run.ts#L44

  3. https://github.com/changesets/changesets/blob/main/packages/config/src/index.ts#L94

  4. https://github.com/changesets/changesets/blob/main/docs/config-file-options.md

  5. https://github.com/changesets/changesets/blob/main/packages/cli/README.md

💖 💪 🙅 🚩
thinkthroo
thinkThroo

Posted on November 22, 2024

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

How Changsets reads config.json internally
javascript How Changsets reads config.json internally

November 22, 2024