npmtest-npm (v0.0.9)

Code coverage report for node-npmtest-npm/node_modules/npm/lib/utils/completion/installed-shallow.js

Statements: 15.87% (10 / 63)      Branches: 0% (0 / 34)      Functions: 0% (0 / 15)      Lines: 17.24% (10 / 58)      Ignored: none     

All files » node-npmtest-npm/node_modules/npm/lib/utils/completion/ » installed-shallow.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89  1   1 1 1 1 1   1                                                           1           1                                                             1                        
 
module.exports = installedShallow
 
var npm = require('../../npm.js')
var fs = require('graceful-fs')
var path = require('path')
var readJson = require('read-package-json')
var asyncMap = require('slide').asyncMap
 
function installedShallow (opts, filter, cb) {
  if (typeof cb !== 'function') {
    cb = filter
    filter = null
  }
  var conf = opts.conf
  var args = conf.argv.remain
  if (args.length > 3) return cb()
  var local
  var global
  var localDir = npm.dir
  var globalDir = npm.globalDir
  if (npm.config.get('global')) {
    local = []
    next()
  } else {
    fs.readdir(localDir, function (er, pkgs) {
      local = (pkgs || []).filter(function (p) {
        return p.charAt(0) !== '.'
      })
      next()
    })
  }
 
  fs.readdir(globalDir, function (er, pkgs) {
    global = (pkgs || []).filter(function (p) {
      return p.charAt(0) !== '.'
    })
    next()
  })
  function next () {
    if (!local || !global) return
    filterInstalled(local, global, filter, cb)
  }
}
 
function filterInstalled (local, global, filter, cb) {
  var fl
  var fg
 
  if (!filter) {
    fl = local
    fg = global
    return next()
  }
 
  asyncMap(local, function (p, cb) {
    readJson(path.join(npm.dir, p, 'package.json'), function (er, d) {
      if (!d || !filter(d)) return cb(null, [])
      return cb(null, d.name)
    })
  }, function (er, local) {
    fl = local || []
    next()
  })
 
  var globalDir = npm.globalDir
  asyncMap(global, function (p, cb) {
    readJson(path.join(globalDir, p, 'package.json'), function (er, d) {
      if (!d || !filter(d)) return cb(null, [])
      return cb(null, d.name)
    })
  }, function (er, global) {
    fg = global || []
    next()
  })
 
  function next () {
    if (!fg || !fl) return
    if (!npm.config.get('global')) {
      fg = fg.map(function (g) {
        return [g, '-g']
      })
    }
    console.error('filtered', fl, fg)
    return cb(null, fl.concat(fg))
  }
}