@@ -3,7 +3,6 @@ import {basename, dirname, extname, normalize, sep, posix} from 'path'
3
3
import { Intersection , JSONSchema , LinkedJSONSchema , NormalizedJSONSchema , Parent } from './types/JSONSchema'
4
4
import { JSONSchema4 } from 'json-schema'
5
5
import yaml from 'js-yaml'
6
- import pc from 'picocolors'
7
6
8
7
// TODO: pull out into a separate package
9
8
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
243
242
if ( messages . length > 1 && typeof messages [ messages . length - 1 ] !== 'string' ) {
244
243
lastMessage = messages . splice ( messages . length - 1 , 1 )
245
244
}
246
- console . info ( pc . bgCyan ( pc . whiteBright ( 'debug' ) ) , getStyledTextForLogging ( style ) ?.( title ) , ...messages )
245
+ console . info ( color ( ) ? .bgCyan ( color ( ) ? .whiteBright ( 'debug' ) ) , getStyledTextForLogging ( style ) ?.( title ) , ...messages )
247
246
if ( lastMessage ) {
248
247
console . dir ( lastMessage , { depth : 6 , maxArrayLength : 6 } )
249
248
}
@@ -253,6 +252,8 @@ function getStyledTextForLogging(style: LogStyle): ((text: string) => string) |
253
252
if ( ! process . env . VERBOSE ) {
254
253
return
255
254
}
255
+ const pc = color ( )
256
+ if ( ! pc ) return
256
257
switch ( style ) {
257
258
case 'blue' :
258
259
return text => pc . bgBlue ( pc . whiteBright ( text ) )
@@ -412,3 +413,11 @@ export function parseFileAsJSONSchema(filename: string | null, contents: string)
412
413
function isYaml ( filename : string ) {
413
414
return filename . endsWith ( '.yaml' ) || filename . endsWith ( '.yml' )
414
415
}
416
+
417
+ function color ( ) {
418
+ let pc
419
+ try {
420
+ pc = require ( 'picocolors' )
421
+ } catch { }
422
+ return pc
423
+ }
0 commit comments