Skip to content

Commit 9216d59

Browse files
authored
fix: better output colors (#7377)
No more grey, no more setting background color. Added the beginnings of guidance to the display layer comments.
1 parent 38ed048 commit 9216d59

24 files changed

+570
-639
lines changed

lib/commands/audit.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ class VerifySignatures {
104104
}
105105

106106
if (missing.length) {
107-
const missingClr = this.npm.chalk.bold(this.npm.chalk.red('missing'))
107+
const missingClr = this.npm.chalk.redBright('missing')
108108
if (missing.length === 1) {
109109
/* eslint-disable-next-line max-len */
110110
output.standard(`1 package has a ${missingClr} registry signature but the registry is providing signing keys:`)
@@ -122,7 +122,7 @@ class VerifySignatures {
122122
if (missing.length) {
123123
output.standard('')
124124
}
125-
const invalidClr = this.npm.chalk.bold(this.npm.chalk.red('invalid'))
125+
const invalidClr = this.npm.chalk.redBright('invalid')
126126
// We can have either invalid signatures or invalid provenance
127127
const invalidSignatures = this.invalid.filter(i => i.code === 'EINTEGRITYSIGNATURE')
128128
if (invalidSignatures.length) {

lib/commands/doctor.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ class Doctor extends BaseCommand {
135135
allOk = false
136136
item[0] = this.npm.chalk.red(item[0])
137137
item[1] = this.npm.chalk.red('not ok')
138-
item[2] = this.npm.chalk.magenta(String(item[2]))
138+
item[2] = this.npm.chalk.cyan(String(item[2]))
139139
} else {
140140
item[1] = this.npm.chalk.green('ok')
141141
}

lib/commands/fund.js

+16-17
Original file line numberDiff line numberDiff line change
@@ -111,26 +111,25 @@ class Fund extends ArboristWorkspaceCmd {
111111
const [fundingSource] = [].concat(normalizeFunding(funding)).filter(isValidFunding)
112112
const { url } = fundingSource || {}
113113
const pkgRef = getPrintableName({ name, version })
114-
let item = {
115-
label: pkgRef,
116-
}
117114

118-
if (url) {
119-
item.label = tree({
120-
label: this.npm.chalk.bgBlack.white(url),
115+
if (!url) {
116+
return { label: pkgRef }
117+
}
118+
let item
119+
if (seenUrls.has(url)) {
120+
item = seenUrls.get(url)
121+
item.label += `${this.npm.chalk.dim(',')} ${pkgRef}`
122+
return null
123+
}
124+
item = {
125+
label: tree({
126+
label: this.npm.chalk.blue(url),
121127
nodes: [pkgRef],
122-
}).trim()
123-
124-
// stacks all packages together under the same item
125-
if (seenUrls.has(url)) {
126-
item = seenUrls.get(url)
127-
item.label += `, ${pkgRef}`
128-
return null
129-
} else {
130-
seenUrls.set(url, item)
131-
}
128+
}).trim(),
132129
}
133130

131+
// stacks all packages together under the same item
132+
seenUrls.set(url, item)
134133
return item
135134
},
136135

@@ -154,7 +153,7 @@ class Fund extends ArboristWorkspaceCmd {
154153
})
155154

156155
const res = tree(result)
157-
return this.npm.chalk.reset(res)
156+
return res
158157
}
159158

160159
async openFundingUrl ({ path, tree, spec, fundingSourceNumber }) {

lib/commands/help-search.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,7 @@ class HelpSearch extends BaseCommand {
170170
for (const f of finder) {
171171
hilitLine.push(line.slice(p, p + f.length))
172172
const word = line.slice(p + f.length, p + f.length + arg.length)
173-
const hilit = this.npm.chalk.bgBlack.red(word)
174-
hilitLine.push(hilit)
173+
hilitLine.push(this.npm.chalk.blue(word))
175174
p += f.length + arg.length
176175
}
177176
}

lib/commands/ls.js

+10-8
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ const augmentItemWithIncludeMetadata = (node, item) => {
280280

281281
const getHumanOutputItem = (node, { args, chalk, global, long }) => {
282282
const { pkgid, path } = node
283-
const workspacePkgId = chalk.green(pkgid)
283+
const workspacePkgId = chalk.blueBright(pkgid)
284284
let printable = node.isWorkspace ? workspacePkgId : pkgid
285285

286286
// special formatting for top-level package name
@@ -293,10 +293,12 @@ const getHumanOutputItem = (node, { args, chalk, global, long }) => {
293293
}
294294
}
295295

296+
// TODO there is a LOT of overlap with lib/utils/explain-dep.js here
297+
296298
const highlightDepName = args.length && node[_filteredBy]
297299
const missingColor = isOptional(node)
298-
? chalk.yellow.bgBlack
299-
: chalk.red.bgBlack
300+
? chalk.yellow
301+
: chalk.red
300302
const missingMsg = `UNMET ${isOptional(node) ? 'OPTIONAL ' : ''}DEPENDENCY`
301303
const targetLocation = node.root
302304
? relative(node.root.realpath, node.realpath)
@@ -310,25 +312,25 @@ const getHumanOutputItem = (node, { args, chalk, global, long }) => {
310312
? missingColor(missingMsg) + ' '
311313
: ''
312314
) +
313-
`${highlightDepName ? chalk.yellow.bgBlack(printable) : printable}` +
315+
`${highlightDepName ? chalk.yellow(printable) : printable}` +
314316
(
315317
node[_dedupe]
316-
? ' ' + chalk.gray('deduped')
318+
? ' ' + chalk.dim('deduped')
317319
: ''
318320
) +
319321
(
320322
invalid
321-
? ' ' + chalk.red.bgBlack(invalid)
323+
? ' ' + chalk.red(invalid)
322324
: ''
323325
) +
324326
(
325327
isExtraneous(node, { global })
326-
? ' ' + chalk.green.bgBlack('extraneous')
328+
? ' ' + chalk.red('extraneous')
327329
: ''
328330
) +
329331
(
330332
node.overridden
331-
? ' ' + chalk.gray('overridden')
333+
? ' ' + chalk.dim('overridden')
332334
: ''
333335
) +
334336
(isGitNode(node) ? ` (${node.resolved})` : '') +

lib/commands/outdated.js

+11-8
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ class Outdated extends ArboristWorkspaceCmd {
102102
}
103103
const outTable = [outHead].concat(outList)
104104

105-
outTable[0] = outTable[0].map(heading => this.npm.chalk.underline(heading))
105+
outTable[0] = outTable[0].map(heading => this.npm.chalk.bold.underline(heading))
106106

107107
const tableOpts = {
108108
align: ['l', 'r', 'r', 'r', 'l'],
@@ -278,7 +278,7 @@ class Outdated extends ArboristWorkspaceCmd {
278278
: node.name
279279

280280
return humanOutput
281-
? this.npm.chalk.green(workspaceName)
281+
? this.npm.chalk.blue(workspaceName)
282282
: workspaceName
283283
}
284284

@@ -295,17 +295,20 @@ class Outdated extends ArboristWorkspaceCmd {
295295
dependent,
296296
} = dep
297297

298-
const columns = [name, current, wanted, latest, location, dependent]
298+
const columns = [
299+
this.npm.chalk[current === wanted ? 'yellow' : 'red'](name),
300+
current,
301+
this.npm.chalk.cyan(wanted),
302+
this.npm.chalk.blue(latest),
303+
location,
304+
dependent,
305+
]
299306

300307
if (this.npm.config.get('long')) {
301308
columns[6] = type
302-
columns[7] = homepage
309+
columns[7] = this.npm.chalk.blue(homepage)
303310
}
304311

305-
columns[0] = this.npm.chalk[current === wanted ? 'yellow' : 'red'](columns[0]) // current
306-
columns[2] = this.npm.chalk.green(columns[2]) // wanted
307-
columns[3] = this.npm.chalk.magenta(columns[3]) // latest
308-
309312
return columns
310313
}
311314

lib/commands/publish.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ class Publish extends BaseCommand {
169169
log.warn(
170170
'publish',
171171
`Skipping workspace ${
172-
this.npm.chalk.green(name)
172+
this.npm.chalk.cyan(name)
173173
}, marked as ${
174174
this.npm.chalk.bold('private')
175175
}`

lib/commands/view.js

+64-100
Original file line numberDiff line numberDiff line change
@@ -318,125 +318,89 @@ class View extends BaseCommand {
318318
// More modern, pretty printing of default view
319319
const unicode = this.npm.config.get('unicode')
320320
const chalk = this.npm.chalk
321-
const tags = []
322-
323-
Object.keys(packu['dist-tags']).forEach((t) => {
324-
const version = packu['dist-tags'][t]
325-
tags.push(`${chalk.bold.green(t)}: ${version}`)
326-
})
327-
const unpackedSize = manifest.dist.unpackedSize &&
328-
formatBytes(manifest.dist.unpackedSize, true)
321+
const deps = Object.keys(manifest.dependencies || {}).map((dep) =>
322+
`${chalk.blue(dep)}: ${manifest.dependencies[dep]}`
323+
)
324+
const site = manifest.homepage?.url || manifest.homepage
325+
const bins = Object.keys(manifest.bin || {})
329326
const licenseField = manifest.license || 'Proprietary'
330-
const info = {
331-
name: chalk.green(manifest.name),
332-
version: chalk.green(manifest.version),
333-
bins: Object.keys(manifest.bin || {}),
334-
versions: chalk.yellow(packu.versions.length + ''),
335-
description: manifest.description,
336-
deprecated: manifest.deprecated,
337-
keywords: packu.keywords || [],
338-
license: typeof licenseField === 'string'
339-
? licenseField
340-
: (licenseField.type || 'Proprietary'),
341-
deps: Object.keys(manifest.dependencies || {}).map((dep) => {
342-
return `${chalk.yellow(dep)}: ${manifest.dependencies[dep]}`
343-
}),
344-
publisher: manifest._npmUser && unparsePerson({
345-
name: chalk.yellow(manifest._npmUser.name),
346-
email: chalk.cyan(manifest._npmUser.email),
347-
}),
348-
modified: !packu.time ? undefined
349-
: chalk.yellow(relativeDate(packu.time[manifest.version])),
350-
maintainers: (packu.maintainers || []).map((u) => unparsePerson({
351-
name: chalk.yellow(u.name),
352-
email: chalk.cyan(u.email),
353-
})),
354-
repo: (
355-
manifest.bugs && (manifest.bugs.url || manifest.bugs)
356-
) || (
357-
manifest.repository && (manifest.repository.url || manifest.repository)
358-
),
359-
site: (
360-
manifest.homepage && (manifest.homepage.url || manifest.homepage)
361-
),
362-
tags,
363-
tarball: chalk.cyan(manifest.dist.tarball),
364-
shasum: chalk.yellow(manifest.dist.shasum),
365-
integrity:
366-
manifest.dist.integrity && chalk.yellow(manifest.dist.integrity),
367-
fileCount:
368-
manifest.dist.fileCount && chalk.yellow(manifest.dist.fileCount),
369-
unpackedSize: unpackedSize && chalk.yellow(unpackedSize),
370-
}
371-
if (info.license.toLowerCase().trim() === 'proprietary') {
372-
info.license = chalk.bold.red(info.license)
373-
} else {
374-
info.license = chalk.green(info.license)
375-
}
327+
const license = typeof licenseField === 'string'
328+
? licenseField
329+
: (licenseField.type || 'Proprietary')
376330

377331
output.standard('')
378-
output.standard(
379-
chalk.underline.bold(`${info.name}@${info.version}`) +
380-
' | ' + info.license +
381-
' | deps: ' + (info.deps.length ? chalk.cyan(info.deps.length) : chalk.green('none')) +
382-
' | versions: ' + info.versions
383-
)
384-
info.description && output.standard(info.description)
385-
if (info.repo || info.site) {
386-
info.site && output.standard(chalk.cyan(info.site))
332+
output.standard([
333+
chalk.underline.cyan(`${manifest.name}@${manifest.version}`),
334+
license.toLowerCase().trim() === 'proprietary'
335+
? chalk.red(license)
336+
: chalk.green(license),
337+
`deps: ${deps.length ? chalk.cyan(deps.length) : chalk.cyan('none')}`,
338+
`versions: ${chalk.cyan(packu.versions.length + '')}`,
339+
].join(' | '))
340+
341+
manifest.description && output.standard(manifest.description)
342+
if (site) {
343+
output.standard(chalk.blue(site))
387344
}
388345

389-
const warningSign = unicode ? ' ⚠️ ' : '!!'
390-
info.deprecated && output.standard(
391-
`\n${chalk.bold.red('DEPRECATED')}${
392-
warningSign
393-
} - ${info.deprecated}`
346+
manifest.deprecated && output.standard(
347+
`\n${chalk.redBright('DEPRECATED')}${unicode ? ' ⚠️ ' : '!!'} - ${manifest.deprecated}`
394348
)
395349

396-
if (info.keywords.length) {
397-
output.standard('')
398-
output.standard(`keywords: ${chalk.yellow(info.keywords.join(', '))}`)
350+
if (packu.keywords?.length) {
351+
output.standard(`\nkeywords: ${
352+
packu.keywords.map(k => chalk.cyan(k)).join(', ')
353+
}`)
399354
}
400355

401-
if (info.bins.length) {
402-
output.standard('')
403-
output.standard(`bin: ${chalk.yellow(info.bins.join(', '))}`)
356+
if (bins.length) {
357+
output.standard(`\nbin: ${chalk.cyan(bins.join(', '))}`)
404358
}
405359

406-
output.standard('')
407-
output.standard('dist')
408-
output.standard(`.tarball: ${info.tarball}`)
409-
output.standard(`.shasum: ${info.shasum}`)
410-
info.integrity && output.standard(`.integrity: ${info.integrity}`)
411-
info.unpackedSize && output.standard(`.unpackedSize: ${info.unpackedSize}`)
412-
413-
const maxDeps = 24
414-
if (info.deps.length) {
415-
output.standard('')
416-
output.standard('dependencies:')
417-
output.standard(columns(info.deps.slice(0, maxDeps), { padding: 1 }))
418-
if (info.deps.length > maxDeps) {
419-
output.standard(`(...and ${info.deps.length - maxDeps} more.)`)
360+
output.standard('\ndist')
361+
output.standard(`.tarball: ${chalk.blue(manifest.dist.tarball)}`)
362+
output.standard(`.shasum: ${chalk.green(manifest.dist.shasum)}`)
363+
if (manifest.dist.integrity) {
364+
output.standard(`.integrity: ${chalk.green(manifest.dist.integrity)}`)
365+
}
366+
if (manifest.dist.unpackedSize) {
367+
output.standard(`.unpackedSize: ${chalk.blue(formatBytes(manifest.dist.unpackedSize, true))}`)
368+
}
369+
370+
if (deps.length) {
371+
const maxDeps = 24
372+
output.standard('\ndependencies:')
373+
output.standard(columns(deps.slice(0, maxDeps), { padding: 1 }))
374+
if (deps.length > maxDeps) {
375+
output.standard(chalk.dim(`(...and ${deps.length - maxDeps} more.)`))
420376
}
421377
}
422378

423-
if (info.maintainers && info.maintainers.length) {
424-
output.standard('')
425-
output.standard('maintainers:')
426-
info.maintainers.forEach((u) => output.standard(`- ${u}`))
379+
if (packu.maintainers?.length) {
380+
output.standard('\nmaintainers:')
381+
packu.maintainers.forEach(u =>
382+
output.standard(`- ${unparsePerson({
383+
name: chalk.blue(u.name),
384+
email: chalk.dim(u.email) })}`)
385+
)
427386
}
428387

429-
output.standard('')
430-
output.standard('dist-tags:')
431-
output.standard(columns(info.tags))
388+
output.standard('\ndist-tags:')
389+
output.standard(columns(Object.keys(packu['dist-tags']).map(t =>
390+
`${chalk.blue(t)}: ${packu['dist-tags'][t]}`
391+
)))
432392

433-
if (info.publisher || info.modified) {
393+
const publisher = manifest._npmUser && unparsePerson({
394+
name: chalk.blue(manifest._npmUser.name),
395+
email: chalk.dim(manifest._npmUser.email),
396+
})
397+
if (publisher || packu.time) {
434398
let publishInfo = 'published'
435-
if (info.modified) {
436-
publishInfo += ` ${info.modified}`
399+
if (packu.time) {
400+
publishInfo += ` ${chalk.cyan(relativeDate(packu.time[manifest.version]))}`
437401
}
438-
if (info.publisher) {
439-
publishInfo += ` by ${info.publisher}`
402+
if (publisher) {
403+
publishInfo += ` by ${publisher}`
440404
}
441405
output.standard('')
442406
output.standard(publishInfo)

0 commit comments

Comments
 (0)