X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=org.simantics.maps.server%2Fnode%2Fnode-v4.8.0-win-x64%2Fnode_modules%2Fnpm%2Flib%2Futils%2Fcompletion%2Finstalled-shallow.js;fp=org.simantics.maps.server%2Fnode%2Fnode-v4.8.0-win-x64%2Fnode_modules%2Fnpm%2Flib%2Futils%2Fcompletion%2Finstalled-shallow.js;h=8d64649d5f66a9f9d6d95e3268cbf47e67837797;hb=2529be6d456deeb07c128603ce4971f1dc29b695;hp=0000000000000000000000000000000000000000;hpb=2636fc31c16c23711cf2b06a4ae8537bba9c1d35;p=simantics%2Fdistrict.git diff --git a/org.simantics.maps.server/node/node-v4.8.0-win-x64/node_modules/npm/lib/utils/completion/installed-shallow.js b/org.simantics.maps.server/node/node-v4.8.0-win-x64/node_modules/npm/lib/utils/completion/installed-shallow.js new file mode 100644 index 00000000..8d64649d --- /dev/null +++ b/org.simantics.maps.server/node/node-v4.8.0-win-x64/node_modules/npm/lib/utils/completion/installed-shallow.js @@ -0,0 +1,79 @@ + +module.exports = installedShallow + +var npm = require("../../npm.js") + , fs = require("graceful-fs") + , path = require("path") + , readJson = require("read-package-json") + , asyncMap = require("slide").asyncMap + +function installedShallow (opts, filter, cb) { + if (typeof cb !== "function") cb = filter, filter = null + var conf = opts.conf + , args = conf.argv.remain + if (args.length > 3) return cb() + var local + , global + , localDir = npm.dir + , 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 + , 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)) + } +}