Remove add changeset confirmation (#2136) · changesets/changesets@2f9ca42 · GitHub
Skip to content

Commit 2f9ca42

Browse files
authored
Remove add changeset confirmation (#2136)
* Remove add changeset confirmation * Fix tests
1 parent 369eb0b commit 2f9ca42

4 files changed

Lines changed: 60 additions & 180 deletions

File tree

‎.changeset/red-coats-create.md‎

Lines changed: 5 additions & 0 deletions

‎packages/cli/src/commands/add/__tests__/add.test.ts‎

Lines changed: 0 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,6 @@ const mockUserResponses = (mockResponses: {
5050
return returnValues[callCount++];
5151
});
5252

53-
const confirmAnswers: Record<string, boolean> = {
54-
"Is this your desired changeset?": true,
55-
};
56-
5753
if (
5854
mockResponses.consoleSummaries != null &&
5955
mockResponses.editorSummaries != null
@@ -75,13 +71,6 @@ const mockUserResponses = (mockResponses: {
7571
} else {
7672
mockedUtils.askQuestion.mockResolvedValue(summary);
7773
}
78-
mockedUtils.askConfirm.mockImplementation(async (question) => {
79-
question = stripVTControlCharacters(question);
80-
if (confirmAnswers[question]) {
81-
return confirmAnswers[question];
82-
}
83-
throw new Error(`An answer could not be found for ${question}`);
84-
});
8574
};
8675

8776
beforeEach(() => {
@@ -183,18 +172,8 @@ describe("Add command", () => {
183172
const summary = "summary message mock";
184173
mockedUtils.askList.mockResolvedValueOnce("minor");
185174

186-
const confirmAnswers: Record<string, boolean> = {
187-
"Is this your desired changeset?": true,
188-
};
189175
mockedUtils.askQuestion.mockResolvedValue("");
190176
mockedAskWithEditor.mockResolvedValueOnce(summary);
191-
mockedUtils.askConfirm.mockImplementation(async (question) => {
192-
question = stripVTControlCharacters(question);
193-
if (confirmAnswers[question]) {
194-
return confirmAnswers[question];
195-
}
196-
throw new Error(`An answer could not be found for ${question}`);
197-
});
198177

199178
await addChangeset({ cwd });
200179

@@ -292,7 +271,6 @@ describe("Add command", () => {
292271
});
293272

294273
mockedUtils.askList.mockReturnValueOnce(Promise.resolve("minor"));
295-
mockedUtils.askConfirm.mockReturnValueOnce(Promise.resolve(true));
296274

297275
await addChangeset({ cwd, message: "summary from message" });
298276

@@ -304,9 +282,6 @@ describe("Add command", () => {
304282
releases: [{ name: "single-package", type: "minor" }],
305283
}),
306284
);
307-
expect(mockedUtils.askConfirm).toHaveBeenCalledWith(
308-
"Is this your desired changeset?",
309-
);
310285
expect(mockedUtils.askQuestion).not.toHaveBeenCalled();
311286
expect(mockedAskWithEditor).not.toHaveBeenCalled();
312287
});
@@ -322,7 +297,6 @@ describe("Add command", () => {
322297
});
323298

324299
mockedUtils.askList.mockReturnValueOnce(Promise.resolve("patch"));
325-
mockedUtils.askConfirm.mockReturnValueOnce(Promise.resolve(true));
326300

327301
await addChangeset({ cwd, message: "" });
328302

@@ -368,84 +342,10 @@ describe("Add command", () => {
368342
releases: [{ name: "pkg-a", type: "patch" }],
369343
}),
370344
);
371-
expect(mockedUtils.askConfirm).toHaveBeenCalledWith(
372-
"Is this your desired changeset?",
373-
);
374-
expect(mockedUtils.askQuestion).not.toHaveBeenCalled();
375-
expect(mockedAskWithEditor).not.toHaveBeenCalled();
376-
});
377-
378-
it("should skip confirmation when release type flags and message are passed", async () => {
379-
const cwd = await testdir({
380-
"package.json": JSON.stringify({
381-
private: true,
382-
workspaces: ["packages/*"],
383-
}),
384-
"package-lock.json": "",
385-
"packages/pkg-a/package.json": JSON.stringify({
386-
name: "pkg-a",
387-
version: "1.0.0",
388-
}),
389-
".changeset/config.json": JSON.stringify(defaultConfig),
390-
});
391-
392-
await addChangeset({
393-
cwd,
394-
message: "summary from message",
395-
patch: ["pkg-a"],
396-
});
397-
398-
const changesets = await getChangesets(cwd);
399-
expect(changesets.length).toBe(1);
400-
expect(changesets[0]).toEqual(
401-
expect.objectContaining({
402-
summary: "summary from message",
403-
releases: [{ name: "pkg-a", type: "patch" }],
404-
}),
405-
);
406-
expect(mockedUtils.askConfirm).not.toHaveBeenCalled();
407345
expect(mockedUtils.askQuestion).not.toHaveBeenCalled();
408-
expect(mockedUtils.askMultiselect).not.toHaveBeenCalled();
409346
expect(mockedAskWithEditor).not.toHaveBeenCalled();
410347
});
411348

412-
it("should keep confirmation flow when only release type flags are passed", async () => {
413-
const cwd = await testdir({
414-
"package.json": JSON.stringify({
415-
private: true,
416-
workspaces: ["packages/*"],
417-
}),
418-
"package-lock.json": "",
419-
"packages/pkg-a/package.json": JSON.stringify({
420-
name: "pkg-a",
421-
version: "1.0.0",
422-
}),
423-
".changeset/config.json": JSON.stringify(defaultConfig),
424-
});
425-
426-
mockedUtils.askQuestion.mockResolvedValue("summary from prompt");
427-
mockedUtils.askConfirm.mockResolvedValue(true);
428-
429-
await addChangeset({
430-
cwd,
431-
patch: ["pkg-a"],
432-
});
433-
434-
const changesets = await getChangesets(cwd);
435-
expect(changesets.length).toBe(1);
436-
expect(changesets[0]).toEqual(
437-
expect.objectContaining({
438-
summary: "summary from prompt",
439-
releases: [{ name: "pkg-a", type: "patch" }],
440-
}),
441-
);
442-
expect(mockedUtils.askConfirm).toHaveBeenCalledWith(
443-
"Is this your desired changeset?",
444-
);
445-
expect(mockedUtils.askQuestion).toHaveBeenCalledOnce();
446-
expect(mockedUtils.askMultiselect).not.toHaveBeenCalled();
447-
});
448-
449349
it("should allow using message with empty changesets", async () => {
450350
const cwd = await testdir({
451351
"package.json": JSON.stringify({

‎packages/cli/src/commands/add/createChangeset.ts‎

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -137,13 +137,10 @@ export async function createChangeset(
137137
changedPackages: Array<string>,
138138
allPackages: Array<Package>,
139139
optionsFromCli?: OptionsFromCli,
140-
): Promise<{ confirmed: boolean; summary: string; releases: Array<Release> }> {
140+
): Promise<{ summary: string; releases: Array<Release> }> {
141141
const releases: Array<Release> = [];
142142

143-
let confirmed = false;
144-
145143
if (optionsFromCli?.major || optionsFromCli?.minor || optionsFromCli?.patch) {
146-
confirmed = true;
147144
const pkgNames = new Set(
148145
allPackages.map(({ packageJson }) => packageJson.name),
149146
);
@@ -266,14 +263,11 @@ ${c.gray(patchBumpedPackages.join(", "))}
266263

267264
if (optionsFromCli?.message != null) {
268265
return {
269-
confirmed,
270266
summary: optionsFromCli.message,
271267
releases,
272268
};
273269
}
274270

275-
confirmed = false;
276-
277271
let summary = await cli.askQuestion(
278272
"Please enter a summary for this change (this will be in the changelogs).",
279273
{ placeholder: " (submit nothing to open an external editor)" },
@@ -285,11 +279,7 @@ ${c.gray(patchBumpedPackages.join(", "))}
285279
"\n\n# Please enter a summary for your changes.\n# An empty message aborts the editor.",
286280
);
287281
if (summary.length > 0) {
288-
return {
289-
confirmed: true,
290-
summary,
291-
releases,
292-
};
282+
return { summary, releases };
293283
}
294284
} catch {
295285
summary = await cli.askQuestion(
@@ -306,9 +296,5 @@ ${c.gray(patchBumpedPackages.join(", "))}
306296
);
307297
}
308298

309-
return {
310-
confirmed,
311-
summary,
312-
releases,
313-
};
299+
return { summary, releases };
314300
}

‎packages/cli/src/commands/add/index.ts‎

Lines changed: 52 additions & 63 deletions

0 commit comments

Comments
 (0)