lerna
Version:
Lerna is a fast, modern build system for managing and publishing multiple JavaScript/TypeScript packages from the same repository
61 lines (58 loc) • 1.55 kB
JavaScript
import {
getLastCommit
} from "./chunk-ZPJ6LV2C.js";
import {
hasCommit
} from "./chunk-RBM6ZKDG.js";
import {
Command,
ValidationError,
getPackage,
spawn
} from "./chunk-WC2B4V4E.js";
// libs/commands/diff/src/index.ts
function factory(argv) {
return new DiffCommand(argv);
}
var DiffCommand = class extends Command {
args = [];
initialize() {
const packageName = this.options.pkgName;
let targetPackage;
if (packageName) {
const project = Object.values(this.projectGraph.nodes).find(
(p) => p.package && getPackage(p).name === packageName
);
targetPackage = project && getPackage(project);
if (!targetPackage) {
throw new ValidationError("ENOPKG", `Cannot diff, the package '${packageName}' does not exist.`);
}
}
if (!hasCommit(this.execOpts)) {
throw new ValidationError("ENOCOMMITS", "Cannot diff, there are no commits in this repository yet.");
}
const args = ["diff", getLastCommit(this.execOpts), "--color=auto"];
if (targetPackage) {
args.push("--", targetPackage.location);
} else {
args.push("--", ...this.project.packageParentDirs);
}
if (this.options.ignoreChanges) {
this.options.ignoreChanges.forEach((ignorePattern) => {
args.push(`:(exclude,glob)${ignorePattern}`);
});
}
this.args = args;
}
execute() {
return spawn("git", this.args, this.execOpts).catch((err) => {
if (err.exitCode) {
throw err;
}
});
}
};
export {
factory,
DiffCommand
};