Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'lib/bugs.js')
-rw-r--r--lib/bugs.js69
1 files changed, 39 insertions, 30 deletions
diff --git a/lib/bugs.js b/lib/bugs.js
index 09856313c..fb0d7c927 100644
--- a/lib/bugs.js
+++ b/lib/bugs.js
@@ -1,46 +1,55 @@
const log = require('npmlog')
const pacote = require('pacote')
-const { promisify } = require('util')
-const openUrl = promisify(require('./utils/open-url.js'))
+const openUrl = require('./utils/open-url.js')
const usageUtil = require('./utils/usage.js')
-const npm = require('./npm.js')
const hostedFromMani = require('./utils/hosted-git-info-from-manifest.js')
-const usage = usageUtil('bugs', 'npm bugs [<pkgname>]')
+class Bugs {
+ constructor (npm) {
+ this.npm = npm
+ }
-const cmd = (args, cb) => bugs(args).then(() => cb()).catch(cb)
+ /* istanbul ignore next - see test/lib/load-all-commands.js */
+ get usage () {
+ return usageUtil('bugs', 'npm bugs [<pkgname>]')
+ }
-const bugs = async args => {
- if (!args || !args.length)
- args = ['.']
+ exec (args, cb) {
+ this.bugs(args).then(() => cb()).catch(cb)
+ }
- await Promise.all(args.map(pkg => getBugs(pkg)))
-}
+ async bugs (args) {
+ if (!args || !args.length)
+ args = ['.']
-const getBugsUrl = mani => {
- if (mani.bugs) {
- if (typeof mani.bugs === 'string')
- return mani.bugs
+ await Promise.all(args.map(pkg => this.getBugs(pkg)))
+ }
- if (typeof mani.bugs === 'object' && mani.bugs.url)
- return mani.bugs.url
+ 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`)
}
- // try to get it from the repo, if possible
- const info = hostedFromMani(mani)
- if (info)
- return info.bugs()
+ getBugsUrl (mani) {
+ if (mani.bugs) {
+ if (typeof mani.bugs === 'string')
+ return mani.bugs
- // just send them to the website, hopefully that has some info!
- return `https://www.npmjs.com/package/${mani.name}`
-}
+ if (typeof mani.bugs === 'object' && mani.bugs.url)
+ return mani.bugs.url
+ }
-const getBugs = async pkg => {
- const opts = { ...npm.flatOptions, fullMetadata: true }
- const mani = await pacote.manifest(pkg, opts)
- const url = getBugsUrl(mani)
- log.silly('bugs', 'url', url)
- await openUrl(url, `${mani.name} bug list available at the following URL`)
+ // 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}`
+ }
}
-module.exports = Object.assign(cmd, { usage })
+module.exports = Bugs