"Fossies" - the Fresh Open Source Software Archive

Member "Atom/resources/app/apm/node_modules/npm/lib/install/validate-args.js" (11 Apr 2017, 1868 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 asyncMap = require('slide').asyncMap
    4 var chain = require('slide').chain
    5 var npmInstallChecks = require('npm-install-checks')
    6 var iferr = require('iferr')
    7 var checkEngine = npmInstallChecks.checkEngine
    8 var checkPlatform = npmInstallChecks.checkPlatform
    9 var npm = require('../npm.js')
   10 
   11 module.exports = function (idealTree, args, next) {
   12   validate('OAF', arguments)
   13   var force = npm.config.get('force')
   14 
   15   asyncMap(args, function (pkg, done) {
   16     chain([
   17       [checkSelf, idealTree, pkg, force],
   18       [isInstallable, pkg]
   19     ], done)
   20   }, next)
   21 }
   22 
   23 function getWarnings (pkg) {
   24   while (pkg.parent) pkg = pkg.parent
   25   if (!pkg.warnings) pkg.warnings = []
   26   return pkg.warnings
   27 }
   28 
   29 var isInstallable = module.exports.isInstallable = function (pkg, next) {
   30   var force = npm.config.get('force')
   31   var nodeVersion = npm.config.get('node-version')
   32   if (/-/.test(nodeVersion)) {
   33     // for the purposes of validation, if the node version is a prerelease,
   34     // strip that. We check and warn about this sceanrio over in validate-tree.
   35     nodeVersion = nodeVersion.replace(/-.*/, '')
   36   }
   37   var strict = npm.config.get('engine-strict')
   38   checkEngine(pkg, npm.version, nodeVersion, force, strict, iferr(next, thenWarnEngineIssues))
   39   function thenWarnEngineIssues (warn) {
   40     if (warn) getWarnings(pkg).push(warn)
   41     checkPlatform(pkg, force, next)
   42   }
   43 }
   44 
   45 function checkSelf (idealTree, pkg, force, next) {
   46   if (idealTree.package && idealTree.package.name !== pkg.name) return next()
   47   if (force) {
   48     var warn = new Error("Wouldn't install " + pkg.name + ' as a dependency of itself, but being forced')
   49     warn.code = 'ENOSELF'
   50     idealTree.warnings.push(warn)
   51     next()
   52   } else {
   53     var er = new Error('Refusing to install ' + pkg.name + ' as a dependency of itself')
   54     er.code = 'ENOSELF'
   55     next(er)
   56   }
   57 }