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 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.
References:
-
https://github.com/changesets/changesets/blob/main/packages/cli/src/run.ts#L29
-
https://github.com/changesets/changesets/blob/main/packages/cli/src/run.ts#L44
-
https://github.com/changesets/changesets/blob/main/packages/config/src/index.ts#L94
-
https://github.com/changesets/changesets/blob/main/docs/config-file-options.md
-
https://github.com/changesets/changesets/blob/main/packages/cli/README.md