From 98d63e0a85506175e219b93478a814f8588c52d3 Mon Sep 17 00:00:00 2001 From: Alexander Chaschin Date: Tue, 20 Sep 2022 11:47:56 +0300 Subject: [PATCH] Add a new line at the end of the default config file generated when invoking `changeset init` (#953) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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 --- .changeset/hungry-spiders-check.md | 5 +++++ packages/cli/src/commands/init/__tests__/command.ts | 12 ++++++++++++ packages/cli/src/commands/init/index.ts | 4 ++-- 3 files changed, 19 insertions(+), 2 deletions(-) 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..d39a7e95a --- /dev/null +++ b/.changeset/hungry-spiders-check.md @@ -0,0 +1,5 @@ +--- +"@changesets/cli": patch +--- + +Add a new line at the end of the default config file generated when invoking `changeset init`. 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"), { 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");