Skip to content

Commit

Permalink
stars: stop using npm-registry-client
Browse files Browse the repository at this point in the history
  • Loading branch information
zkat committed Dec 10, 2018
1 parent 64de4eb commit 6cd87d1
Showing 1 changed file with 28 additions and 38 deletions.
66 changes: 28 additions & 38 deletions lib/stars.js
Original file line number Diff line number Diff line change
@@ -1,47 +1,37 @@
module.exports = stars

stars.usage = 'npm stars [<user>]'

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 [<user>]'

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)
}

0 comments on commit 6cd87d1

Please sign in to comment.