Permalink
Browse files

Support unpublishing an entire project when all versions are removed,…

… or if no version specified
  • Loading branch information...
isaacs committed Aug 24, 2010
1 parent 7c6e641 commit dd817555e71cef675ba6acceb000cdff734164fb
Showing with 13 additions and 4 deletions.
  1. +1 −1 lib/unpublish.js
  2. +12 −3 lib/utils/registry/unpublish.js
View
@@ -8,7 +8,7 @@ function unpublish (args, cb) {
var thing = args.shift().split("@")
, project = thing.shift()
, version = thing.join("@")
- if (!project || !version) return cb(new Error(
+ if (!project) return cb(new Error(
"Usage: npm unpublish <project>@<version>"))
registry.unpublish(project, version, cb)
}
@@ -19,10 +19,19 @@ function unpublish (name, ver, cb) {
get(name, function (er, data) {
if (er) return log(name+" not published", "unpublish", cb)
// remove all if no version specified
- if (!ver) return request("DELETE", name+'/-rev/'+data._rev, cb)
- if (!data.versions.hasOwnProperty(ver)) return log(
- name+"@"+ver+" not published", "unpublish", cb)
+ if (!ver) {
+ log("No version specified, removing all", "unpublish")
+ return request("DELETE", name+'/-rev/'+data._rev, cb)
+ }
+ var versionPublic = data.versions.hasOwnProperty(ver)
+ if (!versionPublic) log(name+"@"+ver+" not published", "unpublish")
delete data.versions[ver]
+ // if it was the only version, then delete the whole package.
+ if (!Object.keys(data.versions).length) {
+ log("No versions remain, removing entire package", "unpublish")
+ return request("DELETE", name+'/-rev/'+data._rev, cb)
+ }
+ if (!versionPublic) return cb()
for (var tag in data["dist-tags"]) {
if (data["dist-tags"][tag] === ver) delete data["dist-tags"][tag]
}

0 comments on commit dd81755

Please sign in to comment.