Skip to content

Commit

Permalink
fix(deps): Explicit read-package-json ^2.0.13
Browse files Browse the repository at this point in the history
  • Loading branch information
evocateur committed Feb 4, 2019
1 parent 506ad6d commit 2695a90
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 18 deletions.
4 changes: 3 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 18 additions & 14 deletions utils/npm-publish/__tests__/npm-publish.test.js
@@ -1,14 +1,14 @@
"use strict";

jest.mock("@lerna/run-lifecycle");
jest.mock("libnpm/read-json");
jest.mock("read-package-json");
jest.mock("libnpm/publish");
jest.mock("fs-extra");

// mocked modules
const fs = require("fs-extra");
const publish = require("libnpm/publish");
const readJSON = require("libnpm/read-json");
const readJSON = require("read-package-json");
const runLifecycle = require("@lerna/run-lifecycle");

// helpers
Expand All @@ -26,7 +26,7 @@ describe("npm-publish", () => {

fs.readFile.mockName("fs.readFile").mockResolvedValue(mockTarData);
publish.mockName("libnpm/publish").mockResolvedValue();
readJSON.mockName("libnpm/read-json").mockResolvedValue(mockManifest);
readJSON.mockName("read-package-json").mockImplementation((file, cb) => cb(null, mockManifest));
runLifecycle.mockName("@lerna/run-lifecycle").mockResolvedValue();

const tarFilePath = "/tmp/test-1.10.100.tgz";
Expand All @@ -43,7 +43,7 @@ describe("npm-publish", () => {
await npmPublish(pkg, tarFilePath, opts);

expect(fs.readFile).toHaveBeenCalledWith(tarFilePath);
expect(readJSON).toHaveBeenCalledWith(pkg.manifestLocation);
expect(readJSON).toHaveBeenCalledWith(pkg.manifestLocation, expect.any(Function));
expect(publish).toHaveBeenCalledWith(
mockManifest,
mockTarData,
Expand All @@ -68,11 +68,13 @@ describe("npm-publish", () => {
});

it("overrides pkg.publishConfig.tag when opts.tag is not defaulted", async () => {
readJSON.mockResolvedValueOnce({
publishConfig: {
tag: "beta",
},
});
readJSON.mockImplementationOnce((file, cb) =>
cb(null, {
publishConfig: {
tag: "beta",
},
})
);
const opts = new Map().set("tag", "temp-tag");

await npmPublish(pkg, tarFilePath, opts);
Expand All @@ -91,11 +93,13 @@ describe("npm-publish", () => {
});

it("respects pkg.publishConfig.tag when opts.tag matches default", async () => {
readJSON.mockResolvedValueOnce({
publishConfig: {
tag: "beta",
},
});
readJSON.mockImplementationOnce((file, cb) =>
cb(null, {
publishConfig: {
tag: "beta",
},
})
);

await npmPublish(pkg, tarFilePath);

Expand Down
7 changes: 5 additions & 2 deletions utils/npm-publish/npm-publish.js
Expand Up @@ -3,12 +3,15 @@
const fs = require("fs-extra");
const log = require("libnpm/log");
const publish = require("libnpm/publish");
const readJSON = require("libnpm/read-json");
const pify = require("pify");
const readJSON = require("read-package-json");
const figgyPudding = require("figgy-pudding");
const runLifecycle = require("@lerna/run-lifecycle");

module.exports = npmPublish;

const readJSONAsync = pify(readJSON);

const PublishConfig = figgyPudding(
{
"dry-run": { default: false },
Expand Down Expand Up @@ -36,7 +39,7 @@ function npmPublish(pkg, tarFilePath, _opts) {
let chain = Promise.resolve();

if (!opts.dryRun) {
chain = chain.then(() => Promise.all([fs.readFile(tarFilePath), readJSON(pkg.manifestLocation)]));
chain = chain.then(() => Promise.all([fs.readFile(tarFilePath), readJSONAsync(pkg.manifestLocation)]));
chain = chain.then(([tarData, manifest]) => {
// non-default tag needs to override publishConfig.tag,
// which is merged over opts.tag in libnpm/publish
Expand Down
4 changes: 3 additions & 1 deletion utils/npm-publish/package.json
Expand Up @@ -33,6 +33,8 @@
"@lerna/run-lifecycle": "file:../run-lifecycle",
"figgy-pudding": "^3.5.1",
"fs-extra": "^7.0.0",
"libnpm": "^2.0.1"
"libnpm": "^2.0.1",
"pify": "^3.0.0",
"read-package-json": "^2.0.13"
}
}

0 comments on commit 2695a90

Please sign in to comment.