From e05880fb2f4abb7a9987e4144a1cf6d841a344a6 Mon Sep 17 00:00:00 2001 From: Alexander Chaschin Date: Tue, 20 Sep 2022 09:57:08 +0300 Subject: [PATCH 1/5] test: add newline at the end case --- packages/cli/src/commands/init/__tests__/command.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/packages/cli/src/commands/init/__tests__/command.ts b/packages/cli/src/commands/init/__tests__/command.ts index 65f460255..57dca15e5 100644 --- a/packages/cli/src/commands/init/__tests__/command.ts +++ b/packages/cli/src/commands/init/__tests__/command.ts @@ -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"), { From 61d31040991742ae5f4a28d222ae99b560750a00 Mon Sep 17 00:00:00 2001 From: Alexander Chaschin Date: Tue, 20 Sep 2022 09:57:42 +0300 Subject: [PATCH 2/5] feat: add newline at the end of the config file --- packages/cli/src/commands/init/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/cli/src/commands/init/index.ts b/packages/cli/src/commands/init/index.ts index 5e5757fc3..b29e61134 100644 --- a/packages/cli/src/commands/init/index.ts +++ b/packages/cli/src/commands/init/index.ts @@ -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"); From 3428bfc89f677f4edd3b4dabd87f81445ad65d58 Mon Sep 17 00:00:00 2001 From: Alexander Chaschin Date: Tue, 20 Sep 2022 10:07:22 +0300 Subject: [PATCH 3/5] chore: add changeset --- .changeset/hungry-spiders-check.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/hungry-spiders-check.md diff --git a/.changeset/hungry-spiders-check.md b/.changeset/hungry-spiders-check.md new file mode 100644 index 000000000..b29da64f6 --- /dev/null +++ b/.changeset/hungry-spiders-check.md @@ -0,0 +1,5 @@ +--- +"@changesets/cli": patch +--- + +Add newline at the end of the default config file. From 2b4777fdfb3539b90248db0f6458d3c4cc528057 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Burzy=C5=84ski?= Date: Tue, 20 Sep 2022 10:46:48 +0200 Subject: [PATCH 4/5] Update .changeset/hungry-spiders-check.md --- .changeset/hungry-spiders-check.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/hungry-spiders-check.md b/.changeset/hungry-spiders-check.md index b29da64f6..eee2b0c30 100644 --- a/.changeset/hungry-spiders-check.md +++ b/.changeset/hungry-spiders-check.md @@ -2,4 +2,4 @@ "@changesets/cli": patch --- -Add newline at the end of the default config file. +Add a new line at the end of the default config file when invoking `changeset init`. From ee6f766ebc8cfcd8dd56ad257ba94f9bf9c95719 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Burzy=C5=84ski?= Date: Tue, 20 Sep 2022 10:47:33 +0200 Subject: [PATCH 5/5] Update .changeset/hungry-spiders-check.md --- .changeset/hungry-spiders-check.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/hungry-spiders-check.md b/.changeset/hungry-spiders-check.md index eee2b0c30..d39a7e95a 100644 --- a/.changeset/hungry-spiders-check.md +++ b/.changeset/hungry-spiders-check.md @@ -2,4 +2,4 @@ "@changesets/cli": patch --- -Add a new line at the end of the default config file when invoking `changeset init`. +Add a new line at the end of the default config file generated when invoking `changeset init`.