@@ -3,7 +3,6 @@ import {basename, dirname, extname, normalize, sep, posix} from 'path'
33import { Intersection , JSONSchema , LinkedJSONSchema , NormalizedJSONSchema , Parent } from './types/JSONSchema'
44import { JSONSchema4 } from 'json-schema'
55import yaml from 'js-yaml'
6- import pc from 'picocolors'
76
87// TODO: pull out into a separate package
98export 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)
412413function isYaml ( filename : string ) {
413414 return filename . endsWith ( '.yaml' ) || filename . endsWith ( '.yml' )
414415}
416+
417+ function color ( ) {
418+ let pc
419+ try {
420+ pc = require ( 'picocolors' )
421+ } catch { }
422+ return pc
423+ }
0 commit comments