• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1module.exports = installedDeep
2
3var npm = require('../../npm.js')
4var readInstalled = require('read-installed')
5
6function installedDeep (opts, cb) {
7  var local
8  var global
9  var depth = npm.config.get('depth')
10  var opt = { depth: depth, dev: true }
11
12  if (npm.config.get('global')) {
13    local = []
14    next()
15  } else {
16    readInstalled(npm.prefix, opt, function (er, data) {
17      local = getNames(data || {})
18      next()
19    })
20  }
21
22  readInstalled(npm.config.get('prefix'), opt, function (er, data) {
23    global = getNames(data || {})
24    next()
25  })
26
27  function getNames_ (d, n) {
28    if (d.realName && n) {
29      if (n[d.realName]) return n
30      n[d.realName] = true
31    }
32    if (!n) n = {}
33    Object.keys(d.dependencies || {}).forEach(function (dep) {
34      getNames_(d.dependencies[dep], n)
35    })
36    return n
37  }
38  function getNames (d) {
39    return Object.keys(getNames_(d))
40  }
41
42  function next () {
43    if (!local || !global) return
44    if (!npm.config.get('global')) {
45      global = global.map(function (g) {
46        return [g, '-g']
47      })
48    }
49    var names = local.concat(global)
50    return cb(null, names)
51  }
52}
53