bugs.js 864 B

12345678910111213141516171819202122232425262728293031
  1. module.exports = bugs
  2. var log = require('npmlog')
  3. var openUrl = require('./utils/open-url')
  4. var fetchPackageMetadata = require('./fetch-package-metadata.js')
  5. var usage = require('./utils/usage')
  6. bugs.usage = usage(
  7. 'bugs',
  8. 'npm bugs [<pkgname>]'
  9. )
  10. bugs.completion = function (opts, cb) {
  11. // FIXME: there used to be registry completion here, but it stopped making
  12. // sense somewhere around 50,000 packages on the registry
  13. cb()
  14. }
  15. function bugs (args, cb) {
  16. var n = args.length ? args[0] : '.'
  17. fetchPackageMetadata(n, '.', {fullMetadata: true}, function (er, d) {
  18. if (er) return cb(er)
  19. var url = d.bugs && ((typeof d.bugs === 'string') ? d.bugs : d.bugs.url)
  20. if (!url) {
  21. url = 'https://www.npmjs.org/package/' + d.name
  22. }
  23. log.silly('bugs', 'url', url)
  24. openUrl(url, 'bug list available at the following URL', cb)
  25. })
  26. }