Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

install: improve isOnly(Dev,Optional) #206

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
install: improve isOnly(Dev,Optional)
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
  • Loading branch information
larsgw committed Jul 1, 2019
commit 4695de859bcdb8f46dc0d9c7a183d013c37cce98
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
}