@socketsecurity/lib 6.0.1 → 6.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,856 @@
1
+ "use strict";
2
+ /* Socket Lib - Built with esbuild */
3
+ "use strict";
4
+ var __create = Object.create;
5
+ var __defProp = Object.defineProperty;
6
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
7
+ var __getOwnPropNames = Object.getOwnPropertyNames;
8
+ var __getProtoOf = Object.getPrototypeOf;
9
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
10
+ var __export = (target, all) => {
11
+ for (var name in all)
12
+ __defProp(target, name, { get: all[name], enumerable: true });
13
+ };
14
+ var __copyProps = (to, from, except, desc) => {
15
+ if (from && typeof from === "object" || typeof from === "function") {
16
+ for (let key of __getOwnPropNames(from))
17
+ if (!__hasOwnProp.call(to, key) && key !== except)
18
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
19
+ }
20
+ return to;
21
+ };
22
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
23
+ // If the importer is in node compatibility mode or this is not an ESM
24
+ // file that has been converted to a CommonJS file using a Babel-
25
+ // compatible transform (i.e. "__esModule" has not been set), then set
26
+ // "default" to the CommonJS "module.exports" for node compatibility.
27
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
28
+ mod
29
+ ));
30
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
31
+ var node_exports = {};
32
+ __export(node_exports, {
33
+ Logger: () => Logger
34
+ });
35
+ module.exports = __toCommonJS(node_exports);
36
+ var import_node_process = __toESM(require("node:process"));
37
+ var import_array = require("../primordials/array");
38
+ var import_error = require("../primordials/error");
39
+ var import_math = require("../primordials/math");
40
+ var import_reflect = require("../primordials/reflect");
41
+ var import_format = require("../strings/format");
42
+ var import_predicates = require("../strings/predicates");
43
+ var import_context = require("../themes/context");
44
+ var import_themes = require("../themes/themes");
45
+ var import_internal = require("./_internal");
46
+ var import_symbols_builder = require("./symbols-builder");
47
+ var import_symbols = require("./symbols");
48
+ var import_console = require("./console");
49
+ class Logger {
50
+ /**
51
+ * Static reference to log symbols for convenience.
52
+ */
53
+ static LOG_SYMBOLS = import_symbols.LOG_SYMBOLS;
54
+ #parent;
55
+ #boundStream;
56
+ #stderrLogger;
57
+ #stdoutLogger;
58
+ #stderrIndention = "";
59
+ #stdoutIndention = "";
60
+ #stderrLastWasBlank = false;
61
+ #stdoutLastWasBlank = false;
62
+ #logCallCount = 0;
63
+ #options;
64
+ #originalStdout;
65
+ #theme;
66
+ /**
67
+ * Creates a new Logger instance.
68
+ *
69
+ * When called without arguments, creates a logger using the default
70
+ * `process.stdout` and `process.stderr` streams. Can accept custom console
71
+ * constructor arguments for advanced use cases.
72
+ *
73
+ * @param args - Optional console constructor arguments.
74
+ */
75
+ constructor(...args) {
76
+ import_internal.privateConstructorArgs.set(this, args);
77
+ const options = args["0"];
78
+ if (typeof options === "object" && options !== null) {
79
+ this.#options = { __proto__: null, ...options };
80
+ this.#originalStdout = options.stdout;
81
+ const themeOption = options.theme;
82
+ if (themeOption) {
83
+ if (typeof themeOption === "string") {
84
+ const resolved = import_themes.THEMES[themeOption];
85
+ if (resolved) {
86
+ this.#theme = resolved;
87
+ }
88
+ } else {
89
+ this.#theme = themeOption;
90
+ }
91
+ }
92
+ } else {
93
+ this.#options = { __proto__: null };
94
+ }
95
+ }
96
+ /**
97
+ * Apply a console method with indentation.
98
+ *
99
+ * @private
100
+ */
101
+ #apply(methodName, args, stream) {
102
+ const con = this.#getConsole();
103
+ const text = (0, import_array.ArrayPrototypeAt)(args, 0);
104
+ const hasText = typeof text === "string";
105
+ const targetStream = stream || (methodName === "log" ? "stdout" : "stderr");
106
+ const indent = this.#getIndent(targetStream);
107
+ const logArgs = hasText ? [
108
+ (0, import_format.applyLinePrefix)(text, { prefix: indent }),
109
+ ...(0, import_array.ArrayPrototypeSlice)(args, 1)
110
+ ] : args;
111
+ (0, import_reflect.ReflectApply)(
112
+ con[methodName],
113
+ con,
114
+ logArgs
115
+ );
116
+ this[import_symbols.lastWasBlankSymbol](hasText && (0, import_predicates.isBlankString)(logArgs[0]), targetStream);
117
+ this[import_symbols.incLogCallCountSymbol]();
118
+ return this;
119
+ }
120
+ /**
121
+ * Get the Console instance for this logger, creating it lazily on first
122
+ * access.
123
+ *
124
+ * This lazy initialization allows the logger to be imported during early
125
+ * Node.js bootstrap before stdout is ready, avoiding Console initialization
126
+ * errors (ERR_CONSOLE_WRITABLE_STREAM).
127
+ *
128
+ * @private
129
+ */
130
+ #getConsole() {
131
+ (0, import_console.ensurePrototypeInitialized)();
132
+ let con = import_internal.privateConsole.get(this);
133
+ if (!con) {
134
+ const ctorArgs = import_internal.privateConstructorArgs.get(this) ?? [];
135
+ if (ctorArgs.length) {
136
+ con = (0, import_console.constructConsole)(...ctorArgs);
137
+ } else {
138
+ con = (0, import_console.constructConsole)({
139
+ stdout: import_node_process.default.stdout,
140
+ stderr: import_node_process.default.stderr
141
+ });
142
+ for (const { 0: key, 1: method } of import_internal.boundConsoleEntries) {
143
+ con[key] = method;
144
+ }
145
+ }
146
+ import_internal.privateConsole.set(this, con);
147
+ import_internal.privateConstructorArgs.delete(this);
148
+ }
149
+ return con;
150
+ }
151
+ /**
152
+ * Get indentation for a specific stream.
153
+ *
154
+ * @private
155
+ */
156
+ #getIndent(stream) {
157
+ const root = this.#getRoot();
158
+ return stream === "stderr" ? root.#stderrIndention : root.#stdoutIndention;
159
+ }
160
+ /**
161
+ * Get lastWasBlank state for a specific stream.
162
+ *
163
+ * @private
164
+ */
165
+ #getLastWasBlank(stream) {
166
+ const root = this.#getRoot();
167
+ return stream === "stderr" ? root.#stderrLastWasBlank : root.#stdoutLastWasBlank;
168
+ }
169
+ /**
170
+ * Get the root logger (for accessing shared indentation state).
171
+ *
172
+ * @private
173
+ */
174
+ #getRoot() {
175
+ return this.#parent || this;
176
+ }
177
+ /**
178
+ * Get logger-specific symbols using the resolved theme.
179
+ *
180
+ * @private
181
+ */
182
+ #getSymbols() {
183
+ return (0, import_symbols_builder.buildLoggerSymbols)(this.#getTheme());
184
+ }
185
+ /**
186
+ * Get the target stream for this logger instance.
187
+ *
188
+ * @private
189
+ */
190
+ #getTargetStream() {
191
+ return this.#boundStream || "stderr";
192
+ }
193
+ /**
194
+ * Get the resolved theme for this logger instance. Returns instance theme if
195
+ * set, otherwise falls back to context theme.
196
+ *
197
+ * @private
198
+ */
199
+ #getTheme() {
200
+ return this.#theme ?? (0, import_context.getTheme)();
201
+ }
202
+ /**
203
+ * Set indentation for a specific stream.
204
+ *
205
+ * @private
206
+ */
207
+ #setIndent(stream, value) {
208
+ const root = this.#getRoot();
209
+ if (stream === "stderr") {
210
+ root.#stderrIndention = value;
211
+ } else {
212
+ root.#stdoutIndention = value;
213
+ }
214
+ }
215
+ /**
216
+ * Set lastWasBlank state for a specific stream.
217
+ *
218
+ * @private
219
+ */
220
+ #setLastWasBlank(stream, value) {
221
+ const root = this.#getRoot();
222
+ if (stream === "stderr") {
223
+ root.#stderrLastWasBlank = value;
224
+ } else {
225
+ root.#stdoutLastWasBlank = value;
226
+ }
227
+ }
228
+ /**
229
+ * Strip log symbols from the start of text.
230
+ *
231
+ * @private
232
+ */
233
+ #stripSymbols(text) {
234
+ return (0, import_symbols_builder.stripLoggerSymbols)(text);
235
+ }
236
+ /**
237
+ * Apply a method with a symbol prefix.
238
+ *
239
+ * @private
240
+ */
241
+ #symbolApply(symbolType, args) {
242
+ const con = this.#getConsole();
243
+ let text = (0, import_array.ArrayPrototypeAt)(args, 0);
244
+ let extras;
245
+ if (typeof text === "string") {
246
+ text = this.#stripSymbols(text);
247
+ extras = (0, import_array.ArrayPrototypeSlice)(args, 1);
248
+ } else {
249
+ extras = args;
250
+ text = "";
251
+ }
252
+ const indent = this.#getIndent("stderr");
253
+ const symbols = this.#getSymbols();
254
+ con.error(
255
+ (0, import_format.applyLinePrefix)(`${symbols[symbolType]} ${text}`, {
256
+ prefix: indent
257
+ }),
258
+ ...extras
259
+ );
260
+ this[import_symbols.lastWasBlankSymbol](false, "stderr");
261
+ this[import_symbols.incLogCallCountSymbol]();
262
+ return this;
263
+ }
264
+ /**
265
+ * Gets a logger instance bound exclusively to stderr.
266
+ *
267
+ * All logging operations on this instance will write to stderr only.
268
+ * Indentation is tracked separately from stdout. The instance is cached and
269
+ * reused on subsequent accesses.
270
+ *
271
+ * @returns A logger instance bound to stderr
272
+ */
273
+ get stderr() {
274
+ if (!this.#stderrLogger) {
275
+ const ctorArgs = import_internal.privateConstructorArgs.get(this) ?? [];
276
+ const instance = new Logger(...ctorArgs);
277
+ instance.#parent = this;
278
+ instance.#boundStream = "stderr";
279
+ instance.#options = { __proto__: null, ...this.#options };
280
+ if (this.#theme) {
281
+ instance.#theme = this.#theme;
282
+ }
283
+ this.#stderrLogger = instance;
284
+ }
285
+ return this.#stderrLogger;
286
+ }
287
+ /**
288
+ * Gets a logger instance bound exclusively to stdout.
289
+ *
290
+ * All logging operations on this instance will write to stdout only.
291
+ * Indentation is tracked separately from stderr. The instance is cached and
292
+ * reused on subsequent accesses.
293
+ *
294
+ * @returns A logger instance bound to stdout
295
+ */
296
+ get stdout() {
297
+ if (!this.#stdoutLogger) {
298
+ const ctorArgs = import_internal.privateConstructorArgs.get(this) ?? [];
299
+ const instance = new Logger(...ctorArgs);
300
+ instance.#parent = this;
301
+ instance.#boundStream = "stdout";
302
+ instance.#options = { __proto__: null, ...this.#options };
303
+ if (this.#theme) {
304
+ instance.#theme = this.#theme;
305
+ }
306
+ this.#stdoutLogger = instance;
307
+ }
308
+ return this.#stdoutLogger;
309
+ }
310
+ /**
311
+ * Gets the total number of log calls made on this logger instance.
312
+ *
313
+ * Tracks all logging method calls including `log()`, `error()`, `warn()`,
314
+ * `success()`, `fail()`, etc. Useful for testing and monitoring logging
315
+ * activity.
316
+ *
317
+ * @returns The number of times logging methods have been called
318
+ */
319
+ get logCallCount() {
320
+ const root = this.#getRoot();
321
+ return root.#logCallCount;
322
+ }
323
+ /**
324
+ * Increments the internal log call counter.
325
+ *
326
+ * This is called automatically by logging methods and should not be called
327
+ * directly in normal usage.
328
+ */
329
+ [import_symbols.incLogCallCountSymbol]() {
330
+ const root = this.#getRoot();
331
+ root.#logCallCount += 1;
332
+ return this;
333
+ }
334
+ /**
335
+ * Sets whether the last logged line was blank.
336
+ *
337
+ * Used internally to track blank lines and prevent duplicate spacing. This is
338
+ * called automatically by logging methods.
339
+ *
340
+ * @param value - Whether the last line was blank.
341
+ * @param stream - Optional stream to update (defaults to both streams if not
342
+ * bound, or target stream if bound)
343
+ */
344
+ [import_symbols.lastWasBlankSymbol](value, stream) {
345
+ if (stream) {
346
+ this.#setLastWasBlank(stream, !!value);
347
+ } else if (this.#boundStream) {
348
+ this.#setLastWasBlank(this.#boundStream, !!value);
349
+ } else {
350
+ this.#setLastWasBlank("stderr", !!value);
351
+ this.#setLastWasBlank("stdout", !!value);
352
+ }
353
+ return this;
354
+ }
355
+ /**
356
+ * Logs an assertion failure message if the value is falsy.
357
+ *
358
+ * Works like `console.assert()` but returns the logger for chaining. If the
359
+ * value is truthy, nothing is logged. If falsy, logs an error message with an
360
+ * assertion failure.
361
+ *
362
+ * @param value - The value to test.
363
+ * @param message - Optional message and additional arguments to log.
364
+ */
365
+ assert(value, ...message) {
366
+ const con = this.#getConsole();
367
+ con.assert(value, message[0], ...message.slice(1));
368
+ this[import_symbols.lastWasBlankSymbol](false);
369
+ return value ? this : this[import_symbols.incLogCallCountSymbol]();
370
+ }
371
+ /**
372
+ * Clears the current line in the terminal.
373
+ *
374
+ * Moves the cursor to the beginning of the line and clears all content. Works
375
+ * in both TTY and non-TTY environments. Useful for clearing progress
376
+ * indicators created with `progress()`.
377
+ *
378
+ * The stream to clear (stderr or stdout) depends on whether the logger is
379
+ * stream-bound.
380
+ */
381
+ clearLine() {
382
+ const con = this.#getConsole();
383
+ const stream = this.#getTargetStream();
384
+ const streamObj = stream === "stderr" ? con["_stderr"] : con["_stdout"];
385
+ if (streamObj.isTTY) {
386
+ streamObj.cursorTo(0);
387
+ streamObj.clearLine(0);
388
+ } else {
389
+ streamObj.write("\r\x1B[K");
390
+ }
391
+ return this;
392
+ }
393
+ /**
394
+ * Clears the visible terminal screen.
395
+ *
396
+ * Only available on the main logger instance, not on stream-bound instances
397
+ * (`.stderr` or `.stdout`). Resets the log call count and blank line tracking
398
+ * if the output is a TTY.
399
+ *
400
+ * @throws {Error} If called on a stream-bound logger instance
401
+ */
402
+ clearVisible() {
403
+ if (this.#boundStream) {
404
+ throw new import_error.ErrorCtor(
405
+ "clearVisible() is only available on the main logger instance, not on stream-bound instances"
406
+ );
407
+ }
408
+ const con = this.#getConsole();
409
+ con.clear();
410
+ if (con._stdout.isTTY) {
411
+ ;
412
+ this[import_symbols.lastWasBlankSymbol](true);
413
+ this.#logCallCount = 0;
414
+ }
415
+ return this;
416
+ }
417
+ /**
418
+ * Increments and logs a counter for the given label.
419
+ *
420
+ * Each unique label maintains its own counter. Works like `console.count()`.
421
+ *
422
+ * @default 'default'
423
+ *
424
+ * @param label - Optional label for the counter.
425
+ */
426
+ count(label) {
427
+ const con = this.#getConsole();
428
+ con.count(label);
429
+ this[import_symbols.lastWasBlankSymbol](false);
430
+ return this[import_symbols.incLogCallCountSymbol]();
431
+ }
432
+ /**
433
+ * Creates a task that logs start and completion messages automatically.
434
+ *
435
+ * Returns a task object with a `run()` method that executes the provided
436
+ * function and logs "Starting task: {name}" before execution and "Completed
437
+ * task: {name}" after completion.
438
+ *
439
+ * @param name - The name of the task.
440
+ *
441
+ * @returns A task object with a `run()` method
442
+ */
443
+ createTask(name) {
444
+ return {
445
+ run: (f) => {
446
+ this.log(`Starting task: ${name}`);
447
+ const result = f();
448
+ this.log(`Completed task: ${name}`);
449
+ return result;
450
+ }
451
+ };
452
+ }
453
+ /**
454
+ * Decreases the indentation level by removing spaces from the prefix.
455
+ *
456
+ * When called on the main logger, affects both stderr and stdout indentation.
457
+ * When called on a stream-bound logger (`.stderr` or `.stdout`), affects only
458
+ * that stream's indentation.
459
+ *
460
+ * @default 2
461
+ */
462
+ dedent(spaces = 2) {
463
+ if (this.#boundStream) {
464
+ const current = this.#getIndent(this.#boundStream);
465
+ this.#setIndent(this.#boundStream, current.slice(0, -spaces));
466
+ } else {
467
+ const stderrCurrent = this.#getIndent("stderr");
468
+ const stdoutCurrent = this.#getIndent("stdout");
469
+ this.#setIndent("stderr", stderrCurrent.slice(0, -spaces));
470
+ this.#setIndent("stdout", stdoutCurrent.slice(0, -spaces));
471
+ }
472
+ return this;
473
+ }
474
+ /**
475
+ * Displays an object's properties in a formatted way.
476
+ *
477
+ * Works like `console.dir()` with customizable options for depth, colors,
478
+ * etc. Useful for inspecting complex objects.
479
+ *
480
+ * @param obj - The object to display.
481
+ * @param options - Optional formatting options (Node.js inspect options)
482
+ */
483
+ dir(obj, options) {
484
+ const con = this.#getConsole();
485
+ con.dir(obj, options);
486
+ this[import_symbols.lastWasBlankSymbol](false);
487
+ return this[import_symbols.incLogCallCountSymbol]();
488
+ }
489
+ /**
490
+ * Displays data as XML/HTML in a formatted way.
491
+ *
492
+ * Works like `console.dirxml()`. In Node.js, behaves the same as `dir()`.
493
+ *
494
+ * @param data - The data to display.
495
+ */
496
+ dirxml(...data) {
497
+ const con = this.#getConsole();
498
+ con.dirxml(data);
499
+ this[import_symbols.lastWasBlankSymbol](false);
500
+ return this[import_symbols.incLogCallCountSymbol]();
501
+ }
502
+ /**
503
+ * Logs a completion message with a success symbol (alias for `success()`).
504
+ *
505
+ * Provides semantic clarity when marking something as "done". Does NOT
506
+ * automatically clear the current line - call `clearLine()` first if needed
507
+ * after using `progress()`.
508
+ */
509
+ done(...args) {
510
+ return this.#symbolApply("success", args);
511
+ }
512
+ /**
513
+ * Logs an error message to stderr.
514
+ *
515
+ * Automatically applies current indentation. All arguments are formatted and
516
+ * logged like `console.error()`.
517
+ */
518
+ error(...args) {
519
+ return this.#apply("error", args);
520
+ }
521
+ /**
522
+ * Logs a newline to stderr only if the last line wasn't already blank.
523
+ *
524
+ * Prevents multiple consecutive blank lines. Useful for adding spacing
525
+ * between sections without creating excessive whitespace.
526
+ */
527
+ errorNewline() {
528
+ return this.#getLastWasBlank("stderr") ? this : this.error("");
529
+ }
530
+ /**
531
+ * Logs a failure message with a red colored fail symbol.
532
+ *
533
+ * Automatically prefixes the message with `LOG_SYMBOLS.fail` (red ✖). Always
534
+ * outputs to stderr. If the message starts with an existing symbol, it will
535
+ * be stripped and replaced.
536
+ */
537
+ fail(...args) {
538
+ return this.#symbolApply("fail", args);
539
+ }
540
+ /**
541
+ * Starts a new indented log group.
542
+ *
543
+ * If a label is provided, it's logged before increasing indentation. Groups
544
+ * can be nested. Each group increases indentation by the `kGroupIndentWidth`
545
+ * (default 2 spaces). Call `groupEnd()` to close.
546
+ *
547
+ * @param label - Optional label to display before the group.
548
+ */
549
+ group(...label) {
550
+ const { length } = label;
551
+ if (length) {
552
+ (0, import_reflect.ReflectApply)(this.log, this, label);
553
+ }
554
+ this.indent(this[(0, import_symbols.getKGroupIndentationWidthSymbol)()]);
555
+ if (length) {
556
+ ;
557
+ this[import_symbols.lastWasBlankSymbol](false);
558
+ this[import_symbols.incLogCallCountSymbol]();
559
+ }
560
+ return this;
561
+ }
562
+ /**
563
+ * Starts a new collapsed log group (alias for `group()`).
564
+ *
565
+ * In browser consoles, this creates a collapsed group. In Node.js, it behaves
566
+ * identically to `group()`.
567
+ *
568
+ * @param label - Optional label to display before the group.
569
+ */
570
+ // groupCollapsed is an alias of group.
571
+ // https://nodejs.org/api/console.html#consolegroupcollapsed
572
+ groupCollapsed(...label) {
573
+ return (0, import_reflect.ReflectApply)(this.group, this, label);
574
+ }
575
+ /**
576
+ * Ends the current log group and decreases indentation.
577
+ *
578
+ * Must be called once for each `group()` or `groupCollapsed()` call to
579
+ * properly close the group and restore indentation.
580
+ */
581
+ groupEnd() {
582
+ this.dedent(this[(0, import_symbols.getKGroupIndentationWidthSymbol)()]);
583
+ return this;
584
+ }
585
+ /**
586
+ * Increases the indentation level by adding spaces to the prefix.
587
+ *
588
+ * When called on the main logger, affects both stderr and stdout indentation.
589
+ * When called on a stream-bound logger (`.stderr` or `.stdout`), affects only
590
+ * that stream's indentation. Maximum indentation is 1000 spaces.
591
+ *
592
+ * @default 2
593
+ */
594
+ indent(spaces = 2) {
595
+ const spacesToAdd = " ".repeat((0, import_math.MathMin)(spaces, import_internal.maxIndentation));
596
+ if (this.#boundStream) {
597
+ const current = this.#getIndent(this.#boundStream);
598
+ this.#setIndent(this.#boundStream, current + spacesToAdd);
599
+ } else {
600
+ const stderrCurrent = this.#getIndent("stderr");
601
+ const stdoutCurrent = this.#getIndent("stdout");
602
+ this.#setIndent("stderr", stderrCurrent + spacesToAdd);
603
+ this.#setIndent("stdout", stdoutCurrent + spacesToAdd);
604
+ }
605
+ return this;
606
+ }
607
+ /**
608
+ * Logs an informational message with a blue colored info symbol.
609
+ *
610
+ * Automatically prefixes the message with `LOG_SYMBOLS.info` (blue ℹ). Always
611
+ * outputs to stderr. If the message starts with an existing symbol, it will
612
+ * be stripped and replaced.
613
+ */
614
+ info(...args) {
615
+ return this.#symbolApply("info", args);
616
+ }
617
+ /**
618
+ * Logs a message to stdout.
619
+ *
620
+ * Automatically applies current indentation. All arguments are formatted and
621
+ * logged like `console.log()`. This is the primary method for standard
622
+ * output.
623
+ */
624
+ log(...args) {
625
+ return this.#apply("log", args);
626
+ }
627
+ /**
628
+ * Logs a newline to stdout only if the last line wasn't already blank.
629
+ *
630
+ * Prevents multiple consecutive blank lines. Useful for adding spacing
631
+ * between sections without creating excessive whitespace.
632
+ */
633
+ logNewline() {
634
+ return this.#getLastWasBlank("stdout") ? this : this.log("");
635
+ }
636
+ /**
637
+ * Shows a progress indicator that can be cleared with `clearLine()`.
638
+ *
639
+ * Displays a simple status message with a '∴' prefix. Does not include
640
+ * animation or spinner. Intended to be cleared once the operation completes.
641
+ * The output stream (stderr or stdout) depends on whether the logger is
642
+ * stream-bound.
643
+ *
644
+ * Always clears the current line before writing so calling `progress(...)`
645
+ * twice in a row redraws cleanly, and any partially-flushed prior output on
646
+ * the same row gets overwritten. TTY path uses `cursorTo(0) + clearLine(0)`;
647
+ * non-TTY path falls back to `\r\x1b[K` (which still works in CI logs).
648
+ *
649
+ * @param text - The progress message to display.
650
+ */
651
+ progress(text) {
652
+ const con = this.#getConsole();
653
+ const stream = this.#getTargetStream();
654
+ const streamObj = stream === "stderr" ? con["_stderr"] : con["_stdout"];
655
+ if (streamObj.isTTY) {
656
+ streamObj.cursorTo(0);
657
+ streamObj.clearLine(0);
658
+ } else {
659
+ streamObj.write("\r\x1B[K");
660
+ }
661
+ const symbols = this.#getSymbols();
662
+ streamObj.write(`${symbols.progress} ${text}`);
663
+ this[import_symbols.lastWasBlankSymbol](false);
664
+ return this;
665
+ }
666
+ /**
667
+ * Resets all indentation to zero.
668
+ *
669
+ * When called on the main logger, resets both stderr and stdout indentation.
670
+ * When called on a stream-bound logger (`.stderr` or `.stdout`), resets only
671
+ * that stream's indentation.
672
+ */
673
+ resetIndent() {
674
+ if (this.#boundStream) {
675
+ this.#setIndent(this.#boundStream, "");
676
+ } else {
677
+ this.#setIndent("stderr", "");
678
+ this.#setIndent("stdout", "");
679
+ }
680
+ return this;
681
+ }
682
+ /**
683
+ * Logs a skip message with a cyan colored skip symbol.
684
+ *
685
+ * Automatically prefixes the message with `LOG_SYMBOLS.skip` (cyan ↻). Always
686
+ * outputs to stderr. If the message starts with an existing symbol, it will
687
+ * be stripped and replaced.
688
+ */
689
+ skip(...args) {
690
+ return this.#symbolApply("skip", args);
691
+ }
692
+ /**
693
+ * Logs a main step message with a cyan arrow symbol and blank line before it.
694
+ *
695
+ * Automatically prefixes the message with `LOG_SYMBOLS.step` (cyan →) and
696
+ * adds a blank line before the message unless the last line was already
697
+ * blank. Useful for marking major steps in a process with clear visual
698
+ * separation. Always outputs to stdout. If the message starts with an
699
+ * existing symbol, it will be stripped and replaced.
700
+ *
701
+ * @param msg - The step message to log.
702
+ * @param extras - Additional arguments to log.
703
+ */
704
+ step(msg, ...extras) {
705
+ if (!this.#getLastWasBlank("stdout")) {
706
+ this.log("");
707
+ }
708
+ const text = this.#stripSymbols(msg);
709
+ const indent = this.#getIndent("stdout");
710
+ const symbols = this.#getSymbols();
711
+ const con = this.#getConsole();
712
+ con.log(
713
+ (0, import_format.applyLinePrefix)(`${symbols.step} ${text}`, {
714
+ prefix: indent
715
+ }),
716
+ ...extras
717
+ );
718
+ this[import_symbols.lastWasBlankSymbol](false, "stdout");
719
+ this[import_symbols.incLogCallCountSymbol]();
720
+ return this;
721
+ }
722
+ /**
723
+ * Logs an indented substep message (stateless).
724
+ *
725
+ * Adds a 2-space indent to the message without affecting the logger's
726
+ * indentation state. Useful for showing sub-items under a main step.
727
+ *
728
+ * @param msg - The substep message to log.
729
+ * @param extras - Additional arguments to log.
730
+ */
731
+ substep(msg, ...extras) {
732
+ const indentedMsg = ` ${msg}`;
733
+ return this.log(indentedMsg, ...extras);
734
+ }
735
+ /**
736
+ * Logs a success message with a green colored success symbol.
737
+ *
738
+ * Automatically prefixes the message with `LOG_SYMBOLS.success` (green ✔).
739
+ * Always outputs to stderr. If the message starts with an existing symbol, it
740
+ * will be stripped and replaced.
741
+ */
742
+ success(...args) {
743
+ return this.#symbolApply("success", args);
744
+ }
745
+ /**
746
+ * Displays data in a table format.
747
+ *
748
+ * Works like `console.table()`. Accepts arrays of objects or objects with
749
+ * nested objects. Optionally specify which properties to include in the
750
+ * table.
751
+ *
752
+ * @param tabularData - The data to display as a table.
753
+ * @param properties - Optional array of property names to include.
754
+ */
755
+ table(tabularData, properties) {
756
+ const con = this.#getConsole();
757
+ con.table(tabularData, properties);
758
+ this[import_symbols.lastWasBlankSymbol](false);
759
+ return this[import_symbols.incLogCallCountSymbol]();
760
+ }
761
+ /**
762
+ * Starts a timer for measuring elapsed time.
763
+ *
764
+ * Creates a timer with the given label. Use `timeEnd()` with the same label
765
+ * to stop the timer and log the elapsed time, or use `timeLog()` to check the
766
+ * time without stopping the timer.
767
+ *
768
+ * @default 'default'
769
+ *
770
+ * @param label - Optional label for the timer.
771
+ */
772
+ time(label) {
773
+ const con = this.#getConsole();
774
+ con.time(label);
775
+ return this;
776
+ }
777
+ /**
778
+ * Ends a timer and logs the elapsed time.
779
+ *
780
+ * Logs the duration since `console.time()` or `logger.time()` was called with
781
+ * the same label. The timer is stopped and removed.
782
+ *
783
+ * @default 'default'
784
+ *
785
+ * @param label - Optional label for the timer.
786
+ */
787
+ timeEnd(label) {
788
+ const con = this.#getConsole();
789
+ con.timeEnd(label);
790
+ this[import_symbols.lastWasBlankSymbol](false);
791
+ return this[import_symbols.incLogCallCountSymbol]();
792
+ }
793
+ /**
794
+ * Logs the current value of a timer without stopping it.
795
+ *
796
+ * Logs the duration since `console.time()` was called with the same label,
797
+ * but keeps the timer running. Can include additional data to log alongside
798
+ * the time.
799
+ *
800
+ * @default 'default'
801
+ *
802
+ * @param label - Optional label for the timer.
803
+ * @param data - Additional data to log with the time.
804
+ */
805
+ timeLog(label, ...data) {
806
+ const con = this.#getConsole();
807
+ con.timeLog(label, ...data);
808
+ this[import_symbols.lastWasBlankSymbol](false);
809
+ return this[import_symbols.incLogCallCountSymbol]();
810
+ }
811
+ /**
812
+ * Logs a stack trace to the console.
813
+ *
814
+ * Works like `console.trace()`. Shows the call stack leading to where this
815
+ * method was called. Useful for debugging.
816
+ *
817
+ * @param message - Optional message to display with the trace.
818
+ * @param args - Additional arguments to log.
819
+ */
820
+ trace(message, ...args) {
821
+ const con = this.#getConsole();
822
+ con.trace(message, ...args);
823
+ this[import_symbols.lastWasBlankSymbol](false);
824
+ return this[import_symbols.incLogCallCountSymbol]();
825
+ }
826
+ /**
827
+ * Logs a warning message with a yellow colored warning symbol.
828
+ *
829
+ * Automatically prefixes the message with `LOG_SYMBOLS.warn` (yellow ⚠).
830
+ * Always outputs to stderr. If the message starts with an existing symbol, it
831
+ * will be stripped and replaced.
832
+ */
833
+ warn(...args) {
834
+ return this.#symbolApply("warn", args);
835
+ }
836
+ /**
837
+ * Writes text directly to stdout without a newline or indentation.
838
+ *
839
+ * Useful for progress indicators or custom formatting where you need
840
+ * low-level control. Does not apply any indentation or formatting.
841
+ *
842
+ * @param text - The text to write.
843
+ */
844
+ write(text) {
845
+ const con = this.#getConsole();
846
+ const ctorArgs = import_internal.privateConstructorArgs.get(this) ?? [];
847
+ const stdout = this.#originalStdout || ctorArgs[0]?.stdout || con._stdout;
848
+ stdout.write(text);
849
+ this[import_symbols.lastWasBlankSymbol](false);
850
+ return this;
851
+ }
852
+ }
853
+ // Annotate the CommonJS export names for ESM import in node:
854
+ 0 && (module.exports = {
855
+ Logger
856
+ });