-
-
Save isaacs/a650087db8e9249d2778477ad05e807d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Node = require('./lib/node.js') | |
const gatherDepSet = require('./lib/gather-dep-set.js') | |
const tree = new Node({ | |
path: '/some/path/to/root', | |
pkg: { name: 'root', version: '1.0.0', dependencies: { a: '1', e: '1.x' }}, | |
children: [ | |
{ pkg: { name: 'a', version: '1.0.0', dependencies: { b: '1.x', c: '1.0.x' }}}, | |
{ pkg: { name: 'b', version: '1.0.0', dependencies: { d: '1.0.0' }}}, | |
{ pkg: { name: 'c', version: '1.0.0' }}, | |
{ pkg: { name: 'd', version: '1.0.0' }}, | |
{ pkg: { name: 'e', version: '1.0.0', dependencies: { d: '1.0', e: '1' }}}, | |
], | |
}) | |
const a = tree.children.get('a') | |
const aSet = gatherDepSet([a], edge => edge.to !== a) | |
console.error([...aSet].map(n => n.name)) // [ 'a', 'b', 'c' ] | |
for (const node of tree.inventory.values()) { | |
console.error('NODE', node.package._id, node.path) | |
for (const edge of node.edgesIn) { | |
const self = edge.from === node ? ' (self)' : '' | |
console.error(' EDGE IN ', `${edge.from.name} -> ${edge.type}(${edge.name}@${edge.spec})${self}`) | |
} | |
for (const edge of node.edgesOut.values()) { | |
const self = edge.to === node ? ' (self)' : '' | |
console.error(' EDGE OUT', `${edge.from.name} -> ${edge.type}(${edge.name}@${edge.spec})${self}`) | |
} | |
} |
Author
isaacs
commented
Aug 24, 2021
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment