"Fossies" - the Fresh Open Source Software Archive

Member "Atom/resources/app/apm/node_modules/npm/lib/install/inflate-shrinkwrap.js" (11 Apr 2017, 3257 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 asyncMap = require('slide').asyncMap
    3 var validate = require('aproba')
    4 var iferr = require('iferr')
    5 var realizeShrinkwrapSpecifier = require('./realize-shrinkwrap-specifier.js')
    6 var isRegistrySpecifier = require('./is-registry-specifier.js')
    7 var fetchPackageMetadata = require('../fetch-package-metadata.js')
    8 var annotateMetadata = require('../fetch-package-metadata.js').annotateMetadata
    9 var addShrinkwrap = require('../fetch-package-metadata.js').addShrinkwrap
   10 var addBundled = require('../fetch-package-metadata.js').addBundled
   11 var inflateBundled = require('./inflate-bundled.js')
   12 var npm = require('../npm.js')
   13 var createChild = require('./node.js').create
   14 var moduleName = require('../utils/module-name.js')
   15 var childPath = require('../utils/child-path.js')
   16 
   17 module.exports = function (tree, swdeps, finishInflating) {
   18   if (!npm.config.get('shrinkwrap')) return finishInflating()
   19   return inflateShrinkwrap(tree.path, tree, swdeps, finishInflating)
   20 }
   21 
   22 function inflateShrinkwrap (topPath, tree, swdeps, finishInflating) {
   23   validate('SOOF', arguments)
   24   var onDisk = {}
   25   tree.children.forEach(function (child) { onDisk[moduleName(child)] = child })
   26   tree.children = []
   27   return asyncMap(Object.keys(swdeps), doRealizeAndInflate, finishInflating)
   28 
   29   function doRealizeAndInflate (name, next) {
   30     return realizeShrinkwrapSpecifier(name, swdeps[name], topPath, iferr(next, andInflate(name, next)))
   31   }
   32 
   33   function andInflate (name, next) {
   34     return function (requested) {
   35       var sw = swdeps[name]
   36       var dependencies = sw.dependencies || {}
   37       var child = onDisk[name]
   38       if (child && (child.fromShrinkwrap ||
   39                     (sw.resolved && child.package._resolved === sw.resolved) ||
   40                     (!isRegistrySpecifier(requested) && child.package._from === sw.from) ||
   41                     child.package.version === sw.version)) {
   42         if (!child.fromShrinkwrap) child.fromShrinkwrap = requested.raw
   43         tree.children.push(child)
   44         annotateMetadata(child.package, requested, requested.raw, topPath)
   45         return inflateShrinkwrap(topPath, child, dependencies || {}, next)
   46       } else {
   47         var from = sw.from || requested.raw
   48         return fetchPackageMetadata(requested, topPath, iferr(next, andAddShrinkwrap(from, dependencies, next)))
   49       }
   50     }
   51   }
   52 
   53   function andAddShrinkwrap (from, dependencies, next) {
   54     return function (pkg) {
   55       pkg._from = from
   56       addShrinkwrap(pkg, iferr(next, andAddBundled(pkg, dependencies, next)))
   57     }
   58   }
   59 
   60   function andAddBundled (pkg, dependencies, next) {
   61     return function () {
   62       return addBundled(pkg, iferr(next, andAddChild(pkg, dependencies, next)))
   63     }
   64   }
   65 
   66   function andAddChild (pkg, dependencies, next) {
   67     return function () {
   68       var child = createChild({
   69         package: pkg,
   70         loaded: false,
   71         parent: tree,
   72         fromShrinkwrap: pkg._from,
   73         path: childPath(tree.path, pkg),
   74         realpath: childPath(tree.realpath, pkg),
   75         children: pkg._bundled || []
   76       })
   77       tree.children.push(child)
   78       if (pkg._bundled) {
   79         delete pkg._bundled
   80         inflateBundled(child, child.children)
   81       }
   82       inflateShrinkwrap(topPath, child, dependencies || {}, next)
   83     }
   84   }
   85 }