File: /home/frenchy/www/extracts/var/www/french-american.org/current/node_modules/snyk/dist/lib/prune.js
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const _debug = require("debug");
const dep_graph_1 = require("@snyk/dep-graph");
const config = require("./config");
const errors_1 = require("./errors");
const debug = _debug('snyk:prune');
const { depTreeToGraph, graphToDepTree } = dep_graph_1.legacy;
function countPathsToGraphRoot(graph) {
return graph
.getPkgs()
.reduce((acc, pkg) => acc + graph.countPathsToRoot(pkg), 0);
}
exports.countPathsToGraphRoot = countPathsToGraphRoot;
function pruneGraph(depGraph, packageManager) {
return __awaiter(this, void 0, void 0, function* () {
try {
// Arbitrary threshold for maximum number of elements in the tree
const threshold = config.PRUNE_DEPS_THRESHOLD;
const prunedTree = (yield graphToDepTree(depGraph, packageManager, {
deduplicateWithinTopLevelDeps: true,
}));
const prunedGraph = yield depTreeToGraph(prunedTree, packageManager);
const count = countPathsToGraphRoot(prunedGraph);
debug('prunedPathsCount: ' + count);
if (count < threshold) {
return prunedGraph;
}
debug('Too many vulnerable paths to process the project');
throw new errors_1.TooManyVulnPaths();
}
catch (e) {
debug('Failed to prune the graph, returning original: ' + e);
return depGraph;
}
});
}
exports.pruneGraph = pruneGraph;
//# sourceMappingURL=prune.js.map