Skip to content

Commit 81e6e66

Browse files
committed
feat: support OTP fetching from config.otpUrl
1 parent 9bd97fc commit 81e6e66

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

lib/publish.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
const path = require('path');
22
const execa = require('execa');
3+
const fetch = require('node-fetch');
34
const getRegistry = require('./get-registry');
45
const getReleaseInfo = require('./get-release-info');
56

6-
module.exports = async ({npmPublish, pkgRoot}, pkg, context) => {
7+
module.exports = async ({npmPublish, pkgRoot, otpUrl}, pkg, context) => {
78
const {
89
cwd,
910
env,
@@ -16,9 +17,14 @@ module.exports = async ({npmPublish, pkgRoot}, pkg, context) => {
1617
if (npmPublish !== false && pkg.private !== true) {
1718
const basePath = pkgRoot ? path.resolve(cwd, pkgRoot) : cwd;
1819
const registry = getRegistry(pkg, context);
20+
let otpArgs = [];
21+
if (otpUrl) {
22+
const res = await fetch(otpUrl);
23+
otpArgs = ['--otp', await res.text()];
24+
}
1925

2026
logger.log('Publishing version %s to npm registry', version);
21-
const result = execa('npm', ['publish', basePath, '--registry', registry], {cwd, env});
27+
const result = execa('npm', ['publish', basePath, '--registry', registry, ...otpArgs], {cwd, env});
2228
result.stdout.pipe(
2329
stdout,
2430
{end: false}

lib/verify-config.js

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const VALIDATORS = {
77
npmPublish: isBoolean,
88
tarballDir: isNonEmptyString,
99
pkgRoot: isNonEmptyString,
10+
otpUrl: isNonEmptyString,
1011
};
1112

1213
module.exports = ({npmPublish, tarballDir, pkgRoot}) => {

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"fs-extra": "^8.0.0",
3131
"lodash": "^4.17.4",
3232
"nerf-dart": "^1.0.0",
33+
"node-fetch": "^2.6.0",
3334
"normalize-url": "^4.0.0",
3435
"npm": "^6.8.0",
3536
"rc": "^1.2.8",

0 commit comments

Comments
 (0)