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:
authorGar <gar+gh@danger.computer>2021-02-25 02:54:50 +0300
committerRuy Adorno <ruyadorno@hotmail.com>2021-03-05 00:05:08 +0300
commit4a5dd3a5a200b3f4f7b47168497d8e03dca3a2ca (patch)
treed34a1ea229b719c3cfbdce85899ceaf67b43e7ab /lib/bugs.js
parentb33c760cea7fe2696d35b5530abc1b455980fef1 (diff)
fix(npm) pass npm context everywhere
Instead of files randomly requiring the npm singleton, we pass it where it needs to go so that tests don't need to do so much require mocking everywhere PR-URL: https://github.com/npm/cli/pull/2772 Credit: @wraithgar Close: #2772 Reviewed-by: @ruyadorno
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