@rushstack/heft
Version:
Build all your JavaScript projects the same way: A way that works.
81 lines • 2.37 kB
JavaScript
;
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
// See LICENSE in the project root for license information.
Object.defineProperty(exports, "__esModule", { value: true });
exports.Selection = void 0;
/**
* This namespace contains functions for manipulating sets of projects
*/
class Selection {
/**
* Computes the set of projects that are not in the input set.
*/
static difference(first, ...rest) {
return new Set(generateDifference(first, ...rest));
}
/**
* Computes the set of direct dependencies of the listed projects.
*/
static directDependenciesOf(input, expandFn) {
const result = new Set();
for (const item of input) {
expandInto(result, item, expandFn);
}
return result;
}
/**
* Computes the intersection of two or more sets.
*/
static intersection(first, ...rest) {
return new Set(generateIntersection(first, ...rest));
}
/**
* Computes the union of two or more sets.
*/
static union(...sets) {
return new Set(generateConcatenation(...sets));
}
/**
* Computes a set that contains all inputs and recursively expanded inputs.
*/
static recursiveExpand(input, expandFn) {
return expandAll(input, expandFn);
}
}
exports.Selection = Selection;
function* generateDifference(first, ...rest) {
for (const item of first) {
if (rest.every((set) => !set.has(item))) {
yield item;
}
}
}
function* generateIntersection(first, ...rest) {
for (const item of first) {
if (rest.every((set) => set.has(item))) {
yield item;
}
}
}
function* generateConcatenation(...sets) {
for (const set of sets) {
yield* set;
}
}
function expandInto(targetSet, input, expandFn) {
for (const child of expandFn(input)) {
targetSet.add(child);
}
}
/**
* Computes a set derived from the input by cloning it, then iterating over every member of the new set and
* calling a step function that may add more elements to the set.
*/
function expandAll(input, expandFn) {
const result = new Set(input);
for (const item of result) {
expandInto(result, item, expandFn);
}
return result;
}
//# sourceMappingURL=Selection.js.map