You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

18 lines
462 B

'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)
})
}