UNPKG

lerna

Version:

Lerna is a fast, modern build system for managing and publishing multiple JavaScript/TypeScript packages from the same repository

60 lines (57 loc) 1.83 kB
import { getProfileData } from "./chunk-UXQPUJ7V.js"; import { getWhoAmI } from "./chunk-A7QY4SUR.js"; import { getFetchConfig } from "./chunk-MDMOE4VM.js"; import { ValidationError } from "./chunk-WC2B4V4E.js"; // libs/commands/publish/src/lib/get-npm-username.ts function getNpmUsername(options = {}) { const opts = getFetchConfig(options, { // don't wait forever for third-party failures to be dealt with fetchRetries: 0 }); opts.log.info("", "Verifying npm credentials"); return getProfileData(opts).catch((err) => { if (err.code === "E500" || err.code === "E404") { return getWhoAmI(opts); } throw err; }).then(success, failure); function success(result) { opts.log.silly("get npm username", "received %j", result); if (!result.username) { throw new ValidationError( "ENEEDAUTH", "You must be logged in to publish packages. Use `npm login` and try again." ); } return result.username; } function failure(err) { opts.log.pause(); console.error(err.message); opts.log.resume(); if (opts.registry === "https://registry.npmjs.org/") { if (err.code === "E403") { throw new ValidationError( "ENEEDAUTH", "Access verification failed. Ensure that your npm access token has both read and write access, or remove the verifyAccess option to skip this verification. Note that npm automation tokens do NOT have read access (https://docs.npmjs.com/creating-and-viewing-access-tokens)." ); } throw new ValidationError("EWHOAMI", "Authentication error. Use `npm whoami` to troubleshoot."); } opts.log.warn( "EWHOAMI", "Unable to determine npm username from third-party registry, this command will likely fail soon!" ); } } export { getNpmUsername };