diff --git a/utils/npm-publish/__tests__/npm-publish.test.js b/utils/npm-publish/__tests__/npm-publish.test.js index df74198e3b..066c277c24 100644 --- a/utils/npm-publish/__tests__/npm-publish.test.js +++ b/utils/npm-publish/__tests__/npm-publish.test.js @@ -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); diff --git a/utils/npm-publish/npm-publish.js b/utils/npm-publish/npm-publish.js index fea180541f..741bdd4411 100644 --- a/utils/npm-publish/npm-publish.js +++ b/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"); @@ -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