"Fossies" - the Fresh Open Source Software Archive

Member "Atom/resources/app/apm/node_modules/npm/lib/install/inflate-shrinkwrap.js" (25 Apr 2018, 3739 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   var dev = npm.config.get('dev') || (!/^prod(uction)?$/.test(npm.config.get('only')) && !npm.config.get('production')) || /^dev(elopment)?$/.test(npm.config.get('only'))
   28   var prod = !/^dev(elopment)?$/.test(npm.config.get('only'))
   29   return asyncMap(Object.keys(swdeps), doRealizeAndInflate, finishInflating)
   30 
   31   function doRealizeAndInflate (name, next) {
   32     return realizeShrinkwrapSpecifier(name, swdeps[name], topPath, iferr(next, andInflate(name, next)))
   33   }
   34 
   35   function andInflate (name, next) {
   36     return function (requested) {
   37       var sw = swdeps[name]
   38       var dependencies = sw.dependencies || {}
   39       if ((!prod && !sw.dev) || (!dev && sw.dev)) return next()
   40       var child = onDisk[name]
   41       if (childIsEquivalent(sw, requested, child)) {
   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         var optional = sw.optional
   49         return fetchPackageMetadata(requested, topPath, iferr(next, andAddShrinkwrap(from, optional, dependencies, next)))
   50       }
   51     }
   52   }
   53 
   54   function andAddShrinkwrap (from, optional, dependencies, next) {
   55     return function (pkg) {
   56       pkg._from = from
   57       pkg._optional = optional
   58       addShrinkwrap(pkg, iferr(next, andAddBundled(pkg, dependencies, next)))
   59     }
   60   }
   61 
   62   function andAddBundled (pkg, dependencies, next) {
   63     return function () {
   64       return addBundled(pkg, iferr(next, andAddChild(pkg, dependencies, next)))
   65     }
   66   }
   67 
   68   function andAddChild (pkg, dependencies, next) {
   69     return function () {
   70       var child = createChild({
   71         package: pkg,
   72         loaded: false,
   73         parent: tree,
   74         fromShrinkwrap: pkg._from,
   75         path: childPath(tree.path, pkg),
   76         realpath: childPath(tree.realpath, pkg),
   77         children: pkg._bundled || []
   78       })
   79       tree.children.push(child)
   80       if (pkg._bundled) {
   81         delete pkg._bundled
   82         inflateBundled(child, child.children)
   83       }
   84       inflateShrinkwrap(topPath, child, dependencies || {}, next)
   85     }
   86   }
   87 }
   88 
   89 function childIsEquivalent (sw, requested, child) {
   90   if (!child) return false
   91   if (child.fromShrinkwrap) return true
   92   if (sw.resolved) return child.package._resolved === sw.resolved
   93   if (!isRegistrySpecifier(requested) && sw.from) return child.package._from === sw.from
   94   return child.package.version === sw.version
   95 }