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:
authorisaacs <i@izs.me>2020-07-07 20:20:06 +0300
committerisaacs <i@izs.me>2020-07-08 03:20:29 +0300
commite23c4af1cc4149d0567f8b15bbeba594685288c9 (patch)
treeb339a4a77da39c6e11042d436a5be53841dc9aa0 /lib/bugs.js
parent12779c8d75dd91af33d299e46c8e253bf0171102 (diff)
rm fetch-package-metadata, refactor bugs/repo/docs
- remove the now-outdated 'fetch-package-metadata' module. - refactor the `bugs`, `repo`, and `docs` commands for consistency. - add unit tests for refactored commands and new util module. - update `browser` config handling to honor `browser = false` in config files, along with command line flag. (previously only cli config was honored.) - slight improvement to `open-url` output when browser not used.
Diffstat (limited to 'lib/bugs.js')
-rw-r--r--lib/bugs.js72
1 files changed, 45 insertions, 27 deletions
diff --git a/lib/bugs.js b/lib/bugs.js
index 10300d1e1..55f81989a 100644
--- a/lib/bugs.js
+++ b/lib/bugs.js
@@ -1,31 +1,49 @@
-module.exports = bugs
-
-var log = require('npmlog')
-var openUrl = require('./utils/open-url')
-var fetchPackageMetadata = require('./fetch-package-metadata.js')
-var usage = require('./utils/usage')
-
-bugs.usage = usage(
- 'bugs',
- 'npm bugs [<pkgname>]'
-)
-
-bugs.completion = function (opts, cb) {
- // FIXME: there used to be registry completion here, but it stopped making
- // sense somewhere around 50,000 packages on the registry
- cb()
-}
+const log = require('npmlog')
+const pacote = require('pacote')
+const { promisify } = require('util')
+const openUrl = promisify(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>]')
+const completion = (opts, cb) => cb(null, [])
-function bugs (args, cb) {
- var n = args.length ? args[0] : '.'
- fetchPackageMetadata(n, '.', {fullMetadata: true}, function (er, d) {
- if (er) return cb(er)
+const cmd = (args, cb) => bugs(args).then(() => cb()).catch(cb)
- var url = d.bugs && ((typeof d.bugs === 'string') ? d.bugs : d.bugs.url)
- if (!url) {
- url = 'https://www.npmjs.org/package/' + d.name
+const bugs = async args => {
+ if (!args || !args.length) {
+ args = ['.']
+ }
+ await Promise.all(args.map(pkg => getBugs(pkg)))
+}
+
+const getBugsUrl = mani => {
+ if (mani.bugs) {
+ if (typeof mani.bugs === 'string') {
+ return mani.bugs
+ }
+ if (typeof mani.bugs === 'object' && mani.bugs.url) {
+ return mani.bugs.url
}
- log.silly('bugs', 'url', url)
- openUrl(url, 'bug list available at the following URL', cb)
- })
+ }
+
+ // 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}`
}
+
+const getBugs = async pkg => {
+ const opts = { ...npm.flatOptions, fullMetadata: true }
+ const mani = await pacote.manifest(pkg, { fullMetadata: true })
+ const url = getBugsUrl(mani)
+ log.silly('bugs', 'url', url)
+ await openUrl(url, `${mani.name} bug list available at the following URL`)
+}
+
+module.exports = Object.assign(cmd, { usage, completion })