Skip to content

Commit 7daaf64

Browse files
author
Milan Meva
committed
fix: modified comments and refactored redundant code
1 parent 4fa2cf5 commit 7daaf64

File tree

3 files changed

+12
-35
lines changed

3 files changed

+12
-35
lines changed

lib/commands/ls.js

Lines changed: 5 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,10 @@ class LS extends ArboristWorkspaceCmd {
144144
},
145145
visit (node) {
146146
// add to seenNodes as soon as we visit and not when the children are calculated in previous call
147-
if (!seenNodes.has(node.path)) {
148-
seenNodes.set(node.path, node)
149-
} else {
147+
if (seenNodes.has(node.path)) {
150148
node[_dedupe] = !node[_missing]
149+
} else {
150+
seenNodes.set(node.path, node)
151151
}
152152

153153
node[_problems] = getProblems(node, { global })
@@ -507,33 +507,8 @@ const augmentNodesWithMetadata = ({
507507
args,
508508
currentDepth,
509509
nodeResult,
510-
seenNodes,
511510
}) => (node) => {
512-
// if the original edge was a deduped dep, treeverse will fail to
513-
// revisit that node in tree traversal logic, so we make it so that
514-
// we have a diff obj for deduped nodes:
515-
if (seenNodes.has(node.path)) {
516-
node = {
517-
name: node.name,
518-
version: node.version,
519-
pkgid: node.pkgid,
520-
target: node.target,
521-
edgesOut: node.edgesOut,
522-
children: node.children,
523-
package: node.package,
524-
path: node.path,
525-
isLink: node.isLink,
526-
realpath: node.realpath,
527-
targetLocation: node.targetLocation,
528-
[_type]: node[_type],
529-
[_invalid]: node[_invalid],
530-
[_missing]: node[_missing],
531-
// if it's missing, it's not deduped, it's just missing
532-
[_dedupe]: !node[_missing],
533-
}
534-
}
535-
536-
// _parent is going to be a ref to a treeverse-visited node (returned from
511+
// _parent is going to be a ref to a traversed node (returned from
537512
// getHumanOutputItem, getJsonOutputItem, etc) so that we have an easy
538513
// shortcut to place new nodes in their right place during tree traversal
539514
node[_parent] = nodeResult
@@ -542,11 +517,7 @@ const augmentNodesWithMetadata = ({
542517
// _filteredBy is used to apply extra color info to the item that
543518
// was used in args in order to filter
544519
node[_filteredBy] = node[_include] =
545-
filterByPositionalArgs(args, {
546-
node: seenNodes.has(node.path)
547-
? seenNodes.get(node.path)
548-
: node,
549-
})
520+
filterByPositionalArgs(args, { node })
550521
// _depth keeps track of how many levels deep tree traversal currently is
551522
// so that we can `npm ls --depth=1`
552523
node[_depth] = currentDepth + 1

tap-snapshots/test/lib/commands/ls.js.test.cjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@ exports[`test/lib/commands/ls.js TAP ls missing package.json > should output tre
528528
+-- [email protected] extraneous
529529
+-- [email protected] extraneous
530530
\`-- [email protected] extraneous
531-
\`-- [email protected] deduped
531+
\`-- [email protected] deduped extraneous
532532
`
533533

534534
exports[`test/lib/commands/ls.js TAP ls missing/invalid/extraneous > should output tree containing missing, invalid, extraneous labels 1`] = `

test/lib/commands/ls.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2748,6 +2748,11 @@ t.test('ls --json', async t => {
27482748
dependencies: {
27492749
dog: {
27502750
version: '1.0.0',
2751+
extraneous: true,
2752+
overridden: false,
2753+
problems: [
2754+
'extraneous: [email protected] {CWD}/prefix/node_modules/dog',
2755+
],
27512756
},
27522757
},
27532758
},
@@ -4103,6 +4108,7 @@ t.test('ls --json', async t => {
41034108
dependencies: {
41044109
a: {
41054110
version: '1.0.0',
4111+
overridden: false,
41064112
},
41074113
},
41084114
},

0 commit comments

Comments
 (0)