From 6cd87d1a9bb90e795f9891ea4db384435f4a8930 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kat=20March=C3=A1n?= Date: Thu, 5 Apr 2018 23:17:33 -0700 Subject: [PATCH] stars: stop using npm-registry-client --- lib/stars.js | 66 ++++++++++++++++++++++------------------------------ 1 file changed, 28 insertions(+), 38 deletions(-) diff --git a/lib/stars.js b/lib/stars.js index 4771079356a17..ea3581f1d4b44 100644 --- a/lib/stars.js +++ b/lib/stars.js @@ -1,47 +1,37 @@ -module.exports = stars - -stars.usage = 'npm stars []' - -var npm = require('./npm.js') -var log = require('npmlog') -var mapToRegistry = require('./utils/map-to-registry.js') -var output = require('./utils/output.js') +'use strict' -function stars (args, cb) { - npm.commands.whoami([], true, function (er, username) { - var name = args.length === 1 ? args[0] : username +const BB = require('bluebird') - if (er) { - if (er.code === 'ENEEDAUTH' && !name) { - var needAuth = new Error("'npm stars' on your own user account requires auth") - needAuth.code = 'ENEEDAUTH' - return cb(needAuth) - } - - if (er.code !== 'ENEEDAUTH') return cb(er) - } +const npmConfig = require('./config/figgy-config.js') +const fetch = require('libnpm/fetch') +const log = require('npmlog') +const output = require('./utils/output.js') +const whoami = require('./whoami.js') - mapToRegistry('', npm.config, function (er, uri, auth) { - if (er) return cb(er) +stars.usage = 'npm stars []' - var params = { - username: name, - auth: auth +module.exports = stars +function stars ([user], cb) { + const opts = npmConfig() + return BB.try(() => { + return (user ? BB.resolve(user) : whoami([], true, () => {})).then(usr => { + return fetch.json('/-/_view/starredByUser', opts.concat({ + query: {key: `"${usr}"`} // WHY. WHY THE ""?! + })) + }).then(data => data.rows).then(stars => { + if (stars.length === 0) { + log.warn('stars', 'user has not starred any packages.') + } else { + stars.forEach(s => output(s.value)) } - npm.registry.stars(uri, params, showstars) }) - }) - - function showstars (er, data) { - if (er) return cb(er) - - if (data.rows.length === 0) { - log.warn('stars', 'user has not starred any packages.') - } else { - data.rows.forEach(function (a) { - output(a.value) + }).catch(err => { + if (err.code === 'ENEEDAUTH') { + throw Object.assign(new Error("'npm starts' on your own user account requires auth"), { + code: 'ENEEDAUTH' }) + } else { + throw err } - cb() - } + }).nodeify(cb) }