diff --git a/commands/publish/__tests__/publish-tagging.test.js b/commands/publish/__tests__/publish-tagging.test.js index 9859ad90cf..f1448083a7 100644 --- a/commands/publish/__tests__/publish-tagging.test.js +++ b/commands/publish/__tests__/publish-tagging.test.js @@ -69,12 +69,15 @@ Map { const conf = expect.objectContaining({ tag: "latest", }); + const cache = expect.objectContaining({ + otp: undefined, + }); - expect(npmDistTag.remove).toHaveBeenCalledWith("@integration/package-1@1.0.1", "lerna-temp", conf); - expect(npmDistTag.remove).toHaveBeenCalledWith("@integration/package-2@1.0.1", "lerna-temp", conf); + expect(npmDistTag.remove).toHaveBeenCalledWith("@integration/package-1@1.0.1", "lerna-temp", conf, cache); + expect(npmDistTag.remove).toHaveBeenCalledWith("@integration/package-2@1.0.1", "lerna-temp", conf, cache); - expect(npmDistTag.add).toHaveBeenCalledWith("@integration/package-1@1.0.1", "CUSTOM", conf); // <-- - expect(npmDistTag.add).toHaveBeenCalledWith("@integration/package-2@1.0.1", "latest", conf); + expect(npmDistTag.add).toHaveBeenCalledWith("@integration/package-1@1.0.1", "CUSTOM", conf, cache); // <-- + expect(npmDistTag.add).toHaveBeenCalledWith("@integration/package-2@1.0.1", "latest", conf, cache); }); test("publish --dist-tag beta --temp-tag", async () => { @@ -92,9 +95,12 @@ Map { const conf = expect.objectContaining({ tag: "beta", }); + const cache = expect.objectContaining({ + otp: undefined, + }); - expect(npmDistTag.add).toHaveBeenCalledWith("@integration/package-1@1.0.1", "beta", conf); // <-- - expect(npmDistTag.add).toHaveBeenCalledWith("@integration/package-2@1.0.1", "beta", conf); + expect(npmDistTag.add).toHaveBeenCalledWith("@integration/package-1@1.0.1", "beta", conf, cache); // <-- + expect(npmDistTag.add).toHaveBeenCalledWith("@integration/package-2@1.0.1", "beta", conf, cache); }); test("publish prerelease --pre-dist-tag beta", async () => { @@ -154,7 +160,10 @@ Map { const conf = expect.objectContaining({ tag: "next", }); + const cache = expect.objectContaining({ + otp: undefined, + }); - expect(npmDistTag.add).toHaveBeenCalledWith("@integration/package-1@1.0.1-beta.0", "beta", conf); - expect(npmDistTag.add).toHaveBeenCalledWith("@integration/package-2@1.0.1-beta.0", "beta", conf); + expect(npmDistTag.add).toHaveBeenCalledWith("@integration/package-1@1.0.1-beta.0", "beta", conf, cache); + expect(npmDistTag.add).toHaveBeenCalledWith("@integration/package-2@1.0.1-beta.0", "beta", conf, cache); }); diff --git a/commands/publish/index.js b/commands/publish/index.js index 0857e8f212..e475c1b0ca 100644 --- a/commands/publish/index.js +++ b/commands/publish/index.js @@ -697,8 +697,8 @@ class PublishCommand extends Command { const distTag = preDistTag || getDistTag(pkg.get("publishConfig")); return Promise.resolve() - .then(() => pulseTillDone(npmDistTag.remove(spec, "lerna-temp", opts))) - .then(() => pulseTillDone(npmDistTag.add(spec, distTag, opts))) + .then(() => pulseTillDone(npmDistTag.remove(spec, "lerna-temp", opts, this.otpCache))) + .then(() => pulseTillDone(npmDistTag.add(spec, distTag, opts, this.otpCache))) .then(() => { tracker.success("dist-tag", "%s@%s => %j", pkg.name, pkg.version, distTag); tracker.completeWork(1); diff --git a/package-lock.json b/package-lock.json index a79dd7f35e..32cca919c8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -996,6 +996,7 @@ "@lerna/npm-dist-tag": { "version": "file:utils/npm-dist-tag", "requires": { + "@lerna/otplease": "file:core/otplease", "figgy-pudding": "^3.5.1", "npm-package-arg": "^6.1.0", "npm-registry-fetch": "^3.9.0", diff --git a/utils/npm-dist-tag/__tests__/npm-dist-tag.test.js b/utils/npm-dist-tag/__tests__/npm-dist-tag.test.js index 1f5085e7c8..a7d3ad203d 100644 --- a/utils/npm-dist-tag/__tests__/npm-dist-tag.test.js +++ b/utils/npm-dist-tag/__tests__/npm-dist-tag.test.js @@ -1,6 +1,7 @@ "use strict"; jest.mock("npm-registry-fetch"); +jest.mock("@lerna/otplease", () => (cb, opts) => Promise.resolve(cb(opts))); // mocked modules const fetch = require("npm-registry-fetch"); diff --git a/utils/npm-dist-tag/npm-dist-tag.js b/utils/npm-dist-tag/npm-dist-tag.js index 4ee71ff2cd..70497d70dc 100644 --- a/utils/npm-dist-tag/npm-dist-tag.js +++ b/utils/npm-dist-tag/npm-dist-tag.js @@ -4,6 +4,7 @@ const log = require("npmlog"); const npa = require("npm-package-arg"); const fetch = require("npm-registry-fetch"); const figgyPudding = require("figgy-pudding"); +const otplease = require("@lerna/otplease"); exports.add = add; exports.remove = remove; @@ -23,7 +24,7 @@ const DistTagConfig = figgyPudding( } ); -function add(spec, tag, _opts) { +function add(spec, tag, _opts, otpCache) { const opts = DistTagConfig(_opts, { spec: npa(spec), tag, @@ -53,7 +54,7 @@ function add(spec, tag, _opts) { }); // success returns HTTP 204, thus no JSON to parse - return fetch(uri, payload).then(() => { + return otplease(wrappedPayload => fetch(uri, wrappedPayload), payload, otpCache).then(() => { opts.log.verbose("dist-tag", `added "${cleanTag}" to ${name}@${version}`); // eslint-disable-next-line no-param-reassign @@ -64,7 +65,7 @@ function add(spec, tag, _opts) { }); } -function remove(spec, tag, _opts) { +function remove(spec, tag, _opts, otpCache) { const opts = DistTagConfig(_opts, { spec: npa(spec), }); @@ -85,7 +86,7 @@ function remove(spec, tag, _opts) { }); // the delete properly returns a 204, so no json to parse - return fetch(uri, payload).then(() => { + return otplease(wrappedPayload => fetch(uri, wrappedPayload), payload, otpCache).then(() => { opts.log.verbose("dist-tag", `removed "${tag}" from ${opts.spec.name}@${version}`); // eslint-disable-next-line no-param-reassign diff --git a/utils/npm-dist-tag/package.json b/utils/npm-dist-tag/package.json index dbc4dfccef..7df0087f50 100644 --- a/utils/npm-dist-tag/package.json +++ b/utils/npm-dist-tag/package.json @@ -32,6 +32,7 @@ "test": "echo \"Run tests from root\" && exit 1" }, "dependencies": { + "@lerna/otplease": "file:../../core/otplease", "figgy-pudding": "^3.5.1", "npm-package-arg": "^6.1.0", "npm-registry-fetch": "^3.9.0",