Skip to content

Commit

Permalink
install: improve isOnly(Dev,Optional)
Browse files Browse the repository at this point in the history
Instead of creating a new set each time a new node gets visited, so that
its siblings do not have it in `seen`, just remove the node from the
original set right after all child nodes are visited.

See #76

Credit: @larsgw

PR-URL: #206
Close: #206
Reviewed-by: @isaacs
  • Loading branch information
larsgw authored and isaacs committed Jul 3, 2019
1 parent 8dfbe86 commit a81a8c4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
5 changes: 3 additions & 2 deletions lib/install/is-only-dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@ function andIsOnlyDev (name, seen) {
return isDev && !isProd
} else {
if (seen.has(req)) return true
seen = new Set(seen)
seen.add(req)
return isOnlyDev(req, seen)
const result = isOnlyDev(req, seen)
seen.delete(req)
return result
}
}
}
5 changes: 3 additions & 2 deletions lib/install/is-only-optional.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ function isOptional (node, seen) {
if (seen.has(node) || node.requiredBy.length === 0) {
return false
}
seen = new Set(seen)
seen.add(node)
const swOptional = node.fromShrinkwrap && node.package._optional
return node.requiredBy.every(function (req) {
const result = node.requiredBy.every(function (req) {
if (req.fakeChild && swOptional) return true
return isOptDep(req, moduleName(node)) || isOptional(req, seen)
})
seen.delete(node)
return result
}

0 comments on commit a81a8c4

Please # to comment.