Skip to content

Commit e791e3e

Browse files
committed
switch to picocolors for console formatting
1 parent 118d6a8 commit e791e3e

File tree

3 files changed

+19
-189
lines changed

3 files changed

+19
-189
lines changed

package-lock.json

Lines changed: 9 additions & 171 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
@@ -56,6 +56,7 @@
5656
"js-yaml": "^4.1.0",
5757
"lodash": "^4.17.21",
5858
"minimist": "^1.2.8",
59+
"picocolors": "^1.1.0",
5960
"prettier": "^3.2.5"
6061
},
6162
"devDependencies": {
@@ -69,7 +70,6 @@
6970
"ava": "^6.1.2",
7071
"browserify": "^17.0.0",
7172
"browserify-shim": "^3.8.16",
72-
"cli-color": "^2.0.4",
7373
"concurrently": "^8.2.2",
7474
"eslint": "^8.56.0",
7575
"eslint-config-prettier": "^9.1.0",

src/utils.ts

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ 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'
6+
import pc from 'picocolors'
77

88
// TODO: pull out into a separate package
99
export function Try<T>(fn: () => T, err: (e: Error) => any): T {
@@ -243,7 +243,7 @@ export function log(style: LogStyle, title: string, ...messages: unknown[]): voi
243243
if (messages.length > 1 && typeof messages[messages.length - 1] !== 'string') {
244244
lastMessage = messages.splice(messages.length - 1, 1)
245245
}
246-
console.info(color()?.whiteBright.bgCyan('debug'), getStyledTextForLogging(style)?.(title), ...messages)
246+
console.info(pc.bgCyan(pc.whiteBright('debug')), getStyledTextForLogging(style)?.(title), ...messages)
247247
if (lastMessage) {
248248
console.dir(lastMessage, {depth: 6, maxArrayLength: 6})
249249
}
@@ -255,19 +255,19 @@ function getStyledTextForLogging(style: LogStyle): ((text: string) => string) |
255255
}
256256
switch (style) {
257257
case 'blue':
258-
return color()?.whiteBright.bgBlue
258+
return (text) => pc.bgBlue(pc.whiteBright(text))
259259
case 'cyan':
260-
return color()?.whiteBright.bgCyan
260+
return (text) => pc.bgCyan(pc.whiteBright(text))
261261
case 'green':
262-
return color()?.whiteBright.bgGreen
262+
return (text) => pc.bgGreen(pc.whiteBright(text))
263263
case 'magenta':
264-
return color()?.whiteBright.bgMagenta
264+
return (text) => pc.bgMagenta(pc.whiteBright(text))
265265
case 'red':
266-
return color()?.whiteBright.bgRedBright
266+
return (text) => pc.bgRedBright(pc.whiteBright(text))
267267
case 'white':
268-
return color()?.black.bgWhite
268+
return (text) => pc.bgWhite(pc.black(text))
269269
case 'yellow':
270-
return color()?.whiteBright.bgYellow
270+
return (text) => pc.bgYellow(pc.whiteBright(text))
271271
}
272272
}
273273

@@ -412,11 +412,3 @@ export function parseFileAsJSONSchema(filename: string | null, contents: string)
412412
function isYaml(filename: string) {
413413
return filename.endsWith('.yaml') || filename.endsWith('.yml')
414414
}
415-
416-
function color(): Format {
417-
let cliColor
418-
try {
419-
cliColor = require('cli-color')
420-
} catch {}
421-
return cliColor
422-
}

0 commit comments

Comments
 (0)