diff options
author | Forrest L Norvell <forrest@npmjs.com> | 2014-05-24 10:38:44 +0400 |
---|---|---|
committer | Forrest L Norvell <forrest@npmjs.com> | 2014-06-13 23:41:12 +0400 |
commit | 626c3e4a7fb37159b79ab9b3af2c030f26540b0f (patch) | |
tree | 2b92e072dd5246840de5dfb838daaeeff76804d3 /lib | |
parent | 4cd935df5467e0d4caaf84f5e894f6aa4f5def57 (diff) |
use the new URL-based npm-registry-client interface
Diffstat (limited to 'lib')
-rw-r--r-- | lib/adduser.js | 2 | ||||
-rw-r--r-- | lib/bugs.js | 7 | ||||
-rw-r--r-- | lib/cache/add-named.js | 9 | ||||
-rw-r--r-- | lib/dedupe.js | 4 | ||||
-rw-r--r-- | lib/deprecate.js | 2 | ||||
-rw-r--r-- | lib/docs.js | 9 | ||||
-rw-r--r-- | lib/install.js | 6 | ||||
-rw-r--r-- | lib/outdated.js | 4 | ||||
-rw-r--r-- | lib/owner.js | 34 | ||||
-rw-r--r-- | lib/publish.js | 4 | ||||
-rw-r--r-- | lib/repo.js | 6 | ||||
-rw-r--r-- | lib/search.js | 12 | ||||
-rw-r--r-- | lib/star.js | 9 | ||||
-rw-r--r-- | lib/stars.js | 6 | ||||
-rw-r--r-- | lib/tag.js | 6 | ||||
-rw-r--r-- | lib/unpublish.js | 12 | ||||
-rw-r--r-- | lib/view.js | 13 |
17 files changed, 95 insertions, 50 deletions
diff --git a/lib/adduser.js b/lib/adduser.js index f826a76e8..84667a360 100644 --- a/lib/adduser.js +++ b/lib/adduser.js @@ -134,7 +134,7 @@ function save (c, u, cb) { } npm.spinner.start() // save existing configs, but yank off for this PUT - registry.adduser(u.u, u.p, u.e, function (er) { + registry.adduser(npm.config.get("registry"), u.u, u.p, u.e, function (er) { npm.spinner.stop() if (er) return cb(er) registry.username = u.u diff --git a/lib/bugs.js b/lib/bugs.js index be79ab30e..9584c326c 100644 --- a/lib/bugs.js +++ b/lib/bugs.js @@ -10,10 +10,12 @@ var npm = require("./npm.js") , path = require("path") , readJson = require("read-package-json") , fs = require("fs") + , url = require("url") bugs.completion = function (opts, cb) { if (opts.conf.argv.remain.length > 2) return cb() - registry.get("/-/short", 60000, function (er, list) { + var uri = url.resolve(npm.config.get("registry"), "/-/short") + registry.get(uri, { timeout : 60000 }, function (er, list) { return cb(null, list || []) }) } @@ -54,7 +56,8 @@ function getUrlAndOpen (d, cb) { } function callRegistry (n, cb) { - registry.get(n + "/latest", 3600, function (er, d) { + var uri = url.resolve(npm.config.get("registry"), n + "/latest") + registry.get(uri, { timeout : 3600 }, function (er, d) { if (er) return cb(er) getUrlAndOpen (d, cb) }) diff --git a/lib/cache/add-named.js b/lib/cache/add-named.js index 8f71acfa0..7137cc9b5 100644 --- a/lib/cache/add-named.js +++ b/lib/cache/add-named.js @@ -65,7 +65,8 @@ function addNameTag (name, tag, data, cb_) { return cb_(er, data) } - registry.get(name, {}, function (er, data, json, resp) { + var uri = url.resolve(npm.config.get("registry"), name) + registry.get(uri, null, function (er, data, json, resp) { if (!er) { er = errorResponse(name, resp) } @@ -113,7 +114,8 @@ function addNameVersion (name, v, data, cb) { response = null return next() } - registry.get(name, function (er, d, json, resp) { + var uri = url.resolve(npm.config.get("registry"), name) + registry.get(uri, null, function (er, d, json, resp) { if (!er) { er = errorResponse(name, resp) } @@ -195,7 +197,8 @@ function addNameRange (name, range, data, cb) { log.silly("addNameRange", {name:name, range:range, hasData:!!data}) if (data) return next() - registry.get(name, function (er, d, json, resp) { + var uri = url.resolve(npm.config.get("registry"), name) + registry.get(uri, null, function (er, d, json, resp) { if (!er) { er = errorResponse(name, resp) } diff --git a/lib/dedupe.js b/lib/dedupe.js index 0c2b18a78..1b3090a5e 100644 --- a/lib/dedupe.js +++ b/lib/dedupe.js @@ -7,6 +7,7 @@ // much better "put pkg X at folder Y" abstraction. Oh well, // whatever. Perfect enemy of the good, and all that. +var url = require("url") var fs = require("fs") var asyncMap = require("slide").asyncMap var path = require("path") @@ -245,7 +246,8 @@ function findVersions (npm, summary, cb) { var versions = data.versions var ranges = data.ranges - npm.registry.get(name, function (er, data) { + var uri = url.resolve(npm.config.get("registry"), name) + npm.registry.get(uri, null, function (er, data) { var regVersions = er ? [] : Object.keys(data.versions) var locMatch = bestMatch(versions, ranges) var regMatch; diff --git a/lib/deprecate.js b/lib/deprecate.js index de8e6cada..175b69ceb 100644 --- a/lib/deprecate.js +++ b/lib/deprecate.js @@ -14,7 +14,7 @@ deprecate.completion = function (opts, cb) { // get the list of packages by user var path = "/-/by-user/"+encodeURIComponent(un) , uri = url.resolve(npm.config.get("registry"), path) - npm.registry.get(uri, null, 60000, function (er, list) { + npm.registry.get(uri, { timeout : 60000 }, function (er, list) { if (er) return cb() console.error(list) return cb(null, list[un]) diff --git a/lib/docs.js b/lib/docs.js index 2abbd62f2..8e19aa056 100644 --- a/lib/docs.js +++ b/lib/docs.js @@ -5,12 +5,14 @@ docs.usage += "\n" docs.usage += "npm docs ." docs.completion = function (opts, cb) { - registry.get("/-/short", 60000, function (er, list) { + var uri = url_.resolve(npm.config.get("registry"), "/-/short") + registry.get(uri, { timeout : 60000 }, function (er, list) { return cb(null, list || []) }) } -var npm = require("./npm.js") +var url_ = require("url") + , npm = require("./npm.js") , registry = npm.registry , opener = require("opener") , path = require('path') @@ -49,7 +51,8 @@ function getDoc (project, cb) { return opener(url(json), { command: npm.config.get("browser") }, cb) } - registry.get(project + "/latest", 3600, function (er, json) { + var uri = url_.resolve(npm.config.get("registry"), project + "/latest") + registry.get(uri, { timeout : 3600 }, function (er, json) { var github = "https://github.com/" + project + "#readme" if (er) { diff --git a/lib/install.js b/lib/install.js index 5cf974ea7..b1c3809a4 100644 --- a/lib/install.js +++ b/lib/install.js @@ -34,7 +34,8 @@ install.completion = function (opts, cb) { // if it starts with https?://, then just give up, because it's a url // for now, not yet implemented. var registry = npm.registry - registry.get("/-/short", function (er, pkgs) { + , uri = url.resolve(npm.config.get("registry"), "/-/short") + registry.get(uri, null, function (er, pkgs) { if (er) return cb() if (!opts.partialWord) return cb(null, pkgs) @@ -47,7 +48,8 @@ install.completion = function (opts, cb) { return cb(null, pkgs) } - registry.get(pkgs[0], function (er, d) { + uri = url.resolve(npm.config.get("registry"), pkgs[0]) + registry.get(uri, null, function (er, d) { if (er) return cb() return cb(null, Object.keys(d["dist-tags"] || {}) .concat(Object.keys(d.versions || {})) diff --git a/lib/outdated.js b/lib/outdated.js index ef406fbdc..9e78b64cc 100644 --- a/lib/outdated.js +++ b/lib/outdated.js @@ -268,9 +268,9 @@ function shouldUpdate (args, dir, dep, has, req, depth, cb) { if (isGitUrl(url.parse(req))) return doIt("git", "git") - var registry = npm.registry // search for the latest package - registry.get(dep, function (er, d) { + var uri = url.resolve(npm.config.get("registry"), dep) + npm.registry.get(uri, null, function (er, d) { if (er) return cb() if (!d || !d['dist-tags'] || !d.versions) return cb() var l = d.versions[d['dist-tags'].latest] diff --git a/lib/owner.js b/lib/owner.js index fdf455955..cf6c16a34 100644 --- a/lib/owner.js +++ b/lib/owner.js @@ -15,17 +15,19 @@ owner.completion = function (opts, cb) { return cb(null, subs) } var un = encodeURIComponent(npm.config.get("username")) + var theUser, uri switch (argv[2]) { case "ls": if (argv.length > 3) return cb() - else return registry.get("/-/short", cb) + uri = url.resolve(npm.config.get("registry"), "/-/short") + else return registry.get(uri, null, cb) case "rm": if (argv.length > 3) { - var theUser = encodeURIComponent(argv[3]) - , uri = "/-/by-user/"+theUser+"|"+un + theUser = encodeURIComponent(argv[3]) + uri = url.resolve(npm.config.get("registry"), "/-/by-user/"+theUser+"|"+un) console.error(uri) - return registry.get(uri, function (er, d) { + return registry.get(uri, null, function (er, d) { if (er) return cb(er) // return the intersection return cb(null, d[theUser].filter(function (p) { @@ -37,10 +39,10 @@ owner.completion = function (opts, cb) { // else fallthrough case "add": if (argv.length > 3) { - var theUser = encodeURIComponent(argv[3]) - , uri = "/-/by-user/"+theUser+"|"+un + theUser = encodeURIComponent(argv[3]) + uri = url.resolve(npm.config.get("registry"), "/-/by-user/"+theUser+"|"+un) console.error(uri) - return registry.get(uri, function (er, d) { + return registry.get(uri, null, function (er, d) { console.error(uri, er || d) // return mine that they're not already on. if (er) return cb(er) @@ -52,7 +54,8 @@ owner.completion = function (opts, cb) { }) } // just list all users who aren't me. - return registry.get("/-/users", function (er, list) { + uri = url.resolve(npm.config.get("registry"), "/-/users") + return registry.get(uri, null, function (er, list) { if (er) return cb() return cb(null, Object.keys(list).filter(function (n) { return n !== un @@ -68,6 +71,7 @@ var npm = require("./npm.js") , registry = npm.registry , log = require("npmlog") , readJson = require("read-package-json") + , url = require("url") function owner (args, cb) { var action = args.shift() @@ -86,7 +90,8 @@ function ls (pkg, cb) { ls(pkg, cb) }) - registry.get(pkg, function (er, data) { + var uri = url.resolve(npm.config.get("registry"), pkg) + registry.get(uri, null, function (er, data) { var msg = "" if (er) { log.error("owner ls", "Couldn't get owner data", pkg) @@ -151,7 +156,8 @@ function rm (user, pkg, cb) { function mutate (pkg, user, mutation, cb) { if (user) { - registry.get("/-/user/org.couchdb.user:"+user, mutate_) + var uri = url.resolve(npm.config.get("registry"), "/-/user/org.couchdb.user:"+user) + registry.get(uri, null, mutate_) } else { mutate_(null, null) } @@ -166,7 +172,8 @@ function mutate (pkg, user, mutation, cb) { } if (u) u = { "name" : u.name, "email" : u.email } - registry.get(pkg, function (er, data) { + var uri = url.resolve(npm.config.get("registry"), pkg) + registry.get(uri, null, function (er, data) { if (er) { log.error("owner mutate", "Error getting package data for %s", pkg) return cb(er) @@ -178,9 +185,8 @@ function mutate (pkg, user, mutation, cb) { , _rev : data._rev , maintainers : m } - registry.request("PUT" - , pkg+"/-rev/"+data._rev, data - , function (er, data) { + var uri = url.resolve(npm.config.get("registry"), pkg+"/-rev/"+data._rev) + registry.request("PUT", uri, { body : data }, function (er, data) { if (!er && data.error) er = new Error( "Failed to update package metadata: "+JSON.stringify(data)) if (er) { diff --git a/lib/publish.js b/lib/publish.js index 01d66b407..b60760c57 100644 --- a/lib/publish.js +++ b/lib/publish.js @@ -70,6 +70,7 @@ function publish_ (arg, data, isRetry, cachedir, cb) { // check for publishConfig hash var registry = npm.registry + var registryURI = npm.config.get("registry") if (data.publishConfig) { var pubConf = new Conf(npm.config) pubConf.save = npm.config.save.bind(npm.config) @@ -81,6 +82,7 @@ function publish_ (arg, data, isRetry, cachedir, cb) { return s }, {})) registry = new RegClient(pubConf) + registryURI = pubConf.get("registry") } data._npmVersion = npm.version @@ -93,7 +95,7 @@ function publish_ (arg, data, isRetry, cachedir, cb) { +"Remove the 'private' field from the package.json to publish it.")) var tarball = cachedir + ".tgz" - registry.publish(data, tarball, function (er) { + registry.publish(registryURI, data, tarball, function (er) { if (er && er.code === "EPUBLISHCONFLICT" && npm.config.get("force") && !isRetry) { log.warn("publish", "Forced publish over "+data._id) diff --git a/lib/repo.js b/lib/repo.js index a2ec99bb0..18b80615e 100644 --- a/lib/repo.js +++ b/lib/repo.js @@ -5,7 +5,8 @@ repo.usage = "npm repo <pkgname>" repo.completion = function (opts, cb) { if (opts.conf.argv.remain.length > 2) return cb() - registry.get("/-/short", 60000, function (er, list) { + var uri = url_.resolve(npm.config.get("registry"), "/-/short") + registry.get(uri, { timeout : 60000 }, function (er, list) { return cb(null, list || []) }) } @@ -52,7 +53,8 @@ function getUrlAndOpen (d, cb) { } function callRegistry (n, cb) { - registry.get(n + "/latest", 3600, function (er, d) { + var uri = url_.resolve(npm.config.get("registry"), n + "/latest") + registry.get(uri, { timeout : 3600 }, function (er, d) { if (er) return cb(er) getUrlAndOpen(d, cb) }) diff --git a/lib/search.js b/lib/search.js index 21b6ab279..72abbe8d6 100644 --- a/lib/search.js +++ b/lib/search.js @@ -1,7 +1,8 @@ module.exports = exports = search -var npm = require("./npm.js") +var url = require("url") + , npm = require("./npm.js") , registry = npm.registry , columnify = require('columnify') @@ -57,8 +58,13 @@ function search (args, silent, staleness, cb) { } function getFilteredData (staleness, args, notArgs, cb) { - registry.get( "/-/all", staleness, false - , true, function (er, data) { + var opts = { + timeout : staleness, + follow : true, + staleOk : true + } + var uri = url.resolve(npm.config.get("registry"), "/-/all") + registry.get(uri, opts, function (er, data) { if (er) return cb(er) return cb(null, filter(data, args, notArgs)) }) diff --git a/lib/star.js b/lib/star.js index 33b12471a..bf68582ca 100644 --- a/lib/star.js +++ b/lib/star.js @@ -1,7 +1,8 @@ module.exports = star -var npm = require("./npm.js") +var url = require("url") + , npm = require("./npm.js") , registry = npm.registry , log = require("npmlog") , asyncMap = require("slide").asyncMap @@ -10,7 +11,8 @@ star.usage = "npm star <package> [pkg, pkg, ...]\n" + "npm unstar <package> [pkg, pkg, ...]" star.completion = function (opts, cb) { - registry.get("/-/short", 60000, function (er, list) { + var uri = url.resolve(npm.config.get("registry"), "/-/short") + registry.get(uri, { timeout : 60000 }, function (er, list) { return cb(null, list || []) }) } @@ -22,7 +24,8 @@ function star (args, cb) { , using = !(npm.command.match(/^un/)) if (!using) s = u asyncMap(args, function (pkg, cb) { - registry.star(pkg, using, function (er, data, raw, req) { + var uri = url.resolve(npm.config.get("registry"), pkg) + registry.star(uri, using, function (er, data, raw, req) { if (!er) { console.log(s + " "+pkg) log.verbose("star", data) diff --git a/lib/stars.js b/lib/stars.js index 74841f2de..f0d2ef73a 100644 --- a/lib/stars.js +++ b/lib/stars.js @@ -2,13 +2,15 @@ module.exports = stars stars.usage = "npm stars [username]" -var npm = require("./npm.js") +var url = require("url") + , npm = require("./npm.js") , registry = npm.registry , log = require("npmlog") function stars (args, cb) { var name = args.length === 1 ? args[0] : npm.config.get("username") - registry.stars(name, showstars) + , uri = url.resolve(npm.config.get("registry"), name) + registry.stars(uri, showstars) function showstars (er, data) { if (er) { diff --git a/lib/tag.js b/lib/tag.js index 8a7c51ca0..1d04ad1f7 100644 --- a/lib/tag.js +++ b/lib/tag.js @@ -5,7 +5,8 @@ tag.usage = "npm tag <project>@<version> [<tag>]" tag.completion = require("./unpublish.js").completion -var npm = require("./npm.js") +var url = require("url") + , npm = require("./npm.js") , registry = npm.registry function tag (args, cb) { @@ -14,5 +15,6 @@ function tag (args, cb) { , version = thing.join("@") , t = args.shift() || npm.config.get("tag") if (!project || !version || !t) return cb("Usage:\n"+tag.usage) - registry.tag(project, version, t, cb) + var uri = url.resolve(npm.config.get("registry"), project) + registry.tag(uri, version, t, cb) } diff --git a/lib/unpublish.js b/lib/unpublish.js index 0e48ab72d..d00bceaf5 100644 --- a/lib/unpublish.js +++ b/lib/unpublish.js @@ -1,7 +1,8 @@ module.exports = unpublish -var log = require("npmlog") +var url = require("url") + , log = require("npmlog") , npm = require("./npm.js") , registry = npm.registry , readJson = require("read-package-json") @@ -13,7 +14,8 @@ unpublish.completion = function (opts, cb) { if (opts.conf.argv.remain.length >= 3) return cb() var un = encodeURIComponent(npm.config.get("username")) if (!un) return cb() - registry.get("/-/by-user/"+un, function (er, pkgs) { + var uri = url.resolve(npm.config.get("registry"), "/-/by-user/"+un) + registry.get(uri, null, function (er, pkgs) { // do a bit of filtering at this point, so that we don't need // to fetch versions for more than one thing, but also don't // accidentally a whole project. @@ -26,7 +28,8 @@ unpublish.completion = function (opts, cb) { return p.indexOf(pp) === 0 }) if (pkgs.length > 1) return cb(null, pkgs) - registry.get(pkgs[0], function (er, d) { + var uri = url.resolve(npm.config.get("registry"), pkgs[0]) + registry.get(uri, null, function (er, d) { if (er) return cb(er) var vers = Object.keys(d.versions) if (!vers.length) return cb(null, pkgs) @@ -78,6 +81,7 @@ function gotProject (project, version, cb_) { return cb(er) } - registry.unpublish(project, version, cb) + var uri = url.resolve(npm.config.get("registry"), project) + registry.unpublish(uri, version, cb) }) } diff --git a/lib/view.js b/lib/view.js index 6b7382378..ae891e5ad 100644 --- a/lib/view.js +++ b/lib/view.js @@ -4,12 +4,15 @@ module.exports = view view.usage = "npm view pkg[@version] [<field>[.subfield]...]" view.completion = function (opts, cb) { + var uri if (opts.conf.argv.remain.length <= 2) { - return registry.get("/-/short", cb) + uri = url.resolve(npm.config.get("registry"), "/-/short") + return registry.get(uri, null, cb) } // have the package, get the fields. var tag = npm.config.get("tag") - registry.get(opts.conf.argv.remain[2], function (er, d) { + uri = url.resolve(npm.config.get("registry"), opts.conf.argv.remain[2]) + registry.get(uri, null, function (er, d) { if (er) return cb(er) var dv = d.versions[d["dist-tags"][tag]] , fields = [] @@ -39,7 +42,8 @@ view.completion = function (opts, cb) { } } -var npm = require("./npm.js") +var url = require("url") + , npm = require("./npm.js") , registry = npm.registry , log = require("npmlog") , util = require("util") @@ -56,7 +60,8 @@ function view (args, silent, cb) { if (name === ".") return cb(view.usage) // get the data about this package - registry.get(name, function (er, data) { + var uri = url.resolve(npm.config.get("registry"), name) + registry.get(uri, null, function (er, data) { if (er) return cb(er) if (data["dist-tags"] && data["dist-tags"].hasOwnProperty(version)) { version = data["dist-tags"][version] |