UNPKG

@lerna/publish

Version:

Publish packages in the current project

86 lines (85 loc) 3.64 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 describe_ref_exports = {}; __export(describe_ref_exports, { describeRef: () => describeRef, describeRefSync: () => describeRefSync }); module.exports = __toCommonJS(describe_ref_exports); var import_npmlog = __toESM(require("npmlog")); const childProcess = require("@lerna/child-process"); function getArgs(options, includeMergedTags = false) { let args = [ "describe", // fallback to short sha if no tags located "--always", // always return full result, helps identify existing release "--long", // annotate if uncommitted changes present "--dirty", // prefer tags originating on upstream branch "--first-parent" ]; if (options.match) { args.push("--match", options.match); } if (includeMergedTags) { args = args.filter((arg) => arg !== "--first-parent"); } return args; } function describeRef(options = {}, includeMergedTags) { const promise = childProcess.exec("git", getArgs(options, includeMergedTags), options); return promise.then(({ stdout }) => { const result = parse(stdout, options.cwd); import_npmlog.default.verbose("git-describe", "%j => %j", options && options.match, stdout); import_npmlog.default.silly("git-describe", "parsed => %j", result); return result; }); } function describeRefSync(options = {}, includeMergedTags) { const stdout = childProcess.execSync("git", getArgs(options, includeMergedTags), options); const result = parse(stdout, options.cwd); import_npmlog.default.silly("git-describe.sync", "%j => %j", stdout, result); return result; } function parse(stdout, cwd) { const minimalShaRegex = /^([0-9a-f]{7,40})(-dirty)?$/; if (minimalShaRegex.test(stdout)) { const [, sha2, isDirty2] = minimalShaRegex.exec(stdout); const refCount2 = childProcess.execSync("git", ["rev-list", "--count", sha2], { cwd }); return { refCount: refCount2, sha: sha2, isDirty: Boolean(isDirty2) }; } const [, lastTagName, lastVersion, refCount, sha, isDirty] = /^((?:.*@)?(.*))-(\d+)-g([0-9a-f]+)(-dirty)?$/.exec(stdout) || []; return { lastTagName, lastVersion, refCount, sha, isDirty: Boolean(isDirty) }; } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { describeRef, describeRefSync });