@lerna/publish
Version:
Publish packages in the current project
97 lines (96 loc) • 4.09 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 npm_publish_exports = {};
__export(npm_publish_exports, {
npmPublish: () => npmPublish
});
module.exports = __toCommonJS(npm_publish_exports);
var import_fs_extra = __toESM(require("fs-extra"));
var import_libnpmpublish = require("libnpmpublish");
var import_npm_package_arg = __toESM(require("npm-package-arg"));
var import_npmlog = __toESM(require("npmlog"));
var import_path = __toESM(require("path"));
var import_pify = __toESM(require("pify"));
var import_otplease = require("./otplease");
var import_run_lifecycle = require("./run-lifecycle");
const readJSON = require("read-package-json");
const readJSONAsync = (0, import_pify.default)(readJSON);
function flattenOptions(obj) {
return {
// eslint-disable-next-line dot-notation -- (npm v7 compat)
defaultTag: obj["tag"] || "latest",
dryRun: obj["dry-run"],
// libnpmpublish / npm-registry-fetch check strictSSL rather than strict-ssl
strictSSL: obj["strict-ssl"],
...obj
};
}
function npmPublish(pkg, tarFilePath, options = {}, otpCache) {
const { dryRun, ...remainingOptions } = flattenOptions(options);
const { scope } = (0, import_npm_package_arg.default)(pkg.name);
const opts = {
log: import_npmlog.default,
...remainingOptions,
projectScope: scope
};
opts.log.verbose("publish", pkg.name);
let chain = Promise.resolve();
if (!dryRun) {
chain = chain.then(() => {
let { manifestLocation } = pkg;
if (pkg.contents !== pkg.location) {
manifestLocation = import_path.default.join(pkg.contents, "package.json");
}
return Promise.all([import_fs_extra.default.readFile(tarFilePath), readJSONAsync(manifestLocation)]);
});
chain = chain.then(([tarData, manifest]) => {
if (opts.defaultTag !== "latest" && manifest.publishConfig && manifest.publishConfig.tag && manifest.publishConfig.tag !== opts.defaultTag) {
manifest.publishConfig.tag = opts.defaultTag;
}
if (manifest.publishConfig) {
Object.assign(opts, publishConfigToOpts(manifest.publishConfig));
}
return (0, import_otplease.otplease)((innerOpts) => (0, import_libnpmpublish.publish)(manifest, tarData, innerOpts), opts, otpCache);
});
}
chain = chain.then(() => (0, import_run_lifecycle.runLifecycle)(pkg, "publish", opts));
chain = chain.then(() => (0, import_run_lifecycle.runLifecycle)(pkg, "postpublish", opts));
return chain;
}
function publishConfigToOpts(publishConfig) {
const opts = { ...publishConfig };
if (publishConfig.tag) {
opts.defaultTag = publishConfig.tag;
delete opts.tag;
}
return opts;
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
npmPublish
});