Skip to content

Commit

Permalink
Add a new line at the end of the default config file generated when i…
Browse files Browse the repository at this point in the history
…nvoking `changeset init` (#953)

* test: add newline at the end case

* feat: add newline at the end of the config file

* chore: add changeset

* Update .changeset/hungry-spiders-check.md

* Update .changeset/hungry-spiders-check.md

Co-authored-by: Mateusz Burzyński <[email protected]>
  • Loading branch information
alexamy and Andarist authored Sep 20, 2022
1 parent 911f314 commit 98d63e0
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/hungry-spiders-check.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@changesets/cli": patch
---

Add a new line at the end of the default config file generated when invoking `changeset init`.
12 changes: 12 additions & 0 deletions packages/cli/src/commands/init/__tests__/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,18 @@ describe("init", () => {
{ ...defaultWrittenConfig, baseBranch: "main" }
);
});
it("should add newline at the end of config", async () => {
const cwd = await f.copy("simple-project");
await fs.remove(path.join(cwd, ".changeset/config.json"));

await initializeCommand(cwd);

const configPath = path.join(cwd, ".changeset/config.json");
const config = (await fs.promises.readFile(configPath)).toString();
const lastCharacter = config.slice(-1);

expect(lastCharacter).toBe("\n");
});
it("shouldn't overwrite a config if it does exist", async () => {
const cwd = await f.copy("simple-project");
await fs.writeJson(path.join(cwd, ".changeset/config.json"), {
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/commands/init/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ 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(
const defaultConfig = `${JSON.stringify(
{ ...defaultWrittenConfig, baseBranch: "main" },
null,
2
);
)}\n`;

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

0 comments on commit 98d63e0

Please sign in to comment.