From f62bd1c190dd052352816d001adf6cf8c5e274a3 Mon Sep 17 00:00:00 2001 From: clover caruso Date: Tue, 23 Dec 2025 14:18:14 -0800 Subject: [PATCH] chore: random lib tidying --- lib/log.ts | 17 +++++++++++++++-- lib/log/stack.ts | 1 - lib/readme.changes.md | 4 ++-- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/lib/log.ts b/lib/log.ts index 92878f9e5caceb3b47e82530e1344fb5e8e23e93..2bccef7bd33087c76ae885b59f4c1d728525cba5 100644 --- a/lib/log.ts +++ b/lib/log.ts @@ -57,7 +57,15 @@ export interface Scope { /** * emit a debugging message. this method is in place for compatibility with * the `console` API. prefer calling `.log` directly. - * @internal + * @internalconst hello = Math.random() > 0.5 ? 1 : "meow"; + +interface Meow { + meow: bigint; +} + +const world = hello as Meow; + +console.log(world); */ debug(...args: unknown[]): void; @@ -441,7 +449,12 @@ const logColors = node.process?.stderr.isTTY ?? false; let formatLine = /* @__PURE__ */ (() => { const fwo = node.builtin("util")?.formatWithOptions; - if (fwo) return (...args: unknown[]) => fwo({ colors: logColors }, ...args); + if (fwo) { + return (...args: unknown[]) => { + if (args[0] instanceof Error) return stack.format(args[0], logColors); + return fwo({ colors: logColors }, ...args); + }; + } return (...args: unknown[]) => args.map((arg) => { if (typeof arg === "string") return arg; diff --git a/lib/log/stack.ts b/lib/log/stack.ts index 3122b33b501b9a60494ffab906a2cc5e55584768..67dc12196c615c98e1cbdaaf7fd9c27b7fbb234d 100644 --- a/lib/log/stack.ts +++ b/lib/log/stack.ts @@ -101,7 +101,6 @@ export function format(error: Error, colors = false): string { ) .join(""); - let frameLines = "[failed to parse stack trace string]"; let frames = parse(error) ?? []; if ("Bun" in globalThis) { frames = frames.filter((frame) => diff --git a/lib/readme.changes.md b/lib/readme.changes.md index 3594cb7cb7df1ee64b7e5ea5611b529419662230..c0dde3a0978b1150903e5097599a74c97e90cb85 100644 --- a/lib/readme.changes.md +++ b/lib/readme.changes.md @@ -16,8 +16,8 @@ - `log` in Node.js will inject into `console.*` to prevent interweaving logs with widget output text. this injection is enabled regardless of if widgets are actually running, but do not otherwise change their behavior. -- `log` scopes render differently in the terminal now -- `log` in the browser will call the correct +- `log` scopes render differently in the terminal now. +- `log` in the browser will call the correct log level function in the browser. ## v2 -- 2.54.0