]> gerrit.simantics Code Review - simantics/district.git/blob - org.simantics.maps.server/node/node-v4.8.0-win-x64/node_modules/npm/lib/utils/completion/installed-deep.js
Adding integrated tile server
[simantics/district.git] / org.simantics.maps.server / node / node-v4.8.0-win-x64 / node_modules / npm / lib / utils / completion / installed-deep.js
1 module.exports = installedDeep
2
3 var npm = require("../../npm.js")
4   , readInstalled = require("read-installed")
5
6 function installedDeep (opts, cb) {
7   var local
8     , global
9     , depth = npm.config.get("depth")
10     , opt = { depth: depth, dev: true }
11
12   if (npm.config.get("global")) local = [], next()
13   else readInstalled(npm.prefix, opt, function (er, data) {
14     local = getNames(data || {})
15     next()
16   })
17
18   readInstalled(npm.config.get("prefix"), opt, function (er, data) {
19     global = getNames(data || {})
20     next()
21   })
22
23   function getNames_ (d, n) {
24     if (d.realName && n) {
25       if (n[d.realName]) return n
26       n[d.realName] = true
27     }
28     if (!n) n = {}
29     Object.keys(d.dependencies || {}).forEach(function (dep) {
30       getNames_(d.dependencies[dep], n)
31     })
32     return n
33   }
34   function getNames (d) {
35     return Object.keys(getNames_(d))
36   }
37
38   function next () {
39     if (!local || !global) return
40     if (!npm.config.get("global")) {
41       global = global.map(function (g) {
42         return [g, "-g"]
43       })
44     }
45     var names = local.concat(global)
46     return cb(null, names)
47   }
48
49 }
50