Skip to content

Commit

Permalink
switch back to dynamically including library
Browse files Browse the repository at this point in the history
  • Loading branch information
benmccann committed Sep 3, 2024
1 parent d15d348 commit 9127357
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {basename, dirname, extname, normalize, sep, posix} from 'path'
import {Intersection, JSONSchema, LinkedJSONSchema, NormalizedJSONSchema, Parent} from './types/JSONSchema'
import {JSONSchema4} from 'json-schema'
import yaml from 'js-yaml'
import pc from 'picocolors'

// TODO: pull out into a separate package
export function Try<T>(fn: () => T, err: (e: Error) => any): T {
Expand Down Expand Up @@ -243,7 +242,7 @@ export function log(style: LogStyle, title: string, ...messages: unknown[]): voi
if (messages.length > 1 && typeof messages[messages.length - 1] !== 'string') {
lastMessage = messages.splice(messages.length - 1, 1)
}
console.info(pc.bgCyan(pc.whiteBright('debug')), getStyledTextForLogging(style)?.(title), ...messages)
console.info(color()?.bgCyan(color()?.whiteBright('debug')), getStyledTextForLogging(style)?.(title), ...messages)
if (lastMessage) {
console.dir(lastMessage, {depth: 6, maxArrayLength: 6})
}
Expand All @@ -253,6 +252,8 @@ function getStyledTextForLogging(style: LogStyle): ((text: string) => string) |
if (!process.env.VERBOSE) {
return
}
const pc = color()
if (!pc) return
switch (style) {
case 'blue':
return text => pc.bgBlue(pc.whiteBright(text))
Expand Down Expand Up @@ -412,3 +413,11 @@ export function parseFileAsJSONSchema(filename: string | null, contents: string)
function isYaml(filename: string) {
return filename.endsWith('.yaml') || filename.endsWith('.yml')
}

function color(): Format {

Check failure on line 417 in src/utils.ts

View workflow job for this annotation

GitHub Actions / build (16.x, ubuntu-latest)

Cannot find name 'Format'. Did you mean 'FormData'?

Check failure on line 417 in src/utils.ts

View workflow job for this annotation

GitHub Actions / build (16.x, windows-latest)

Cannot find name 'Format'. Did you mean 'FormData'?

Check failure on line 417 in src/utils.ts

View workflow job for this annotation

GitHub Actions / build (16.x, macOS-latest)

Cannot find name 'Format'. Did you mean 'FormData'?

Check failure on line 417 in src/utils.ts

View workflow job for this annotation

GitHub Actions / build (17.x, ubuntu-latest)

Cannot find name 'Format'. Did you mean 'FormData'?

Check failure on line 417 in src/utils.ts

View workflow job for this annotation

GitHub Actions / build (17.x, windows-latest)

Cannot find name 'Format'. Did you mean 'FormData'?

Check failure on line 417 in src/utils.ts

View workflow job for this annotation

GitHub Actions / build (17.x, macOS-latest)

Cannot find name 'Format'. Did you mean 'FormData'?

Check failure on line 417 in src/utils.ts

View workflow job for this annotation

GitHub Actions / build (18.x, ubuntu-latest)

Cannot find name 'Format'. Did you mean 'FormData'?

Check failure on line 417 in src/utils.ts

View workflow job for this annotation

GitHub Actions / build (18.x, windows-latest)

Cannot find name 'Format'. Did you mean 'FormData'?

Check failure on line 417 in src/utils.ts

View workflow job for this annotation

GitHub Actions / build (18.x, macOS-latest)

Cannot find name 'Format'. Did you mean 'FormData'?

Check failure on line 417 in src/utils.ts

View workflow job for this annotation

GitHub Actions / build (19.x, ubuntu-latest)

Cannot find name 'Format'. Did you mean 'FormData'?

Check failure on line 417 in src/utils.ts

View workflow job for this annotation

GitHub Actions / build (19.x, windows-latest)

Cannot find name 'Format'. Did you mean 'FormData'?

Check failure on line 417 in src/utils.ts

View workflow job for this annotation

GitHub Actions / build (19.x, macOS-latest)

Cannot find name 'Format'. Did you mean 'FormData'?

Check failure on line 417 in src/utils.ts

View workflow job for this annotation

GitHub Actions / build (20.x, ubuntu-latest)

Cannot find name 'Format'. Did you mean 'FormData'?

Check failure on line 417 in src/utils.ts

View workflow job for this annotation

GitHub Actions / build (20.x, windows-latest)

Cannot find name 'Format'. Did you mean 'FormData'?

Check failure on line 417 in src/utils.ts

View workflow job for this annotation

GitHub Actions / build (20.x, macOS-latest)

Cannot find name 'Format'. Did you mean 'FormData'?

Check failure on line 417 in src/utils.ts

View workflow job for this annotation

GitHub Actions / build (21.x, ubuntu-latest)

Cannot find name 'Format'. Did you mean 'FormData'?

Check failure on line 417 in src/utils.ts

View workflow job for this annotation

GitHub Actions / build (21.x, windows-latest)

Cannot find name 'Format'. Did you mean 'FormData'?

Check failure on line 417 in src/utils.ts

View workflow job for this annotation

GitHub Actions / build (21.x, macOS-latest)

Cannot find name 'Format'. Did you mean 'FormData'?
let pc
try {
pc = require('picocolors')
} catch {}
return pc
}

0 comments on commit 9127357

Please sign in to comment.