blob: 81e227bae7a89c947fd65efc17344241266a28fb (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
'use strict'
module.exports = isOptional
const isOptDep = require('./is-opt-dep.js')
const moduleName = require('../utils/module-name.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 = new Set(seen)
seen.add(node)
const swOptional = node.fromShrinkwrap && node.package._optional
return node.requiredBy.every(function (req) {
if (req.fakeChild && swOptional) return true
return isOptDep(req, moduleName(node)) || isOptional(req, seen)
})
}
|