aboutsummaryrefslogtreecommitdiff
path: root/deps/npm/lib/install/is-only-optional.js
diff options
context:
space:
mode:
Diffstat (limited to 'deps/npm/lib/install/is-only-optional.js')
-rw-r--r--deps/npm/lib/install/is-only-optional.js18
1 files changed, 18 insertions, 0 deletions
diff --git a/deps/npm/lib/install/is-only-optional.js b/deps/npm/lib/install/is-only-optional.js
new file mode 100644
index 0000000000..7366e9abe1
--- /dev/null
+++ b/deps/npm/lib/install/is-only-optional.js
@@ -0,0 +1,18 @@
+'use strict'
+module.exports = isOptional
+
+const isOptDep = require('./is-opt-dep.js')
+
+function isOptional (node, seen) {
+ if (!seen) seen = new Set()
+ // If a node is not required by anything, then we've reached
+ // the top level package.
+ if (seen.has(node) || node.requiredBy.length === 0) {
+ return false
+ }
+ seen.add(node)
+
+ return node.requiredBy.every(function (req) {
+ return isOptDep(req, node.package.name) || isOptional(req, seen)
+ })
+}