马宇豪
2024-07-16 f591c27b57e2418c9495bc02ae8cfff84d35bc18
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
const PackageUrlCmd = require('../package-url-cmd.js')
 
class Bugs extends PackageUrlCmd {
  static description = 'Report bugs for a package in a web browser'
  static name = 'bugs'
 
  getUrl (spec, mani) {
    if (mani.bugs) {
      if (typeof mani.bugs === 'string') {
        return mani.bugs
      }
 
      if (typeof mani.bugs === 'object' && mani.bugs.url) {
        return mani.bugs.url
      }
 
      if (typeof mani.bugs === 'object' && mani.bugs.email) {
        return `mailto:${mani.bugs.email}`
      }
    }
 
    // try to get it from the repo, if possible
    const info = this.hostedFromMani(mani)
    const infoUrl = info?.bugs()
    if (infoUrl) {
      return infoUrl
    }
 
    // just send them to the website, hopefully that has some info!
    return `https://www.npmjs.com/package/${mani.name}`
  }
}
 
module.exports = Bugs