UNPKG

npminstall

Version:

Make npm install fast and handy.

34 lines (26 loc) 595 B
class Nested { constructor(pkgs, parent) { this.depMap = new Map(); this.update(pkgs, parent); } update(pkgs, parent) { pkgs.forEach(pkg => { this.depMap.set(pkg, parent || 'root'); }); } showPath(raw) { const raws = [ raw ]; let currentRaw = raw; while (this.depMap.has(currentRaw)) { const parent = this.depMap.get(currentRaw); // cycle nested deps if (raws.includes(parent)) { break; } raws.unshift(parent); currentRaw = parent; } return raws.join(' › '); } } module.exports = Nested;