Skip to content

Commit

Permalink
fix: better output colors
Browse files Browse the repository at this point in the history
No more grey, no more setting background colors
  • Loading branch information
wraithgar committed Apr 16, 2024
1 parent 9622597 commit 3eaf7c2
Show file tree
Hide file tree
Showing 24 changed files with 570 additions and 639 deletions.
4 changes: 2 additions & 2 deletions lib/commands/audit.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class VerifySignatures {
}

if (missing.length) {
const missingClr = this.npm.chalk.bold(this.npm.chalk.red('missing'))
const missingClr = this.npm.chalk.redBright('missing')
if (missing.length === 1) {
/* eslint-disable-next-line max-len */
this.npm.output(`1 package has a ${missingClr} registry signature but the registry is providing signing keys:`)
Expand All @@ -122,7 +122,7 @@ class VerifySignatures {
if (missing.length) {
this.npm.output('')
}
const invalidClr = this.npm.chalk.bold(this.npm.chalk.red('invalid'))
const invalidClr = this.npm.chalk.redBright('invalid')
// We can have either invalid signatures or invalid provenance
const invalidSignatures = this.invalid.filter(i => i.code === 'EINTEGRITYSIGNATURE')
if (invalidSignatures.length) {
Expand Down
2 changes: 1 addition & 1 deletion lib/commands/doctor.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ class Doctor extends BaseCommand {
allOk = false
item[0] = this.npm.chalk.red(item[0])
item[1] = this.npm.chalk.red('not ok')
item[2] = this.npm.chalk.magenta(String(item[2]))
item[2] = this.npm.chalk.cyan(String(item[2]))
} else {
item[1] = this.npm.chalk.green('ok')
}
Expand Down
33 changes: 16 additions & 17 deletions lib/commands/fund.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,26 +110,25 @@ class Fund extends ArboristWorkspaceCmd {
const [fundingSource] = [].concat(normalizeFunding(funding)).filter(isValidFunding)
const { url } = fundingSource || {}
const pkgRef = getPrintableName({ name, version })
let item = {
label: pkgRef,
}

if (url) {
item.label = tree({
label: this.npm.chalk.bgBlack.white(url),
if (!url) {
return { label: pkgRef }
}
let item
if (seenUrls.has(url)) {
item = seenUrls.get(url)
item.label += `${this.npm.chalk.dim(',')} ${pkgRef}`
return null
}
item = {
label: tree({
label: this.npm.chalk.blue(url),
nodes: [pkgRef],
}).trim()

// stacks all packages together under the same item
if (seenUrls.has(url)) {
item = seenUrls.get(url)
item.label += `, ${pkgRef}`
return null
} else {
seenUrls.set(url, item)
}
}).trim(),
}

// stacks all packages together under the same item
seenUrls.set(url, item)
return item
},

Expand All @@ -153,7 +152,7 @@ class Fund extends ArboristWorkspaceCmd {
})

const res = tree(result)
return this.npm.chalk.reset(res)
return res
}

async openFundingUrl ({ path, tree, spec, fundingSourceNumber }) {
Expand Down
3 changes: 1 addition & 2 deletions lib/commands/help-search.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,7 @@ class HelpSearch extends BaseCommand {
for (const f of finder) {
hilitLine.push(line.slice(p, p + f.length))
const word = line.slice(p + f.length, p + f.length + arg.length)
const hilit = this.npm.chalk.bgBlack.red(word)
hilitLine.push(hilit)
hilitLine.push(this.npm.chalk.blue(word))
p += f.length + arg.length
}
}
Expand Down
18 changes: 10 additions & 8 deletions lib/commands/ls.js
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ const augmentItemWithIncludeMetadata = (node, item) => {

const getHumanOutputItem = (node, { args, chalk, global, long }) => {
const { pkgid, path } = node
const workspacePkgId = chalk.green(pkgid)
const workspacePkgId = chalk.blueBright(pkgid)
let printable = node.isWorkspace ? workspacePkgId : pkgid

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

// TODO there is a LOT of overlap with lib/utils/explain-dep.js here

const highlightDepName = args.length && node[_filteredBy]
const missingColor = isOptional(node)
? chalk.yellow.bgBlack
: chalk.red.bgBlack
? chalk.yellow
: chalk.red
const missingMsg = `UNMET ${isOptional(node) ? 'OPTIONAL ' : ''}DEPENDENCY`
const targetLocation = node.root
? relative(node.root.realpath, node.realpath)
Expand All @@ -309,25 +311,25 @@ const getHumanOutputItem = (node, { args, chalk, global, long }) => {
? missingColor(missingMsg) + ' '
: ''
) +
`${highlightDepName ? chalk.yellow.bgBlack(printable) : printable}` +
`${highlightDepName ? chalk.yellow(printable) : printable}` +
(
node[_dedupe]
? ' ' + chalk.gray('deduped')
? ' ' + chalk.dim('deduped')
: ''
) +
(
invalid
? ' ' + chalk.red.bgBlack(invalid)
? ' ' + chalk.red(invalid)
: ''
) +
(
isExtraneous(node, { global })
? ' ' + chalk.green.bgBlack('extraneous')
? ' ' + chalk.red('extraneous')
: ''
) +
(
node.overridden
? ' ' + chalk.gray('overridden')
? ' ' + chalk.dim('overridden')
: ''
) +
(isGitNode(node) ? ` (${node.resolved})` : '') +
Expand Down
19 changes: 11 additions & 8 deletions lib/commands/outdated.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class Outdated extends ArboristWorkspaceCmd {
}
const outTable = [outHead].concat(outList)

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

const tableOpts = {
align: ['l', 'r', 'r', 'r', 'l'],
Expand Down Expand Up @@ -277,7 +277,7 @@ class Outdated extends ArboristWorkspaceCmd {
: node.name

return humanOutput
? this.npm.chalk.green(workspaceName)
? this.npm.chalk.blue(workspaceName)
: workspaceName
}

Expand All @@ -294,17 +294,20 @@ class Outdated extends ArboristWorkspaceCmd {
dependent,
} = dep

const columns = [name, current, wanted, latest, location, dependent]
const columns = [
this.npm.chalk[current === wanted ? 'yellow' : 'red'](name),
current,
this.npm.chalk.cyan(wanted),
this.npm.chalk.blue(latest),
location,
dependent,
]

if (this.npm.config.get('long')) {
columns[6] = type
columns[7] = homepage
columns[7] = this.npm.chalk.blue(homepage)
}

columns[0] = this.npm.chalk[current === wanted ? 'yellow' : 'red'](columns[0]) // current
columns[2] = this.npm.chalk.green(columns[2]) // wanted
columns[3] = this.npm.chalk.magenta(columns[3]) // latest

return columns
}

Expand Down
2 changes: 1 addition & 1 deletion lib/commands/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ class Publish extends BaseCommand {
log.warn(
'publish',
`Skipping workspace ${
this.npm.chalk.green(name)
this.npm.chalk.cyan(name)
}, marked as ${
this.npm.chalk.bold('private')
}`
Expand Down
164 changes: 64 additions & 100 deletions lib/commands/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -318,125 +318,89 @@ class View extends BaseCommand {
// More modern, pretty printing of default view
const unicode = this.npm.config.get('unicode')
const chalk = this.npm.chalk
const tags = []

Object.keys(packu['dist-tags']).forEach((t) => {
const version = packu['dist-tags'][t]
tags.push(`${chalk.bold.green(t)}: ${version}`)
})
const unpackedSize = manifest.dist.unpackedSize &&
formatBytes(manifest.dist.unpackedSize, true)
const deps = Object.keys(manifest.dependencies || {}).map((dep) =>
`${chalk.blue(dep)}: ${manifest.dependencies[dep]}`
)
const site = manifest.homepage?.url || manifest.homepage
const bins = Object.keys(manifest.bin || {})
const licenseField = manifest.license || 'Proprietary'
const info = {
name: chalk.green(manifest.name),
version: chalk.green(manifest.version),
bins: Object.keys(manifest.bin || {}),
versions: chalk.yellow(packu.versions.length + ''),
description: manifest.description,
deprecated: manifest.deprecated,
keywords: packu.keywords || [],
license: typeof licenseField === 'string'
? licenseField
: (licenseField.type || 'Proprietary'),
deps: Object.keys(manifest.dependencies || {}).map((dep) => {
return `${chalk.yellow(dep)}: ${manifest.dependencies[dep]}`
}),
publisher: manifest._npmUser && unparsePerson({
name: chalk.yellow(manifest._npmUser.name),
email: chalk.cyan(manifest._npmUser.email),
}),
modified: !packu.time ? undefined
: chalk.yellow(relativeDate(packu.time[manifest.version])),
maintainers: (packu.maintainers || []).map((u) => unparsePerson({
name: chalk.yellow(u.name),
email: chalk.cyan(u.email),
})),
repo: (
manifest.bugs && (manifest.bugs.url || manifest.bugs)
) || (
manifest.repository && (manifest.repository.url || manifest.repository)
),
site: (
manifest.homepage && (manifest.homepage.url || manifest.homepage)
),
tags,
tarball: chalk.cyan(manifest.dist.tarball),
shasum: chalk.yellow(manifest.dist.shasum),
integrity:
manifest.dist.integrity && chalk.yellow(manifest.dist.integrity),
fileCount:
manifest.dist.fileCount && chalk.yellow(manifest.dist.fileCount),
unpackedSize: unpackedSize && chalk.yellow(unpackedSize),
}
if (info.license.toLowerCase().trim() === 'proprietary') {
info.license = chalk.bold.red(info.license)
} else {
info.license = chalk.green(info.license)
}
const license = typeof licenseField === 'string'
? licenseField
: (licenseField.type || 'Proprietary')

this.npm.output('')
this.npm.output(
chalk.underline.bold(`${info.name}@${info.version}`) +
' | ' + info.license +
' | deps: ' + (info.deps.length ? chalk.cyan(info.deps.length) : chalk.green('none')) +
' | versions: ' + info.versions
)
info.description && this.npm.output(info.description)
if (info.repo || info.site) {
info.site && this.npm.output(chalk.cyan(info.site))
this.npm.output([
chalk.underline.cyan(`${manifest.name}@${manifest.version}`),
license.toLowerCase().trim() === 'proprietary'
? chalk.red(license)
: chalk.green(license),
`deps: ${deps.length ? chalk.cyan(deps.length) : chalk.cyan('none')}`,
`versions: ${chalk.cyan(packu.versions.length + '')}`,
].join(' | '))

manifest.description && this.npm.output(manifest.description)
if (site) {
this.npm.output(chalk.blue(site))
}

const warningSign = unicode ? ' ⚠️ ' : '!!'
info.deprecated && this.npm.output(
`\n${chalk.bold.red('DEPRECATED')}${
warningSign
} - ${info.deprecated}`
manifest.deprecated && this.npm.output(
`\n${chalk.redBright('DEPRECATED')}${unicode ? ' ⚠️ ' : '!!'} - ${manifest.deprecated}`
)

if (info.keywords.length) {
this.npm.output('')
this.npm.output(`keywords: ${chalk.yellow(info.keywords.join(', '))}`)
if (packu.keywords?.length) {
this.npm.output(`\nkeywords: ${
packu.keywords.map(k => chalk.cyan(k)).join(', ')
}`)
}

if (info.bins.length) {
this.npm.output('')
this.npm.output(`bin: ${chalk.yellow(info.bins.join(', '))}`)
if (bins.length) {
this.npm.output(`\nbin: ${chalk.cyan(bins.join(', '))}`)
}

this.npm.output('')
this.npm.output('dist')
this.npm.output(`.tarball: ${info.tarball}`)
this.npm.output(`.shasum: ${info.shasum}`)
info.integrity && this.npm.output(`.integrity: ${info.integrity}`)
info.unpackedSize && this.npm.output(`.unpackedSize: ${info.unpackedSize}`)

const maxDeps = 24
if (info.deps.length) {
this.npm.output('')
this.npm.output('dependencies:')
this.npm.output(columns(info.deps.slice(0, maxDeps), { padding: 1 }))
if (info.deps.length > maxDeps) {
this.npm.output(`(...and ${info.deps.length - maxDeps} more.)`)
this.npm.output('\ndist')
this.npm.output(`.tarball: ${chalk.blue(manifest.dist.tarball)}`)
this.npm.output(`.shasum: ${chalk.green(manifest.dist.shasum)}`)
if (manifest.dist.integrity) {
this.npm.output(`.integrity: ${chalk.green(manifest.dist.integrity)}`)
}
if (manifest.dist.unpackedSize) {
this.npm.output(`.unpackedSize: ${chalk.blue(formatBytes(manifest.dist.unpackedSize, true))}`)
}

if (deps.length) {
const maxDeps = 24
this.npm.output('\ndependencies:')
this.npm.output(columns(deps.slice(0, maxDeps), { padding: 1 }))
if (deps.length > maxDeps) {
this.npm.output(chalk.dim(`(...and ${deps.length - maxDeps} more.)`))
}
}

if (info.maintainers && info.maintainers.length) {
this.npm.output('')
this.npm.output('maintainers:')
info.maintainers.forEach((u) => this.npm.output(`- ${u}`))
if (packu.maintainers?.length) {
this.npm.output('\nmaintainers:')
packu.maintainers.forEach(u =>
this.npm.output(`- ${unparsePerson({
name: chalk.blue(u.name),
email: chalk.dim(u.email) })}`)
)
}

this.npm.output('')
this.npm.output('dist-tags:')
this.npm.output(columns(info.tags))
this.npm.output('\ndist-tags:')
this.npm.output(columns(Object.keys(packu['dist-tags']).map(t =>
`${chalk.blue(t)}: ${packu['dist-tags'][t]}`
)))

if (info.publisher || info.modified) {
const publisher = manifest._npmUser && unparsePerson({
name: chalk.blue(manifest._npmUser.name),
email: chalk.dim(manifest._npmUser.email),
})
if (publisher || packu.time) {
let publishInfo = 'published'
if (info.modified) {
publishInfo += ` ${info.modified}`
if (packu.time) {
publishInfo += ` ${chalk.cyan(relativeDate(packu.time[manifest.version]))}`
}
if (info.publisher) {
publishInfo += ` by ${info.publisher}`
if (publisher) {
publishInfo += ` by ${publisher}`
}
this.npm.output('')
this.npm.output(publishInfo)
Expand Down
Loading

0 comments on commit 3eaf7c2

Please sign in to comment.