Skip to content

Commit 5b913a7

Browse files
committed
switch to picocolors for console formatting
1 parent a5834aa commit 5b913a7

File tree

3 files changed

+23
-183
lines changed

3 files changed

+23
-183
lines changed

package-lock.json

Lines changed: 8 additions & 169 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,11 @@
6767
"ava": "^6.1.2",
6868
"browserify": "^17.0.0",
6969
"browserify-shim": "^3.8.16",
70-
"cli-color": "^2.0.4",
7170
"concurrently": "^8.2.2",
7271
"eslint": "^8.56.0",
7372
"eslint-config-prettier": "^9.1.0",
7473
"eslint-plugin-prettier": "^5.1.3",
74+
"picocolors": "^1.1.0",
7575
"rimraf": "^5.0.5",
7676
"shx": "^0.3.4",
7777
"tsify": "^5.0.4",

src/utils.ts

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import {basename, dirname, extname, normalize, sep, posix} from 'path'
33
import {Intersection, JSONSchema, LinkedJSONSchema, NormalizedJSONSchema, Parent} from './types/JSONSchema'
44
import {JSONSchema4} from 'json-schema'
55
import yaml from 'js-yaml'
6-
import type {Format} from 'cli-color'
76

87
// TODO: pull out into a separate package
98
export function Try<T>(fn: () => T, err: (e: Error) => any): T {
@@ -243,7 +242,7 @@ export function log(style: LogStyle, title: string, ...messages: unknown[]): voi
243242
if (messages.length > 1 && typeof messages[messages.length - 1] !== 'string') {
244243
lastMessage = messages.splice(messages.length - 1, 1)
245244
}
246-
console.info(color()?.whiteBright.bgCyan('debug'), getStyledTextForLogging(style)?.(title), ...messages)
245+
console.info(color()?.bgCyan(color()?.whiteBright('debug')), getStyledTextForLogging(style)?.(title), ...messages)
247246
if (lastMessage) {
248247
console.dir(lastMessage, {depth: 6, maxArrayLength: 6})
249248
}
@@ -253,21 +252,23 @@ function getStyledTextForLogging(style: LogStyle): ((text: string) => string) |
253252
if (!process.env.VERBOSE) {
254253
return
255254
}
255+
const pc = color()
256+
if (!pc) return
256257
switch (style) {
257258
case 'blue':
258-
return color()?.whiteBright.bgBlue
259+
return text => pc.bgBlue(pc.whiteBright(text))
259260
case 'cyan':
260-
return color()?.whiteBright.bgCyan
261+
return text => pc.bgCyan(pc.whiteBright(text))
261262
case 'green':
262-
return color()?.whiteBright.bgGreen
263+
return text => pc.bgGreen(pc.whiteBright(text))
263264
case 'magenta':
264-
return color()?.whiteBright.bgMagenta
265+
return text => pc.bgMagenta(pc.whiteBright(text))
265266
case 'red':
266-
return color()?.whiteBright.bgRedBright
267+
return text => pc.bgRedBright(pc.whiteBright(text))
267268
case 'white':
268-
return color()?.black.bgWhite
269+
return text => pc.bgWhite(pc.black(text))
269270
case 'yellow':
270-
return color()?.whiteBright.bgYellow
271+
return text => pc.bgYellow(pc.whiteBright(text))
271272
}
272273
}
273274

@@ -413,10 +414,10 @@ function isYaml(filename: string) {
413414
return filename.endsWith('.yaml') || filename.endsWith('.yml')
414415
}
415416

416-
function color(): Format {
417-
let cliColor
417+
function color() {
418+
let pc
418419
try {
419-
cliColor = require('cli-color')
420+
pc = require('picocolors')
420421
} catch {}
421-
return cliColor
422+
return pc
422423
}

0 commit comments

Comments
 (0)