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 npm#76
  • Loading branch information
larsgw committed Jul 1, 2019
1 parent eee0bcd commit 4695de8
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 4695de8

Please sign in to comment.