Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change default baseBranch in changeset init from master to main #776

Merged
merged 4 commits into from
Mar 12, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/funny-cooks-clap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@changesets/cli": patch
---

Change default `baseBranch` in `changeset init` from `master` to `main`.
Andarist marked this conversation as resolved.
Show resolved Hide resolved
6 changes: 3 additions & 3 deletions packages/cli/src/commands/init/__tests__/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ describe("init", () => {
true
);
await initializeCommand(cwd);
expect(await fs.readJson(path.join(cwd, ".changeset/config.json"))).toEqual(
defaultWrittenConfig
);
expect(
await fs.readJson(path.join(cwd, ".changeset/config.json"))
).toEqual({ ...defaultWrittenConfig, baseBranch: "main" });
});
it("shouldn't overwrite a config if it does exist", async () => {
const cwd = await f.copy("simple-project");
Expand Down
12 changes: 10 additions & 2 deletions packages/cli/src/commands/init/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ import { info, log, warn, error } from "@changesets/logger";

const pkgPath = path.dirname(require.resolve("@changesets/cli/package.json"));

// Modify base branch to "main" without changing defaultWrittenConfig since it also serves as a fallback
// for config files that don't specify a base branch. Changing that to main would be a breaking change.
const defaultConfig = JSON.stringify(
{ ...defaultWrittenConfig, baseBranch: "main" },
null,
2
);

export default async function init(cwd: string) {
const changesetBase = path.resolve(cwd, ".changeset");

Expand All @@ -33,7 +41,7 @@ export default async function init(cwd: string) {
}
await fs.writeFile(
path.resolve(changesetBase, "config.json"),
JSON.stringify(defaultWrittenConfig, null, 2)
defaultConfig
);
} else {
warn(
Expand All @@ -44,7 +52,7 @@ export default async function init(cwd: string) {
await fs.copy(path.resolve(pkgPath, "./default-files"), changesetBase);
await fs.writeFile(
path.resolve(changesetBase, "config.json"),
JSON.stringify(defaultWrittenConfig, null, 2)
defaultConfig
);

log(
Expand Down