UNPKG

@nodesecure/tree-walker

Version:
29 lines 1.06 kB
// Import Node.js Dependencies import path from "node:path"; import fs from "node:fs/promises"; // Import Third-party Dependencies import Arborist from "@npmcli/arborist"; // Import Internal Dependencies import { TreeDependencies } from "./TreeDependencies.js"; import * as utils from "../utils/index.js"; export class LocalDependencyTreeLoader { async load(location, options = {}) { const { registry, ...treeDepOptions } = options; const arb = new Arborist({ ...utils.NPM_TOKEN, path: location, registry }); try { await fs.access(path.join(location, "node_modules")); await arb.loadActual(); const treeNode = await arb.buildIdealTree(); return TreeDependencies.fromArboristNode(treeNode, treeDepOptions); } catch { const treeNode = await arb.loadVirtual(); return TreeDependencies.fromArboristNode(treeNode, treeDepOptions); } } } //# sourceMappingURL=LocalDependencyTreeLoader.js.map