Skip to content

Commit

Permalink
unpublish: check the publishConfig field as same behavior as npm publish
Browse files Browse the repository at this point in the history
  • Loading branch information
watilde authored and othiym23 committed Apr 24, 2015
1 parent 92aa0bc commit 18ce0ec
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions lib/unpublish.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ var log = require("npmlog")
, path = require("path")
, mapToRegistry = require("./utils/map-to-registry.js")
, npa = require("npm-package-arg")
, Conf = require("./config/core.js").Conf
, CachingRegClient = require("./cache/caching-client.js")

unpublish.usage = "npm unpublish <project>[@<version>]"

Expand Down Expand Up @@ -71,34 +73,53 @@ function unpublish (args, cb) {
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)
gotProject(data.name, data.version, cb)
gotProject(data.name, data.version, data.publishConfig, cb)
})
}
return gotProject(project, version, cb)
}

function gotProject (project, version, cb_) {
function gotProject (project, version, publishConfig, cb_) {
if (typeof cb_ !== 'function') {
cb_ = publishConfig
publishConfig = null
}

function cb (er) {
if (er) return cb_(er)
console.log("- " + project + (version ? "@" + version : ""))
cb_()
}

var registry = npm.registry
var config = npm.config

if (publishConfig) {
config = new Conf(npm.config)
config.save = npm.config.save.bind(npm.config)

config.unshift(Object.keys(publishConfig).reduce(function (s, k) {
s[k] = publishConfig[k]
return s
}, {}))
registry = new CachingRegClient(config)
}

// remove from the cache first
npm.commands.cache(["clean", project, version], function (er) {
if (er) {
log.error("unpublish", "Failed to clean cache")
return cb(er)
}

mapToRegistry(project, npm.config, function (er, uri, auth) {
mapToRegistry(project, config, function (er, uri, auth) {
if (er) return cb(er)

var params = {
version : version,
auth : auth
}
npm.registry.unpublish(uri, params, cb)
registry.unpublish(uri, params, cb)
})
})
}

0 comments on commit 18ce0ec

Please sign in to comment.