Skip to content

Commit a5eefe0

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

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

package-lock.json

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@
5656
"js-yaml": "^4.1.0",
5757
"lodash": "^4.17.21",
5858
"minimist": "^1.2.8",
59-
"picocolors": "^1.1.0",
6059
"prettier": "^3.2.5"
6160
},
6261
"devDependencies": {
@@ -74,6 +73,7 @@
7473
"eslint": "^8.56.0",
7574
"eslint-config-prettier": "^9.1.0",
7675
"eslint-plugin-prettier": "^5.1.3",
76+
"picocolors": "^1.1.0",
7777
"rimraf": "^5.0.5",
7878
"shx": "^0.3.4",
7979
"tsify": "^5.0.4",

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() {
418+
let pc
419+
try {
420+
pc = require('picocolors')
421+
} catch {}
422+
return pc
423+
}

0 commit comments

Comments
 (0)