"Fossies" - the Fresh Open Source Software Archive

Member "Atom/resources/app/apm/node_modules/npm/lib/install/action/extract.js" (8 Mar 2017, 2860 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 var path = require('path')
    3 var iferr = require('iferr')
    4 var asyncMap = require('slide').asyncMap
    5 var fs = require('graceful-fs')
    6 var rename = require('../../utils/rename.js')
    7 var gentlyRm = require('../../utils/gently-rm.js')
    8 var updatePackageJson = require('../update-package-json')
    9 var npm = require('../../npm.js')
   10 var moduleName = require('../../utils/module-name.js')
   11 var packageId = require('../../utils/package-id.js')
   12 var cache = require('../../cache.js')
   13 var buildPath = require('../build-path.js')
   14 
   15 module.exports = function (top, buildpath, pkg, log, next) {
   16   log.silly('extract', packageId(pkg))
   17   var up = npm.config.get('unsafe-perm')
   18   var user = up ? null : npm.config.get('user')
   19   var group = up ? null : npm.config.get('group')
   20   cache.unpack(pkg.package.name, pkg.package.version, buildpath, null, null, user, group,
   21         andUpdatePackageJson(pkg, buildpath, andStageBundledChildren(pkg, buildpath, log, next)))
   22 }
   23 
   24 function andUpdatePackageJson (pkg, buildpath, next) {
   25   return iferr(next, function () {
   26     updatePackageJson(pkg, buildpath, next)
   27   })
   28 }
   29 
   30 function andStageBundledChildren (pkg, buildpath, log, next) {
   31   var staging = path.resolve(buildpath, '..')
   32   return iferr(next, function () {
   33     for (var i = 0; i < pkg.children.length; ++i) {
   34       var c = pkg.children[i]
   35       if (!c.package.name) return next(c.error)
   36     }
   37 
   38     asyncMap(pkg.children, andStageBundledModule(pkg, staging, buildpath), cleanupBundled)
   39   })
   40   function cleanupBundled () {
   41     gentlyRm(path.join(buildpath, 'node_modules'), next)
   42   }
   43 }
   44 
   45 function andStageBundledModule (bundler, staging, parentPath) {
   46   return function (child, next) {
   47     stageBundledModule(bundler, child, staging, parentPath, next)
   48   }
   49 }
   50 
   51 function getTree (pkg) {
   52   while (pkg.parent) pkg = pkg.parent
   53   return pkg
   54 }
   55 
   56 function warn (pkg, code, msg) {
   57   var tree = getTree(pkg)
   58   var err = new Error(msg)
   59   err.code = code
   60   tree.warnings.push(err)
   61 }
   62 
   63 function stageBundledModule (bundler, child, staging, parentPath, next) {
   64   var stageFrom = path.join(parentPath, 'node_modules', child.package.name)
   65   var stageTo = buildPath(staging, child)
   66 
   67   asyncMap(child.children, andStageBundledModule(bundler, staging, stageFrom), iferr(next, moveModule))
   68 
   69   function moveModule () {
   70     if (child.fromBundle) {
   71       return rename(stageFrom, stageTo, iferr(next, updateMovedPackageJson))
   72     } else {
   73       return fs.stat(stageFrom, function (notExists, exists) {
   74         if (exists) {
   75           warn(bundler, 'EBUNDLEOVERRIDE', 'In ' + packageId(bundler) +
   76             ' replacing bundled version of ' + moduleName(child) +
   77             ' with ' + packageId(child))
   78           return gentlyRm(stageFrom, next)
   79         } else {
   80           return next()
   81         }
   82       })
   83     }
   84   }
   85 
   86   function updateMovedPackageJson () {
   87     updatePackageJson(child, stageTo, next)
   88   }
   89 }