aboutsummaryrefslogtreecommitdiff
path: root/deps/npm/lib/bugs.js
diff options
context:
space:
mode:
authorisaacs <i@izs.me>2013-12-25 19:15:23 -0800
committerisaacs <i@izs.me>2013-12-25 19:15:23 -0800
commit7f82faee307de546a91c647086a0bb0c36de3132 (patch)
treeaf0051f131829ace07b4c782b79f9d07a3c56383 /deps/npm/lib/bugs.js
parent55b0bd639dea3e0d56b596aaa6ba2d26458c2be1 (diff)
downloadandroid-node-v8-7f82faee307de546a91c647086a0bb0c36de3132.tar.gz
android-node-v8-7f82faee307de546a91c647086a0bb0c36de3132.tar.bz2
android-node-v8-7f82faee307de546a91c647086a0bb0c36de3132.zip
npm: Upgrade to v1.3.22
Diffstat (limited to 'deps/npm/lib/bugs.js')
-rw-r--r--deps/npm/lib/bugs.js60
1 files changed, 39 insertions, 21 deletions
diff --git a/deps/npm/lib/bugs.js b/deps/npm/lib/bugs.js
index bcbf2bebb1..604748a97b 100644
--- a/deps/npm/lib/bugs.js
+++ b/deps/npm/lib/bugs.js
@@ -7,6 +7,9 @@ var npm = require("./npm.js")
, registry = npm.registry
, log = require("npmlog")
, opener = require("opener")
+ , path = require("path")
+ , readJson = require("read-package-json")
+ , fs = require("fs")
bugs.completion = function (opts, cb) {
if (opts.conf.argv.remain.length > 2) return cb()
@@ -16,28 +19,43 @@ bugs.completion = function (opts, cb) {
}
function bugs (args, cb) {
- if (!args.length) return cb(bugs.usage)
- var n = args[0].split("@").shift()
+ var n = args.length && args[0].split("@").shift() || '.'
+ fs.stat(n, function (er, s) {
+ if (er && er.code === "ENOENT") return callRegistry(n, cb)
+ else if (er) return cb (er)
+ if (!s.isDirectory()) return callRegistry(n, cb)
+ readJson(path.resolve(n, "package.json"), function(er, d) {
+ if (er) return cb(err)
+ getUrlAndOpen(d, cb)
+ })
+ })
+}
+
+function getUrlAndOpen (d, cb) {
+ var bugs = d.bugs
+ , repo = d.repository || d.repositories
+ , url
+ if (bugs) {
+ url = (typeof url === "string") ? bugs : bugs.url
+ } else if (repo) {
+ if (Array.isArray(repo)) repo = repo.shift()
+ if (repo.hasOwnProperty("url")) repo = repo.url
+ log.verbose("repository", repo)
+ if (bugs && bugs.match(/^(https?:\/\/|git(:\/\/|@))github.com/)) {
+ url = bugs.replace(/^git(@|:\/\/)/, "https://")
+ .replace(/^https?:\/\/github.com:/, "https://github.com/")
+ .replace(/\.git$/, '')+"/issues"
+ }
+ }
+ if (!url) {
+ url = "https://npmjs.org/package/" + d.name
+ }
+ opener(url, { command: npm.config.get("browser") }, cb)
+}
+
+function callRegistry (n, cb) {
registry.get(n + "/latest", 3600, function (er, d) {
if (er) return cb(er)
- var bugs = d.bugs
- , repo = d.repository || d.repositories
- , url
- if (bugs) {
- url = (typeof bugs === "string") ? bugs : bugs.url
- } else if (repo) {
- if (Array.isArray(repo)) repo = repo.shift()
- if (repo.hasOwnProperty("url")) repo = repo.url
- log.verbose("repository", repo)
- if (repo && repo.match(/^(https?:\/\/|git(:\/\/|@))github.com/)) {
- url = repo.replace(/^git(@|:\/\/)/, "https://")
- .replace(/^https?:\/\/github.com:/, "https://github.com/")
- .replace(/\.git$/, '')+"/issues"
- }
- }
- if (!url) {
- url = "https://npmjs.org/package/" + d.name
- }
- opener(url, { command: npm.config.get("browser") }, cb)
+ getUrlAndOpen (d, cb)
})
}