UNPKG

@lerna/publish

Version:

Publish packages in the current project

33 lines (32 loc) 1.13 kB
var import_core = require("@lerna/core"); const { getFetchConfig } = require("./fetch-config"); const { getProfileData } = require("./get-profile-data"); module.exports.getTwoFactorAuthRequired = getTwoFactorAuthRequired; function getTwoFactorAuthRequired(options) { const opts = getFetchConfig(options, { // don't wait forever for third-party failures to be dealt with fetchRetries: 0 }); opts.log.info("", "Checking two-factor auth mode"); return getProfileData(opts).then(success, failure); function success(result) { opts.log.silly("2FA", result.tfa); if (result.tfa.pending) { return false; } return result.tfa.mode === "auth-and-writes"; } function failure(err) { if (err.code === "E500" || err.code === "E404") { opts.log.warn( "EREGISTRY", `Registry "${opts.registry}" does not support 'npm profile get', skipping two-factor auth check...` ); return false; } opts.log.pause(); console.error(err.message); opts.log.resume(); throw new import_core.ValidationError("ETWOFACTOR", "Unable to obtain two-factor auth mode"); } }