Skip to content

Commit af870bb

Browse files
committedMay 14, 2019
feat(dist-tag): Prompt for OTP when required
1 parent 86383f5 commit af870bb

File tree

6 files changed

+27
-14
lines changed

6 files changed

+27
-14
lines changed
 

‎commands/publish/__tests__/publish-tagging.test.js

+17-8
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,15 @@ Map {
6969
const conf = expect.objectContaining({
7070
tag: "latest",
7171
});
72+
const cache = expect.objectContaining({
73+
otp: undefined,
74+
});
7275

73-
expect(npmDistTag.remove).toHaveBeenCalledWith("@integration/package-1@1.0.1", "lerna-temp", conf);
74-
expect(npmDistTag.remove).toHaveBeenCalledWith("@integration/package-2@1.0.1", "lerna-temp", conf);
76+
expect(npmDistTag.remove).toHaveBeenCalledWith("@integration/package-1@1.0.1", "lerna-temp", conf, cache);
77+
expect(npmDistTag.remove).toHaveBeenCalledWith("@integration/package-2@1.0.1", "lerna-temp", conf, cache);
7578

76-
expect(npmDistTag.add).toHaveBeenCalledWith("@integration/package-1@1.0.1", "CUSTOM", conf); // <--
77-
expect(npmDistTag.add).toHaveBeenCalledWith("@integration/package-2@1.0.1", "latest", conf);
79+
expect(npmDistTag.add).toHaveBeenCalledWith("@integration/package-1@1.0.1", "CUSTOM", conf, cache); // <--
80+
expect(npmDistTag.add).toHaveBeenCalledWith("@integration/package-2@1.0.1", "latest", conf, cache);
7881
});
7982

8083
test("publish --dist-tag beta --temp-tag", async () => {
@@ -92,9 +95,12 @@ Map {
9295
const conf = expect.objectContaining({
9396
tag: "beta",
9497
});
98+
const cache = expect.objectContaining({
99+
otp: undefined,
100+
});
95101

96-
expect(npmDistTag.add).toHaveBeenCalledWith("@integration/package-1@1.0.1", "beta", conf); // <--
97-
expect(npmDistTag.add).toHaveBeenCalledWith("@integration/package-2@1.0.1", "beta", conf);
102+
expect(npmDistTag.add).toHaveBeenCalledWith("@integration/package-1@1.0.1", "beta", conf, cache); // <--
103+
expect(npmDistTag.add).toHaveBeenCalledWith("@integration/package-2@1.0.1", "beta", conf, cache);
98104
});
99105

100106
test("publish prerelease --pre-dist-tag beta", async () => {
@@ -154,7 +160,10 @@ Map {
154160
const conf = expect.objectContaining({
155161
tag: "next",
156162
});
163+
const cache = expect.objectContaining({
164+
otp: undefined,
165+
});
157166

158-
expect(npmDistTag.add).toHaveBeenCalledWith("@integration/package-1@1.0.1-beta.0", "beta", conf);
159-
expect(npmDistTag.add).toHaveBeenCalledWith("@integration/package-2@1.0.1-beta.0", "beta", conf);
167+
expect(npmDistTag.add).toHaveBeenCalledWith("@integration/package-1@1.0.1-beta.0", "beta", conf, cache);
168+
expect(npmDistTag.add).toHaveBeenCalledWith("@integration/package-2@1.0.1-beta.0", "beta", conf, cache);
160169
});

‎commands/publish/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -697,8 +697,8 @@ class PublishCommand extends Command {
697697
const distTag = preDistTag || getDistTag(pkg.get("publishConfig"));
698698

699699
return Promise.resolve()
700-
.then(() => pulseTillDone(npmDistTag.remove(spec, "lerna-temp", opts)))
701-
.then(() => pulseTillDone(npmDistTag.add(spec, distTag, opts)))
700+
.then(() => pulseTillDone(npmDistTag.remove(spec, "lerna-temp", opts, this.otpCache)))
701+
.then(() => pulseTillDone(npmDistTag.add(spec, distTag, opts, this.otpCache)))
702702
.then(() => {
703703
tracker.success("dist-tag", "%s@%s => %j", pkg.name, pkg.version, distTag);
704704
tracker.completeWork(1);

‎package-lock.json

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎utils/npm-dist-tag/__tests__/npm-dist-tag.test.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"use strict";
22

33
jest.mock("npm-registry-fetch");
4+
jest.mock("@lerna/otplease", () => (cb, opts) => Promise.resolve(cb(opts)));
45

56
// mocked modules
67
const fetch = require("npm-registry-fetch");

‎utils/npm-dist-tag/npm-dist-tag.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const log = require("npmlog");
44
const npa = require("npm-package-arg");
55
const fetch = require("npm-registry-fetch");
66
const figgyPudding = require("figgy-pudding");
7+
const otplease = require("@lerna/otplease");
78

89
exports.add = add;
910
exports.remove = remove;
@@ -23,7 +24,7 @@ const DistTagConfig = figgyPudding(
2324
}
2425
);
2526

26-
function add(spec, tag, _opts) {
27+
function add(spec, tag, _opts, otpCache) {
2728
const opts = DistTagConfig(_opts, {
2829
spec: npa(spec),
2930
tag,
@@ -53,7 +54,7 @@ function add(spec, tag, _opts) {
5354
});
5455

5556
// success returns HTTP 204, thus no JSON to parse
56-
return fetch(uri, payload).then(() => {
57+
return otplease(wrappedPayload => fetch(uri, wrappedPayload), payload, otpCache).then(() => {
5758
opts.log.verbose("dist-tag", `added "${cleanTag}" to ${name}@${version}`);
5859

5960
// eslint-disable-next-line no-param-reassign
@@ -64,7 +65,7 @@ function add(spec, tag, _opts) {
6465
});
6566
}
6667

67-
function remove(spec, tag, _opts) {
68+
function remove(spec, tag, _opts, otpCache) {
6869
const opts = DistTagConfig(_opts, {
6970
spec: npa(spec),
7071
});
@@ -85,7 +86,7 @@ function remove(spec, tag, _opts) {
8586
});
8687

8788
// the delete properly returns a 204, so no json to parse
88-
return fetch(uri, payload).then(() => {
89+
return otplease(wrappedPayload => fetch(uri, wrappedPayload), payload, otpCache).then(() => {
8990
opts.log.verbose("dist-tag", `removed "${tag}" from ${opts.spec.name}@${version}`);
9091

9192
// eslint-disable-next-line no-param-reassign

‎utils/npm-dist-tag/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"test": "echo \"Run tests from root\" && exit 1"
3333
},
3434
"dependencies": {
35+
"@lerna/otplease": "file:../../core/otplease",
3536
"figgy-pudding": "^3.5.1",
3637
"npm-package-arg": "^6.1.0",
3738
"npm-registry-fetch": "^3.9.0",

0 commit comments

Comments
 (0)
Please sign in to comment.