feat(npm-info): support private modules

closes #28
This commit is contained in:
Christoph Witzko 2015-05-25 00:15:15 +02:00
parent 0930a6e33d
commit 25cb545ea3
2 changed files with 36 additions and 21 deletions

View File

@ -1,28 +1,41 @@
'use strict'
var async = require('async')
var npmconf = require('npmconf')
var request = require('request')
var efh = require('./error').efh
module.exports = function (pkgName, cb) {
var encodedPkgName = pkgName.replace(/\//g, '%2F')
request(process.env.npm_config_registry + encodedPkgName, efh(cb)(function (response, body) {
var res = {
version: null,
gitHead: null,
pkg: null
var registry = process.env.npm_config_registry
async.waterfall([
npmconf.load,
function (conf, callback) {
var cred = conf.getCredentialsByURI(registry)
callback(null, {
url: registry + pkgName.replace(/\//g, '%2F'),
headers: {
'Authorization': cred.token ? 'Bearer ' + cred.token : null
}
})
},
request,
function (response, body, callback) {
var res = {
version: null,
gitHead: null,
pkg: null
}
if (response.statusCode === 404 || !body) return callback(null, res)
var pkg = JSON.parse(body)
if (pkg.error) return callback(pkg.error)
res.version = pkg['dist-tags'].latest
res.gitHead = pkg.versions[res.version].gitHead
res.pkg = pkg
callback(null, res)
}
if (response.statusCode === 404 || !body) return cb(null, res)
var pkg = JSON.parse(body)
if (pkg.error) return cb(pkg.error)
res.version = pkg['dist-tags'].latest
res.gitHead = pkg.versions[res.version].gitHead
res.pkg = pkg
cb(null, res)
}))
], cb)
}

View File

@ -9,6 +9,7 @@
},
"dependencies": {
"abbrev": "^1.0.5",
"async": "^1.0.0",
"conventional-changelog": "0.0.17",
"error-first-handler": "^1.0.1",
"git-head": "^1.2.1",
@ -16,6 +17,7 @@
"github-url-from-git": "^1.4.0",
"ini": "^1.3.2",
"minimist": "^1.1.0",
"npmconf": "^2.1.2",
"parse-github-repo-url": "^1.0.0",
"request": "^2.53.0",
"semver": "^4.3.3"