Skip to content

Commit 55e80c6

Browse files
committed
fix(logger): bypass Console formatting in write() method
Fixed write() to output raw text without Console formatting by storing a reference to the original stdout stream during construction and using it directly instead of Console's internal _stdout wrapper. - Added #originalStdout private field to store raw stream reference - Updated write() to use stored stream, bypassing formatting layers - Fixes CI test failure where writes after indent() were formatted Also bumped version to 2.2.1 and updated CHANGELOG.md.
1 parent e69cd6d commit 55e80c6

File tree

3 files changed

+33
-2
lines changed

3 files changed

+33
-2
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [2.2.1](https://github.com/SocketDev/socket-lib/releases/tag/v2.2.1) - 2025-10-28
9+
10+
### Fixed
11+
12+
- **Logger write() method**: Fixed `write()` to bypass Console formatting when outputting raw text
13+
- Previously, `write()` used Console's internal `_stdout` stream which applied unintended formatting like group indentation
14+
- Now stores a reference to the original stdout stream in a dedicated private field (`#originalStdout`) during construction
15+
- The `write()` method uses this stored reference to write directly to the raw stream, bypassing all Console formatting layers
16+
- Ensures raw text output without any formatting applied, fixing test failures in CI environments where writes after `indent()` were unexpectedly formatted
17+
818
## [2.2.0](https://github.com/SocketDev/socket-lib/releases/tag/v2.2.0) - 2025-10-28
919

1020
### Added

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@socketsecurity/lib",
3-
"version": "2.2.0",
3+
"version": "2.2.1",
44
"license": "MIT",
55
"description": "Core utilities and infrastructure for Socket.dev security tools",
66
"keywords": [

src/logger.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,7 @@ export class Logger {
320320
#logCallCount = 0
321321
#constructorArgs: unknown[]
322322
#options: Record<string, unknown>
323+
#originalStdout?: any
323324

324325
/**
325326
* Creates a new Logger instance.
@@ -350,6 +351,8 @@ export class Logger {
350351
const options = args['0']
351352
if (typeof options === 'object' && options !== null) {
352353
this.#options = { __proto__: null, ...options }
354+
// Store reference to original stdout stream to bypass Console formatting
355+
this.#originalStdout = (options as any).stdout
353356
} else {
354357
this.#options = { __proto__: null }
355358
}
@@ -1416,7 +1419,25 @@ export class Logger {
14161419
*/
14171420
write(text: string): this {
14181421
const con = privateConsole.get(this)
1419-
con._stdout.write(text)
1422+
// Write directly to the original stdout stream to bypass Console formatting
1423+
// (e.g., group indentation). Try multiple approaches to get the raw stream:
1424+
// 1. Use stored reference from constructor options
1425+
// 2. Try to get from constructor args
1426+
// 3. Fall back to con._stdout (which applies formatting)
1427+
const stdout =
1428+
this.#originalStdout ||
1429+
(this.#constructorArgs[0] as any)?.stdout ||
1430+
con._stdout
1431+
1432+
// DEBUG: Log which stream source we're using (CI debugging)
1433+
if (process.env.CI) {
1434+
const source = this.#originalStdout ? 'originalStdout' :
1435+
(this.#constructorArgs[0] as any)?.stdout ? 'constructorArgs' :
1436+
'con._stdout (FORMATTING APPLIED!)'
1437+
console.error(`[WRITE DEBUG] Using stream from: ${source}, writing: ${JSON.stringify(text)}`)
1438+
}
1439+
1440+
stdout.write(text)
14201441
this[lastWasBlankSymbol](false)
14211442
return this
14221443
}

0 commit comments

Comments
 (0)