-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
stars: stop using npm-registry-client
- Loading branch information
Showing
1 changed file
with
28 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |