4 bugs.usage = "npm bugs <pkgname>"
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")
13 , mapToRegistry = require("./utils/map-to-registry.js")
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
21 function bugs (args, cb) {
22 var n = args.length && npa(args[0]).name || "."
23 fs.stat(n, function (er, s) {
25 if (er.code === "ENOENT") return callRegistry(n, cb)
28 if (!s.isDirectory()) return callRegistry(n, cb)
29 readJson(path.resolve(n, "package.json"), function(er, d) {
36 function getUrlAndOpen (d, cb) {
37 var repo = d.repository || d.repositories
40 url = (typeof d.bugs === "string") ? d.bugs : d.bugs.url
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"
53 url = "https://www.npmjs.org/package/" + d.name
55 log.silly("bugs", "url", url)
56 opener(url, { command: npm.config.get("browser") }, cb)
59 function callRegistry (name, cb) {
60 mapToRegistry(name, npm.config, function (er, uri, auth) {
63 npm.registry.get(uri + "/latest", { auth : auth }, function (er, d) {