UNPKG

@lerna/publish

Version:

Publish packages in the current project

100 lines (99 loc) 3.31 kB
var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var otplease_exports = {}; __export(otplease_exports, { getOneTimePassword: () => getOneTimePassword, otplease: () => otplease }); module.exports = __toCommonJS(otplease_exports); var import_prompt = require("./prompt"); const semaphore = { _promise: void 0, _resolve: void 0, wait() { return new Promise((resolve) => { if (!this._promise) { this._promise = new Promise((release) => { this._resolve = release; }); resolve(void 0); } else { resolve(this._promise.then(() => this.wait())); } }); }, release() { const resolve = this._resolve; if (resolve) { this._resolve = void 0; this._promise = void 0; resolve(); } } }; function otplease(fn, _opts, otpCache) { const opts = { ...otpCache, ..._opts }; return attempt(fn, opts, otpCache); } function attempt(fn, opts, otpCache) { return new Promise((resolve) => { resolve(fn(opts)); }).catch((err) => { if (err.code !== "EOTP" && !(err.code === "E401" && /one-time pass/.test(err.body))) { throw err; } else if (!process.stdin.isTTY || !process.stdout.isTTY) { throw err; } else { if (otpCache != null && otpCache.otp != null && otpCache.otp !== opts["otp"]) { return attempt(fn, { ...opts, ...otpCache }, otpCache); } return semaphore.wait().then(() => { if (otpCache != null && otpCache.otp != null && otpCache.otp !== opts["otp"]) { semaphore.release(); return attempt(fn, { ...opts, ...otpCache }, otpCache); } return getOneTimePassword().then( (otp) => { if (otpCache != null) { otpCache.otp = otp; } semaphore.release(); return otp; }, (promptError) => { semaphore.release(); return Promise.reject(promptError); } ).then((otp) => { return fn({ ...opts, otp }); }); }); } }); } function getOneTimePassword(message = "This operation requires a one-time password:") { return (0, import_prompt.promptTextInput)(message, { filter: (otp) => otp.replace(/\s+/g, ""), validate: (otp) => otp && /^[\d ]+$|^[A-Fa-f0-9]{64,64}$/.test(otp) || "Must be a valid one-time-password. See https://docs.npmjs.com/getting-started/using-two-factor-authentication" }); } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { getOneTimePassword, otplease });