Skip to content

Commit

Permalink
fix(npm-publish): Use generated manifest when publishing subdirectory
Browse files Browse the repository at this point in the history
Fixes #2113
  • Loading branch information
evocateur committed Jun 9, 2019
1 parent ea861d9 commit b922766
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
37 changes: 37 additions & 0 deletions utils/npm-publish/__tests__/npm-publish.test.js
Expand Up @@ -119,6 +119,43 @@ describe("npm-publish", () => {
);
});

it("uses pkg.contents manifest when pkg.publishConfig.directory is defined", async () => {
const fancyPkg = new Package(
{
name: "fancy",
version: "1.10.100",
publishConfig: {
directory: "dist",
},
},
path.join(rootPath, "npmPublish/fancy"),
rootPath
);

readJSON.mockImplementationOnce((file, cb) =>
cb(null, {
name: "fancy-fancy",
version: "1.10.100",
})
);

await npmPublish(fancyPkg, tarFilePath);

expect(readJSON).toHaveBeenCalledWith(
path.join(fancyPkg.location, "dist/package.json"),
expect.any(Function)
);
expect(publish).toHaveBeenCalledWith(
expect.objectContaining({
name: "fancy-fancy",
}),
mockTarData,
expect.figgyPudding({
tag: "latest",
})
);
});

it("respects opts.dryRun", async () => {
const opts = new Map().set("dryRun", true);

Expand Down
12 changes: 11 additions & 1 deletion utils/npm-publish/npm-publish.js
@@ -1,6 +1,7 @@
"use strict";

const fs = require("fs-extra");
const path = require("path");
const log = require("npmlog");
const { publish } = require("libnpmpublish");
const pify = require("pify");
Expand Down Expand Up @@ -43,7 +44,16 @@ function npmPublish(pkg, tarFilePath, _opts, otpCache) {
let chain = Promise.resolve();

if (!opts.dryRun) {
chain = chain.then(() => Promise.all([fs.readFile(tarFilePath), readJSONAsync(pkg.manifestLocation)]));
chain = chain.then(() => {
let { manifestLocation } = pkg;

if (pkg.contents !== pkg.location) {
// "rebase" manifest used to generated directory
manifestLocation = path.join(pkg.contents, "package.json");
}

return Promise.all([fs.readFile(tarFilePath), readJSONAsync(manifestLocation)]);
});
chain = chain.then(([tarData, manifest]) => {
// non-default tag needs to override publishConfig.tag,
// which is merged over opts.tag in libnpmpublish
Expand Down

0 comments on commit b922766

Please sign in to comment.