DEV Community

Ramu Narasinga
Ramu Narasinga

Posted on • Edited on • Originally published at thinkthroo.com

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 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 an interesting project. 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

Sentry blog image

How I fixed 20 seconds of lag for every user in just 20 minutes.

Our AI agent was running 10-20 seconds slower than it should, impacting both our own developers and our early adopters. See how I used Sentry Profiling to fix it in record time.

Read more

Top comments (0)

Heroku

This site is built on Heroku

Join the ranks of developers at Salesforce, Airbase, DEV, and more who deploy their mission critical applications on Heroku. Sign up today and launch your first app!

Get Started

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay