Skip to content

Commit d410a58

Browse files
committed
fix(publish): Propagate root license into custom publish directories
Fixes #2157
1 parent 6703a8e commit d410a58

File tree

3 files changed

+36
-10
lines changed

3 files changed

+36
-10
lines changed

commands/publish/__tests__/create-temp-licenses.test.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,34 @@ describe("createTempLicenses", () => {
1818
expect(licenseWritten).toBe(true);
1919
});
2020

21+
it("copies root license into package contents", async () => {
22+
const cwd = await initFixture("licenses");
23+
const project = new Project(cwd);
24+
const [pkg] = await project.getPackages();
25+
26+
// automagical "contents" setter creates absolute path
27+
pkg.contents = "dist";
28+
29+
await createTempLicenses(project.licensePath, [pkg]);
30+
31+
const licenseWritten = await fs.pathExists(path.join(pkg.contents, "LICENSE"));
32+
expect(licenseWritten).toBe(true);
33+
});
34+
35+
it("copies root license into package publishConfig.directory", async () => {
36+
const cwd = await initFixture("licenses");
37+
const project = new Project(cwd);
38+
const [pkg] = await project.getPackages();
39+
40+
// automagical "contents" getter creates absolute path
41+
await pkg.set("publishConfig", { directory: "build" }).serialize();
42+
43+
await createTempLicenses(project.licensePath, [pkg]);
44+
45+
const licenseWritten = await fs.pathExists(path.join(pkg.contents, "LICENSE"));
46+
expect(licenseWritten).toBe(true);
47+
});
48+
2149
it("copies root license with extension into package location", async () => {
2250
const cwd = await initFixture("licenses");
2351
const project = new Project(cwd);

commands/publish/index.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,13 @@ class PublishCommand extends Command {
164164

165165
this.packagesToPublish = this.updates.map(({ pkg }) => pkg).filter(pkg => !pkg.private);
166166

167+
if (this.options.contents) {
168+
// globally override directory to publish
169+
for (const pkg of this.packagesToPublish) {
170+
pkg.contents = this.options.contents;
171+
}
172+
}
173+
167174
if (result.needsConfirmation) {
168175
// only confirm for --canary, bump === "from-git",
169176
// or bump === "from-package", as VersionCommand
@@ -616,15 +623,6 @@ class PublishCommand extends Command {
616623
chain = chain.then(() => this.runPackageLifecycle(this.project.manifest, "prepack"));
617624
}
618625

619-
const { contents } = this.options;
620-
621-
if (contents) {
622-
// globally override directory to publish
623-
for (const pkg of this.packagesToPublish) {
624-
pkg.contents = contents;
625-
}
626-
}
627-
628626
const opts = this.conf.snapshot;
629627
const mapper = pPipe(
630628
[

commands/publish/lib/create-temp-licenses.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ function createTempLicenses(srcLicensePath, packagesToBeLicensed) {
2121

2222
// store target path for removal later
2323
packagesToBeLicensed.forEach(pkg => {
24-
pkg.licensePath = path.join(pkg.location, licenseFileName);
24+
pkg.licensePath = path.join(pkg.contents, licenseFileName);
2525
});
2626

2727
return pMap(packagesToBeLicensed, pkg => fs.copy(srcLicensePath, pkg.licensePath, options));

0 commit comments

Comments
 (0)