2020-10-02 17:52:19 -04:00
|
|
|
const log = require('npmlog')
|
|
|
|
const pacote = require('pacote')
|
2021-11-04 20:42:47 +00:00
|
|
|
const openUrl = require('../utils/open-url.js')
|
|
|
|
const hostedFromMani = require('../utils/hosted-git-info-from-manifest.js')
|
|
|
|
const BaseCommand = require('../base-command.js')
|
2020-10-02 17:52:19 -04:00
|
|
|
|
2021-03-11 17:54:23 -05:00
|
|
|
class Bugs extends BaseCommand {
|
2021-03-23 14:58:11 -04:00
|
|
|
static get description () {
|
|
|
|
return 'Report bugs for a package in a web browser'
|
|
|
|
}
|
|
|
|
|
2021-03-11 17:54:23 -05:00
|
|
|
static get name () {
|
|
|
|
return 'bugs'
|
2021-03-04 17:40:28 -05:00
|
|
|
}
|
2011-11-21 09:48:45 -08:00
|
|
|
|
2021-03-11 17:54:23 -05:00
|
|
|
static get usage () {
|
|
|
|
return ['[<pkgname>]']
|
2021-03-04 17:40:28 -05:00
|
|
|
}
|
2014-09-24 14:41:07 -07:00
|
|
|
|
2021-05-20 15:54:50 -04:00
|
|
|
/* istanbul ignore next - see test/lib/load-all-commands.js */
|
|
|
|
static get params () {
|
|
|
|
return ['browser', 'registry']
|
|
|
|
}
|
|
|
|
|
2021-11-04 20:42:47 +00:00
|
|
|
async exec (args) {
|
2021-03-04 17:40:28 -05:00
|
|
|
if (!args || !args.length)
|
|
|
|
args = ['.']
|
2020-10-02 17:52:19 -04:00
|
|
|
|
2021-03-04 17:40:28 -05:00
|
|
|
await Promise.all(args.map(pkg => this.getBugs(pkg)))
|
|
|
|
}
|
2020-11-01 07:54:36 +01:00
|
|
|
|
2021-03-04 17:40:28 -05:00
|
|
|
async getBugs (pkg) {
|
|
|
|
const opts = { ...this.npm.flatOptions, fullMetadata: true }
|
|
|
|
const mani = await pacote.manifest(pkg, opts)
|
|
|
|
const url = this.getBugsUrl(mani)
|
|
|
|
log.silly('bugs', 'url', url)
|
|
|
|
await openUrl(this.npm, url, `${mani.name} bug list available at the following URL`)
|
2020-10-02 17:52:19 -04:00
|
|
|
}
|
|
|
|
|
2021-03-04 17:40:28 -05:00
|
|
|
getBugsUrl (mani) {
|
|
|
|
if (mani.bugs) {
|
|
|
|
if (typeof mani.bugs === 'string')
|
|
|
|
return mani.bugs
|
2020-10-02 17:52:19 -04:00
|
|
|
|
2021-03-04 17:40:28 -05:00
|
|
|
if (typeof mani.bugs === 'object' && mani.bugs.url)
|
|
|
|
return mani.bugs.url
|
2021-04-15 21:53:45 -04:00
|
|
|
|
|
|
|
if (typeof mani.bugs === 'object' && mani.bugs.email)
|
|
|
|
return `mailto:${mani.bugs.email}`
|
2021-03-04 17:40:28 -05:00
|
|
|
}
|
2020-10-02 17:52:19 -04:00
|
|
|
|
2021-03-04 17:40:28 -05:00
|
|
|
// try to get it from the repo, if possible
|
|
|
|
const info = hostedFromMani(mani)
|
|
|
|
if (info)
|
|
|
|
return info.bugs()
|
|
|
|
|
|
|
|
// just send them to the website, hopefully that has some info!
|
|
|
|
return `https://www.npmjs.com/package/${mani.name}`
|
|
|
|
}
|
2020-10-02 17:52:19 -04:00
|
|
|
}
|
|
|
|
|
2021-03-04 17:40:28 -05:00
|
|
|
module.exports = Bugs
|