UNPKG

@idlebox/esbuild-executer

Version:

A simple script to execute typescript file during development.

70 lines 2.16 kB
import { inspect } from 'node:util'; import { debugs } from './cli.js'; let log_port; export function registerLogger(port) { log_port = port; } export const logger = { worker(message, ...args) { if (!debugs.worker.enabled) { return; } log_port.postMessage({ type: 'debug', message: template(message, args), kind: 'worker' }); }, hook(message, ...args) { if (!debugs.import.enabled) { return; } log_port.postMessage({ type: 'debug', message: template(message, args), kind: 'import' }); }, esbuild(message, ...args) { if (!debugs.esbuild.enabled) { return; } log_port.postMessage({ type: 'debug', message: template(message, args), kind: 'esbuild' }); }, error(message, ...args) { log_port.postMessage({ type: 'warning', message: template(message, args) }); }, output(message, ...args) { log_port.postMessage({ type: 'debug', message: template(message, args), kind: 'output' }); }, resolve(message, ...args) { if (!debugs.resolve.enabled) { return; } log_port.postMessage({ type: 'debug', message: template(message, args), kind: 'resolve', }); }, }; function template(strings, args) { let ret = ''; for (const part of strings) { ret += part; if (args.length > 0) { ret += stringify(args.shift()); } } return ret; } function stringify(arg) { if (typeof arg === 'string' || typeof arg === 'number' || typeof arg === 'boolean') { return arg.toString().trim(); } if (arg === null || arg === undefined) { // biome-ignore lint/style/useTemplate: <explanation> return '' + arg; } if (Array.isArray(arg) && typeof arg[0] === 'string') { let r = '\n'; for (const item of arg) { r += ` - ${item}\n`; } return r.trim(); } return inspect(arg, { colors: true, depth: 3, maxArrayLength: 2, compact: true, maxStringLength: 30 }).trim(); } //# sourceMappingURL=logger.js.map