Skip to content

Commit 8a71ac4

Browse files
ken-kenwareevocateur
authored andcommittedFeb 13, 2019
fix(publish): Make the missing license warning clearer and more actionable (#1921)
1 parent 5c1b84c commit 8a71ac4

File tree

2 files changed

+47
-2
lines changed

2 files changed

+47
-2
lines changed
 

‎commands/publish/__tests__/publish-licenses.test.js

+30-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ jest.mock("../../version/lib/is-anything-committed");
1111
jest.mock("../../version/lib/is-behind-upstream");
1212
jest.mock("../../version/lib/remote-branch-exists");
1313

14+
const fs = require("fs-extra");
1415
const path = require("path");
1516

1617
// mocked modules
@@ -70,9 +71,37 @@ describe("licenses", () => {
7071
await lernaPublish(cwd)();
7172

7273
const [warning] = loggingOutput("warn");
73-
expect(warning).toMatch("Packages package-1, package-3 are missing a license");
74+
expect(warning).toMatchInlineSnapshot(`
75+
"Packages package-1 and package-3 are missing a license.
76+
One way to fix this is to add a LICENSE.md file to the root of this repository.
77+
See https://choosealicense.com for additional guidance."
78+
`);
7479

7580
expect(createTempLicenses).toHaveBeenLastCalledWith(undefined, []);
7681
expect(removeTempLicenses).toHaveBeenLastCalledWith([]);
7782
});
83+
84+
it("warns when one package needs a license", async () => {
85+
const cwd = await initFixture("licenses");
86+
87+
// remove root license so warning is triggered
88+
await fs.remove(path.join(cwd, "LICENSE"));
89+
90+
await lernaPublish(cwd)();
91+
92+
const [warning] = loggingOutput("warn");
93+
expect(warning).toMatch("Package package-1 is missing a license.");
94+
});
95+
96+
it("warns when multiple packages need a license", async () => {
97+
const cwd = await initFixture("licenses-missing");
98+
99+
// simulate _all_ packages missing a license
100+
await fs.remove(path.join(cwd, "packages/package-2/LICENSE"));
101+
102+
await lernaPublish(cwd)();
103+
104+
const [warning] = loggingOutput("warn");
105+
expect(warning).toMatch("Packages package-1, package-2, and package-3 are missing a license.");
106+
});
78107
});

‎commands/publish/index.js

+17-1
Original file line numberDiff line numberDiff line change
@@ -378,9 +378,25 @@ class PublishCommand extends Command {
378378
.then(packagesWithoutLicense => {
379379
if (packagesWithoutLicense.length && !this.project.licensePath) {
380380
this.packagesToBeLicensed = [];
381+
382+
const names = packagesWithoutLicense.map(pkg => pkg.name);
383+
const noun = names.length > 1 ? "Packages" : "Package";
384+
const verb = names.length > 1 ? "are" : "is";
385+
const list =
386+
names.length > 1
387+
? `${names.slice(0, -1).join(", ")}${names.length > 2 ? "," : ""} and ${
388+
names[names.length - 1] /* oxford commas _are_ that important */
389+
}`
390+
: names[0];
391+
381392
this.logger.warn(
382393
"ENOLICENSE",
383-
`Packages ${packagesWithoutLicense.map(pkg => pkg.name).join(", ")} are missing a license`
394+
"%s %s %s missing a license.\n%s\n%s",
395+
noun,
396+
list,
397+
verb,
398+
"One way to fix this is to add a LICENSE.md file to the root of this repository.",
399+
"See https://choosealicense.com for additional guidance."
384400
);
385401
} else {
386402
this.packagesToBeLicensed = packagesWithoutLicense;

0 commit comments

Comments
 (0)
Please sign in to comment.