Skip to content

Commit 6cd87d1

Browse files
committed
stars: stop using npm-registry-client
1 parent 64de4eb commit 6cd87d1

1 file changed

Lines changed: 28 additions & 38 deletions

File tree

lib/stars.js

Lines changed: 28 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,37 @@
1-
module.exports = stars
2-
3-
stars.usage = 'npm stars [<user>]'
4-
5-
var npm = require('./npm.js')
6-
var log = require('npmlog')
7-
var mapToRegistry = require('./utils/map-to-registry.js')
8-
var output = require('./utils/output.js')
1+
'use strict'
92

10-
function stars (args, cb) {
11-
npm.commands.whoami([], true, function (er, username) {
12-
var name = args.length === 1 ? args[0] : username
3+
const BB = require('bluebird')
134

14-
if (er) {
15-
if (er.code === 'ENEEDAUTH' && !name) {
16-
var needAuth = new Error("'npm stars' on your own user account requires auth")
17-
needAuth.code = 'ENEEDAUTH'
18-
return cb(needAuth)
19-
}
20-
21-
if (er.code !== 'ENEEDAUTH') return cb(er)
22-
}
5+
const npmConfig = require('./config/figgy-config.js')
6+
const fetch = require('libnpm/fetch')
7+
const log = require('npmlog')
8+
const output = require('./utils/output.js')
9+
const whoami = require('./whoami.js')
2310

24-
mapToRegistry('', npm.config, function (er, uri, auth) {
25-
if (er) return cb(er)
11+
stars.usage = 'npm stars [<user>]'
2612

27-
var params = {
28-
username: name,
29-
auth: auth
13+
module.exports = stars
14+
function stars ([user], cb) {
15+
const opts = npmConfig()
16+
return BB.try(() => {
17+
return (user ? BB.resolve(user) : whoami([], true, () => {})).then(usr => {
18+
return fetch.json('/-/_view/starredByUser', opts.concat({
19+
query: {key: `"${usr}"`} // WHY. WHY THE ""?!
20+
}))
21+
}).then(data => data.rows).then(stars => {
22+
if (stars.length === 0) {
23+
log.warn('stars', 'user has not starred any packages.')
24+
} else {
25+
stars.forEach(s => output(s.value))
3026
}
31-
npm.registry.stars(uri, params, showstars)
3227
})
33-
})
34-
35-
function showstars (er, data) {
36-
if (er) return cb(er)
37-
38-
if (data.rows.length === 0) {
39-
log.warn('stars', 'user has not starred any packages.')
40-
} else {
41-
data.rows.forEach(function (a) {
42-
output(a.value)
28+
}).catch(err => {
29+
if (err.code === 'ENEEDAUTH') {
30+
throw Object.assign(new Error("'npm starts' on your own user account requires auth"), {
31+
code: 'ENEEDAUTH'
4332
})
33+
} else {
34+
throw err
4435
}
45-
cb()
46-
}
36+
}).nodeify(cb)
4737
}

0 commit comments

Comments
 (0)