"Fossies" - the Fresh Open Source Software Archive

Member "Atom/resources/app/apm/node_modules/npm/lib/install/validate-tree.js" (8 Mar 2017, 2610 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 asyncMap = require('slide').asyncMap
    5 var chain = require('slide').chain
    6 var npmInstallChecks = require('npm-install-checks')
    7 var checkGit = npmInstallChecks.checkGit
    8 var clone = require('lodash.clonedeep')
    9 var normalizePackageData = require('normalize-package-data')
   10 var npm = require('../npm.js')
   11 var andFinishTracker = require('./and-finish-tracker.js')
   12 var flattenTree = require('./flatten-tree.js')
   13 var validateAllPeerDeps = require('./deps.js').validateAllPeerDeps
   14 var packageId = require('../utils/package-id.js')
   15 
   16 module.exports = function (idealTree, log, next) {
   17   validate('OOF', arguments)
   18   var moduleMap = flattenTree(idealTree)
   19   var modules = Object.keys(moduleMap).map(function (name) { return moduleMap[name] })
   20 
   21   chain([
   22     [asyncMap, modules, function (mod, done) {
   23       chain([
   24         mod.parent && !mod.isLink && [checkGit, mod.realpath],
   25         [checkErrors, mod, idealTree]
   26       ], done)
   27     }],
   28     [thenValidateAllPeerDeps, idealTree],
   29     [thenCheckTop, idealTree]
   30   ], andFinishTracker(log, next))
   31 }
   32 
   33 function checkErrors (mod, idealTree, next) {
   34   if (mod.error && (mod.parent || path.resolve(npm.globalDir, '..') !== mod.path)) idealTree.warnings.push(mod.error)
   35   next()
   36 }
   37 
   38 function thenValidateAllPeerDeps (idealTree, next) {
   39   validate('OF', arguments)
   40   validateAllPeerDeps(idealTree, function (tree, pkgname, version) {
   41     var warn = new Error(packageId(tree) + ' requires a peer of ' + pkgname + '@' +
   42       version + ' but none was installed.')
   43     warn.code = 'EPEERINVALID'
   44     idealTree.warnings.push(warn)
   45   })
   46   next()
   47 }
   48 
   49 function thenCheckTop (idealTree, next) {
   50   validate('OF', arguments)
   51   if (idealTree.package.error) return next()
   52 
   53   // FIXME: when we replace read-package-json with something less magic,
   54   // this should done elsewhere.
   55   // As it is, the package has already been normalized and thus some
   56   // errors are suppressed.
   57   var pkg = clone(idealTree.package)
   58   try {
   59     normalizePackageData(pkg, function (warn) {
   60       var warnObj = new Error(packageId(idealTree) + ' ' + warn)
   61       warnObj.code = 'EPACKAGEJSON'
   62       idealTree.warnings.push(warnObj)
   63     }, false)
   64   } catch (er) {
   65     er.code = 'EPACKAGEJSON'
   66     idealTree.warnings.push(er)
   67   }
   68 
   69   var nodeVersion = npm.config.get('node-version')
   70   if (/-/.test(nodeVersion)) {
   71     // if this is a prerelease nodeā€¦
   72     var warnObj = new Error('You are using a pre-release version of node and things may not work as expected')
   73     warnObj.code = 'ENODEPRE'
   74     idealTree.warnings.push(warnObj)
   75   }
   76   next()
   77 }