Skip to content

Commit

Permalink
fix(publish): Propagate root license into custom publish directories
Browse files Browse the repository at this point in the history
Fixes #2157
  • Loading branch information
evocateur committed Jul 18, 2019
1 parent 6703a8e commit d410a58
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 10 deletions.
28 changes: 28 additions & 0 deletions commands/publish/__tests__/create-temp-licenses.test.js
Expand Up @@ -18,6 +18,34 @@ describe("createTempLicenses", () => {
expect(licenseWritten).toBe(true);
});

it("copies root license into package contents", async () => {
const cwd = await initFixture("licenses");
const project = new Project(cwd);
const [pkg] = await project.getPackages();

// automagical "contents" setter creates absolute path
pkg.contents = "dist";

await createTempLicenses(project.licensePath, [pkg]);

const licenseWritten = await fs.pathExists(path.join(pkg.contents, "LICENSE"));
expect(licenseWritten).toBe(true);
});

it("copies root license into package publishConfig.directory", async () => {
const cwd = await initFixture("licenses");
const project = new Project(cwd);
const [pkg] = await project.getPackages();

// automagical "contents" getter creates absolute path
await pkg.set("publishConfig", { directory: "build" }).serialize();

await createTempLicenses(project.licensePath, [pkg]);

const licenseWritten = await fs.pathExists(path.join(pkg.contents, "LICENSE"));
expect(licenseWritten).toBe(true);
});

it("copies root license with extension into package location", async () => {
const cwd = await initFixture("licenses");
const project = new Project(cwd);
Expand Down
16 changes: 7 additions & 9 deletions commands/publish/index.js
Expand Up @@ -164,6 +164,13 @@ class PublishCommand extends Command {

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

if (this.options.contents) {
// globally override directory to publish
for (const pkg of this.packagesToPublish) {
pkg.contents = this.options.contents;
}
}

if (result.needsConfirmation) {
// only confirm for --canary, bump === "from-git",
// or bump === "from-package", as VersionCommand
Expand Down Expand Up @@ -616,15 +623,6 @@ class PublishCommand extends Command {
chain = chain.then(() => this.runPackageLifecycle(this.project.manifest, "prepack"));
}

const { contents } = this.options;

if (contents) {
// globally override directory to publish
for (const pkg of this.packagesToPublish) {
pkg.contents = contents;
}
}

const opts = this.conf.snapshot;
const mapper = pPipe(
[
Expand Down
2 changes: 1 addition & 1 deletion commands/publish/lib/create-temp-licenses.js
Expand Up @@ -21,7 +21,7 @@ function createTempLicenses(srcLicensePath, packagesToBeLicensed) {

// store target path for removal later
packagesToBeLicensed.forEach(pkg => {
pkg.licensePath = path.join(pkg.location, licenseFileName);
pkg.licensePath = path.join(pkg.contents, licenseFileName);
});

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

0 comments on commit d410a58

Please sign in to comment.