]> gerrit.simantics Code Review - simantics/district.git/blob - org.simantics.maps.server/node/node-v4.8.0-win-x64/node_modules/npm/lib/bugs.js
Adding integrated tile server
[simantics/district.git] / org.simantics.maps.server / node / node-v4.8.0-win-x64 / node_modules / npm / lib / bugs.js
1
2 module.exports = bugs
3
4 bugs.usage = "npm bugs <pkgname>"
5
6 var npm = require("./npm.js")
7   , log = require("npmlog")
8   , opener = require("opener")
9   , path = require("path")
10   , readJson = require("read-package-json")
11   , npa = require("npm-package-arg")
12   , fs = require("fs")
13   , mapToRegistry = require("./utils/map-to-registry.js")
14
15 bugs.completion = function (opts, cb) {
16   // FIXME: there used to be registry completion here, but it stopped making
17   // sense somewhere around 50,000 packages on the registry
18   cb()
19 }
20
21 function bugs (args, cb) {
22   var n = args.length && npa(args[0]).name || "."
23   fs.stat(n, function (er, s) {
24     if (er) {
25       if (er.code === "ENOENT") return callRegistry(n, cb)
26       return cb(er)
27     }
28     if (!s.isDirectory()) return callRegistry(n, cb)
29     readJson(path.resolve(n, "package.json"), function(er, d) {
30       if (er) return cb(er)
31       getUrlAndOpen(d, cb)
32     })
33   })
34 }
35
36 function getUrlAndOpen (d, cb) {
37   var repo = d.repository || d.repositories
38     , url
39   if (d.bugs) {
40     url = (typeof d.bugs === "string") ? d.bugs : d.bugs.url
41   }
42   else if (repo) {
43     if (Array.isArray(repo)) repo = repo.shift()
44     if (repo.hasOwnProperty("url")) repo = repo.url
45     log.verbose("bugs", "repository", repo)
46     if (repo && repo.match(/^(https?:\/\/|git(:\/\/|@))github.com/)) {
47       url = repo.replace(/^git(@|:\/\/)/, "https://")
48                 .replace(/^https?:\/\/github.com:/, "https://github.com/")
49                 .replace(/\.git$/, "")+"/issues"
50     }
51   }
52   if (!url) {
53     url = "https://www.npmjs.org/package/" + d.name
54   }
55   log.silly("bugs", "url", url)
56   opener(url, { command: npm.config.get("browser") }, cb)
57 }
58
59 function callRegistry (name, cb) {
60   mapToRegistry(name, npm.config, function (er, uri, auth) {
61     if (er) return cb(er)
62
63     npm.registry.get(uri + "/latest", { auth : auth }, function (er, d) {
64       if (er) return cb(er)
65
66       getUrlAndOpen(d, cb)
67     })
68   })
69 }