"Fossies" - the Fresh Open Source Software Archive

Member "Atom/resources/app/apm/node_modules/npm/lib/install/is-extraneous.js" (7 Feb 2017, 889 Bytes) of archive /windows/misc/atom-windows.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Javascript source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

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