({
args,
currentDepth,
nodeResult,
seenNodes,
})
| 462 | ) : true |
| 463 | |
| 464 | const augmentNodesWithMetadata = ({ |
| 465 | args, |
| 466 | currentDepth, |
| 467 | nodeResult, |
| 468 | seenNodes, |
| 469 | }) => (node) => { |
| 470 | // 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: |
| 471 | if (seenNodes.has(node.path)) { |
| 472 | const { realpath, root } = node |
| 473 | const targetLocation = root ? relative(root.realpath, realpath) |
| 474 | : node.targetLocation |
| 475 | node = { |
| 476 | name: node.name, |
| 477 | version: node.version, |
| 478 | pkgid: node.pkgid, |
| 479 | package: node.package, |
| 480 | path: node.path, |
| 481 | isLink: node.isLink, |
| 482 | realpath: node.realpath, |
| 483 | targetLocation, |
| 484 | [_type]: node[_type], |
| 485 | [_invalid]: node[_invalid], |
| 486 | [_missing]: node[_missing], |
| 487 | // if it's missing, it's not deduped, it's just missing |
| 488 | [_dedupe]: !node[_missing], |
| 489 | } |
| 490 | } else { |
| 491 | // keeps track of already seen nodes in order to check for dedupes |
| 492 | seenNodes.set(node.path, node) |
| 493 | } |
| 494 | |
| 495 | // _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 |
| 496 | node[_parent] = nodeResult |
| 497 | // _include is the property that allow us to filter based on position args |
| 498 | // e.g: `npm ls foo`, `npm ls simple-output@2` |
| 499 | // _filteredBy is used to apply extra color info to the item that was used in args in order to filter |
| 500 | node[_filteredBy] = node[_include] = |
| 501 | filterByPositionalArgs(args, { node: seenNodes.get(node.path) }) |
| 502 | // _depth keeps track of how many levels deep tree traversal currently is so that we can `npm ls --depth=1` |
| 503 | node[_depth] = currentDepth + 1 |
| 504 | |
| 505 | return node |
| 506 | } |
| 507 | |
| 508 | const sortAlphabetically = ({ pkgid: a }, { pkgid: b }) => localeCompare(a, b) |
| 509 |
no test coverage detected