Skip to content

Instantly share code, notes, and snippets.

@isaacs
Last active November 8, 2021 17:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save isaacs/8b5877403ac3ed8492ee1b5ec830d5aa to your computer and use it in GitHub Desktop.
Save isaacs/8b5877403ac3ed8492ee1b5ec830d5aa to your computer and use it in GitHub Desktop.
const {Node} = require('../')
const tree = new Node({
path: '/some/path',
pkg: { dependencies: { foo: '' }},
children: [
{
pkg: {name:'foo',version:'1.2.3',dependencies:{bar:''}},
children: [{pkg: {name:'bar',version:'1.2.3'}}],
},
],
})
for (const node of tree.inventory.values()) {
console.log(node.path, node.version)
if (node.name === 'foo') {
for (const kid of node.children.values()) {
console.log('deleting', kid.path, kid.version)
kid.root = null
}
}
}
/*
/some/path
/some/path/node_modules/foo 1.2.3
deleting /some/path/node_modules/foo/node_modules/bar 1.2.3
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment