UNPKG

bit-bin

Version:

<a href="https://opensource.org/licenses/Apache-2.0"><img alt="apache" src="https://img.shields.io/badge/License-Apache%202.0-blue.svg"></a> <a href="https://github.com/teambit/bit/blob/master/CONTRIBUTING.md"><img alt="prs" src="https://img.shields.io/b

48 lines (38 loc) 1.25 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.createSubGraph = createSubGraph; exports.getNeighborsByDirection = getNeighborsByDirection; function _ramda() { const data = require("ramda"); _ramda = function () { return data; }; return data; } function createSubGraph(components, options, graph) { const shouldStay = (0, _ramda().uniq)((0, _ramda().flatten)(components.map(comp => { const id = comp.id.toString(); const base = [id]; let pre = []; let post = []; if (options.traverse === 'both' || options.traverse === 'dependencies') { pre = getNeighborsByDirection(id, graph, 'predecessors'); } if (options.traverse === 'both' || options.traverse === 'dependents') { post = getNeighborsByDirection(id, graph); } return base.concat(post).concat(pre); }))); return graph.nodes().reduce((g, curr) => { if (!shouldStay.includes(curr)) { g.removeNode(curr); } return graph; }, graph); } function getNeighborsByDirection(id, g, direction = 'successors') { const neighbors = g[direction](id) || []; return neighbors.concat(neighbors.map(pre => (0, _ramda().flatten)(getNeighborsByDirection(pre, g, direction)))); }