workspace-tools
Version:
A collection of utilities that are useful in a git-controlled monorepo managed by one of these tools:
52 lines • 2.12 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getChangedPackages = exports.getChangedPackagesBetweenRefs = void 0;
const git_1 = require("../git");
const getPackagesByFiles_1 = require("./getPackagesByFiles");
function getChangedPackagesBetweenRefs(paramsOrCwd, _fromRef, _toRef, _ignoreGlobs, _returnAllPackagesOnNoMatch) {
const params = typeof paramsOrCwd === "string"
? {
cwd: paramsOrCwd,
fromRef: _fromRef,
toRef: _toRef,
ignoreGlobs: _ignoreGlobs,
returnAllPackagesOnNoMatch: _returnAllPackagesOnNoMatch,
}
: paramsOrCwd;
const { fromRef, toRef, ignoreGlobs, returnAllPackagesOnNoMatch = true, ...gitOptions } = params;
gitOptions.throwOnError ?? (gitOptions.throwOnError = true);
const changes = [
...new Set([
...(0, git_1.getUntrackedChanges)(gitOptions),
...(0, git_1.getUnstagedChanges)(gitOptions),
...(0, git_1.getChangesBetweenRefs)({ fromRef, toRef, ...gitOptions }),
...(0, git_1.getStagedChanges)(gitOptions),
]),
];
return (0, getPackagesByFiles_1.getPackagesByFiles)({
root: gitOptions.cwd,
files: changes,
ignoreGlobs,
returnAllPackagesOnNoMatch,
});
}
exports.getChangedPackagesBetweenRefs = getChangedPackagesBetweenRefs;
function getChangedPackages(cwdOrOptions, target, ignoreGlobs, returnAllPackagesOnNoMatch) {
let gitOptions;
if (typeof cwdOrOptions === "string") {
gitOptions = { cwd: cwdOrOptions };
}
else {
({ target, ignoreGlobs, returnAllPackagesOnNoMatch, ...gitOptions } = cwdOrOptions);
}
gitOptions.throwOnError ?? (gitOptions.throwOnError = true);
const targetBranch = target || (0, git_1.getDefaultRemoteBranch)(gitOptions);
return getChangedPackagesBetweenRefs({
fromRef: targetBranch,
...gitOptions,
ignoreGlobs,
returnAllPackagesOnNoMatch,
});
}
exports.getChangedPackages = getChangedPackages;
//# sourceMappingURL=getChangedPackages.js.map