2 module.exports = installedShallow
4 var npm = require("../../npm.js")
5 , fs = require("graceful-fs")
6 , path = require("path")
7 , readJson = require("read-package-json")
8 , asyncMap = require("slide").asyncMap
10 function installedShallow (opts, filter, cb) {
11 if (typeof cb !== "function") cb = filter, filter = null
13 , args = conf.argv.remain
14 if (args.length > 3) return cb()
18 , globalDir = npm.globalDir
19 if (npm.config.get("global")) local = [], next()
20 else fs.readdir(localDir, function (er, pkgs) {
21 local = (pkgs || []).filter(function (p) {
22 return p.charAt(0) !== "."
26 fs.readdir(globalDir, function (er, pkgs) {
27 global = (pkgs || []).filter(function (p) {
28 return p.charAt(0) !== "."
33 if (!local || !global) return
34 filterInstalled(local, global, filter, cb)
38 function filterInstalled (local, global, filter, cb) {
48 asyncMap(local, function (p, cb) {
49 readJson(path.join(npm.dir, p, "package.json"), function (er, d) {
50 if (!d || !filter(d)) return cb(null, [])
51 return cb(null, d.name)
53 }, function (er, local) {
58 var globalDir = npm.globalDir
59 asyncMap(global, function (p, cb) {
60 readJson(path.join(globalDir, p, "package.json"), function (er, d) {
61 if (!d || !filter(d)) return cb(null, [])
62 return cb(null, d.name)
64 }, function (er, global) {
70 if (!fg || !fl) return
71 if (!npm.config.get("global")) {
72 fg = fg.map(function (g) {
76 console.error("filtered", fl, fg)
77 return cb(null, fl.concat(fg))