@lerna/publish
Version:
Publish packages in the current project
85 lines (84 loc) • 3.49 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 make_diff_predicate_exports = {};
__export(make_diff_predicate_exports, {
makeDiffPredicate: () => makeDiffPredicate
});
module.exports = __toCommonJS(make_diff_predicate_exports);
var import_npmlog = __toESM(require("npmlog"));
var import_minimatch = __toESM(require("minimatch"));
var import_path = __toESM(require("path"));
var import_slash = __toESM(require("slash"));
const childProcess = require("@lerna/child-process");
function makeDiffPredicate(committish, execOpts, ignorePatterns = []) {
const ignoreFilters = new Set(
ignorePatterns.map(
(p) => import_minimatch.default.filter(`!${p}`, {
matchBase: true,
// dotfiles inside ignored directories should also match
dot: true
})
)
);
if (ignoreFilters.size) {
import_npmlog.default.info("ignoring diff in paths matching", ignorePatterns);
}
return function hasDiffSinceThatIsntIgnored(node) {
const diff = diffSinceIn(committish, node.location, execOpts);
if (diff === "") {
import_npmlog.default.silly("", "no diff found in %s", node.name);
return false;
}
import_npmlog.default.silly("found diff in", diff);
let changedFiles = diff.split("\n");
if (ignoreFilters.size) {
for (const ignored of ignoreFilters) {
changedFiles = changedFiles.filter(ignored);
}
}
if (changedFiles.length) {
import_npmlog.default.verbose("filtered diff", changedFiles);
} else {
import_npmlog.default.verbose("", "no diff found in %s (after filtering)", node.name);
}
return changedFiles.length > 0;
};
}
function diffSinceIn(committish, location, opts) {
const args = ["diff", "--name-only", committish];
const formattedLocation = (0, import_slash.default)(import_path.default.relative(opts.cwd, location));
if (formattedLocation) {
args.push("--", formattedLocation);
}
import_npmlog.default.silly("checking diff", formattedLocation);
return childProcess.execSync("git", args, opts);
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
makeDiffPredicate
});