"Fossies" - the Fresh Open Source Software Archive

Member "Atom/resources/app/apm/node_modules/npm/lib/install/actions.js" (7 Feb 2017, 4680 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 validate = require('aproba')
    4 var chain = require('slide').chain
    5 var asyncMap = require('slide').asyncMap
    6 var log = require('npmlog')
    7 var andFinishTracker = require('./and-finish-tracker.js')
    8 var andAddParentToErrors = require('./and-add-parent-to-errors.js')
    9 var failedDependency = require('./deps.js').failedDependency
   10 var packageId = require('../utils/package-id.js')
   11 var moduleName = require('../utils/module-name.js')
   12 var buildPath = require('./build-path.js')
   13 
   14 var actions = {}
   15 
   16 actions.fetch = require('./action/fetch.js')
   17 actions.extract = require('./action/extract.js')
   18 actions.build = require('./action/build.js')
   19 actions.test = require('./action/test.js')
   20 actions.preinstall = require('./action/preinstall.js')
   21 actions.install = require('./action/install.js')
   22 actions.postinstall = require('./action/postinstall.js')
   23 actions.prepublish = require('./action/prepublish.js')
   24 actions.finalize = require('./action/finalize.js')
   25 actions.remove = require('./action/remove.js')
   26 actions.move = require('./action/move.js')
   27 actions['update-linked'] = require('./action/update-linked.js')
   28 actions['global-install'] = require('./action/global-install.js')
   29 actions['global-link'] = require('./action/global-link.js')
   30 
   31 // FIXME: We wrap actions like three ways to sunday here.
   32 // Rewrite this to only work one way.
   33 
   34 Object.keys(actions).forEach(function (actionName) {
   35   var action = actions[actionName]
   36   actions[actionName] = function (top, buildpath, pkg, log, next) {
   37     validate('SSOOF', arguments)
   38     // refuse to run actions for failed packages
   39     if (pkg.failed) return next()
   40     if (action.rollback) {
   41       if (!pkg.rollback) pkg.rollback = []
   42       pkg.rollback.unshift(action.rollback)
   43     }
   44     if (action.commit) {
   45       if (!pkg.commit) pkg.commit = []
   46       pkg.commit.push(action.commit)
   47     }
   48     return action(top, buildpath, pkg, log, andFinishTracker(log, andAddParentToErrors(pkg.parent, andHandleOptionalDepErrors(pkg, next))))
   49   }
   50 })
   51 
   52 function markAsFailed (pkg) {
   53   pkg.failed = true
   54   pkg.requires.forEach(function (req) {
   55     req.requiredBy = req.requiredBy.filter(function (reqReqBy) { return reqReqBy !== pkg })
   56     if (req.requiredBy.length === 0 && !req.userRequired && !req.existing) {
   57       markAsFailed(req)
   58     }
   59   })
   60 }
   61 
   62 function andHandleOptionalDepErrors (pkg, next) {
   63   return function (er) {
   64     if (!er) return next.apply(null, arguments)
   65     markAsFailed(pkg)
   66     var anyFatal = pkg.userRequired || pkg.isTop
   67     for (var ii = 0; ii < pkg.requiredBy.length; ++ii) {
   68       var parent = pkg.requiredBy[ii]
   69       var isFatal = failedDependency(parent, pkg)
   70       if (isFatal) anyFatal = true
   71     }
   72     if (anyFatal) return next.apply(null, arguments)
   73     log.warn('install:' + packageId(pkg), er.message)
   74     log.verbose('install:' + packageId(pkg), er.stack)
   75     next()
   76   }
   77 }
   78 
   79 function prepareAction (staging, log) {
   80   validate('SO', arguments)
   81   return function (action) {
   82     validate('SO', action)
   83     var cmd = action[0]
   84     var pkg = action[1]
   85     if (!actions[cmd]) throw new Error('Unknown decomposed command "' + cmd + '" (is it new?)')
   86     var top = path.resolve(staging, '../..')
   87     var buildpath = buildPath(staging, pkg)
   88     return [actions[cmd], top, buildpath, pkg, log.newGroup(cmd + ':' + moduleName(pkg))]
   89   }
   90 }
   91 
   92 exports.actions = actions
   93 
   94 function execAction (todo, done) {
   95   validate('AF', arguments)
   96   var cmd = todo.shift()
   97   todo.push(done)
   98   cmd.apply(null, todo)
   99 }
  100 
  101 exports.doOne = function (cmd, staging, pkg, log, next) {
  102   validate('SSOOF', arguments)
  103   execAction(prepareAction(staging, log)([cmd, pkg]), next)
  104 }
  105 
  106 exports.doSerial = function (type, staging, actionsToRun, log, next) {
  107   validate('SSAOF', arguments)
  108   actionsToRun = actionsToRun
  109     .filter(function (value) { return value[0] === type })
  110   log.silly('doSerial', '%s %d', type, actionsToRun.length)
  111   chain(actionsToRun.map(prepareAction(staging, log)), andFinishTracker(log, next))
  112 }
  113 
  114 exports.doReverseSerial = function (type, staging, actionsToRun, log, next) {
  115   validate('SSAOF', arguments)
  116   actionsToRun = actionsToRun
  117     .filter(function (value) { return value[0] === type })
  118     .reverse()
  119   log.silly('doReverseSerial', '%s %d', type, actionsToRun.length)
  120   chain(actionsToRun.map(prepareAction(staging, log)), andFinishTracker(log, next))
  121 }
  122 
  123 exports.doParallel = function (type, staging, actionsToRun, log, next) {
  124   validate('SSAOF', arguments)
  125   actionsToRun = actionsToRun.filter(function (value) { return value[0] === type })
  126   log.silly('doParallel', type + ' ' + actionsToRun.length)
  127 
  128   asyncMap(actionsToRun.map(prepareAction(staging, log)), execAction, andFinishTracker(log, next))
  129 }