bugs.js 847 B

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