summaryrefslogtreecommitdiff
path: root/deps/npm/lib/stars.js
diff options
context:
space:
mode:
Diffstat (limited to 'deps/npm/lib/stars.js')
-rw-r--r--deps/npm/lib/stars.js66
1 files changed, 28 insertions, 38 deletions
diff --git a/deps/npm/lib/stars.js b/deps/npm/lib/stars.js
index 4771079356..ea3581f1d4 100644
--- a/deps/npm/lib/stars.js
+++ b/deps/npm/lib/stars.js
@@ -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)
}