diff options
author | isaacs <i@izs.me> | 2020-03-03 10:49:04 +0300 |
---|---|---|
committer | isaacs <i@izs.me> | 2020-05-08 04:12:27 +0300 |
commit | 410f7436af8ce71d079c9d0983204a8b850cd594 (patch) | |
tree | e499762194bb1a6c7031a3fd35776fd2ec79e95f /lib/view.js | |
parent | 14997fb0084c642aa8b0c46c284835659f5752f7 (diff) |
Remove bluebird, figgy-pudding from several smaller commands
This mostly touches the commands that *don't* have a libnpmwhatever module
that handles their inner workings.
Still todo:
- publish (libnpmpublish)
- unpublish (also libnpmpublish)
- pack (should leverage pacote more than it does)
- audit (should use @npmcli/arborist)
- shrinkwrap (should use @npmcli/arborist)
- update (should use @npmcli/arborist)
- outdated (should use @npmcli/arborist)
- ci (should use @npmcli/arborist)
Diffstat (limited to 'lib/view.js')
-rw-r--r-- | lib/view.js | 55 |
1 files changed, 23 insertions, 32 deletions
diff --git a/lib/view.js b/lib/view.js index 8be277073..6872d8894 100644 --- a/lib/view.js +++ b/lib/view.js @@ -3,20 +3,16 @@ // npm view [pkg [pkg ...]] module.exports = view -const BB = require('bluebird') - const byteSize = require('byte-size') const color = require('ansicolors') const columns = require('cli-columns') -const npmConfig = require('./config/figgy-config.js') const log = require('npmlog') -const figgyPudding = require('figgy-pudding') const npa = require('npm-package-arg') const npm = require('./npm.js') const { packument } = require('pacote') const path = require('path') -const util = require('util') -const readJson = util.promisify(require('read-package-json')) +const { inspect, promisify } = require('util') +const readJson = promisify(require('read-package-json')) const relativeDate = require('tiny-relative-date') const semver = require('semver') const style = require('ansistyles') @@ -24,13 +20,6 @@ const usage = require('./utils/usage') const validateName = require('validate-npm-package-name') -const ViewConfig = figgyPudding({ - global: {}, - json: {}, - tag: {}, - unicode: {} -}) - view.usage = usage( 'view', 'npm view [<@scope>/]<pkg>[@<version>] [<field>[.subfield]...]' @@ -43,14 +32,14 @@ view.completion = function (opts, cb) { return cb() } // have the package, get the fields. - const config = ViewConfig(npmConfig()) - const tag = config.tag + const config = npm.flatOptions + const { defaultTag } = config const spec = npa(opts.conf.argv.remain[2]) return packument(spec, config).then(d => { - const dv = d.versions[d['dist-tags'][tag]] + const dv = d.versions[d['dist-tags'][defaultTag]] d.versions = Object.keys(d.versions).sort(semver.compareLoose) return getFields(d).concat(getFields(dv)) - }).nodeify(cb) + }).then(() => cb(), cb) function getFields (d, f, pref) { f = f || [] @@ -82,7 +71,7 @@ function view (args, silent, cb) { if (!args.length) args = ['.'] - const opts = ViewConfig(npmConfig()) + const opts = npm.flatOptions const pkg = args.shift() let nv if (/^[.]@/.test(pkg)) { @@ -99,10 +88,11 @@ function view (args, silent, cb) { if (local) { const dir = npm.prefix - BB.resolve(readJson(path.resolve(dir, 'package.json'))).nodeify((er, d) => { - d = d || {} - if (er && er.code !== 'ENOENT' && er.code !== 'ENOTDIR') return cb(er) - if (!d.name) return cb(new Error('Invalid package.json')) + readJson(path.resolve(dir, 'package.json')).catch(er => { + if (er && er.code !== 'ENOENT' && er.code !== 'ENOTDIR') throw er + return {} + }).then(d => { + if (!d || !d.name) return cb(new Error('Invalid package.json')) const p = d.name nv = npa(p) @@ -111,7 +101,7 @@ function view (args, silent, cb) { } fetchAndRead(nv, args, silent, opts, cb) - }) + }).catch(er => cb(er)) } else { fetchAndRead(nv, args, silent, opts, cb) } @@ -119,12 +109,13 @@ function view (args, silent, cb) { function fetchAndRead (nv, args, silent, opts, cb) { // get the data about this package - let version = nv.rawSpec || npm.config.get('tag') + let version = nv.rawSpec || npm.flatOptions.defaultTag - return packument(nv, opts.concat({ + return packument(nv, { + ...opts, fullMetadata: true, 'prefer-online': true - })).catch(err => { + }).catch(err => { // TODO - this should probably go into pacote, but the tests expect it. if (err.code === 'E404') { err.message = `'${nv.name}' is not in the npm registry.` @@ -195,21 +186,21 @@ function fetchAndRead (nv, args, silent, opts, cb) { args[0] === '' ) { data.version = version - return BB.all( + return Promise.all( results.map((v) => prettyView(data, v[Object.keys(v)[0]][''], opts)) ).then(() => retval) } else { - return BB.fromNode(cb => { - printData(retval, data._id, opts, cb) + return new Promise((res, rej) => { + printData(retval, data._id, opts, er => er ? rej(er) : res()) }).then(() => retval) } - }).nodeify(cb) + }).then(() => cb(), cb) } function prettyView (packument, manifest, opts) { // More modern, pretty printing of default view const unicode = opts.unicode - return BB.try(() => { + return Promise.resolve().then(() => { if (!manifest) { log.error( 'view', @@ -441,7 +432,7 @@ function printData (data, name, opts, cb) { if (opts.json) { msgJson[msgJson.length - 1][f] = d } else { - d = util.inspect(d, { showHidden: false, depth: 5, colors: npm.color, maxArrayLength: null }) + d = inspect(d, { showHidden: false, depth: 5, colors: npm.color, maxArrayLength: null }) } } else if (typeof d === 'string' && opts.json) { d = JSON.stringify(d) |