1'use strict' 2module.exports = isExtraneous 3 4function isExtraneous (tree) { 5 var result = !isNotExtraneous(tree) 6 return result 7} 8 9function topHasNoPjson (tree) { 10 var top = tree 11 while (!top.isTop) top = top.parent 12 return top.error 13} 14 15function isNotExtraneous (tree, isCycle) { 16 if (!isCycle) isCycle = {} 17 if (tree.isTop || tree.userRequired) { 18 return true 19 } else if (isCycle[tree.path]) { 20 return topHasNoPjson(tree) 21 } else { 22 isCycle[tree.path] = true 23 return tree.requiredBy && tree.requiredBy.some(function (node) { 24 return isNotExtraneous(node, Object.create(isCycle)) 25 }) 26 } 27} 28