UNPKG

@lerna/publish

Version:

Publish packages in the current project

104 lines (103 loc) 4.54 kB
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 pack_directory_exports = {}; __export(pack_directory_exports, { packDirectory: () => packDirectory }); module.exports = __toCommonJS(pack_directory_exports); var import_path = __toESM(require("path")); var import_npm_packlist = __toESM(require("npm-packlist")); var import_npmlog = __toESM(require("npmlog")); var import_tar = __toESM(require("tar")); var import_temp_write = __toESM(require("./temp-write")); var import_get_packed = require("./get-packed"); var import_package = require("./package"); var import_run_lifecycle = require("./run-lifecycle"); function packDirectory(_pkg, dir, options) { const pkg = import_package.Package.lazy(_pkg, dir); const opts = { log: import_npmlog.default, ...options }; opts.log.verbose("pack-directory", import_path.default.relative(".", pkg.contents)); let chain = Promise.resolve(); if (opts.ignorePrepublish !== true) { chain = chain.then(() => (0, import_run_lifecycle.runLifecycle)(pkg, "prepublish", opts)); } chain = chain.then(() => (0, import_run_lifecycle.runLifecycle)(pkg, "prepare", opts)); if (opts.lernaCommand === "publish") { opts.stdio = "inherit"; chain = chain.then(() => pkg.refresh()); chain = chain.then(() => (0, import_run_lifecycle.runLifecycle)(pkg, "prepublishOnly", opts)); chain = chain.then(() => pkg.refresh()); } chain = chain.then(() => (0, import_run_lifecycle.runLifecycle)(pkg, "prepack", opts)); chain = chain.then(() => pkg.refresh()); chain = chain.then(() => (0, import_npm_packlist.default)({ path: pkg.contents })); chain = chain.then( (files) => import_tar.default.create( { cwd: pkg.contents, prefix: "package/", portable: true, // Provide a specific date in the 1980s for the benefit of zip, // which is confounded by files dated at the Unix epoch 0. // TODO: refactor based on TS feedback // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore mtime: /* @__PURE__ */ new Date("1985-10-26T08:15:00.000Z"), gzip: true }, // NOTE: node-tar does some Magic Stuff depending on prefixes for files // specifically with @ signs, so we just neutralize that one // and any such future "features" by prepending `./` // TODO: refactor based on TS feedback // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore files.map((f) => `./${f}`) ) ); chain = chain.then((stream) => (0, import_temp_write.default)(stream, getTarballName(pkg))); chain = chain.then( (tarFilePath) => (0, import_get_packed.getPacked)(pkg, tarFilePath).then( (packed) => Promise.resolve().then(() => (0, import_run_lifecycle.runLifecycle)(pkg, "postpack", opts)).then(() => packed) ) ); return chain; } function getTarballName(pkg) { const name = pkg.name[0] === "@" ? ( // scoped packages get special treatment pkg.name.substr(1).replace(/\//g, "-") ) : pkg.name; return `${name}-${pkg.version}.tgz`; } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { packDirectory });