Skip to content

Commit 3eaf7c2

Browse files
committed
fix: better output colors
No more grey, no more setting background colors
1 parent 9622597 commit 3eaf7c2

24 files changed

Lines changed: 570 additions & 639 deletions

lib/commands/audit.js

Lines changed: 2 additions & 2 deletions
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
this.npm.output(`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
this.npm.output('')
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -110,26 +110,25 @@ class Fund extends ArboristWorkspaceCmd {
110110
const [fundingSource] = [].concat(normalizeFunding(funding)).filter(isValidFunding)
111111
const { url } = fundingSource || {}
112112
const pkgRef = getPrintableName({ name, version })
113-
let item = {
114-
label: pkgRef,
115-
}
116113

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

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

@@ -153,7 +152,7 @@ class Fund extends ArboristWorkspaceCmd {
153152
})
154153

155154
const res = tree(result)
156-
return this.npm.chalk.reset(res)
155+
return res
157156
}
158157

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

lib/commands/help-search.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,7 @@ class HelpSearch extends BaseCommand {
169169
for (const f of finder) {
170170
hilitLine.push(line.slice(p, p + f.length))
171171
const word = line.slice(p + f.length, p + f.length + arg.length)
172-
const hilit = this.npm.chalk.bgBlack.red(word)
173-
hilitLine.push(hilit)
172+
hilitLine.push(this.npm.chalk.blue(word))
174173
p += f.length + arg.length
175174
}
176175
}

lib/commands/ls.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ const augmentItemWithIncludeMetadata = (node, item) => {
279279

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

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

295+
// TODO there is a LOT of overlap with lib/utils/explain-dep.js here
296+
295297
const highlightDepName = args.length && node[_filteredBy]
296298
const missingColor = isOptional(node)
297-
? chalk.yellow.bgBlack
298-
: chalk.red.bgBlack
299+
? chalk.yellow
300+
: chalk.red
299301
const missingMsg = `UNMET ${isOptional(node) ? 'OPTIONAL ' : ''}DEPENDENCY`
300302
const targetLocation = node.root
301303
? relative(node.root.realpath, node.realpath)
@@ -309,25 +311,25 @@ const getHumanOutputItem = (node, { args, chalk, global, long }) => {
309311
? missingColor(missingMsg) + ' '
310312
: ''
311313
) +
312-
`${highlightDepName ? chalk.yellow.bgBlack(printable) : printable}` +
314+
`${highlightDepName ? chalk.yellow(printable) : printable}` +
313315
(
314316
node[_dedupe]
315-
? ' ' + chalk.gray('deduped')
317+
? ' ' + chalk.dim('deduped')
316318
: ''
317319
) +
318320
(
319321
invalid
320-
? ' ' + chalk.red.bgBlack(invalid)
322+
? ' ' + chalk.red(invalid)
321323
: ''
322324
) +
323325
(
324326
isExtraneous(node, { global })
325-
? ' ' + chalk.green.bgBlack('extraneous')
327+
? ' ' + chalk.red('extraneous')
326328
: ''
327329
) +
328330
(
329331
node.overridden
330-
? ' ' + chalk.gray('overridden')
332+
? ' ' + chalk.dim('overridden')
331333
: ''
332334
) +
333335
(isGitNode(node) ? ` (${node.resolved})` : '') +

lib/commands/outdated.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ class Outdated extends ArboristWorkspaceCmd {
101101
}
102102
const outTable = [outHead].concat(outList)
103103

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

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

279279
return humanOutput
280-
? this.npm.chalk.green(workspaceName)
280+
? this.npm.chalk.blue(workspaceName)
281281
: workspaceName
282282
}
283283

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

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

299306
if (this.npm.config.get('long')) {
300307
columns[6] = type
301-
columns[7] = homepage
308+
columns[7] = this.npm.chalk.blue(homepage)
302309
}
303310

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

lib/commands/publish.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ class Publish extends BaseCommand {
172172
log.warn(
173173
'publish',
174174
`Skipping workspace ${
175-
this.npm.chalk.green(name)
175+
this.npm.chalk.cyan(name)
176176
}, marked as ${
177177
this.npm.chalk.bold('private')
178178
}`

lib/commands/view.js

Lines changed: 64 additions & 100 deletions
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
this.npm.output('')
378-
this.npm.output(
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 && this.npm.output(info.description)
385-
if (info.repo || info.site) {
386-
info.site && this.npm.output(chalk.cyan(info.site))
332+
this.npm.output([
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 && this.npm.output(manifest.description)
342+
if (site) {
343+
this.npm.output(chalk.blue(site))
387344
}
388345

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

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

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

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

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

429-
this.npm.output('')
430-
this.npm.output('dist-tags:')
431-
this.npm.output(columns(info.tags))
388+
this.npm.output('\ndist-tags:')
389+
this.npm.output(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
this.npm.output('')
442406
this.npm.output(publishInfo)

0 commit comments

Comments
 (0)