Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/AnonR/smanonr..../lib/node_mod.../npm/lib
File: view.js
'use strict'
[0] Fix | Delete
[1] Fix | Delete
// npm view [pkg [pkg ...]]
[2] Fix | Delete
module.exports = view
[3] Fix | Delete
[4] Fix | Delete
const BB = require('bluebird')
[5] Fix | Delete
[6] Fix | Delete
const byteSize = require('byte-size')
[7] Fix | Delete
const color = require('ansicolors')
[8] Fix | Delete
const columns = require('cli-columns')
[9] Fix | Delete
const npmConfig = require('./config/figgy-config.js')
[10] Fix | Delete
const log = require('npmlog')
[11] Fix | Delete
const figgyPudding = require('figgy-pudding')
[12] Fix | Delete
const npa = require('libnpm/parse-arg')
[13] Fix | Delete
const npm = require('./npm.js')
[14] Fix | Delete
const packument = require('libnpm/packument')
[15] Fix | Delete
const path = require('path')
[16] Fix | Delete
const readJson = require('libnpm/read-json')
[17] Fix | Delete
const relativeDate = require('tiny-relative-date')
[18] Fix | Delete
const semver = require('semver')
[19] Fix | Delete
const style = require('ansistyles')
[20] Fix | Delete
const usage = require('./utils/usage')
[21] Fix | Delete
const util = require('util')
[22] Fix | Delete
const validateName = require('validate-npm-package-name')
[23] Fix | Delete
[24] Fix | Delete
const ViewConfig = figgyPudding({
[25] Fix | Delete
global: {},
[26] Fix | Delete
json: {},
[27] Fix | Delete
tag: {},
[28] Fix | Delete
unicode: {}
[29] Fix | Delete
})
[30] Fix | Delete
[31] Fix | Delete
view.usage = usage(
[32] Fix | Delete
'view',
[33] Fix | Delete
'npm view [<@scope>/]<pkg>[@<version>] [<field>[.subfield]...]'
[34] Fix | Delete
)
[35] Fix | Delete
[36] Fix | Delete
view.completion = function (opts, cb) {
[37] Fix | Delete
if (opts.conf.argv.remain.length <= 2) {
[38] Fix | Delete
// FIXME: there used to be registry completion here, but it stopped making
[39] Fix | Delete
// sense somewhere around 50,000 packages on the registry
[40] Fix | Delete
return cb()
[41] Fix | Delete
}
[42] Fix | Delete
// have the package, get the fields.
[43] Fix | Delete
const config = ViewConfig(npmConfig())
[44] Fix | Delete
const tag = config.tag
[45] Fix | Delete
const spec = npa(opts.conf.argv.remain[2])
[46] Fix | Delete
return packument(spec, config).then(d => {
[47] Fix | Delete
const dv = d.versions[d['dist-tags'][tag]]
[48] Fix | Delete
d.versions = Object.keys(d.versions).sort(semver.compareLoose)
[49] Fix | Delete
return getFields(d).concat(getFields(dv))
[50] Fix | Delete
}).nodeify(cb)
[51] Fix | Delete
[52] Fix | Delete
function getFields (d, f, pref) {
[53] Fix | Delete
f = f || []
[54] Fix | Delete
if (!d) return f
[55] Fix | Delete
pref = pref || []
[56] Fix | Delete
Object.keys(d).forEach(function (k) {
[57] Fix | Delete
if (k.charAt(0) === '_' || k.indexOf('.') !== -1) return
[58] Fix | Delete
const p = pref.concat(k).join('.')
[59] Fix | Delete
f.push(p)
[60] Fix | Delete
if (Array.isArray(d[k])) {
[61] Fix | Delete
d[k].forEach(function (val, i) {
[62] Fix | Delete
const pi = p + '[' + i + ']'
[63] Fix | Delete
if (val && typeof val === 'object') getFields(val, f, [p])
[64] Fix | Delete
else f.push(pi)
[65] Fix | Delete
})
[66] Fix | Delete
return
[67] Fix | Delete
}
[68] Fix | Delete
if (typeof d[k] === 'object') getFields(d[k], f, [p])
[69] Fix | Delete
})
[70] Fix | Delete
return f
[71] Fix | Delete
}
[72] Fix | Delete
}
[73] Fix | Delete
[74] Fix | Delete
function view (args, silent, cb) {
[75] Fix | Delete
if (typeof cb !== 'function') {
[76] Fix | Delete
cb = silent
[77] Fix | Delete
silent = false
[78] Fix | Delete
}
[79] Fix | Delete
[80] Fix | Delete
if (!args.length) args = ['.']
[81] Fix | Delete
[82] Fix | Delete
const opts = ViewConfig(npmConfig())
[83] Fix | Delete
const pkg = args.shift()
[84] Fix | Delete
let nv
[85] Fix | Delete
if (/^[.]@/.test(pkg)) {
[86] Fix | Delete
nv = npa.resolve(null, pkg.slice(2))
[87] Fix | Delete
} else {
[88] Fix | Delete
nv = npa(pkg)
[89] Fix | Delete
}
[90] Fix | Delete
const name = nv.name
[91] Fix | Delete
const local = (name === '.' || !name)
[92] Fix | Delete
[93] Fix | Delete
if (opts.global && local) {
[94] Fix | Delete
return cb(new Error('Cannot use view command in global mode.'))
[95] Fix | Delete
}
[96] Fix | Delete
[97] Fix | Delete
if (local) {
[98] Fix | Delete
const dir = npm.prefix
[99] Fix | Delete
BB.resolve(readJson(path.resolve(dir, 'package.json'))).nodeify((er, d) => {
[100] Fix | Delete
d = d || {}
[101] Fix | Delete
if (er && er.code !== 'ENOENT' && er.code !== 'ENOTDIR') return cb(er)
[102] Fix | Delete
if (!d.name) return cb(new Error('Invalid package.json'))
[103] Fix | Delete
[104] Fix | Delete
const p = d.name
[105] Fix | Delete
nv = npa(p)
[106] Fix | Delete
if (pkg && ~pkg.indexOf('@')) {
[107] Fix | Delete
nv.rawSpec = pkg.split('@')[pkg.indexOf('@')]
[108] Fix | Delete
}
[109] Fix | Delete
[110] Fix | Delete
fetchAndRead(nv, args, silent, opts, cb)
[111] Fix | Delete
})
[112] Fix | Delete
} else {
[113] Fix | Delete
fetchAndRead(nv, args, silent, opts, cb)
[114] Fix | Delete
}
[115] Fix | Delete
}
[116] Fix | Delete
[117] Fix | Delete
function fetchAndRead (nv, args, silent, opts, cb) {
[118] Fix | Delete
// get the data about this package
[119] Fix | Delete
let version = nv.rawSpec || npm.config.get('tag')
[120] Fix | Delete
[121] Fix | Delete
return packument(nv, opts.concat({
[122] Fix | Delete
fullMetadata: true,
[123] Fix | Delete
'prefer-online': true
[124] Fix | Delete
})).catch(err => {
[125] Fix | Delete
// TODO - this should probably go into pacote, but the tests expect it.
[126] Fix | Delete
if (err.code === 'E404') {
[127] Fix | Delete
err.message = `'${nv.name}' is not in the npm registry.`
[128] Fix | Delete
const validated = validateName(nv.name)
[129] Fix | Delete
if (!validated.validForNewPackages) {
[130] Fix | Delete
err.message += '\n'
[131] Fix | Delete
err.message += (validated.errors || []).join('\n')
[132] Fix | Delete
err.message += (validated.warnings || []).join('\n')
[133] Fix | Delete
} else {
[134] Fix | Delete
err.message += '\nYou should bug the author to publish it'
[135] Fix | Delete
err.message += '\n(or use the name yourself!)'
[136] Fix | Delete
err.message += '\n'
[137] Fix | Delete
err.message += '\nNote that you can also install from a'
[138] Fix | Delete
err.message += '\ntarball, folder, http url, or git url.'
[139] Fix | Delete
}
[140] Fix | Delete
}
[141] Fix | Delete
throw err
[142] Fix | Delete
}).then(data => {
[143] Fix | Delete
if (data['dist-tags'] && data['dist-tags'][version]) {
[144] Fix | Delete
version = data['dist-tags'][version]
[145] Fix | Delete
}
[146] Fix | Delete
[147] Fix | Delete
if (data.time && data.time.unpublished) {
[148] Fix | Delete
const u = data.time.unpublished
[149] Fix | Delete
let er = new Error('Unpublished by ' + u.name + ' on ' + u.time)
[150] Fix | Delete
er.statusCode = 404
[151] Fix | Delete
er.code = 'E404'
[152] Fix | Delete
er.pkgid = data._id
[153] Fix | Delete
throw er
[154] Fix | Delete
}
[155] Fix | Delete
[156] Fix | Delete
const results = []
[157] Fix | Delete
let error = null
[158] Fix | Delete
const versions = data.versions || {}
[159] Fix | Delete
data.versions = Object.keys(versions).sort(semver.compareLoose)
[160] Fix | Delete
if (!args.length) args = ['']
[161] Fix | Delete
[162] Fix | Delete
// remove readme unless we asked for it
[163] Fix | Delete
if (args.indexOf('readme') === -1) {
[164] Fix | Delete
delete data.readme
[165] Fix | Delete
}
[166] Fix | Delete
[167] Fix | Delete
Object.keys(versions).forEach(function (v) {
[168] Fix | Delete
if (semver.satisfies(v, version, true)) {
[169] Fix | Delete
args.forEach(function (args) {
[170] Fix | Delete
// remove readme unless we asked for it
[171] Fix | Delete
if (args.indexOf('readme') !== -1) {
[172] Fix | Delete
delete versions[v].readme
[173] Fix | Delete
}
[174] Fix | Delete
results.push(showFields(data, versions[v], args))
[175] Fix | Delete
})
[176] Fix | Delete
}
[177] Fix | Delete
})
[178] Fix | Delete
let retval = results.reduce(reducer, {})
[179] Fix | Delete
[180] Fix | Delete
if (args.length === 1 && args[0] === '') {
[181] Fix | Delete
retval = cleanBlanks(retval)
[182] Fix | Delete
log.silly('view', retval)
[183] Fix | Delete
}
[184] Fix | Delete
[185] Fix | Delete
if (silent) {
[186] Fix | Delete
return retval
[187] Fix | Delete
} else if (error) {
[188] Fix | Delete
throw error
[189] Fix | Delete
} else if (
[190] Fix | Delete
!opts.json &&
[191] Fix | Delete
args.length === 1 &&
[192] Fix | Delete
args[0] === ''
[193] Fix | Delete
) {
[194] Fix | Delete
data.version = version
[195] Fix | Delete
return BB.all(
[196] Fix | Delete
results.map((v) => prettyView(data, v[Object.keys(v)[0]][''], opts))
[197] Fix | Delete
).then(() => retval)
[198] Fix | Delete
} else {
[199] Fix | Delete
return BB.fromNode(cb => {
[200] Fix | Delete
printData(retval, data._id, opts, cb)
[201] Fix | Delete
}).then(() => retval)
[202] Fix | Delete
}
[203] Fix | Delete
}).nodeify(cb)
[204] Fix | Delete
}
[205] Fix | Delete
[206] Fix | Delete
function prettyView (packument, manifest, opts) {
[207] Fix | Delete
// More modern, pretty printing of default view
[208] Fix | Delete
const unicode = opts.unicode
[209] Fix | Delete
return BB.try(() => {
[210] Fix | Delete
if (!manifest) {
[211] Fix | Delete
log.error(
[212] Fix | Delete
'view',
[213] Fix | Delete
'No matching versions.\n' +
[214] Fix | Delete
'To see a list of versions, run:\n' +
[215] Fix | Delete
`> npm view ${packument.name} versions`
[216] Fix | Delete
)
[217] Fix | Delete
return
[218] Fix | Delete
}
[219] Fix | Delete
const tags = []
[220] Fix | Delete
Object.keys(packument['dist-tags']).forEach((t) => {
[221] Fix | Delete
const version = packument['dist-tags'][t]
[222] Fix | Delete
tags.push(`${style.bright(color.green(t))}: ${version}`)
[223] Fix | Delete
})
[224] Fix | Delete
const unpackedSize = manifest.dist.unpackedSize &&
[225] Fix | Delete
byteSize(manifest.dist.unpackedSize)
[226] Fix | Delete
const licenseField = manifest.license || manifest.licence || 'Proprietary'
[227] Fix | Delete
const info = {
[228] Fix | Delete
name: color.green(manifest.name),
[229] Fix | Delete
version: color.green(manifest.version),
[230] Fix | Delete
bins: Object.keys(manifest.bin || {}).map(color.yellow),
[231] Fix | Delete
versions: color.yellow(packument.versions.length + ''),
[232] Fix | Delete
description: manifest.description,
[233] Fix | Delete
deprecated: manifest.deprecated,
[234] Fix | Delete
keywords: (packument.keywords || []).map(color.yellow),
[235] Fix | Delete
license: typeof licenseField === 'string'
[236] Fix | Delete
? licenseField
[237] Fix | Delete
: (licenseField.type || 'Proprietary'),
[238] Fix | Delete
deps: Object.keys(manifest.dependencies || {}).map((dep) => {
[239] Fix | Delete
return `${color.yellow(dep)}: ${manifest.dependencies[dep]}`
[240] Fix | Delete
}),
[241] Fix | Delete
publisher: manifest._npmUser && unparsePerson({
[242] Fix | Delete
name: color.yellow(manifest._npmUser.name),
[243] Fix | Delete
email: color.cyan(manifest._npmUser.email)
[244] Fix | Delete
}),
[245] Fix | Delete
modified: packument.time ? color.yellow(relativeDate(packument.time[packument.version])) : undefined,
[246] Fix | Delete
maintainers: (packument.maintainers || []).map((u) => unparsePerson({
[247] Fix | Delete
name: color.yellow(u.name),
[248] Fix | Delete
email: color.cyan(u.email)
[249] Fix | Delete
})),
[250] Fix | Delete
repo: (
[251] Fix | Delete
manifest.bugs && (manifest.bugs.url || manifest.bugs)
[252] Fix | Delete
) || (
[253] Fix | Delete
manifest.repository && (manifest.repository.url || manifest.repository)
[254] Fix | Delete
),
[255] Fix | Delete
site: (
[256] Fix | Delete
manifest.homepage && (manifest.homepage.url || manifest.homepage)
[257] Fix | Delete
),
[258] Fix | Delete
stars: color.yellow('' + packument.users ? Object.keys(packument.users || {}).length : 0),
[259] Fix | Delete
tags,
[260] Fix | Delete
tarball: color.cyan(manifest.dist.tarball),
[261] Fix | Delete
shasum: color.yellow(manifest.dist.shasum),
[262] Fix | Delete
integrity: manifest.dist.integrity && color.yellow(manifest.dist.integrity),
[263] Fix | Delete
fileCount: manifest.dist.fileCount && color.yellow(manifest.dist.fileCount),
[264] Fix | Delete
unpackedSize: unpackedSize && color.yellow(unpackedSize.value) + ' ' + unpackedSize.unit
[265] Fix | Delete
}
[266] Fix | Delete
if (info.license.toLowerCase().trim() === 'proprietary') {
[267] Fix | Delete
info.license = style.bright(color.red(info.license))
[268] Fix | Delete
} else {
[269] Fix | Delete
info.license = color.green(info.license)
[270] Fix | Delete
}
[271] Fix | Delete
console.log('')
[272] Fix | Delete
console.log(
[273] Fix | Delete
style.underline(style.bright(`${info.name}@${info.version}`)) +
[274] Fix | Delete
' | ' + info.license +
[275] Fix | Delete
' | deps: ' + (info.deps.length ? color.cyan(info.deps.length) : color.green('none')) +
[276] Fix | Delete
' | versions: ' + info.versions
[277] Fix | Delete
)
[278] Fix | Delete
info.description && console.log(info.description)
[279] Fix | Delete
if (info.repo || info.site) {
[280] Fix | Delete
info.site && console.log(color.cyan(info.site))
[281] Fix | Delete
}
[282] Fix | Delete
[283] Fix | Delete
const warningSign = unicode ? ' ⚠️ ' : '!!'
[284] Fix | Delete
info.deprecated && console.log(
[285] Fix | Delete
`\n${style.bright(color.red('DEPRECATED'))}${
[286] Fix | Delete
warningSign
[287] Fix | Delete
} - ${info.deprecated}`
[288] Fix | Delete
)
[289] Fix | Delete
[290] Fix | Delete
if (info.keywords.length) {
[291] Fix | Delete
console.log('')
[292] Fix | Delete
console.log('keywords:', info.keywords.join(', '))
[293] Fix | Delete
}
[294] Fix | Delete
[295] Fix | Delete
if (info.bins.length) {
[296] Fix | Delete
console.log('')
[297] Fix | Delete
console.log('bin:', info.bins.join(', '))
[298] Fix | Delete
}
[299] Fix | Delete
[300] Fix | Delete
console.log('')
[301] Fix | Delete
console.log('dist')
[302] Fix | Delete
console.log('.tarball:', info.tarball)
[303] Fix | Delete
console.log('.shasum:', info.shasum)
[304] Fix | Delete
info.integrity && console.log('.integrity:', info.integrity)
[305] Fix | Delete
info.unpackedSize && console.log('.unpackedSize:', info.unpackedSize)
[306] Fix | Delete
[307] Fix | Delete
const maxDeps = 24
[308] Fix | Delete
if (info.deps.length) {
[309] Fix | Delete
console.log('')
[310] Fix | Delete
console.log('dependencies:')
[311] Fix | Delete
console.log(columns(info.deps.slice(0, maxDeps), {padding: 1}))
[312] Fix | Delete
if (info.deps.length > maxDeps) {
[313] Fix | Delete
console.log(`(...and ${info.deps.length - maxDeps} more.)`)
[314] Fix | Delete
}
[315] Fix | Delete
}
[316] Fix | Delete
[317] Fix | Delete
if (info.maintainers && info.maintainers.length) {
[318] Fix | Delete
console.log('')
[319] Fix | Delete
console.log('maintainers:')
[320] Fix | Delete
info.maintainers.forEach((u) => console.log('-', u))
[321] Fix | Delete
}
[322] Fix | Delete
[323] Fix | Delete
console.log('')
[324] Fix | Delete
console.log('dist-tags:')
[325] Fix | Delete
console.log(columns(info.tags))
[326] Fix | Delete
[327] Fix | Delete
if (info.publisher || info.modified) {
[328] Fix | Delete
let publishInfo = 'published'
[329] Fix | Delete
if (info.modified) { publishInfo += ` ${info.modified}` }
[330] Fix | Delete
if (info.publisher) { publishInfo += ` by ${info.publisher}` }
[331] Fix | Delete
console.log('')
[332] Fix | Delete
console.log(publishInfo)
[333] Fix | Delete
}
[334] Fix | Delete
})
[335] Fix | Delete
}
[336] Fix | Delete
[337] Fix | Delete
function cleanBlanks (obj) {
[338] Fix | Delete
const clean = {}
[339] Fix | Delete
Object.keys(obj).forEach(function (version) {
[340] Fix | Delete
clean[version] = obj[version]['']
[341] Fix | Delete
})
[342] Fix | Delete
return clean
[343] Fix | Delete
}
[344] Fix | Delete
[345] Fix | Delete
function reducer (l, r) {
[346] Fix | Delete
if (r) {
[347] Fix | Delete
Object.keys(r).forEach(function (v) {
[348] Fix | Delete
l[v] = l[v] || {}
[349] Fix | Delete
Object.keys(r[v]).forEach(function (t) {
[350] Fix | Delete
l[v][t] = r[v][t]
[351] Fix | Delete
})
[352] Fix | Delete
})
[353] Fix | Delete
}
[354] Fix | Delete
[355] Fix | Delete
return l
[356] Fix | Delete
}
[357] Fix | Delete
[358] Fix | Delete
// return whatever was printed
[359] Fix | Delete
function showFields (data, version, fields) {
[360] Fix | Delete
const o = {}
[361] Fix | Delete
;[data, version].forEach(function (s) {
[362] Fix | Delete
Object.keys(s).forEach(function (k) {
[363] Fix | Delete
o[k] = s[k]
[364] Fix | Delete
})
[365] Fix | Delete
})
[366] Fix | Delete
return search(o, fields.split('.'), version.version, fields)
[367] Fix | Delete
}
[368] Fix | Delete
[369] Fix | Delete
function search (data, fields, version, title) {
[370] Fix | Delete
let field
[371] Fix | Delete
const tail = fields
[372] Fix | Delete
while (!field && fields.length) field = tail.shift()
[373] Fix | Delete
fields = [field].concat(tail)
[374] Fix | Delete
let o
[375] Fix | Delete
if (!field && !tail.length) {
[376] Fix | Delete
o = {}
[377] Fix | Delete
o[version] = {}
[378] Fix | Delete
o[version][title] = data
[379] Fix | Delete
return o
[380] Fix | Delete
}
[381] Fix | Delete
let index = field.match(/(.+)\[([^\]]+)\]$/)
[382] Fix | Delete
if (index) {
[383] Fix | Delete
field = index[1]
[384] Fix | Delete
index = index[2]
[385] Fix | Delete
if (data.field && data.field.hasOwnProperty(index)) {
[386] Fix | Delete
return search(data[field][index], tail, version, title)
[387] Fix | Delete
} else {
[388] Fix | Delete
field = field + '[' + index + ']'
[389] Fix | Delete
}
[390] Fix | Delete
}
[391] Fix | Delete
if (Array.isArray(data)) {
[392] Fix | Delete
if (data.length === 1) {
[393] Fix | Delete
return search(data[0], fields, version, title)
[394] Fix | Delete
}
[395] Fix | Delete
let results = []
[396] Fix | Delete
data.forEach(function (data, i) {
[397] Fix | Delete
const tl = title.length
[398] Fix | Delete
const newt = title.substr(0, tl - fields.join('.').length - 1) +
[399] Fix | Delete
'[' + i + ']' + [''].concat(fields).join('.')
[400] Fix | Delete
results.push(search(data, fields.slice(), version, newt))
[401] Fix | Delete
})
[402] Fix | Delete
results = results.reduce(reducer, {})
[403] Fix | Delete
return results
[404] Fix | Delete
}
[405] Fix | Delete
if (!data.hasOwnProperty(field)) return undefined
[406] Fix | Delete
data = data[field]
[407] Fix | Delete
if (tail.length) {
[408] Fix | Delete
if (typeof data === 'object') {
[409] Fix | Delete
// there are more fields to deal with.
[410] Fix | Delete
return search(data, tail, version, title)
[411] Fix | Delete
} else {
[412] Fix | Delete
return new Error('Not an object: ' + data)
[413] Fix | Delete
}
[414] Fix | Delete
}
[415] Fix | Delete
o = {}
[416] Fix | Delete
o[version] = {}
[417] Fix | Delete
o[version][title] = data
[418] Fix | Delete
return o
[419] Fix | Delete
}
[420] Fix | Delete
[421] Fix | Delete
function printData (data, name, opts, cb) {
[422] Fix | Delete
const versions = Object.keys(data)
[423] Fix | Delete
let msg = ''
[424] Fix | Delete
let msgJson = []
[425] Fix | Delete
const includeVersions = versions.length > 1
[426] Fix | Delete
let includeFields
[427] Fix | Delete
[428] Fix | Delete
versions.forEach(function (v) {
[429] Fix | Delete
const fields = Object.keys(data[v])
[430] Fix | Delete
includeFields = includeFields || (fields.length > 1)
[431] Fix | Delete
if (opts.json) msgJson.push({})
[432] Fix | Delete
fields.forEach(function (f) {
[433] Fix | Delete
let d = cleanup(data[v][f])
[434] Fix | Delete
if (fields.length === 1 && opts.json) {
[435] Fix | Delete
msgJson[msgJson.length - 1][f] = d
[436] Fix | Delete
}
[437] Fix | Delete
if (includeVersions || includeFields || typeof d !== 'string') {
[438] Fix | Delete
if (opts.json) {
[439] Fix | Delete
msgJson[msgJson.length - 1][f] = d
[440] Fix | Delete
} else {
[441] Fix | Delete
d = util.inspect(d, { showHidden: false, depth: 5, colors: npm.color, maxArrayLength: null })
[442] Fix | Delete
}
[443] Fix | Delete
} else if (typeof d === 'string' && opts.json) {
[444] Fix | Delete
d = JSON.stringify(d)
[445] Fix | Delete
}
[446] Fix | Delete
if (!opts.json) {
[447] Fix | Delete
if (f && includeFields) f += ' = '
[448] Fix | Delete
if (d.indexOf('\n') !== -1) d = ' \n' + d
[449] Fix | Delete
msg += (includeVersions ? name + '@' + v + ' ' : '') +
[450] Fix | Delete
(includeFields ? f : '') + d + '\n'
[451] Fix | Delete
}
[452] Fix | Delete
})
[453] Fix | Delete
})
[454] Fix | Delete
[455] Fix | Delete
if (opts.json) {
[456] Fix | Delete
if (msgJson.length && Object.keys(msgJson[0]).length === 1) {
[457] Fix | Delete
const k = Object.keys(msgJson[0])[0]
[458] Fix | Delete
msgJson = msgJson.map(function (m) { return m[k] })
[459] Fix | Delete
}
[460] Fix | Delete
[461] Fix | Delete
if (msgJson.length === 1) {
[462] Fix | Delete
msg = JSON.stringify(msgJson[0], null, 2) + '\n'
[463] Fix | Delete
} else if (msgJson.length > 1) {
[464] Fix | Delete
msg = JSON.stringify(msgJson, null, 2) + '\n'
[465] Fix | Delete
}
[466] Fix | Delete
}
[467] Fix | Delete
[468] Fix | Delete
// preserve output symmetry by adding a whitespace-only line at the end if
[469] Fix | Delete
// there's one at the beginning
[470] Fix | Delete
if (/^\s*\n/.test(msg)) msg += '\n'
[471] Fix | Delete
[472] Fix | Delete
// disable the progress bar entirely, as we can't meaningfully update it if
[473] Fix | Delete
// we may have partial lines printed.
[474] Fix | Delete
log.disableProgress()
[475] Fix | Delete
[476] Fix | Delete
// print directly to stdout to not unnecessarily add blank lines
[477] Fix | Delete
process.stdout.write(msg, () => cb(null, data))
[478] Fix | Delete
}
[479] Fix | Delete
function cleanup (data) {
[480] Fix | Delete
if (Array.isArray(data)) {
[481] Fix | Delete
return data.map(cleanup)
[482] Fix | Delete
}
[483] Fix | Delete
if (!data || typeof data !== 'object') return data
[484] Fix | Delete
[485] Fix | Delete
if (typeof data.versions === 'object' &&
[486] Fix | Delete
data.versions &&
[487] Fix | Delete
!Array.isArray(data.versions)) {
[488] Fix | Delete
data.versions = Object.keys(data.versions || {})
[489] Fix | Delete
}
[490] Fix | Delete
[491] Fix | Delete
let keys = Object.keys(data)
[492] Fix | Delete
keys.forEach(function (d) {
[493] Fix | Delete
if (d.charAt(0) === '_') delete data[d]
[494] Fix | Delete
else if (typeof data[d] === 'object') data[d] = cleanup(data[d])
[495] Fix | Delete
})
[496] Fix | Delete
keys = Object.keys(data)
[497] Fix | Delete
if (keys.length <= 3 &&
[498] Fix | Delete
data.name &&
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function