@lerna/publish
Version:
Publish packages in the current project
114 lines (113 loc) • 4.52 kB
JavaScript
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
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 __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var map_to_registry_exports = {};
__export(map_to_registry_exports, {
mapToRegistry: () => mapToRegistry
});
module.exports = __toCommonJS(map_to_registry_exports);
var import_npm_package_arg = __toESM(require("npm-package-arg"));
var import_npmlog = __toESM(require("npmlog"));
var import_url = __toESM(require("url"));
function mapToRegistry(name, config) {
import_npmlog.default.silly("mapToRegistry", "name", name);
let registry;
const data = (0, import_npm_package_arg.default)(name);
if (data.scope) {
name = name.replace("/", "%2f");
import_npmlog.default.silly("mapToRegistry", "scope (from package name)", data.scope);
registry = config.get(`${data.scope}:registry`);
if (!registry) {
import_npmlog.default.verbose("mapToRegistry", "no registry URL found in name for scope", data.scope);
}
}
let scope = config.get("scope");
if (!registry && scope) {
if (scope.charAt(0) !== "@") {
scope = `@${scope}`;
}
import_npmlog.default.silly("mapToRegistry", "scope (from config)", scope);
registry = config.get(`${scope}:registry`);
if (!registry) {
import_npmlog.default.verbose("mapToRegistry", "no registry URL found in config for scope", scope);
}
}
if (!registry) {
import_npmlog.default.silly("mapToRegistry", "using default registry");
registry = config.get("registry");
}
import_npmlog.default.silly("mapToRegistry", "registry", registry);
const credentials = config.getCredentialsByURI(registry);
const normalized = registry.slice(-1) !== "/" ? `${registry}/` : registry;
let uri;
import_npmlog.default.silly("mapToRegistry", "data", data);
if (data.type === "remote") {
uri = data.fetchSpec;
} else {
uri = import_url.default.resolve(normalized, name);
}
import_npmlog.default.silly("mapToRegistry", "uri", uri);
const auth = scopeAuth(uri, registry, credentials, config);
return { uri, auth };
}
function scopeAuth(uri, registry, auth, config) {
const cleaned = {
scope: auth.scope,
email: auth.email,
alwaysAuth: auth.alwaysAuth,
token: void 0,
username: void 0,
password: void 0,
auth: void 0
};
if (auth.token || auth.auth || auth.username && auth.password) {
const requestHost = import_url.default.parse(uri).hostname;
const registryHost = import_url.default.parse(registry).hostname;
if (requestHost === registryHost) {
cleaned.token = auth.token;
cleaned.auth = auth.auth;
cleaned.username = auth.username;
cleaned.password = auth.password;
} else if (auth.alwaysAuth) {
import_npmlog.default.verbose("scopeAuth", "alwaysAuth set for", registry);
cleaned.token = auth.token;
cleaned.auth = auth.auth;
cleaned.username = auth.username;
cleaned.password = auth.password;
} else {
import_npmlog.default.silly("scopeAuth", uri, "doesn't share host with registry", registry);
}
if (config.get("otp")) {
cleaned.otp = config.get("otp");
}
}
return cleaned;
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
mapToRegistry
});