Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(publish): Ensure published packages contain a LICENSE file (#1465)
Fixes #1213
- Loading branch information
1 parent
346d156
commit 5863564
Showing
43 changed files
with
486 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
commands/publish/__tests__/__fixtures__/licenses-missing/lerna.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"version": "1.0.0" | ||
} |
4 changes: 4 additions & 0 deletions
4
commands/publish/__tests__/__fixtures__/licenses-missing/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"name": "licenses-missing", | ||
"version": "0.0.0-monorepo" | ||
} |
4 changes: 4 additions & 0 deletions
4
commands/publish/__tests__/__fixtures__/licenses-missing/packages/package-1/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"name": "package-1", | ||
"version": "1.0.0" | ||
} |
3 changes: 3 additions & 0 deletions
3
commands/publish/__tests__/__fixtures__/licenses-missing/packages/package-2/LICENSE
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Copyright (c) 2018 Tester McPerson <test@example.com> | ||
|
||
XYZ License |
4 changes: 4 additions & 0 deletions
4
commands/publish/__tests__/__fixtures__/licenses-missing/packages/package-2/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"name": "package-2", | ||
"version": "1.0.0" | ||
} |
4 changes: 4 additions & 0 deletions
4
commands/publish/__tests__/__fixtures__/licenses-missing/packages/package-3/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"name": "package-3", | ||
"version": "1.0.0" | ||
} |
4 changes: 4 additions & 0 deletions
4
commands/publish/__tests__/__fixtures__/licenses-names/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"name": "licenses-names", | ||
"version": "0.0.0-monorepo" | ||
} |
3 changes: 3 additions & 0 deletions
3
commands/publish/__tests__/__fixtures__/licenses-names/packages/package-1/LICENSE
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Copyright (c) 2018 Tester McPerson <test@example.com> | ||
|
||
ABC License |
4 changes: 4 additions & 0 deletions
4
commands/publish/__tests__/__fixtures__/licenses-names/packages/package-1/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"name": "package-1", | ||
"version": "1.0.0" | ||
} |
3 changes: 3 additions & 0 deletions
3
commands/publish/__tests__/__fixtures__/licenses-names/packages/package-2/licence
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Copyright (c) 2018 Tester McPerson <test@example.com> | ||
|
||
ABC License |
4 changes: 4 additions & 0 deletions
4
commands/publish/__tests__/__fixtures__/licenses-names/packages/package-2/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"name": "package-2", | ||
"version": "1.0.0" | ||
} |
3 changes: 3 additions & 0 deletions
3
commands/publish/__tests__/__fixtures__/licenses-names/packages/package-3/LiCeNSe
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Copyright (c) 2018 Tester McPerson <test@example.com> | ||
|
||
ABC License |
4 changes: 4 additions & 0 deletions
4
commands/publish/__tests__/__fixtures__/licenses-names/packages/package-3/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"name": "package-3", | ||
"version": "1.0.0" | ||
} |
3 changes: 3 additions & 0 deletions
3
commands/publish/__tests__/__fixtures__/licenses-names/packages/package-4/LICENSE-ABC
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Copyright (c) 2018 Tester McPerson <test@example.com> | ||
|
||
ABC License |
4 changes: 4 additions & 0 deletions
4
commands/publish/__tests__/__fixtures__/licenses-names/packages/package-4/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"name": "package-4", | ||
"version": "1.0.0" | ||
} |
3 changes: 3 additions & 0 deletions
3
commands/publish/__tests__/__fixtures__/licenses-names/packages/package-5/LICENCE
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Copyright (c) 2018 Tester McPerson <test@example.com> | ||
|
||
ABC License |
3 changes: 3 additions & 0 deletions
3
commands/publish/__tests__/__fixtures__/licenses-names/packages/package-5/license
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Copyright (c) 2018 Tester McPerson <test@example.com> | ||
|
||
ABC License |
4 changes: 4 additions & 0 deletions
4
commands/publish/__tests__/__fixtures__/licenses-names/packages/package-5/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"name": "package-5", | ||
"version": "1.0.0" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Copyright (c) 2018 Tester McPerson <test@example.com> | ||
|
||
ABC License |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"version": "1.0.0" | ||
} |
4 changes: 4 additions & 0 deletions
4
commands/publish/__tests__/__fixtures__/licenses/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"name": "licenses", | ||
"version": "0.0.0-monorepo" | ||
} |
4 changes: 4 additions & 0 deletions
4
commands/publish/__tests__/__fixtures__/licenses/packages/package-1/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"name": "package-1", | ||
"version": "1.0.0" | ||
} |
3 changes: 3 additions & 0 deletions
3
commands/publish/__tests__/__fixtures__/licenses/packages/package-2/licence
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Copyright (c) 2018 Tester McPerson <test@example.com> | ||
|
||
XYZ License |
7 changes: 7 additions & 0 deletions
7
commands/publish/__tests__/__fixtures__/licenses/packages/package-2/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"name": "package-2", | ||
"version": "1.0.0", | ||
"dependencies": { | ||
"package-1": "^1.0.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
"use strict"; | ||
|
||
const fs = require("fs-extra"); | ||
const path = require("path"); | ||
|
||
const initFixture = require("@lerna-test/init-fixture")(__dirname); | ||
const createTempLicenses = require("../lib/create-temp-licenses"); | ||
|
||
test("creates temporary copy of the source license", async () => { | ||
const cwd = await initFixture("licenses"); | ||
|
||
const pkg = { name: "package-1", location: path.join(cwd, "packages", "package-1") }; | ||
await createTempLicenses(path.join(cwd, "LICENSE"), [pkg]); | ||
|
||
expect(fs.exists(path.join(pkg.location, "LICENSE"))).resolves.toBe(true); | ||
}); | ||
|
||
test("resolves when source license path is missing", async () => { | ||
const cwd = await initFixture("licenses"); | ||
|
||
const pkg = { name: "package-1", location: path.join(cwd, "packages", "package-1") }; | ||
await createTempLicenses(null, [pkg]); | ||
|
||
expect(fs.exists(path.join(pkg.location, "LICENSE"))).resolves.toBe(false); | ||
}); | ||
|
||
test("resolves when there are no packages", async () => { | ||
const cwd = await initFixture("licenses"); | ||
|
||
await createTempLicenses(path.join(cwd, "LICENSE"), []); | ||
|
||
expect(fs.exists(path.join(cwd, "packages", "package-1", "LICENSE"))).resolves.toBe(false); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
"use strict"; | ||
|
||
const path = require("path"); | ||
|
||
const initFixture = require("@lerna-test/init-fixture")(__dirname); | ||
const getLicensePath = require("../lib/get-license-path"); | ||
|
||
test("recognizes American spelling", async () => { | ||
const cwd = await initFixture("licenses-names"); | ||
|
||
expect(getLicensePath(path.join(cwd, "packages", "package-1"))).resolves.toBe("LICENSE"); | ||
}); | ||
|
||
test("recognizes British spelling", async () => { | ||
const cwd = await initFixture("licenses-names"); | ||
|
||
expect(getLicensePath(path.join(cwd, "packages", "package-2"))).resolves.toBe("licence"); | ||
}); | ||
|
||
test("doesn't mind upper or lower case", async () => { | ||
const cwd = await initFixture("licenses-names"); | ||
|
||
expect(getLicensePath(path.join(cwd, "packages", "package-3"))).resolves.toBe("LiCeNSe"); | ||
}); | ||
|
||
test("resolves to null if there is no license file", async () => { | ||
const cwd = await initFixture("licenses-names"); | ||
|
||
expect(getLicensePath(path.join(cwd, "packages", "package-4"))).resolves.toBeNull(); | ||
}); | ||
|
||
test("resolves to the first license file, alphabetically", async () => { | ||
const cwd = await initFixture("licenses-names"); | ||
|
||
expect(getLicensePath(path.join(cwd, "packages", "package-5"))).resolves.toBe("LICENCE"); | ||
}); |
15 changes: 15 additions & 0 deletions
15
commands/publish/__tests__/get-packages-without-license.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
"use strict"; | ||
|
||
const path = require("path"); | ||
|
||
const initFixture = require("@lerna-test/init-fixture")(__dirname); | ||
const getPackagesWithoutLicense = require("../lib/get-packages-without-license"); | ||
|
||
test("getPackagesWithoutLicense", async () => { | ||
const cwd = await initFixture("licenses"); | ||
|
||
const pkg1 = { name: "package-1", location: path.join(cwd, "packages", "package-1") }; | ||
const pkg2 = { name: "package-2", location: path.join(cwd, "packages", "package-2") }; | ||
|
||
expect(getPackagesWithoutLicense([pkg1, pkg2])).resolves.toEqual(expect.arrayContaining([pkg1])); | ||
}); |
Oops, something went wrong.