Skip to content

Commit

Permalink
Don't reopen an editor that is saved without summary (#518)
Browse files Browse the repository at this point in the history
* fix: don't reopen an editor that is saved without summary

close #445

* Update .changeset/happy-goats-remember.md

Co-authored-by: Mateusz Burzy艅ski <mateuszburzynski@gmail.com>
  • Loading branch information
zkochan and Andarist committed Jan 21, 2021
1 parent b544b83 commit 0d5b9e1
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 14 deletions.
5 changes: 5 additions & 0 deletions .changeset/happy-goats-remember.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@changesets/cli": patch
---

From now on, to fix issues with some auto-save configurations in IDEs, the editor won't be re-opened if one saves an empty summary. In such a scenario the CLI will prompt again for the summary to be written in the terminal.
10 changes: 5 additions & 5 deletions packages/cli/src/commands/add/__tests__/add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,11 @@ describe("Changesets", () => {
});

it.each`
consoleSummaries | editorSummaries | expectedSummary
${["summary on step 1"]} | ${[]} | ${"summary on step 1"}
${[""]} | ${["summary in external editor"]} | ${"summary in external editor"}
${[""]} | ${["", "", "summary in external editor"]} | ${"summary in external editor"}
${["", "summary after error"]} | ${1 /* mock implementation will throw */} | ${"summary after error"}
consoleSummaries | editorSummaries | expectedSummary
${["summary on step 1"]} | ${[]} | ${"summary on step 1"}
${[""]} | ${["summary in external editor"]} | ${"summary in external editor"}
${["", "summary after editor cancelled"]} | ${[""]} | ${"summary after editor cancelled"}
${["", "summary after error"]} | ${1 /* mock implementation will throw */} | ${"summary after error"}
`(
"should read summary",
// @ts-ignore
Expand Down
24 changes: 15 additions & 9 deletions packages/cli/src/commands/add/createChangeset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,17 +232,23 @@ export default async function createChangeset(
);

let summary = await cli.askQuestion("Summary");
if (summary.length === 0) summary = cli.askQuestionWithEditor("");
try {
while (summary.length === 0) {
summary = await cli.askQuestionWithEditor(
"\n\n# A summary is required for the changelog! 馃槳"
if (summary.length === 0) {
try {
summary = cli.askQuestionWithEditor(
"\n\n# Please enter a summary for your changes.\n# An empty message aborts the editor."
);
if (summary.length > 0) {
return {
summary,
releases
};
}
} catch (err) {
log(
"An error happened using external editor. Please type your summary here:"
);
}
} catch (err) {
log(
"An error happened using external editor. Please type your summary here:"
);

summary = await cli.askQuestion("");
while (summary.length === 0) {
summary = await cli.askQuestion(
Expand Down

0 comments on commit 0d5b9e1

Please sign in to comment.