Skip to content

Instantly share code, notes, and snippets.

@isaacs
Created 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/8298932a0e7507a3b8bf893f519e4996 to your computer and use it in GitHub Desktop.
Save isaacs/8298932a0e7507a3b8bf893f519e4996 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
/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