Skip to content

Commit f1a1f5a

Browse files
authored
Merge branch 'master' into publish-subdirectory
2 parents 35545a4 + dca4a91 commit f1a1f5a

16 files changed

Lines changed: 218 additions & 108 deletions

File tree

‎.changeset/modern-ligers-fetch.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@changesets/cli": minor
3+
---
4+
5+
Open an editor when no message is given when creating a changeset

‎package.json‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,24 +40,24 @@
4040
"@types/js-yaml": "^3.12.1",
4141
"@types/lodash": "^4.14.136",
4242
"@types/meow": "^5.0.0",
43-
"@types/prettier": "^1.18.3",
43+
"@types/prettier": "^1.19.1",
4444
"@types/semver": "^6.0.0",
4545
"@typescript-eslint/eslint-plugin": "^3.5.0",
4646
"@typescript-eslint/parser": "^3.5.0",
4747
"codecov": "^3.6.5",
4848
"eslint": "^6.6.0",
49-
"eslint-config-prettier": "^6.5.0",
49+
"eslint-config-prettier": "^6.11.0",
5050
"eslint-config-standard": "^14.1.0",
5151
"eslint-plugin-import": "^2.18.2",
5252
"eslint-plugin-jest": "^23.0.2",
5353
"eslint-plugin-node": "^10.0.0",
54-
"eslint-plugin-prettier": "^3.1.1",
54+
"eslint-plugin-prettier": "^3.1.4",
5555
"eslint-plugin-promise": "^4.2.1",
5656
"eslint-plugin-standard": "^4.0.1",
5757
"jest": "^24.7.1",
5858
"jest-junit": "^6.4.0",
5959
"jest-watch-typeahead": "^0.4.2",
60-
"prettier": "^1.18.2",
60+
"prettier": "^1.19.1",
6161
"typescript": "^3.9.6"
6262
},
6363
"preconstruct": {

‎packages/apply-release-plan/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"fs-extra": "^7.0.1",
1717
"lodash.startcase": "^4.4.0",
1818
"outdent": "^0.5.0",
19-
"prettier": "^1.18.2",
19+
"prettier": "^1.19.1",
2020
"resolve-from": "^5.0.0",
2121
"semver": "^5.4.1"
2222
},

‎packages/assemble-release-plan/src/index.test.ts‎

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,13 @@ describe("assemble-release-plan", () => {
239239
let { releases } = assembleReleasePlan(
240240
setup.changesets,
241241
setup.packages,
242-
{ ...defaultConfig, linked: [["pkg-a", "pkg-b"], ["pkg-c", "pkg-d"]] },
242+
{
243+
...defaultConfig,
244+
linked: [
245+
["pkg-a", "pkg-b"],
246+
["pkg-c", "pkg-d"]
247+
]
248+
},
243249
undefined
244250
);
245251

@@ -253,7 +259,13 @@ describe("assemble-release-plan", () => {
253259
let { releases } = assembleReleasePlan(
254260
[],
255261
setup.packages,
256-
{ ...defaultConfig, linked: [["pkg-a", "pkg-b"], ["pkg-c", "pkg-d"]] },
262+
{
263+
...defaultConfig,
264+
linked: [
265+
["pkg-a", "pkg-b"],
266+
["pkg-c", "pkg-d"]
267+
]
268+
},
257269
undefined
258270
);
259271

@@ -266,7 +278,13 @@ describe("assemble-release-plan", () => {
266278
let { releases } = assembleReleasePlan(
267279
setup.changesets,
268280
setup.packages,
269-
{ ...defaultConfig, linked: [["pkg-a", "pkg-b"], ["pkg-c", "pkg-d"]] },
281+
{
282+
...defaultConfig,
283+
linked: [
284+
["pkg-a", "pkg-b"],
285+
["pkg-c", "pkg-d"]
286+
]
287+
},
270288
undefined
271289
);
272290

@@ -285,7 +303,13 @@ describe("assemble-release-plan", () => {
285303
let { releases } = assembleReleasePlan(
286304
setup.changesets,
287305
setup.packages,
288-
{ ...defaultConfig, linked: [["pkg-a", "pkg-b"], ["pkg-c", "pkg-d"]] },
306+
{
307+
...defaultConfig,
308+
linked: [
309+
["pkg-a", "pkg-b"],
310+
["pkg-c", "pkg-d"]
311+
]
312+
},
289313
undefined
290314
);
291315

‎packages/changelog-github/src/index.ts‎

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,19 @@ const changelogFunctions: ChangelogFunctions = {
1818
}
1919
if (dependenciesUpdated.length === 0) return "";
2020

21-
const changesetLink = `- Updated dependencies [${(await Promise.all(
22-
changesets.map(async cs => {
23-
if (cs.commit) {
24-
let { links } = await getInfo({
25-
repo: options.repo,
26-
commit: cs.commit
27-
});
28-
return links.commit;
29-
}
30-
})
31-
))
21+
const changesetLink = `- Updated dependencies [${(
22+
await Promise.all(
23+
changesets.map(async cs => {
24+
if (cs.commit) {
25+
let { links } = await getInfo({
26+
repo: options.repo,
27+
commit: cs.commit
28+
});
29+
return links.commit;
30+
}
31+
})
32+
)
33+
)
3234
.filter(_ => _)
3335
.join(", ")}]:`;
3436

‎packages/cli/package.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
"boxen": "^1.3.0",
4242
"chalk": "^2.1.0",
4343
"enquirer": "^2.3.0",
44+
"external-editor": "^3.1.0",
4445
"fs-extra": "^7.0.1",
4546
"human-id": "^1.0.2",
4647
"is-ci": "^2.0.0",

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

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import writeChangeset from "@changesets/write";
88
import {
99
askCheckboxPlus,
1010
askConfirm,
11+
askQuestionWithEditor,
1112
askQuestion,
1213
askList
1314
} from "../../../utils/cli-utilities";
@@ -58,8 +59,21 @@ const mockUserResponses = mockResponses => {
5859
let confirmAnswers = {
5960
"Is this your desired changeset?": true
6061
};
61-
// @ts-ignore
62-
askQuestion.mockReturnValueOnce(summary);
62+
63+
if (mockResponses.consoleSummaries && mockResponses.editorSummaries) {
64+
let i = 0;
65+
let j = 0;
66+
// @ts-ignore
67+
askQuestion.mockImplementation(() => mockResponses.consoleSummaries[i++]);
68+
// @ts-ignore
69+
askQuestionWithEditor.mockImplementation(
70+
() => mockResponses.editorSummaries[j++]
71+
);
72+
} else {
73+
// @ts-ignore
74+
askQuestion.mockReturnValueOnce(summary);
75+
}
76+
6377
// @ts-ignore
6478
askConfirm.mockImplementation(question => {
6579
question = stripAnsi(question);
@@ -89,6 +103,36 @@ describe("Changesets", () => {
89103
const call = writeChangeset.mock.calls[0][0];
90104
expect(call).toEqual(expectedChangeset);
91105
});
106+
107+
it.each`
108+
consoleSummaries | editorSummaries | expectedSummary
109+
${["summary on step 1"]} | ${[]} | ${"summary on step 1"}
110+
${[""]} | ${["summary in external editor"]} | ${"summary in external editor"}
111+
${[""]} | ${["", "", "summary in external editor"]} | ${"summary in external editor"}
112+
${["", "summary after error"]} | ${1 /* mock implementation will throw */} | ${"summary after error"}
113+
`(
114+
"should read summary",
115+
// @ts-ignore
116+
async ({ consoleSummaries, editorSummaries, expectedSummary }) => {
117+
const cwd = await f.copy("simple-project");
118+
119+
mockUserResponses({
120+
releases: { "pkg-a": "patch" },
121+
consoleSummaries,
122+
editorSummaries
123+
});
124+
await addChangeset(cwd, { empty: false }, defaultConfig);
125+
126+
const expectedChangeset = {
127+
summary: expectedSummary,
128+
releases: [{ name: "pkg-a", type: "patch" }]
129+
};
130+
// @ts-ignore
131+
const call = writeChangeset.mock.calls[0][0];
132+
expect(call).toEqual(expectedChangeset);
133+
}
134+
);
135+
92136
it("should generate a changeset in a single package repo", async () => {
93137
const cwd = await f.copy("single-package");
94138

@@ -101,7 +145,9 @@ describe("Changesets", () => {
101145
"Is this your desired changeset?": true
102146
};
103147
// @ts-ignore
104-
askQuestion.mockReturnValueOnce(summary);
148+
askQuestion.mockReturnValueOnce("");
149+
// @ts-ignore
150+
askQuestionWithEditor.mockReturnValueOnce(summary);
105151
// @ts-ignore
106152
askConfirm.mockImplementation(question => {
107153
question = stripAnsi(question);

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

Lines changed: 70 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -114,56 +114,13 @@ export default async function createChangeset(
114114

115115
let pkgsLeftToGetBumpTypeFor = new Set(packagesToRelease);
116116

117-
let pkgsThatShouldBeMajorBumped = (await cli.askCheckboxPlus(
118-
bold(`Which packages should have a ${red("major")} bump?`),
119-
[
120-
{
121-
name: "all packages",
122-
choices: packagesToRelease.map(pkgName => {
123-
return {
124-
name: pkgName,
125-
message: formatPkgNameAndVersion(
126-
pkgName,
127-
pkgJsonsByName.get(pkgName)!.version
128-
)
129-
};
130-
})
131-
}
132-
],
133-
x => {
134-
// this removes changed packages and unchanged packages from the list
135-
// of packages shown after selection
136-
if (Array.isArray(x)) {
137-
return x
138-
.filter(x => x !== "all packages")
139-
.map(x => cyan(x))
140-
.join(", ");
141-
}
142-
return x;
143-
}
144-
)).filter(x => x !== "all packages");
145-
146-
for (const pkgName of pkgsThatShouldBeMajorBumped) {
147-
// for packages that are under v1, we want to make sure major releases are intended,
148-
// as some repo-wide sweeping changes have mistakenly release first majors
149-
// of packages.
150-
let pkgJson = pkgJsonsByName.get(pkgName)!;
151-
152-
let shouldReleaseFirstMajor = await confirmMajorRelease(pkgJson);
153-
if (shouldReleaseFirstMajor) {
154-
pkgsLeftToGetBumpTypeFor.delete(pkgName);
155-
156-
releases.push({ name: pkgName, type: "major" });
157-
}
158-
}
159-
160-
if (pkgsLeftToGetBumpTypeFor.size !== 0) {
161-
let pkgsThatShouldBeMinorBumped = (await cli.askCheckboxPlus(
162-
bold(`Which packages should have a ${green("minor")} bump?`),
117+
let pkgsThatShouldBeMajorBumped = (
118+
await cli.askCheckboxPlus(
119+
bold(`Which packages should have a ${red("major")} bump?`),
163120
[
164121
{
165122
name: "all packages",
166-
choices: [...pkgsLeftToGetBumpTypeFor].map(pkgName => {
123+
choices: packagesToRelease.map(pkgName => {
167124
return {
168125
name: pkgName,
169126
message: formatPkgNameAndVersion(
@@ -185,7 +142,54 @@ export default async function createChangeset(
185142
}
186143
return x;
187144
}
188-
)).filter(x => x !== "all packages");
145+
)
146+
).filter(x => x !== "all packages");
147+
148+
for (const pkgName of pkgsThatShouldBeMajorBumped) {
149+
// for packages that are under v1, we want to make sure major releases are intended,
150+
// as some repo-wide sweeping changes have mistakenly release first majors
151+
// of packages.
152+
let pkgJson = pkgJsonsByName.get(pkgName)!;
153+
154+
let shouldReleaseFirstMajor = await confirmMajorRelease(pkgJson);
155+
if (shouldReleaseFirstMajor) {
156+
pkgsLeftToGetBumpTypeFor.delete(pkgName);
157+
158+
releases.push({ name: pkgName, type: "major" });
159+
}
160+
}
161+
162+
if (pkgsLeftToGetBumpTypeFor.size !== 0) {
163+
let pkgsThatShouldBeMinorBumped = (
164+
await cli.askCheckboxPlus(
165+
bold(`Which packages should have a ${green("minor")} bump?`),
166+
[
167+
{
168+
name: "all packages",
169+
choices: [...pkgsLeftToGetBumpTypeFor].map(pkgName => {
170+
return {
171+
name: pkgName,
172+
message: formatPkgNameAndVersion(
173+
pkgName,
174+
pkgJsonsByName.get(pkgName)!.version
175+
)
176+
};
177+
})
178+
}
179+
],
180+
x => {
181+
// this removes changed packages and unchanged packages from the list
182+
// of packages shown after selection
183+
if (Array.isArray(x)) {
184+
return x
185+
.filter(x => x !== "all packages")
186+
.map(x => cyan(x))
187+
.join(", ");
188+
}
189+
return x;
190+
}
191+
)
192+
).filter(x => x !== "all packages");
189193

190194
for (const pkgName of pkgsThatShouldBeMinorBumped) {
191195
pkgsLeftToGetBumpTypeFor.delete(pkgName);
@@ -225,13 +229,27 @@ export default async function createChangeset(
225229
}
226230

227231
log(
228-
"Please enter a summary for this change (this will be in the changelogs)"
232+
"Please enter a summary for this change (this will be in the changelogs). Submit empty line to open external editor"
229233
);
230234

231235
let summary = await cli.askQuestion("Summary");
232-
while (summary.length === 0) {
233-
error("A summary is required for the changelog! 😪");
234-
summary = await cli.askQuestion("Summary");
236+
if (summary.length === 0) summary = cli.askQuestionWithEditor("");
237+
try {
238+
while (summary.length === 0) {
239+
summary = await cli.askQuestionWithEditor(
240+
"\n\n# A summary is required for the changelog! 😪"
241+
);
242+
}
243+
} catch (err) {
244+
log(
245+
"An error happened using external editor. Please type your summary here:"
246+
);
247+
summary = await cli.askQuestion("");
248+
while (summary.length === 0) {
249+
summary = await cli.askQuestion(
250+
"\n\n# A summary is required for the changelog! 😪"
251+
);
252+
}
235253
}
236254

237255
return {

‎packages/cli/src/commands/pre/index.test.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ describe("exitPre", () => {
6363
);
6464
await pre(cwd, { command: "exit" });
6565

66-
expect(await fs.readJson(path.join(cwd, ".changeset", "pre.json"))).toEqual(
67-
{ ...preStateForSimpleProject, mode: "exit" }
68-
);
66+
expect(
67+
await fs.readJson(path.join(cwd, ".changeset", "pre.json"))
68+
).toEqual({ ...preStateForSimpleProject, mode: "exit" });
6969
});
7070
it("should throw if not in pre", async () => {
7171
let cwd = f.copy("simple-project");

‎packages/cli/src/commands/status/__tests__/status.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ const f = fixtures(__dirname);
1717
const simpleChangeset: NewChangeset = {
1818
id: "fake-ids-abound",
1919
summary: "This is a summary",
20-
releases: [{ name: "pkg-a", type: "minor" }, { name: "pkg-b", type: "patch" }]
20+
releases: [
21+
{ name: "pkg-a", type: "minor" },
22+
{ name: "pkg-b", type: "patch" }
23+
]
2124
};
2225

2326
const simpleReleasePlan: ReleasePlan = {

0 commit comments

Comments
 (0)