UNPKG

@typed/content-hash

Version:

Content hash a directory of HTML/JS/CSS files and other static assets

46 lines 1.9 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getEntrypoints = void 0; const tslib_1 = require("tslib"); const function_1 = require("fp-ts/function"); const RA = (0, tslib_1.__importStar)(require("fp-ts/ReadonlyArray")); const getStronglyConnectedComponents_1 = require("./getStronglyConnectedComponents"); const removeVertice_1 = require("./removeVertice"); const toDependencyMap_1 = require("./toDependencyMap"); function getEntrypoints(graph) { const depedencyMap = (0, toDependencyMap_1.toDependencyMap)(graph); const sccsList = (0, getStronglyConnectedComponents_1.getStronglyConnectedComponents)(graph); const possibleEntrypoints = sccsList.map(toEntrypoint); return possibleEntrypoints.filter((possibility) => isEntrypoint(possibility, depedencyMap, graph)); } exports.getEntrypoints = getEntrypoints; function toEntrypoint(sccs) { if (sccs.length === 1) { return { type: 'acyclic', vertice: sccs[0], }; } return { type: 'cyclic', vertices: sccs, }; } function isEntrypoint(entrypoint, map, graph) { if (entrypoint.type === 'acyclic') { return !(0, function_1.pipe)(Array.from(map.values()), RA.flatten, RA.elem(graph)(entrypoint.vertice)); } for (const vertice of entrypoint.vertices) { const effectiveGraph = (0, function_1.pipe)(entrypoint.vertices, RA.filter((v) => !graph.equals(v)(vertice)), RA.reduce(graph, (g, a) => (0, removeVertice_1.removeVertice)(a, g))); const effectiveDependencyMap = (0, toDependencyMap_1.toDependencyMap)(effectiveGraph); const asEntrypoint = { type: 'acyclic', vertice, }; if (isEntrypoint(asEntrypoint, effectiveDependencyMap, effectiveGraph)) { return true; } } return false; } //# sourceMappingURL=getEntrypoints.js.map