From c40b0b56c1045a55b51efc81d0b85eea9629b90a Mon Sep 17 00:00:00 2001 From: Nyrox Date: Tue, 19 Aug 2025 18:18:25 +0200 Subject: [PATCH 1/5] fix: correct stack-trace file paths on bun and windows --- src/Logger.ts | 4 +++- src/runtime/index.ts | 2 +- tsconfig.json | 4 ++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Logger.ts b/src/Logger.ts index ee2d918..aa2eaa1 100644 --- a/src/Logger.ts +++ b/src/Logger.ts @@ -22,7 +22,9 @@ export class Logger { constructor(options?: ILogOptionsParam, transports?: ITransport[], private stackDepthLevel: number = 4) { const isBrowser = ![typeof window, typeof document].includes("undefined"); const isSafari = isBrowser ? /^((?!chrome|android).)*safari/i.test(navigator?.userAgent) : false; - this.stackDepthLevel = isSafari ? 4 : this.stackDepthLevel; + const isBun = "Bun" in global; + + this.stackDepthLevel = isSafari ? 4 : isBun ? 3 : this.stackDepthLevel; this.attachedTransports = transports || [new PrettyPrinterTransport(ConsoleSink, {})]; this.options = { diff --git a/src/runtime/index.ts b/src/runtime/index.ts index d4681f5..16ec82c 100644 --- a/src/runtime/index.ts +++ b/src/runtime/index.ts @@ -72,7 +72,7 @@ function stackLineToStackFrame(line?: string): IStackFrame { method: undefined, }; if (line != null) { - const match = line.match(pathRegex); + const match = line.replaceAll("\\", "/").match(pathRegex); if (match) { pathResult.fullFilePath = match[1].replace(/\?.*$/, ""); const pathParts = pathResult.fullFilePath.split("/"); diff --git a/tsconfig.json b/tsconfig.json index d6975b4..0283e4b 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -2,8 +2,8 @@ "$schema": "http://json.schemastore.org/tsconfig", "compileOnSave": false, "compilerOptions": { - "lib": ["es2020", "dom"], - "target": "es2020", + "lib": ["ES2021", "dom"], + "target": "ES2021", "module": "CommonJS", "moduleResolution": "Node", "types": ["node", "jest", "puppeteer", "jest-environment-puppeteer", "expect-puppeteer"], From 0832440a9222316f9e81366116ad117c54313a03 Mon Sep 17 00:00:00 2001 From: Nyrox Date: Wed, 20 Aug 2025 10:41:12 +0200 Subject: [PATCH 2/5] chore: add bun CI --- .github/workflows/ci.yml | 8 ++++++++ tests/Nodejs/5_pretty_Log_Types.test.ts | 3 ++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bcb7263..85355b4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -31,3 +31,11 @@ jobs: run: yarn coverage - name: Report coverage uses: codecov/codecov-action@v3 + tests-bun: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: oven-sh/setup-bun@v2 + + - run: bun install + - run: bun coverage diff --git a/tests/Nodejs/5_pretty_Log_Types.test.ts b/tests/Nodejs/5_pretty_Log_Types.test.ts index 3b3d20b..b11d3c3 100644 --- a/tests/Nodejs/5_pretty_Log_Types.test.ts +++ b/tests/Nodejs/5_pretty_Log_Types.test.ts @@ -96,6 +96,7 @@ describe("Pretty: Log Types", () => { expect(getConsoleOutput()).toContain("test"); expect(getConsoleOutput()).toContain("error stack:\n"); expect(getConsoleOutput()).toContain("5_pretty_Log_Types.test.ts"); - expect(getConsoleOutput()).toContain("Object."); + // too specific to nodejs + // expect(getConsoleOutput()).toContain("Object."); }); }); From a1977aaf6dce7588779f2953b50dbde331d5ea4f Mon Sep 17 00:00:00 2001 From: Nyrox Date: Wed, 20 Aug 2025 10:57:09 +0200 Subject: [PATCH 3/5] fix bun tests --- .github/workflows/ci.yml | 4 +++- tests/Nodejs/5_pretty_Log_Types.test.ts | 7 +++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 85355b4..a43c198 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -33,9 +33,11 @@ jobs: uses: codecov/codecov-action@v3 tests-bun: runs-on: ubuntu-latest + env: + CI: true steps: - uses: actions/checkout@v4 - uses: oven-sh/setup-bun@v2 - run: bun install - - run: bun coverage + - run: bun test Nodejs diff --git a/tests/Nodejs/5_pretty_Log_Types.test.ts b/tests/Nodejs/5_pretty_Log_Types.test.ts index b11d3c3..fd0560f 100644 --- a/tests/Nodejs/5_pretty_Log_Types.test.ts +++ b/tests/Nodejs/5_pretty_Log_Types.test.ts @@ -5,7 +5,7 @@ import { getConsoleOutput, mockConsoleLog } from "./helper.js"; describe("Pretty: Log Types", () => { beforeEach(() => { - mockConsoleLog(true, false); + mockConsoleLog(true, true); }); test("plain string", (): void => { @@ -86,7 +86,7 @@ describe("Pretty: Log Types", () => { expect(getConsoleOutput()).toContain("test"); expect(getConsoleOutput()).toContain("error stack:\n"); expect(getConsoleOutput()).toContain("5_pretty_Log_Types.test.ts"); - expect(getConsoleOutput()).toContain("Object."); + expect(getConsoleOutput()).toContain(""); }); test("string and Error", (): void => { @@ -96,7 +96,6 @@ describe("Pretty: Log Types", () => { expect(getConsoleOutput()).toContain("test"); expect(getConsoleOutput()).toContain("error stack:\n"); expect(getConsoleOutput()).toContain("5_pretty_Log_Types.test.ts"); - // too specific to nodejs - // expect(getConsoleOutput()).toContain("Object."); + expect(getConsoleOutput()).toContain(""); }); }); From def3cdff325e07bb98bd9804bf4d908ccc86a6df Mon Sep 17 00:00:00 2001 From: Nyrox Date: Wed, 20 Aug 2025 10:58:50 +0200 Subject: [PATCH 4/5] remove extraneous prints --- tests/Nodejs/2_pretty_loglevel.test.ts | 2 +- tests/Nodejs/5_pretty_Log_Types.test.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Nodejs/2_pretty_loglevel.test.ts b/tests/Nodejs/2_pretty_loglevel.test.ts index 51fc308..8f8ac0e 100644 --- a/tests/Nodejs/2_pretty_loglevel.test.ts +++ b/tests/Nodejs/2_pretty_loglevel.test.ts @@ -6,7 +6,7 @@ const logger = new Logger(); describe("Pretty: Log level", () => { beforeEach(() => { - mockConsoleLog(true, true); + mockConsoleLog(true, false); }); test("silly (console)", (): void => { diff --git a/tests/Nodejs/5_pretty_Log_Types.test.ts b/tests/Nodejs/5_pretty_Log_Types.test.ts index fd0560f..8749f6c 100644 --- a/tests/Nodejs/5_pretty_Log_Types.test.ts +++ b/tests/Nodejs/5_pretty_Log_Types.test.ts @@ -5,7 +5,7 @@ import { getConsoleOutput, mockConsoleLog } from "./helper.js"; describe("Pretty: Log Types", () => { beforeEach(() => { - mockConsoleLog(true, true); + mockConsoleLog(true, false); }); test("plain string", (): void => { From 41a0d08571852ed8dcf280ad261f812716a25aa9 Mon Sep 17 00:00:00 2001 From: Nyrox Date: Wed, 20 Aug 2025 11:03:26 +0200 Subject: [PATCH 5/5] fix: use globalThis --- src/Logger.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Logger.ts b/src/Logger.ts index aa2eaa1..154dfaf 100644 --- a/src/Logger.ts +++ b/src/Logger.ts @@ -22,7 +22,7 @@ export class Logger { constructor(options?: ILogOptionsParam, transports?: ITransport[], private stackDepthLevel: number = 4) { const isBrowser = ![typeof window, typeof document].includes("undefined"); const isSafari = isBrowser ? /^((?!chrome|android).)*safari/i.test(navigator?.userAgent) : false; - const isBun = "Bun" in global; + const isBun = "Bun" in globalThis; this.stackDepthLevel = isSafari ? 4 : isBun ? 3 : this.stackDepthLevel;