Skip to content

Instantly share code, notes, and snippets.

@isaacs
Last active August 24, 2021 15:57
Show Gist options
  • Save isaacs/a650087db8e9249d2778477ad05e807d to your computer and use it in GitHub Desktop.
Save isaacs/a650087db8e9249d2778477ad05e807d to your computer and use it in GitHub Desktop.
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}`)
}
}
@isaacs
Copy link
Author

isaacs commented Aug 24, 2021

[ 'a', 'b', 'c' ]
NODE root@1.0.0 /some/path/to/root
  EDGE OUT root -> prod(a@1)
  EDGE OUT root -> prod(e@1.x)
NODE a@1.0.0 /some/path/to/root/node_modules/a
  EDGE IN  root -> prod(a@1)
  EDGE OUT a -> prod(b@1.x)
  EDGE OUT a -> prod(c@1.0.x)
NODE b@1.0.0 /some/path/to/root/node_modules/b
  EDGE IN  a -> prod(b@1.x)
  EDGE OUT b -> prod(d@1.0.0)
NODE c@1.0.0 /some/path/to/root/node_modules/c
  EDGE IN  a -> prod(c@1.0.x)
NODE d@1.0.0 /some/path/to/root/node_modules/d
  EDGE IN  b -> prod(d@1.0.0)
  EDGE IN  e -> prod(d@1.0)
NODE e@1.0.0 /some/path/to/root/node_modules/e
  EDGE IN  e -> prod(e@1) (self)
  EDGE IN  root -> prod(e@1.x)
  EDGE OUT e -> prod(d@1.0)
  EDGE OUT e -> prod(e@1) (self)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment