Created
November 8, 2021 17:08
-
-
Save isaacs/8298932a0e7507a3b8bf893f519e4996 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('../') | |
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