aboutsummaryrefslogtreecommitdiff
path: root/deps/npm/lib/unpublish.js
diff options
context:
space:
mode:
authorTimothy J Fontaine <tjfontaine@gmail.com>2014-09-24 14:41:07 -0700
committerTimothy J Fontaine <tjfontaine@gmail.com>2014-09-24 17:15:10 -0700
commit9fad8958df671c0e894506ef59b4c781c3dfb349 (patch)
tree4db7643b40c4ffd726fb27fb4aa276d420b3bfd8 /deps/npm/lib/unpublish.js
parentb26dd4e5ab9192bad72b9dc61fa4ad2d8f215da2 (diff)
downloadandroid-node-v8-9fad8958df671c0e894506ef59b4c781c3dfb349.tar.gz
android-node-v8-9fad8958df671c0e894506ef59b4c781c3dfb349.tar.bz2
android-node-v8-9fad8958df671c0e894506ef59b4c781c3dfb349.zip
deps: upgrade npm to 2.0.0
Diffstat (limited to 'deps/npm/lib/unpublish.js')
-rw-r--r--deps/npm/lib/unpublish.js84
1 files changed, 50 insertions, 34 deletions
diff --git a/deps/npm/lib/unpublish.js b/deps/npm/lib/unpublish.js
index 225c1c3c45..2566cd5ae6 100644
--- a/deps/npm/lib/unpublish.js
+++ b/deps/npm/lib/unpublish.js
@@ -1,40 +1,51 @@
module.exports = unpublish
-var url = require("url")
- , log = require("npmlog")
+var log = require("npmlog")
, npm = require("./npm.js")
, registry = npm.registry
, readJson = require("read-package-json")
, path = require("path")
+ , mapToRegistry = require("./utils/map-to-registry.js")
+ , npa = require("npm-package-arg")
unpublish.usage = "npm unpublish <project>[@<version>]"
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()
- 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.
- pkgs = pkgs[un]
- if (!pkgs || !pkgs.length) return cb()
- var partial = opts.partialWord.split("@")
- , pp = partial.shift()
- pkgs = pkgs.filter(function (p) {
- return p.indexOf(pp) === 0
- })
- if (pkgs.length > 1) return cb(null, pkgs)
- var uri = url.resolve(npm.config.get("registry"), pkgs[0])
- registry.get(uri, null, function (er, d) {
+ npm.commands.whoami([], true, function (er, username) {
+ if (er) return cb()
+
+ var un = encodeURIComponent(username)
+ if (!un) return cb()
+ var byUser = "-/by-user/" + un
+ mapToRegistry(byUser, npm.config, function (er, uri) {
if (er) return cb(er)
- var vers = Object.keys(d.versions)
- if (!vers.length) return cb(null, pkgs)
- return cb(null, vers.map(function (v) {
- return pkgs[0]+"@"+v
- }))
+
+ 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.
+ pkgs = pkgs[un]
+ if (!pkgs || !pkgs.length) return cb()
+ var pp = npa(opts.partialWord).name
+ pkgs = pkgs.filter(function (p) {
+ return p.indexOf(pp) === 0
+ })
+ if (pkgs.length > 1) return cb(null, pkgs)
+ mapToRegistry(pkgs[0], npm.config, function (er, uri) {
+ if (er) return cb(er)
+
+ 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)
+ return cb(null, vers.map(function (v) {
+ return pkgs[0] + "@" + v
+ }))
+ })
+ })
+ })
})
})
}
@@ -42,23 +53,25 @@ unpublish.completion = function (opts, cb) {
function unpublish (args, cb) {
if (args.length > 1) return cb(unpublish.usage)
- var thing = args.length ? args.shift().split("@") : []
- , project = thing.shift()
- , version = thing.join("@")
+ var thing = args.length ? npa(args[0]) : {}
+ , project = thing.name
+ , version = thing.rawSpec
+ log.silly("unpublish", "args[0]", args[0])
+ log.silly("unpublish", "thing", thing)
if (!version && !npm.config.get("force")) {
return cb("Refusing to delete entire project.\n"
- +"Run with --force to do this.\n"
- +unpublish.usage)
+ + "Run with --force to do this.\n"
+ + unpublish.usage)
}
- if (!project || path.resolve(project) === npm.prefix) {
+ if (!project || path.resolve(project) === npm.localPrefix) {
// if there's a package.json in the current folder, then
// read the package name and version out of that.
- var cwdJson = path.join(process.cwd(), "package.json")
+ var cwdJson = path.join(npm.localPrefix, "package.json")
return readJson(cwdJson, function (er, data) {
if (er && er.code !== "ENOENT" && er.code !== "ENOTDIR") return cb(er)
- if (er) return cb("Usage:\n"+unpublish.usage)
+ if (er) return cb("Usage:\n" + unpublish.usage)
gotProject(data.name, data.version, cb)
})
}
@@ -79,7 +92,10 @@ function gotProject (project, version, cb_) {
return cb(er)
}
- var uri = url.resolve(npm.config.get("registry"), project)
- registry.unpublish(uri, version, cb)
+ mapToRegistry(project, npm.config, function (er, uri) {
+ if (er) return cb(er)
+
+ registry.unpublish(uri, version, cb)
+ })
})
}