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

Fix(cli): add last newline in the end of default config #953

Merged
merged 5 commits into from Sep 20, 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/hungry-spiders-check.md
@@ -0,0 +1,5 @@
---
"@changesets/cli": patch
---

Add newline at the end of the default config file.
Andarist marked this conversation as resolved.
Show resolved Hide resolved
12 changes: 12 additions & 0 deletions packages/cli/src/commands/init/__tests__/command.ts
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
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