"Fossies" - the Fresh Open Source Software Archive

Member "Atom/resources/app/apm/node_modules/npm/lib/install/flatten-tree.js" (31 May 2018, 1023 Bytes) of package /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 var validate = require('aproba')
    3 var moduleName = require('../utils/module-name.js')
    4 
    5 module.exports = flattenTree
    6 module.exports.flatName = flatName
    7 module.exports.flatNameFromTree = flatNameFromTree
    8 
    9 function flattenTree (tree) {
   10   validate('O', arguments)
   11   var seen = {}
   12   var flat = {}
   13   var todo = [[tree, '/']]
   14   while (todo.length) {
   15     var next = todo.shift()
   16     var pkg = next[0]
   17     seen[pkg.path] = true
   18     var path = next[1]
   19     flat[path] = pkg
   20     if (path !== '/') path += '/'
   21     for (var ii = 0; ii < pkg.children.length; ++ii) {
   22       var child = pkg.children[ii]
   23       if (!seen[child.path]) {
   24         todo.push([child, flatName(path, child)])
   25       }
   26     }
   27   }
   28   return flat
   29 }
   30 
   31 function flatName (path, child) {
   32   validate('SO', arguments)
   33   return path + (moduleName(child) || 'TOP')
   34 }
   35 
   36 function flatNameFromTree (tree) {
   37   validate('O', arguments)
   38   if (tree.isTop) return '/'
   39   var path = flatNameFromTree(tree.parent)
   40   if (path !== '/') path += '/'
   41   return flatName(path, tree)
   42 }