UNPKG

lerna

Version:

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

56 lines (53 loc) 1.63 kB
import { getFetchConfig } from "./chunk-MDMOE4VM.js"; import { ValidationError, pulseTillDone } from "./chunk-WC2B4V4E.js"; // libs/commands/publish/src/lib/verify-npm-package-access.ts import access from "libnpmaccess"; function verifyNpmPackageAccess(packages, username, options) { const opts = getFetchConfig(options, { // don't wait forever for third-party failures to be dealt with fetchRetries: 0 }); opts.log.silly("verifyNpmPackageAccess", ""); return pulseTillDone(access.getPackages(username, opts)).then(success, failure); function success(result) { const userPackages = Object.keys(result || {}); if (userPackages.length === 0) { opts.log.warn( "", "The logged-in user does not have any previously-published packages, skipping permission checks..." ); return; } for (const pkg of packages) { if (pkg.name in result && result[pkg.name] !== "read-write") { throw new ValidationError( "EACCESS", `You do not have write permission required to publish "${pkg.name}"` ); } } } function failure(err) { if (err.code === "E500" || err.code === "E404") { opts.log.warn( "EREGISTRY", "Registry %j does not support `npm access list packages`, skipping permission checks...", // registry opts.registry ); return; } opts.log.pause(); console.error(err.message); opts.log.resume(); throw new ValidationError("EWHOAMI", "Authentication error. Use `npm whoami` to troubleshoot."); } } export { verifyNpmPackageAccess };