UNPKG

@nodesecure/tree-walker

Version:
28 lines 1.03 kB
/* eslint-disable func-style */ // Import Third-party Dependencies import Arborist from "@npmcli/arborist"; import * as iter from "itertools"; export class TreeDependencies { dependencies; static fromArboristNode(node, options = {}) { const { includeDevDeps = false } = options; const shouldIncludeEdge = ([packageName, edge]) => { const { to } = edge; if (to === null) { return []; } const shouldInclude = includeDevDeps || to.dev === false || to.isWorkspace; if (!shouldInclude) { return []; } const targetNode = to.isWorkspace ? to.target : to; return [[packageName, targetNode]]; }; const dependencies = new Map(iter.flatmap(node.edgesOut.entries(), shouldIncludeEdge)); return new TreeDependencies(dependencies); } constructor(dependencies) { this.dependencies = dependencies; } } //# sourceMappingURL=TreeDependencies.js.map