• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1const fetch = require('npm-registry-fetch')
2const log = require('../utils/log-shim')
3const getIdentity = require('../utils/get-identity.js')
4
5const BaseCommand = require('../base-command.js')
6class Stars extends BaseCommand {
7  static description = 'View packages marked as favorites'
8  static name = 'stars'
9  static usage = ['[<user>]']
10  static params = ['registry']
11  static ignoreImplicitWorkspace = false
12
13  async exec ([user]) {
14    try {
15      if (!user) {
16        user = await getIdentity(this.npm, this.npm.flatOptions)
17      }
18
19      const { rows } = await fetch.json('/-/_view/starredByUser', {
20        ...this.npm.flatOptions,
21        query: { key: `"${user}"` },
22      })
23      if (rows.length === 0) {
24        log.warn('stars', 'user has not starred any packages')
25      }
26
27      for (const row of rows) {
28        this.npm.output(row.value)
29      }
30    } catch (err) {
31      if (err.code === 'ENEEDAUTH') {
32        log.warn('stars', 'auth is required to look up your username')
33      }
34      throw err
35    }
36  }
37}
38module.exports = Stars
39