diff options
author | Forrest L Norvell <forrest@npmjs.com> | 2016-03-29 23:30:51 -0700 |
---|---|---|
committer | Myles Borins <mborins@us.ibm.com> | 2016-04-01 14:47:39 -0700 |
commit | 0928584444ac6edf1ead0b93c9d05b1124183702 (patch) | |
tree | f64c5646b8e2817009e7afe97c2670c73d38a7eb /deps/npm/lib/view.js | |
parent | 39de601e1c3eda92eb2e37eca4e6aa960f206f39 (diff) | |
download | node-new-0928584444ac6edf1ead0b93c9d05b1124183702.tar.gz |
deps: upgrade npm to 3.8.3
PR-URL: https://github.com/npm/node/pull/6
Reviewed-By: Evan Lucas <evanlucas@me.com>
Diffstat (limited to 'deps/npm/lib/view.js')
-rw-r--r-- | deps/npm/lib/view.js | 35 |
1 files changed, 27 insertions, 8 deletions
diff --git a/deps/npm/lib/view.js b/deps/npm/lib/view.js index 9ca18d3540..e6fa21655e 100644 --- a/deps/npm/lib/view.js +++ b/deps/npm/lib/view.js @@ -239,29 +239,48 @@ function search (data, fields, version, title) { function printData (data, name, cb) { var versions = Object.keys(data) var msg = '' + var msgJson = [] var includeVersions = versions.length > 1 var includeFields versions.forEach(function (v) { var fields = Object.keys(data[v]) includeFields = includeFields || (fields.length > 1) + msgJson.push({}) fields.forEach(function (f) { var d = cleanup(data[v][f]) + if (fields.length === 1 && npm.config.get('json')) { + msgJson[msgJson.length - 1][f] = d + } if (includeVersions || includeFields || typeof d !== 'string') { - d = cleanup(data[v][f]) - d = npm.config.get('json') - ? JSON.stringify(d, null, 2) - : util.inspect(d, false, 5, npm.color) + if (npm.config.get('json')) { + msgJson[msgJson.length - 1][f] = d + } else { + d = util.inspect(d, false, 5, npm.color) + } } else if (typeof d === 'string' && npm.config.get('json')) { d = JSON.stringify(d) } - if (f && includeFields) f += ' = ' - if (d.indexOf('\n') !== -1) d = ' \n' + d - msg += (includeVersions ? name + '@' + v + ' ' : '') + - (includeFields ? f : '') + d + '\n' + if (!npm.config.get('json')) { + if (f && includeFields) f += ' = ' + if (d.indexOf('\n') !== -1) d = ' \n' + d + msg += (includeVersions ? name + '@' + v + ' ' : '') + + (includeFields ? f : '') + d + '\n' + } }) }) + if (msgJson.length && Object.keys(msgJson[0]).length === 1) { + var k = Object.keys(msgJson[0])[0] + msgJson = msgJson.map(function (m) { return m[k] }) + } + + if (!msg) { + msg = JSON.stringify(msgJson[0], null, 2) + '\n' + } else if (msgJson.length > 1) { + msg = JSON.stringify(msgJson, null, 2) + '\n' + } + // preserve output symmetry by adding a whitespace-only line at the end if // there's one at the beginning if (/^\s*\n/.test(msg)) msg += '\n' |