Blog
How Changsets reads config.json internally

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"
}

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")
 );

read function is part of another package named config.

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

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 me:

Hey, my name is Ramu Narasinga. I study large open-source projects and create content about their codebase architecture and best practices, sharing it through articles, videos.

I am open to work on interesting projects. Send me an email at ramu.narasinga@gmail.com

My Github — https://github.com/ramu-narasinga

My website — https://ramunarasinga.com

My Youtube channel — https://www.youtube.com/@thinkthroo

Learning platform — https://thinkthroo.com

Codebase Architecture — https://app.thinkthroo.com/architecture

Best practices — https://app.thinkthroo.com/best-practices

Production-grade projects — https://app.thinkthroo.com/production-grade-projects

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