4 repo.usage = "npm repo <pkgname>"
6 var npm = require("./npm.js")
7 , opener = require("opener")
8 , github = require("github-url-from-git")
9 , githubUserRepo = require("github-url-from-username-repo")
10 , path = require("path")
11 , readJson = require("read-package-json")
13 , url_ = require("url")
14 , mapToRegistry = require("./utils/map-to-registry.js")
15 , npa = require("npm-package-arg")
17 repo.completion = function (opts, cb) {
18 // FIXME: there used to be registry completion here, but it stopped making
19 // sense somewhere around 50,000 packages on the registry
23 function repo (args, cb) {
24 var n = args.length && npa(args[0]).name || "."
25 fs.stat(n, function (er, s) {
26 if (er && er.code === "ENOENT") return callRegistry(n, cb)
27 else if (er) return cb(er)
28 if (!s.isDirectory()) return callRegistry(n, cb)
29 readJson(path.resolve(n, "package.json"), function (er, d) {
36 function getUrlAndOpen (d, cb) {
38 if (!r) return cb(new Error("no repository"))
39 // XXX remove this when npm@v1.3.10 from node 0.10 is deprecated
40 // from https://github.com/npm/npm-www/issues/418
41 if (githubUserRepo(r.url))
42 r.url = githubUserRepo(r.url)
44 var url = (r.url && ~r.url.indexOf("github"))
49 return cb(new Error("no repository: could not get url"))
50 opener(url, { command: npm.config.get("browser") }, cb)
53 function callRegistry (n, cb) {
54 mapToRegistry(n, npm.config, function (er, uri) {
57 npm.registry.get(uri + "/latest", { timeout : 3600 }, function (er, d) {
64 function nonGithubUrl (url) {
66 var idx = url.indexOf("@")
68 url = url.slice(idx+1).replace(/:([^\d]+)/, "/$1")
71 var protocol = url.protocol === "https:"
74 return protocol + "//" + (url.host || "") +
75 url.path.replace(/\.git$/, "")