diff options
author | Forrest L Norvell <forrest@npmjs.com> | 2014-10-24 10:06:04 +0400 |
---|---|---|
committer | Forrest L Norvell <forrest@npmjs.com> | 2014-10-31 11:04:10 +0300 |
commit | 6750b05dcba20d8990a672957ec56c48f97e241a (patch) | |
tree | 7f46a9641512c24820ed4f8360b1e0e40d4d6174 | |
parent | 19022ff22758922c4fad46d4e21cbd7526e5d2f3 (diff) |
npm-registry-client@4.0.0
* Explicitly pass auth into all calls.
* Reworked the npm-registry-client API for consistency.
* Break registry client dependency on npm's cache.
* Remove getAll logic (moved to lib/cache/update-index.js).
* Decouple config from npm / npmconf.
* Remove bugs and upload because they're unused.
105 files changed, 7609 insertions, 1088 deletions
diff --git a/node_modules/npm-registry-client/README.md b/node_modules/npm-registry-client/README.md index 6d15dadf7..182552aeb 100644 --- a/node_modules/npm-registry-client/README.md +++ b/node_modules/npm-registry-client/README.md @@ -10,9 +10,9 @@ It handles all the caching and HTTP calls. var RegClient = require('npm-registry-client') var client = new RegClient(config) var uri = "npm://registry.npmjs.org/npm" -var options = {timeout: 1000} +var params = {timeout: 1000} -client.get(uri, options, function (error, data, raw, res) { +client.get(uri, params, function (error, data, raw, res) { // error is an error if there was a problem. // data is the parsed data object // raw is the json string @@ -23,124 +23,98 @@ client.get(uri, options, function (error, data, raw, res) { # Registry URLs The registry calls take either a full URL pointing to a resource in the -registry, or a base URL for the registry as a whole (for the base URL, any path -will be ignored). In addition to `http` and `https`, `npm` URLs are allowed. -`npm` URLs are `https` URLs with the additional restrictions that they will -always include authorization credentials, and the response is always registry -metadata (and not tarballs or other attachments). +registry, or a base URL for the registry as a whole (including the registry +path – but be sure to terminate the path with `/`). `http` and `https` URLs are +the only ones supported. -# Configuration +## Using the client -This program is designed to work with -[npmconf](https://npmjs.org/package/npmconf), but you can also pass in -a plain-jane object with the appropriate configs, and it'll shim it -for you. Any configuration thingie that has get/set/del methods will -also be accepted. - -* `cache` **Required** {String} Path to the cache folder -* `always-auth` {Boolean} Auth even for GET requests. -* `auth` {String} A base64-encoded `username:password` -* `email` {String} User's email address -* `tag` {String} The default tag to use when publishing new packages. - Default = `"latest"` -* `ca` {String} Cerficate signing authority certificates to trust. -* `cert` {String} Client certificate (PEM encoded). Enable access - to servers that require client certificates -* `key` {String} Private key (PEM encoded) for client certificate 'cert' -* `strict-ssl` {Boolean} Whether or not to be strict with SSL - certificates. Default = `true` -* `user-agent` {String} User agent header to send. Default = - `"node/{process.version} {process.platform} {process.arch}"` -* `log` {Object} The logger to use. Defaults to `require("npmlog")` if - that works, otherwise logs are disabled. -* `fetch-retries` {Number} Number of times to retry on GET failures. - Default=2 -* `fetch-retry-factor` {Number} `factor` setting for `node-retry`. Default=10 -* `fetch-retry-mintimeout` {Number} `minTimeout` setting for `node-retry`. - Default=10000 (10 seconds) -* `fetch-retry-maxtimeout` {Number} `maxTimeout` setting for `node-retry`. - Default=60000 (60 seconds) -* `proxy` {URL} The url to proxy requests through. -* `https-proxy` {URL} The url to proxy https requests through. - Defaults to be the same as `proxy` if unset. -* `_auth` {String} The base64-encoded authorization header. -* `username` `_password` {String} Username/password to use to generate - `_auth` if not supplied. -* `_token` {Object} A token for use with - [couch-login](https://npmjs.org/package/couch-login) - -# client.request(method, uri, options, cb) - -* `method` {String} HTTP method -* `uri` {String} URI pointing to the resource to request -* `options` {Object} Object containing optional per-request properties. - * `what` {Stream | Buffer | String | Object} The request body. Objects - that are not Buffers or Streams are encoded as JSON. - * `etag` {String} The cached ETag - * `follow` {Boolean} Follow 302/301 responses (defaults to true) -* `cb` {Function} - * `error` {Error | null} - * `data` {Object} the parsed data object - * `raw` {String} the json - * `res` {Response Object} response from couch +Every call to the client follows the same pattern: -Make a request to the registry. All the other methods are wrappers around -`request`. +* `uri` {String} The *fully-qualified* URI of the registry API method being + invoked. +* `params` {Object} Per-request parameters. +* `callback` {Function} Callback to be invoked when the call is complete. -# client.adduser(base, username, password, email, cb) +### Credentials + +Many requests to the registry can by authenticated, and require credentials +for authorization. These credentials always look the same: -* `base` {String} Base registry URL * `username` {String} * `password` {String} * `email` {String} -* `cb` {Function} +* `alwaysAuth` {Boolean} Whether calls to the target registry are always + authed. -Add a user account to the registry, or verify the credentials. +**or** + +* `token` {String} +* `alwaysAuth` {Boolean} Whether calls to the target registry are always + authed. + +## API -# client.deprecate(uri, version, message, cb) +### client.adduser(uri, params, cb) -* `uri` {String} Full registry URI for the deprecated package -* `version` {String} Semver version range -* `message` {String} The message to use as a deprecation warning +* `uri` {String} Base registry URL. +* `params` {Object} Object containing per-request properties. + * `auth` {Credentials} * `cb` {Function} + * `error` {Error | null} + * `data` {Object} the parsed data object + * `raw` {String} the json + * `res` {Response Object} response from couch -Deprecate a version of a package in the registry. +Add a user account to the registry, or verify the credentials. -# client.bugs(uri, cb) +### client.deprecate(uri, params, cb) -* `uri` {String} Full registry URI for the package +* `uri` {String} Full registry URI for the deprecated package. +* `params` {Object} Object containing per-request properties. + * `version` {String} Semver version range. + * `message` {String} The message to use as a deprecation warning. + * `auth` {Credentials} * `cb` {Function} -Get the url for bugs of a package +Deprecate a version of a package in the registry. -# client.get(uri, options, cb) +### client.get(uri, params, cb) * `uri` {String} The complete registry URI to fetch -* `options` {Object} Object containing optional per-request properties. - * `timeout` {Number} Duration before the request times out. - * `follow` {Boolean} Follow 302/301 responses (defaults to true) - * `staleOk` {Boolean} If there's cached data available, then return that - to the callback quickly, and update the cache the background. +* `params` {Object} Object containing per-request properties. + * `timeout` {Number} Duration before the request times out. Optional + (default: never). + * `follow` {Boolean} Follow 302/301 responses. Optional (default: true). + * `staleOk` {Boolean} If there's cached data available, then return that to + the callback quickly, and update the cache the background. Optional + (default: false). + * `auth` {Credentials} Optional. +* `cb` {Function} Fetches data from the registry via a GET request, saving it in the cache folder with the ETag. -# client.publish(uri, data, tarball, cb) +### client.publish(uri, params, cb) -* `uri` {String} The registry URI to publish to -* `data` {Object} Package data -* `tarball` {String | Stream} Filename or stream of the package tarball +* `uri` {String} The registry URI for the package to publish. +* `params` {Object} Object containing per-request properties. + * `metadata` {Object} Package metadata. + * `body` {Stream} Stream of the package body / tarball. + * `auth` {Credentials} * `cb` {Function} Publish a package to the registry. -Note that this does not create the tarball from a folder. However, it can -accept a gzipped tar stream or a filename to a tarball. +Note that this does not create the tarball from a folder. -# client.star(uri, starred, cb) +### client.star(uri, params, cb) -* `uri` {String} The complete registry URI to star -* `starred` {Boolean} True to star the package, false to unstar it. +* `uri` {String} The complete registry URI for the package to star. +* `params` {Object} Object containing per-request properties. + * `starred` {Boolean} True to star the package, false to unstar it. Optional + (default: false). + * `auth` {Credentials} * `cb` {Function} Star or unstar a package. @@ -148,40 +122,117 @@ Star or unstar a package. Note that the user does not have to be the package owner to star or unstar a package, though other writes do require that the user be the package owner. -# client.stars(base, username, cb) +### client.stars(uri, params, cb) -* `base` {String} The base URL for the registry -* `username` {String} Name of user to fetch starred packages for. +* `uri` {String} The base URL for the registry. +* `params` {Object} Object containing per-request properties. + * `username` {String} Name of user to fetch starred packages for. Optional + (default: user in `auth`). + * `auth` {Credentials} Optional (required if `username` is omitted). * `cb` {Function} View your own or another user's starred packages. -# client.tag(uri, version, tag, cb) +### client.tag(uri, params, cb) * `uri` {String} The complete registry URI to tag -* `version` {String} Version to tag -* `tag` {String} Tag name to apply +* `params` {Object} Object containing per-request properties. + * `version` {String} Version to tag. + * `tag` {String} Tag name to apply. + * `auth` {Credentials} * `cb` {Function} Mark a version in the `dist-tags` hash, so that `pkg@tag` will fetch the specified version. -# client.unpublish(uri, [ver], cb) +### client.unpublish(uri, params, cb) -* `uri` {String} The complete registry URI to unpublish -* `ver` {String} version to unpublish. Leave blank to unpublish all - versions. +* `uri` {String} The complete registry URI of the package to unpublish. +* `params` {Object} Object containing per-request properties. + * `version` {String} version to unpublish. Optional – omit to unpublish all + versions. + * `auth` {Credentials} * `cb` {Function} Remove a version of a package (or all versions) from the registry. When the last version us unpublished, the entire document is removed from the database. -# client.upload(uri, file, [etag], [nofollow], cb) +### client.whoami(uri, params, cb) + +* `uri` {String} The base registry for the URI. +* `params` {Object} Object containing per-request properties. + * `auth` {Credentials} +* `cb` {Function} + +Simple call to see who the registry thinks you are. Especially useful with +token-based auth. + + +## PLUMBING + +The below are primarily intended for use by the rest of the API, or by the npm +caching logic directly. + +### client.request(uri, params, cb) + +* `uri` {String} URI pointing to the resource to request. +* `params` {Object} Object containing per-request properties. + * `method` {String} HTTP method. Optional (default: "GET"). + * `body` {Stream | Buffer | String | Object} The request body. Objects + that are not Buffers or Streams are encoded as JSON. Optional – body + only used for write operations. + * `etag` {String} The cached ETag. Optional. + * `follow` {Boolean} Follow 302/301 responses. Optional (default: true). + * `auth` {Credentials} Optional. +* `cb` {Function} + * `error` {Error | null} + * `data` {Object} the parsed data object + * `raw` {String} the json + * `res` {Response Object} response from couch + +Make a generic request to the registry. All the other methods are wrappers +around `client.request`. + +### client.fetch(uri, params, cb) * `uri` {String} The complete registry URI to upload to -* `file` {String | Stream} Either the filename or a readable stream -* `etag` {String} Cache ETag -* `nofollow` {Boolean} Do not follow 301/302 responses +* `params` {Object} Object containing per-request properties. + * `headers` {Stream} HTTP headers to be included with the request. Optional. + * `auth` {Credentials} Optional. * `cb` {Function} -Upload an attachment. Mostly used by `client.publish()`. +Fetch a package from a URL, with auth set appropriately if included. Used to +cache remote tarballs as well as request package tarballs from the registry. + +# Configuration + +The client uses its own configuration, which is just passed in as a simple +nested object. The following are the supported values (with their defaults, if +any): + +* `proxy.http` {URL} The URL to proxy HTTP requests through. +* `proxy.https` {URL} The URL to proxy HTTPS requests through. Defaults to be + the same as `proxy.http` if unset. +* `proxy.localAddress` {IP} The local address to use on multi-homed systems. +* `ssl.ca` {String} Cerficate signing authority certificates to trust. +* `ssl.certificate` {String} Client certificate (PEM encoded). Enable access + to servers that require client certificates. +* `ssl.key` {String} Private key (PEM encoded) for client certificate. +* `ssl.strict` {Boolean} Whether or not to be strict with SSL certificates. + Default = `true` +* `retry.count` {Number} Number of times to retry on GET failures. Default = 2. +* `retry.factor` {Number} `factor` setting for `node-retry`. Default = 10. +* `retry.minTimeout` {Number} `minTimeout` setting for `node-retry`. + Default = 10000 (10 seconds) +* `retry.maxTimeout` {Number} `maxTimeout` setting for `node-retry`. + Default = 60000 (60 seconds) +* `userAgent` {String} User agent header to send. Default = + `"node/{process.version}"` +* `log` {Object} The logger to use. Defaults to `require("npmlog")` if + that works, otherwise logs are disabled. +* `defaultTag` {String} The default tag to use when publishing new packages. + Default = `"latest"` +* `couchToken` {Object} A token for use with + [couch-login](https://npmjs.org/package/couch-login). +* `sessionToken` {string} A random identifier for this set of client requests. + Default = 8 random hexadecimal bytes. diff --git a/node_modules/npm-registry-client/index.js b/node_modules/npm-registry-client/index.js index a75e8bbdb..ad4c4470b 100644 --- a/node_modules/npm-registry-client/index.js +++ b/node_modules/npm-registry-client/index.js @@ -2,13 +2,14 @@ module.exports = RegClient -var url = require('url') -, npmlog -, cacheFile = require('npm-cache-filename') +var join = require("path").join + , fs = require("graceful-fs") +var npmlog try { npmlog = require("npmlog") -} catch (er) { +} +catch (er) { npmlog = { error: noop, warn: noop, info: noop, verbose: noop, silly: noop, http: noop, pause: noop, resume: noop } @@ -16,42 +17,33 @@ try { function noop () {} -function RegClient (conf) { - // accept either a plain-jane object, or a npmconf object - // with a "get" method. - if (typeof conf.get !== 'function') { - var data = conf - conf = { get: function (k) { return data[k] } - , set: function (k, v) { data[k] = v } - , del: function (k) { delete data[k] } } - } +function RegClient (config) { + this.config = Object.create(config || {}) - this.conf = conf - - // if provided, then the registry needs to be a url. - // if it's not provided, then we're just using the cache only. - var registry = conf.get('registry') - if (registry) { - registry = url.parse(registry) - if (!registry.protocol) throw new Error( - 'Invalid registry: ' + registry.url) - registry = registry.href - if (registry.slice(-1) !== '/') { - registry += '/' - } - this.conf.set('registry', registry) - } else { - registry = null + this.config.proxy = this.config.proxy || {} + if (!this.config.proxy.https && this.config.proxy.http) { + this.config.proxy.https = this.config.proxy.http } - this.registry = registry + this.config.ssl = this.config.ssl || {} + if (this.config.ssl.strict === undefined) this.config.ssl.strict = true + + this.config.retry = this.config.retry || {} + if (!this.config.retry.count) this.config.retry.count = 2 + if (!this.config.retry.factor) this.config.retry.factor = 10 + if (!this.config.retry.minTimeout) this.config.retry.minTimeout = 10000 + if (!this.config.retry.maxTimeout) this.config.retry.maxTimeout = 60000 + + this.config.userAgent = this.config.userAgent || "node/" + process.version + this.config.defaultTag = this.config.defaultTag || "latest" - if (!conf.get('cache')) throw new Error("Cache dir is required") - this.cacheFile = cacheFile(this.conf.get('cache')) - this.log = conf.log || conf.get('log') || npmlog + this.log = this.config.log || npmlog + delete this.config.log } -require('fs').readdirSync(__dirname + "/lib").forEach(function (f) { +fs.readdirSync(join(__dirname, "lib")).forEach(function (f) { if (!f.match(/\.js$/)) return - RegClient.prototype[f.replace(/\.js$/, '')] = require('./lib/' + f) + var name = f.replace(/\.js$/, "") + .replace(/-([a-z])/, function (_, l) { return l.toUpperCase() }) + RegClient.prototype[name] = require(join(__dirname, "lib", f)) }) diff --git a/node_modules/npm-registry-client/lib/adduser.js b/node_modules/npm-registry-client/lib/adduser.js index e449c2580..5f4abc8ef 100644 --- a/node_modules/npm-registry-client/lib/adduser.js +++ b/node_modules/npm-registry-client/lib/adduser.js @@ -1,49 +1,54 @@ module.exports = adduser var url = require("url") - -function adduser (base, username, password, email, cb) { - if (!base) return cb(new Error("Required base URI not supplied")) - - username = ("" + (username || "")).trim() +var assert = require("assert") + +function adduser (uri, params, cb) { + assert(typeof uri === "string", "must pass registry URI to adduser") + assert( + params && typeof params === "object", + "must pass params to adduser" + ) + assert(typeof cb === "function", "must pass callback to adduser") + + assert(params.auth && typeof params.auth, "must pass auth to adduser") + var auth = params.auth + assert(typeof auth.username === "string", "must include username in auth") + assert(typeof auth.password === "string", "must include password in auth") + assert(typeof auth.email === "string", "must include email in auth") + + // normalize registry URL + if (uri.slice(-1) !== "/") uri += "/" + + var username = auth.username.trim() + var password = auth.password.trim() + var email = auth.email.trim() + + // validation if (!username) return cb(new Error("No username supplied.")) - - password = ("" + (password || "")).trim() if (!password) return cb(new Error("No password supplied.")) - - email = ("" + (email || "")).trim() if (!email) return cb(new Error("No email address supplied.")) if (!email.match(/^[^@]+@[^\.]+\.[^\.]+/)) { return cb(new Error("Please use a real email address.")) } - var userobj = - { name : username - , password : password - , email : email - , _id : 'org.couchdb.user:'+username - , type : "user" - , roles : [] - , date: new Date().toISOString() - } - - // pluck off any other username/password/token. it needs to be the - // same as the user we're becoming now. replace them on error. - var c = this.conf.getCredentialsByURI(base) - var pre = { username: c.username - , password: c.password - , email: c.email - , token: this.conf.get('_token') } - - this.conf.del('_token') - if (this.couchLogin) { - this.couchLogin.token = null + var userobj = { + _id : "org.couchdb.user:"+username, + name : username, + password : password, + email : email, + type : "user", + roles : [], + date : new Date().toISOString() } - cb = done.call(this, cb, pre) + var token = this.config.couchToken + if (this.couchLogin) this.couchLogin.token = null + + cb = done.call(this, token, cb) var logObj = Object.keys(userobj).map(function (k) { - if (k === 'password') return [k, 'XXXXX'] + if (k === "password") return [k, "XXXXX"] return [k, userobj[k]] }).reduce(function (s, kv) { s[kv[0]] = kv[1] @@ -52,70 +57,57 @@ function adduser (base, username, password, email, cb) { this.log.verbose("adduser", "before first PUT", logObj) - var uri = url.resolve(base, '/-/user/org.couchdb.user:' + encodeURIComponent(username)) - this.request('PUT' - , uri - , { body : userobj } - , function (error, data, json, response) { - // if it worked, then we just created a new user, and all is well. - // but if we're updating a current record, then it'll 409 first - var c = this.conf.getCredentialsByURI(base) - if (error && !c.auth) { - // must be trying to re-auth on a new machine. - // use this info as auth - this.conf.setCredentialsByURI(base, { - username : username, - password : password, - email : email - }) - } + var client = this - if (!error || !response || response.statusCode !== 409) { - return cb(error, data, json, response) + uri = url.resolve(uri, "-/user/org.couchdb.user:" + encodeURIComponent(username)) + var options = { + method : "PUT", + body : userobj, + auth : auth + } + this.request( + uri, + options, + function (error, data, json, response) { + if (!error || !response || response.statusCode !== 409) { + return cb(error, data, json, response) + } + + client.log.verbose("adduser", "update existing user") + return client.request( + uri+"?write=true", + { body : userobj, auth : auth }, + function (er, data, json, response) { + if (er || data.error) { + return cb(er, data, json, response) + } + Object.keys(data).forEach(function (k) { + if (!userobj[k] || k === "roles") { + userobj[k] = data[k] + } + }) + client.log.verbose("adduser", "userobj", logObj) + client.request(uri+"/-rev/"+userobj._rev, options, cb) } + ) + } + ) - this.log.verbose("adduser", "update existing user") - return this.request('GET' - , uri + '?write=true' - , null - , function (er, data, json, response) { - if (er || data.error) { - return cb(er, data, json, response) - } - Object.keys(data).forEach(function (k) { - if (!userobj[k] || k === 'roles') { - userobj[k] = data[k] - } - }) - this.log.verbose("adduser", "userobj", logObj) - this.request('PUT' - , uri + "/-rev/" + userobj._rev - , { body : userobj } - , cb) - }.bind(this)) - }.bind(this)) - - function done (cb, pre) { + function done (token, cb) { return function (error, data, json, response) { if (!error && (!response || response.statusCode === 201)) { return cb(error, data, json, response) } - // there was some kind of error, re-instate previous auth/token/etc. - this.conf.set('_token', pre.token) - if (this.couchLogin) { - this.couchLogin.token = pre.token - if (this.couchLogin.tokenSet) { - this.couchLogin.tokenSet(pre.token) + // there was some kind of error, reinstate previous auth/token/etc. + if (client.couchLogin) { + client.couchLogin.token = token + if (client.couchLogin.tokenSet) { + client.couchLogin.tokenSet(token) } } - this.conf.setCredentialsByURI(base, { - username : pre.username, - password : pre.password, - email : pre.email - }) - this.log.verbose("adduser", "back", [error, data, json]) + client.log.verbose("adduser", "back", [error, data, json]) if (!error) { error = new Error( (response && response.statusCode || "") + " " + @@ -124,13 +116,13 @@ function adduser (base, username, password, email, cb) { } if (response && (response.statusCode === 401 || response.statusCode === 403)) { - this.log.warn("adduser", "Incorrect username or password\n" + - "You can reset your account by visiting:\n" + - "\n" + - " https://npmjs.org/forgot\n") + client.log.warn("adduser", "Incorrect username or password\n" + + "You can reset your account by visiting:\n" + + "\n" + + " https://npmjs.org/forgot\n") } return cb(error) - }.bind(this) + } } } diff --git a/node_modules/npm-registry-client/lib/attempt.js b/node_modules/npm-registry-client/lib/attempt.js index 0794fdc3b..7f289efeb 100644 --- a/node_modules/npm-registry-client/lib/attempt.js +++ b/node_modules/npm-registry-client/lib/attempt.js @@ -5,12 +5,7 @@ module.exports = attempt function attempt(cb) { // Tuned to spread 3 attempts over about a minute. // See formula at <https://github.com/tim-kos/node-retry>. - var operation = retry.operation({ - retries : this.conf.get("fetch-retries") || 2, - factor : this.conf.get("fetch-retry-factor"), - minTimeout : this.conf.get("fetch-retry-mintimeout") || 10000, - maxTimeout : this.conf.get("fetch-retry-maxtimeout") || 60000 - }) + var operation = retry.operation(this.config.retry) var client = this operation.attempt(function (currentAttempt) { diff --git a/node_modules/npm-registry-client/lib/authify.js b/node_modules/npm-registry-client/lib/authify.js index 2b0c7a2a3..4d1a4dd4a 100644 --- a/node_modules/npm-registry-client/lib/authify.js +++ b/node_modules/npm-registry-client/lib/authify.js @@ -1,21 +1,17 @@ -var url = require("url") - module.exports = authify -function authify (authed, parsed, headers) { - var c = this.conf.getCredentialsByURI(url.format(parsed)) - - if (c && c.token) { +function authify (authed, parsed, headers, credentials) { + if (credentials && credentials.token) { this.log.verbose("request", "using bearer token for auth") - headers.authorization = "Bearer " + c.token + headers.authorization = "Bearer " + credentials.token return null } if (authed) { - if (c && c.username && c.password) { - var username = encodeURIComponent(c.username) - var password = encodeURIComponent(c.password) + if (credentials && credentials.username && credentials.password) { + var username = encodeURIComponent(credentials.username) + var password = encodeURIComponent(credentials.password) parsed.auth = username + ":" + password } else { diff --git a/node_modules/npm-registry-client/lib/bugs.js b/node_modules/npm-registry-client/lib/bugs.js deleted file mode 100644 index fd0365eed..000000000 --- a/node_modules/npm-registry-client/lib/bugs.js +++ /dev/null @@ -1,9 +0,0 @@ - -module.exports = bugs - -function bugs (uri, cb) { - this.get(uri + "/latest", 3600, function (er, d) { - if (er) return cb(er) - cb(null, d.bugs) - }) -} diff --git a/node_modules/npm-registry-client/lib/deprecate.js b/node_modules/npm-registry-client/lib/deprecate.js index f5fd59704..c018570d9 100644 --- a/node_modules/npm-registry-client/lib/deprecate.js +++ b/node_modules/npm-registry-client/lib/deprecate.js @@ -1,27 +1,43 @@ module.exports = deprecate +var assert = require("assert") var url = require("url") var semver = require("semver") -function deprecate (uri, ver, message, cb) { - var c = this.conf.getCredentialsByURI(uri) - if (!(c.token || c.auth)) { - return cb(new Error("Must be logged in to deprecate a package")) - } +function deprecate (uri, params, cb) { + assert(typeof uri === "string", "must pass registry URI to deprecate") + assert(params && typeof params === "object", "must pass params to deprecate") + assert(typeof cb === "function", "must pass callback to deprecate") + + assert(typeof params.version === "string", "must pass version to deprecate") + assert(typeof params.message === "string", "must pass message to deprecate") + assert( + params.auth && typeof params.auth === "object", + "must pass auth to deprecate" + ) + + var version = params.version + var message = params.message + var auth = params.auth - if (semver.validRange(ver) === null) { - return cb(new Error("invalid version range: "+ver)) + if (semver.validRange(version) === null) { + return cb(new Error("invalid version range: "+version)) } - this.get(uri + '?write=true', null, function (er, data) { + this.get(uri + "?write=true", { auth : auth }, function (er, data) { if (er) return cb(er) // filter all the versions that match Object.keys(data.versions).filter(function (v) { - return semver.satisfies(v, ver) + return semver.satisfies(v, version) }).forEach(function (v) { data.versions[v].deprecated = message }) // now update the doc on the registry - this.request('PUT', url.resolve(uri, data._id), { body : data }, cb) + var options = { + method : "PUT", + body : data, + auth : auth + } + this.request(url.resolve(uri, data._id), options, cb) }.bind(this)) } diff --git a/node_modules/npm-registry-client/lib/fetch.js b/node_modules/npm-registry-client/lib/fetch.js index 75c52de3a..069bc73aa 100644 --- a/node_modules/npm-registry-client/lib/fetch.js +++ b/node_modules/npm-registry-client/lib/fetch.js @@ -6,17 +6,16 @@ var request = require("request") module.exports = fetch -function fetch (uri, headers, cb) { - assert(uri, "must pass resource to fetch") - assert(cb, "must pass callback") - - if (!headers) headers = {} +function fetch (uri, params, cb) { + assert(typeof uri === "string", "must pass uri to request") + assert(params && typeof params === "object", "must pass params to request") + assert(typeof cb === "function", "must pass callback to request") cb = once(cb) var client = this this.attempt(function (operation) { - makeRequest.call(client, uri, headers, function (er, req) { + makeRequest.call(client, uri, params, function (er, req) { if (er) return cb(er) req.on("error", function (er) { @@ -65,14 +64,16 @@ function unstick(response) { }}(response.resume) } -function makeRequest (remote, headers, cb) { +function makeRequest (remote, params, cb) { var parsed = url.parse(remote) this.log.http("fetch", "GET", parsed.href) + var headers = params.headers || {} var er = this.authify( - this.conf.getCredentialsByURI(remote).alwaysAuth, + params.auth && params.auth.alwaysAuth, parsed, - headers + headers, + params.auth ) if (er) return cb(er) diff --git a/node_modules/npm-registry-client/lib/get.js b/node_modules/npm-registry-client/lib/get.js index d7b58092b..17e134977 100644 --- a/node_modules/npm-registry-client/lib/get.js +++ b/node_modules/npm-registry-client/lib/get.js @@ -1,203 +1,22 @@ - module.exports = get -var fs = require("graceful-fs") - , assert = require("assert") - , path = require("path") - , mkdir = require("mkdirp") - , chownr = require("chownr") +var assert = require("assert") , url = require("url") -/** - * options: - * - * timeout: request timeouts - * follow: follow redirects - * staleOk: stale results are OK - * stat: results of checking for cached metadata - * data: the cached metadata +/* + * This is meant to be overridden in specific implementations if you + * want specialized behavior for metadata (i.e. caching). */ -function get (uri, options, cb) { - assert(uri, "must have URL to fetch") - assert(cb, "must have callback") - if (!options) options = {} +function get (uri, params, cb) { + assert(typeof uri === "string", "must pass registry URI to get") + assert(params && typeof params === "object", "must pass params to get") + assert(typeof cb === "function", "must pass callback to get") var parsed = url.parse(uri) - assert(parsed.protocol, "must have a URL that starts with npm:, http:, or https:") - - var cache = this.cacheFile(uri) + "/.cache.json" - - // /-/all is special. - // It uses timestamp-based caching and partial updates, - // because it is a monster. - if (parsed.pathname === "/-/all") { - return requestAll.call(this, uri, cache, cb) - } - - // If the GET is part of a write operation (PUT or DELETE), then - // skip past the cache entirely, but still save the results. - if (uri.match(/\?write=true$/)) { - return get_.call(this, uri, cache, options, cb) - } - - fs.stat(cache, function (er, stat) { - if (!er) fs.readFile(cache, function (er, data) { - try { data = JSON.parse(data) } - catch (ex) { data = null } - options.stat = stat - options.data = data - get_.call(this, uri, cache, options, cb) - }.bind(this)) - else { - get_.call(this, uri, cache, options, cb) - } - }.bind(this)) -} - -function requestAll (uri, cache, cb) { - this.log.info("get", cache) - mkdir(path.dirname(cache), function (er) { - if (er) return cb(er) - fs.readFile(cache, function (er, data) { - if (er) return requestAll_.call(this, uri, 0, {}, cache, cb) - try { - data = JSON.parse(data) - } catch (ex) { - fs.writeFile(cache, "{}", function (er) { - if (er) return cb(new Error("Broken cache.")) - return requestAll_.call(this, uri, 0, {}, cache, cb) - }.bind(this)) - } - var t = +data._updated || 0 - requestAll_.call(this, uri, t, data, cache, cb) - }.bind(this)) - }.bind(this)) -} - -function requestAll_ (uri, c, data, cache, cb) { - // use the cache and update in the background if it's not too old - if (Date.now() - c < 60000) { - cb(null, data) - cb = function () {} - } - - if (c === 0) { - this.log.warn("", "Building the local index for the first time, please be patient") - uri = url.resolve(uri, "/-/all") - } - else { - uri = url.resolve(uri, "/-/all/since?stale=update_after&startkey=" + c) - } - - this.request('GET', uri, null, function (er, updates, _, res) { - if (er) return cb(er, data) - var headers = res.headers - , updated = updates._updated || Date.parse(headers.date) - Object.keys(updates).forEach(function (p) { - data[p] = updates[p] - }) - data._updated = updated - fs.writeFile( cache, JSON.stringify(data) - , function (er) { - delete data._updated - return cb(er, data) - }) - }) -} - -function get_ (uri, cache, options, cb) { - var staleOk = options.staleOk === undefined ? false : options.staleOk - , follow = options.follow - , data = options.data - , stat = options.stat - , etag - - var timeout = options.timeout === undefined ? -1 : options.timeout - timeout = Math.min(timeout, this.conf.get('cache-max') || 0) - timeout = Math.max(timeout, this.conf.get('cache-min') || -Infinity) - if (process.env.COMP_CWORD !== undefined && - process.env.COMP_LINE !== undefined && - process.env.COMP_POINT !== undefined) { - timeout = Math.max(timeout, 60000) - } - - if (data && data._etag) etag = data._etag - - if (timeout && timeout > 0 && options.stat && options.data) { - if ((Date.now() - stat.mtime.getTime())/1000 < timeout) { - this.log.verbose("registry.get", uri, "not expired, no request") - delete data._etag - return cb(null, data, JSON.stringify(data), {statusCode:304}) - } - if (staleOk) { - this.log.verbose("registry.get", uri, "staleOk, background update") - delete data._etag - process.nextTick(cb.bind( null, null, data, JSON.stringify(data) - , {statusCode: 304} )) - cb = function () {} - } - } - - this.request('GET', uri, { etag : etag, follow : follow }, function (er, remoteData, raw, response) { - // if we get an error talking to the registry, but we have it - // from the cache, then just pretend we got it. - if (er && cache && data && !data.error) { - er = null - response = {statusCode: 304} - } - - if (response) { - this.log.silly("registry.get", "cb", [response.statusCode, response.headers]) - if (response.statusCode === 304 && etag) { - remoteData = data - this.log.verbose("etag", uri+" from cache") - } - } - - data = remoteData - if (!data) { - er = er || new Error("failed to fetch from registry: " + uri) - } - - if (er) return cb(er, data, raw, response) - - // just give the write the old college try. if it fails, whatever. - function saved () { - delete data._etag - cb(er, data, raw, response) - } - - saveToCache.call(this, cache, data, saved) - }.bind(this)) -} - -function saveToCache (cache, data, saved) { - if (this._cacheStat) { - var cs = this._cacheStat - return saveToCache_.call(this, cache, data, cs.uid, cs.gid, saved) - } - fs.stat(this.conf.get('cache'), function (er, st) { - if (er) { - return fs.stat(process.env.HOME || "", function (er, st) { - // if this fails, oh well. - if (er) return saved() - this._cacheStat = st - return saveToCache.call(this, cache, data, saved) - }.bind(this)) - } - this._cacheStat = st || { uid: null, gid: null } - return saveToCache.call(this, cache, data, saved) - }.bind(this)) -} + assert( + parsed.protocol === "http:" || parsed.protocol === "https:", + "must have a URL that starts with http: or https:" + ) -function saveToCache_ (cache, data, uid, gid, saved) { - mkdir(path.dirname(cache), function (er, made) { - if (er) return saved() - fs.writeFile(cache, JSON.stringify(data), function (er) { - if (er || uid === null || gid === null) { - return saved() - } - chownr(made || cache, uid, gid, saved) - }) - }) + this.request(uri, params, cb) } diff --git a/node_modules/npm-registry-client/lib/initialize.js b/node_modules/npm-registry-client/lib/initialize.js index b6e89ffe9..9c3571155 100644 --- a/node_modules/npm-registry-client/lib/initialize.js +++ b/node_modules/npm-registry-client/lib/initialize.js @@ -5,27 +5,22 @@ var pkg = require("../package.json") module.exports = initialize function initialize (uri, method, accept, headers) { - if (!this.sessionToken) { - this.sessionToken = crypto.randomBytes(8).toString("hex") - this.log.verbose("request id", this.sessionToken) + if (!this.config.sessionToken) { + this.config.sessionToken = crypto.randomBytes(8).toString("hex") + this.log.verbose("request id", this.config.sessionToken) } - var strict = this.conf.get("strict-ssl") - if (strict === undefined) strict = true - - var p = this.conf.get("proxy") - var sp = this.conf.get("https-proxy") || p - var opts = { url : uri, method : method, headers : headers, - proxy : uri.protocol === "https:" ? sp : p, - localAddress : this.conf.get("local-address"), - strictSSL : strict, - cert : this.conf.get("cert"), - key : this.conf.get("key"), - ca : this.conf.get("ca") + proxy : uri.protocol === "https:" ? this.config.proxy.https + : this.config.proxy.http, + localAddress : this.config.proxy.localAddress, + strictSSL : this.config.ssl.strict, + cert : this.config.ssl.certificate, + key : this.config.ssl.key, + ca : this.config.ssl.ca } headers.version = this.version || pkg.version @@ -33,9 +28,8 @@ function initialize (uri, method, accept, headers) { if (this.refer) headers.referer = this.refer - headers["npm-session"] = this.sessionToken - headers["user-agent"] = this.conf.get("user-agent") || - "node/" + process.version + headers["npm-session"] = this.config.sessionToken + headers["user-agent"] = this.config.userAgent return opts } diff --git a/node_modules/npm-registry-client/lib/publish.js b/node_modules/npm-registry-client/lib/publish.js index c3b2f3e1f..5ee15abf3 100644 --- a/node_modules/npm-registry-client/lib/publish.js +++ b/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") + , Stream = require("stream").Stream + , assert = require("assert") , fixNameField = require("normalize-package-data/lib/fixer.js").fixNameField + , 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) + 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) { diff --git a/node_modules/npm-registry-client/lib/request.js b/node_modules/npm-registry-client/lib/request.js index 910fe0131..aa17ae1ce 100644 --- a/node_modules/npm-registry-client/lib/request.js +++ b/node_modules/npm-registry-client/lib/request.js @@ -1,105 +1,72 @@ -var assert = require("assert") - , url = require("url") - , zlib = require("zlib") - , Stream = require("stream").Stream - -var rm = require("rimraf") - , request = require("request") - , once = require("once") - module.exports = regRequest // npm: means // 1. https // 2. send authorization // 3. content-type is 'application/json' -- metadata -function regRequest (method, uri, options, cb_) { - assert(uri, "must pass resource to load") - assert(cb_, "must pass callback") +// +var assert = require("assert") + , url = require("url") + , zlib = require("zlib") + , Stream = require("stream").Stream + +var request = require("request") + , once = require("once") - options = options || {} +function regRequest (uri, params, cb_) { + assert(typeof uri === "string", "must pass uri to request") + assert(params && typeof params === "object", "must pass params to request") + assert(typeof cb_ === "function", "must pass callback to request") - var parsed = url.parse(uri) - var where = parsed.pathname - var what = options.body - var follow = (typeof options.follow === "boolean" ? options.follow : true) - this.log.verbose("request", "on initialization, where is", where) - - if (parsed.search) { - where = where + parsed.search - parsed.search = "" - } - parsed.pathname = "/" - this.log.verbose("request", "after pass 1, where is", where) + params.method = params.method || "GET" + this.log.verbose("request", "uri", uri) // Since there are multiple places where an error could occur, // don't let the cb be called more than once. var cb = once(cb_) - if (where.match(/^\/?favicon.ico/)) { + if (uri.match(/^\/?favicon.ico/)) { return cb(new Error("favicon.ico isn't a package, it's a picture.")) } - var adduserChange = /^\/?-\/user\/org\.couchdb\.user:([^\/]+)\/-rev/ - , isUserChange = where.match(adduserChange) - , adduserNew = /^\/?-\/user\/org\.couchdb\.user:([^\/]+)$/ - , isNewUser = where.match(adduserNew) - , registry = url.format(parsed) - , alwaysAuth = this.conf.getCredentialsByURI(registry).alwaysAuth - , isDelete = method === "DELETE" - , isWrite = what || isDelete + var adduserChange = /\/?-\/user\/org\.couchdb\.user:([^/]+)\/-rev/ + , isUserChange = uri.match(adduserChange) + , adduserNew = /\/?-\/user\/org\.couchdb\.user:([^/?]+)$/ + , isNewUser = uri.match(adduserNew) + , alwaysAuth = params.auth && params.auth.alwaysAuth + , isDelete = params.method === "DELETE" + , isWrite = params.body || isDelete if (isUserChange && !isWrite) { return cb(new Error("trying to change user document without writing(?!)")) } - // resolve to a full url on the registry - if (!where.match(/^https?:\/\//)) { - this.log.verbose("request", "url raw", where) - - var q = where.split("?") - where = q.shift() - q = q.join("?") - - if (where.charAt(0) !== "/") where = "/" + where - where = "." + where.split("/").map(function (p) { - p = p.trim() - if (p.match(/^org.couchdb.user/)) { - return p.replace(/\//g, encodeURIComponent("/")) - } - return p - }).join("/") - if (q) where += "?" + q - - this.log.verbose("request", "resolving registry", [registry, where]) - where = url.resolve(registry, where) - this.log.verbose("request", "after pass 2, where is", where) - } - - var authed // new users can *not* use auth, because they don't *have* auth yet - if (isNewUser) { + if (isUserChange) { + this.log.verbose("request", "updating existing user; sending authorization") + params.authed = true + } + else if (isNewUser) { this.log.verbose("request", "new user, so can't send auth") - authed = false + params.authed = false } else if (alwaysAuth) { this.log.verbose("request", "always-auth set; sending authorization") - authed = true + params.authed = true } else if (isWrite) { this.log.verbose("request", "sending authorization for write operation") - authed = true + params.authed = true } else { // most of the time we don't want to auth this.log.verbose("request", "no auth needed") - authed = false + params.authed = false } var self = this this.attempt(function (operation) { - makeRequest.call(self, method, where, what, options.etag, follow, authed - , function (er, parsed, raw, response) { + makeRequest.call(self, uri, params, function (er, parsed, raw, response) { if (!er || (er.message && er.message.match(/^SSL Error/))) { if (er) er.code = "ESSL" @@ -127,51 +94,58 @@ function regRequest (method, uri, options, cb_) { }) } -function makeRequest (method, where, what, etag, follow, authed, cb_) { +function makeRequest (uri, params, cb_) { var cb = once(cb_) - var parsed = url.parse(where) + var parsed = url.parse(uri) var headers = {} // metadata should be compressed headers["accept-encoding"] = "gzip" - var er = this.authify(authed, parsed, headers) + var er = this.authify(params.authed, parsed, headers, params.auth) if (er) return cb_(er) var opts = this.initialize( parsed, - method, + params.method, "application/json", headers ) - opts.followRedirect = follow + opts.followRedirect = (typeof params.follow === "boolean" ? params.follow : true) opts.encoding = null // tell request let body be Buffer instance - if (etag) { - this.log.verbose("etag", etag) - headers[method === "GET" ? "if-none-match" : "if-match"] = etag + if (params.etag) { + this.log.verbose("etag", params.etag) + headers[params.method === "GET" ? "if-none-match" : "if-match"] = params.etag } - // figure out wth "what" is - if (what) { - if (Buffer.isBuffer(what) || typeof what === "string") { - opts.body = what + // figure out wth body is + if (params.body) { + if (Buffer.isBuffer(params.body)) { + opts.body = params.body headers["content-type"] = "application/json" - headers["content-length"] = Buffer.byteLength(what) - } else if (what instanceof Stream) { + headers["content-length"] = params.body.length + } + else if (typeof params.body === "string") { + opts.body = params.body + headers["content-type"] = "application/json" + headers["content-length"] = Buffer.byteLength(params.body) + } + else if (params.body instanceof Stream) { headers["content-type"] = "application/octet-stream" - if (what.size) headers["content-length"] = what.size - } else { - delete what._etag - opts.json = what + if (params.body.size) headers["content-length"] = params.body.size + } + else { + delete params.body._etag + opts.json = params.body } } - this.log.http("request", method, parsed.href || "/") + this.log.http("request", params.method, parsed.href || "/") - var done = requestDone.call(this, method, where, cb) + var done = requestDone.call(this, params.method, uri, cb) var req = request(opts, decodeResponseBody(done)) req.on("error", cb) @@ -179,8 +153,8 @@ function makeRequest (method, where, what, etag, follow, authed, cb_) { s.on("error", cb) }) - if (what && (what instanceof Stream)) { - what.pipe(req) + if (params.body && (params.body instanceof Stream)) { + params.body.pipe(req) } } @@ -194,7 +168,9 @@ function decodeResponseBody(cb) { response.socket.destroy() } - if (response.headers["content-encoding"] !== "gzip") return cb(er, response, data) + if (response.headers["content-encoding"] !== "gzip") { + return cb(er, response, data) + } zlib.gunzip(data, function (er, buf) { if (er) return cb(er, response, data) @@ -210,16 +186,14 @@ function requestDone (method, where, cb) { if (er) return cb(er) var urlObj = url.parse(where) - if (urlObj.auth) - urlObj.auth = "***" + if (urlObj.auth) urlObj.auth = "***" this.log.http(response.statusCode, url.format(urlObj)) - var parsed - if (Buffer.isBuffer(data)) { data = data.toString() } + var parsed if (data && typeof data === "string" && response.statusCode !== 304) { try { parsed = JSON.parse(data) @@ -264,14 +238,6 @@ function requestDone (method, where, cb) { er.statusCode = response.statusCode er.code = "E" + er.statusCode - } else if (method !== "HEAD" && method !== "GET") { - // invalidate cache - // This is irrelevant for commands that do etag caching, but - // ls and view also have a timed cache, so this keeps the user - // from thinking that it didn't work when it did. - // Note that failure is an acceptable option here, since the - // only result will be a stale cache for some helper commands. - rm(this.cacheFile(where), function() {}) } return cb(er, parsed, data, response) }.bind(this) diff --git a/node_modules/npm-registry-client/lib/star.js b/node_modules/npm-registry-client/lib/star.js index 97745851e..aa707e159 100644 --- a/node_modules/npm-registry-client/lib/star.js +++ b/node_modules/npm-registry-client/lib/star.js @@ -1,32 +1,48 @@ - module.exports = star -function star (uri, starred, cb) { - var c = this.conf.getCredentialsByURI(uri) - if (c.token) { +var assert = require("assert") + +function star (uri, params, cb) { + assert(typeof uri === "string", "must pass registry URI to star") + assert(params && typeof params === "object", "must pass params to star") + assert(typeof cb === "function", "must pass callback to star") + + var starred = params.starred ? true : false + + var auth = params.auth + assert(auth && typeof auth === "object", "must pass auth to star") + if (auth.token) { return cb(new Error("This operation is unsupported for token-based auth")) } - else if (!c.auth) { + else if (!(auth.username && auth.password)) { return cb(new Error("Must be logged in to star/unstar packages")) } - this.request("GET", uri + "?write=true", null, function (er, fullData) { + var client = this + this.request(uri+"?write=true", { auth : auth }, function (er, fullData) { if (er) return cb(er) - fullData = { _id: fullData._id - , _rev: fullData._rev - , users: fullData.users || {} } + fullData = { + _id : fullData._id, + _rev : fullData._rev, + users : fullData.users || {} + } if (starred) { - this.log.info("starring", fullData._id) - fullData.users[c.username] = true - this.log.verbose("starring", fullData) + client.log.info("starring", fullData._id) + fullData.users[auth.username] = true + client.log.verbose("starring", fullData) } else { - delete fullData.users[c.username] - this.log.info("unstarring", fullData._id) - this.log.verbose("unstarring", fullData) + delete fullData.users[auth.username] + client.log.info("unstarring", fullData._id) + client.log.verbose("unstarring", fullData) } - return this.request("PUT", uri, { body : fullData }, cb) - }.bind(this)) + var options = { + method : "PUT", + body : fullData, + auth : auth + } + return client.request(uri, options, cb) + }) } diff --git a/node_modules/npm-registry-client/lib/stars.js b/node_modules/npm-registry-client/lib/stars.js index 86a252efb..f55551242 100644 --- a/node_modules/npm-registry-client/lib/stars.js +++ b/node_modules/npm-registry-client/lib/stars.js @@ -1,9 +1,18 @@ +module.exports = stars + +var assert = require("assert") var url = require("url") -module.exports = stars +function stars (uri, params, cb) { + assert(typeof uri === "string", "must pass registry URI to stars") + assert(params && typeof params === "object", "must pass params to stars") + assert(typeof cb === "function", "must pass callback to stars") + + var auth = params.auth + var name = params.username || (auth && auth.username) + if (!name) return cb(new Error("must pass either username or auth to stars")) + var encoded = encodeURIComponent(name) + var path = "-/_view/starredByUser?key=\""+encoded+"\"" -function stars (base, name, cb) { - name = encodeURIComponent(name) - var path = "/-/_view/starredByUser?key=\""+name+"\"" - this.request("GET", url.resolve(base, path), null, cb) + this.request(url.resolve(uri, path), { auth : auth }, cb) } diff --git a/node_modules/npm-registry-client/lib/tag.js b/node_modules/npm-registry-client/lib/tag.js index 65430fe93..8b4219907 100644 --- a/node_modules/npm-registry-client/lib/tag.js +++ b/node_modules/npm-registry-client/lib/tag.js @@ -1,5 +1,20 @@ module.exports = tag -function tag (uri, version, tagName, cb) { - this.request("PUT", uri+"/"+tagName, { body : JSON.stringify(version) }, cb) +var assert = require("assert") + +function tag (uri, params, cb) { + assert(typeof uri === "string", "must pass registry URI to tag") + assert(params && typeof params === "object", "must pass params to tag") + assert(typeof cb === "function", "must pass callback to tag") + + assert(typeof params.version === "string", "must pass version to tag") + assert(typeof params.tag === "string", "must pass tag name to tag") + assert(params.auth && typeof params.auth === "object", "must pass auth to tag") + + var options = { + method : "PUT", + body : JSON.stringify(params.version), + auth : params.auth + } + this.request(uri+"/"+params.tag, options, cb) } diff --git a/node_modules/npm-registry-client/lib/unpublish.js b/node_modules/npm-registry-client/lib/unpublish.js index 346d537fe..e6e954935 100644 --- a/node_modules/npm-registry-client/lib/unpublish.js +++ b/node_modules/npm-registry-client/lib/unpublish.js @@ -1,3 +1,4 @@ +module.exports = unpublish // fetch the data // modify to remove the version in question @@ -5,16 +6,26 @@ // else, PUT the modified data // delete the tarball -module.exports = unpublish - var semver = require("semver") , url = require("url") , chain = require("slide").chain + , assert = require("assert") -function unpublish (uri, ver, cb) { - if (typeof cb !== "function") cb = ver, ver = null +function unpublish (uri, params, cb) { + assert(typeof uri === "string", "must pass registry URI to unpublish") + assert(params && typeof params === "object", "must pass params to unpublish") + assert(typeof cb === "function", "must pass callback to unpublish") - this.get(uri + "?write=true", { timeout : -1, follow : false }, function (er, data) { + var ver = params.version + var auth = params.auth + assert(auth && typeof auth === "object", "must pass auth to unpublish") + + var options = { + timeout : -1, + follow : false, + auth : auth + } + this.get(uri + "?write=true", options, function (er, data) { if (er) { this.log.info("unpublish", uri+" not published") return cb() @@ -22,7 +33,7 @@ function unpublish (uri, ver, cb) { // remove all if no version specified if (!ver) { this.log.info("unpublish", "No version specified, removing all") - return this.request("DELETE", uri+"/-rev/"+data._rev, null, cb) + return this.request(uri+"/-rev/"+data._rev, { method : "DELETE", auth : auth }, cb) } var versions = data.versions || {} @@ -40,7 +51,7 @@ function unpublish (uri, ver, cb) { // if it was the only version, then delete the whole package. if (!Object.keys(versions).length) { this.log.info("unpublish", "No versions remain, removing entire package") - return this.request("DELETE", uri + "/-rev/" + data._rev, null, cb) + return this.request(uri+"/-rev/"+data._rev, { method : "DELETE", auth : auth }, cb) } if (!versionPublic) return cb() @@ -58,9 +69,9 @@ function unpublish (uri, ver, cb) { var rev = data._rev delete data._revisions delete data._attachments - var cb_ = detacher.call(this, uri, data, dist, cb) + var cb_ = detacher.call(this, uri, data, dist, auth, cb) - this.request("PUT", uri + "/-rev/" + rev, { body : data }, function (er) { + this.request(uri+"/-rev/"+rev, { method : "PUT", body : data, auth : auth }, function (er) { if (er) { this.log.error("unpublish", "Failed to update data") } @@ -69,20 +80,20 @@ function unpublish (uri, ver, cb) { }.bind(this)) } -function detacher (uri, data, dist, cb) { +function detacher (uri, data, dist, credentials, cb) { return function (er) { if (er) return cb(er) - this.get(escape(uri, data.name), null, function (er, data) { + this.get(escape(uri, data.name), { auth : credentials }, function (er, data) { if (er) return cb(er) var tb = url.parse(dist.tarball) - detach.call(this, uri, data, tb.pathname, data._rev, function (er) { + detach.call(this, uri, data, tb.pathname, data._rev, credentials, function (er) { if (er || !dist.bin) return cb(er) chain(Object.keys(dist.bin).map(function (bt) { return function (cb) { var d = dist.bin[bt] - detach.call(this, uri, data, url.parse(d.tarball).pathname, null, cb) + detach.call(this, uri, data, url.parse(d.tarball).pathname, null, credentials, cb) }.bind(this) }, this), cb) }.bind(this)) @@ -90,13 +101,13 @@ function detacher (uri, data, dist, cb) { }.bind(this) } -function detach (uri, data, path, rev, cb) { +function detach (uri, data, path, rev, credentials, cb) { if (rev) { path += "/-rev/" + rev this.log.info("detach", path) - return this.request("DELETE", url.resolve(uri, path), null, cb) + return this.request(url.resolve(uri, path), { method : "DELETE", auth : credentials }, cb) } - this.get(escape(uri, data.name), null, function (er, data) { + this.get(escape(uri, data.name), { auth : credentials }, function (er, data) { rev = data._rev if (!rev) return cb(new Error( "No _rev found in "+data._id)) diff --git a/node_modules/npm-registry-client/lib/upload.js b/node_modules/npm-registry-client/lib/upload.js deleted file mode 100644 index f624a266c..000000000 --- a/node_modules/npm-registry-client/lib/upload.js +++ /dev/null @@ -1,22 +0,0 @@ -module.exports = upload - -var fs = require('fs') -, Stream = require("stream").Stream - -function upload (uri, file, etag, nofollow, cb) { - if (typeof nofollow === "function") cb = nofollow, nofollow = false - if (typeof etag === "function") cb = etag, etag = null - - if (file instanceof Stream) { - return this.request("PUT", uri, { body : file, etag : etag, follow : !nofollow }, cb) - } - - fs.stat(file, function (er, stat) { - if (er) return cb(er) - var s = fs.createReadStream(file) - s.size = stat.size - s.on("error", cb) - - this.request("PUT", uri, { body : s, etag : etag, follow : !nofollow }, cb) - }.bind(this)) -} diff --git a/node_modules/npm-registry-client/lib/util/nerf-dart.js b/node_modules/npm-registry-client/lib/util/nerf-dart.js deleted file mode 100644 index 3b26a56c6..000000000 --- a/node_modules/npm-registry-client/lib/util/nerf-dart.js +++ /dev/null @@ -1,21 +0,0 @@ -var url = require("url") - -module.exports = toNerfDart - -/** - * Maps a URL to an identifier. - * - * Name courtesy schiffertronix media LLC, a New Jersey corporation - * - * @param {String} uri The URL to be nerfed. - * - * @returns {String} A nerfed URL. - */ -function toNerfDart(uri) { - var parsed = url.parse(uri) - parsed.pathname = "/" - delete parsed.protocol - delete parsed.auth - - return url.format(parsed) -} diff --git a/node_modules/npm-registry-client/lib/whoami.js b/node_modules/npm-registry-client/lib/whoami.js index ffa7bd704..684ce7bfb 100644 --- a/node_modules/npm-registry-client/lib/whoami.js +++ b/node_modules/npm-registry-client/lib/whoami.js @@ -1,13 +1,17 @@ module.exports = whoami var url = require("url") + , assert = require("assert") -function whoami (uri, cb) { - if (!this.conf.getCredentialsByURI(uri)) { - return cb(new Error("Must be logged in to see who you are")) - } +function whoami (uri, params, cb) { + assert(typeof uri === "string", "must pass registry URI to whoami") + assert(params && typeof params === "object", "must pass params to whoami") + assert(typeof cb === "function", "must pass callback to whoami") - this.request("GET", url.resolve(uri, "whoami"), null, function (er, userdata) { + var auth = params.auth + assert(auth && typeof auth === "object", "must pass auth to whoami") + + this.request(url.resolve(uri, "whoami"), { auth : auth }, function (er, userdata) { if (er) return cb(er) cb(null, userdata.username) diff --git a/node_modules/npm-registry-client/node_modules/concat-stream/.npmignore b/node_modules/npm-registry-client/node_modules/concat-stream/.npmignore new file mode 100644 index 000000000..b512c09d4 --- /dev/null +++ b/node_modules/npm-registry-client/node_modules/concat-stream/.npmignore @@ -0,0 +1 @@ +node_modules
\ No newline at end of file diff --git a/node_modules/npm-registry-client/node_modules/concat-stream/LICENSE b/node_modules/npm-registry-client/node_modules/concat-stream/LICENSE new file mode 100644 index 000000000..99c130e1d --- /dev/null +++ b/node_modules/npm-registry-client/node_modules/concat-stream/LICENSE @@ -0,0 +1,24 @@ +The MIT License + +Copyright (c) 2013 Max Ogden + +Permission is hereby granted, free of charge, +to any person obtaining a copy of this software and +associated documentation files (the "Software"), to +deal in the Software without restriction, including +without limitation the rights to use, copy, modify, +merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom +the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice +shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR +ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\ No newline at end of file diff --git a/node_modules/npm-registry-client/node_modules/concat-stream/index.js b/node_modules/npm-registry-client/node_modules/concat-stream/index.js new file mode 100644 index 000000000..7511eed8a --- /dev/null +++ b/node_modules/npm-registry-client/node_modules/concat-stream/index.js @@ -0,0 +1,132 @@ +var Writable = require('readable-stream').Writable +var inherits = require('inherits') +var TA = require('typedarray') +var U8 = typeof Uint8Array !== 'undefined' ? Uint8Array : TA.Uint8Array + +function ConcatStream(opts, cb) { + if (!(this instanceof ConcatStream)) return new ConcatStream(opts, cb) + + if (typeof opts === 'function') { + cb = opts + opts = {} + } + if (!opts) opts = {} + + var encoding = opts.encoding + var shouldInferEncoding = false + + if (!encoding) { + shouldInferEncoding = true + } else { + encoding = String(encoding).toLowerCase() + if (encoding === 'u8' || encoding === 'uint8') { + encoding = 'uint8array' + } + } + + Writable.call(this, { objectMode: true }) + + this.encoding = encoding + this.shouldInferEncoding = shouldInferEncoding + + if (cb) this.on('finish', function () { cb(this.getBody()) }) + this.body = [] +} + +module.exports = ConcatStream +inherits(ConcatStream, Writable) + +ConcatStream.prototype._write = function(chunk, enc, next) { + this.body.push(chunk) + next() +} + +ConcatStream.prototype.inferEncoding = function (buff) { + var firstBuffer = buff === undefined ? this.body[0] : buff; + if (Buffer.isBuffer(firstBuffer)) return 'buffer' + if (typeof Uint8Array !== 'undefined' && firstBuffer instanceof Uint8Array) return 'uint8array' + if (Array.isArray(firstBuffer)) return 'array' + if (typeof firstBuffer === 'string') return 'string' + if (Object.prototype.toString.call(firstBuffer) === "[object Object]") return 'object' + return 'buffer' +} + +ConcatStream.prototype.getBody = function () { + if (!this.encoding && this.body.length === 0) return [] + if (this.shouldInferEncoding) this.encoding = this.inferEncoding() + if (this.encoding === 'array') return arrayConcat(this.body) + if (this.encoding === 'string') return stringConcat(this.body) + if (this.encoding === 'buffer') return bufferConcat(this.body) + if (this.encoding === 'uint8array') return u8Concat(this.body) + return this.body +} + +var isArray = Array.isArray || function (arr) { + return Object.prototype.toString.call(arr) == '[object Array]' +} + +function isArrayish (arr) { + return /Array\]$/.test(Object.prototype.toString.call(arr)) +} + +function stringConcat (parts) { + var strings = [] + var needsToString = false + for (var i = 0; i < parts.length; i++) { + var p = parts[i] + if (typeof p === 'string') { + strings.push(p) + } else if (Buffer.isBuffer(p)) { + strings.push(p) + } else { + strings.push(Buffer(p)) + } + } + if (Buffer.isBuffer(parts[0])) { + strings = Buffer.concat(strings) + strings = strings.toString('utf8') + } else { + strings = strings.join('') + } + return strings +} + +function bufferConcat (parts) { + var bufs = [] + for (var i = 0; i < parts.length; i++) { + var p = parts[i] + if (Buffer.isBuffer(p)) { + bufs.push(p) + } else if (typeof p === 'string' || isArrayish(p) + || (p && typeof p.subarray === 'function')) { + bufs.push(Buffer(p)) + } else bufs.push(Buffer(String(p))) + } + return Buffer.concat(bufs) +} + +function arrayConcat (parts) { + var res = [] + for (var i = 0; i < parts.length; i++) { + res.push.apply(res, parts[i]) + } + return res +} + +function u8Concat (parts) { + var len = 0 + for (var i = 0; i < parts.length; i++) { + if (typeof parts[i] === 'string') { + parts[i] = Buffer(parts[i]) + } + len += parts[i].length + } + var u8 = new U8(len) + for (var i = 0, offset = 0; i < parts.length; i++) { + var part = parts[i] + for (var j = 0; j < part.length; j++) { + u8[offset++] = part[j] + } + } + return u8 +} diff --git a/node_modules/npm-registry-client/node_modules/concat-stream/node_modules/readable-stream/.npmignore b/node_modules/npm-registry-client/node_modules/concat-stream/node_modules/readable-stream/.npmignore new file mode 100644 index 000000000..38344f87a --- /dev/null +++ b/node_modules/npm-registry-client/node_modules/concat-stream/node_modules/readable-stream/.npmignore @@ -0,0 +1,5 @@ +build/ +test/ +examples/ +fs.js +zlib.js
\ No newline at end of file diff --git a/node_modules/npm-registry-client/node_modules/concat-stream/node_modules/readable-stream/LICENSE b/node_modules/npm-registry-client/node_modules/concat-stream/node_modules/readable-stream/LICENSE new file mode 100644 index 000000000..e3d4e695a --- /dev/null +++ b/node_modules/npm-registry-client/node_modules/concat-stream/node_modules/readable-stream/LICENSE @@ -0,0 +1,18 @@ +Copyright Joyent, Inc. and other Node contributors. All rights reserved. +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to +deal in the Software without restriction, including without limitation the +rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +sell copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +IN THE SOFTWARE. diff --git a/node_modules/npm-registry-client/node_modules/concat-stream/node_modules/readable-stream/README.md b/node_modules/npm-registry-client/node_modules/concat-stream/node_modules/readable-stream/README.md new file mode 100644 index 000000000..e46b82390 --- /dev/null +++ b/node_modules/npm-registry-client/node_modules/concat-stream/node_modules/readable-stream/README.md @@ -0,0 +1,15 @@ +# readable-stream + +***Node-core streams for userland*** + +[![NPM](https://nodei.co/npm/readable-stream.png?downloads=true&downloadRank=true)](https://nodei.co/npm/readable-stream/) +[![NPM](https://nodei.co/npm-dl/readable-stream.png&months=6&height=3)](https://nodei.co/npm/readable-stream/) + +This package is a mirror of the Streams2 and Streams3 implementations in Node-core. + +If you want to guarantee a stable streams base, regardless of what version of Node you, or the users of your libraries are using, use **readable-stream** *only* and avoid the *"stream"* module in Node-core. + +**readable-stream** comes in two major versions, v1.0.x and v1.1.x. The former tracks the Streams2 implementation in Node 0.10, including bug-fixes and minor improvements as they are added. The latter tracks Streams3 as it develops in Node 0.11; we will likely see a v1.2.x branch for Node 0.12. + +**readable-stream** uses proper patch-level versioning so if you pin to `"~1.0.0"` you’ll get the latest Node 0.10 Streams2 implementation, including any fixes and minor non-breaking improvements. The patch-level versions of 1.0.x and 1.1.x should mirror the patch-level versions of Node-core releases. You should prefer the **1.0.x** releases for now and when you’re ready to start using Streams3, pin to `"~1.1.0"` + diff --git a/node_modules/npm-registry-client/node_modules/concat-stream/node_modules/readable-stream/duplex.js b/node_modules/npm-registry-client/node_modules/concat-stream/node_modules/readable-stream/duplex.js new file mode 100644 index 000000000..ca807af87 --- /dev/null +++ b/node_modules/npm-registry-client/node_modules/concat-stream/node_modules/readable-stream/duplex.js @@ -0,0 +1 @@ +module.exports = require("./lib/_stream_duplex.js") diff --git a/node_modules/npm-registry-client/node_modules/concat-stream/node_modules/readable-stream/float.patch b/node_modules/npm-registry-client/node_modules/concat-stream/node_modules/readable-stream/float.patch new file mode 100644 index 000000000..b984607a4 --- /dev/null +++ b/node_modules/npm-registry-client/node_modules/concat-stream/node_modules/readable-stream/float.patch @@ -0,0 +1,923 @@ +diff --git a/lib/_stream_duplex.js b/lib/_stream_duplex.js +index c5a741c..a2e0d8e 100644 +--- a/lib/_stream_duplex.js ++++ b/lib/_stream_duplex.js +@@ -26,8 +26,8 @@ + + module.exports = Duplex; + var util = require('util'); +-var Readable = require('_stream_readable'); +-var Writable = require('_stream_writable'); ++var Readable = require('./_stream_readable'); ++var Writable = require('./_stream_writable'); + + util.inherits(Duplex, Readable); + +diff --git a/lib/_stream_passthrough.js b/lib/_stream_passthrough.js +index a5e9864..330c247 100644 +--- a/lib/_stream_passthrough.js ++++ b/lib/_stream_passthrough.js +@@ -25,7 +25,7 @@ + + module.exports = PassThrough; + +-var Transform = require('_stream_transform'); ++var Transform = require('./_stream_transform'); + var util = require('util'); + util.inherits(PassThrough, Transform); + +diff --git a/lib/_stream_readable.js b/lib/_stream_readable.js +index 0c3fe3e..90a8298 100644 +--- a/lib/_stream_readable.js ++++ b/lib/_stream_readable.js +@@ -23,10 +23,34 @@ module.exports = Readable; + Readable.ReadableState = ReadableState; + + var EE = require('events').EventEmitter; ++if (!EE.listenerCount) EE.listenerCount = function(emitter, type) { ++ return emitter.listeners(type).length; ++}; ++ ++if (!global.setImmediate) global.setImmediate = function setImmediate(fn) { ++ return setTimeout(fn, 0); ++}; ++if (!global.clearImmediate) global.clearImmediate = function clearImmediate(i) { ++ return clearTimeout(i); ++}; ++ + var Stream = require('stream'); + var util = require('util'); ++if (!util.isUndefined) { ++ var utilIs = require('core-util-is'); ++ for (var f in utilIs) { ++ util[f] = utilIs[f]; ++ } ++} + var StringDecoder; +-var debug = util.debuglog('stream'); ++var debug; ++if (util.debuglog) ++ debug = util.debuglog('stream'); ++else try { ++ debug = require('debuglog')('stream'); ++} catch (er) { ++ debug = function() {}; ++} + + util.inherits(Readable, Stream); + +@@ -380,7 +404,7 @@ function chunkInvalid(state, chunk) { + + + function onEofChunk(stream, state) { +- if (state.decoder && !state.ended) { ++ if (state.decoder && !state.ended && state.decoder.end) { + var chunk = state.decoder.end(); + if (chunk && chunk.length) { + state.buffer.push(chunk); +diff --git a/lib/_stream_transform.js b/lib/_stream_transform.js +index b1f9fcc..b0caf57 100644 +--- a/lib/_stream_transform.js ++++ b/lib/_stream_transform.js +@@ -64,8 +64,14 @@ + + module.exports = Transform; + +-var Duplex = require('_stream_duplex'); ++var Duplex = require('./_stream_duplex'); + var util = require('util'); ++if (!util.isUndefined) { ++ var utilIs = require('core-util-is'); ++ for (var f in utilIs) { ++ util[f] = utilIs[f]; ++ } ++} + util.inherits(Transform, Duplex); + + +diff --git a/lib/_stream_writable.js b/lib/_stream_writable.js +index ba2e920..f49288b 100644 +--- a/lib/_stream_writable.js ++++ b/lib/_stream_writable.js +@@ -27,6 +27,12 @@ module.exports = Writable; + Writable.WritableState = WritableState; + + var util = require('util'); ++if (!util.isUndefined) { ++ var utilIs = require('core-util-is'); ++ for (var f in utilIs) { ++ util[f] = utilIs[f]; ++ } ++} + var Stream = require('stream'); + + util.inherits(Writable, Stream); +@@ -119,7 +125,7 @@ function WritableState(options, stream) { + function Writable(options) { + // Writable ctor is applied to Duplexes, though they're not + // instanceof Writable, they're instanceof Readable. +- if (!(this instanceof Writable) && !(this instanceof Stream.Duplex)) ++ if (!(this instanceof Writable) && !(this instanceof require('./_stream_duplex'))) + return new Writable(options); + + this._writableState = new WritableState(options, this); +diff --git a/test/simple/test-stream-big-push.js b/test/simple/test-stream-big-push.js +index e3787e4..8cd2127 100644 +--- a/test/simple/test-stream-big-push.js ++++ b/test/simple/test-stream-big-push.js +@@ -21,7 +21,7 @@ + + var common = require('../common'); + var assert = require('assert'); +-var stream = require('stream'); ++var stream = require('../../'); + var str = 'asdfasdfasdfasdfasdf'; + + var r = new stream.Readable({ +diff --git a/test/simple/test-stream-end-paused.js b/test/simple/test-stream-end-paused.js +index bb73777..d40efc7 100644 +--- a/test/simple/test-stream-end-paused.js ++++ b/test/simple/test-stream-end-paused.js +@@ -25,7 +25,7 @@ var gotEnd = false; + + // Make sure we don't miss the end event for paused 0-length streams + +-var Readable = require('stream').Readable; ++var Readable = require('../../').Readable; + var stream = new Readable(); + var calledRead = false; + stream._read = function() { +diff --git a/test/simple/test-stream-pipe-after-end.js b/test/simple/test-stream-pipe-after-end.js +index b46ee90..0be8366 100644 +--- a/test/simple/test-stream-pipe-after-end.js ++++ b/test/simple/test-stream-pipe-after-end.js +@@ -22,8 +22,8 @@ + var common = require('../common'); + var assert = require('assert'); + +-var Readable = require('_stream_readable'); +-var Writable = require('_stream_writable'); ++var Readable = require('../../lib/_stream_readable'); ++var Writable = require('../../lib/_stream_writable'); + var util = require('util'); + + util.inherits(TestReadable, Readable); +diff --git a/test/simple/test-stream-pipe-cleanup.js b/test/simple/test-stream-pipe-cleanup.js +deleted file mode 100644 +index f689358..0000000 +--- a/test/simple/test-stream-pipe-cleanup.js ++++ /dev/null +@@ -1,122 +0,0 @@ +-// Copyright Joyent, Inc. and other Node contributors. +-// +-// Permission is hereby granted, free of charge, to any person obtaining a +-// copy of this software and associated documentation files (the +-// "Software"), to deal in the Software without restriction, including +-// without limitation the rights to use, copy, modify, merge, publish, +-// distribute, sublicense, and/or sell copies of the Software, and to permit +-// persons to whom the Software is furnished to do so, subject to the +-// following conditions: +-// +-// The above copyright notice and this permission notice shall be included +-// in all copies or substantial portions of the Software. +-// +-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +-// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +-// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +-// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +-// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE +-// USE OR OTHER DEALINGS IN THE SOFTWARE. +- +-// This test asserts that Stream.prototype.pipe does not leave listeners +-// hanging on the source or dest. +- +-var common = require('../common'); +-var stream = require('stream'); +-var assert = require('assert'); +-var util = require('util'); +- +-function Writable() { +- this.writable = true; +- this.endCalls = 0; +- stream.Stream.call(this); +-} +-util.inherits(Writable, stream.Stream); +-Writable.prototype.end = function() { +- this.endCalls++; +-}; +- +-Writable.prototype.destroy = function() { +- this.endCalls++; +-}; +- +-function Readable() { +- this.readable = true; +- stream.Stream.call(this); +-} +-util.inherits(Readable, stream.Stream); +- +-function Duplex() { +- this.readable = true; +- Writable.call(this); +-} +-util.inherits(Duplex, Writable); +- +-var i = 0; +-var limit = 100; +- +-var w = new Writable(); +- +-var r; +- +-for (i = 0; i < limit; i++) { +- r = new Readable(); +- r.pipe(w); +- r.emit('end'); +-} +-assert.equal(0, r.listeners('end').length); +-assert.equal(limit, w.endCalls); +- +-w.endCalls = 0; +- +-for (i = 0; i < limit; i++) { +- r = new Readable(); +- r.pipe(w); +- r.emit('close'); +-} +-assert.equal(0, r.listeners('close').length); +-assert.equal(limit, w.endCalls); +- +-w.endCalls = 0; +- +-r = new Readable(); +- +-for (i = 0; i < limit; i++) { +- w = new Writable(); +- r.pipe(w); +- w.emit('close'); +-} +-assert.equal(0, w.listeners('close').length); +- +-r = new Readable(); +-w = new Writable(); +-var d = new Duplex(); +-r.pipe(d); // pipeline A +-d.pipe(w); // pipeline B +-assert.equal(r.listeners('end').length, 2); // A.onend, A.cleanup +-assert.equal(r.listeners('close').length, 2); // A.onclose, A.cleanup +-assert.equal(d.listeners('end').length, 2); // B.onend, B.cleanup +-assert.equal(d.listeners('close').length, 3); // A.cleanup, B.onclose, B.cleanup +-assert.equal(w.listeners('end').length, 0); +-assert.equal(w.listeners('close').length, 1); // B.cleanup +- +-r.emit('end'); +-assert.equal(d.endCalls, 1); +-assert.equal(w.endCalls, 0); +-assert.equal(r.listeners('end').length, 0); +-assert.equal(r.listeners('close').length, 0); +-assert.equal(d.listeners('end').length, 2); // B.onend, B.cleanup +-assert.equal(d.listeners('close').length, 2); // B.onclose, B.cleanup +-assert.equal(w.listeners('end').length, 0); +-assert.equal(w.listeners('close').length, 1); // B.cleanup +- +-d.emit('end'); +-assert.equal(d.endCalls, 1); +-assert.equal(w.endCalls, 1); +-assert.equal(r.listeners('end').length, 0); +-assert.equal(r.listeners('close').length, 0); +-assert.equal(d.listeners('end').length, 0); +-assert.equal(d.listeners('close').length, 0); +-assert.equal(w.listeners('end').length, 0); +-assert.equal(w.listeners('close').length, 0); +diff --git a/test/simple/test-stream-pipe-error-handling.js b/test/simple/test-stream-pipe-error-handling.js +index c5d724b..c7d6b7d 100644 +--- a/test/simple/test-stream-pipe-error-handling.js ++++ b/test/simple/test-stream-pipe-error-handling.js +@@ -21,7 +21,7 @@ + + var common = require('../common'); + var assert = require('assert'); +-var Stream = require('stream').Stream; ++var Stream = require('../../').Stream; + + (function testErrorListenerCatches() { + var source = new Stream(); +diff --git a/test/simple/test-stream-pipe-event.js b/test/simple/test-stream-pipe-event.js +index cb9d5fe..56f8d61 100644 +--- a/test/simple/test-stream-pipe-event.js ++++ b/test/simple/test-stream-pipe-event.js +@@ -20,7 +20,7 @@ + // USE OR OTHER DEALINGS IN THE SOFTWARE. + + var common = require('../common'); +-var stream = require('stream'); ++var stream = require('../../'); + var assert = require('assert'); + var util = require('util'); + +diff --git a/test/simple/test-stream-push-order.js b/test/simple/test-stream-push-order.js +index f2e6ec2..a5c9bf9 100644 +--- a/test/simple/test-stream-push-order.js ++++ b/test/simple/test-stream-push-order.js +@@ -20,7 +20,7 @@ + // USE OR OTHER DEALINGS IN THE SOFTWARE. + + var common = require('../common.js'); +-var Readable = require('stream').Readable; ++var Readable = require('../../').Readable; + var assert = require('assert'); + + var s = new Readable({ +diff --git a/test/simple/test-stream-push-strings.js b/test/simple/test-stream-push-strings.js +index 06f43dc..1701a9a 100644 +--- a/test/simple/test-stream-push-strings.js ++++ b/test/simple/test-stream-push-strings.js +@@ -22,7 +22,7 @@ + var common = require('../common'); + var assert = require('assert'); + +-var Readable = require('stream').Readable; ++var Readable = require('../../').Readable; + var util = require('util'); + + util.inherits(MyStream, Readable); +diff --git a/test/simple/test-stream-readable-event.js b/test/simple/test-stream-readable-event.js +index ba6a577..a8e6f7b 100644 +--- a/test/simple/test-stream-readable-event.js ++++ b/test/simple/test-stream-readable-event.js +@@ -22,7 +22,7 @@ + var common = require('../common'); + var assert = require('assert'); + +-var Readable = require('stream').Readable; ++var Readable = require('../../').Readable; + + (function first() { + // First test, not reading when the readable is added. +diff --git a/test/simple/test-stream-readable-flow-recursion.js b/test/simple/test-stream-readable-flow-recursion.js +index 2891ad6..11689ba 100644 +--- a/test/simple/test-stream-readable-flow-recursion.js ++++ b/test/simple/test-stream-readable-flow-recursion.js +@@ -27,7 +27,7 @@ var assert = require('assert'); + // more data continuously, but without triggering a nextTick + // warning or RangeError. + +-var Readable = require('stream').Readable; ++var Readable = require('../../').Readable; + + // throw an error if we trigger a nextTick warning. + process.throwDeprecation = true; +diff --git a/test/simple/test-stream-unshift-empty-chunk.js b/test/simple/test-stream-unshift-empty-chunk.js +index 0c96476..7827538 100644 +--- a/test/simple/test-stream-unshift-empty-chunk.js ++++ b/test/simple/test-stream-unshift-empty-chunk.js +@@ -24,7 +24,7 @@ var assert = require('assert'); + + // This test verifies that stream.unshift(Buffer(0)) or + // stream.unshift('') does not set state.reading=false. +-var Readable = require('stream').Readable; ++var Readable = require('../../').Readable; + + var r = new Readable(); + var nChunks = 10; +diff --git a/test/simple/test-stream-unshift-read-race.js b/test/simple/test-stream-unshift-read-race.js +index 83fd9fa..17c18aa 100644 +--- a/test/simple/test-stream-unshift-read-race.js ++++ b/test/simple/test-stream-unshift-read-race.js +@@ -29,7 +29,7 @@ var assert = require('assert'); + // 3. push() after the EOF signaling null is an error. + // 4. _read() is not called after pushing the EOF null chunk. + +-var stream = require('stream'); ++var stream = require('../../'); + var hwm = 10; + var r = stream.Readable({ highWaterMark: hwm }); + var chunks = 10; +@@ -51,7 +51,14 @@ r._read = function(n) { + + function push(fast) { + assert(!pushedNull, 'push() after null push'); +- var c = pos >= data.length ? null : data.slice(pos, pos + n); ++ var c; ++ if (pos >= data.length) ++ c = null; ++ else { ++ if (n + pos > data.length) ++ n = data.length - pos; ++ c = data.slice(pos, pos + n); ++ } + pushedNull = c === null; + if (fast) { + pos += n; +diff --git a/test/simple/test-stream-writev.js b/test/simple/test-stream-writev.js +index 5b49e6e..b5321f3 100644 +--- a/test/simple/test-stream-writev.js ++++ b/test/simple/test-stream-writev.js +@@ -22,7 +22,7 @@ + var common = require('../common'); + var assert = require('assert'); + +-var stream = require('stream'); ++var stream = require('../../'); + + var queue = []; + for (var decode = 0; decode < 2; decode++) { +diff --git a/test/simple/test-stream2-basic.js b/test/simple/test-stream2-basic.js +index 3814bf0..248c1be 100644 +--- a/test/simple/test-stream2-basic.js ++++ b/test/simple/test-stream2-basic.js +@@ -21,7 +21,7 @@ + + + var common = require('../common.js'); +-var R = require('_stream_readable'); ++var R = require('../../lib/_stream_readable'); + var assert = require('assert'); + + var util = require('util'); +diff --git a/test/simple/test-stream2-compatibility.js b/test/simple/test-stream2-compatibility.js +index 6cdd4e9..f0fa84b 100644 +--- a/test/simple/test-stream2-compatibility.js ++++ b/test/simple/test-stream2-compatibility.js +@@ -21,7 +21,7 @@ + + + var common = require('../common.js'); +-var R = require('_stream_readable'); ++var R = require('../../lib/_stream_readable'); + var assert = require('assert'); + + var util = require('util'); +diff --git a/test/simple/test-stream2-finish-pipe.js b/test/simple/test-stream2-finish-pipe.js +index 39b274f..006a19b 100644 +--- a/test/simple/test-stream2-finish-pipe.js ++++ b/test/simple/test-stream2-finish-pipe.js +@@ -20,7 +20,7 @@ + // USE OR OTHER DEALINGS IN THE SOFTWARE. + + var common = require('../common.js'); +-var stream = require('stream'); ++var stream = require('../../'); + var Buffer = require('buffer').Buffer; + + var r = new stream.Readable(); +diff --git a/test/simple/test-stream2-fs.js b/test/simple/test-stream2-fs.js +deleted file mode 100644 +index e162406..0000000 +--- a/test/simple/test-stream2-fs.js ++++ /dev/null +@@ -1,72 +0,0 @@ +-// Copyright Joyent, Inc. and other Node contributors. +-// +-// Permission is hereby granted, free of charge, to any person obtaining a +-// copy of this software and associated documentation files (the +-// "Software"), to deal in the Software without restriction, including +-// without limitation the rights to use, copy, modify, merge, publish, +-// distribute, sublicense, and/or sell copies of the Software, and to permit +-// persons to whom the Software is furnished to do so, subject to the +-// following conditions: +-// +-// The above copyright notice and this permission notice shall be included +-// in all copies or substantial portions of the Software. +-// +-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +-// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +-// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +-// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +-// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE +-// USE OR OTHER DEALINGS IN THE SOFTWARE. +- +- +-var common = require('../common.js'); +-var R = require('_stream_readable'); +-var assert = require('assert'); +- +-var fs = require('fs'); +-var FSReadable = fs.ReadStream; +- +-var path = require('path'); +-var file = path.resolve(common.fixturesDir, 'x1024.txt'); +- +-var size = fs.statSync(file).size; +- +-var expectLengths = [1024]; +- +-var util = require('util'); +-var Stream = require('stream'); +- +-util.inherits(TestWriter, Stream); +- +-function TestWriter() { +- Stream.apply(this); +- this.buffer = []; +- this.length = 0; +-} +- +-TestWriter.prototype.write = function(c) { +- this.buffer.push(c.toString()); +- this.length += c.length; +- return true; +-}; +- +-TestWriter.prototype.end = function(c) { +- if (c) this.buffer.push(c.toString()); +- this.emit('results', this.buffer); +-} +- +-var r = new FSReadable(file); +-var w = new TestWriter(); +- +-w.on('results', function(res) { +- console.error(res, w.length); +- assert.equal(w.length, size); +- var l = 0; +- assert.deepEqual(res.map(function (c) { +- return c.length; +- }), expectLengths); +- console.log('ok'); +-}); +- +-r.pipe(w); +diff --git a/test/simple/test-stream2-httpclient-response-end.js b/test/simple/test-stream2-httpclient-response-end.js +deleted file mode 100644 +index 15cffc2..0000000 +--- a/test/simple/test-stream2-httpclient-response-end.js ++++ /dev/null +@@ -1,52 +0,0 @@ +-// Copyright Joyent, Inc. and other Node contributors. +-// +-// Permission is hereby granted, free of charge, to any person obtaining a +-// copy of this software and associated documentation files (the +-// "Software"), to deal in the Software without restriction, including +-// without limitation the rights to use, copy, modify, merge, publish, +-// distribute, sublicense, and/or sell copies of the Software, and to permit +-// persons to whom the Software is furnished to do so, subject to the +-// following conditions: +-// +-// The above copyright notice and this permission notice shall be included +-// in all copies or substantial portions of the Software. +-// +-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +-// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +-// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +-// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +-// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE +-// USE OR OTHER DEALINGS IN THE SOFTWARE. +- +-var common = require('../common.js'); +-var assert = require('assert'); +-var http = require('http'); +-var msg = 'Hello'; +-var readable_event = false; +-var end_event = false; +-var server = http.createServer(function(req, res) { +- res.writeHead(200, {'Content-Type': 'text/plain'}); +- res.end(msg); +-}).listen(common.PORT, function() { +- http.get({port: common.PORT}, function(res) { +- var data = ''; +- res.on('readable', function() { +- console.log('readable event'); +- readable_event = true; +- data += res.read(); +- }); +- res.on('end', function() { +- console.log('end event'); +- end_event = true; +- assert.strictEqual(msg, data); +- server.close(); +- }); +- }); +-}); +- +-process.on('exit', function() { +- assert(readable_event); +- assert(end_event); +-}); +- +diff --git a/test/simple/test-stream2-large-read-stall.js b/test/simple/test-stream2-large-read-stall.js +index 2fbfbca..667985b 100644 +--- a/test/simple/test-stream2-large-read-stall.js ++++ b/test/simple/test-stream2-large-read-stall.js +@@ -30,7 +30,7 @@ var PUSHSIZE = 20; + var PUSHCOUNT = 1000; + var HWM = 50; + +-var Readable = require('stream').Readable; ++var Readable = require('../../').Readable; + var r = new Readable({ + highWaterMark: HWM + }); +@@ -39,23 +39,23 @@ var rs = r._readableState; + r._read = push; + + r.on('readable', function() { +- console.error('>> readable'); ++ //console.error('>> readable'); + do { +- console.error(' > read(%d)', READSIZE); ++ //console.error(' > read(%d)', READSIZE); + var ret = r.read(READSIZE); +- console.error(' < %j (%d remain)', ret && ret.length, rs.length); ++ //console.error(' < %j (%d remain)', ret && ret.length, rs.length); + } while (ret && ret.length === READSIZE); + +- console.error('<< after read()', +- ret && ret.length, +- rs.needReadable, +- rs.length); ++ //console.error('<< after read()', ++ // ret && ret.length, ++ // rs.needReadable, ++ // rs.length); + }); + + var endEmitted = false; + r.on('end', function() { + endEmitted = true; +- console.error('end'); ++ //console.error('end'); + }); + + var pushes = 0; +@@ -64,11 +64,11 @@ function push() { + return; + + if (pushes++ === PUSHCOUNT) { +- console.error(' push(EOF)'); ++ //console.error(' push(EOF)'); + return r.push(null); + } + +- console.error(' push #%d', pushes); ++ //console.error(' push #%d', pushes); + if (r.push(new Buffer(PUSHSIZE))) + setTimeout(push); + } +diff --git a/test/simple/test-stream2-objects.js b/test/simple/test-stream2-objects.js +index 3e6931d..ff47d89 100644 +--- a/test/simple/test-stream2-objects.js ++++ b/test/simple/test-stream2-objects.js +@@ -21,8 +21,8 @@ + + + var common = require('../common.js'); +-var Readable = require('_stream_readable'); +-var Writable = require('_stream_writable'); ++var Readable = require('../../lib/_stream_readable'); ++var Writable = require('../../lib/_stream_writable'); + var assert = require('assert'); + + // tiny node-tap lookalike. +diff --git a/test/simple/test-stream2-pipe-error-handling.js b/test/simple/test-stream2-pipe-error-handling.js +index cf7531c..e3f3e4e 100644 +--- a/test/simple/test-stream2-pipe-error-handling.js ++++ b/test/simple/test-stream2-pipe-error-handling.js +@@ -21,7 +21,7 @@ + + var common = require('../common'); + var assert = require('assert'); +-var stream = require('stream'); ++var stream = require('../../'); + + (function testErrorListenerCatches() { + var count = 1000; +diff --git a/test/simple/test-stream2-pipe-error-once-listener.js b/test/simple/test-stream2-pipe-error-once-listener.js +index 5e8e3cb..53b2616 100755 +--- a/test/simple/test-stream2-pipe-error-once-listener.js ++++ b/test/simple/test-stream2-pipe-error-once-listener.js +@@ -24,7 +24,7 @@ var common = require('../common.js'); + var assert = require('assert'); + + var util = require('util'); +-var stream = require('stream'); ++var stream = require('../../'); + + + var Read = function() { +diff --git a/test/simple/test-stream2-push.js b/test/simple/test-stream2-push.js +index b63edc3..eb2b0e9 100644 +--- a/test/simple/test-stream2-push.js ++++ b/test/simple/test-stream2-push.js +@@ -20,7 +20,7 @@ + // USE OR OTHER DEALINGS IN THE SOFTWARE. + + var common = require('../common.js'); +-var stream = require('stream'); ++var stream = require('../../'); + var Readable = stream.Readable; + var Writable = stream.Writable; + var assert = require('assert'); +diff --git a/test/simple/test-stream2-read-sync-stack.js b/test/simple/test-stream2-read-sync-stack.js +index e8a7305..9740a47 100644 +--- a/test/simple/test-stream2-read-sync-stack.js ++++ b/test/simple/test-stream2-read-sync-stack.js +@@ -21,7 +21,7 @@ + + var common = require('../common'); + var assert = require('assert'); +-var Readable = require('stream').Readable; ++var Readable = require('../../').Readable; + var r = new Readable(); + var N = 256 * 1024; + +diff --git a/test/simple/test-stream2-readable-empty-buffer-no-eof.js b/test/simple/test-stream2-readable-empty-buffer-no-eof.js +index cd30178..4b1659d 100644 +--- a/test/simple/test-stream2-readable-empty-buffer-no-eof.js ++++ b/test/simple/test-stream2-readable-empty-buffer-no-eof.js +@@ -22,10 +22,9 @@ + var common = require('../common'); + var assert = require('assert'); + +-var Readable = require('stream').Readable; ++var Readable = require('../../').Readable; + + test1(); +-test2(); + + function test1() { + var r = new Readable(); +@@ -88,31 +87,3 @@ function test1() { + console.log('ok'); + }); + } +- +-function test2() { +- var r = new Readable({ encoding: 'base64' }); +- var reads = 5; +- r._read = function(n) { +- if (!reads--) +- return r.push(null); // EOF +- else +- return r.push(new Buffer('x')); +- }; +- +- var results = []; +- function flow() { +- var chunk; +- while (null !== (chunk = r.read())) +- results.push(chunk + ''); +- } +- r.on('readable', flow); +- r.on('end', function() { +- results.push('EOF'); +- }); +- flow(); +- +- process.on('exit', function() { +- assert.deepEqual(results, [ 'eHh4', 'eHg=', 'EOF' ]); +- console.log('ok'); +- }); +-} +diff --git a/test/simple/test-stream2-readable-from-list.js b/test/simple/test-stream2-readable-from-list.js +index 7c96ffe..04a96f5 100644 +--- a/test/simple/test-stream2-readable-from-list.js ++++ b/test/simple/test-stream2-readable-from-list.js +@@ -21,7 +21,7 @@ + + var assert = require('assert'); + var common = require('../common.js'); +-var fromList = require('_stream_readable')._fromList; ++var fromList = require('../../lib/_stream_readable')._fromList; + + // tiny node-tap lookalike. + var tests = []; +diff --git a/test/simple/test-stream2-readable-legacy-drain.js b/test/simple/test-stream2-readable-legacy-drain.js +index 675da8e..51fd3d5 100644 +--- a/test/simple/test-stream2-readable-legacy-drain.js ++++ b/test/simple/test-stream2-readable-legacy-drain.js +@@ -22,7 +22,7 @@ + var common = require('../common'); + var assert = require('assert'); + +-var Stream = require('stream'); ++var Stream = require('../../'); + var Readable = Stream.Readable; + + var r = new Readable(); +diff --git a/test/simple/test-stream2-readable-non-empty-end.js b/test/simple/test-stream2-readable-non-empty-end.js +index 7314ae7..c971898 100644 +--- a/test/simple/test-stream2-readable-non-empty-end.js ++++ b/test/simple/test-stream2-readable-non-empty-end.js +@@ -21,7 +21,7 @@ + + var assert = require('assert'); + var common = require('../common.js'); +-var Readable = require('_stream_readable'); ++var Readable = require('../../lib/_stream_readable'); + + var len = 0; + var chunks = new Array(10); +diff --git a/test/simple/test-stream2-readable-wrap-empty.js b/test/simple/test-stream2-readable-wrap-empty.js +index 2e5cf25..fd8a3dc 100644 +--- a/test/simple/test-stream2-readable-wrap-empty.js ++++ b/test/simple/test-stream2-readable-wrap-empty.js +@@ -22,7 +22,7 @@ + var common = require('../common'); + var assert = require('assert'); + +-var Readable = require('_stream_readable'); ++var Readable = require('../../lib/_stream_readable'); + var EE = require('events').EventEmitter; + + var oldStream = new EE(); +diff --git a/test/simple/test-stream2-readable-wrap.js b/test/simple/test-stream2-readable-wrap.js +index 90eea01..6b177f7 100644 +--- a/test/simple/test-stream2-readable-wrap.js ++++ b/test/simple/test-stream2-readable-wrap.js +@@ -22,8 +22,8 @@ + var common = require('../common'); + var assert = require('assert'); + +-var Readable = require('_stream_readable'); +-var Writable = require('_stream_writable'); ++var Readable = require('../../lib/_stream_readable'); ++var Writable = require('../../lib/_stream_writable'); + var EE = require('events').EventEmitter; + + var testRuns = 0, completedRuns = 0; +diff --git a/test/simple/test-stream2-set-encoding.js b/test/simple/test-stream2-set-encoding.js +index 5d2c32a..685531b 100644 +--- a/test/simple/test-stream2-set-encoding.js ++++ b/test/simple/test-stream2-set-encoding.js +@@ -22,7 +22,7 @@ + + var common = require('../common.js'); + var assert = require('assert'); +-var R = require('_stream_readable'); ++var R = require('../../lib/_stream_readable'); + var util = require('util'); + + // tiny node-tap lookalike. +diff --git a/test/simple/test-stream2-transform.js b/test/simple/test-stream2-transform.js +index 9c9ddd8..a0cacc6 100644 +--- a/test/simple/test-stream2-transform.js ++++ b/test/simple/test-stream2-transform.js +@@ -21,8 +21,8 @@ + + var assert = require('assert'); + var common = require('../common.js'); +-var PassThrough = require('_stream_passthrough'); +-var Transform = require('_stream_transform'); ++var PassThrough = require('../../').PassThrough; ++var Transform = require('../../').Transform; + + // tiny node-tap lookalike. + var tests = []; +diff --git a/test/simple/test-stream2-unpipe-drain.js b/test/simple/test-stream2-unpipe-drain.js +index d66dc3c..365b327 100644 +--- a/test/simple/test-stream2-unpipe-drain.js ++++ b/test/simple/test-stream2-unpipe-drain.js +@@ -22,7 +22,7 @@ + + var common = require('../common.js'); + var assert = require('assert'); +-var stream = require('stream'); ++var stream = require('../../'); + var crypto = require('crypto'); + + var util = require('util'); +diff --git a/test/simple/test-stream2-unpipe-leak.js b/test/simple/test-stream2-unpipe-leak.js +index 99f8746..17c92ae 100644 +--- a/test/simple/test-stream2-unpipe-leak.js ++++ b/test/simple/test-stream2-unpipe-leak.js +@@ -22,7 +22,7 @@ + + var common = require('../common.js'); + var assert = require('assert'); +-var stream = require('stream'); ++var stream = require('../../'); + + var chunk = new Buffer('hallo'); + +diff --git a/test/simple/test-stream2-writable.js b/test/simple/test-stream2-writable.js +index 704100c..209c3a6 100644 +--- a/test/simple/test-stream2-writable.js ++++ b/test/simple/test-stream2-writable.js +@@ -20,8 +20,8 @@ + // USE OR OTHER DEALINGS IN THE SOFTWARE. + + var common = require('../common.js'); +-var W = require('_stream_writable'); +-var D = require('_stream_duplex'); ++var W = require('../../').Writable; ++var D = require('../../').Duplex; + var assert = require('assert'); + + var util = require('util'); +diff --git a/test/simple/test-stream3-pause-then-read.js b/test/simple/test-stream3-pause-then-read.js +index b91bde3..2f72c15 100644 +--- a/test/simple/test-stream3-pause-then-read.js ++++ b/test/simple/test-stream3-pause-then-read.js +@@ -22,7 +22,7 @@ + var common = require('../common'); + var assert = require('assert'); + +-var stream = require('stream'); ++var stream = require('../../'); + var Readable = stream.Readable; + var Writable = stream.Writable; + diff --git a/node_modules/npm-registry-client/node_modules/concat-stream/node_modules/readable-stream/lib/_stream_duplex.js b/node_modules/npm-registry-client/node_modules/concat-stream/node_modules/readable-stream/lib/_stream_duplex.js new file mode 100644 index 000000000..b513d61a9 --- /dev/null +++ b/node_modules/npm-registry-client/node_modules/concat-stream/node_modules/readable-stream/lib/_stream_duplex.js @@ -0,0 +1,89 @@ +// Copyright Joyent, Inc. and other Node contributors. +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to permit +// persons to whom the Software is furnished to do so, subject to the +// following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE +// USE OR OTHER DEALINGS IN THE SOFTWARE. + +// a duplex stream is just a stream that is both readable and writable. +// Since JS doesn't have multiple prototypal inheritance, this class +// prototypally inherits from Readable, and then parasitically from +// Writable. + +module.exports = Duplex; + +/*<replacement>*/ +var objectKeys = Object.keys || function (obj) { + var keys = []; + for (var key in obj) keys.push(key); + return keys; +} +/*</replacement>*/ + + +/*<replacement>*/ +var util = require('core-util-is'); +util.inherits = require('inherits'); +/*</replacement>*/ + +var Readable = require('./_stream_readable'); +var Writable = require('./_stream_writable'); + +util.inherits(Duplex, Readable); + +forEach(objectKeys(Writable.prototype), function(method) { + if (!Duplex.prototype[method]) + Duplex.prototype[method] = Writable.prototype[method]; +}); + +function Duplex(options) { + if (!(this instanceof Duplex)) + return new Duplex(options); + + Readable.call(this, options); + Writable.call(this, options); + + if (options && options.readable === false) + this.readable = false; + + if (options && options.writable === false) + this.writable = false; + + this.allowHalfOpen = true; + if (options && options.allowHalfOpen === false) + this.allowHalfOpen = false; + + this.once('end', onend); +} + +// the no-half-open enforcer +function onend() { + // if we allow half-open state, or if the writable side ended, + // then we're ok. + if (this.allowHalfOpen || this._writableState.ended) + return; + + // no more data can be written. + // But allow more writes to happen in this tick. + process.nextTick(this.end.bind(this)); +} + +function forEach (xs, f) { + for (var i = 0, l = xs.length; i < l; i++) { + f(xs[i], i); + } +} diff --git a/node_modules/npm-registry-client/node_modules/concat-stream/node_modules/readable-stream/lib/_stream_passthrough.js b/node_modules/npm-registry-client/node_modules/concat-stream/node_modules/readable-stream/lib/_stream_passthrough.js new file mode 100644 index 000000000..895ca50a1 --- /dev/null +++ b/node_modules/npm-registry-client/node_modules/concat-stream/node_modules/readable-stream/lib/_stream_passthrough.js @@ -0,0 +1,46 @@ +// Copyright Joyent, Inc. and other Node contributors. +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to permit +// persons to whom the Software is furnished to do so, subject to the +// following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE +// USE OR OTHER DEALINGS IN THE SOFTWARE. + +// a passthrough stream. +// basically just the most minimal sort of Transform stream. +// Every written chunk gets output as-is. + +module.exports = PassThrough; + +var Transform = require('./_stream_transform'); + +/*<replacement>*/ +var util = require('core-util-is'); +util.inherits = require('inherits'); +/*</replacement>*/ + +util.inherits(PassThrough, Transform); + +function PassThrough(options) { + if (!(this instanceof PassThrough)) + return new PassThrough(options); + + Transform.call(this, options); +} + +PassThrough.prototype._transform = function(chunk, encoding, cb) { + cb(null, chunk); +}; diff --git a/node_modules/npm-registry-client/node_modules/concat-stream/node_modules/readable-stream/lib/_stream_readable.js b/node_modules/npm-registry-client/node_modules/concat-stream/node_modules/readable-stream/lib/_stream_readable.js new file mode 100644 index 000000000..19ab35889 --- /dev/null +++ b/node_modules/npm-registry-client/node_modules/concat-stream/node_modules/readable-stream/lib/_stream_readable.js @@ -0,0 +1,951 @@ +// Copyright Joyent, Inc. and other Node contributors. +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to permit +// persons to whom the Software is furnished to do so, subject to the +// following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE +// USE OR OTHER DEALINGS IN THE SOFTWARE. + +module.exports = Readable; + +/*<replacement>*/ +var isArray = require('isarray'); +/*</replacement>*/ + + +/*<replacement>*/ +var Buffer = require('buffer').Buffer; +/*</replacement>*/ + +Readable.ReadableState = ReadableState; + +var EE = require('events').EventEmitter; + +/*<replacement>*/ +if (!EE.listenerCount) EE.listenerCount = function(emitter, type) { + return emitter.listeners(type).length; +}; +/*</replacement>*/ + +var Stream = require('stream'); + +/*<replacement>*/ +var util = require('core-util-is'); +util.inherits = require('inherits'); +/*</replacement>*/ + +var StringDecoder; + + +/*<replacement>*/ +var debug = require('util'); +if (debug && debug.debuglog) { + debug = debug.debuglog('stream'); +} else { + debug = function () {}; +} +/*</replacement>*/ + + +util.inherits(Readable, Stream); + +function ReadableState(options, stream) { + var Duplex = require('./_stream_duplex'); + + options = options || {}; + + // the point at which it stops calling _read() to fill the buffer + // Note: 0 is a valid value, means "don't call _read preemptively ever" + var hwm = options.highWaterMark; + var defaultHwm = options.objectMode ? 16 : 16 * 1024; + this.highWaterMark = (hwm || hwm === 0) ? hwm : defaultHwm; + + // cast to ints. + this.highWaterMark = ~~this.highWaterMark; + + this.buffer = []; + this.length = 0; + this.pipes = null; + this.pipesCount = 0; + this.flowing = null; + this.ended = false; + this.endEmitted = false; + this.reading = false; + + // a flag to be able to tell if the onwrite cb is called immediately, + // or on a later tick. We set this to true at first, because any + // actions that shouldn't happen until "later" should generally also + // not happen before the first write call. + this.sync = true; + + // whenever we return null, then we set a flag to say + // that we're awaiting a 'readable' event emission. + this.needReadable = false; + this.emittedReadable = false; + this.readableListening = false; + + + // object stream flag. Used to make read(n) ignore n and to + // make all the buffer merging and length checks go away + this.objectMode = !!options.objectMode; + + if (stream instanceof Duplex) + this.objectMode = this.objectMode || !!options.readableObjectMode; + + // Crypto is kind of old and crusty. Historically, its default string + // encoding is 'binary' so we have to make this configurable. + // Everything else in the universe uses 'utf8', though. + this.defaultEncoding = options.defaultEncoding || 'utf8'; + + // when piping, we only care about 'readable' events that happen + // after read()ing all the bytes and not getting any pushback. + this.ranOut = false; + + // the number of writers that are awaiting a drain event in .pipe()s + this.awaitDrain = 0; + + // if true, a maybeReadMore has been scheduled + this.readingMore = false; + + this.decoder = null; + this.encoding = null; + if (options.encoding) { + if (!StringDecoder) + StringDecoder = require('string_decoder/').StringDecoder; + this.decoder = new StringDecoder(options.encoding); + this.encoding = options.encoding; + } +} + +function Readable(options) { + var Duplex = require('./_stream_duplex'); + + if (!(this instanceof Readable)) + return new Readable(options); + + this._readableState = new ReadableState(options, this); + + // legacy + this.readable = true; + + Stream.call(this); +} + +// Manually shove something into the read() buffer. +// This returns true if the highWaterMark has not been hit yet, +// similar to how Writable.write() returns true if you should +// write() some more. +Readable.prototype.push = function(chunk, encoding) { + var state = this._readableState; + + if (util.isString(chunk) && !state.objectMode) { + encoding = encoding || state.defaultEncoding; + if (encoding !== state.encoding) { + chunk = new Buffer(chunk, encoding); + encoding = ''; + } + } + + return readableAddChunk(this, state, chunk, encoding, false); +}; + +// Unshift should *always* be something directly out of read() +Readable.prototype.unshift = function(chunk) { + var state = this._readableState; + return readableAddChunk(this, state, chunk, '', true); +}; + +function readableAddChunk(stream, state, chunk, encoding, addToFront) { + var er = chunkInvalid(state, chunk); + if (er) { + stream.emit('error', er); + } else if (util.isNullOrUndefined(chunk)) { + state.reading = false; + if (!state.ended) + onEofChunk(stream, state); + } else if (state.objectMode || chunk && chunk.length > 0) { + if (state.ended && !addToFront) { + var e = new Error('stream.push() after EOF'); + stream.emit('error', e); + } else if (state.endEmitted && addToFront) { + var e = new Error('stream.unshift() after end event'); + stream.emit('error', e); + } else { + if (state.decoder && !addToFront && !encoding) + chunk = state.decoder.write(chunk); + + if (!addToFront) + state.reading = false; + + // if we want the data now, just emit it. + if (state.flowing && state.length === 0 && !state.sync) { + stream.emit('data', chunk); + stream.read(0); + } else { + // update the buffer info. + state.length += state.objectMode ? 1 : chunk.length; + if (addToFront) + state.buffer.unshift(chunk); + else + state.buffer.push(chunk); + + if (state.needReadable) + emitReadable(stream); + } + + maybeReadMore(stream, state); + } + } else if (!addToFront) { + state.reading = false; + } + + return needMoreData(state); +} + + + +// if it's past the high water mark, we can push in some more. +// Also, if we have no data yet, we can stand some +// more bytes. This is to work around cases where hwm=0, +// such as the repl. Also, if the push() triggered a +// readable event, and the user called read(largeNumber) such that +// needReadable was set, then we ought to push more, so that another +// 'readable' event will be triggered. +function needMoreData(state) { + return !state.ended && + (state.needReadable || + state.length < state.highWaterMark || + state.length === 0); +} + +// backwards compatibility. +Readable.prototype.setEncoding = function(enc) { + if (!StringDecoder) + StringDecoder = require('string_decoder/').StringDecoder; + this._readableState.decoder = new StringDecoder(enc); + this._readableState.encoding = enc; + return this; +}; + +// Don't raise the hwm > 128MB +var MAX_HWM = 0x800000; +function roundUpToNextPowerOf2(n) { + if (n >= MAX_HWM) { + n = MAX_HWM; + } else { + // Get the next highest power of 2 + n--; + for (var p = 1; p < 32; p <<= 1) n |= n >> p; + n++; + } + return n; +} + +function howMuchToRead(n, state) { + if (state.length === 0 && state.ended) + return 0; + + if (state.objectMode) + return n === 0 ? 0 : 1; + + if (isNaN(n) || util.isNull(n)) { + // only flow one buffer at a time + if (state.flowing && state.buffer.length) + return state.buffer[0].length; + else + return state.length; + } + + if (n <= 0) + return 0; + + // If we're asking for more than the target buffer level, + // then raise the water mark. Bump up to the next highest + // power of 2, to prevent increasing it excessively in tiny + // amounts. + if (n > state.highWaterMark) + state.highWaterMark = roundUpToNextPowerOf2(n); + + // don't have that much. return null, unless we've ended. + if (n > state.length) { + if (!state.ended) { + state.needReadable = true; + return 0; + } else + return state.length; + } + + return n; +} + +// you can override either this method, or the async _read(n) below. +Readable.prototype.read = function(n) { + debug('read', n); + var state = this._readableState; + var nOrig = n; + + if (!util.isNumber(n) || n > 0) + state.emittedReadable = false; + + // if we're doing read(0) to trigger a readable event, but we + // already have a bunch of data in the buffer, then just trigger + // the 'readable' event and move on. + if (n === 0 && + state.needReadable && + (state.length >= state.highWaterMark || state.ended)) { + debug('read: emitReadable', state.length, state.ended); + if (state.length === 0 && state.ended) + endReadable(this); + else + emitReadable(this); + return null; + } + + n = howMuchToRead(n, state); + + // if we've ended, and we're now clear, then finish it up. + if (n === 0 && state.ended) { + if (state.length === 0) + endReadable(this); + return null; + } + + // All the actual chunk generation logic needs to be + // *below* the call to _read. The reason is that in certain + // synthetic stream cases, such as passthrough streams, _read + // may be a completely synchronous operation which may change + // the state of the read buffer, providing enough data when + // before there was *not* enough. + // + // So, the steps are: + // 1. Figure out what the state of things will be after we do + // a read from the buffer. + // + // 2. If that resulting state will trigger a _read, then call _read. + // Note that this may be asynchronous, or synchronous. Yes, it is + // deeply ugly to write APIs this way, but that still doesn't mean + // that the Readable class should behave improperly, as streams are + // designed to be sync/async agnostic. + // Take note if the _read call is sync or async (ie, if the read call + // has returned yet), so that we know whether or not it's safe to emit + // 'readable' etc. + // + // 3. Actually pull the requested chunks out of the buffer and return. + + // if we need a readable event, then we need to do some reading. + var doRead = state.needReadable; + debug('need readable', doRead); + + // if we currently have less than the highWaterMark, then also read some + if (state.length === 0 || state.length - n < state.highWaterMark) { + doRead = true; + debug('length less than watermark', doRead); + } + + // however, if we've ended, then there's no point, and if we're already + // reading, then it's unnecessary. + if (state.ended || state.reading) { + doRead = false; + debug('reading or ended', doRead); + } + + if (doRead) { + debug('do read'); + state.reading = true; + state.sync = true; + // if the length is currently zero, then we *need* a readable event. + if (state.length === 0) + state.needReadable = true; + // call internal read method + this._read(state.highWaterMark); + state.sync = false; + } + + // If _read pushed data synchronously, then `reading` will be false, + // and we need to re-evaluate how much data we can return to the user. + if (doRead && !state.reading) + n = howMuchToRead(nOrig, state); + + var ret; + if (n > 0) + ret = fromList(n, state); + else + ret = null; + + if (util.isNull(ret)) { + state.needReadable = true; + n = 0; + } + + state.length -= n; + + // If we have nothing in the buffer, then we want to know + // as soon as we *do* get something into the buffer. + if (state.length === 0 && !state.ended) + state.needReadable = true; + + // If we tried to read() past the EOF, then emit end on the next tick. + if (nOrig !== n && state.ended && state.length === 0) + endReadable(this); + + if (!util.isNull(ret)) + this.emit('data', ret); + + return ret; +}; + +function chunkInvalid(state, chunk) { + var er = null; + if (!util.isBuffer(chunk) && + !util.isString(chunk) && + !util.isNullOrUndefined(chunk) && + !state.objectMode) { + er = new TypeError('Invalid non-string/buffer chunk'); + } + return er; +} + + +function onEofChunk(stream, state) { + if (state.decoder && !state.ended) { + var chunk = state.decoder.end(); + if (chunk && chunk.length) { + state.buffer.push(chunk); + state.length += state.objectMode ? 1 : chunk.length; + } + } + state.ended = true; + + // emit 'readable' now to make sure it gets picked up. + emitReadable(stream); +} + +// Don't emit readable right away in sync mode, because this can trigger +// another read() call => stack overflow. This way, it might trigger +// a nextTick recursion warning, but that's not so bad. +function emitReadable(stream) { + var state = stream._readableState; + state.needReadable = false; + if (!state.emittedReadable) { + debug('emitReadable', state.flowing); + state.emittedReadable = true; + if (state.sync) + process.nextTick(function() { + emitReadable_(stream); + }); + else + emitReadable_(stream); + } +} + +function emitReadable_(stream) { + debug('emit readable'); + stream.emit('readable'); + flow(stream); +} + + +// at this point, the user has presumably seen the 'readable' event, +// and called read() to consume some data. that may have triggered +// in turn another _read(n) call, in which case reading = true if +// it's in progress. +// However, if we're not ended, or reading, and the length < hwm, +// then go ahead and try to read some more preemptively. +function maybeReadMore(stream, state) { + if (!state.readingMore) { + state.readingMore = true; + process.nextTick(function() { + maybeReadMore_(stream, state); + }); + } +} + +function maybeReadMore_(stream, state) { + var len = state.length; + while (!state.reading && !state.flowing && !state.ended && + state.length < state.highWaterMark) { + debug('maybeReadMore read 0'); + stream.read(0); + if (len === state.length) + // didn't get any data, stop spinning. + break; + else + len = state.length; + } + state.readingMore = false; +} + +// abstract method. to be overridden in specific implementation classes. +// call cb(er, data) where data is <= n in length. +// for virtual (non-string, non-buffer) streams, "length" is somewhat +// arbitrary, and perhaps not very meaningful. +Readable.prototype._read = function(n) { + this.emit('error', new Error('not implemented')); +}; + +Readable.prototype.pipe = function(dest, pipeOpts) { + var src = this; + var state = this._readableState; + + switch (state.pipesCount) { + case 0: + state.pipes = dest; + break; + case 1: + state.pipes = [state.pipes, dest]; + break; + default: + state.pipes.push(dest); + break; + } + state.pipesCount += 1; + debug('pipe count=%d opts=%j', state.pipesCount, pipeOpts); + + var doEnd = (!pipeOpts || pipeOpts.end !== false) && + dest !== process.stdout && + dest !== process.stderr; + + var endFn = doEnd ? onend : cleanup; + if (state.endEmitted) + process.nextTick(endFn); + else + src.once('end', endFn); + + dest.on('unpipe', onunpipe); + function onunpipe(readable) { + debug('onunpipe'); + if (readable === src) { + cleanup(); + } + } + + function onend() { + debug('onend'); + dest.end(); + } + + // when the dest drains, it reduces the awaitDrain counter + // on the source. This would be more elegant with a .once() + // handler in flow(), but adding and removing repeatedly is + // too slow. + var ondrain = pipeOnDrain(src); + dest.on('drain', ondrain); + + function cleanup() { + debug('cleanup'); + // cleanup event handlers once the pipe is broken + dest.removeListener('close', onclose); + dest.removeListener('finish', onfinish); + dest.removeListener('drain', ondrain); + dest.removeListener('error', onerror); + dest.removeListener('unpipe', onunpipe); + src.removeListener('end', onend); + src.removeListener('end', cleanup); + src.removeListener('data', ondata); + + // if the reader is waiting for a drain event from this + // specific writer, then it would cause it to never start + // flowing again. + // So, if this is awaiting a drain, then we just call it now. + // If we don't know, then assume that we are waiting for one. + if (state.awaitDrain && + (!dest._writableState || dest._writableState.needDrain)) + ondrain(); + } + + src.on('data', ondata); + function ondata(chunk) { + debug('ondata'); + var ret = dest.write(chunk); + if (false === ret) { + debug('false write response, pause', + src._readableState.awaitDrain); + src._readableState.awaitDrain++; + src.pause(); + } + } + + // if the dest has an error, then stop piping into it. + // however, don't suppress the throwing behavior for this. + function onerror(er) { + debug('onerror', er); + unpipe(); + dest.removeListener('error', onerror); + if (EE.listenerCount(dest, 'error') === 0) + dest.emit('error', er); + } + // This is a brutally ugly hack to make sure that our error handler + // is attached before any userland ones. NEVER DO THIS. + if (!dest._events || !dest._events.error) + dest.on('error', onerror); + else if (isArray(dest._events.error)) + dest._events.error.unshift(onerror); + else + dest._events.error = [onerror, dest._events.error]; + + + + // Both close and finish should trigger unpipe, but only once. + function onclose() { + dest.removeListener('finish', onfinish); + unpipe(); + } + dest.once('close', onclose); + function onfinish() { + debug('onfinish'); + dest.removeListener('close', onclose); + unpipe(); + } + dest.once('finish', onfinish); + + function unpipe() { + debug('unpipe'); + src.unpipe(dest); + } + + // tell the dest that it's being piped to + dest.emit('pipe', src); + + // start the flow if it hasn't been started already. + if (!state.flowing) { + debug('pipe resume'); + src.resume(); + } + + return dest; +}; + +function pipeOnDrain(src) { + return function() { + var state = src._readableState; + debug('pipeOnDrain', state.awaitDrain); + if (state.awaitDrain) + state.awaitDrain--; + if (state.awaitDrain === 0 && EE.listenerCount(src, 'data')) { + state.flowing = true; + flow(src); + } + }; +} + + +Readable.prototype.unpipe = function(dest) { + var state = this._readableState; + + // if we're not piping anywhere, then do nothing. + if (state.pipesCount === 0) + return this; + + // just one destination. most common case. + if (state.pipesCount === 1) { + // passed in one, but it's not the right one. + if (dest && dest !== state.pipes) + return this; + + if (!dest) + dest = state.pipes; + + // got a match. + state.pipes = null; + state.pipesCount = 0; + state.flowing = false; + if (dest) + dest.emit('unpipe', this); + return this; + } + + // slow case. multiple pipe destinations. + + if (!dest) { + // remove all. + var dests = state.pipes; + var len = state.pipesCount; + state.pipes = null; + state.pipesCount = 0; + state.flowing = false; + + for (var i = 0; i < len; i++) + dests[i].emit('unpipe', this); + return this; + } + + // try to find the right one. + var i = indexOf(state.pipes, dest); + if (i === -1) + return this; + + state.pipes.splice(i, 1); + state.pipesCount -= 1; + if (state.pipesCount === 1) + state.pipes = state.pipes[0]; + + dest.emit('unpipe', this); + + return this; +}; + +// set up data events if they are asked for +// Ensure readable listeners eventually get something +Readable.prototype.on = function(ev, fn) { + var res = Stream.prototype.on.call(this, ev, fn); + + // If listening to data, and it has not explicitly been paused, + // then call resume to start the flow of data on the next tick. + if (ev === 'data' && false !== this._readableState.flowing) { + this.resume(); + } + + if (ev === 'readable' && this.readable) { + var state = this._readableState; + if (!state.readableListening) { + state.readableListening = true; + state.emittedReadable = false; + state.needReadable = true; + if (!state.reading) { + var self = this; + process.nextTick(function() { + debug('readable nexttick read 0'); + self.read(0); + }); + } else if (state.length) { + emitReadable(this, state); + } + } + } + + return res; +}; +Readable.prototype.addListener = Readable.prototype.on; + +// pause() and resume() are remnants of the legacy readable stream API +// If the user uses them, then switch into old mode. +Readable.prototype.resume = function() { + var state = this._readableState; + if (!state.flowing) { + debug('resume'); + state.flowing = true; + if (!state.reading) { + debug('resume read 0'); + this.read(0); + } + resume(this, state); + } + return this; +}; + +function resume(stream, state) { + if (!state.resumeScheduled) { + state.resumeScheduled = true; + process.nextTick(function() { + resume_(stream, state); + }); + } +} + +function resume_(stream, state) { + state.resumeScheduled = false; + stream.emit('resume'); + flow(stream); + if (state.flowing && !state.reading) + stream.read(0); +} + +Readable.prototype.pause = function() { + debug('call pause flowing=%j', this._readableState.flowing); + if (false !== this._readableState.flowing) { + debug('pause'); + this._readableState.flowing = false; + this.emit('pause'); + } + return this; +}; + +function flow(stream) { + var state = stream._readableState; + debug('flow', state.flowing); + if (state.flowing) { + do { + var chunk = stream.read(); + } while (null !== chunk && state.flowing); + } +} + +// wrap an old-style stream as the async data source. +// This is *not* part of the readable stream interface. +// It is an ugly unfortunate mess of history. +Readable.prototype.wrap = function(stream) { + var state = this._readableState; + var paused = false; + + var self = this; + stream.on('end', function() { + debug('wrapped end'); + if (state.decoder && !state.ended) { + var chunk = state.decoder.end(); + if (chunk && chunk.length) + self.push(chunk); + } + + self.push(null); + }); + + stream.on('data', function(chunk) { + debug('wrapped data'); + if (state.decoder) + chunk = state.decoder.write(chunk); + if (!chunk || !state.objectMode && !chunk.length) + return; + + var ret = self.push(chunk); + if (!ret) { + paused = true; + stream.pause(); + } + }); + + // proxy all the other methods. + // important when wrapping filters and duplexes. + for (var i in stream) { + if (util.isFunction(stream[i]) && util.isUndefined(this[i])) { + this[i] = function(method) { return function() { + return stream[method].apply(stream, arguments); + }}(i); + } + } + + // proxy certain important events. + var events = ['error', 'close', 'destroy', 'pause', 'resume']; + forEach(events, function(ev) { + stream.on(ev, self.emit.bind(self, ev)); + }); + + // when we try to consume some more bytes, simply unpause the + // underlying stream. + self._read = function(n) { + debug('wrapped _read', n); + if (paused) { + paused = false; + stream.resume(); + } + }; + + return self; +}; + + + +// exposed for testing purposes only. +Readable._fromList = fromList; + +// Pluck off n bytes from an array of buffers. +// Length is the combined lengths of all the buffers in the list. +function fromList(n, state) { + var list = state.buffer; + var length = state.length; + var stringMode = !!state.decoder; + var objectMode = !!state.objectMode; + var ret; + + // nothing in the list, definitely empty. + if (list.length === 0) + return null; + + if (length === 0) + ret = null; + else if (objectMode) + ret = list.shift(); + else if (!n || n >= length) { + // read it all, truncate the array. + if (stringMode) + ret = list.join(''); + else + ret = Buffer.concat(list, length); + list.length = 0; + } else { + // read just some of it. + if (n < list[0].length) { + // just take a part of the first list item. + // slice is the same for buffers and strings. + var buf = list[0]; + ret = buf.slice(0, n); + list[0] = buf.slice(n); + } else if (n === list[0].length) { + // first list is a perfect match + ret = list.shift(); + } else { + // complex case. + // we have enough to cover it, but it spans past the first buffer. + if (stringMode) + ret = ''; + else + ret = new Buffer(n); + + var c = 0; + for (var i = 0, l = list.length; i < l && c < n; i++) { + var buf = list[0]; + var cpy = Math.min(n - c, buf.length); + + if (stringMode) + ret += buf.slice(0, cpy); + else + buf.copy(ret, c, 0, cpy); + + if (cpy < buf.length) + list[0] = buf.slice(cpy); + else + list.shift(); + + c += cpy; + } + } + } + + return ret; +} + +function endReadable(stream) { + var state = stream._readableState; + + // If we get here before consuming all the bytes, then that is a + // bug in node. Should never happen. + if (state.length > 0) + throw new Error('endReadable called on non-empty stream'); + + if (!state.endEmitted) { + state.ended = true; + process.nextTick(function() { + // Check that we didn't get one last unshift. + if (!state.endEmitted && state.length === 0) { + state.endEmitted = true; + stream.readable = false; + stream.emit('end'); + } + }); + } +} + +function forEach (xs, f) { + for (var i = 0, l = xs.length; i < l; i++) { + f(xs[i], i); + } +} + +function indexOf (xs, x) { + for (var i = 0, l = xs.length; i < l; i++) { + if (xs[i] === x) return i; + } + return -1; +} diff --git a/node_modules/npm-registry-client/node_modules/concat-stream/node_modules/readable-stream/lib/_stream_transform.js b/node_modules/npm-registry-client/node_modules/concat-stream/node_modules/readable-stream/lib/_stream_transform.js new file mode 100644 index 000000000..905c5e450 --- /dev/null +++ b/node_modules/npm-registry-client/node_modules/concat-stream/node_modules/readable-stream/lib/_stream_transform.js @@ -0,0 +1,209 @@ +// Copyright Joyent, Inc. and other Node contributors. +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to permit +// persons to whom the Software is furnished to do so, subject to the +// following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE +// USE OR OTHER DEALINGS IN THE SOFTWARE. + + +// a transform stream is a readable/writable stream where you do +// something with the data. Sometimes it's called a "filter", +// but that's not a great name for it, since that implies a thing where +// some bits pass through, and others are simply ignored. (That would +// be a valid example of a transform, of course.) +// +// While the output is causally related to the input, it's not a +// necessarily symmetric or synchronous transformation. For example, +// a zlib stream might take multiple plain-text writes(), and then +// emit a single compressed chunk some time in the future. +// +// Here's how this works: +// +// The Transform stream has all the aspects of the readable and writable +// stream classes. When you write(chunk), that calls _write(chunk,cb) +// internally, and returns false if there's a lot of pending writes +// buffered up. When you call read(), that calls _read(n) until +// there's enough pending readable data buffered up. +// +// In a transform stream, the written data is placed in a buffer. When +// _read(n) is called, it transforms the queued up data, calling the +// buffered _write cb's as it consumes chunks. If consuming a single +// written chunk would result in multiple output chunks, then the first +// outputted bit calls the readcb, and subsequent chunks just go into +// the read buffer, and will cause it to emit 'readable' if necessary. +// +// This way, back-pressure is actually determined by the reading side, +// since _read has to be called to start processing a new chunk. However, +// a pathological inflate type of transform can cause excessive buffering +// here. For example, imagine a stream where every byte of input is +// interpreted as an integer from 0-255, and then results in that many +// bytes of output. Writing the 4 bytes {ff,ff,ff,ff} would result in +// 1kb of data being output. In this case, you could write a very small +// amount of input, and end up with a very large amount of output. In +// such a pathological inflating mechanism, there'd be no way to tell +// the system to stop doing the transform. A single 4MB write could +// cause the system to run out of memory. +// +// However, even in such a pathological case, only a single written chunk +// would be consumed, and then the rest would wait (un-transformed) until +// the results of the previous transformed chunk were consumed. + +module.exports = Transform; + +var Duplex = require('./_stream_duplex'); + +/*<replacement>*/ +var util = require('core-util-is'); +util.inherits = require('inherits'); +/*</replacement>*/ + +util.inherits(Transform, Duplex); + + +function TransformState(options, stream) { + this.afterTransform = function(er, data) { + return afterTransform(stream, er, data); + }; + + this.needTransform = false; + this.transforming = false; + this.writecb = null; + this.writechunk = null; +} + +function afterTransform(stream, er, data) { + var ts = stream._transformState; + ts.transforming = false; + + var cb = ts.writecb; + + if (!cb) + return stream.emit('error', new Error('no writecb in Transform class')); + + ts.writechunk = null; + ts.writecb = null; + + if (!util.isNullOrUndefined(data)) + stream.push(data); + + if (cb) + cb(er); + + var rs = stream._readableState; + rs.reading = false; + if (rs.needReadable || rs.length < rs.highWaterMark) { + stream._read(rs.highWaterMark); + } +} + + +function Transform(options) { + if (!(this instanceof Transform)) + return new Transform(options); + + Duplex.call(this, options); + + this._transformState = new TransformState(options, this); + + // when the writable side finishes, then flush out anything remaining. + var stream = this; + + // start out asking for a readable event once data is transformed. + this._readableState.needReadable = true; + + // we have implemented the _read method, and done the other things + // that Readable wants before the first _read call, so unset the + // sync guard flag. + this._readableState.sync = false; + + this.once('prefinish', function() { + if (util.isFunction(this._flush)) + this._flush(function(er) { + done(stream, er); + }); + else + done(stream); + }); +} + +Transform.prototype.push = function(chunk, encoding) { + this._transformState.needTransform = false; + return Duplex.prototype.push.call(this, chunk, encoding); +}; + +// This is the part where you do stuff! +// override this function in implementation classes. +// 'chunk' is an input chunk. +// +// Call `push(newChunk)` to pass along transformed output +// to the readable side. You may call 'push' zero or more times. +// +// Call `cb(err)` when you are done with this chunk. If you pass +// an error, then that'll put the hurt on the whole operation. If you +// never call cb(), then you'll never get another chunk. +Transform.prototype._transform = function(chunk, encoding, cb) { + throw new Error('not implemented'); +}; + +Transform.prototype._write = function(chunk, encoding, cb) { + var ts = this._transformState; + ts.writecb = cb; + ts.writechunk = chunk; + ts.writeencoding = encoding; + if (!ts.transforming) { + var rs = this._readableState; + if (ts.needTransform || + rs.needReadable || + rs.length < rs.highWaterMark) + this._read(rs.highWaterMark); + } +}; + +// Doesn't matter what the args are here. +// _transform does all the work. +// That we got here means that the readable side wants more data. +Transform.prototype._read = function(n) { + var ts = this._transformState; + + if (!util.isNull(ts.writechunk) && ts.writecb && !ts.transforming) { + ts.transforming = true; + this._transform(ts.writechunk, ts.writeencoding, ts.afterTransform); + } else { + // mark that we need a transform, so that any data that comes in + // will get processed, now that we've asked for it. + ts.needTransform = true; + } +}; + + +function done(stream, er) { + if (er) + return stream.emit('error', er); + + // if there's nothing in the write buffer, then that means + // that nothing more will ever be provided + var ws = stream._writableState; + var ts = stream._transformState; + + if (ws.length) + throw new Error('calling transform done when ws.length != 0'); + + if (ts.transforming) + throw new Error('calling transform done when still transforming'); + + return stream.push(null); +} diff --git a/node_modules/npm-registry-client/node_modules/concat-stream/node_modules/readable-stream/lib/_stream_writable.js b/node_modules/npm-registry-client/node_modules/concat-stream/node_modules/readable-stream/lib/_stream_writable.js new file mode 100644 index 000000000..db8539cd5 --- /dev/null +++ b/node_modules/npm-registry-client/node_modules/concat-stream/node_modules/readable-stream/lib/_stream_writable.js @@ -0,0 +1,477 @@ +// Copyright Joyent, Inc. and other Node contributors. +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to permit +// persons to whom the Software is furnished to do so, subject to the +// following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE +// USE OR OTHER DEALINGS IN THE SOFTWARE. + +// A bit simpler than readable streams. +// Implement an async ._write(chunk, cb), and it'll handle all +// the drain event emission and buffering. + +module.exports = Writable; + +/*<replacement>*/ +var Buffer = require('buffer').Buffer; +/*</replacement>*/ + +Writable.WritableState = WritableState; + + +/*<replacement>*/ +var util = require('core-util-is'); +util.inherits = require('inherits'); +/*</replacement>*/ + +var Stream = require('stream'); + +util.inherits(Writable, Stream); + +function WriteReq(chunk, encoding, cb) { + this.chunk = chunk; + this.encoding = encoding; + this.callback = cb; +} + +function WritableState(options, stream) { + var Duplex = require('./_stream_duplex'); + + options = options || {}; + + // the point at which write() starts returning false + // Note: 0 is a valid value, means that we always return false if + // the entire buffer is not flushed immediately on write() + var hwm = options.highWaterMark; + var defaultHwm = options.objectMode ? 16 : 16 * 1024; + this.highWaterMark = (hwm || hwm === 0) ? hwm : defaultHwm; + + // object stream flag to indicate whether or not this stream + // contains buffers or objects. + this.objectMode = !!options.objectMode; + + if (stream instanceof Duplex) + this.objectMode = this.objectMode || !!options.writableObjectMode; + + // cast to ints. + this.highWaterMark = ~~this.highWaterMark; + + this.needDrain = false; + // at the start of calling end() + this.ending = false; + // when end() has been called, and returned + this.ended = false; + // when 'finish' is emitted + this.finished = false; + + // should we decode strings into buffers before passing to _write? + // this is here so that some node-core streams can optimize string + // handling at a lower level. + var noDecode = options.decodeStrings === false; + this.decodeStrings = !noDecode; + + // Crypto is kind of old and crusty. Historically, its default string + // encoding is 'binary' so we have to make this configurable. + // Everything else in the universe uses 'utf8', though. + this.defaultEncoding = options.defaultEncoding || 'utf8'; + + // not an actual buffer we keep track of, but a measurement + // of how much we're waiting to get pushed to some underlying + // socket or file. + this.length = 0; + + // a flag to see when we're in the middle of a write. + this.writing = false; + + // when true all writes will be buffered until .uncork() call + this.corked = 0; + + // a flag to be able to tell if the onwrite cb is called immediately, + // or on a later tick. We set this to true at first, because any + // actions that shouldn't happen until "later" should generally also + // not happen before the first write call. + this.sync = true; + + // a flag to know if we're processing previously buffered items, which + // may call the _write() callback in the same tick, so that we don't + // end up in an overlapped onwrite situation. + this.bufferProcessing = false; + + // the callback that's passed to _write(chunk,cb) + this.onwrite = function(er) { + onwrite(stream, er); + }; + + // the callback that the user supplies to write(chunk,encoding,cb) + this.writecb = null; + + // the amount that is being written when _write is called. + this.writelen = 0; + + this.buffer = []; + + // number of pending user-supplied write callbacks + // this must be 0 before 'finish' can be emitted + this.pendingcb = 0; + + // emit prefinish if the only thing we're waiting for is _write cbs + // This is relevant for synchronous Transform streams + this.prefinished = false; + + // True if the error was already emitted and should not be thrown again + this.errorEmitted = false; +} + +function Writable(options) { + var Duplex = require('./_stream_duplex'); + + // Writable ctor is applied to Duplexes, though they're not + // instanceof Writable, they're instanceof Readable. + if (!(this instanceof Writable) && !(this instanceof Duplex)) + return new Writable(options); + + this._writableState = new WritableState(options, this); + + // legacy. + this.writable = true; + + Stream.call(this); +} + +// Otherwise people can pipe Writable streams, which is just wrong. +Writable.prototype.pipe = function() { + this.emit('error', new Error('Cannot pipe. Not readable.')); +}; + + +function writeAfterEnd(stream, state, cb) { + var er = new Error('write after end'); + // TODO: defer error events consistently everywhere, not just the cb + stream.emit('error', er); + process.nextTick(function() { + cb(er); + }); +} + +// If we get something that is not a buffer, string, null, or undefined, +// and we're not in objectMode, then that's an error. +// Otherwise stream chunks are all considered to be of length=1, and the +// watermarks determine how many objects to keep in the buffer, rather than +// how many bytes or characters. +function validChunk(stream, state, chunk, cb) { + var valid = true; + if (!util.isBuffer(chunk) && + !util.isString(chunk) && + !util.isNullOrUndefined(chunk) && + !state.objectMode) { + var er = new TypeError('Invalid non-string/buffer chunk'); + stream.emit('error', er); + process.nextTick(function() { + cb(er); + }); + valid = false; + } + return valid; +} + +Writable.prototype.write = function(chunk, encoding, cb) { + var state = this._writableState; + var ret = false; + + if (util.isFunction(encoding)) { + cb = encoding; + encoding = null; + } + + if (util.isBuffer(chunk)) + encoding = 'buffer'; + else if (!encoding) + encoding = state.defaultEncoding; + + if (!util.isFunction(cb)) + cb = function() {}; + + if (state.ended) + writeAfterEnd(this, state, cb); + else if (validChunk(this, state, chunk, cb)) { + state.pendingcb++; + ret = writeOrBuffer(this, state, chunk, encoding, cb); + } + + return ret; +}; + +Writable.prototype.cork = function() { + var state = this._writableState; + + state.corked++; +}; + +Writable.prototype.uncork = function() { + var state = this._writableState; + + if (state.corked) { + state.corked--; + + if (!state.writing && + !state.corked && + !state.finished && + !state.bufferProcessing && + state.buffer.length) + clearBuffer(this, state); + } +}; + +function decodeChunk(state, chunk, encoding) { + if (!state.objectMode && + state.decodeStrings !== false && + util.isString(chunk)) { + chunk = new Buffer(chunk, encoding); + } + return chunk; +} + +// if we're already writing something, then just put this +// in the queue, and wait our turn. Otherwise, call _write +// If we return false, then we need a drain event, so set that flag. +function writeOrBuffer(stream, state, chunk, encoding, cb) { + chunk = decodeChunk(state, chunk, encoding); + if (util.isBuffer(chunk)) + encoding = 'buffer'; + var len = state.objectMode ? 1 : chunk.length; + + state.length += len; + + var ret = state.length < state.highWaterMark; + // we must ensure that previous needDrain will not be reset to false. + if (!ret) + state.needDrain = true; + + if (state.writing || state.corked) + state.buffer.push(new WriteReq(chunk, encoding, cb)); + else + doWrite(stream, state, false, len, chunk, encoding, cb); + + return ret; +} + +function doWrite(stream, state, writev, len, chunk, encoding, cb) { + state.writelen = len; + state.writecb = cb; + state.writing = true; + state.sync = true; + if (writev) + stream._writev(chunk, state.onwrite); + else + stream._write(chunk, encoding, state.onwrite); + state.sync = false; +} + +function onwriteError(stream, state, sync, er, cb) { + if (sync) + process.nextTick(function() { + state.pendingcb--; + cb(er); + }); + else { + state.pendingcb--; + cb(er); + } + + stream._writableState.errorEmitted = true; + stream.emit('error', er); +} + +function onwriteStateUpdate(state) { + state.writing = false; + state.writecb = null; + state.length -= state.writelen; + state.writelen = 0; +} + +function onwrite(stream, er) { + var state = stream._writableState; + var sync = state.sync; + var cb = state.writecb; + + onwriteStateUpdate(state); + + if (er) + onwriteError(stream, state, sync, er, cb); + else { + // Check if we're actually ready to finish, but don't emit yet + var finished = needFinish(stream, state); + + if (!finished && + !state.corked && + !state.bufferProcessing && + state.buffer.length) { + clearBuffer(stream, state); + } + + if (sync) { + process.nextTick(function() { + afterWrite(stream, state, finished, cb); + }); + } else { + afterWrite(stream, state, finished, cb); + } + } +} + +function afterWrite(stream, state, finished, cb) { + if (!finished) + onwriteDrain(stream, state); + state.pendingcb--; + cb(); + finishMaybe(stream, state); +} + +// Must force callback to be called on nextTick, so that we don't +// emit 'drain' before the write() consumer gets the 'false' return +// value, and has a chance to attach a 'drain' listener. +function onwriteDrain(stream, state) { + if (state.length === 0 && state.needDrain) { + state.needDrain = false; + stream.emit('drain'); + } +} + + +// if there's something in the buffer waiting, then process it +function clearBuffer(stream, state) { + state.bufferProcessing = true; + + if (stream._writev && state.buffer.length > 1) { + // Fast case, write everything using _writev() + var cbs = []; + for (var c = 0; c < state.buffer.length; c++) + cbs.push(state.buffer[c].callback); + + // count the one we are adding, as well. + // TODO(isaacs) clean this up + state.pendingcb++; + doWrite(stream, state, true, state.length, state.buffer, '', function(err) { + for (var i = 0; i < cbs.length; i++) { + state.pendingcb--; + cbs[i](err); + } + }); + + // Clear buffer + state.buffer = []; + } else { + // Slow case, write chunks one-by-one + for (var c = 0; c < state.buffer.length; c++) { + var entry = state.buffer[c]; + var chunk = entry.chunk; + var encoding = entry.encoding; + var cb = entry.callback; + var len = state.objectMode ? 1 : chunk.length; + + doWrite(stream, state, false, len, chunk, encoding, cb); + + // if we didn't call the onwrite immediately, then + // it means that we need to wait until it does. + // also, that means that the chunk and cb are currently + // being processed, so move the buffer counter past them. + if (state.writing) { + c++; + break; + } + } + + if (c < state.buffer.length) + state.buffer = state.buffer.slice(c); + else + state.buffer.length = 0; + } + + state.bufferProcessing = false; +} + +Writable.prototype._write = function(chunk, encoding, cb) { + cb(new Error('not implemented')); + +}; + +Writable.prototype._writev = null; + +Writable.prototype.end = function(chunk, encoding, cb) { + var state = this._writableState; + + if (util.isFunction(chunk)) { + cb = chunk; + chunk = null; + encoding = null; + } else if (util.isFunction(encoding)) { + cb = encoding; + encoding = null; + } + + if (!util.isNullOrUndefined(chunk)) + this.write(chunk, encoding); + + // .end() fully uncorks + if (state.corked) { + state.corked = 1; + this.uncork(); + } + + // ignore unnecessary end() calls. + if (!state.ending && !state.finished) + endWritable(this, state, cb); +}; + + +function needFinish(stream, state) { + return (state.ending && + state.length === 0 && + !state.finished && + !state.writing); +} + +function prefinish(stream, state) { + if (!state.prefinished) { + state.prefinished = true; + stream.emit('prefinish'); + } +} + +function finishMaybe(stream, state) { + var need = needFinish(stream, state); + if (need) { + if (state.pendingcb === 0) { + prefinish(stream, state); + state.finished = true; + stream.emit('finish'); + } else + prefinish(stream, state); + } + return need; +} + +function endWritable(stream, state, cb) { + state.ending = true; + finishMaybe(stream, state); + if (cb) { + if (state.finished) + process.nextTick(cb); + else + stream.once('finish', cb); + } + state.ended = true; +} diff --git a/node_modules/npm-registry-client/node_modules/concat-stream/node_modules/readable-stream/node_modules/core-util-is/README.md b/node_modules/npm-registry-client/node_modules/concat-stream/node_modules/readable-stream/node_modules/core-util-is/README.md new file mode 100644 index 000000000..5a76b4149 --- /dev/null +++ b/node_modules/npm-registry-client/node_modules/concat-stream/node_modules/readable-stream/node_modules/core-util-is/README.md @@ -0,0 +1,3 @@ +# core-util-is + +The `util.is*` functions introduced in Node v0.12. diff --git a/node_modules/npm-registry-client/node_modules/concat-stream/node_modules/readable-stream/node_modules/core-util-is/float.patch b/node_modules/npm-registry-client/node_modules/concat-stream/node_modules/readable-stream/node_modules/core-util-is/float.patch new file mode 100644 index 000000000..a06d5c05f --- /dev/null +++ b/node_modules/npm-registry-client/node_modules/concat-stream/node_modules/readable-stream/node_modules/core-util-is/float.patch @@ -0,0 +1,604 @@ +diff --git a/lib/util.js b/lib/util.js +index a03e874..9074e8e 100644 +--- a/lib/util.js ++++ b/lib/util.js +@@ -19,430 +19,6 @@ + // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + // USE OR OTHER DEALINGS IN THE SOFTWARE. + +-var formatRegExp = /%[sdj%]/g; +-exports.format = function(f) { +- if (!isString(f)) { +- var objects = []; +- for (var i = 0; i < arguments.length; i++) { +- objects.push(inspect(arguments[i])); +- } +- return objects.join(' '); +- } +- +- var i = 1; +- var args = arguments; +- var len = args.length; +- var str = String(f).replace(formatRegExp, function(x) { +- if (x === '%%') return '%'; +- if (i >= len) return x; +- switch (x) { +- case '%s': return String(args[i++]); +- case '%d': return Number(args[i++]); +- case '%j': +- try { +- return JSON.stringify(args[i++]); +- } catch (_) { +- return '[Circular]'; +- } +- default: +- return x; +- } +- }); +- for (var x = args[i]; i < len; x = args[++i]) { +- if (isNull(x) || !isObject(x)) { +- str += ' ' + x; +- } else { +- str += ' ' + inspect(x); +- } +- } +- return str; +-}; +- +- +-// Mark that a method should not be used. +-// Returns a modified function which warns once by default. +-// If --no-deprecation is set, then it is a no-op. +-exports.deprecate = function(fn, msg) { +- // Allow for deprecating things in the process of starting up. +- if (isUndefined(global.process)) { +- return function() { +- return exports.deprecate(fn, msg).apply(this, arguments); +- }; +- } +- +- if (process.noDeprecation === true) { +- return fn; +- } +- +- var warned = false; +- function deprecated() { +- if (!warned) { +- if (process.throwDeprecation) { +- throw new Error(msg); +- } else if (process.traceDeprecation) { +- console.trace(msg); +- } else { +- console.error(msg); +- } +- warned = true; +- } +- return fn.apply(this, arguments); +- } +- +- return deprecated; +-}; +- +- +-var debugs = {}; +-var debugEnviron; +-exports.debuglog = function(set) { +- if (isUndefined(debugEnviron)) +- debugEnviron = process.env.NODE_DEBUG || ''; +- set = set.toUpperCase(); +- if (!debugs[set]) { +- if (new RegExp('\\b' + set + '\\b', 'i').test(debugEnviron)) { +- var pid = process.pid; +- debugs[set] = function() { +- var msg = exports.format.apply(exports, arguments); +- console.error('%s %d: %s', set, pid, msg); +- }; +- } else { +- debugs[set] = function() {}; +- } +- } +- return debugs[set]; +-}; +- +- +-/** +- * Echos the value of a value. Trys to print the value out +- * in the best way possible given the different types. +- * +- * @param {Object} obj The object to print out. +- * @param {Object} opts Optional options object that alters the output. +- */ +-/* legacy: obj, showHidden, depth, colors*/ +-function inspect(obj, opts) { +- // default options +- var ctx = { +- seen: [], +- stylize: stylizeNoColor +- }; +- // legacy... +- if (arguments.length >= 3) ctx.depth = arguments[2]; +- if (arguments.length >= 4) ctx.colors = arguments[3]; +- if (isBoolean(opts)) { +- // legacy... +- ctx.showHidden = opts; +- } else if (opts) { +- // got an "options" object +- exports._extend(ctx, opts); +- } +- // set default options +- if (isUndefined(ctx.showHidden)) ctx.showHidden = false; +- if (isUndefined(ctx.depth)) ctx.depth = 2; +- if (isUndefined(ctx.colors)) ctx.colors = false; +- if (isUndefined(ctx.customInspect)) ctx.customInspect = true; +- if (ctx.colors) ctx.stylize = stylizeWithColor; +- return formatValue(ctx, obj, ctx.depth); +-} +-exports.inspect = inspect; +- +- +-// http://en.wikipedia.org/wiki/ANSI_escape_code#graphics +-inspect.colors = { +- 'bold' : [1, 22], +- 'italic' : [3, 23], +- 'underline' : [4, 24], +- 'inverse' : [7, 27], +- 'white' : [37, 39], +- 'grey' : [90, 39], +- 'black' : [30, 39], +- 'blue' : [34, 39], +- 'cyan' : [36, 39], +- 'green' : [32, 39], +- 'magenta' : [35, 39], +- 'red' : [31, 39], +- 'yellow' : [33, 39] +-}; +- +-// Don't use 'blue' not visible on cmd.exe +-inspect.styles = { +- 'special': 'cyan', +- 'number': 'yellow', +- 'boolean': 'yellow', +- 'undefined': 'grey', +- 'null': 'bold', +- 'string': 'green', +- 'date': 'magenta', +- // "name": intentionally not styling +- 'regexp': 'red' +-}; +- +- +-function stylizeWithColor(str, styleType) { +- var style = inspect.styles[styleType]; +- +- if (style) { +- return '\u001b[' + inspect.colors[style][0] + 'm' + str + +- '\u001b[' + inspect.colors[style][1] + 'm'; +- } else { +- return str; +- } +-} +- +- +-function stylizeNoColor(str, styleType) { +- return str; +-} +- +- +-function arrayToHash(array) { +- var hash = {}; +- +- array.forEach(function(val, idx) { +- hash[val] = true; +- }); +- +- return hash; +-} +- +- +-function formatValue(ctx, value, recurseTimes) { +- // Provide a hook for user-specified inspect functions. +- // Check that value is an object with an inspect function on it +- if (ctx.customInspect && +- value && +- isFunction(value.inspect) && +- // Filter out the util module, it's inspect function is special +- value.inspect !== exports.inspect && +- // Also filter out any prototype objects using the circular check. +- !(value.constructor && value.constructor.prototype === value)) { +- var ret = value.inspect(recurseTimes, ctx); +- if (!isString(ret)) { +- ret = formatValue(ctx, ret, recurseTimes); +- } +- return ret; +- } +- +- // Primitive types cannot have properties +- var primitive = formatPrimitive(ctx, value); +- if (primitive) { +- return primitive; +- } +- +- // Look up the keys of the object. +- var keys = Object.keys(value); +- var visibleKeys = arrayToHash(keys); +- +- if (ctx.showHidden) { +- keys = Object.getOwnPropertyNames(value); +- } +- +- // Some type of object without properties can be shortcutted. +- if (keys.length === 0) { +- if (isFunction(value)) { +- var name = value.name ? ': ' + value.name : ''; +- return ctx.stylize('[Function' + name + ']', 'special'); +- } +- if (isRegExp(value)) { +- return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp'); +- } +- if (isDate(value)) { +- return ctx.stylize(Date.prototype.toString.call(value), 'date'); +- } +- if (isError(value)) { +- return formatError(value); +- } +- } +- +- var base = '', array = false, braces = ['{', '}']; +- +- // Make Array say that they are Array +- if (isArray(value)) { +- array = true; +- braces = ['[', ']']; +- } +- +- // Make functions say that they are functions +- if (isFunction(value)) { +- var n = value.name ? ': ' + value.name : ''; +- base = ' [Function' + n + ']'; +- } +- +- // Make RegExps say that they are RegExps +- if (isRegExp(value)) { +- base = ' ' + RegExp.prototype.toString.call(value); +- } +- +- // Make dates with properties first say the date +- if (isDate(value)) { +- base = ' ' + Date.prototype.toUTCString.call(value); +- } +- +- // Make error with message first say the error +- if (isError(value)) { +- base = ' ' + formatError(value); +- } +- +- if (keys.length === 0 && (!array || value.length == 0)) { +- return braces[0] + base + braces[1]; +- } +- +- if (recurseTimes < 0) { +- if (isRegExp(value)) { +- return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp'); +- } else { +- return ctx.stylize('[Object]', 'special'); +- } +- } +- +- ctx.seen.push(value); +- +- var output; +- if (array) { +- output = formatArray(ctx, value, recurseTimes, visibleKeys, keys); +- } else { +- output = keys.map(function(key) { +- return formatProperty(ctx, value, recurseTimes, visibleKeys, key, array); +- }); +- } +- +- ctx.seen.pop(); +- +- return reduceToSingleString(output, base, braces); +-} +- +- +-function formatPrimitive(ctx, value) { +- if (isUndefined(value)) +- return ctx.stylize('undefined', 'undefined'); +- if (isString(value)) { +- var simple = '\'' + JSON.stringify(value).replace(/^"|"$/g, '') +- .replace(/'/g, "\\'") +- .replace(/\\"/g, '"') + '\''; +- return ctx.stylize(simple, 'string'); +- } +- if (isNumber(value)) { +- // Format -0 as '-0'. Strict equality won't distinguish 0 from -0, +- // so instead we use the fact that 1 / -0 < 0 whereas 1 / 0 > 0 . +- if (value === 0 && 1 / value < 0) +- return ctx.stylize('-0', 'number'); +- return ctx.stylize('' + value, 'number'); +- } +- if (isBoolean(value)) +- return ctx.stylize('' + value, 'boolean'); +- // For some reason typeof null is "object", so special case here. +- if (isNull(value)) +- return ctx.stylize('null', 'null'); +-} +- +- +-function formatError(value) { +- return '[' + Error.prototype.toString.call(value) + ']'; +-} +- +- +-function formatArray(ctx, value, recurseTimes, visibleKeys, keys) { +- var output = []; +- for (var i = 0, l = value.length; i < l; ++i) { +- if (hasOwnProperty(value, String(i))) { +- output.push(formatProperty(ctx, value, recurseTimes, visibleKeys, +- String(i), true)); +- } else { +- output.push(''); +- } +- } +- keys.forEach(function(key) { +- if (!key.match(/^\d+$/)) { +- output.push(formatProperty(ctx, value, recurseTimes, visibleKeys, +- key, true)); +- } +- }); +- return output; +-} +- +- +-function formatProperty(ctx, value, recurseTimes, visibleKeys, key, array) { +- var name, str, desc; +- desc = Object.getOwnPropertyDescriptor(value, key) || { value: value[key] }; +- if (desc.get) { +- if (desc.set) { +- str = ctx.stylize('[Getter/Setter]', 'special'); +- } else { +- str = ctx.stylize('[Getter]', 'special'); +- } +- } else { +- if (desc.set) { +- str = ctx.stylize('[Setter]', 'special'); +- } +- } +- if (!hasOwnProperty(visibleKeys, key)) { +- name = '[' + key + ']'; +- } +- if (!str) { +- if (ctx.seen.indexOf(desc.value) < 0) { +- if (isNull(recurseTimes)) { +- str = formatValue(ctx, desc.value, null); +- } else { +- str = formatValue(ctx, desc.value, recurseTimes - 1); +- } +- if (str.indexOf('\n') > -1) { +- if (array) { +- str = str.split('\n').map(function(line) { +- return ' ' + line; +- }).join('\n').substr(2); +- } else { +- str = '\n' + str.split('\n').map(function(line) { +- return ' ' + line; +- }).join('\n'); +- } +- } +- } else { +- str = ctx.stylize('[Circular]', 'special'); +- } +- } +- if (isUndefined(name)) { +- if (array && key.match(/^\d+$/)) { +- return str; +- } +- name = JSON.stringify('' + key); +- if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) { +- name = name.substr(1, name.length - 2); +- name = ctx.stylize(name, 'name'); +- } else { +- name = name.replace(/'/g, "\\'") +- .replace(/\\"/g, '"') +- .replace(/(^"|"$)/g, "'"); +- name = ctx.stylize(name, 'string'); +- } +- } +- +- return name + ': ' + str; +-} +- +- +-function reduceToSingleString(output, base, braces) { +- var numLinesEst = 0; +- var length = output.reduce(function(prev, cur) { +- numLinesEst++; +- if (cur.indexOf('\n') >= 0) numLinesEst++; +- return prev + cur.replace(/\u001b\[\d\d?m/g, '').length + 1; +- }, 0); +- +- if (length > 60) { +- return braces[0] + +- (base === '' ? '' : base + '\n ') + +- ' ' + +- output.join(',\n ') + +- ' ' + +- braces[1]; +- } +- +- return braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1]; +-} +- +- + // NOTE: These type checking functions intentionally don't use `instanceof` + // because it is fragile and can be easily faked with `Object.create()`. + function isArray(ar) { +@@ -522,166 +98,10 @@ function isPrimitive(arg) { + exports.isPrimitive = isPrimitive; + + function isBuffer(arg) { +- return arg instanceof Buffer; ++ return Buffer.isBuffer(arg); + } + exports.isBuffer = isBuffer; + + function objectToString(o) { + return Object.prototype.toString.call(o); +-} +- +- +-function pad(n) { +- return n < 10 ? '0' + n.toString(10) : n.toString(10); +-} +- +- +-var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', +- 'Oct', 'Nov', 'Dec']; +- +-// 26 Feb 16:19:34 +-function timestamp() { +- var d = new Date(); +- var time = [pad(d.getHours()), +- pad(d.getMinutes()), +- pad(d.getSeconds())].join(':'); +- return [d.getDate(), months[d.getMonth()], time].join(' '); +-} +- +- +-// log is just a thin wrapper to console.log that prepends a timestamp +-exports.log = function() { +- console.log('%s - %s', timestamp(), exports.format.apply(exports, arguments)); +-}; +- +- +-/** +- * Inherit the prototype methods from one constructor into another. +- * +- * The Function.prototype.inherits from lang.js rewritten as a standalone +- * function (not on Function.prototype). NOTE: If this file is to be loaded +- * during bootstrapping this function needs to be rewritten using some native +- * functions as prototype setup using normal JavaScript does not work as +- * expected during bootstrapping (see mirror.js in r114903). +- * +- * @param {function} ctor Constructor function which needs to inherit the +- * prototype. +- * @param {function} superCtor Constructor function to inherit prototype from. +- */ +-exports.inherits = function(ctor, superCtor) { +- ctor.super_ = superCtor; +- ctor.prototype = Object.create(superCtor.prototype, { +- constructor: { +- value: ctor, +- enumerable: false, +- writable: true, +- configurable: true +- } +- }); +-}; +- +-exports._extend = function(origin, add) { +- // Don't do anything if add isn't an object +- if (!add || !isObject(add)) return origin; +- +- var keys = Object.keys(add); +- var i = keys.length; +- while (i--) { +- origin[keys[i]] = add[keys[i]]; +- } +- return origin; +-}; +- +-function hasOwnProperty(obj, prop) { +- return Object.prototype.hasOwnProperty.call(obj, prop); +-} +- +- +-// Deprecated old stuff. +- +-exports.p = exports.deprecate(function() { +- for (var i = 0, len = arguments.length; i < len; ++i) { +- console.error(exports.inspect(arguments[i])); +- } +-}, 'util.p: Use console.error() instead'); +- +- +-exports.exec = exports.deprecate(function() { +- return require('child_process').exec.apply(this, arguments); +-}, 'util.exec is now called `child_process.exec`.'); +- +- +-exports.print = exports.deprecate(function() { +- for (var i = 0, len = arguments.length; i < len; ++i) { +- process.stdout.write(String(arguments[i])); +- } +-}, 'util.print: Use console.log instead'); +- +- +-exports.puts = exports.deprecate(function() { +- for (var i = 0, len = arguments.length; i < len; ++i) { +- process.stdout.write(arguments[i] + '\n'); +- } +-}, 'util.puts: Use console.log instead'); +- +- +-exports.debug = exports.deprecate(function(x) { +- process.stderr.write('DEBUG: ' + x + '\n'); +-}, 'util.debug: Use console.error instead'); +- +- +-exports.error = exports.deprecate(function(x) { +- for (var i = 0, len = arguments.length; i < len; ++i) { +- process.stderr.write(arguments[i] + '\n'); +- } +-}, 'util.error: Use console.error instead'); +- +- +-exports.pump = exports.deprecate(function(readStream, writeStream, callback) { +- var callbackCalled = false; +- +- function call(a, b, c) { +- if (callback && !callbackCalled) { +- callback(a, b, c); +- callbackCalled = true; +- } +- } +- +- readStream.addListener('data', function(chunk) { +- if (writeStream.write(chunk) === false) readStream.pause(); +- }); +- +- writeStream.addListener('drain', function() { +- readStream.resume(); +- }); +- +- readStream.addListener('end', function() { +- writeStream.end(); +- }); +- +- readStream.addListener('close', function() { +- call(); +- }); +- +- readStream.addListener('error', function(err) { +- writeStream.end(); +- call(err); +- }); +- +- writeStream.addListener('error', function(err) { +- readStream.destroy(); +- call(err); +- }); +-}, 'util.pump(): Use readableStream.pipe() instead'); +- +- +-var uv; +-exports._errnoException = function(err, syscall) { +- if (isUndefined(uv)) uv = process.binding('uv'); +- var errname = uv.errname(err); +- var e = new Error(syscall + ' ' + errname); +- e.code = errname; +- e.errno = errname; +- e.syscall = syscall; +- return e; +-}; ++}
\ No newline at end of file diff --git a/node_modules/npm-registry-client/node_modules/concat-stream/node_modules/readable-stream/node_modules/core-util-is/lib/util.js b/node_modules/npm-registry-client/node_modules/concat-stream/node_modules/readable-stream/node_modules/core-util-is/lib/util.js new file mode 100644 index 000000000..9074e8ebc --- /dev/null +++ b/node_modules/npm-registry-client/node_modules/concat-stream/node_modules/readable-stream/node_modules/core-util-is/lib/util.js @@ -0,0 +1,107 @@ +// Copyright Joyent, Inc. and other Node contributors. +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to permit +// persons to whom the Software is furnished to do so, subject to the +// following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE +// USE OR OTHER DEALINGS IN THE SOFTWARE. + +// NOTE: These type checking functions intentionally don't use `instanceof` +// because it is fragile and can be easily faked with `Object.create()`. +function isArray(ar) { + return Array.isArray(ar); +} +exports.isArray = isArray; + +function isBoolean(arg) { + return typeof arg === 'boolean'; +} +exports.isBoolean = isBoolean; + +function isNull(arg) { + return arg === null; +} +exports.isNull = isNull; + +function isNullOrUndefined(arg) { + return arg == null; +} +exports.isNullOrUndefined = isNullOrUndefined; + +function isNumber(arg) { + return typeof arg === 'number'; +} +exports.isNumber = isNumber; + +function isString(arg) { + return typeof arg === 'string'; +} +exports.isString = isString; + +function isSymbol(arg) { + return typeof arg === 'symbol'; +} +exports.isSymbol = isSymbol; + +function isUndefined(arg) { + return arg === void 0; +} +exports.isUndefined = isUndefined; + +function isRegExp(re) { + return isObject(re) && objectToString(re) === '[object RegExp]'; +} +exports.isRegExp = isRegExp; + +function isObject(arg) { + return typeof arg === 'object' && arg !== null; +} +exports.isObject = isObject; + +function isDate(d) { + return isObject(d) && objectToString(d) === '[object Date]'; +} +exports.isDate = isDate; + +function isError(e) { + return isObject(e) && + (objectToString(e) === '[object Error]' || e instanceof Error); +} +exports.isError = isError; + +function isFunction(arg) { + return typeof arg === 'function'; +} +exports.isFunction = isFunction; + +function isPrimitive(arg) { + return arg === null || + typeof arg === 'boolean' || + typeof arg === 'number' || + typeof arg === 'string' || + typeof arg === 'symbol' || // ES6 symbol + typeof arg === 'undefined'; +} +exports.isPrimitive = isPrimitive; + +function isBuffer(arg) { + return Buffer.isBuffer(arg); +} +exports.isBuffer = isBuffer; + +function objectToString(o) { + return Object.prototype.toString.call(o); +}
\ No newline at end of file diff --git a/node_modules/npm-registry-client/node_modules/concat-stream/node_modules/readable-stream/node_modules/core-util-is/package.json b/node_modules/npm-registry-client/node_modules/concat-stream/node_modules/readable-stream/node_modules/core-util-is/package.json new file mode 100644 index 000000000..2155d11c6 --- /dev/null +++ b/node_modules/npm-registry-client/node_modules/concat-stream/node_modules/readable-stream/node_modules/core-util-is/package.json @@ -0,0 +1,53 @@ +{ + "name": "core-util-is", + "version": "1.0.1", + "description": "The `util.is*` functions introduced in Node v0.12.", + "main": "lib/util.js", + "repository": { + "type": "git", + "url": "git://github.com/isaacs/core-util-is" + }, + "keywords": [ + "util", + "isBuffer", + "isArray", + "isNumber", + "isString", + "isRegExp", + "isThis", + "isThat", + "polyfill" + ], + "author": { + "name": "Isaac Z. Schlueter", + "email": "i@izs.me", + "url": "http://blog.izs.me/" + }, + "license": "MIT", + "bugs": { + "url": "https://github.com/isaacs/core-util-is/issues" + }, + "readme": "# core-util-is\n\nThe `util.is*` functions introduced in Node v0.12.\n", + "readmeFilename": "README.md", + "homepage": "https://github.com/isaacs/core-util-is", + "_id": "core-util-is@1.0.1", + "dist": { + "shasum": "6b07085aef9a3ccac6ee53bf9d3df0c1521a5538", + "tarball": "http://registry.npmjs.org/core-util-is/-/core-util-is-1.0.1.tgz" + }, + "_from": "core-util-is@>=1.0.0 <1.1.0", + "_npmVersion": "1.3.23", + "_npmUser": { + "name": "isaacs", + "email": "i@izs.me" + }, + "maintainers": [ + { + "name": "isaacs", + "email": "i@izs.me" + } + ], + "directories": {}, + "_shasum": "6b07085aef9a3ccac6ee53bf9d3df0c1521a5538", + "_resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.1.tgz" +} diff --git a/node_modules/npm-registry-client/node_modules/concat-stream/node_modules/readable-stream/node_modules/core-util-is/util.js b/node_modules/npm-registry-client/node_modules/concat-stream/node_modules/readable-stream/node_modules/core-util-is/util.js new file mode 100644 index 000000000..007fa1057 --- /dev/null +++ b/node_modules/npm-registry-client/node_modules/concat-stream/node_modules/readable-stream/node_modules/core-util-is/util.js @@ -0,0 +1,106 @@ +// Copyright Joyent, Inc. and other Node contributors. +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to permit +// persons to whom the Software is furnished to do so, subject to the +// following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE +// USE OR OTHER DEALINGS IN THE SOFTWARE. + +// NOTE: These type checking functions intentionally don't use `instanceof` +// because it is fragile and can be easily faked with `Object.create()`. +function isArray(ar) { + return Array.isArray(ar); +} +exports.isArray = isArray; + +function isBoolean(arg) { + return typeof arg === 'boolean'; +} +exports.isBoolean = isBoolean; + +function isNull(arg) { + return arg === null; +} +exports.isNull = isNull; + +function isNullOrUndefined(arg) { + return arg == null; +} +exports.isNullOrUndefined = isNullOrUndefined; + +function isNumber(arg) { + return typeof arg === 'number'; +} +exports.isNumber = isNumber; + +function isString(arg) { + return typeof arg === 'string'; +} +exports.isString = isString; + +function isSymbol(arg) { + return typeof arg === 'symbol'; +} +exports.isSymbol = isSymbol; + +function isUndefined(arg) { + return arg === void 0; +} +exports.isUndefined = isUndefined; + +function isRegExp(re) { + return isObject(re) && objectToString(re) === '[object RegExp]'; +} +exports.isRegExp = isRegExp; + +function isObject(arg) { + return typeof arg === 'object' && arg !== null; +} +exports.isObject = isObject; + +function isDate(d) { + return isObject(d) && objectToString(d) === '[object Date]'; +} +exports.isDate = isDate; + +function isError(e) { + return isObject(e) && objectToString(e) === '[object Error]'; +} +exports.isError = isError; + +function isFunction(arg) { + return typeof arg === 'function'; +} +exports.isFunction = isFunction; + +function isPrimitive(arg) { + return arg === null || + typeof arg === 'boolean' || + typeof arg === 'number' || + typeof arg === 'string' || + typeof arg === 'symbol' || // ES6 symbol + typeof arg === 'undefined'; +} +exports.isPrimitive = isPrimitive; + +function isBuffer(arg) { + return arg instanceof Buffer; +} +exports.isBuffer = isBuffer; + +function objectToString(o) { + return Object.prototype.toString.call(o); +} diff --git a/node_modules/npm-registry-client/node_modules/concat-stream/node_modules/readable-stream/node_modules/isarray/README.md b/node_modules/npm-registry-client/node_modules/concat-stream/node_modules/readable-stream/node_modules/isarray/README.md new file mode 100644 index 000000000..052a62b8d --- /dev/null +++ b/node_modules/npm-registry-client/node_modules/concat-stream/node_modules/readable-stream/node_modules/isarray/README.md @@ -0,0 +1,54 @@ + +# isarray + +`Array#isArray` for older browsers. + +## Usage + +```js +var isArray = require('isarray'); + +console.log(isArray([])); // => true +console.log(isArray({})); // => false +``` + +## Installation + +With [npm](http://npmjs.org) do + +```bash +$ npm install isarray +``` + +Then bundle for the browser with +[browserify](https://github.com/substack/browserify). + +With [component](http://component.io) do + +```bash +$ component install juliangruber/isarray +``` + +## License + +(MIT) + +Copyright (c) 2013 Julian Gruber <julian@juliangruber.com> + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +of the Software, and to permit persons to whom the Software is furnished to do +so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/node_modules/npm-registry-client/node_modules/concat-stream/node_modules/readable-stream/node_modules/isarray/build/build.js b/node_modules/npm-registry-client/node_modules/concat-stream/node_modules/readable-stream/node_modules/isarray/build/build.js new file mode 100644 index 000000000..ec58596ae --- /dev/null +++ b/node_modules/npm-registry-client/node_modules/concat-stream/node_modules/readable-stream/node_modules/isarray/build/build.js @@ -0,0 +1,209 @@ + +/** + * Require the given path. + * + * @param {String} path + * @return {Object} exports + * @api public + */ + +function require(path, parent, orig) { + var resolved = require.resolve(path); + + // lookup failed + if (null == resolved) { + orig = orig || path; + parent = parent || 'root'; + var err = new Error('Failed to require "' + orig + '" from "' + parent + '"'); + err.path = orig; + err.parent = parent; + err.require = true; + throw err; + } + + var module = require.modules[resolved]; + + // perform real require() + // by invoking the module's + // registered function + if (!module.exports) { + module.exports = {}; + module.client = module.component = true; + module.call(this, module.exports, require.relative(resolved), module); + } + + return module.exports; +} + +/** + * Registered modules. + */ + +require.modules = {}; + +/** + * Registered aliases. + */ + +require.aliases = {}; + +/** + * Resolve `path`. + * + * Lookup: + * + * - PATH/index.js + * - PATH.js + * - PATH + * + * @param {String} path + * @return {String} path or null + * @api private + */ + +require.resolve = function(path) { + if (path.charAt(0) === '/') path = path.slice(1); + var index = path + '/index.js'; + + var paths = [ + path, + path + '.js', + path + '.json', + path + '/index.js', + path + '/index.json' + ]; + + for (var i = 0; i < paths.length; i++) { + var path = paths[i]; + if (require.modules.hasOwnProperty(path)) return path; + } + + if (require.aliases.hasOwnProperty(index)) { + return require.aliases[index]; + } +}; + +/** + * Normalize `path` relative to the current path. + * + * @param {String} curr + * @param {String} path + * @return {String} + * @api private + */ + +require.normalize = function(curr, path) { + var segs = []; + + if ('.' != path.charAt(0)) return path; + + curr = curr.split('/'); + path = path.split('/'); + + for (var i = 0; i < path.length; ++i) { + if ('..' == path[i]) { + curr.pop(); + } else if ('.' != path[i] && '' != path[i]) { + segs.push(path[i]); + } + } + + return curr.concat(segs).join('/'); +}; + +/** + * Register module at `path` with callback `definition`. + * + * @param {String} path + * @param {Function} definition + * @api private + */ + +require.register = function(path, definition) { + require.modules[path] = definition; +}; + +/** + * Alias a module definition. + * + * @param {String} from + * @param {String} to + * @api private + */ + +require.alias = function(from, to) { + if (!require.modules.hasOwnProperty(from)) { + throw new Error('Failed to alias "' + from + '", it does not exist'); + } + require.aliases[to] = from; +}; + +/** + * Return a require function relative to the `parent` path. + * + * @param {String} parent + * @return {Function} + * @api private + */ + +require.relative = function(parent) { + var p = require.normalize(parent, '..'); + + /** + * lastIndexOf helper. + */ + + function lastIndexOf(arr, obj) { + var i = arr.length; + while (i--) { + if (arr[i] === obj) return i; + } + return -1; + } + + /** + * The relative require() itself. + */ + + function localRequire(path) { + var resolved = localRequire.resolve(path); + return require(resolved, parent, path); + } + + /** + * Resolve relative to the parent. + */ + + localRequire.resolve = function(path) { + var c = path.charAt(0); + if ('/' == c) return path.slice(1); + if ('.' == c) return require.normalize(p, path); + + // resolve deps by returning + // the dep in the nearest "deps" + // directory + var segs = parent.split('/'); + var i = lastIndexOf(segs, 'deps') + 1; + if (!i) i = 0; + path = segs.slice(0, i + 1).join('/') + '/deps/' + path; + return path; + }; + + /** + * Check if module is defined at `path`. + */ + + localRequire.exists = function(path) { + return require.modules.hasOwnProperty(localRequire.resolve(path)); + }; + + return localRequire; +}; +require.register("isarray/index.js", function(exports, require, module){ +module.exports = Array.isArray || function (arr) { + return Object.prototype.toString.call(arr) == '[object Array]'; +}; + +}); +require.alias("isarray/index.js", "isarray/index.js"); + diff --git a/node_modules/npm-registry-client/node_modules/concat-stream/node_modules/readable-stream/node_modules/isarray/component.json b/node_modules/npm-registry-client/node_modules/concat-stream/node_modules/readable-stream/node_modules/isarray/component.json new file mode 100644 index 000000000..9e31b6838 --- /dev/null +++ b/node_modules/npm-registry-client/node_modules/concat-stream/node_modules/readable-stream/node_modules/isarray/component.json @@ -0,0 +1,19 @@ +{ + "name" : "isarray", + "description" : "Array#isArray for older browsers", + "version" : "0.0.1", + "repository" : "juliangruber/isarray", + "homepage": "https://github.com/juliangruber/isarray", + "main" : "index.js", + "scripts" : [ + "index.js" + ], + "dependencies" : {}, + "keywords": ["browser","isarray","array"], + "author": { + "name": "Julian Gruber", + "email": "mail@juliangruber.com", + "url": "http://juliangruber.com" + }, + "license": "MIT" +} diff --git a/node_modules/npm-registry-client/node_modules/concat-stream/node_modules/readable-stream/node_modules/isarray/index.js b/node_modules/npm-registry-client/node_modules/concat-stream/node_modules/readable-stream/node_modules/isarray/index.js new file mode 100644 index 000000000..5f5ad45d4 --- /dev/null +++ b/node_modules/npm-registry-client/node_modules/concat-stream/node_modules/readable-stream/node_modules/isarray/index.js @@ -0,0 +1,3 @@ +module.exports = Array.isArray || function (arr) { + return Object.prototype.toString.call(arr) == '[object Array]'; +}; diff --git a/node_modules/npm-registry-client/node_modules/concat-stream/node_modules/readable-stream/node_modules/isarray/package.json b/node_modules/npm-registry-client/node_modules/concat-stream/node_modules/readable-stream/node_modules/isarray/package.json new file mode 100644 index 000000000..fc7904b67 --- /dev/null +++ b/node_modules/npm-registry-client/node_modules/concat-stream/node_modules/readable-stream/node_modules/isarray/package.json @@ -0,0 +1,54 @@ +{ + "name": "isarray", + "description": "Array#isArray for older browsers", + "version": "0.0.1", + "repository": { + "type": "git", + "url": "git://github.com/juliangruber/isarray.git" + }, + "homepage": "https://github.com/juliangruber/isarray", + "main": "index.js", + "scripts": { + "test": "tap test/*.js" + }, + "dependencies": {}, + "devDependencies": { + "tap": "*" + }, + "keywords": [ + "browser", + "isarray", + "array" + ], + "author": { + "name": "Julian Gruber", + "email": "mail@juliangruber.com", + "url": "http://juliangruber.com" + }, + "license": "MIT", + "readme": "\n# isarray\n\n`Array#isArray` for older browsers.\n\n## Usage\n\n```js\nvar isArray = require('isarray');\n\nconsole.log(isArray([])); // => true\nconsole.log(isArray({})); // => false\n```\n\n## Installation\n\nWith [npm](http://npmjs.org) do\n\n```bash\n$ npm install isarray\n```\n\nThen bundle for the browser with\n[browserify](https://github.com/substack/browserify).\n\nWith [component](http://component.io) do\n\n```bash\n$ component install juliangruber/isarray\n```\n\n## License\n\n(MIT)\n\nCopyright (c) 2013 Julian Gruber <julian@juliangruber.com>\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of\nthis software and associated documentation files (the \"Software\"), to deal in\nthe Software without restriction, including without limitation the rights to\nuse, copy, modify, merge, publish, distribute, sublicense, and/or sell copies\nof the Software, and to permit persons to whom the Software is furnished to do\nso, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n", + "readmeFilename": "README.md", + "_id": "isarray@0.0.1", + "dist": { + "shasum": "8a18acfca9a8f4177e09abfc6038939b05d1eedf", + "tarball": "http://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz" + }, + "_from": "isarray@0.0.1", + "_npmVersion": "1.2.18", + "_npmUser": { + "name": "juliangruber", + "email": "julian@juliangruber.com" + }, + "maintainers": [ + { + "name": "juliangruber", + "email": "julian@juliangruber.com" + } + ], + "directories": {}, + "_shasum": "8a18acfca9a8f4177e09abfc6038939b05d1eedf", + "_resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz", + "bugs": { + "url": "https://github.com/juliangruber/isarray/issues" + } +} diff --git a/node_modules/npm-registry-client/node_modules/concat-stream/node_modules/readable-stream/node_modules/string_decoder/.npmignore b/node_modules/npm-registry-client/node_modules/concat-stream/node_modules/readable-stream/node_modules/string_decoder/.npmignore new file mode 100644 index 000000000..206320cc1 --- /dev/null +++ b/node_modules/npm-registry-client/node_modules/concat-stream/node_modules/readable-stream/node_modules/string_decoder/.npmignore @@ -0,0 +1,2 @@ +build +test diff --git a/node_modules/npm-registry-client/node_modules/concat-stream/node_modules/readable-stream/node_modules/string_decoder/LICENSE b/node_modules/npm-registry-client/node_modules/concat-stream/node_modules/readable-stream/node_modules/string_decoder/LICENSE new file mode 100644 index 000000000..6de584a48 --- /dev/null +++ b/node_modules/npm-registry-client/node_modules/concat-stream/node_modules/readable-stream/node_modules/string_decoder/LICENSE @@ -0,0 +1,20 @@ +Copyright Joyent, Inc. and other Node contributors. + +Permission is hereby granted, free of charge, to any person obtaining a +copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to permit +persons to whom the Software is furnished to do so, subject to the +following conditions: + +The above copyright notice and this permission notice shall be included +in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE +USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/node_modules/npm-registry-client/node_modules/concat-stream/node_modules/readable-stream/node_modules/string_decoder/README.md b/node_modules/npm-registry-client/node_modules/concat-stream/node_modules/readable-stream/node_modules/string_decoder/README.md new file mode 100644 index 000000000..4d2aa0015 --- /dev/null +++ b/node_modules/npm-registry-client/node_modules/concat-stream/node_modules/readable-stream/node_modules/string_decoder/README.md @@ -0,0 +1,7 @@ +**string_decoder.js** (`require('string_decoder')`) from Node.js core + +Copyright Joyent, Inc. and other Node contributors. See LICENCE file for details. + +Version numbers match the versions found in Node core, e.g. 0.10.24 matches Node 0.10.24, likewise 0.11.10 matches Node 0.11.10. **Prefer the stable version over the unstable.** + +The *build/* directory contains a build script that will scrape the source from the [joyent/node](https://github.com/joyent/node) repo given a specific Node version.
\ No newline at end of file diff --git a/node_modules/npm-registry-client/node_modules/concat-stream/node_modules/readable-stream/node_modules/string_decoder/index.js b/node_modules/npm-registry-client/node_modules/concat-stream/node_modules/readable-stream/node_modules/string_decoder/index.js new file mode 100644 index 000000000..b00e54fb7 --- /dev/null +++ b/node_modules/npm-registry-client/node_modules/concat-stream/node_modules/readable-stream/node_modules/string_decoder/index.js @@ -0,0 +1,221 @@ +// Copyright Joyent, Inc. and other Node contributors. +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to permit +// persons to whom the Software is furnished to do so, subject to the +// following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE +// USE OR OTHER DEALINGS IN THE SOFTWARE. + +var Buffer = require('buffer').Buffer; + +var isBufferEncoding = Buffer.isEncoding + || function(encoding) { + switch (encoding && encoding.toLowerCase()) { + case 'hex': case 'utf8': case 'utf-8': case 'ascii': case 'binary': case 'base64': case 'ucs2': case 'ucs-2': case 'utf16le': case 'utf-16le': case 'raw': return true; + default: return false; + } + } + + +function assertEncoding(encoding) { + if (encoding && !isBufferEncoding(encoding)) { + throw new Error('Unknown encoding: ' + encoding); + } +} + +// StringDecoder provides an interface for efficiently splitting a series of +// buffers into a series of JS strings without breaking apart multi-byte +// characters. CESU-8 is handled as part of the UTF-8 encoding. +// +// @TODO Handling all encodings inside a single object makes it very difficult +// to reason about this code, so it should be split up in the future. +// @TODO There should be a utf8-strict encoding that rejects invalid UTF-8 code +// points as used by CESU-8. +var StringDecoder = exports.StringDecoder = function(encoding) { + this.encoding = (encoding || 'utf8').toLowerCase().replace(/[-_]/, ''); + assertEncoding(encoding); + switch (this.encoding) { + case 'utf8': + // CESU-8 represents each of Surrogate Pair by 3-bytes + this.surrogateSize = 3; + break; + case 'ucs2': + case 'utf16le': + // UTF-16 represents each of Surrogate Pair by 2-bytes + this.surrogateSize = 2; + this.detectIncompleteChar = utf16DetectIncompleteChar; + break; + case 'base64': + // Base-64 stores 3 bytes in 4 chars, and pads the remainder. + this.surrogateSize = 3; + this.detectIncompleteChar = base64DetectIncompleteChar; + break; + default: + this.write = passThroughWrite; + return; + } + + // Enough space to store all bytes of a single character. UTF-8 needs 4 + // bytes, but CESU-8 may require up to 6 (3 bytes per surrogate). + this.charBuffer = new Buffer(6); + // Number of bytes received for the current incomplete multi-byte character. + this.charReceived = 0; + // Number of bytes expected for the current incomplete multi-byte character. + this.charLength = 0; +}; + + +// write decodes the given buffer and returns it as JS string that is +// guaranteed to not contain any partial multi-byte characters. Any partial +// character found at the end of the buffer is buffered up, and will be +// returned when calling write again with the remaining bytes. +// +// Note: Converting a Buffer containing an orphan surrogate to a String +// currently works, but converting a String to a Buffer (via `new Buffer`, or +// Buffer#write) will replace incomplete surrogates with the unicode +// replacement character. See https://codereview.chromium.org/121173009/ . +StringDecoder.prototype.write = function(buffer) { + var charStr = ''; + // if our last write ended with an incomplete multibyte character + while (this.charLength) { + // determine how many remaining bytes this buffer has to offer for this char + var available = (buffer.length >= this.charLength - this.charReceived) ? + this.charLength - this.charReceived : + buffer.length; + + // add the new bytes to the char buffer + buffer.copy(this.charBuffer, this.charReceived, 0, available); + this.charReceived += available; + + if (this.charReceived < this.charLength) { + // still not enough chars in this buffer? wait for more ... + return ''; + } + + // remove bytes belonging to the current character from the buffer + buffer = buffer.slice(available, buffer.length); + + // get the character that was split + charStr = this.charBuffer.slice(0, this.charLength).toString(this.encoding); + + // CESU-8: lead surrogate (D800-DBFF) is also the incomplete character + var charCode = charStr.charCodeAt(charStr.length - 1); + if (charCode >= 0xD800 && charCode <= 0xDBFF) { + this.charLength += this.surrogateSize; + charStr = ''; + continue; + } + this.charReceived = this.charLength = 0; + + // if there are no more bytes in this buffer, just emit our char + if (buffer.length === 0) { + return charStr; + } + break; + } + + // determine and set charLength / charReceived + this.detectIncompleteChar(buffer); + + var end = buffer.length; + if (this.charLength) { + // buffer the incomplete character bytes we got + buffer.copy(this.charBuffer, 0, buffer.length - this.charReceived, end); + end -= this.charReceived; + } + + charStr += buffer.toString(this.encoding, 0, end); + + var end = charStr.length - 1; + var charCode = charStr.charCodeAt(end); + // CESU-8: lead surrogate (D800-DBFF) is also the incomplete character + if (charCode >= 0xD800 && charCode <= 0xDBFF) { + var size = this.surrogateSize; + this.charLength += size; + this.charReceived += size; + this.charBuffer.copy(this.charBuffer, size, 0, size); + buffer.copy(this.charBuffer, 0, 0, size); + return charStr.substring(0, end); + } + + // or just emit the charStr + return charStr; +}; + +// detectIncompleteChar determines if there is an incomplete UTF-8 character at +// the end of the given buffer. If so, it sets this.charLength to the byte +// length that character, and sets this.charReceived to the number of bytes +// that are available for this character. +StringDecoder.prototype.detectIncompleteChar = function(buffer) { + // determine how many bytes we have to check at the end of this buffer + var i = (buffer.length >= 3) ? 3 : buffer.length; + + // Figure out if one of the last i bytes of our buffer announces an + // incomplete char. + for (; i > 0; i--) { + var c = buffer[buffer.length - i]; + + // See http://en.wikipedia.org/wiki/UTF-8#Description + + // 110XXXXX + if (i == 1 && c >> 5 == 0x06) { + this.charLength = 2; + break; + } + + // 1110XXXX + if (i <= 2 && c >> 4 == 0x0E) { + this.charLength = 3; + break; + } + + // 11110XXX + if (i <= 3 && c >> 3 == 0x1E) { + this.charLength = 4; + break; + } + } + this.charReceived = i; +}; + +StringDecoder.prototype.end = function(buffer) { + var res = ''; + if (buffer && buffer.length) + res = this.write(buffer); + + if (this.charReceived) { + var cr = this.charReceived; + var buf = this.charBuffer; + var enc = this.encoding; + res += buf.slice(0, cr).toString(enc); + } + + return res; +}; + +function passThroughWrite(buffer) { + return buffer.toString(this.encoding); +} + +function utf16DetectIncompleteChar(buffer) { + this.charReceived = buffer.length % 2; + this.charLength = this.charReceived ? 2 : 0; +} + +function base64DetectIncompleteChar(buffer) { + this.charReceived = buffer.length % 3; + this.charLength = this.charReceived ? 3 : 0; +} diff --git a/node_modules/npm-registry-client/node_modules/concat-stream/node_modules/readable-stream/node_modules/string_decoder/package.json b/node_modules/npm-registry-client/node_modules/concat-stream/node_modules/readable-stream/node_modules/string_decoder/package.json new file mode 100644 index 000000000..0364d54ba --- /dev/null +++ b/node_modules/npm-registry-client/node_modules/concat-stream/node_modules/readable-stream/node_modules/string_decoder/package.json @@ -0,0 +1,54 @@ +{ + "name": "string_decoder", + "version": "0.10.31", + "description": "The string_decoder module from Node core", + "main": "index.js", + "dependencies": {}, + "devDependencies": { + "tap": "~0.4.8" + }, + "scripts": { + "test": "tap test/simple/*.js" + }, + "repository": { + "type": "git", + "url": "git://github.com/rvagg/string_decoder.git" + }, + "homepage": "https://github.com/rvagg/string_decoder", + "keywords": [ + "string", + "decoder", + "browser", + "browserify" + ], + "license": "MIT", + "gitHead": "d46d4fd87cf1d06e031c23f1ba170ca7d4ade9a0", + "bugs": { + "url": "https://github.com/rvagg/string_decoder/issues" + }, + "_id": "string_decoder@0.10.31", + "_shasum": "62e203bc41766c6c28c9fc84301dab1c5310fa94", + "_from": "string_decoder@>=0.10.0 <0.11.0", + "_npmVersion": "1.4.23", + "_npmUser": { + "name": "rvagg", + "email": "rod@vagg.org" + }, + "maintainers": [ + { + "name": "substack", + "email": "mail@substack.net" + }, + { + "name": "rvagg", + "email": "rod@vagg.org" + } + ], + "dist": { + "shasum": "62e203bc41766c6c28c9fc84301dab1c5310fa94", + "tarball": "http://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz" + }, + "directories": {}, + "_resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz", + "readme": "ERROR: No README data found!" +} diff --git a/node_modules/npm-registry-client/node_modules/concat-stream/node_modules/readable-stream/package.json b/node_modules/npm-registry-client/node_modules/concat-stream/node_modules/readable-stream/package.json new file mode 100644 index 000000000..295adce71 --- /dev/null +++ b/node_modules/npm-registry-client/node_modules/concat-stream/node_modules/readable-stream/package.json @@ -0,0 +1,70 @@ +{ + "name": "readable-stream", + "version": "1.1.13", + "description": "Streams3, a user-land copy of the stream library from Node.js v0.11.x", + "main": "readable.js", + "dependencies": { + "core-util-is": "~1.0.0", + "isarray": "0.0.1", + "string_decoder": "~0.10.x", + "inherits": "~2.0.1" + }, + "devDependencies": { + "tap": "~0.2.6" + }, + "scripts": { + "test": "tap test/simple/*.js" + }, + "repository": { + "type": "git", + "url": "git://github.com/isaacs/readable-stream" + }, + "keywords": [ + "readable", + "stream", + "pipe" + ], + "browser": { + "util": false + }, + "author": { + "name": "Isaac Z. Schlueter", + "email": "i@izs.me", + "url": "http://blog.izs.me/" + }, + "license": "MIT", + "gitHead": "3b672fd7ae92acf5b4ffdbabf74b372a0a56b051", + "bugs": { + "url": "https://github.com/isaacs/readable-stream/issues" + }, + "homepage": "https://github.com/isaacs/readable-stream", + "_id": "readable-stream@1.1.13", + "_shasum": "f6eef764f514c89e2b9e23146a75ba106756d23e", + "_from": "readable-stream@>=1.1.9 <1.2.0", + "_npmVersion": "1.4.23", + "_npmUser": { + "name": "rvagg", + "email": "rod@vagg.org" + }, + "maintainers": [ + { + "name": "isaacs", + "email": "i@izs.me" + }, + { + "name": "tootallnate", + "email": "nathan@tootallnate.net" + }, + { + "name": "rvagg", + "email": "rod@vagg.org" + } + ], + "dist": { + "shasum": "f6eef764f514c89e2b9e23146a75ba106756d23e", + "tarball": "http://registry.npmjs.org/readable-stream/-/readable-stream-1.1.13.tgz" + }, + "directories": {}, + "_resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-1.1.13.tgz", + "readme": "ERROR: No README data found!" +} diff --git a/node_modules/npm-registry-client/node_modules/concat-stream/node_modules/readable-stream/passthrough.js b/node_modules/npm-registry-client/node_modules/concat-stream/node_modules/readable-stream/passthrough.js new file mode 100644 index 000000000..27e8d8a55 --- /dev/null +++ b/node_modules/npm-registry-client/node_modules/concat-stream/node_modules/readable-stream/passthrough.js @@ -0,0 +1 @@ +module.exports = require("./lib/_stream_passthrough.js") diff --git a/node_modules/npm-registry-client/node_modules/concat-stream/node_modules/readable-stream/readable.js b/node_modules/npm-registry-client/node_modules/concat-stream/node_modules/readable-stream/readable.js new file mode 100644 index 000000000..09b8bf509 --- /dev/null +++ b/node_modules/npm-registry-client/node_modules/concat-stream/node_modules/readable-stream/readable.js @@ -0,0 +1,7 @@ +exports = module.exports = require('./lib/_stream_readable.js'); +exports.Stream = require('stream'); +exports.Readable = exports; +exports.Writable = require('./lib/_stream_writable.js'); +exports.Duplex = require('./lib/_stream_duplex.js'); +exports.Transform = require('./lib/_stream_transform.js'); +exports.PassThrough = require('./lib/_stream_passthrough.js'); diff --git a/node_modules/npm-registry-client/node_modules/concat-stream/node_modules/readable-stream/transform.js b/node_modules/npm-registry-client/node_modules/concat-stream/node_modules/readable-stream/transform.js new file mode 100644 index 000000000..5d482f078 --- /dev/null +++ b/node_modules/npm-registry-client/node_modules/concat-stream/node_modules/readable-stream/transform.js @@ -0,0 +1 @@ +module.exports = require("./lib/_stream_transform.js") diff --git a/node_modules/npm-registry-client/node_modules/concat-stream/node_modules/readable-stream/writable.js b/node_modules/npm-registry-client/node_modules/concat-stream/node_modules/readable-stream/writable.js new file mode 100644 index 000000000..e1e9efdf3 --- /dev/null +++ b/node_modules/npm-registry-client/node_modules/concat-stream/node_modules/readable-stream/writable.js @@ -0,0 +1 @@ +module.exports = require("./lib/_stream_writable.js") diff --git a/node_modules/npm-registry-client/node_modules/concat-stream/node_modules/typedarray/.travis.yml b/node_modules/npm-registry-client/node_modules/concat-stream/node_modules/typedarray/.travis.yml new file mode 100644 index 000000000..cc4dba29d --- /dev/null +++ b/node_modules/npm-registry-client/node_modules/concat-stream/node_modules/typedarray/.travis.yml @@ -0,0 +1,4 @@ +language: node_js +node_js: + - "0.8" + - "0.10" diff --git a/node_modules/npm-registry-client/node_modules/concat-stream/node_modules/typedarray/LICENSE b/node_modules/npm-registry-client/node_modules/concat-stream/node_modules/typedarray/LICENSE new file mode 100644 index 000000000..11adfaec9 --- /dev/null +++ b/node_modules/npm-registry-client/node_modules/concat-stream/node_modules/typedarray/LICENSE @@ -0,0 +1,35 @@ +/* + Copyright (c) 2010, Linden Research, Inc. + Copyright (c) 2012, Joshua Bell + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + $/LicenseInfo$ + */ + +// Original can be found at: +// https://bitbucket.org/lindenlab/llsd +// Modifications by Joshua Bell inexorabletash@gmail.com +// https://github.com/inexorabletash/polyfill + +// ES3/ES5 implementation of the Krhonos Typed Array Specification +// Ref: http://www.khronos.org/registry/typedarray/specs/latest/ +// Date: 2011-02-01 +// +// Variations: +// * Allows typed_array.get/set() as alias for subscripts (typed_array[]) diff --git a/node_modules/npm-registry-client/node_modules/concat-stream/node_modules/typedarray/example/tarray.js b/node_modules/npm-registry-client/node_modules/concat-stream/node_modules/typedarray/example/tarray.js new file mode 100644 index 000000000..8423d7c9b --- /dev/null +++ b/node_modules/npm-registry-client/node_modules/concat-stream/node_modules/typedarray/example/tarray.js @@ -0,0 +1,4 @@ +var Uint8Array = require('../').Uint8Array; +var ua = new Uint8Array(5); +ua[1] = 256 + 55; +console.log(ua[1]); diff --git a/node_modules/npm-registry-client/node_modules/concat-stream/node_modules/typedarray/index.js b/node_modules/npm-registry-client/node_modules/concat-stream/node_modules/typedarray/index.js new file mode 100644 index 000000000..5e540841f --- /dev/null +++ b/node_modules/npm-registry-client/node_modules/concat-stream/node_modules/typedarray/index.js @@ -0,0 +1,630 @@ +var undefined = (void 0); // Paranoia + +// Beyond this value, index getters/setters (i.e. array[0], array[1]) are so slow to +// create, and consume so much memory, that the browser appears frozen. +var MAX_ARRAY_LENGTH = 1e5; + +// Approximations of internal ECMAScript conversion functions +var ECMAScript = (function() { + // Stash a copy in case other scripts modify these + var opts = Object.prototype.toString, + ophop = Object.prototype.hasOwnProperty; + + return { + // Class returns internal [[Class]] property, used to avoid cross-frame instanceof issues: + Class: function(v) { return opts.call(v).replace(/^\[object *|\]$/g, ''); }, + HasProperty: function(o, p) { return p in o; }, + HasOwnProperty: function(o, p) { return ophop.call(o, p); }, + IsCallable: function(o) { return typeof o === 'function'; }, + ToInt32: function(v) { return v >> 0; }, + ToUint32: function(v) { return v >>> 0; } + }; +}()); + +// Snapshot intrinsics +var LN2 = Math.LN2, + abs = Math.abs, + floor = Math.floor, + log = Math.log, + min = Math.min, + pow = Math.pow, + round = Math.round; + +// ES5: lock down object properties +function configureProperties(obj) { + if (getOwnPropNames && defineProp) { + var props = getOwnPropNames(obj), i; + for (i = 0; i < props.length; i += 1) { + defineProp(obj, props[i], { + value: obj[props[i]], + writable: false, + enumerable: false, + configurable: false + }); + } + } +} + +// emulate ES5 getter/setter API using legacy APIs +// http://blogs.msdn.com/b/ie/archive/2010/09/07/transitioning-existing-code-to-the-es5-getter-setter-apis.aspx +// (second clause tests for Object.defineProperty() in IE<9 that only supports extending DOM prototypes, but +// note that IE<9 does not support __defineGetter__ or __defineSetter__ so it just renders the method harmless) +var defineProp +if (Object.defineProperty && (function() { + try { + Object.defineProperty({}, 'x', {}); + return true; + } catch (e) { + return false; + } + })()) { + defineProp = Object.defineProperty; +} else { + defineProp = function(o, p, desc) { + if (!o === Object(o)) throw new TypeError("Object.defineProperty called on non-object"); + if (ECMAScript.HasProperty(desc, 'get') && Object.prototype.__defineGetter__) { Object.prototype.__defineGetter__.call(o, p, desc.get); } + if (ECMAScript.HasProperty(desc, 'set') && Object.prototype.__defineSetter__) { Object.prototype.__defineSetter__.call(o, p, desc.set); } + if (ECMAScript.HasProperty(desc, 'value')) { o[p] = desc.value; } + return o; + }; +} + +var getOwnPropNames = Object.getOwnPropertyNames || function (o) { + if (o !== Object(o)) throw new TypeError("Object.getOwnPropertyNames called on non-object"); + var props = [], p; + for (p in o) { + if (ECMAScript.HasOwnProperty(o, p)) { + props.push(p); + } + } + return props; +}; + +// ES5: Make obj[index] an alias for obj._getter(index)/obj._setter(index, value) +// for index in 0 ... obj.length +function makeArrayAccessors(obj) { + if (!defineProp) { return; } + + if (obj.length > MAX_ARRAY_LENGTH) throw new RangeError("Array too large for polyfill"); + + function makeArrayAccessor(index) { + defineProp(obj, index, { + 'get': function() { return obj._getter(index); }, + 'set': function(v) { obj._setter(index, v); }, + enumerable: true, + configurable: false + }); + } + + var i; + for (i = 0; i < obj.length; i += 1) { + makeArrayAccessor(i); + } +} + +// Internal conversion functions: +// pack<Type>() - take a number (interpreted as Type), output a byte array +// unpack<Type>() - take a byte array, output a Type-like number + +function as_signed(value, bits) { var s = 32 - bits; return (value << s) >> s; } +function as_unsigned(value, bits) { var s = 32 - bits; return (value << s) >>> s; } + +function packI8(n) { return [n & 0xff]; } +function unpackI8(bytes) { return as_signed(bytes[0], 8); } + +function packU8(n) { return [n & 0xff]; } +function unpackU8(bytes) { return as_unsigned(bytes[0], 8); } + +function packU8Clamped(n) { n = round(Number(n)); return [n < 0 ? 0 : n > 0xff ? 0xff : n & 0xff]; } + +function packI16(n) { return [(n >> 8) & 0xff, n & 0xff]; } +function unpackI16(bytes) { return as_signed(bytes[0] << 8 | bytes[1], 16); } + +function packU16(n) { return [(n >> 8) & 0xff, n & 0xff]; } +function unpackU16(bytes) { return as_unsigned(bytes[0] << 8 | bytes[1], 16); } + +function packI32(n) { return [(n >> 24) & 0xff, (n >> 16) & 0xff, (n >> 8) & 0xff, n & 0xff]; } +function unpackI32(bytes) { return as_signed(bytes[0] << 24 | bytes[1] << 16 | bytes[2] << 8 | bytes[3], 32); } + +function packU32(n) { return [(n >> 24) & 0xff, (n >> 16) & 0xff, (n >> 8) & 0xff, n & 0xff]; } +function unpackU32(bytes) { return as_unsigned(bytes[0] << 24 | bytes[1] << 16 | bytes[2] << 8 | bytes[3], 32); } + +function packIEEE754(v, ebits, fbits) { + + var bias = (1 << (ebits - 1)) - 1, + s, e, f, ln, + i, bits, str, bytes; + + function roundToEven(n) { + var w = floor(n), f = n - w; + if (f < 0.5) + return w; + if (f > 0.5) + return w + 1; + return w % 2 ? w + 1 : w; + } + + // Compute sign, exponent, fraction + if (v !== v) { + // NaN + // http://dev.w3.org/2006/webapi/WebIDL/#es-type-mapping + e = (1 << ebits) - 1; f = pow(2, fbits - 1); s = 0; + } else if (v === Infinity || v === -Infinity) { + e = (1 << ebits) - 1; f = 0; s = (v < 0) ? 1 : 0; + } else if (v === 0) { + e = 0; f = 0; s = (1 / v === -Infinity) ? 1 : 0; + } else { + s = v < 0; + v = abs(v); + + if (v >= pow(2, 1 - bias)) { + e = min(floor(log(v) / LN2), 1023); + f = roundToEven(v / pow(2, e) * pow(2, fbits)); + if (f / pow(2, fbits) >= 2) { + e = e + 1; + f = 1; + } + if (e > bias) { + // Overflow + e = (1 << ebits) - 1; + f = 0; + } else { + // Normalized + e = e + bias; + f = f - pow(2, fbits); + } + } else { + // Denormalized + e = 0; + f = roundToEven(v / pow(2, 1 - bias - fbits)); + } + } + + // Pack sign, exponent, fraction + bits = []; + for (i = fbits; i; i -= 1) { bits.push(f % 2 ? 1 : 0); f = floor(f / 2); } + for (i = ebits; i; i -= 1) { bits.push(e % 2 ? 1 : 0); e = floor(e / 2); } + bits.push(s ? 1 : 0); + bits.reverse(); + str = bits.join(''); + + // Bits to bytes + bytes = []; + while (str.length) { + bytes.push(parseInt(str.substring(0, 8), 2)); + str = str.substring(8); + } + return bytes; +} + +function unpackIEEE754(bytes, ebits, fbits) { + + // Bytes to bits + var bits = [], i, j, b, str, + bias, s, e, f; + + for (i = bytes.length; i; i -= 1) { + b = bytes[i - 1]; + for (j = 8; j; j -= 1) { + bits.push(b % 2 ? 1 : 0); b = b >> 1; + } + } + bits.reverse(); + str = bits.join(''); + + // Unpack sign, exponent, fraction + bias = (1 << (ebits - 1)) - 1; + s = parseInt(str.substring(0, 1), 2) ? -1 : 1; + e = parseInt(str.substring(1, 1 + ebits), 2); + f = parseInt(str.substring(1 + ebits), 2); + + // Produce number + if (e === (1 << ebits) - 1) { + return f !== 0 ? NaN : s * Infinity; + } else if (e > 0) { + // Normalized + return s * pow(2, e - bias) * (1 + f / pow(2, fbits)); + } else if (f !== 0) { + // Denormalized + return s * pow(2, -(bias - 1)) * (f / pow(2, fbits)); + } else { + return s < 0 ? -0 : 0; + } +} + +function unpackF64(b) { return unpackIEEE754(b, 11, 52); } +function packF64(v) { return packIEEE754(v, 11, 52); } +function unpackF32(b) { return unpackIEEE754(b, 8, 23); } +function packF32(v) { return packIEEE754(v, 8, 23); } + + +// +// 3 The ArrayBuffer Type +// + +(function() { + + /** @constructor */ + var ArrayBuffer = function ArrayBuffer(length) { + length = ECMAScript.ToInt32(length); + if (length < 0) throw new RangeError('ArrayBuffer size is not a small enough positive integer'); + + this.byteLength = length; + this._bytes = []; + this._bytes.length = length; + + var i; + for (i = 0; i < this.byteLength; i += 1) { + this._bytes[i] = 0; + } + + configureProperties(this); + }; + + exports.ArrayBuffer = exports.ArrayBuffer || ArrayBuffer; + + // + // 4 The ArrayBufferView Type + // + + // NOTE: this constructor is not exported + /** @constructor */ + var ArrayBufferView = function ArrayBufferView() { + //this.buffer = null; + //this.byteOffset = 0; + //this.byteLength = 0; + }; + + // + // 5 The Typed Array View Types + // + + function makeConstructor(bytesPerElement, pack, unpack) { + // Each TypedArray type requires a distinct constructor instance with + // identical logic, which this produces. + + var ctor; + ctor = function(buffer, byteOffset, length) { + var array, sequence, i, s; + + if (!arguments.length || typeof arguments[0] === 'number') { + // Constructor(unsigned long length) + this.length = ECMAScript.ToInt32(arguments[0]); + if (length < 0) throw new RangeError('ArrayBufferView size is not a small enough positive integer'); + + this.byteLength = this.length * this.BYTES_PER_ELEMENT; + this.buffer = new ArrayBuffer(this.byteLength); + this.byteOffset = 0; + } else if (typeof arguments[0] === 'object' && arguments[0].constructor === ctor) { + // Constructor(TypedArray array) + array = arguments[0]; + + this.length = array.length; + this.byteLength = this.length * this.BYTES_PER_ELEMENT; + this.buffer = new ArrayBuffer(this.byteLength); + this.byteOffset = 0; + + for (i = 0; i < this.length; i += 1) { + this._setter(i, array._getter(i)); + } + } else if (typeof arguments[0] === 'object' && + !(arguments[0] instanceof ArrayBuffer || ECMAScript.Class(arguments[0]) === 'ArrayBuffer')) { + // Constructor(sequence<type> array) + sequence = arguments[0]; + + this.length = ECMAScript.ToUint32(sequence.length); + this.byteLength = this.length * this.BYTES_PER_ELEMENT; + this.buffer = new ArrayBuffer(this.byteLength); + this.byteOffset = 0; + + for (i = 0; i < this.length; i += 1) { + s = sequence[i]; + this._setter(i, Number(s)); + } + } else if (typeof arguments[0] === 'object' && + (arguments[0] instanceof ArrayBuffer || ECMAScript.Class(arguments[0]) === 'ArrayBuffer')) { + // Constructor(ArrayBuffer buffer, + // optional unsigned long byteOffset, optional unsigned long length) + this.buffer = buffer; + + this.byteOffset = ECMAScript.ToUint32(byteOffset); + if (this.byteOffset > this.buffer.byteLength) { + throw new RangeError("byteOffset out of range"); + } + + if (this.byteOffset % this.BYTES_PER_ELEMENT) { + // The given byteOffset must be a multiple of the element + // size of the specific type, otherwise an exception is raised. + throw new RangeError("ArrayBuffer length minus the byteOffset is not a multiple of the element size."); + } + + if (arguments.length < 3) { + this.byteLength = this.buffer.byteLength - this.byteOffset; + + if (this.byteLength % this.BYTES_PER_ELEMENT) { + throw new RangeError("length of buffer minus byteOffset not a multiple of the element size"); + } + this.length = this.byteLength / this.BYTES_PER_ELEMENT; + } else { + this.length = ECMAScript.ToUint32(length); + this.byteLength = this.length * this.BYTES_PER_ELEMENT; + } + + if ((this.byteOffset + this.byteLength) > this.buffer.byteLength) { + throw new RangeError("byteOffset and length reference an area beyond the end of the buffer"); + } + } else { + throw new TypeError("Unexpected argument type(s)"); + } + + this.constructor = ctor; + + configureProperties(this); + makeArrayAccessors(this); + }; + + ctor.prototype = new ArrayBufferView(); + ctor.prototype.BYTES_PER_ELEMENT = bytesPerElement; + ctor.prototype._pack = pack; + ctor.prototype._unpack = unpack; + ctor.BYTES_PER_ELEMENT = bytesPerElement; + + // getter type (unsigned long index); + ctor.prototype._getter = function(index) { + if (arguments.length < 1) throw new SyntaxError("Not enough arguments"); + + index = ECMAScript.ToUint32(index); + if (index >= this.length) { + return undefined; + } + + var bytes = [], i, o; + for (i = 0, o = this.byteOffset + index * this.BYTES_PER_ELEMENT; + i < this.BYTES_PER_ELEMENT; + i += 1, o += 1) { + bytes.push(this.buffer._bytes[o]); + } + return this._unpack(bytes); + }; + + // NONSTANDARD: convenience alias for getter: type get(unsigned long index); + ctor.prototype.get = ctor.prototype._getter; + + // setter void (unsigned long index, type value); + ctor.prototype._setter = function(index, value) { + if (arguments.length < 2) throw new SyntaxError("Not enough arguments"); + + index = ECMAScript.ToUint32(index); + if (index >= this.length) { + return undefined; + } + + var bytes = this._pack(value), i, o; + for (i = 0, o = this.byteOffset + index * this.BYTES_PER_ELEMENT; + i < this.BYTES_PER_ELEMENT; + i += 1, o += 1) { + this.buffer._bytes[o] = bytes[i]; + } + }; + + // void set(TypedArray array, optional unsigned long offset); + // void set(sequence<type> array, optional unsigned long offset); + ctor.prototype.set = function(index, value) { + if (arguments.length < 1) throw new SyntaxError("Not enough arguments"); + var array, sequence, offset, len, + i, s, d, + byteOffset, byteLength, tmp; + + if (typeof arguments[0] === 'object' && arguments[0].constructor === this.constructor) { + // void set(TypedArray array, optional unsigned long offset); + array = arguments[0]; + offset = ECMAScript.ToUint32(arguments[1]); + + if (offset + array.length > this.length) { + throw new RangeError("Offset plus length of array is out of range"); + } + + byteOffset = this.byteOffset + offset * this.BYTES_PER_ELEMENT; + byteLength = array.length * this.BYTES_PER_ELEMENT; + + if (array.buffer === this.buffer) { + tmp = []; + for (i = 0, s = array.byteOffset; i < byteLength; i += 1, s += 1) { + tmp[i] = array.buffer._bytes[s]; + } + for (i = 0, d = byteOffset; i < byteLength; i += 1, d += 1) { + this.buffer._bytes[d] = tmp[i]; + } + } else { + for (i = 0, s = array.byteOffset, d = byteOffset; + i < byteLength; i += 1, s += 1, d += 1) { + this.buffer._bytes[d] = array.buffer._bytes[s]; + } + } + } else if (typeof arguments[0] === 'object' && typeof arguments[0].length !== 'undefined') { + // void set(sequence<type> array, optional unsigned long offset); + sequence = arguments[0]; + len = ECMAScript.ToUint32(sequence.length); + offset = ECMAScript.ToUint32(arguments[1]); + + if (offset + len > this.length) { + throw new RangeError("Offset plus length of array is out of range"); + } + + for (i = 0; i < len; i += 1) { + s = sequence[i]; + this._setter(offset + i, Number(s)); + } + } else { + throw new TypeError("Unexpected argument type(s)"); + } + }; + + // TypedArray subarray(long begin, optional long end); + ctor.prototype.subarray = function(start, end) { + function clamp(v, min, max) { return v < min ? min : v > max ? max : v; } + + start = ECMAScript.ToInt32(start); + end = ECMAScript.ToInt32(end); + + if (arguments.length < 1) { start = 0; } + if (arguments.length < 2) { end = this.length; } + + if (start < 0) { start = this.length + start; } + if (end < 0) { end = this.length + end; } + + start = clamp(start, 0, this.length); + end = clamp(end, 0, this.length); + + var len = end - start; + if (len < 0) { + len = 0; + } + + return new this.constructor( + this.buffer, this.byteOffset + start * this.BYTES_PER_ELEMENT, len); + }; + + return ctor; + } + + var Int8Array = makeConstructor(1, packI8, unpackI8); + var Uint8Array = makeConstructor(1, packU8, unpackU8); + var Uint8ClampedArray = makeConstructor(1, packU8Clamped, unpackU8); + var Int16Array = makeConstructor(2, packI16, unpackI16); + var Uint16Array = makeConstructor(2, packU16, unpackU16); + var Int32Array = makeConstructor(4, packI32, unpackI32); + var Uint32Array = makeConstructor(4, packU32, unpackU32); + var Float32Array = makeConstructor(4, packF32, unpackF32); + var Float64Array = makeConstructor(8, packF64, unpackF64); + + exports.Int8Array = exports.Int8Array || Int8Array; + exports.Uint8Array = exports.Uint8Array || Uint8Array; + exports.Uint8ClampedArray = exports.Uint8ClampedArray || Uint8ClampedArray; + exports.Int16Array = exports.Int16Array || Int16Array; + exports.Uint16Array = exports.Uint16Array || Uint16Array; + exports.Int32Array = exports.Int32Array || Int32Array; + exports.Uint32Array = exports.Uint32Array || Uint32Array; + exports.Float32Array = exports.Float32Array || Float32Array; + exports.Float64Array = exports.Float64Array || Float64Array; +}()); + +// +// 6 The DataView View Type +// + +(function() { + function r(array, index) { + return ECMAScript.IsCallable(array.get) ? array.get(index) : array[index]; + } + + var IS_BIG_ENDIAN = (function() { + var u16array = new(exports.Uint16Array)([0x1234]), + u8array = new(exports.Uint8Array)(u16array.buffer); + return r(u8array, 0) === 0x12; + }()); + + // Constructor(ArrayBuffer buffer, + // optional unsigned long byteOffset, + // optional unsigned long byteLength) + /** @constructor */ + var DataView = function DataView(buffer, byteOffset, byteLength) { + if (arguments.length === 0) { + buffer = new exports.ArrayBuffer(0); + } else if (!(buffer instanceof exports.ArrayBuffer || ECMAScript.Class(buffer) === 'ArrayBuffer')) { + throw new TypeError("TypeError"); + } + + this.buffer = buffer || new exports.ArrayBuffer(0); + + this.byteOffset = ECMAScript.ToUint32(byteOffset); + if (this.byteOffset > this.buffer.byteLength) { + throw new RangeError("byteOffset out of range"); + } + + if (arguments.length < 3) { + this.byteLength = this.buffer.byteLength - this.byteOffset; + } else { + this.byteLength = ECMAScript.ToUint32(byteLength); + } + + if ((this.byteOffset + this.byteLength) > this.buffer.byteLength) { + throw new RangeError("byteOffset and length reference an area beyond the end of the buffer"); + } + + configureProperties(this); + }; + + function makeGetter(arrayType) { + return function(byteOffset, littleEndian) { + + byteOffset = ECMAScript.ToUint32(byteOffset); + + if (byteOffset + arrayType.BYTES_PER_ELEMENT > this.byteLength) { + throw new RangeError("Array index out of range"); + } + byteOffset += this.byteOffset; + + var uint8Array = new exports.Uint8Array(this.buffer, byteOffset, arrayType.BYTES_PER_ELEMENT), + bytes = [], i; + for (i = 0; i < arrayType.BYTES_PER_ELEMENT; i += 1) { + bytes.push(r(uint8Array, i)); + } + + if (Boolean(littleEndian) === Boolean(IS_BIG_ENDIAN)) { + bytes.reverse(); + } + + return r(new arrayType(new exports.Uint8Array(bytes).buffer), 0); + }; + } + + DataView.prototype.getUint8 = makeGetter(exports.Uint8Array); + DataView.prototype.getInt8 = makeGetter(exports.Int8Array); + DataView.prototype.getUint16 = makeGetter(exports.Uint16Array); + DataView.prototype.getInt16 = makeGetter(exports.Int16Array); + DataView.prototype.getUint32 = makeGetter(exports.Uint32Array); + DataView.prototype.getInt32 = makeGetter(exports.Int32Array); + DataView.prototype.getFloat32 = makeGetter(exports.Float32Array); + DataView.prototype.getFloat64 = makeGetter(exports.Float64Array); + + function makeSetter(arrayType) { + return function(byteOffset, value, littleEndian) { + + byteOffset = ECMAScript.ToUint32(byteOffset); + if (byteOffset + arrayType.BYTES_PER_ELEMENT > this.byteLength) { + throw new RangeError("Array index out of range"); + } + + // Get bytes + var typeArray = new arrayType([value]), + byteArray = new exports.Uint8Array(typeArray.buffer), + bytes = [], i, byteView; + + for (i = 0; i < arrayType.BYTES_PER_ELEMENT; i += 1) { + bytes.push(r(byteArray, i)); + } + + // Flip if necessary + if (Boolean(littleEndian) === Boolean(IS_BIG_ENDIAN)) { + bytes.reverse(); + } + + // Write them + byteView = new exports.Uint8Array(this.buffer, byteOffset, arrayType.BYTES_PER_ELEMENT); + byteView.set(bytes); + }; + } + + DataView.prototype.setUint8 = makeSetter(exports.Uint8Array); + DataView.prototype.setInt8 = makeSetter(exports.Int8Array); + DataView.prototype.setUint16 = makeSetter(exports.Uint16Array); + DataView.prototype.setInt16 = makeSetter(exports.Int16Array); + DataView.prototype.setUint32 = makeSetter(exports.Uint32Array); + DataView.prototype.setInt32 = makeSetter(exports.Int32Array); + DataView.prototype.setFloat32 = makeSetter(exports.Float32Array); + DataView.prototype.setFloat64 = makeSetter(exports.Float64Array); + + exports.DataView = exports.DataView || DataView; + +}()); diff --git a/node_modules/npm-registry-client/node_modules/concat-stream/node_modules/typedarray/package.json b/node_modules/npm-registry-client/node_modules/concat-stream/node_modules/typedarray/package.json new file mode 100644 index 000000000..b8b59f5c3 --- /dev/null +++ b/node_modules/npm-registry-client/node_modules/concat-stream/node_modules/typedarray/package.json @@ -0,0 +1,79 @@ +{ + "name": "typedarray", + "version": "0.0.6", + "description": "TypedArray polyfill for old browsers", + "main": "index.js", + "devDependencies": { + "tape": "~2.3.2" + }, + "scripts": { + "test": "tape test/*.js test/server/*.js" + }, + "repository": { + "type": "git", + "url": "git://github.com/substack/typedarray.git" + }, + "homepage": "https://github.com/substack/typedarray", + "keywords": [ + "ArrayBuffer", + "DataView", + "Float32Array", + "Float64Array", + "Int8Array", + "Int16Array", + "Int32Array", + "Uint8Array", + "Uint8ClampedArray", + "Uint16Array", + "Uint32Array", + "typed", + "array", + "polyfill" + ], + "author": { + "name": "James Halliday", + "email": "mail@substack.net", + "url": "http://substack.net" + }, + "license": "MIT", + "testling": { + "files": "test/*.js", + "browsers": [ + "ie/6..latest", + "firefox/16..latest", + "firefox/nightly", + "chrome/22..latest", + "chrome/canary", + "opera/12..latest", + "opera/next", + "safari/5.1..latest", + "ipad/6.0..latest", + "iphone/6.0..latest", + "android-browser/4.2..latest" + ] + }, + "bugs": { + "url": "https://github.com/substack/typedarray/issues" + }, + "_id": "typedarray@0.0.6", + "dist": { + "shasum": "867ac74e3864187b1d3d47d996a78ec5c8830777", + "tarball": "http://registry.npmjs.org/typedarray/-/typedarray-0.0.6.tgz" + }, + "_from": "typedarray@>=0.0.5 <0.1.0", + "_npmVersion": "1.4.3", + "_npmUser": { + "name": "substack", + "email": "mail@substack.net" + }, + "maintainers": [ + { + "name": "substack", + "email": "mail@substack.net" + } + ], + "directories": {}, + "_shasum": "867ac74e3864187b1d3d47d996a78ec5c8830777", + "_resolved": "https://registry.npmjs.org/typedarray/-/typedarray-0.0.6.tgz", + "readme": "ERROR: No README data found!" +} diff --git a/node_modules/npm-registry-client/node_modules/concat-stream/node_modules/typedarray/readme.markdown b/node_modules/npm-registry-client/node_modules/concat-stream/node_modules/typedarray/readme.markdown new file mode 100644 index 000000000..d18f6f719 --- /dev/null +++ b/node_modules/npm-registry-client/node_modules/concat-stream/node_modules/typedarray/readme.markdown @@ -0,0 +1,61 @@ +# typedarray + +TypedArray polyfill ripped from [this +module](https://raw.github.com/inexorabletash/polyfill). + +[![build status](https://secure.travis-ci.org/substack/typedarray.png)](http://travis-ci.org/substack/typedarray) + +[![testling badge](https://ci.testling.com/substack/typedarray.png)](https://ci.testling.com/substack/typedarray) + +# example + +``` js +var Uint8Array = require('typedarray').Uint8Array; +var ua = new Uint8Array(5); +ua[1] = 256 + 55; +console.log(ua[1]); +``` + +output: + +``` +55 +``` + +# methods + +``` js +var TA = require('typedarray') +``` + +The `TA` object has the following constructors: + +* TA.ArrayBuffer +* TA.DataView +* TA.Float32Array +* TA.Float64Array +* TA.Int8Array +* TA.Int16Array +* TA.Int32Array +* TA.Uint8Array +* TA.Uint8ClampedArray +* TA.Uint16Array +* TA.Uint32Array + +# install + +With [npm](https://npmjs.org) do: + +``` +npm install typedarray +``` + +To use this module in the browser, compile with +[browserify](http://browserify.org) +or download a UMD build from browserify CDN: + +http://wzrd.in/standalone/typedarray@latest + +# license + +MIT diff --git a/node_modules/npm-registry-client/node_modules/concat-stream/node_modules/typedarray/test/server/undef_globals.js b/node_modules/npm-registry-client/node_modules/concat-stream/node_modules/typedarray/test/server/undef_globals.js new file mode 100644 index 000000000..425950f9f --- /dev/null +++ b/node_modules/npm-registry-client/node_modules/concat-stream/node_modules/typedarray/test/server/undef_globals.js @@ -0,0 +1,19 @@ +var test = require('tape'); +var vm = require('vm'); +var fs = require('fs'); +var src = fs.readFileSync(__dirname + '/../../index.js', 'utf8'); + +test('u8a without globals', function (t) { + var c = { + module: { exports: {} }, + }; + c.exports = c.module.exports; + vm.runInNewContext(src, c); + var TA = c.module.exports; + var ua = new(TA.Uint8Array)(5); + + t.equal(ua.length, 5); + ua[1] = 256 + 55; + t.equal(ua[1], 55); + t.end(); +}); diff --git a/node_modules/npm-registry-client/node_modules/concat-stream/node_modules/typedarray/test/tarray.js b/node_modules/npm-registry-client/node_modules/concat-stream/node_modules/typedarray/test/tarray.js new file mode 100644 index 000000000..df596a34f --- /dev/null +++ b/node_modules/npm-registry-client/node_modules/concat-stream/node_modules/typedarray/test/tarray.js @@ -0,0 +1,10 @@ +var TA = require('../'); +var test = require('tape'); + +test('tiny u8a test', function (t) { + var ua = new(TA.Uint8Array)(5); + t.equal(ua.length, 5); + ua[1] = 256 + 55; + t.equal(ua[1], 55); + t.end(); +}); diff --git a/node_modules/npm-registry-client/node_modules/concat-stream/package.json b/node_modules/npm-registry-client/node_modules/concat-stream/package.json new file mode 100644 index 000000000..d0800ac33 --- /dev/null +++ b/node_modules/npm-registry-client/node_modules/concat-stream/package.json @@ -0,0 +1,76 @@ +{ + "name": "concat-stream", + "version": "1.4.6", + "description": "writable stream that concatenates strings or binary data and calls a callback with the result", + "tags": [ + "stream", + "simple", + "util", + "utility" + ], + "author": { + "name": "Max Ogden", + "email": "max@maxogden.com" + }, + "repository": { + "type": "git", + "url": "http://github.com/maxogden/concat-stream.git" + }, + "bugs": { + "url": "http://github.com/maxogden/concat-stream/issues" + }, + "engines": [ + "node >= 0.8" + ], + "main": "index.js", + "scripts": { + "test": "tape test/*.js test/server/*.js" + }, + "license": "MIT", + "dependencies": { + "inherits": "~2.0.1", + "typedarray": "~0.0.5", + "readable-stream": "~1.1.9" + }, + "devDependencies": { + "tape": "~2.3.2" + }, + "testling": { + "files": "test/*.js", + "browsers": [ + "ie/8..latest", + "firefox/17..latest", + "firefox/nightly", + "chrome/22..latest", + "chrome/canary", + "opera/12..latest", + "opera/next", + "safari/5.1..latest", + "ipad/6.0..latest", + "iphone/6.0..latest", + "android-browser/4.2..latest" + ] + }, + "homepage": "https://github.com/maxogden/concat-stream", + "_id": "concat-stream@1.4.6", + "_shasum": "8cb736a556a32f020f1ddc82fa3448381c5e5cce", + "_from": "concat-stream@>=1.4.6 <2.0.0", + "_npmVersion": "1.4.10", + "_npmUser": { + "name": "maxogden", + "email": "max@maxogden.com" + }, + "maintainers": [ + { + "name": "maxogden", + "email": "max@maxogden.com" + } + ], + "dist": { + "shasum": "8cb736a556a32f020f1ddc82fa3448381c5e5cce", + "tarball": "http://registry.npmjs.org/concat-stream/-/concat-stream-1.4.6.tgz" + }, + "directories": {}, + "_resolved": "https://registry.npmjs.org/concat-stream/-/concat-stream-1.4.6.tgz", + "readme": "ERROR: No README data found!" +} diff --git a/node_modules/npm-registry-client/node_modules/concat-stream/readme.md b/node_modules/npm-registry-client/node_modules/concat-stream/readme.md new file mode 100644 index 000000000..dfd441b5f --- /dev/null +++ b/node_modules/npm-registry-client/node_modules/concat-stream/readme.md @@ -0,0 +1,72 @@ +# concat-stream + +Writable stream that concatenates strings or binary data and calls a callback with the result. Not a transform stream -- more of a stream sink. + +[![NPM](https://nodei.co/npm/concat-stream.png)](https://nodei.co/npm/concat-stream/) + +[![browser support](https://ci.testling.com/maxogden/concat-stream.png)](https://ci.testling.com/maxogden/concat-stream) + +### examples + +#### Buffers + +```js +var concat = require('concat-stream') +var fs = require('fs') + +var read = fs.createReadStream('readme.md') +var write = concat(function(data) { + // data is all of readme.md as a Buffer +}) + +read.pipe(write) +``` + +#### Arrays + +```js +var write = concat(function(data) {}) +write.write([1,2,3]) +write.write([4,5,6]) +write.end() +// data will be [1,2,3,4,5,6] in the above callback +``` + +#### Uint8Arrays + +```js +var write = concat(function(data) {}) +var a = new Uint8Array(3) +a[0] = 97; a[1] = 98; a[2] = 99 +write.write(a) +write.write('!') +write.end(Buffer('!!1')) +``` + +See `test/` for more examples + +# methods + +```js +var concat = require('concat-stream') +``` + +## var writable = concat(opts={}, cb) + +Return a `writable` stream that will fire `cb(data)` with all of the data that +was written to the stream. Data can be written to `writable` as strings, +Buffers, arrays of byte integers, and Uint8Arrays. + +By default `concat-stream` will give you back the same data type as the type of the first buffer written to the stream. Use `opts.encoding` to set what format `data` should be returned as, e.g. if you if you don't want to rely on the built-in type checking or for some other reason. + +* `string` - get a string +* `buffer` - get back a Buffer +* `array` - get an array of byte integers +* `uint8array`, `u8`, `uint8` - get back a Uint8Array +* `object`, get back an array of Objects + +If you don't specify an encoding, and the types can't be inferred (e.g. you write things that aren't int he list above), it will try to convert concat them into a `Buffer`. + +# license + +MIT LICENSE diff --git a/node_modules/npm-registry-client/node_modules/concat-stream/test/array.js b/node_modules/npm-registry-client/node_modules/concat-stream/test/array.js new file mode 100644 index 000000000..86e7dd43b --- /dev/null +++ b/node_modules/npm-registry-client/node_modules/concat-stream/test/array.js @@ -0,0 +1,12 @@ +var concat = require('../') +var test = require('tape') + +test('array stream', function (t) { + t.plan(1) + var arrays = concat({ encoding: 'array' }, function(out) { + t.deepEqual(out, [1,2,3,4,5,6]) + }) + arrays.write([1,2,3]) + arrays.write([4,5,6]) + arrays.end() +}) diff --git a/node_modules/npm-registry-client/node_modules/concat-stream/test/buffer.js b/node_modules/npm-registry-client/node_modules/concat-stream/test/buffer.js new file mode 100644 index 000000000..d28f5f9c1 --- /dev/null +++ b/node_modules/npm-registry-client/node_modules/concat-stream/test/buffer.js @@ -0,0 +1,31 @@ +var concat = require('../') +var test = require('tape') +var TA = require('typedarray') +var U8 = typeof Uint8Array !== 'undefined' ? Uint8Array : TA.Uint8Array + +test('buffer stream', function (t) { + t.plan(2) + var buffers = concat(function(out) { + t.ok(Buffer.isBuffer(out)) + t.equal(out.toString('utf8'), 'pizza Array is not a stringy cat') + }) + buffers.write(new Buffer('pizza Array is not a ', 'utf8')) + buffers.write(new Buffer('stringy cat')) + buffers.end() +}) + +test('buffer mixed writes', function (t) { + t.plan(2) + var buffers = concat(function(out) { + t.ok(Buffer.isBuffer(out)) + t.equal(out.toString('utf8'), 'pizza Array is not a stringy cat555') + }) + buffers.write(new Buffer('pizza')) + buffers.write(' Array is not a ') + buffers.write([ 115, 116, 114, 105, 110, 103, 121 ]) + var u8 = new U8(4) + u8[0] = 32; u8[1] = 99; u8[2] = 97; u8[3] = 116 + buffers.write(u8) + buffers.write(555) + buffers.end() +}) diff --git a/node_modules/npm-registry-client/node_modules/concat-stream/test/infer.js b/node_modules/npm-registry-client/node_modules/concat-stream/test/infer.js new file mode 100644 index 000000000..91ab933f4 --- /dev/null +++ b/node_modules/npm-registry-client/node_modules/concat-stream/test/infer.js @@ -0,0 +1,15 @@ +var concat = require('../') +var test = require('tape') + +test('type inference works as expected', function(t) { + var stream = concat() + t.equal(stream.inferEncoding(['hello']), 'array', 'array') + t.equal(stream.inferEncoding(new Buffer('hello')), 'buffer', 'buffer') + t.equal(stream.inferEncoding(undefined), 'buffer', 'buffer') + t.equal(stream.inferEncoding(new Uint8Array(1)), 'uint8array', 'uint8array') + t.equal(stream.inferEncoding('hello'), 'string', 'string') + t.equal(stream.inferEncoding(''), 'string', 'string') + t.equal(stream.inferEncoding({hello: "world"}), 'object', 'object') + t.equal(stream.inferEncoding(1), 'buffer', 'buffer') + t.end() +}) diff --git a/node_modules/npm-registry-client/node_modules/concat-stream/test/nothing.js b/node_modules/npm-registry-client/node_modules/concat-stream/test/nothing.js new file mode 100644 index 000000000..6ac604965 --- /dev/null +++ b/node_modules/npm-registry-client/node_modules/concat-stream/test/nothing.js @@ -0,0 +1,25 @@ +var concat = require('../') +var test = require('tape') + +test('no callback stream', function (t) { + var stream = concat() + stream.write('space') + stream.end(' cats') + t.end() +}) + +test('no encoding set, no data', function (t) { + var stream = concat(function(data) { + t.deepEqual(data, []) + t.end() + }) + stream.end() +}) + +test('encoding set to string, no data', function (t) { + var stream = concat({ encoding: 'string' }, function(data) { + t.deepEqual(data, '') + t.end() + }) + stream.end() +}) diff --git a/node_modules/npm-registry-client/node_modules/concat-stream/test/objects.js b/node_modules/npm-registry-client/node_modules/concat-stream/test/objects.js new file mode 100644 index 000000000..ad921ed25 --- /dev/null +++ b/node_modules/npm-registry-client/node_modules/concat-stream/test/objects.js @@ -0,0 +1,29 @@ +var concat = require('../') +var test = require('tape') + +test('writing objects', function (t) { + var stream = concat({encoding: "objects"}, concatted) + function concatted(objs) { + t.equal(objs.length, 2) + t.deepEqual(objs[0], {"foo": "bar"}) + t.deepEqual(objs[1], {"baz": "taco"}) + } + stream.write({"foo": "bar"}) + stream.write({"baz": "taco"}) + stream.end() + t.end() +}) + + +test('switch to objects encoding if no encoding specified and objects are written', function (t) { + var stream = concat(concatted) + function concatted(objs) { + t.equal(objs.length, 2) + t.deepEqual(objs[0], {"foo": "bar"}) + t.deepEqual(objs[1], {"baz": "taco"}) + } + stream.write({"foo": "bar"}) + stream.write({"baz": "taco"}) + stream.end() + t.end() +}) diff --git a/node_modules/npm-registry-client/node_modules/concat-stream/test/server/ls.js b/node_modules/npm-registry-client/node_modules/concat-stream/test/server/ls.js new file mode 100644 index 000000000..3258d8ddc --- /dev/null +++ b/node_modules/npm-registry-client/node_modules/concat-stream/test/server/ls.js @@ -0,0 +1,16 @@ +var concat = require('../../') +var spawn = require('child_process').spawn +var exec = require('child_process').exec +var test = require('tape') + +test('ls command', function (t) { + t.plan(1) + var cmd = spawn('ls', [ __dirname ]) + cmd.stdout.pipe( + concat(function(out) { + exec('ls ' + __dirname, function (err, body) { + t.equal(out.toString('utf8'), body.toString('utf8')) + }) + }) + ) +}) diff --git a/node_modules/npm-registry-client/node_modules/concat-stream/test/string.js b/node_modules/npm-registry-client/node_modules/concat-stream/test/string.js new file mode 100644 index 000000000..218c52206 --- /dev/null +++ b/node_modules/npm-registry-client/node_modules/concat-stream/test/string.js @@ -0,0 +1,76 @@ +var concat = require('../') +var test = require('tape') +var TA = require('typedarray') +var U8 = typeof Uint8Array !== 'undefined' ? Uint8Array : TA.Uint8Array + +test('string -> buffer stream', function (t) { + t.plan(2) + var strings = concat({ encoding: 'buffer'}, function(out) { + t.ok(Buffer.isBuffer(out)) + t.equal(out.toString('utf8'), 'nacho dogs') + }) + strings.write("nacho ") + strings.write("dogs") + strings.end() +}) + +test('string stream', function (t) { + t.plan(2) + var strings = concat({ encoding: 'string' }, function(out) { + t.equal(typeof out, 'string') + t.equal(out, 'nacho dogs') + }) + strings.write("nacho ") + strings.write("dogs") + strings.end() +}) + +test('end chunk', function (t) { + t.plan(1) + var endchunk = concat({ encoding: 'string' }, function(out) { + t.equal(out, 'this is the end') + }) + endchunk.write("this ") + endchunk.write("is the ") + endchunk.end("end") +}) + +test('string from mixed write encodings', function (t) { + t.plan(2) + var strings = concat({ encoding: 'string' }, function(out) { + t.equal(typeof out, 'string') + t.equal(out, 'nacho dogs') + }) + strings.write('na') + strings.write(Buffer('cho')) + strings.write([ 32, 100 ]) + var u8 = new U8(3) + u8[0] = 111; u8[1] = 103; u8[2] = 115; + strings.end(u8) +}) + +test('string from buffers with multibyte characters', function (t) { + t.plan(2) + var strings = concat({ encoding: 'string' }, function(out) { + t.equal(typeof out, 'string') + t.equal(out, '☃☃☃☃☃☃☃☃') + }) + var snowman = new Buffer('☃') + for (var i = 0; i < 8; i++) { + strings.write(snowman.slice(0, 1)) + strings.write(snowman.slice(1)) + } + strings.end() +}) + +test('string infer encoding with empty string chunk', function (t) { + t.plan(2) + var strings = concat(function(out) { + t.equal(typeof out, 'string') + t.equal(out, 'nacho dogs') + }) + strings.write("") + strings.write("nacho ") + strings.write("dogs") + strings.end() +}) diff --git a/node_modules/npm-registry-client/node_modules/concat-stream/test/typedarray.js b/node_modules/npm-registry-client/node_modules/concat-stream/test/typedarray.js new file mode 100644 index 000000000..ee0711082 --- /dev/null +++ b/node_modules/npm-registry-client/node_modules/concat-stream/test/typedarray.js @@ -0,0 +1,33 @@ +var concat = require('../') +var test = require('tape') +var TA = require('typedarray') +var U8 = typeof Uint8Array !== 'undefined' ? Uint8Array : TA.Uint8Array + +test('typed array stream', function (t) { + t.plan(2) + var a = new U8(5) + a[0] = 97; a[1] = 98; a[2] = 99; a[3] = 100; a[4] = 101; + var b = new U8(3) + b[0] = 32; b[1] = 102; b[2] = 103; + var c = new U8(4) + c[0] = 32; c[1] = 120; c[2] = 121; c[3] = 122; + + var arrays = concat({ encoding: 'Uint8Array' }, function(out) { + t.equal(typeof out.subarray, 'function') + t.deepEqual(Buffer(out).toString('utf8'), 'abcde fg xyz') + }) + arrays.write(a) + arrays.write(b) + arrays.end(c) +}) + +test('typed array from strings, buffers, and arrays', function (t) { + t.plan(2) + var arrays = concat({ encoding: 'Uint8Array' }, function(out) { + t.equal(typeof out.subarray, 'function') + t.deepEqual(Buffer(out).toString('utf8'), 'abcde fg xyz') + }) + arrays.write('abcde') + arrays.write(Buffer(' fg ')) + arrays.end([ 120, 121, 122 ]) +}) diff --git a/node_modules/npm-registry-client/package.json b/node_modules/npm-registry-client/package.json index f9c447ee2..bda29cb8b 100644 --- a/node_modules/npm-registry-client/package.json +++ b/node_modules/npm-registry-client/package.json @@ -6,7 +6,7 @@ }, "name": "npm-registry-client", "description": "Client for the npm registry", - "version": "3.2.4", + "version": "4.0.0", "repository": { "url": "git://github.com/isaacs/npm-registry-client" }, @@ -16,12 +16,12 @@ }, "dependencies": { "chownr": "0", + "concat-stream": "^1.4.6", "graceful-fs": "^3.0.0", "mkdirp": "^0.5.0", "normalize-package-data": "~1.0.1", - "npm-cache-filename": "^1.0.0", "once": "^1.3.0", - "request": "2 >=2.25.0", + "request": "2 >=2.45.0", "retry": "^0.6.1", "rimraf": "2", "semver": "2 >=2.2.1 || 3.x || 4", @@ -29,22 +29,20 @@ "npmlog": "" }, "devDependencies": { - "concat-stream": "^1.4.6", - "npmconf": "^2.1.0", "tap": "" }, "optionalDependencies": { "npmlog": "" }, "license": "ISC", - "readme": "# npm-registry-client\n\nThe code that npm uses to talk to the registry.\n\nIt handles all the caching and HTTP calls.\n\n## Usage\n\n```javascript\nvar RegClient = require('npm-registry-client')\nvar client = new RegClient(config)\nvar uri = \"npm://registry.npmjs.org/npm\"\nvar options = {timeout: 1000}\n\nclient.get(uri, options, function (error, data, raw, res) {\n // error is an error if there was a problem.\n // data is the parsed data object\n // raw is the json string\n // res is the response from couch\n})\n```\n\n# Registry URLs\n\nThe registry calls take either a full URL pointing to a resource in the\nregistry, or a base URL for the registry as a whole (for the base URL, any path\nwill be ignored). In addition to `http` and `https`, `npm` URLs are allowed.\n`npm` URLs are `https` URLs with the additional restrictions that they will\nalways include authorization credentials, and the response is always registry\nmetadata (and not tarballs or other attachments).\n\n# Configuration\n\nThis program is designed to work with\n[npmconf](https://npmjs.org/package/npmconf), but you can also pass in\na plain-jane object with the appropriate configs, and it'll shim it\nfor you. Any configuration thingie that has get/set/del methods will\nalso be accepted.\n\n* `cache` **Required** {String} Path to the cache folder\n* `always-auth` {Boolean} Auth even for GET requests.\n* `auth` {String} A base64-encoded `username:password`\n* `email` {String} User's email address\n* `tag` {String} The default tag to use when publishing new packages.\n Default = `\"latest\"`\n* `ca` {String} Cerficate signing authority certificates to trust.\n* `cert` {String} Client certificate (PEM encoded). Enable access\n to servers that require client certificates\n* `key` {String} Private key (PEM encoded) for client certificate 'cert'\n* `strict-ssl` {Boolean} Whether or not to be strict with SSL\n certificates. Default = `true`\n* `user-agent` {String} User agent header to send. Default =\n `\"node/{process.version} {process.platform} {process.arch}\"`\n* `log` {Object} The logger to use. Defaults to `require(\"npmlog\")` if\n that works, otherwise logs are disabled.\n* `fetch-retries` {Number} Number of times to retry on GET failures.\n Default=2\n* `fetch-retry-factor` {Number} `factor` setting for `node-retry`. Default=10\n* `fetch-retry-mintimeout` {Number} `minTimeout` setting for `node-retry`.\n Default=10000 (10 seconds)\n* `fetch-retry-maxtimeout` {Number} `maxTimeout` setting for `node-retry`.\n Default=60000 (60 seconds)\n* `proxy` {URL} The url to proxy requests through.\n* `https-proxy` {URL} The url to proxy https requests through.\n Defaults to be the same as `proxy` if unset.\n* `_auth` {String} The base64-encoded authorization header.\n* `username` `_password` {String} Username/password to use to generate\n `_auth` if not supplied.\n* `_token` {Object} A token for use with\n [couch-login](https://npmjs.org/package/couch-login)\n\n# client.request(method, uri, options, cb)\n\n* `method` {String} HTTP method\n* `uri` {String} URI pointing to the resource to request\n* `options` {Object} Object containing optional per-request properties.\n * `what` {Stream | Buffer | String | Object} The request body. Objects\n that are not Buffers or Streams are encoded as JSON.\n * `etag` {String} The cached ETag\n * `follow` {Boolean} Follow 302/301 responses (defaults to true)\n* `cb` {Function}\n * `error` {Error | null}\n * `data` {Object} the parsed data object\n * `raw` {String} the json\n * `res` {Response Object} response from couch\n\nMake a request to the registry. All the other methods are wrappers around\n`request`.\n\n# client.adduser(base, username, password, email, cb)\n\n* `base` {String} Base registry URL\n* `username` {String}\n* `password` {String}\n* `email` {String}\n* `cb` {Function}\n\nAdd a user account to the registry, or verify the credentials.\n\n# client.deprecate(uri, version, message, cb)\n\n* `uri` {String} Full registry URI for the deprecated package\n* `version` {String} Semver version range\n* `message` {String} The message to use as a deprecation warning\n* `cb` {Function}\n\nDeprecate a version of a package in the registry.\n\n# client.bugs(uri, cb)\n\n* `uri` {String} Full registry URI for the package\n* `cb` {Function}\n\nGet the url for bugs of a package\n\n# client.get(uri, options, cb)\n\n* `uri` {String} The complete registry URI to fetch\n* `options` {Object} Object containing optional per-request properties.\n * `timeout` {Number} Duration before the request times out.\n * `follow` {Boolean} Follow 302/301 responses (defaults to true)\n * `staleOk` {Boolean} If there's cached data available, then return that\n to the callback quickly, and update the cache the background.\n\nFetches data from the registry via a GET request, saving it in the cache folder\nwith the ETag.\n\n# client.publish(uri, data, tarball, cb)\n\n* `uri` {String} The registry URI to publish to\n* `data` {Object} Package data\n* `tarball` {String | Stream} Filename or stream of the package tarball\n* `cb` {Function}\n\nPublish a package to the registry.\n\nNote that this does not create the tarball from a folder. However, it can\naccept a gzipped tar stream or a filename to a tarball.\n\n# client.star(uri, starred, cb)\n\n* `uri` {String} The complete registry URI to star\n* `starred` {Boolean} True to star the package, false to unstar it.\n* `cb` {Function}\n\nStar or unstar a package.\n\nNote that the user does not have to be the package owner to star or unstar a\npackage, though other writes do require that the user be the package owner.\n\n# client.stars(base, username, cb)\n\n* `base` {String} The base URL for the registry\n* `username` {String} Name of user to fetch starred packages for.\n* `cb` {Function}\n\nView your own or another user's starred packages.\n\n# client.tag(uri, version, tag, cb)\n\n* `uri` {String} The complete registry URI to tag\n* `version` {String} Version to tag\n* `tag` {String} Tag name to apply\n* `cb` {Function}\n\nMark a version in the `dist-tags` hash, so that `pkg@tag` will fetch the\nspecified version.\n\n# client.unpublish(uri, [ver], cb)\n\n* `uri` {String} The complete registry URI to unpublish\n* `ver` {String} version to unpublish. Leave blank to unpublish all\n versions.\n* `cb` {Function}\n\nRemove a version of a package (or all versions) from the registry. When the\nlast version us unpublished, the entire document is removed from the database.\n\n# client.upload(uri, file, [etag], [nofollow], cb)\n\n* `uri` {String} The complete registry URI to upload to\n* `file` {String | Stream} Either the filename or a readable stream\n* `etag` {String} Cache ETag\n* `nofollow` {Boolean} Do not follow 301/302 responses\n* `cb` {Function}\n\nUpload an attachment. Mostly used by `client.publish()`.\n", + "readme": "# npm-registry-client\n\nThe code that npm uses to talk to the registry.\n\nIt handles all the caching and HTTP calls.\n\n## Usage\n\n```javascript\nvar RegClient = require('npm-registry-client')\nvar client = new RegClient(config)\nvar uri = \"npm://registry.npmjs.org/npm\"\nvar params = {timeout: 1000}\n\nclient.get(uri, params, function (error, data, raw, res) {\n // error is an error if there was a problem.\n // data is the parsed data object\n // raw is the json string\n // res is the response from couch\n})\n```\n\n# Registry URLs\n\nThe registry calls take either a full URL pointing to a resource in the\nregistry, or a base URL for the registry as a whole (including the registry\npath – but be sure to terminate the path with `/`). `http` and `https` URLs are\nthe only ones supported.\n\n## Using the client\n\nEvery call to the client follows the same pattern:\n\n* `uri` {String} The *fully-qualified* URI of the registry API method being\n invoked.\n* `params` {Object} Per-request parameters.\n* `callback` {Function} Callback to be invoked when the call is complete.\n\n### Credentials\n\nMany requests to the registry can by authenticated, and require credentials\nfor authorization. These credentials always look the same:\n\n* `username` {String}\n* `password` {String}\n* `email` {String}\n* `alwaysAuth` {Boolean} Whether calls to the target registry are always\n authed.\n\n**or**\n\n* `token` {String}\n* `alwaysAuth` {Boolean} Whether calls to the target registry are always\n authed.\n\n## API\n\n### client.adduser(uri, params, cb)\n\n* `uri` {String} Base registry URL.\n* `params` {Object} Object containing per-request properties.\n * `auth` {Credentials}\n* `cb` {Function}\n * `error` {Error | null}\n * `data` {Object} the parsed data object\n * `raw` {String} the json\n * `res` {Response Object} response from couch\n\nAdd a user account to the registry, or verify the credentials.\n\n### client.deprecate(uri, params, cb)\n\n* `uri` {String} Full registry URI for the deprecated package.\n* `params` {Object} Object containing per-request properties.\n * `version` {String} Semver version range.\n * `message` {String} The message to use as a deprecation warning.\n * `auth` {Credentials}\n* `cb` {Function}\n\nDeprecate a version of a package in the registry.\n\n### client.get(uri, params, cb)\n\n* `uri` {String} The complete registry URI to fetch\n* `params` {Object} Object containing per-request properties.\n * `timeout` {Number} Duration before the request times out. Optional\n (default: never).\n * `follow` {Boolean} Follow 302/301 responses. Optional (default: true).\n * `staleOk` {Boolean} If there's cached data available, then return that to\n the callback quickly, and update the cache the background. Optional\n (default: false).\n * `auth` {Credentials} Optional.\n* `cb` {Function}\n\nFetches data from the registry via a GET request, saving it in the cache folder\nwith the ETag.\n\n### client.publish(uri, params, cb)\n\n* `uri` {String} The registry URI for the package to publish.\n* `params` {Object} Object containing per-request properties.\n * `metadata` {Object} Package metadata.\n * `body` {Stream} Stream of the package body / tarball.\n * `auth` {Credentials}\n* `cb` {Function}\n\nPublish a package to the registry.\n\nNote that this does not create the tarball from a folder.\n\n### client.star(uri, params, cb)\n\n* `uri` {String} The complete registry URI for the package to star.\n* `params` {Object} Object containing per-request properties.\n * `starred` {Boolean} True to star the package, false to unstar it. Optional\n (default: false).\n * `auth` {Credentials}\n* `cb` {Function}\n\nStar or unstar a package.\n\nNote that the user does not have to be the package owner to star or unstar a\npackage, though other writes do require that the user be the package owner.\n\n### client.stars(uri, params, cb)\n\n* `uri` {String} The base URL for the registry.\n* `params` {Object} Object containing per-request properties.\n * `username` {String} Name of user to fetch starred packages for. Optional\n (default: user in `auth`).\n * `auth` {Credentials} Optional (required if `username` is omitted).\n* `cb` {Function}\n\nView your own or another user's starred packages.\n\n### client.tag(uri, params, cb)\n\n* `uri` {String} The complete registry URI to tag\n* `params` {Object} Object containing per-request properties.\n * `version` {String} Version to tag.\n * `tag` {String} Tag name to apply.\n * `auth` {Credentials}\n* `cb` {Function}\n\nMark a version in the `dist-tags` hash, so that `pkg@tag` will fetch the\nspecified version.\n\n### client.unpublish(uri, params, cb)\n\n* `uri` {String} The complete registry URI of the package to unpublish.\n* `params` {Object} Object containing per-request properties.\n * `version` {String} version to unpublish. Optional – omit to unpublish all\n versions.\n * `auth` {Credentials}\n* `cb` {Function}\n\nRemove a version of a package (or all versions) from the registry. When the\nlast version us unpublished, the entire document is removed from the database.\n\n### client.whoami(uri, params, cb)\n\n* `uri` {String} The base registry for the URI.\n* `params` {Object} Object containing per-request properties.\n * `auth` {Credentials}\n* `cb` {Function}\n\nSimple call to see who the registry thinks you are. Especially useful with\ntoken-based auth.\n\n\n## PLUMBING\n\nThe below are primarily intended for use by the rest of the API, or by the npm\ncaching logic directly.\n\n### client.request(uri, params, cb)\n\n* `uri` {String} URI pointing to the resource to request.\n* `params` {Object} Object containing per-request properties.\n * `method` {String} HTTP method. Optional (default: \"GET\").\n * `body` {Stream | Buffer | String | Object} The request body. Objects\n that are not Buffers or Streams are encoded as JSON. Optional – body\n only used for write operations.\n * `etag` {String} The cached ETag. Optional.\n * `follow` {Boolean} Follow 302/301 responses. Optional (default: true).\n * `auth` {Credentials} Optional.\n* `cb` {Function}\n * `error` {Error | null}\n * `data` {Object} the parsed data object\n * `raw` {String} the json\n * `res` {Response Object} response from couch\n\nMake a generic request to the registry. All the other methods are wrappers\naround `client.request`.\n\n### client.fetch(uri, params, cb)\n\n* `uri` {String} The complete registry URI to upload to\n* `params` {Object} Object containing per-request properties.\n * `headers` {Stream} HTTP headers to be included with the request. Optional.\n * `auth` {Credentials} Optional.\n* `cb` {Function}\n\nFetch a package from a URL, with auth set appropriately if included. Used to\ncache remote tarballs as well as request package tarballs from the registry.\n\n# Configuration\n\nThe client uses its own configuration, which is just passed in as a simple\nnested object. The following are the supported values (with their defaults, if\nany):\n\n* `proxy.http` {URL} The URL to proxy HTTP requests through.\n* `proxy.https` {URL} The URL to proxy HTTPS requests through. Defaults to be\n the same as `proxy.http` if unset.\n* `proxy.localAddress` {IP} The local address to use on multi-homed systems.\n* `ssl.ca` {String} Cerficate signing authority certificates to trust.\n* `ssl.certificate` {String} Client certificate (PEM encoded). Enable access\n to servers that require client certificates.\n* `ssl.key` {String} Private key (PEM encoded) for client certificate.\n* `ssl.strict` {Boolean} Whether or not to be strict with SSL certificates.\n Default = `true`\n* `retry.count` {Number} Number of times to retry on GET failures. Default = 2.\n* `retry.factor` {Number} `factor` setting for `node-retry`. Default = 10.\n* `retry.minTimeout` {Number} `minTimeout` setting for `node-retry`.\n Default = 10000 (10 seconds)\n* `retry.maxTimeout` {Number} `maxTimeout` setting for `node-retry`.\n Default = 60000 (60 seconds)\n* `userAgent` {String} User agent header to send. Default =\n `\"node/{process.version}\"`\n* `log` {Object} The logger to use. Defaults to `require(\"npmlog\")` if\n that works, otherwise logs are disabled.\n* `defaultTag` {String} The default tag to use when publishing new packages.\n Default = `\"latest\"`\n* `couchToken` {Object} A token for use with\n [couch-login](https://npmjs.org/package/couch-login).\n* `sessionToken` {string} A random identifier for this set of client requests.\n Default = 8 random hexadecimal bytes.\n", "readmeFilename": "README.md", - "gitHead": "ddafd4913bdca30a1f9111660767f71653604b57", + "gitHead": "e8fe4786d4bc7306020b3d76fd7234a182f14b70", "bugs": { "url": "https://github.com/isaacs/npm-registry-client/issues" }, "homepage": "https://github.com/isaacs/npm-registry-client", - "_id": "npm-registry-client@3.2.4", - "_shasum": "8659b3449e1c9a9f8181dad142cadb048bfe521f", - "_from": "npm-registry-client@>=3.2.4 <3.3.0" + "_id": "npm-registry-client@4.0.0", + "_shasum": "4ad3a6046cb3985626244ebcf2f212b931155787", + "_from": "npm-registry-client@>=4.0.0 <4.1.0" } diff --git a/node_modules/npm-registry-client/test/adduser-new.js b/node_modules/npm-registry-client/test/adduser-new.js index 57dca0b52..3789fc954 100644 --- a/node_modules/npm-registry-client/test/adduser-new.js +++ b/node_modules/npm-registry-client/test/adduser-new.js @@ -5,20 +5,27 @@ var common = require("./lib/common.js") var client = common.freshClient() var password = "%1234@asdf%" -, username = "username" -, email = "i@izs.me" -, userdata = { - name: username, - email: email, - _id: "org.couchdb.user:username", - type: "user", - roles: [], - date: "2012-06-07T04:11:21.591Z" } -, SD = require("string_decoder").StringDecoder -, decoder = new SD() + , username = "username" + , email = "i@izs.me" + , userdata = { + name: username, + email: email, + _id: "org.couchdb.user:username", + type: "user", + roles: [], + date: "2012-06-07T04:11:21.591Z" } + , SD = require("string_decoder").StringDecoder + , decoder = new SD() tap.test("create new user account", function (t) { - server.expect("/-/user/org.couchdb.user:username", function (req, res) { + var auth = { + username : username, + password : password, + email : email + } + var params = { auth : auth } + + server.expect("/registry/_design/app/_rewrite/-/user/org.couchdb.user:username", function (req, res) { t.equal(req.method, "PUT") var b = "" req.on("data", function (d) { @@ -32,13 +39,17 @@ tap.test("create new user account", function (t) { t.deepEqual(o, userdata) res.statusCode = 201 - res.json({created:true}) + res.json(auth) }) }) - client.adduser("http://localhost:1337/", username, password, email, function (er, data) { - if (er) throw er - t.deepEqual(data, { created: true }) - t.end() - }) + client.adduser( + "http://localhost:1337/registry/_design/app/_rewrite", + params, + function (er, data) { + if (er) throw er + t.deepEqual(data, auth, "received expected auth data") + t.end() + } + ) }) diff --git a/node_modules/npm-registry-client/test/adduser-update.js b/node_modules/npm-registry-client/test/adduser-update.js index 2c5ccde6e..6732f7ba0 100644 --- a/node_modules/npm-registry-client/test/adduser-update.js +++ b/node_modules/npm-registry-client/test/adduser-update.js @@ -19,6 +19,13 @@ var password = "%1234@asdf%" tap.test("update a user acct", function (t) { + var auth = { + username : username, + password : password, + email : email + } + var params = { auth : auth } + server.expect("PUT", "/-/user/org.couchdb.user:username", function (req, res) { t.equal(req.method, "PUT") res.statusCode = 409 @@ -45,13 +52,17 @@ tap.test("update a user acct", function (t) { t.deepEqual(o, userdata) res.statusCode = 201 - res.json({created:true}) + res.json(auth) }) }) - client.adduser("http://localhost:1337/", username, password, email, function (er, data) { - if (er) throw er - t.deepEqual(data, { created: true }) - t.end() - }) + client.adduser( + "http://localhost:1337/", + params, + function (er, data) { + if (er) throw er + t.deepEqual(data, auth, "got expected auth data") + t.end() + } + ) }) diff --git a/node_modules/npm-registry-client/test/adduser.js b/node_modules/npm-registry-client/test/adduser.js new file mode 100644 index 000000000..fccb037af --- /dev/null +++ b/node_modules/npm-registry-client/test/adduser.js @@ -0,0 +1,162 @@ +var test = require("tap").test + +var server = require("./lib/server.js") +var common = require("./lib/common.js") +var client = common.freshClient() + +function nop () {} + +var URI = "https://npm.registry:8043/rewrite" +var USERNAME = "username" +var PASSWORD = "password" +var EMAIL = "n@p.m" +var AUTH = { + auth : { + username : USERNAME, + password : PASSWORD, + email : EMAIL + } +} + +test("adduser call contract", function (t) { + t.throws(function () { + client.adduser(undefined, AUTH, nop) + }, "requires a URI") + + t.throws(function () { + client.adduser([], AUTH, nop) + }, "requires URI to be a string") + + t.throws(function () { + client.adduser(URI, undefined, nop) + }, "requires params object") + + t.throws(function () { + client.adduser(URI, "", nop) + }, "params must be object") + + t.throws(function () { + client.adduser(URI, AUTH, undefined) + }, "requires callback") + + t.throws(function () { + client.adduser(URI, AUTH, "callback") + }, "callback must be function") + + t.throws( + function () { + var params = { + auth : { + password : PASSWORD, + email : EMAIL + } + } + client.adduser(URI, params, nop) + }, + { name : "AssertionError", message : "must include username in auth" }, + "auth must include username" + ) + + t.throws( + function () { + var params = { + auth : { + username : USERNAME, + email : EMAIL + } + } + client.adduser(URI, params, nop) + }, + { name : "AssertionError", message : "must include password in auth" }, + "auth must include password" + ) + + t.throws( + function () { + var params = { + auth : { + username : USERNAME, + password : PASSWORD + } + } + client.adduser(URI, params, nop) + }, + { name : "AssertionError", message : "must include email in auth" }, + "auth must include email" + ) + + t.test("username missing", function (t) { + var params = { + auth : { + username : "", + password : PASSWORD, + email : EMAIL + } + } + client.adduser(URI, params, function (err) { + t.equal(err && err.message, "No username supplied.", "username must not be empty") + t.end() + }) + }) + + t.test("password missing", function (t) { + var params = { + auth : { + username : USERNAME, + password : "", + email : EMAIL + } + } + client.adduser(URI, params, function (err) { + t.equal( + err && err.message, + "No password supplied.", + "password must not be empty" + ) + t.end() + }) + }) + + t.test("email missing", function (t) { + var params = { + auth : { + username : USERNAME, + password : PASSWORD, + email : "" + } + } + client.adduser(URI, params, function (err) { + t.equal( + err && err.message, + "No email address supplied.", + "email must not be empty" + ) + t.end() + }) + }) + + t.test("email malformed", function (t) { + var params = { + auth : { + username : USERNAME, + password : PASSWORD, + email : "lolbutts" + } + } + client.adduser(URI, params, function (err) { + t.equal( + err && err.message, + "Please use a real email address.", + "email must look like email" + ) + t.end() + }) + }) + + t.end() +}) + +test("cleanup", function (t) { + server.close() + t.end() +}) diff --git a/node_modules/npm-registry-client/test/bugs.js b/node_modules/npm-registry-client/test/bugs.js deleted file mode 100644 index 799445295..000000000 --- a/node_modules/npm-registry-client/test/bugs.js +++ /dev/null @@ -1,28 +0,0 @@ -var tap = require("tap") - -var server = require("./lib/server.js") -var common = require("./lib/common.js") -var client = common.freshClient() - -tap.test("get the URL for the bugs page on a package", function (t) { - server.expect("GET", "/sample/latest", function (req, res) { - t.equal(req.method, "GET") - - res.json({ - bugs : { - url : "http://github.com/example/sample/issues", - email : "sample@example.com" - } - }) - }) - - client.bugs("http://localhost:1337/sample", function (error, info) { - t.ifError(error) - - t.ok(info.url, "got the URL") - t.ok(info.email, "got the email address") - - t.end() - }) -}) - diff --git a/node_modules/npm-registry-client/test/config-defaults.js b/node_modules/npm-registry-client/test/config-defaults.js new file mode 100644 index 000000000..7c0852d1e --- /dev/null +++ b/node_modules/npm-registry-client/test/config-defaults.js @@ -0,0 +1,42 @@ +var test = require("tap").test + +require("./lib/server.js").close() +var common = require("./lib/common.js") + +test("config defaults", function (t) { + var client = common.freshClient() + + var proxy = client.config.proxy + t.notOk(proxy.http, "no default value for HTTP proxy") + t.notOk(proxy.https, "no default value for HTTPS proxy") + t.notOk(proxy.localAddress, "no default value for local address") + + var ssl = client.config.ssl + t.notOk(ssl.ca, "no default value for SSL certificate authority bundle") + t.notOk(ssl.certificate, "no default value for SSL client certificate") + t.notOk(ssl.key, "no default value for SSL client certificate key") + t.equal(ssl.strict, true, "SSL is strict by default") + + var retry = client.config.retry + t.equal(retry.count, 2, "default retry count is 2") + t.equal(retry.factor, 10, "default retry factor is 10") + t.equal(retry.minTimeout, 10000, "retry minimum timeout is 10000 (10 seconds)") + t.equal(retry.maxTimeout, 60000, "retry maximum timeout is 60000 (60 seconds)") + + t.equal(client.config.userAgent, "node/"+process.version, "default userAgent") + t.ok(client.log.info, "there's a default logger") + t.equal(client.config.defaultTag, "latest", "default tag is 'latest'") + t.notOk(client.config.couchToken, "no couchToken by default") + t.notOk(client.config.sessionToken, "no sessionToken by default") + + t.end() +}) + +test("missing HTTPS proxy defaults to HTTP proxy", function (t) { + var client = common.freshClient({ proxy : { http : "http://proxy.npm:8088/" }}) + + t.equal(client.config.proxy.http, "http://proxy.npm:8088/", "HTTP proxy set") + t.equal(client.config.proxy.http, client.config.proxy.https, "HTTP === HTTPS") + + t.end() +}) diff --git a/node_modules/npm-registry-client/test/config-override.js b/node_modules/npm-registry-client/test/config-override.js new file mode 100644 index 000000000..4e1240692 --- /dev/null +++ b/node_modules/npm-registry-client/test/config-override.js @@ -0,0 +1,57 @@ +var test = require("tap").test + +require("./lib/server.js").close() +var common = require("./lib/common.js") +var config = { + proxy : { + http : "http://proxy.npm:8088/", + https : "https://proxy.npm:8043/", + localAddress : "localhost.localdomain" + }, + ssl : { + ca : "not including a PEM", + certificate : "still not including a PEM", + key : "nope", + strict : false + }, + retry : { + count : 1, + factor : 9001, + minTimeout : -1, + maxTimeout : Infinity + }, + userAgent : "npm-awesome/4 (Mozilla 5.0)", + log : { fake : function () {} }, + defaultTag : "next", + couchToken : { object : true }, + sessionToken : "hamchunx" +} + +test("config defaults", function (t) { + var client = common.freshClient(config) + + var proxy = client.config.proxy + t.equal(proxy.http, "http://proxy.npm:8088/") + t.equal(proxy.https, "https://proxy.npm:8043/") + t.equal(proxy.localAddress, "localhost.localdomain") + + var ssl = client.config.ssl + t.equal(ssl.ca, "not including a PEM") + t.equal(ssl.certificate, "still not including a PEM") + t.equal(ssl.key, "nope") + t.equal(ssl.strict, false) + + var retry = client.config.retry + t.equal(retry.count, 1) + t.equal(retry.factor, 9001) + t.equal(retry.minTimeout, -1) + t.equal(retry.maxTimeout, Infinity) + + t.equal(client.config.userAgent, "npm-awesome/4 (Mozilla 5.0)") + t.ok(client.log.fake) + t.equal(client.config.defaultTag, "next") + t.ok(client.config.couchToken.object) + t.equal(client.config.sessionToken, "hamchunx") + + t.end() +}) diff --git a/node_modules/npm-registry-client/test/deprecate.js b/node_modules/npm-registry-client/test/deprecate.js index 76a5ba128..84b82b919 100644 --- a/node_modules/npm-registry-client/test/deprecate.js +++ b/node_modules/npm-registry-client/test/deprecate.js @@ -1,21 +1,107 @@ -var tap = require("tap") +var test = require("tap").test var server = require("./lib/server.js") var common = require("./lib/common.js") +var cache = require("./fixtures/underscore/cache.json") -var nerfed = "//localhost:" + server.port + "/:" - -var configuration = {} -configuration[nerfed + "_authToken"] = "not-bad-meaning-bad-but-bad-meaning-wombat" - -var client = common.freshClient(configuration) +var client = common.freshClient() -var cache = require("./fixtures/underscore/cache.json") +function nop () {} +var URI = "https://npm.registry:8043/rewrite" var VERSION = "1.3.2" var MESSAGE = "uhhh" +var TOKEN = "lolbutts" +var AUTH = { + token : TOKEN +} +var PARAMS = { + version : VERSION, + message : MESSAGE, + auth : AUTH +} + +test("deprecate call contract", function (t) { + t.throws(function () { + client.deprecate(undefined, PARAMS, nop) + }, "requires a URI") + + t.throws(function () { + client.deprecate([], PARAMS, nop) + }, "requires URI to be a string") + + t.throws(function () { + client.deprecate(URI, undefined, nop) + }, "requires params object") + + t.throws(function () { + client.deprecate(URI, "", nop) + }, "params must be object") + + t.throws(function () { + client.deprecate(URI, PARAMS, undefined) + }, "requires callback") + + t.throws(function () { + client.deprecate(URI, PARAMS, "callback") + }, "callback must be function") + + t.throws( + function () { + var params = { + message : MESSAGE, + auth : AUTH + } + client.deprecate(URI, params, nop) + }, + { name : "AssertionError", message : "must pass version to deprecate" }, + "params must include version to deprecate" + ) -tap.test("deprecate a package", function (t) { + t.throws( + function () { + var params = { + version : VERSION, + auth : AUTH + } + client.deprecate(URI, params, nop) + }, + { name : "AssertionError", message : "must pass message to deprecate" }, + "params must include deprecation message" + ) + + t.throws( + function () { + var params = { + version : VERSION, + message : MESSAGE + } + client.deprecate(URI, params, nop) + }, + { name : "AssertionError", message : "must pass auth to deprecate" }, + "params must include auth" + ) + + t.test("malformed semver in deprecation", function (t) { + var params = { + version : "-9001", + message : MESSAGE, + auth : AUTH + } + client.deprecate(URI, params, function (err) { + t.equal( + err && err.message, + "invalid version range: -9001", + "got expected semver validation failure" + ) + t.end() + }) + }) + + t.end() +}) + +test("deprecate a package", function (t) { server.expect("GET", "/underscore?write=true", function (req, res) { t.equal(req.method, "GET") @@ -57,10 +143,14 @@ tap.test("deprecate a package", function (t) { }) }) - client.deprecate(common.registry + "/underscore", VERSION, MESSAGE, function (er, data) { - t.ifError(er) - t.ok(data.deprecated, "was deprecated") + client.deprecate( + common.registry + "/underscore", + PARAMS, + function (er, data) { + t.ifError(er) + t.ok(data.deprecated, "was deprecated") - t.end() - }) + t.end() + } + ) }) diff --git a/node_modules/npm-registry-client/test/fetch-404.js b/node_modules/npm-registry-client/test/fetch-404.js index 2ce3b212b..25def1bec 100644 --- a/node_modules/npm-registry-client/test/fetch-404.js +++ b/node_modules/npm-registry-client/test/fetch-404.js @@ -10,7 +10,7 @@ var common = require("./lib/common.js") var tgz = resolve(__dirname, "./fixtures/underscore/1.3.3/package.tgz") -tap.test("basic fetch", function (t) { +tap.test("fetch with a 404 response", function (t) { server.expect("/underscore/-/underscore-1.3.3.tgz", function (req, res) { t.equal(req.method, "GET", "got expected method") @@ -23,9 +23,10 @@ tap.test("basic fetch", function (t) { }) var client = common.freshClient() + var defaulted = {} client.fetch( "http://localhost:1337/underscore/-/underscore-1.3.3.tgz", - null, + defaulted, function (er, res) { t.ifError(er, "loaded successfully") diff --git a/node_modules/npm-registry-client/test/fetch-408.js b/node_modules/npm-registry-client/test/fetch-408.js index bdd8bf070..1e48bd42e 100644 --- a/node_modules/npm-registry-client/test/fetch-408.js +++ b/node_modules/npm-registry-client/test/fetch-408.js @@ -30,10 +30,11 @@ tap.test("fetch with retry on timeout", function (t) { }) var client = common.freshClient() - client.conf.set("fetch-retry-mintimeout", 100) + var defaulted = {} + client.config.retry.minTimeout = 100 client.fetch( "http://localhost:1337/underscore/-/underscore-1.3.3.tgz", - {}, + defaulted, function (er, res) { t.ifError(er, "loaded successfully") diff --git a/node_modules/npm-registry-client/test/fetch-503.js b/node_modules/npm-registry-client/test/fetch-503.js index 91cd6754d..239e2e774 100644 --- a/node_modules/npm-registry-client/test/fetch-503.js +++ b/node_modules/npm-registry-client/test/fetch-503.js @@ -30,10 +30,11 @@ tap.test("fetch with retry on server error", function (t) { }) var client = common.freshClient() - client.conf.set("fetch-retry-mintimeout", 100) + var defaulted = {} + client.config.retry.minTimeout = 100 client.fetch( "http://localhost:1337/underscore/-/underscore-1.3.3.tgz", - {}, + defaulted, function (er, res) { t.ifError(er, "loaded successfully") diff --git a/node_modules/npm-registry-client/test/fetch-authed.js b/node_modules/npm-registry-client/test/fetch-authed.js index da359296c..e3171a559 100644 --- a/node_modules/npm-registry-client/test/fetch-authed.js +++ b/node_modules/npm-registry-client/test/fetch-authed.js @@ -27,17 +27,18 @@ tap.test("basic fetch with scoped always-auth enabled", function (t) { createReadStream(tgz).pipe(res) }) - var nerfed = "//localhost:" + server.port + "/:" - var configuration = {} - configuration[nerfed + "username"] = "username" - configuration[nerfed + "_password"] = new Buffer("%1234@asdf%").toString("base64") - configuration[nerfed + "email"] = "i@izs.me" - configuration[nerfed + "always-auth"] = true - - var client = common.freshClient(configuration) + var auth = { + username : "username", + password : "%1234@asdf%", + email : "i@izs.me", + alwaysAuth : true + } + + var client = common.freshClient() + var authed = { auth : auth } client.fetch( "http://localhost:1337/underscore/-/underscore-1.3.3.tgz", - null, + authed, function (er, res) { t.ifError(er, "loaded successfully") diff --git a/node_modules/npm-registry-client/test/fetch-basic.js b/node_modules/npm-registry-client/test/fetch-basic.js index 2ce3b212b..68e67f023 100644 --- a/node_modules/npm-registry-client/test/fetch-basic.js +++ b/node_modules/npm-registry-client/test/fetch-basic.js @@ -2,15 +2,63 @@ var resolve = require("path").resolve var createReadStream = require("graceful-fs").createReadStream var readFileSync = require("graceful-fs").readFileSync -var tap = require("tap") -var cat = require("concat-stream") +var test = require("tap").test +var concat = require("concat-stream") var server = require("./lib/server.js") var common = require("./lib/common.js") +var client = common.freshClient() var tgz = resolve(__dirname, "./fixtures/underscore/1.3.3/package.tgz") -tap.test("basic fetch", function (t) { +function nop () {} + +var URI = "https://npm.registry:8043/rewrite" +var USERNAME = "username" +var PASSWORD = "hi" +var EMAIL = "n@p.m" +var HEADERS = { + "npm-custom" : "lolbutts" +} +var AUTH = { + username : USERNAME, + password : PASSWORD, + email : EMAIL +} +var PARAMS = { + headers : HEADERS, + auth : AUTH +} + +test("fetch call contract", function (t) { + t.throws(function () { + client.get(undefined, PARAMS, nop) + }, "requires a URI") + + t.throws(function () { + client.get([], PARAMS, nop) + }, "requires URI to be a string") + + t.throws(function () { + client.get(URI, undefined, nop) + }, "requires params object") + + t.throws(function () { + client.get(URI, "", nop) + }, "params must be object") + + t.throws(function () { + client.get(URI, PARAMS, undefined) + }, "requires callback") + + t.throws(function () { + client.get(URI, PARAMS, "callback") + }, "callback must be function") + + t.end() +}) + +test("basic fetch", function (t) { server.expect("/underscore/-/underscore-1.3.3.tgz", function (req, res) { t.equal(req.method, "GET", "got expected method") @@ -22,14 +70,14 @@ tap.test("basic fetch", function (t) { createReadStream(tgz).pipe(res) }) - var client = common.freshClient() + var defaulted = {} client.fetch( "http://localhost:1337/underscore/-/underscore-1.3.3.tgz", - null, + defaulted, function (er, res) { t.ifError(er, "loaded successfully") - var sink = cat(function (data) { + var sink = concat(function (data) { t.deepEqual(data, readFileSync(tgz)) t.end() }) diff --git a/node_modules/npm-registry-client/test/fetch-not-authed.js b/node_modules/npm-registry-client/test/fetch-not-authed.js index 0275dc2b9..413377044 100644 --- a/node_modules/npm-registry-client/test/fetch-not-authed.js +++ b/node_modules/npm-registry-client/test/fetch-not-authed.js @@ -23,17 +23,18 @@ tap.test("basic fetch with scoped always-auth disabled", function (t) { createReadStream(tgz).pipe(res) }) - var nerfed = "//localhost:" + server.port + "/:" - var configuration = {} - configuration[nerfed + "username"] = "username" - configuration[nerfed + "_password"] = new Buffer("%1234@asdf%").toString("base64") - configuration[nerfed + "email"] = "i@izs.me" - configuration[nerfed + "always-auth"] = false - - var client = common.freshClient(configuration) + var auth = { + username : "username", + password : "%1234@asdf%", + email : "i@izs.me", + alwaysAuth : false + } + + var client = common.freshClient() + var authed = { auth : auth } client.fetch( "http://localhost:1337/underscore/-/underscore-1.3.3.tgz", - null, + authed, function (er, res) { t.ifError(er, "loaded successfully") diff --git a/node_modules/npm-registry-client/test/get-all.js b/node_modules/npm-registry-client/test/get-all.js deleted file mode 100644 index 75570fcbb..000000000 --- a/node_modules/npm-registry-client/test/get-all.js +++ /dev/null @@ -1,16 +0,0 @@ -var tap = require("tap") - -var server = require("./lib/server.js") -var common = require("./lib/common.js") -var client = common.freshClient() - -tap.test("basic request", function (t) { - server.expect("/-/all", function (req, res) { - res.json([]) - }) - - client.get("http://localhost:1337/-/all", null, function (er) { - t.ifError(er, "no error") - t.end() - }) -}) diff --git a/node_modules/npm-registry-client/test/get-basic.js b/node_modules/npm-registry-client/test/get-basic.js index 240dc8762..1f28bdfbf 100644 --- a/node_modules/npm-registry-client/test/get-basic.js +++ b/node_modules/npm-registry-client/test/get-basic.js @@ -1,4 +1,4 @@ -var tap = require("tap") +var test = require("tap").test var server = require("./lib/server.js") var common = require("./lib/common.js") @@ -7,7 +7,52 @@ var client = common.freshClient() var us = require("./fixtures/underscore/1.3.3/cache.json") var usroot = require("./fixtures/underscore/cache.json") -tap.test("basic request", function (t) { +function nop () {} + +var URI = "https://npm.registry:8043/rewrite" +var TIMEOUT = 3600 +var FOLLOW = false +var STALE_OK = true +var TOKEN = "lolbutts" +var AUTH = { + token : TOKEN +} +var PARAMS = { + timeout : TIMEOUT, + follow : FOLLOW, + staleOk : STALE_OK, + auth : AUTH +} + +test("get call contract", function (t) { + t.throws(function () { + client.get(undefined, PARAMS, nop) + }, "requires a URI") + + t.throws(function () { + client.get([], PARAMS, nop) + }, "requires URI to be a string") + + t.throws(function () { + client.get(URI, undefined, nop) + }, "requires params object") + + t.throws(function () { + client.get(URI, "", nop) + }, "params must be object") + + t.throws(function () { + client.get(URI, PARAMS, undefined) + }, "requires callback") + + t.throws(function () { + client.get(URI, PARAMS, "callback") + }, "callback must be function") + + t.end() +}) + +test("basic request", function (t) { server.expect("/underscore/1.3.3", function (req, res) { res.json(us) }) @@ -21,15 +66,15 @@ tap.test("basic request", function (t) { }) t.plan(3) - client.get("http://localhost:1337/underscore/1.3.3", null, function (er, data) { + client.get("http://localhost:1337/underscore/1.3.3", PARAMS, function (er, data) { t.deepEqual(data, us) }) - client.get("http://localhost:1337/underscore", null, function (er, data) { + client.get("http://localhost:1337/underscore", PARAMS, function (er, data) { t.deepEqual(data, usroot) }) - client.get("http://localhost:1337/@bigco%2funderscore", null, function (er, data) { + client.get("http://localhost:1337/@bigco%2funderscore", PARAMS, function (er, data) { t.deepEqual(data, usroot) }) }) diff --git a/node_modules/npm-registry-client/test/get-error-403.js b/node_modules/npm-registry-client/test/get-error-403.js index 27406b168..dc20a8caf 100644 --- a/node_modules/npm-registry-client/test/get-error-403.js +++ b/node_modules/npm-registry-client/test/get-error-403.js @@ -12,7 +12,7 @@ tap.test("get fails with 403", function (t) { }) var client = common.freshClient() - client.conf.set("fetch-retry-mintimeout", 100) + client.config.retry.minTimeout = 100 client.get( "http://localhost:1337/habanero", {}, diff --git a/node_modules/npm-registry-client/test/lib/common.js b/node_modules/npm-registry-client/test/lib/common.js index 712f6632f..178a75bb5 100644 --- a/node_modules/npm-registry-client/test/lib/common.js +++ b/node_modules/npm-registry-client/test/lib/common.js @@ -1,78 +1,12 @@ -var resolve = require("path").resolve - var server = require("./server.js") var RC = require("../../") -var toNerfDart = require("../../lib/util/nerf-dart.js") - var REGISTRY = "http://localhost:" + server.port module.exports = { port : server.port, registry : REGISTRY, freshClient : function freshClient(config) { - config = config || {} - config.cache = resolve(__dirname, "../fixtures/cache") - config.registry = REGISTRY - var container = { - get: function (k) { return config[k] }, - set: function (k, v) { config[k] = v }, - del: function (k) { delete config[k] }, - getCredentialsByURI: function(uri) { - var nerfed = toNerfDart(uri) - var c = {scope : nerfed} - - if (this.get(nerfed + ":_authToken")) { - c.token = this.get(nerfed + ":_authToken") - // the bearer token is enough, don't confuse things - return c - } - - if (this.get(nerfed + ":_password")) { - c.password = new Buffer(this.get(nerfed + ":_password"), "base64").toString("utf8") - } - - if (this.get(nerfed + ":username")) { - c.username = this.get(nerfed + ":username") - } - - if (this.get(nerfed + ":email")) { - c.email = this.get(nerfed + ":email") - } - - if (this.get(nerfed + ":always-auth") !== undefined) { - c.alwaysAuth = this.get(nerfed + ":always-auth") - } - - if (c.username && c.password) { - c.auth = new Buffer(c.username + ":" + c.password).toString("base64") - } - - return c - }, - setCredentialsByURI: function (uri, c) { - var nerfed = toNerfDart(uri) - - if (c.token) { - this.set(nerfed + ":_authToken", c.token, "user") - this.del(nerfed + ":_password", "user") - this.del(nerfed + ":username", "user") - this.del(nerfed + ":email", "user") - } - else if (c.username || c.password || c.email) { - this.del(nerfed + ":_authToken", "user") - - var encoded = new Buffer(c.password, "utf8").toString("base64") - this.set(nerfed + ":_password", encoded, "user") - this.set(nerfed + ":username", c.username, "user") - this.set(nerfed + ":email", c.email, "user") - } - else { - throw new Error("No credentials to set.") - } - } - } - - var client = new RC(container) + var client = new RC(config) server.log = client.log client.log.level = "silent" diff --git a/node_modules/npm-registry-client/test/publish-again-scoped.js b/node_modules/npm-registry-client/test/publish-again-scoped.js index 97838ca44..10b127505 100644 --- a/node_modules/npm-registry-client/test/publish-again-scoped.js +++ b/node_modules/npm-registry-client/test/publish-again-scoped.js @@ -4,19 +4,20 @@ var fs = require("fs") var server = require("./lib/server.js") var common = require("./lib/common.js") -var nerfed = "//localhost:" + server.port + "/:" +var auth = { + username : "username", + password : "%1234@asdf%", + email : "i@izs.me", + alwaysAuth : true +} -var configuration = {} -configuration[nerfed + "username"] = "username" -configuration[nerfed + "_password"] = new Buffer("%1234@asdf%").toString("base64") -configuration[nerfed + "email"] = "i@izs.me" - -var client = common.freshClient(configuration) +var client = common.freshClient() tap.test("publish again", function (t) { // not really a tarball, but doesn't matter - var tarball = require.resolve("../package.json") - var pd = fs.readFileSync(tarball, "base64") + var bodyPath = require.resolve("../package.json") + var tarball = fs.createReadStream(bodyPath, "base64") + var pd = fs.readFileSync(bodyPath, "base64") var pkg = require("../package.json") var lastTime = null @@ -74,7 +75,13 @@ tap.test("publish again", function (t) { }) pkg.name = "@npm/npm-registry-client" - client.publish("http://localhost:1337/", pkg, tarball, function (er, data) { + + var params = { + metadata : pkg, + body : tarball, + auth : auth + } + client.publish("http://localhost:1337/", params, function (er, data) { if (er) throw er t.deepEqual(data, { created: true }) t.end() diff --git a/node_modules/npm-registry-client/test/publish-again.js b/node_modules/npm-registry-client/test/publish-again.js index 39c368fd3..9c547ca01 100644 --- a/node_modules/npm-registry-client/test/publish-again.js +++ b/node_modules/npm-registry-client/test/publish-again.js @@ -4,19 +4,20 @@ var fs = require("fs") var server = require("./lib/server.js") var common = require("./lib/common.js") -var nerfed = "//localhost:" + server.port + "/:" +var auth = { + username : "username", + password : "%1234@asdf%", + email : "i@izs.me", + alwaysAuth : true +} -var configuration = {} -configuration[nerfed + "username"] = "username" -configuration[nerfed + "_password"] = new Buffer("%1234@asdf%").toString("base64") -configuration[nerfed + "email"] = "i@izs.me" - -var client = common.freshClient(configuration) +var client = common.freshClient() tap.test("publish again", function (t) { // not really a tarball, but doesn't matter - var tarball = require.resolve("../package.json") - var pd = fs.readFileSync(tarball, "base64") + var bodyPath = require.resolve("../package.json") + var tarball = fs.createReadStream(bodyPath, "base64") + var pd = fs.readFileSync(bodyPath, "base64") var pkg = require("../package.json") var lastTime = null @@ -73,7 +74,12 @@ tap.test("publish again", function (t) { }) }) - client.publish("http://localhost:1337/", pkg, tarball, function (er, data) { + var params = { + metadata : pkg, + body : tarball, + auth : auth + } + client.publish("http://localhost:1337/", params, function (er, data) { if (er) throw er t.deepEqual(data, { created: true }) t.end() diff --git a/node_modules/npm-registry-client/test/publish-scoped-auth-token.js b/node_modules/npm-registry-client/test/publish-scoped-auth-token.js index e1bb7dd1e..70ff1e93f 100644 --- a/node_modules/npm-registry-client/test/publish-scoped-auth-token.js +++ b/node_modules/npm-registry-client/test/publish-scoped-auth-token.js @@ -5,17 +5,15 @@ var fs = require("fs") var server = require("./lib/server.js") var common = require("./lib/common.js") -var nerfed = "//localhost:" + server.port + "/:" +var auth = { token : "of-glad-tidings" } -var configuration = {} -configuration[nerfed + "_authToken"] = "of-glad-tidings" - -var client = common.freshClient(configuration) +var client = common.freshClient() tap.test("publish", function (t) { // not really a tarball, but doesn't matter - var tarball = require.resolve("../package.json") - var pd = fs.readFileSync(tarball, "base64") + var bodyPath = require.resolve("../package.json") + var tarball = fs.createReadStream(bodyPath, "base64") + var pd = fs.readFileSync(bodyPath, "base64") var pkg = require("../package.json") pkg.name = "@npm/npm-registry-client" @@ -44,7 +42,12 @@ tap.test("publish", function (t) { }) }) - client.publish(common.registry, pkg, tarball, function (er, data) { + var params = { + metadata : pkg, + body : tarball, + auth : auth + } + client.publish(common.registry, params, function (er, data) { if (er) throw er t.deepEqual(data, { created: true }) t.end() diff --git a/node_modules/npm-registry-client/test/publish-scoped.js b/node_modules/npm-registry-client/test/publish-scoped.js index b5dea3649..b21e33f41 100644 --- a/node_modules/npm-registry-client/test/publish-scoped.js +++ b/node_modules/npm-registry-client/test/publish-scoped.js @@ -5,21 +5,21 @@ var fs = require("fs") var server = require("./lib/server.js") var common = require("./lib/common.js") -var nerfed = "//localhost:" + server.port + "/:" +var auth = { + username : "username", + password : "%1234@asdf%", + email : "ogd@aoaioxxysz.net" +} -var configuration = {} -configuration[nerfed + "username"] = "username" -configuration[nerfed + "_password"] = new Buffer("%1234@asdf%").toString("base64") -configuration[nerfed + "email"] = "ogd@aoaioxxysz.net" - -var client = common.freshClient(configuration) +var client = common.freshClient() var _auth = new Buffer("username:%1234@asdf%").toString("base64") tap.test("publish", function (t) { // not really a tarball, but doesn't matter - var tarball = require.resolve("../package.json") - var pd = fs.readFileSync(tarball, "base64") + var bodyPath = require.resolve("../package.json") + var tarball = fs.createReadStream(bodyPath, "base64") + var pd = fs.readFileSync(bodyPath, "base64") var pkg = require("../package.json") pkg.name = "@npm/npm-registry-client" @@ -49,7 +49,12 @@ tap.test("publish", function (t) { }) }) - client.publish(common.registry, pkg, tarball, function (er, data) { + var params = { + metadata : pkg, + body : tarball, + auth : auth + } + client.publish(common.registry, params, function (er, data) { if (er) throw er t.deepEqual(data, { created: true }) t.end() diff --git a/node_modules/npm-registry-client/test/publish.js b/node_modules/npm-registry-client/test/publish.js index 2d76dfae2..9292a94c7 100644 --- a/node_modules/npm-registry-client/test/publish.js +++ b/node_modules/npm-registry-client/test/publish.js @@ -1,24 +1,145 @@ -var tap = require("tap") +var test = require("tap").test var crypto = require("crypto") var fs = require("fs") var server = require("./lib/server.js") var common = require("./lib/common.js") +var client = common.freshClient() -var nerfed = "//localhost:" + server.port + "/:" +function nop () {} -var configuration = {} -configuration[nerfed + "username"] = "username" -configuration[nerfed + "_password"] = new Buffer("%1234@asdf%").toString("base64") -configuration[nerfed + "email"] = "i@izs.me" +var URI = "http://localhost:1337/" +var USERNAME = "username" +var PASSWORD = "%1234@asdf%" +var EMAIL = "i@izs.me" +var METADATA = require("../package.json") +// not really a tarball, but doesn't matter +var BODY_PATH = require.resolve("../package.json") +var BODY = fs.createReadStream(BODY_PATH, "base64") +var AUTH = { + username : USERNAME, + password : PASSWORD, + email : EMAIL +} +var PARAMS = { + metadata : METADATA, + body : BODY, + auth : AUTH +} -var client = common.freshClient(configuration) +test("publish call contract", function (t) { + t.throws(function () { + client.publish(undefined, PARAMS, nop) + }, "requires a URI") -tap.test("publish", function (t) { - // not really a tarball, but doesn't matter - var tarball = require.resolve("../package.json") - var pd = fs.readFileSync(tarball, "base64") - var pkg = require("../package.json") + t.throws(function () { + client.publish([], PARAMS, nop) + }, "requires URI to be a string") + + t.throws(function () { + client.publish(URI, undefined, nop) + }, "requires params object") + + t.throws(function () { + client.publish(URI, "", nop) + }, "params must be object") + + t.throws(function () { + client.publish(URI, PARAMS, undefined) + }, "requires callback") + + t.throws(function () { + client.publish(URI, PARAMS, "callback") + }, "callback must be function") + + t.throws( + function () { + var params = { + body : BODY, + auth : AUTH + } + client.publish(URI, params, nop) + }, + { name : "AssertionError", message : "must pass package metadata to publish" }, + "params must include metadata for package" + ) + + t.throws( + function () { + var params = { + metadata : METADATA, + auth : AUTH + } + client.publish(URI, params, nop) + }, + { name : "AssertionError", message : "must pass package body to publish" }, + "params must include body of package to publish" + ) + + t.throws( + function () { + var params = { + metadata : METADATA, + body : BODY + } + client.publish(URI, params, nop) + }, + { name : "AssertionError", message : "must pass auth to publish" }, + "params must include auth" + ) + + t.throws( + function () { + var params = { + metadata : -1, + body : BODY, + auth : AUTH + } + client.publish(URI, params, nop) + }, + { name : "AssertionError", message : "must pass package metadata to publish" }, + "metadata must be object" + ) + + t.throws( + function () { + var params = { + metadata : METADATA, + body : -1, + auth : AUTH + } + client.publish(URI, params, nop) + }, + { + name : "AssertionError", + message : "package body passed to publish must be a stream" + }, + "body must be a Stream" + ) + + t.test("malformed semver in publish", function (t) { + var metadata = JSON.parse(JSON.stringify(METADATA)) + metadata.version = "%!@#$" + var params = { + metadata : metadata, + message : BODY, + auth : AUTH + } + client.publish(URI, params, function (err) { + t.equal( + err && err.message, + "invalid semver: %!@#$", + "got expected semver validation failure" + ) + t.end() + }) + }) + + t.end() +}) + +test("publish", function (t) { + var pd = fs.readFileSync(BODY_PATH, "base64") server.expect("/npm-registry-client", function (req, res) { t.equal(req.method, "PUT") @@ -31,22 +152,26 @@ tap.test("publish", function (t) { req.on("end", function () { var o = JSON.parse(b) t.equal(o._id, "npm-registry-client") - t.equal(o["dist-tags"].latest, pkg.version) - t.has(o.versions[pkg.version], pkg) - t.same(o.maintainers, [ { name: "username", email: "i@izs.me" } ]) - t.same(o.maintainers, o.versions[pkg.version].maintainers) - var att = o._attachments[ pkg.name + "-" + pkg.version + ".tgz" ] + t.equal(o["dist-tags"].latest, METADATA.version) + t.has(o.versions[METADATA.version], METADATA) + t.same(o.maintainers, [{ name : "username", email : "i@izs.me" }]) + t.same(o.maintainers, o.versions[METADATA.version].maintainers) + + var att = o._attachments[METADATA.name+"-"+METADATA.version+".tgz"] t.same(att.data, pd) + var hash = crypto.createHash("sha1").update(pd, "base64").digest("hex") - t.equal(o.versions[pkg.version].dist.shasum, hash) + t.equal(o.versions[METADATA.version].dist.shasum, hash) + res.statusCode = 201 - res.json({created:true}) + res.json({ created : true }) }) }) - client.publish("http://localhost:1337/", pkg, tarball, function (er, data) { + client.publish(URI, PARAMS, function (er, data) { if (er) throw er - t.deepEqual(data, { created: true }) + + t.deepEqual(data, { created : true }) t.end() }) }) diff --git a/node_modules/npm-registry-client/test/redirects.js b/node_modules/npm-registry-client/test/redirects.js index b7ead8795..ba3814349 100644 --- a/node_modules/npm-registry-client/test/redirects.js +++ b/node_modules/npm-registry-client/test/redirects.js @@ -31,18 +31,21 @@ tap.test("basic request", function (t) { res.json(pkg) }) - t.plan(2); - - client.get("http://localhost:1337/-/some-package/1.2.3", { - follow: false - }, function(er, data) { - t.assert(er, "Error must be set"); - }) - - client.get("http://localhost:1337/-/some-package/1.2.3", { - follow: true - }, function(er, data) { - t.deepEqual(data, pkg) - }) + t.plan(2) + + client.get( + "http://localhost:1337/-/some-package/1.2.3", + { follow : false }, + function (er) { + t.ok(er, "Error must be set") + } + ) + + client.get( + "http://localhost:1337/-/some-package/1.2.3", + { follow : true }, + function (er, data) { + t.deepEqual(data, pkg) + } + ) }) - diff --git a/node_modules/npm-registry-client/test/request-gzip-content.js b/node_modules/npm-registry-client/test/request-gzip-content.js index 1085bfaca..4463de9a7 100644 --- a/node_modules/npm-registry-client/test/request-gzip-content.js +++ b/node_modules/npm-registry-client/test/request-gzip-content.js @@ -4,9 +4,11 @@ var tap = require("tap") var server = require("./lib/server.js") var common = require("./lib/common.js") var client = common.freshClient({ - "fetch-retries" : 1, - "fetch-retry-mintimeout" : 10, - "fetch-retry-maxtimeout" : 100 + retry : { + count : 1, + minTimeout : 10, + maxTimeout : 100 + } }) var TEST_URL = "http://localhost:1337/some-package-gzip/1.2.3" @@ -28,7 +30,7 @@ zlib.gzip(JSON.stringify(pkg), function (err, pkgGzip) { res.end(pkgGzip) }) - client.get(TEST_URL, null, function (er, data) { + client.get(TEST_URL, {}, function (er, data) { if (er) throw er t.deepEqual(data, pkg) t.end() @@ -43,7 +45,7 @@ zlib.gzip(JSON.stringify(pkg), function (err, pkgGzip) { res.end(new Buffer("wrong gzip content")) }) - client.get(TEST_URL, null, function (er) { + client.get(TEST_URL, {}, function (er) { t.ok(er) t.end() }) diff --git a/node_modules/npm-registry-client/test/request.js b/node_modules/npm-registry-client/test/request.js new file mode 100644 index 000000000..72a066bad --- /dev/null +++ b/node_modules/npm-registry-client/test/request.js @@ -0,0 +1,207 @@ +var Readable = require("stream").Readable +var inherits = require("util").inherits + +var test = require("tap").test +var concat = require("concat-stream") + +var server = require("./lib/server.js") +var common = require("./lib/common.js") +var client = common.freshClient() + +function OneA() { + Readable.call(this) + this.push("A") + this.push(null) +} +inherits(OneA, Readable) + +function nop () {} + +var URI = "http://localhost:1337/" +var USERNAME = "username" +var PASSWORD = "%1234@asdf%" +var EMAIL = "i@izs.me" +var AUTH = { + username : USERNAME, + password : PASSWORD, + email : EMAIL +} +var PARAMS = { auth : AUTH } + +test("request call contract", function (t) { + t.throws( + function () { + client.request(undefined, PARAMS, nop) + }, + { name : "AssertionError", message : "must pass uri to request" }, + "requires a URI" + ) + + t.throws( + function () { + client.request([], PARAMS, nop) + }, + { name : "AssertionError", message : "must pass uri to request" }, + "requires URI to be a string" + ) + + t.throws( + function () { + client.request(URI, undefined, nop) + }, + { name : "AssertionError", message : "must pass params to request" }, + "requires params object" + ) + + t.throws( + function () { + client.request(URI, "", nop) + }, + { name : "AssertionError", message : "must pass params to request" }, + "params must be object" + ) + + t.throws( + function () { + client.request(URI, PARAMS, undefined) + }, + { name : "AssertionError", message : "must pass callback to request" }, + "requires callback" + ) + + t.throws( + function () { + client.request(URI, PARAMS, "callback") + }, + { name : "AssertionError", message : "must pass callback to request" }, + "callback must be function" + ) + + t.end() +}) + +test("run request through its paces", function (t) { + t.plan(22) + + server.expect("/request-defaults", function (req, res) { + t.equal(req.method, "GET", "uses GET by default") + + req.pipe(concat(function (d) { + t.notOk(d.toString("utf7"), "no data included in request") + + res.statusCode = 200 + res.json({ fetched : "defaults" }) + })) + }) + + server.expect("/etag", function (req, res) { + t.equal(req.headers["if-none-match"], "test-etag", "got test etag") + + res.statusCode = 200 + res.json({ fetched : "etag" }) + }) + + server.expect("POST", "/etag-post", function (req, res) { + t.equal(req.headers["if-match"], "post-etag", "got test post etag") + + res.statusCode = 200 + res.json({ posted : "etag" }) + }) + + server.expect("PUT", "/body-stream", function (req, res) { + req.pipe(concat(function (d) { + t.equal(d.toString("utf8"), "A", "streamed expected data") + + res.statusCode = 200 + res.json({ put : "stream" }) + })) + }) + + server.expect("PUT", "/body-buffer", function (req, res) { + req.pipe(concat(function (d) { + t.equal(d.toString("utf8"), "hi", "streamed expected data") + + res.statusCode = 200 + res.json({ put : "buffer" }) + })) + }) + + server.expect("PUT", "/body-string", function (req, res) { + req.pipe(concat(function (d) { + t.equal(d.toString("utf8"), "erp", "streamed expected data") + + res.statusCode = 200 + res.json({ put : "string" }) + })) + }) + + server.expect("PUT", "/body-object", function (req, res) { + req.pipe(concat(function (d) { + t.equal(d.toString("utf8"), '["tricky"]', "streamed expected data") + + res.statusCode = 200 + res.json({ put : "object" }) + })) + }) + + var defaults = {} + client.request(common.registry+"/request-defaults", defaults, function (er, data) { + t.ifError(er, "call worked") + t.deepEquals(data, { fetched : "defaults" }, "confirmed defaults work") + }) + + var etagged = { etag : "test-etag" } + client.request(common.registry+"/etag", etagged, function (er, data) { + t.ifError(er, "call worked") + t.deepEquals(data, { fetched : "etag" }, "etag request sent") + }) + + var postEtagged = { + method : "post", + etag : "post-etag" + } + client.request(common.registry+"/etag-post", postEtagged, function (er, data) { + t.ifError(er, "call worked") + t.deepEquals(data, { posted : "etag" }, "POST etag request sent") + }) + + var putStream = { + method : "PUT", + body : new OneA(), + auth : AUTH + } + client.request(common.registry+"/body-stream", putStream, function (er, data) { + t.ifError(er, "call worked") + t.deepEquals(data, { put : "stream" }, "PUT request with stream sent") + }) + + var putBuffer = { + method : "PUT", + body : new Buffer("hi"), + auth : AUTH + } + client.request(common.registry+"/body-buffer", putBuffer, function (er, data) { + t.ifError(er, "call worked") + t.deepEquals(data, { put : "buffer" }, "PUT request with buffer sent") + }) + + var putString = { + method : "PUT", + body : "erp", + auth : AUTH + } + client.request(common.registry+"/body-string", putString, function (er, data) { + t.ifError(er, "call worked") + t.deepEquals(data, { put : "string" }, "PUT request with string sent") + }) + + var putObject = { + method : "PUT", + body : { toJSON : function () { return [ "tricky" ] } }, + auth : AUTH + } + client.request(common.registry+"/body-object", putObject, function (er, data) { + t.ifError(er, "call worked") + t.deepEquals(data, { put : "object" }, "PUT request with object sent") + }) +}) diff --git a/node_modules/npm-registry-client/test/retries.js b/node_modules/npm-registry-client/test/retries.js index f30f68080..c0b73ce7f 100644 --- a/node_modules/npm-registry-client/test/retries.js +++ b/node_modules/npm-registry-client/test/retries.js @@ -3,9 +3,11 @@ var tap = require("tap") var server = require("./lib/server.js") var common = require("./lib/common.js") var client = common.freshClient({ - "fetch-retries": 6, - "fetch-retry-mintimeout": 10, - "fetch-retry-maxtimeout": 100 + retry : { + count : 6, + minTimeout : 10, + maxTimeout : 100 + } }) var pkg = { @@ -41,7 +43,7 @@ tap.test("create new user account", function (t) { res.json(pkg) }) - client.get("http://localhost:1337/some-package/1.2.3", null, function (er, data) { + client.get("http://localhost:1337/some-package/1.2.3", {}, function (er, data) { if (er) throw er t.deepEqual(data, pkg) t.end() diff --git a/node_modules/npm-registry-client/test/star.js b/node_modules/npm-registry-client/test/star.js index 43c8888ef..1a8576f85 100644 --- a/node_modules/npm-registry-client/test/star.js +++ b/node_modules/npm-registry-client/test/star.js @@ -1,22 +1,83 @@ -var tap = require("tap") +var test = require("tap").test var server = require("./lib/server.js") var common = require("./lib/common.js") +var client = common.freshClient() +var cache = require("./fixtures/underscore/cache.json") -var DEP_USER = "username" +function nop () {} -var nerfed = "//localhost:" + server.port + "/:" +var URI = "https://npm.registry:8043/rewrite" +var STARRED = true +var USERNAME = "username" +var PASSWORD = "%1234@asdf%" +var EMAIL = "i@izs.me" +var AUTH = { + username : USERNAME, + password : PASSWORD, + email : EMAIL +} +var PARAMS = { + starred : STARRED, + auth : AUTH +} -var configuration = {} -configuration[nerfed + "username"] = DEP_USER -configuration[nerfed + "_password"] = new Buffer("%1234@asdf%").toString("base64") -configuration[nerfed + "email"] = "i@izs.me" +test("star call contract", function (t) { + t.throws(function () { + client.star(undefined, PARAMS, nop) + }, "requires a URI") -var client = common.freshClient(configuration) + t.throws(function () { + client.star([], PARAMS, nop) + }, "requires URI to be a string") -var cache = require("./fixtures/underscore/cache.json") + t.throws(function () { + client.star(URI, undefined, nop) + }, "requires params object") + + t.throws(function () { + client.star(URI, "", nop) + }, "params must be object") + + t.throws(function () { + client.star(URI, PARAMS, undefined) + }, "requires callback") + + t.throws(function () { + client.star(URI, PARAMS, "callback") + }, "callback must be function") + + t.throws( + function () { + var params = { + starred : STARRED + } + client.star(URI, params, nop) + }, + { name : "AssertionError", message : "must pass auth to star" }, + "params must include auth" + ) + + t.test("token auth disallowed in star", function (t) { + var params = { + auth : { + token : "lol" + } + } + client.star(URI, params, function (err) { + t.equal( + err && err.message, + "This operation is unsupported for token-based auth", + "star doesn't support token-based auth" + ) + t.end() + }) + }) + + t.end() +}) -tap.test("star a package", function (t) { +test("star a package", function (t) { server.expect("GET", "/underscore?write=true", function (req, res) { t.equal(req.method, "GET") @@ -46,14 +107,18 @@ tap.test("star a package", function (t) { current + " still likes this package" ) } - t.ok(updated.users[DEP_USER], "user is in the starred list") + t.ok(updated.users[USERNAME], "user is in the starred list") res.statusCode = 201 res.json({starred:true}) }) }) - client.star("http://localhost:1337/underscore", true, function (error, data) { + var params = { + starred : STARRED, + auth : AUTH + } + client.star("http://localhost:1337/underscore", params, function (error, data) { t.ifError(error, "no errors") t.ok(data.starred, "was starred") diff --git a/node_modules/npm-registry-client/test/stars.js b/node_modules/npm-registry-client/test/stars.js index 28f8a98d7..cd1c28686 100644 --- a/node_modules/npm-registry-client/test/stars.js +++ b/node_modules/npm-registry-client/test/stars.js @@ -1,25 +1,79 @@ -var tap = require("tap") +var test = require("tap").test var server = require("./lib/server.js") var common = require("./lib/common.js") var client = common.freshClient() -var users = [ +function nop () {} + +var URI = "https://npm.registry:8043/rewrite" +var USERNAME = "sample" +var PASSWORD = "%1234@asdf%" +var EMAIL = "i@izs.me" +var AUTH = { + username : USERNAME, + password : PASSWORD, + email : EMAIL +} +var PARAMS = { + username : USERNAME, + auth : AUTH +} +var USERS = [ "benjamincoe", "seldo", "ceejbot" ] -tap.test("get the URL for the bugs page on a package", function (t) { +test("stars call contract", function (t) { + t.throws(function () { + client.stars(undefined, PARAMS, nop) + }, "requires a URI") + + t.throws(function () { + client.stars([], PARAMS, nop) + }, "requires URI to be a string") + + t.throws(function () { + client.stars(URI, undefined, nop) + }, "requires params object") + + t.throws(function () { + client.stars(URI, "", nop) + }, "params must be object") + + t.throws(function () { + client.stars(URI, PARAMS, undefined) + }, "requires callback") + + t.throws(function () { + client.stars(URI, PARAMS, "callback") + }, "callback must be function") + + t.test("no username anywhere", function (t) { + var params = {} + client.stars(URI, params, function (err) { + t.equal( + err && err.message, + "must pass either username or auth to stars", + "username must not be empty") + t.end() + }) + }) + + t.end() +}) + +test("get the stars for a package", function (t) { server.expect("GET", "/-/_view/starredByUser?key=%22sample%22", function (req, res) { t.equal(req.method, "GET") - res.json(users) + res.json(USERS) }) - client.stars("http://localhost:1337/", "sample", function (error, info) { - t.ifError(error, "no errors") - t.deepEqual(info, users, "got the list of users") + client.stars("http://localhost:1337/", PARAMS, function (er, info) { + t.ifError(er, "no errors") + t.deepEqual(info, USERS, "got the list of users") t.end() }) diff --git a/node_modules/npm-registry-client/test/tag.js b/node_modules/npm-registry-client/test/tag.js index 755156930..687df5d7d 100644 --- a/node_modules/npm-registry-client/test/tag.js +++ b/node_modules/npm-registry-client/test/tag.js @@ -1,18 +1,93 @@ -var tap = require("tap") +var test = require("tap").test var server = require("./lib/server.js") var common = require("./lib/common.js") +var client = common.freshClient() -var nerfed = "//localhost:" + server.port + "/:" +function nop () {} -var configuration = {} -configuration[nerfed + "username"] = "username" -configuration[nerfed + "_password"] = new Buffer("%1234@asdf%").toString("base64") -configuration[nerfed + "email"] = "i@izs.me" +var URI = "http://localhost:1337/underscore" +var USERNAME = "username" +var PASSWORD = "%1234@asdf%" +var EMAIL = "i@izs.me" +var VERSION = "1.3.2" +var TAG = "not-lodash" +var AUTH = { + username : USERNAME, + password : PASSWORD, + email : EMAIL +} +var PARAMS = { + tag : TAG, + version : VERSION, + auth : AUTH +} -var client = common.freshClient(configuration) +test("tag call contract", function (t) { + t.throws(function () { + client.tag(undefined, AUTH, nop) + }, "requires a URI") -tap.test("tag a package", function (t) { + t.throws(function () { + client.tag([], AUTH, nop) + }, "requires URI to be a string") + + t.throws(function () { + client.tag(URI, undefined, nop) + }, "requires params object") + + t.throws(function () { + client.tag(URI, "", nop) + }, "params must be object") + + t.throws(function () { + client.tag(URI, AUTH, undefined) + }, "requires callback") + + t.throws(function () { + client.tag(URI, AUTH, "callback") + }, "callback must be function") + + t.throws( + function () { + var params = { + tag : TAG, + auth : AUTH + } + client.tag(URI, params, nop) + }, + { name : "AssertionError", message : "must pass version to tag" }, + "auth must include username" + ) + + t.throws( + function () { + var params = { + version : VERSION, + auth : AUTH + } + client.tag(URI, params, nop) + }, + { name : "AssertionError", message : "must pass tag name to tag" }, + "auth must include username" + ) + + t.throws( + function () { + var params = { + version : VERSION, + tag : TAG + } + client.tag(URI, params, nop) + }, + { name : "AssertionError", message : "must pass auth to tag" }, + "auth must include username" + ) + + t.end() +}) + +test("tag a package", function (t) { server.expect("PUT", "/underscore/not-lodash", function (req, res) { t.equal(req.method, "PUT") @@ -25,14 +100,14 @@ tap.test("tag a package", function (t) { req.on("end", function () { var updated = JSON.parse(b) - t.deepEqual(updated, {"1.3.2":{}}) + t.deepEqual(updated, "1.3.2") res.statusCode = 201 res.json({tagged:true}) }) }) - client.tag("http://localhost:1337/underscore", {"1.3.2":{}}, "not-lodash", function (error, data) { + client.tag(URI, PARAMS, function (error, data) { t.ifError(error, "no errors") t.ok(data.tagged, "was tagged") diff --git a/node_modules/npm-registry-client/test/unpublish-scoped.js b/node_modules/npm-registry-client/test/unpublish-scoped.js index 0e5cb8606..88ee13f37 100644 --- a/node_modules/npm-registry-client/test/unpublish-scoped.js +++ b/node_modules/npm-registry-client/test/unpublish-scoped.js @@ -2,18 +2,22 @@ var tap = require("tap") var server = require("./lib/server.js") var common = require("./lib/common.js") - -var nerfed = "//localhost:" + server.port + "/:" - -var configuration = {} -configuration[nerfed + "_authToken"] = "of-glad-tidings" - -var client = common.freshClient(configuration) +var client = common.freshClient() var cache = require("./fixtures/@npm/npm-registry-client/cache.json") -var REV = "/-rev/213-0a1049cf56172b7d9a1184742c6477b9" +var REV = "/-rev/213-0a1049cf56172b7d9a1184742c6477b9" +var PACKAGE = "/@npm%2fnpm-registry-client" +var URI = common.registry + PACKAGE +var TOKEN = "of-glad-tidings" var VERSION = "3.0.6" +var AUTH = { + token : TOKEN +} +var PARAMS = { + version : VERSION, + auth : AUTH +} tap.test("unpublish a package", function (t) { server.expect("GET", "/@npm%2fnpm-registry-client?write=true", function (req, res) { @@ -39,20 +43,20 @@ tap.test("unpublish a package", function (t) { res.json(cache) }) - server.expect("GET", "/@npm%2fnpm-registry-client", function (req, res) { + server.expect("GET", PACKAGE, function (req, res) { t.equal(req.method, "GET") res.json(cache) }) - server.expect("DELETE", "/@npm%2fnpm-registry-client/-/@npm%2fnpm-registry-client-" + VERSION + ".tgz" + REV, function (req, res) { + server.expect("DELETE", PACKAGE+"/-"+PACKAGE+"-"+VERSION+".tgz"+REV, function (req, res) { t.equal(req.method, "DELETE") res.json({unpublished:true}) }) - client.unpublish("http://localhost:1337/@npm%2fnpm-registry-client", VERSION, function (error) { - t.ifError(error, "no errors") + client.unpublish(URI, PARAMS, function (er) { + t.ifError(er, "no errors") t.end() }) diff --git a/node_modules/npm-registry-client/test/unpublish.js b/node_modules/npm-registry-client/test/unpublish.js index 7a60431fa..edc42699e 100644 --- a/node_modules/npm-registry-client/test/unpublish.js +++ b/node_modules/npm-registry-client/test/unpublish.js @@ -1,21 +1,65 @@ -var tap = require("tap") +var test = require("tap").test var server = require("./lib/server.js") var common = require("./lib/common.js") - -var nerfed = "//localhost:" + server.port + "/:" - -var configuration = {} -configuration[nerfed + "_authToken"] = "of-glad-tidings" - -var client = common.freshClient(configuration) +var client = common.freshClient() var cache = require("./fixtures/underscore/cache.json") -var REV = "/-rev/72-47f2986bfd8e8b55068b204588bbf484" -var VERSION = "1.3.2" +function nop () {} + +var REV = "/-rev/72-47f2986bfd8e8b55068b204588bbf484" +var URI = "http://localhost:1337/underscore" +var TOKEN = "of-glad-tidings" +var VERSION = "1.3.2" +var AUTH = { + token : TOKEN +} +var PARAMS = { + version : VERSION, + auth : AUTH +} + +test("unpublish call contract", function (t) { + t.throws(function () { + client.unpublish(undefined, AUTH, nop) + }, "requires a URI") + + t.throws(function () { + client.unpublish([], AUTH, nop) + }, "requires URI to be a string") + + t.throws(function () { + client.unpublish(URI, undefined, nop) + }, "requires params object") + + t.throws(function () { + client.unpublish(URI, "", nop) + }, "params must be object") + + t.throws(function () { + client.unpublish(URI, AUTH, undefined) + }, "requires callback") + + t.throws(function () { + client.unpublish(URI, AUTH, "callback") + }, "callback must be function") + + t.throws( + function () { + var params = { + version : VERSION + } + client.unpublish(URI, params, nop) + }, + { name : "AssertionError", message : "must pass auth to unpublish" }, + "must pass auth to unpublish" + ) + + t.end() +}) -tap.test("unpublish a package", function (t) { +test("unpublish a package", function (t) { server.expect("GET", "/underscore?write=true", function (req, res) { t.equal(req.method, "GET") @@ -51,7 +95,7 @@ tap.test("unpublish a package", function (t) { res.json({unpublished:true}) }) - client.unpublish("http://localhost:1337/underscore", VERSION, function (error) { + client.unpublish(URI, PARAMS, function (error) { t.ifError(error, "no errors") t.end() diff --git a/node_modules/npm-registry-client/test/upload.js b/node_modules/npm-registry-client/test/upload.js deleted file mode 100644 index fa197e368..000000000 --- a/node_modules/npm-registry-client/test/upload.js +++ /dev/null @@ -1,36 +0,0 @@ -var tap = require("tap") -var Readable = require("stream").Readable -var inherits = require("util").inherits - -var common = require("./lib/common.js") -var server = require("./lib/server.js") - -var cache = require("./fixtures/underscore/cache.json") - -var nerfed = "//localhost:" + server.port + "/:" - -var configuration = {} -configuration[nerfed + "_authToken"] = "of-glad-tidings" - -var client = common.freshClient(configuration) - -function OneA() { - Readable.call(this) - this.push("A") - this.push(null) -} -inherits(OneA, Readable) - -tap.test("uploading a tarball", function (t) { - server.expect("PUT", "/underscore", function (req, res) { - t.equal(req.method, "PUT") - - res.json(cache) - }) - - client.upload("http://localhost:1337/underscore", new OneA(), "daedabeefa", true, function (error) { - t.ifError(error, "no errors") - - t.end() - }) -}) diff --git a/node_modules/npm-registry-client/test/whoami.js b/node_modules/npm-registry-client/test/whoami.js index f9c817684..ccb173a09 100644 --- a/node_modules/npm-registry-client/test/whoami.js +++ b/node_modules/npm-registry-client/test/whoami.js @@ -1,18 +1,54 @@ -var tap = require("tap") +var test = require("tap").test var server = require("./lib/server.js") var common = require("./lib/common.js") +var client = common.freshClient() -var nerfed = "//localhost:" + server.port + "/:" +function nop () {} -var configuration = {} -configuration[nerfed + "_authToken"] = "not-bad-meaning-bad-but-bad-meaning-wombat" +var WHOIAM = "wombat" +var TOKEN = "not-bad-meaning-bad-but-bad-meaning-wombat" +var AUTH = { token : TOKEN } +var PARAMS = { auth : AUTH } -var client = common.freshClient(configuration) +test("whoami call contract", function (t) { + t.throws(function () { + client.whoami(undefined, AUTH, nop) + }, "requires a URI") -var WHOIAM = "wombat" + t.throws(function () { + client.whoami([], AUTH, nop) + }, "requires URI to be a string") + + t.throws(function () { + client.whoami(common.registry, undefined, nop) + }, "requires params object") + + t.throws(function () { + client.whoami(common.registry, "", nop) + }, "params must be object") + + t.throws(function () { + client.whoami(common.registry, AUTH, undefined) + }, "requires callback") + + t.throws(function () { + client.whoami(common.registry, AUTH, "callback") + }, "callback must be function") + + t.throws( + function () { + var params = {} + client.whoami(common.registry, params, nop) + }, + { name : "AssertionError", message : "must pass auth to whoami" }, + "must pass auth to whoami" + ) + + t.end() +}) -tap.test("whoami", function (t) { +test("whoami", function (t) { server.expect("GET", "/whoami", function (req, res) { t.equal(req.method, "GET") // only available for token-based auth for now @@ -21,7 +57,7 @@ tap.test("whoami", function (t) { res.json({username : WHOIAM}) }) - client.whoami(common.registry, function (error, wombat) { + client.whoami(common.registry, PARAMS, function (error, wombat) { t.ifError(error, "no errors") t.equal(wombat, WHOIAM, "im a wombat") diff --git a/package.json b/package.json index 761c8c814..242e90f42 100644 --- a/package.json +++ b/package.json @@ -69,7 +69,7 @@ "npm-cache-filename": "~1.0.1", "npm-install-checks": "~1.0.2", "npm-package-arg": "~2.1.3", - "npm-registry-client": "~3.2.4", + "npm-registry-client": "~4.0.0", "npm-user-validate": "~0.1.1", "npmlog": "~0.1.1", "once": "~1.3.1", |