Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorKat Marchán <kzm@zkat.tech>2018-04-06 09:17:33 +0300
committerKat Marchán <kzm@zkat.tech>2018-12-11 01:55:39 +0300
commit6cd87d1a9bb90e795f9891ea4db384435f4a8930 (patch)
tree254a26de17eca639e73e0eca29321bc13d780d43 /lib
parent64de4ebf019b217179039124c6621e74651e4d27 (diff)
stars: stop using npm-registry-client
Diffstat (limited to 'lib')
-rw-r--r--lib/stars.js66
1 files changed, 28 insertions, 38 deletions
diff --git a/lib/stars.js b/lib/stars.js
index 477107935..ea3581f1d 100644
--- a/lib/stars.js
+++ b/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)
}