Skip to content

Commit 69f5ff8

Browse files
committed
fix(view): convert command to use output instead of console
1 parent dc52222 commit 69f5ff8

File tree

2 files changed

+126
-137
lines changed

2 files changed

+126
-137
lines changed

lib/commands/view.js

Lines changed: 31 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
/* eslint-disable no-console */
2-
// XXX: remove console.log later
3-
4-
// npm view [pkg [pkg ...]]
5-
61
const chalk = require('chalk')
72
const columns = require('cli-columns')
83
const fs = require('fs')
@@ -127,7 +122,7 @@ class View extends BaseCommand {
127122

128123
const msg = await this.jsonData(reducedData, pckmnt._id)
129124
if (msg !== '') {
130-
console.log(msg)
125+
this.npm.output(msg)
131126
}
132127
}
133128
}
@@ -166,10 +161,10 @@ class View extends BaseCommand {
166161
if (wholePackument) {
167162
data.map((v) => this.prettyView(pckmnt, v[Object.keys(v)[0]]['']))
168163
} else {
169-
console.log(`${name}:`)
164+
this.npm.output(`${name}:`)
170165
const msg = await this.jsonData(reducedData, pckmnt._id)
171166
if (msg !== '') {
172-
console.log(msg)
167+
this.npm.output(msg)
173168
}
174169
}
175170
} else {
@@ -180,7 +175,7 @@ class View extends BaseCommand {
180175
}
181176
}
182177
if (Object.keys(results).length > 0) {
183-
console.log(JSON.stringify(results, null, 2))
178+
this.npm.output(JSON.stringify(results, null, 2))
184179
}
185180
}
186181

@@ -376,61 +371,61 @@ class View extends BaseCommand {
376371
info.license = chalk.green(info.license)
377372
}
378373

379-
console.log('')
380-
console.log(
374+
this.npm.output('')
375+
this.npm.output(
381376
chalk.underline.bold(`${info.name}@${info.version}`) +
382377
' | ' + info.license +
383378
' | deps: ' + (info.deps.length ? chalk.cyan(info.deps.length) : chalk.green('none')) +
384379
' | versions: ' + info.versions
385380
)
386-
info.description && console.log(info.description)
381+
info.description && this.npm.output(info.description)
387382
if (info.repo || info.site) {
388-
info.site && console.log(chalk.cyan(info.site))
383+
info.site && this.npm.output(chalk.cyan(info.site))
389384
}
390385

391386
const warningSign = unicode ? ' ⚠️ ' : '!!'
392-
info.deprecated && console.log(
387+
info.deprecated && this.npm.output(
393388
`\n${chalk.bold.red('DEPRECATED')}${
394389
warningSign
395390
} - ${info.deprecated}`
396391
)
397392

398393
if (info.keywords.length) {
399-
console.log('')
400-
console.log('keywords:', chalk.yellow(info.keywords.join(', ')))
394+
this.npm.output('')
395+
this.npm.output('keywords:', chalk.yellow(info.keywords.join(', ')))
401396
}
402397

403398
if (info.bins.length) {
404-
console.log('')
405-
console.log('bin:', chalk.yellow(info.bins.join(', ')))
399+
this.npm.output('')
400+
this.npm.output('bin:', chalk.yellow(info.bins.join(', ')))
406401
}
407402

408-
console.log('')
409-
console.log('dist')
410-
console.log('.tarball:', info.tarball)
411-
console.log('.shasum:', info.shasum)
412-
info.integrity && console.log('.integrity:', info.integrity)
413-
info.unpackedSize && console.log('.unpackedSize:', info.unpackedSize)
403+
this.npm.output('')
404+
this.npm.output('dist')
405+
this.npm.output('.tarball:', info.tarball)
406+
this.npm.output('.shasum:', info.shasum)
407+
info.integrity && this.npm.output('.integrity:', info.integrity)
408+
info.unpackedSize && this.npm.output('.unpackedSize:', info.unpackedSize)
414409

415410
const maxDeps = 24
416411
if (info.deps.length) {
417-
console.log('')
418-
console.log('dependencies:')
419-
console.log(columns(info.deps.slice(0, maxDeps), { padding: 1 }))
412+
this.npm.output('')
413+
this.npm.output('dependencies:')
414+
this.npm.output(columns(info.deps.slice(0, maxDeps), { padding: 1 }))
420415
if (info.deps.length > maxDeps) {
421-
console.log(`(...and ${info.deps.length - maxDeps} more.)`)
416+
this.npm.output(`(...and ${info.deps.length - maxDeps} more.)`)
422417
}
423418
}
424419

425420
if (info.maintainers && info.maintainers.length) {
426-
console.log('')
427-
console.log('maintainers:')
428-
info.maintainers.forEach((u) => console.log('-', u))
421+
this.npm.output('')
422+
this.npm.output('maintainers:')
423+
info.maintainers.forEach((u) => this.npm.output('-', u))
429424
}
430425

431-
console.log('')
432-
console.log('dist-tags:')
433-
console.log(columns(info.tags))
426+
this.npm.output('')
427+
this.npm.output('dist-tags:')
428+
this.npm.output(columns(info.tags))
434429

435430
if (info.publisher || info.modified) {
436431
let publishInfo = 'published'
@@ -440,8 +435,8 @@ class View extends BaseCommand {
440435
if (info.publisher) {
441436
publishInfo += ` by ${info.publisher}`
442437
}
443-
console.log('')
444-
console.log(publishInfo)
438+
this.npm.output('')
439+
this.npm.output(publishInfo)
445440
}
446441
}
447442
}

0 commit comments

Comments
 (0)