Last active
November 8, 2021 17:08
-
-
Save isaacs/8b5877403ac3ed8492ee1b5ec830d5aa 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 | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment