({
args,
currentDepth,
nodeResult,
seenNodes,
})
| 478 | ) : true |
| 479 | |
| 480 | const augmentNodesWithMetadata = ({ |
| 481 | args, |
| 482 | currentDepth, |
| 483 | nodeResult, |
| 484 | seenNodes, |
| 485 | }) => (node) => { |
| 486 | // if the original edge was a deduped dep, treeverse will fail to revisit that node in tree traversal logic, so we make it so that we have a diff obj for deduped nodes: |
| 487 | if (seenNodes.has(node.path)) { |
| 488 | const { realpath, root } = node |
| 489 | const targetLocation = root ? relative(root.realpath, realpath) |
| 490 | : node.targetLocation |
| 491 | node = { |
| 492 | name: node.name, |
| 493 | version: node.version, |
| 494 | pkgid: node.pkgid, |
| 495 | package: node.package, |
| 496 | path: node.path, |
| 497 | isLink: node.isLink, |
| 498 | realpath: node.realpath, |
| 499 | targetLocation, |
| 500 | [_type]: node[_type], |
| 501 | [_invalid]: node[_invalid], |
| 502 | [_missing]: node[_missing], |
| 503 | // if it's missing, it's not deduped, it's just missing |
| 504 | [_dedupe]: !node[_missing], |
| 505 | } |
| 506 | } else { |
| 507 | // keeps track of already seen nodes in order to check for dedupes |
| 508 | seenNodes.set(node.path, node) |
| 509 | } |
| 510 | |
| 511 | // _parent is going to be a ref to a treeverse-visited node (returned from getHumanOutputItem, getJsonOutputItem, etc) so that we have an easy shortcut to place new nodes in their right place during tree traversal |
| 512 | node[_parent] = nodeResult |
| 513 | // _include is the property that allow us to filter based on position args |
| 514 | // e.g: `npm ls foo`, `npm ls simple-output@2` |
| 515 | // _filteredBy is used to apply extra color info to the item that was used in args in order to filter |
| 516 | node[_filteredBy] = node[_include] = |
| 517 | filterByPositionalArgs(args, { node: seenNodes.get(node.path) }) |
| 518 | // _depth keeps track of how many levels deep tree traversal currently is so that we can `npm ls --depth=1` |
| 519 | node[_depth] = currentDepth + 1 |
| 520 | |
| 521 | return node |
| 522 | } |
| 523 | |
| 524 | const sortAlphabetically = ({ pkgid: a }, { pkgid: b }) => localeCompare(a, b) |
| 525 |
no test coverage detected