diff options
author | Timothy J Fontaine <tjfontaine@gmail.com> | 2014-06-05 15:18:15 -0700 |
---|---|---|
committer | Timothy J Fontaine <tjfontaine@gmail.com> | 2014-06-06 15:07:29 -0700 |
commit | f051f317905b3b31945dfe965a492e54902e595f (patch) | |
tree | 06fedaefc3fc2dd5d6f197762afa4cd351659858 /deps/npm/lib/repo.js | |
parent | 535c7777ac674ba86cf93c44824e07b0e23ea8c4 (diff) | |
download | node-f051f317905b3b31945dfe965a492e54902e595f.tar.gz |
npm: upgrade to v1.4.14
Diffstat (limited to 'deps/npm/lib/repo.js')
-rw-r--r-- | deps/npm/lib/repo.js | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/deps/npm/lib/repo.js b/deps/npm/lib/repo.js index b95bd7562..a2ec99bb0 100644 --- a/deps/npm/lib/repo.js +++ b/deps/npm/lib/repo.js @@ -19,6 +19,7 @@ var npm = require("./npm.js") , path = require("path") , readJson = require("read-package-json") , fs = require("fs") + , url_ = require('url') function repo (args, cb) { var n = args.length && args[0].split("@").shift() || '.' @@ -40,7 +41,11 @@ function getUrlAndOpen (d, cb) { // from https://github.com/npm/npm-www/issues/418 if (githubUserRepo(r.url)) r.url = githubUserRepo(r.url) - var url = github(r.url) + + var url = (r.url && ~r.url.indexOf('github')) + ? github(r.url) + : nonGithubUrl(r.url) + if (!url) return cb(new Error('no repository: could not get url')) opener(url, { command: npm.config.get("browser") }, cb) @@ -52,3 +57,19 @@ function callRegistry (n, cb) { getUrlAndOpen(d, cb) }) } + +function nonGithubUrl (url) { + try { + var idx = url.indexOf('@') + if (idx !== -1) { + url = url.slice(idx+1).replace(/:([^\d]+)/, '/$1') + } + url = url_.parse(url) + var protocol = url.protocol === 'https:' + ? 'https:' + : 'http:' + return protocol + '//' + (url.host || '') + + url.path.replace(/\.git$/, '') + } + catch(e) {} +} |