aboutsummaryrefslogtreecommitdiff
path: root/deps/npm/node_modules/npm-registry-client/lib/publish.js
diff options
context:
space:
mode:
authorForrest L Norvell <ogd@aoaioxxysz.net>2015-01-08 14:37:26 -0800
committerBen Noordhuis <info@bnoordhuis.nl>2015-01-08 23:49:03 +0100
commite79ccee1685393e4ec73746bac93835cbcf3a809 (patch)
tree304a1ddd59495b50a20d1b25c62da2a4519228db /deps/npm/node_modules/npm-registry-client/lib/publish.js
parent156cd82ef4d2ff4fa291407de562c3a7c2386dc7 (diff)
downloadandroid-node-v8-e79ccee1685393e4ec73746bac93835cbcf3a809.tar.gz
android-node-v8-e79ccee1685393e4ec73746bac93835cbcf3a809.tar.bz2
android-node-v8-e79ccee1685393e4ec73746bac93835cbcf3a809.zip
npm: upgrade to v2.1.18
PR-URL: https://github.com/iojs/io.js/pull/266 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Diffstat (limited to 'deps/npm/node_modules/npm-registry-client/lib/publish.js')
-rw-r--r--deps/npm/node_modules/npm-registry-client/lib/publish.js103
1 files changed, 62 insertions, 41 deletions
diff --git a/deps/npm/node_modules/npm-registry-client/lib/publish.js b/deps/npm/node_modules/npm-registry-client/lib/publish.js
index c3b2f3e1f2..ea9dcaef74 100644
--- a/deps/npm/node_modules/npm-registry-client/lib/publish.js
+++ b/deps/npm/node_modules/npm-registry-client/lib/publish.js
@@ -1,47 +1,58 @@
-
module.exports = publish
var url = require("url")
, semver = require("semver")
, crypto = require("crypto")
- , fs = require("fs")
- , fixNameField = require("normalize-package-data/lib/fixer.js").fixNameField
+ , Stream = require("stream").Stream
+ , assert = require("assert")
+ , fixer = require("normalize-package-data/lib/fixer.js")
+ , concat = require("concat-stream")
-function escaped(name) {
+function escaped (name) {
return name.replace("/", "%2f")
}
-function publish (uri, data, tarball, cb) {
- var c = this.conf.getCredentialsByURI(uri)
- if (!(c.token || (c.auth && c.username && c.email))) {
- var er = new Error("auth and email required for publishing")
- er.code = 'ENEEDAUTH'
+function publish (uri, params, cb) {
+ assert(typeof uri === "string", "must pass registry URI to publish")
+ assert(params && typeof params === "object", "must pass params to publish")
+ assert(typeof cb === "function", "must pass callback to publish")
+
+ var auth = params.auth
+ assert(auth && typeof auth === "object", "must pass auth to publish")
+ if (!(auth.token ||
+ (auth.password && auth.username && auth.email))) {
+ var er = new Error("auth required for publishing")
+ er.code = "ENEEDAUTH"
return cb(er)
}
+ var metadata = params.metadata
+ assert(
+ metadata && typeof metadata === "object",
+ "must pass package metadata to publish"
+ )
try {
- fixNameField(data, true)
+ fixer.fixNameField(metadata, true)
}
catch (er) {
return cb(er)
}
-
- var ver = semver.clean(data.version)
- if (!ver)
- return cb(new Error('invalid semver: ' + data.version))
- data.version = ver
-
- var self = this
- fs.stat(tarball, function(er, s) {
- if (er) return cb(er)
- fs.readFile(tarball, function(er, tarbuffer) {
- if (er) return cb(er)
- putFirst.call(self, uri, data, tarbuffer, s, c, cb)
- })
+ var version = semver.clean(metadata.version)
+ if (!version) return cb(new Error("invalid semver: " + metadata.version))
+ metadata.version = version
+
+ var body = params.body
+ assert(body, "must pass package body to publish")
+ assert(body instanceof Stream, "package body passed to publish must be a stream")
+ var client = this
+ var sink = concat(function (tarbuffer) {
+ putFirst.call(client, uri, metadata, tarbuffer, auth, cb)
})
+ sink.on("error", cb)
+ body.pipe(sink)
}
-function putFirst (registry, data, tarbuffer, stat, creds, cb) {
+function putFirst (registry, data, tarbuffer, auth, cb) {
// optimistically try to PUT all in one single atomic thing.
// If 409, then GET and merge, try again.
// If other error, then fail.
@@ -55,13 +66,13 @@ function putFirst (registry, data, tarbuffer, stat, creds, cb) {
, readme: data.readme || ""
}
- if (!creds.token) {
- root.maintainers = [{name : creds.username, email : creds.email}]
+ if (!auth.token) {
+ root.maintainers = [{name : auth.username, email : auth.email}]
data.maintainers = JSON.parse(JSON.stringify(root.maintainers))
}
root.versions[ data.version ] = data
- var tag = data.tag || this.conf.get('tag') || "latest"
+ var tag = data.tag || this.config.defaultTag
root["dist-tags"][tag] = data.version
var tbName = data.name + "-" + data.version + ".tgz"
@@ -77,11 +88,17 @@ function putFirst (registry, data, tarbuffer, stat, creds, cb) {
root._attachments[ tbName ] = {
"content_type": "application/octet-stream",
"data": tarbuffer.toString("base64"),
- "length": stat.size
+ "length": tarbuffer.length
}
var fixed = url.resolve(registry, escaped(data.name))
- this.request("PUT", fixed, { body : root }, function (er, parsed, json, res) {
+ var client = this
+ var options = {
+ method : "PUT",
+ body : root,
+ auth : auth
+ }
+ this.request(fixed, options, function (er, parsed, json, res) {
var r409 = "must supply latest _rev to update existing package"
var r409b = "Document update conflict."
var conflict = res && res.statusCode === 409
@@ -90,8 +107,7 @@ function putFirst (registry, data, tarbuffer, stat, creds, cb) {
// a 409 is typical here. GET the data and merge in.
if (er && !conflict) {
- this.log.error("publish", "Failed PUT "
- +(res && res.statusCode))
+ client.log.error("publish", "Failed PUT "+(res && res.statusCode))
return cb(er)
}
@@ -99,15 +115,15 @@ function putFirst (registry, data, tarbuffer, stat, creds, cb) {
return cb(er, parsed, json, res)
// let's see what versions are already published.
- this.request("GET", fixed + "?write=true", null, function (er, current) {
+ client.request(fixed+"?write=true", { auth : auth }, function (er, current) {
if (er) return cb(er)
- putNext.call(this, registry, data.version, root, current, cb)
- }.bind(this))
- }.bind(this))
+ putNext.call(client, registry, data.version, root, current, auth, cb)
+ })
+ })
}
-function putNext(registry, newVersion, root, current, cb) {
+function putNext (registry, newVersion, root, current, auth, cb) {
// already have the tardata on the root object
// just merge in existing stuff
var curVers = Object.keys(current.versions || {}).map(function (v) {
@@ -128,15 +144,15 @@ function putNext(registry, newVersion, root, current, cb) {
for (var i in root) {
switch (i) {
// objects that copy over the new stuffs
- case 'dist-tags':
- case 'versions':
- case '_attachments':
+ case "dist-tags":
+ case "versions":
+ case "_attachments":
for (var j in root[i])
current[i][j] = root[i][j]
break
// ignore these
- case 'maintainers':
+ case "maintainers":
break
// copy
@@ -148,7 +164,12 @@ function putNext(registry, newVersion, root, current, cb) {
root.versions[newVersion].maintainers = maint
var uri = url.resolve(registry, escaped(root.name))
- this.request("PUT", uri, { body : current }, cb)
+ var options = {
+ method : "PUT",
+ body : current,
+ auth : auth
+ }
+ this.request(uri, options, cb)
}
function conflictError (pkgid, version) {