diff options
author | isaacs <i@izs.me> | 2010-08-24 23:31:45 +0400 |
---|---|---|
committer | isaacs <i@izs.me> | 2010-08-25 16:21:50 +0400 |
commit | dd817555e71cef675ba6acceb000cdff734164fb (patch) | |
tree | c125944f512e0dde87c5b5a75bfdacf613551a01 | |
parent | 7c6e641d4109d4bb547c891314496adae4a06d31 (diff) |
Support unpublishing an entire project when all versions are removed, or if no version specified
-rw-r--r-- | lib/unpublish.js | 2 | ||||
-rw-r--r-- | lib/utils/registry/unpublish.js | 15 |
2 files changed, 13 insertions, 4 deletions
diff --git a/lib/unpublish.js b/lib/unpublish.js index 3e3db53f8..cace1ba8e 100644 --- a/lib/unpublish.js +++ b/lib/unpublish.js @@ -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) } diff --git a/lib/utils/registry/unpublish.js b/lib/utils/registry/unpublish.js index f0205754b..ca6f2ecc5 100644 --- a/lib/utils/registry/unpublish.js +++ b/lib/utils/registry/unpublish.js @@ -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] } |