UNPKG

@lerna/publish

Version:

Publish packages in the current project

92 lines (91 loc) 3.33 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 get_packed_exports = {}; __export(get_packed_exports, { getPacked: () => getPacked }); module.exports = __toCommonJS(get_packed_exports); var import_fs_extra = __toESM(require("fs-extra")); var import_path = __toESM(require("path")); var import_ssri = __toESM(require("ssri")); var import_tar = __toESM(require("tar")); function getPacked(pkg, tarFilePath) { const bundledWanted = new Set(pkg.bundleDependencies || pkg.bundledDependencies || []); const bundled = /* @__PURE__ */ new Set(); const files = []; let totalEntries = 0; let totalEntrySize = 0; return import_tar.default.list({ file: tarFilePath, onentry(entry) { totalEntries += 1; totalEntrySize += entry.size; const p = entry.path; if (p.startsWith("package/node_modules/")) { const name = p.match(/^package\/node_modules\/((?:@[^/]+\/)?[^/]+)/)[1]; if (bundledWanted.has(name)) { bundled.add(name); } } else { files.push({ path: entry.path.replace(/^package\//, ""), size: entry.size, mode: entry.mode }); } }, strip: 1 }).then( () => Promise.all([ import_fs_extra.default.stat(tarFilePath), import_ssri.default.fromStream(import_fs_extra.default.createReadStream(tarFilePath), { algorithms: ["sha1", "sha512"] }) ]) ).then(([{ size }, { sha1, sha512 }]) => { const shasum = sha1[0].hexDigest(); return { id: `${pkg.name}@${pkg.version}`, name: pkg.name, version: pkg.version, size, unpackedSize: totalEntrySize, shasum, integrity: import_ssri.default.parse(sha512[0]), filename: import_path.default.basename(tarFilePath), files, entryCount: totalEntries, bundled: Array.from(bundled), tarFilePath }; }); } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { getPacked });