11cb0ef41Sopenharmony_ciconst fetch = require('npm-registry-fetch') 21cb0ef41Sopenharmony_ciconst log = require('../utils/log-shim') 31cb0ef41Sopenharmony_ciconst getIdentity = require('../utils/get-identity.js') 41cb0ef41Sopenharmony_ci 51cb0ef41Sopenharmony_ciconst BaseCommand = require('../base-command.js') 61cb0ef41Sopenharmony_ciclass Stars extends BaseCommand { 71cb0ef41Sopenharmony_ci static description = 'View packages marked as favorites' 81cb0ef41Sopenharmony_ci static name = 'stars' 91cb0ef41Sopenharmony_ci static usage = ['[<user>]'] 101cb0ef41Sopenharmony_ci static params = ['registry'] 111cb0ef41Sopenharmony_ci static ignoreImplicitWorkspace = false 121cb0ef41Sopenharmony_ci 131cb0ef41Sopenharmony_ci async exec ([user]) { 141cb0ef41Sopenharmony_ci try { 151cb0ef41Sopenharmony_ci if (!user) { 161cb0ef41Sopenharmony_ci user = await getIdentity(this.npm, this.npm.flatOptions) 171cb0ef41Sopenharmony_ci } 181cb0ef41Sopenharmony_ci 191cb0ef41Sopenharmony_ci const { rows } = await fetch.json('/-/_view/starredByUser', { 201cb0ef41Sopenharmony_ci ...this.npm.flatOptions, 211cb0ef41Sopenharmony_ci query: { key: `"${user}"` }, 221cb0ef41Sopenharmony_ci }) 231cb0ef41Sopenharmony_ci if (rows.length === 0) { 241cb0ef41Sopenharmony_ci log.warn('stars', 'user has not starred any packages') 251cb0ef41Sopenharmony_ci } 261cb0ef41Sopenharmony_ci 271cb0ef41Sopenharmony_ci for (const row of rows) { 281cb0ef41Sopenharmony_ci this.npm.output(row.value) 291cb0ef41Sopenharmony_ci } 301cb0ef41Sopenharmony_ci } catch (err) { 311cb0ef41Sopenharmony_ci if (err.code === 'ENEEDAUTH') { 321cb0ef41Sopenharmony_ci log.warn('stars', 'auth is required to look up your username') 331cb0ef41Sopenharmony_ci } 341cb0ef41Sopenharmony_ci throw err 351cb0ef41Sopenharmony_ci } 361cb0ef41Sopenharmony_ci } 371cb0ef41Sopenharmony_ci} 381cb0ef41Sopenharmony_cimodule.exports = Stars 39