Skip to content

Commit 9127357

Browse files
committed
switch back to dynamically including library
1 parent d15d348 commit 9127357

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/utils.ts

Lines changed: 11 additions & 2 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 pc from 'picocolors'
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(pc.bgCyan(pc.whiteBright('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,6 +252,8 @@ 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':
258259
return text => pc.bgBlue(pc.whiteBright(text))
@@ -412,3 +413,11 @@ export function parseFileAsJSONSchema(filename: string | null, contents: string)
412413
function isYaml(filename: string) {
413414
return filename.endsWith('.yaml') || filename.endsWith('.yml')
414415
}
416+
417+
function color(): Format {
418+
let pc
419+
try {
420+
pc = require('picocolors')
421+
} catch {}
422+
return pc
423+
}

0 commit comments

Comments
 (0)