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 Oct 3, 2024
1 parent d15d348 commit a5eefe0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
3 changes: 2 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
"js-yaml": "^4.1.0",
"lodash": "^4.17.21",
"minimist": "^1.2.8",
"picocolors": "^1.1.0",
"prettier": "^3.2.5"
},
"devDependencies": {
Expand All @@ -74,6 +73,7 @@
"eslint": "^8.56.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.1.3",
"picocolors": "^1.1.0",
"rimraf": "^5.0.5",
"shx": "^0.3.4",
"tsify": "^5.0.4",
Expand Down
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() {
let pc
try {
pc = require('picocolors')
} catch {}
return pc
}

0 comments on commit a5eefe0

Please sign in to comment.