@visulima/pail 3.1.0 → 3.2.1
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.
- package/CHANGELOG.md +59 -0
- package/LICENSE.md +3 -407
- package/README.md +298 -0
- package/dist/constants.d.ts +37 -0
- package/dist/index.browser.d.ts +47 -12
- package/dist/index.browser.js +12 -1
- package/dist/index.server.d.ts +65 -40
- package/dist/index.server.js +533 -2
- package/dist/interactive/index.d.ts +2 -28
- package/dist/interactive/index.js +2 -1
- package/dist/interactive/interactive-manager.d.ts +108 -0
- package/dist/interactive/interactive-stream-hook.d.ts +68 -0
- package/dist/object-tree.d.ts +65 -7
- package/dist/object-tree.js +89 -2
- package/dist/packem_shared/AbstractJsonReporter-intFdT_A.js +204 -0
- package/dist/packem_shared/InteractiveManager-CZ85hGNW.js +172 -0
- package/dist/packem_shared/InteractiveStreamHook-DiSubbJ1.js +21 -0
- package/dist/packem_shared/JsonReporter-C0AXk99i.js +58 -0
- package/dist/packem_shared/JsonReporter-DcM2LBX9.js +28 -0
- package/dist/packem_shared/PrettyReporter-BFWaYP_J.js +222 -0
- package/dist/packem_shared/PrettyReporter-CuLLKr6-.js +169 -0
- package/dist/packem_shared/abstract-pretty-reporter-DMPDCslJ.js +50 -0
- package/dist/packem_shared/constants-DfDr4MHC.js +119 -0
- package/dist/packem_shared/format-label-Btft2KGP.js +1194 -0
- package/dist/packem_shared/get-longest-label-C9PWeyKq.js +9 -0
- package/dist/packem_shared/index-BomQ3E6J.js +650 -0
- package/dist/packem_shared/index-DqKWykfa.js +1146 -0
- package/dist/packem_shared/interactive-stream-hook-DG4BtN12.js +141 -0
- package/dist/packem_shared/pail.browser-CPjQrsyy.js +1427 -0
- package/dist/packem_shared/write-console-log-based-on-level-DBmRYXpj.js +14 -0
- package/dist/packem_shared/write-stream-BG8fhcs3.js +6 -0
- package/dist/pail.browser.d.ts +412 -0
- package/dist/pail.server.d.ts +233 -0
- package/dist/processor/caller/caller-processor.d.ts +40 -7
- package/dist/processor/caller/caller-processor.js +59 -1
- package/dist/processor/caller/get-caller-filename.d.ts +23 -0
- package/dist/processor/message-formatter-processor.d.ts +44 -9
- package/dist/processor/message-formatter-processor.js +67 -1
- package/dist/processor/opentelemetry-processor.d.ts +70 -0
- package/dist/processor/opentelemetry-processor.js +52 -0
- package/dist/processor/redact-processor.d.ts +39 -8
- package/dist/processor/redact-processor.js +30 -1
- package/dist/progress-bar.d.ts +75 -15
- package/dist/progress-bar.js +404 -1
- package/dist/reporter/file/json-file-reporter.d.ts +39 -20
- package/dist/reporter/file/json-file-reporter.js +136 -4
- package/dist/reporter/file/utils/rotating-file-stream.d.ts +48 -0
- package/dist/reporter/http/abstract-http-reporter.d.ts +215 -0
- package/dist/reporter/http/abstract-http-reporter.js +435 -0
- package/dist/reporter/http/http-reporter.d.ts +39 -0
- package/dist/reporter/http/http-reporter.edge-light.d.ts +40 -0
- package/dist/reporter/http/http-reporter.edge-light.js +651 -0
- package/dist/reporter/http/http-reporter.js +13 -0
- package/dist/reporter/http/utils/compression.d.ts +7 -0
- package/dist/reporter/http/utils/log-size-error.d.ts +30 -0
- package/dist/reporter/http/utils/retry.d.ts +27 -0
- package/dist/reporter/json/abstract-json-reporter.d.ts +61 -0
- package/dist/reporter/json/index.browser.d.ts +3 -13
- package/dist/reporter/json/index.browser.js +2 -1
- package/dist/reporter/json/index.d.ts +3 -16
- package/dist/reporter/json/index.js +2 -1
- package/dist/reporter/json/json-reporter.browser.d.ts +40 -0
- package/dist/reporter/json/json-reporter.server.d.ts +50 -0
- package/dist/reporter/pretty/abstract-pretty-reporter.d.ts +83 -0
- package/dist/reporter/pretty/index.browser.d.ts +2 -13
- package/dist/reporter/pretty/index.browser.js +1 -1
- package/dist/reporter/pretty/index.d.ts +2 -25
- package/dist/reporter/pretty/index.js +1 -1
- package/dist/reporter/pretty/pretty-reporter.browser.d.ts +36 -0
- package/dist/reporter/pretty/pretty-reporter.server.d.ts +70 -0
- package/dist/reporter/raw/raw-reporter.browser.d.ts +5 -0
- package/dist/reporter/raw/raw-reporter.server.d.ts +13 -0
- package/dist/reporter/simple/simple-reporter.server.d.ts +10 -14
- package/dist/reporter/simple/simple-reporter.server.js +186 -8
- package/dist/reporter/utils/default-inspector-config.d.ts +3 -0
- package/dist/reporter/utils/format-label.d.ts +3 -0
- package/dist/spinner.d.ts +170 -104
- package/dist/spinner.js +2150 -1
- package/dist/types.d.ts +241 -0
- package/dist/utils/ansi-escapes.d.ts +4 -0
- package/dist/utils/arrayify.d.ts +2 -0
- package/dist/utils/get-longest-badge.d.ts +4 -0
- package/dist/utils/get-longest-label.d.ts +4 -0
- package/dist/utils/merge-types.d.ts +4 -0
- package/dist/utils/stream/safe-stream-handler.d.ts +21 -0
- package/dist/utils/write-console-log-based-on-level.d.ts +4 -0
- package/dist/utils/write-stream.d.ts +2 -0
- package/package.json +53 -4
- package/dist/packem_shared/AbstractJsonReporter-UftN6CIL.js +0 -1
- package/dist/packem_shared/InteractiveManager-CgmJyW9x.js +0 -3
- package/dist/packem_shared/InteractiveStreamHook-NtJu71aN.js +0 -1
- package/dist/packem_shared/JsonReporter-DTBtHNaD.js +0 -2
- package/dist/packem_shared/JsonReporter-Dl4m0xZe.js +0 -1
- package/dist/packem_shared/PrettyReporter-Bns0ZWLy.js +0 -12
- package/dist/packem_shared/PrettyReporter-CGKSTI7X.js +0 -5
- package/dist/packem_shared/abstract-json-reporter-CPsNkpz8.d.ts +0 -22
- package/dist/packem_shared/abstract-pretty-reporter-CUtSm20r.js +0 -1
- package/dist/packem_shared/abstract-pretty-reporter-DB2G-qlI.d.ts +0 -28
- package/dist/packem_shared/constants-DKfCaSUR.js +0 -1
- package/dist/packem_shared/format-label-CpyyTBom.js +0 -26
- package/dist/packem_shared/get-longest-label-B0NrI-o2.js +0 -1
- package/dist/packem_shared/index-CysYvHXs.js +0 -8
- package/dist/packem_shared/index-D9hWq9ka.js +0 -1
- package/dist/packem_shared/index.d-BR1GjZri.d.ts +0 -53
- package/dist/packem_shared/index.d-oxZvg_y7.d.ts +0 -20
- package/dist/packem_shared/interactive-stream-hook-CeVo4Kth.js +0 -2
- package/dist/packem_shared/pail.browser-BmHoDvEA.js +0 -19
- package/dist/packem_shared/pail.browser-CmWcqnn9.d.ts +0 -64
- package/dist/packem_shared/types-DVzG8TWL.d.ts +0 -95
- package/dist/packem_shared/write-console-log-based-on-level-BP95fgQZ.js +0 -1
- package/dist/packem_shared/write-stream-CD8XFv1L.js +0 -1
package/dist/index.server.js
CHANGED
|
@@ -1,2 +1,533 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { createRequire as __cjs_createRequire } from "node:module";
|
|
2
|
+
|
|
3
|
+
const __cjs_require = __cjs_createRequire(import.meta.url);
|
|
4
|
+
|
|
5
|
+
const __cjs_getProcess = typeof globalThis !== "undefined" && typeof globalThis.process !== "undefined" ? globalThis.process : process;
|
|
6
|
+
|
|
7
|
+
const {
|
|
8
|
+
stdout,
|
|
9
|
+
stderr,
|
|
10
|
+
env
|
|
11
|
+
} = __cjs_getProcess;
|
|
12
|
+
import InteractiveManager from './packem_shared/InteractiveManager-CZ85hGNW.js';
|
|
13
|
+
import { I as InteractiveStreamHook, c as clearTerminal } from './packem_shared/interactive-stream-hook-DG4BtN12.js';
|
|
14
|
+
import { a as PailBrowserImpl, m as mergeTypes, b as arrayify } from './packem_shared/pail.browser-CPjQrsyy.js';
|
|
15
|
+
import { ProgressBar, applyStyleToOptions, MultiProgressBar } from './progress-bar.js';
|
|
16
|
+
export { getBarChar } from './progress-bar.js';
|
|
17
|
+
import { i as inspect } from './packem_shared/format-label-Btft2KGP.js';
|
|
18
|
+
import { E as EMPTY_SYMBOL } from './packem_shared/constants-DfDr4MHC.js';
|
|
19
|
+
import { w as writeStream } from './packem_shared/write-stream-BG8fhcs3.js';
|
|
20
|
+
import { Spinner, MultiSpinner } from './spinner.js';
|
|
21
|
+
import { g as getLongestLabel } from './packem_shared/get-longest-label-C9PWeyKq.js';
|
|
22
|
+
import MessageFormatterProcessor from './processor/message-formatter-processor.js';
|
|
23
|
+
import { PrettyReporter } from './packem_shared/PrettyReporter-BFWaYP_J.js';
|
|
24
|
+
|
|
25
|
+
class RawReporter {
|
|
26
|
+
#stdout;
|
|
27
|
+
#stderr;
|
|
28
|
+
#interactiveManager;
|
|
29
|
+
#interactive = false;
|
|
30
|
+
#inspectOptions;
|
|
31
|
+
constructor(inspectOptions = {}) {
|
|
32
|
+
this.#stdout = stdout;
|
|
33
|
+
this.#stderr = stderr;
|
|
34
|
+
this.#inspectOptions = inspectOptions;
|
|
35
|
+
}
|
|
36
|
+
setStdout(stdout_) {
|
|
37
|
+
this.#stdout = stdout_;
|
|
38
|
+
}
|
|
39
|
+
setStderr(stderr_) {
|
|
40
|
+
this.#stderr = stderr_;
|
|
41
|
+
}
|
|
42
|
+
setInteractiveManager(manager) {
|
|
43
|
+
this.#interactiveManager = manager;
|
|
44
|
+
}
|
|
45
|
+
setIsInteractive(interactive) {
|
|
46
|
+
this.#interactive = interactive;
|
|
47
|
+
}
|
|
48
|
+
log(meta) {
|
|
49
|
+
const { context, groups, message, type } = meta;
|
|
50
|
+
const items = [];
|
|
51
|
+
if (message !== EMPTY_SYMBOL) {
|
|
52
|
+
const formattedMessage = typeof message === "string" ? message : inspect(message, this.#inspectOptions);
|
|
53
|
+
items.push(formattedMessage);
|
|
54
|
+
}
|
|
55
|
+
if (context) {
|
|
56
|
+
items.push(
|
|
57
|
+
...context.map((value) => {
|
|
58
|
+
if (typeof value === "object") {
|
|
59
|
+
return ` ${inspect(value, this.#inspectOptions)}`;
|
|
60
|
+
}
|
|
61
|
+
return ` ${value}`;
|
|
62
|
+
})
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
const streamType = ["error", "trace", "warn"].includes(type.level) ? "stderr" : "stdout";
|
|
66
|
+
const stream = streamType === "stderr" ? this.#stderr : this.#stdout;
|
|
67
|
+
const groupSpaces = groups.map(() => " ").join("");
|
|
68
|
+
if (this.#interactive && this.#interactiveManager !== void 0 && stream.isTTY) {
|
|
69
|
+
this.#interactiveManager.update(streamType, (groupSpaces + items.join("")).split("\n"), 0);
|
|
70
|
+
} else {
|
|
71
|
+
writeStream(groupSpaces + items.join(""), stream);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
class PailServerImpl extends PailBrowserImpl {
|
|
77
|
+
/**
|
|
78
|
+
* Creates a new Pail server logger instance.
|
|
79
|
+
*
|
|
80
|
+
* Initializes the server-compatible logger with streams, interactive support,
|
|
81
|
+
* and server-specific configuration options.
|
|
82
|
+
* @param options Server-specific configuration options
|
|
83
|
+
*/
|
|
84
|
+
constructor(options) {
|
|
85
|
+
const parentStderr = options.parentStderr;
|
|
86
|
+
const parentStdout = options.parentStdout;
|
|
87
|
+
const { interactive, processors, rawReporter, reporters, stderr: optionsStderr, stdout: optionsStdout } = options;
|
|
88
|
+
const stderr = parentStderr ?? optionsStderr;
|
|
89
|
+
const stdout = parentStdout ?? optionsStdout;
|
|
90
|
+
const parentLongestLabel = options.parentLongestLabel;
|
|
91
|
+
const parentTypes = options.parentTypes;
|
|
92
|
+
const { parentLogLevels, parentMessages, parentStringify } = options;
|
|
93
|
+
const parentOptions = {
|
|
94
|
+
disabled: options.disabled,
|
|
95
|
+
logLevel: options.logLevel,
|
|
96
|
+
logLevels: options.logLevels,
|
|
97
|
+
messages: options.messages,
|
|
98
|
+
processors: [],
|
|
99
|
+
rawReporter: options.rawReporter,
|
|
100
|
+
reporters: [],
|
|
101
|
+
scope: options.scope,
|
|
102
|
+
throttle: options.throttle,
|
|
103
|
+
throttleMin: options.throttleMin
|
|
104
|
+
};
|
|
105
|
+
const hasTypesProperty = "types" in options;
|
|
106
|
+
if (parentTypes && parentLongestLabel && !hasTypesProperty) {
|
|
107
|
+
parentOptions.parentTypes = parentTypes;
|
|
108
|
+
parentOptions.parentLongestLabel = parentLongestLabel;
|
|
109
|
+
} else if (hasTypesProperty && options.types !== void 0) {
|
|
110
|
+
parentOptions.types = options.types;
|
|
111
|
+
}
|
|
112
|
+
if (parentStringify) {
|
|
113
|
+
parentOptions.parentStringify = parentStringify;
|
|
114
|
+
}
|
|
115
|
+
if (parentLogLevels && !options.logLevels) {
|
|
116
|
+
parentOptions.parentLogLevels = parentLogLevels;
|
|
117
|
+
}
|
|
118
|
+
if (parentMessages && !options.messages) {
|
|
119
|
+
parentOptions.parentMessages = parentMessages;
|
|
120
|
+
}
|
|
121
|
+
super(parentOptions);
|
|
122
|
+
this.options = options;
|
|
123
|
+
this.interactive = interactive ?? false;
|
|
124
|
+
this.stdout = stdout;
|
|
125
|
+
this.stderr = stderr;
|
|
126
|
+
if (this.interactive) {
|
|
127
|
+
this.interactiveManager = new InteractiveManager(new InteractiveStreamHook(this.stdout), new InteractiveStreamHook(this.stderr));
|
|
128
|
+
}
|
|
129
|
+
if (Array.isArray(reporters)) {
|
|
130
|
+
this.registerReporters(reporters);
|
|
131
|
+
}
|
|
132
|
+
this.rawReporter = this.extendReporter(rawReporter ?? new RawReporter());
|
|
133
|
+
if (Array.isArray(processors)) {
|
|
134
|
+
this.registerProcessors(processors);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
stdout;
|
|
138
|
+
stderr;
|
|
139
|
+
interactiveManager;
|
|
140
|
+
interactive;
|
|
141
|
+
// @ts-expect-error - this returns a different type
|
|
142
|
+
scope(...name) {
|
|
143
|
+
if (name.length === 0) {
|
|
144
|
+
throw new Error("No scope name was defined.");
|
|
145
|
+
}
|
|
146
|
+
this.scopeName = name.flat();
|
|
147
|
+
return this;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Creates a child logger that inherits settings from the parent.
|
|
151
|
+
*
|
|
152
|
+
* Returns a new logger instance that inherits all configuration from the parent
|
|
153
|
+
* (reporters, processors, types, log levels, throttle settings, etc.) while allowing
|
|
154
|
+
* you to override only what you need. Child loggers are independent instances with
|
|
155
|
+
* their own state (timers, counters, etc.).
|
|
156
|
+
* @template N - The new custom logger type names
|
|
157
|
+
* @template LC - The new log level types
|
|
158
|
+
* @param options Configuration options to override or extend parent settings
|
|
159
|
+
* @returns A new child logger instance
|
|
160
|
+
* @example
|
|
161
|
+
* ```typescript
|
|
162
|
+
* const parent = createPail({
|
|
163
|
+
* logLevel: "info",
|
|
164
|
+
* types: { http: { label: "HTTP", logLevel: "info" } },
|
|
165
|
+
* reporters: [new PrettyReporter()],
|
|
166
|
+
* });
|
|
167
|
+
*
|
|
168
|
+
* // Child inherits parent settings but overrides log level
|
|
169
|
+
* const child = parent.child({ logLevel: "debug" });
|
|
170
|
+
* child.info("This will be logged"); // Uses debug level from child
|
|
171
|
+
* child.http("GET /api 200"); // Inherits http type from parent
|
|
172
|
+
*
|
|
173
|
+
* // Child can add new types
|
|
174
|
+
* const childWithNewType = parent.child({
|
|
175
|
+
* types: { db: { label: "DB", logLevel: "info" } },
|
|
176
|
+
* });
|
|
177
|
+
* childWithNewType.db("Query executed"); // New type available
|
|
178
|
+
* ```
|
|
179
|
+
*/
|
|
180
|
+
// @ts-expect-error - override signature differs due to server-specific options
|
|
181
|
+
child(options) {
|
|
182
|
+
const typesChanged = options?.types !== void 0 && options.types !== null;
|
|
183
|
+
const mergedTypes = typesChanged ? mergeTypes(this.types, options.types) : this.types;
|
|
184
|
+
const childReporters = options?.reporters ?? [];
|
|
185
|
+
const allReporters = childReporters.length > 0 ? [...this.reporters, ...childReporters] : [...this.reporters];
|
|
186
|
+
const childProcessors = options?.processors ?? [];
|
|
187
|
+
const allProcessors = childProcessors.length > 0 ? [...this.processors, ...childProcessors] : [...this.processors];
|
|
188
|
+
const mergedLogLevels = options?.logLevels ? { ...this.logLevels, ...options.logLevels } : this.logLevels;
|
|
189
|
+
let mergedScope;
|
|
190
|
+
if (options?.scope) {
|
|
191
|
+
const childScope = arrayify(options.scope).filter(Boolean);
|
|
192
|
+
mergedScope = this.scopeName.length > 0 ? [...this.scopeName, ...childScope] : childScope;
|
|
193
|
+
} else {
|
|
194
|
+
mergedScope = this.scopeName.length > 0 ? this.scopeName : [];
|
|
195
|
+
}
|
|
196
|
+
const mergedMessages = options?.messages ? {
|
|
197
|
+
timerEnd: this.endTimerMessage,
|
|
198
|
+
timerStart: this.startTimerMessage,
|
|
199
|
+
...options.messages
|
|
200
|
+
} : {
|
|
201
|
+
timerEnd: this.endTimerMessage,
|
|
202
|
+
timerStart: this.startTimerMessage
|
|
203
|
+
};
|
|
204
|
+
const childOptions = {
|
|
205
|
+
disabled: options?.disabled ?? this.disabled,
|
|
206
|
+
interactive: options?.interactive ?? this.interactive,
|
|
207
|
+
logLevel: options?.logLevel ?? this.generalLogLevel,
|
|
208
|
+
logLevels: mergedLogLevels,
|
|
209
|
+
messages: mergedMessages,
|
|
210
|
+
processors: allProcessors,
|
|
211
|
+
rawReporter: options?.rawReporter ?? this.rawReporter,
|
|
212
|
+
reporters: allReporters,
|
|
213
|
+
scope: mergedScope,
|
|
214
|
+
stderr: options?.stderr ?? this.stderr,
|
|
215
|
+
stdout: options?.stdout ?? this.stdout,
|
|
216
|
+
throttle: options?.throttle ?? this.throttle,
|
|
217
|
+
throttleMin: options?.throttleMin ?? this.throttleMin
|
|
218
|
+
};
|
|
219
|
+
this.#assignParentValues(childOptions, options, typesChanged, mergedTypes);
|
|
220
|
+
return new PailServerImpl(childOptions);
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Assigns parent values to child options for optimization.
|
|
224
|
+
*
|
|
225
|
+
* Reuses parent values when they haven't changed to avoid unnecessary recalculations.
|
|
226
|
+
*/
|
|
227
|
+
/* eslint-disable no-param-reassign */
|
|
228
|
+
#assignParentValues(childOptions, options, typesChanged, mergedTypes) {
|
|
229
|
+
if (typesChanged) {
|
|
230
|
+
childOptions.parentTypes = mergedTypes;
|
|
231
|
+
childOptions.parentLongestLabel = getLongestLabel(mergedTypes);
|
|
232
|
+
} else {
|
|
233
|
+
childOptions.parentTypes = this.types;
|
|
234
|
+
childOptions.parentLongestLabel = this.longestLabel;
|
|
235
|
+
}
|
|
236
|
+
if (!options?.logLevels) {
|
|
237
|
+
childOptions.parentLogLevels = this.logLevels;
|
|
238
|
+
}
|
|
239
|
+
if (!options?.messages) {
|
|
240
|
+
childOptions.parentMessages = {
|
|
241
|
+
timerEnd: this.endTimerMessage,
|
|
242
|
+
timerStart: this.startTimerMessage
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
childOptions.parentStringify = this.stringify;
|
|
246
|
+
if (!options?.stdout) {
|
|
247
|
+
childOptions.parentStdout = this.stdout;
|
|
248
|
+
}
|
|
249
|
+
if (!options?.stderr) {
|
|
250
|
+
childOptions.parentStderr = this.stderr;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
/* eslint-enable no-param-reassign */
|
|
254
|
+
/**
|
|
255
|
+
* Gets the interactive manager instance if interactive mode is enabled.
|
|
256
|
+
*
|
|
257
|
+
* Returns the InteractiveManager instance that handles interactive terminal
|
|
258
|
+
* features like progress bars and dynamic updates. Only available when
|
|
259
|
+
* interactive mode is enabled in the constructor options.
|
|
260
|
+
* @returns The interactive manager instance, or undefined if not in interactive mode
|
|
261
|
+
* @example
|
|
262
|
+
* ```typescript
|
|
263
|
+
* const logger = createPail({ interactive: true });
|
|
264
|
+
* const manager = logger.getInteractiveManager();
|
|
265
|
+
* if (manager) {
|
|
266
|
+
* manager.hook();
|
|
267
|
+
* // Use interactive features
|
|
268
|
+
* manager.unhook();
|
|
269
|
+
* }
|
|
270
|
+
* ```
|
|
271
|
+
*/
|
|
272
|
+
getInteractiveManager() {
|
|
273
|
+
return this.interactiveManager;
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* Wraps stdout and stderr streams to redirect them through the logger.
|
|
277
|
+
*
|
|
278
|
+
* Intercepts writes to process.stdout and process.stderr, redirecting them
|
|
279
|
+
* through the logger instead of writing directly to the streams. This allows
|
|
280
|
+
* all output to be processed by the logging pipeline.
|
|
281
|
+
* @example
|
|
282
|
+
* ```typescript
|
|
283
|
+
* const logger = createPail();
|
|
284
|
+
* logger.wrapStd();
|
|
285
|
+
*
|
|
286
|
+
* console.log("This goes through logger");
|
|
287
|
+
* process.stdout.write("This too");
|
|
288
|
+
*
|
|
289
|
+
* logger.restoreStd(); // Restore original streams
|
|
290
|
+
* ```
|
|
291
|
+
*/
|
|
292
|
+
wrapStd() {
|
|
293
|
+
this.#wrapStream(this.stdout, "log");
|
|
294
|
+
this.#wrapStream(this.stderr, "log");
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* Restores the original stdout and stderr streams.
|
|
298
|
+
*
|
|
299
|
+
* Removes the stream wrapping that was applied by wrapStd(),
|
|
300
|
+
* restoring the original stream write methods.
|
|
301
|
+
* @example
|
|
302
|
+
* ```typescript
|
|
303
|
+
* const logger = createPail();
|
|
304
|
+
* logger.wrapStd();
|
|
305
|
+
* // Streams are wrapped
|
|
306
|
+
* logger.restoreStd();
|
|
307
|
+
* // Streams are restored to original behavior
|
|
308
|
+
* ```
|
|
309
|
+
*/
|
|
310
|
+
restoreStd() {
|
|
311
|
+
this.#restoreStream(this.stdout);
|
|
312
|
+
this.#restoreStream(this.stderr);
|
|
313
|
+
}
|
|
314
|
+
/**
|
|
315
|
+
* Wraps all output sources (console and streams).
|
|
316
|
+
*
|
|
317
|
+
* Convenience method that calls both wrapConsole() and wrapStd()
|
|
318
|
+
* to redirect all output through the logger.
|
|
319
|
+
* @example
|
|
320
|
+
* ```typescript
|
|
321
|
+
* const logger = createPail();
|
|
322
|
+
* logger.wrapAll(); // Wraps console and streams
|
|
323
|
+
*
|
|
324
|
+
* // All output now goes through logger
|
|
325
|
+
* console.log("Console output");
|
|
326
|
+
* process.stdout.write("Stream output");
|
|
327
|
+
*
|
|
328
|
+
* logger.restoreAll(); // Restore everything
|
|
329
|
+
* ```
|
|
330
|
+
*/
|
|
331
|
+
wrapAll() {
|
|
332
|
+
this.wrapConsole();
|
|
333
|
+
this.wrapStd();
|
|
334
|
+
}
|
|
335
|
+
/**
|
|
336
|
+
* Restores all wrapped output sources.
|
|
337
|
+
*
|
|
338
|
+
* Convenience method that calls both restoreConsole() and restoreStd()
|
|
339
|
+
* to restore all original output behavior.
|
|
340
|
+
* @example
|
|
341
|
+
* ```typescript
|
|
342
|
+
* const logger = createPail();
|
|
343
|
+
* logger.wrapAll();
|
|
344
|
+
* // All output is wrapped
|
|
345
|
+
* logger.restoreAll();
|
|
346
|
+
* // All output sources are restored
|
|
347
|
+
* ```
|
|
348
|
+
*/
|
|
349
|
+
restoreAll() {
|
|
350
|
+
this.restoreConsole();
|
|
351
|
+
this.restoreStd();
|
|
352
|
+
}
|
|
353
|
+
/**
|
|
354
|
+
* Creates a single progress bar.
|
|
355
|
+
* @param options Configuration options for the progress bar
|
|
356
|
+
* @returns A new ProgressBar instance
|
|
357
|
+
* @example
|
|
358
|
+
* ```typescript
|
|
359
|
+
* const logger = createPail({ interactive: true });
|
|
360
|
+
* const bar = logger.createProgressBar({
|
|
361
|
+
* total: 100,
|
|
362
|
+
* format: 'Downloading [{bar}] {percentage}% | ETA: {eta}s | {value}/{total}'
|
|
363
|
+
* });
|
|
364
|
+
*
|
|
365
|
+
* bar.start();
|
|
366
|
+
* // ... do work and update progress
|
|
367
|
+
* bar.update(50);
|
|
368
|
+
* bar.stop();
|
|
369
|
+
* ```
|
|
370
|
+
*/
|
|
371
|
+
createProgressBar(options) {
|
|
372
|
+
if (!this.interactiveManager) {
|
|
373
|
+
throw new Error("Interactive mode is not enabled. Create Pail with { interactive: true } to use progress bars.");
|
|
374
|
+
}
|
|
375
|
+
const styledOptions = applyStyleToOptions(options);
|
|
376
|
+
return new ProgressBar(styledOptions, this.interactiveManager);
|
|
377
|
+
}
|
|
378
|
+
/**
|
|
379
|
+
* Creates a multi-bar progress manager for displaying multiple progress bars.
|
|
380
|
+
* @param options Configuration options for the multi-bar manager
|
|
381
|
+
* @returns A new MultiProgressBar instance
|
|
382
|
+
* @example
|
|
383
|
+
* ```typescript
|
|
384
|
+
* const logger = createPail({ interactive: true });
|
|
385
|
+
* const multiBar = logger.createMultiProgressBar();
|
|
386
|
+
*
|
|
387
|
+
* const bar1 = multiBar.create(100);
|
|
388
|
+
* const bar2 = multiBar.create(200);
|
|
389
|
+
*
|
|
390
|
+
* bar1.start();
|
|
391
|
+
* bar2.start();
|
|
392
|
+
* // ... update bars as needed
|
|
393
|
+
* multiBar.stop();
|
|
394
|
+
* ```
|
|
395
|
+
*/
|
|
396
|
+
createMultiProgressBar(options = {}) {
|
|
397
|
+
if (!this.interactiveManager) {
|
|
398
|
+
throw new Error("Interactive mode is not enabled. Create Pail with { interactive: true } to use progress bars.");
|
|
399
|
+
}
|
|
400
|
+
const styledOptions = applyStyleToOptions(options);
|
|
401
|
+
return new MultiProgressBar(styledOptions, this.interactiveManager);
|
|
402
|
+
}
|
|
403
|
+
/**
|
|
404
|
+
* Creates a single spinner.
|
|
405
|
+
* @param options Configuration options for the spinner
|
|
406
|
+
* @returns A new Spinner instance
|
|
407
|
+
* @example
|
|
408
|
+
* ```typescript
|
|
409
|
+
* const logger = createPail({ interactive: true });
|
|
410
|
+
* const spinner = logger.createSpinner({ name: 'dots' });
|
|
411
|
+
* spinner.start('Loading...');
|
|
412
|
+
* // ... do work
|
|
413
|
+
* spinner.succeed('Done');
|
|
414
|
+
* ```
|
|
415
|
+
*/
|
|
416
|
+
createSpinner(options = {}) {
|
|
417
|
+
if (!this.interactiveManager) {
|
|
418
|
+
throw new Error("Interactive mode is not enabled. Create Pail with { interactive: true } to use spinners.");
|
|
419
|
+
}
|
|
420
|
+
return new Spinner(options, this.interactiveManager);
|
|
421
|
+
}
|
|
422
|
+
/**
|
|
423
|
+
* Creates a multi-spinner manager for displaying multiple spinners.
|
|
424
|
+
* @param options Configuration options for the multi-spinner manager
|
|
425
|
+
* @returns A new MultiSpinner instance
|
|
426
|
+
* @example
|
|
427
|
+
* ```typescript
|
|
428
|
+
* const logger = createPail({ interactive: true });
|
|
429
|
+
* const multiSpinner = logger.createMultiSpinner();
|
|
430
|
+
*
|
|
431
|
+
* const spinner1 = multiSpinner.create('Loading 1');
|
|
432
|
+
* const spinner2 = multiSpinner.create('Loading 2');
|
|
433
|
+
*
|
|
434
|
+
* spinner1.start();
|
|
435
|
+
* spinner2.start();
|
|
436
|
+
* // ... update spinners as needed
|
|
437
|
+
* multiSpinner.stop();
|
|
438
|
+
* ```
|
|
439
|
+
*/
|
|
440
|
+
createMultiSpinner(options = {}) {
|
|
441
|
+
if (!this.interactiveManager) {
|
|
442
|
+
throw new Error("Interactive mode is not enabled. Create Pail with { interactive: true } to use spinners.");
|
|
443
|
+
}
|
|
444
|
+
return new MultiSpinner(options, this.interactiveManager);
|
|
445
|
+
}
|
|
446
|
+
/**
|
|
447
|
+
* Clears the terminal screen.
|
|
448
|
+
*
|
|
449
|
+
* Sends ANSI escape sequences to clear the terminal screen and move
|
|
450
|
+
* the cursor to the top-left position. This overrides the browser
|
|
451
|
+
* implementation to work with terminal streams.
|
|
452
|
+
* @example
|
|
453
|
+
* ```typescript
|
|
454
|
+
* const logger = createPail();
|
|
455
|
+
* logger.info("Some output");
|
|
456
|
+
* logger.clear(); // Clears the terminal screen
|
|
457
|
+
* ```
|
|
458
|
+
*/
|
|
459
|
+
clear() {
|
|
460
|
+
this.stdout.write(clearTerminal);
|
|
461
|
+
this.stderr.write(clearTerminal);
|
|
462
|
+
}
|
|
463
|
+
extendReporter(reporter) {
|
|
464
|
+
if (typeof reporter.setStdout === "function") {
|
|
465
|
+
reporter.setStdout(this.stdout);
|
|
466
|
+
}
|
|
467
|
+
if (typeof reporter.setStderr === "function") {
|
|
468
|
+
reporter.setStderr(this.stderr);
|
|
469
|
+
}
|
|
470
|
+
if (typeof reporter.setLoggerTypes === "function") {
|
|
471
|
+
reporter.setLoggerTypes(this.types);
|
|
472
|
+
}
|
|
473
|
+
if (typeof reporter.setStringify === "function") {
|
|
474
|
+
reporter.setStringify(this.stringify);
|
|
475
|
+
}
|
|
476
|
+
if (typeof reporter.setIsInteractive === "function") {
|
|
477
|
+
reporter.setIsInteractive(this.interactive);
|
|
478
|
+
}
|
|
479
|
+
if (this.interactive && typeof reporter.setInteractiveManager === "function") {
|
|
480
|
+
reporter.setInteractiveManager(this.interactiveManager);
|
|
481
|
+
}
|
|
482
|
+
return reporter;
|
|
483
|
+
}
|
|
484
|
+
#wrapStream(stream, type) {
|
|
485
|
+
if (!stream) {
|
|
486
|
+
return;
|
|
487
|
+
}
|
|
488
|
+
if (!stream.__write) {
|
|
489
|
+
stream.__write = stream.write;
|
|
490
|
+
}
|
|
491
|
+
stream.write = (data) => {
|
|
492
|
+
this[type](String(data).trim());
|
|
493
|
+
};
|
|
494
|
+
}
|
|
495
|
+
// eslint-disable-next-line class-methods-use-this
|
|
496
|
+
#restoreStream(stream) {
|
|
497
|
+
if (!stream) {
|
|
498
|
+
return;
|
|
499
|
+
}
|
|
500
|
+
if (stream.__write) {
|
|
501
|
+
stream.write = stream.__write;
|
|
502
|
+
delete stream.__write;
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
const PailServer = PailServerImpl;
|
|
507
|
+
|
|
508
|
+
const getDefaultLogLevel = () => {
|
|
509
|
+
if (env.NODE_ENV === "debug" || env.DEBUG !== void 0) {
|
|
510
|
+
return "debug";
|
|
511
|
+
}
|
|
512
|
+
if (env.NODE_ENV === "test") {
|
|
513
|
+
return "warning";
|
|
514
|
+
}
|
|
515
|
+
return "informational";
|
|
516
|
+
};
|
|
517
|
+
const createPail = (options) => {
|
|
518
|
+
let logLevel = getDefaultLogLevel();
|
|
519
|
+
if (env.PAIL_LOG_LEVEL !== void 0) {
|
|
520
|
+
logLevel = env.PAIL_LOG_LEVEL;
|
|
521
|
+
}
|
|
522
|
+
return new PailServer({
|
|
523
|
+
logLevel,
|
|
524
|
+
processors: [new MessageFormatterProcessor()],
|
|
525
|
+
reporters: [new PrettyReporter()],
|
|
526
|
+
stderr,
|
|
527
|
+
stdout,
|
|
528
|
+
...options
|
|
529
|
+
});
|
|
530
|
+
};
|
|
531
|
+
const pail = createPail();
|
|
532
|
+
|
|
533
|
+
export { MultiProgressBar, MultiSpinner, ProgressBar, Spinner, createPail, pail };
|
|
@@ -1,28 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
static readonly DRAIN = true;
|
|
4
|
-
constructor(stream: NodeJS.WriteStream);
|
|
5
|
-
active(): void;
|
|
6
|
-
erase(count: number): void;
|
|
7
|
-
inactive(separateHistory?: boolean): void;
|
|
8
|
-
renew(): void;
|
|
9
|
-
write(message: string): void;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
type StreamType = "stderr" | "stdout";
|
|
13
|
-
declare class InteractiveManager {
|
|
14
|
-
#private;
|
|
15
|
-
constructor(stdout: InteractiveStreamHook, stderr: InteractiveStreamHook);
|
|
16
|
-
get lastLength(): number;
|
|
17
|
-
get outside(): number;
|
|
18
|
-
get isHooked(): boolean;
|
|
19
|
-
get isSuspended(): boolean;
|
|
20
|
-
erase(stream: StreamType, count?: number): void;
|
|
21
|
-
hook(): boolean;
|
|
22
|
-
resume(stream: StreamType, eraseRowCount?: number): void;
|
|
23
|
-
suspend(stream: StreamType, erase?: boolean): void;
|
|
24
|
-
unhook(separateHistory?: boolean): boolean;
|
|
25
|
-
update(stream: StreamType, rows: string[], from?: number): void;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export { InteractiveManager, InteractiveStreamHook };
|
|
1
|
+
export { default as InteractiveManager } from "./interactive-manager.d.ts";
|
|
2
|
+
export { default as InteractiveStreamHook } from "./interactive-stream-hook.d.ts";
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
export { default as InteractiveManager } from '../packem_shared/InteractiveManager-CZ85hGNW.js';
|
|
2
|
+
export { I as InteractiveStreamHook } from '../packem_shared/interactive-stream-hook-DG4BtN12.js';
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import type InteractiveStreamHook from "./interactive-stream-hook.d.ts";
|
|
2
|
+
/** Supported stream types for interactive output */
|
|
3
|
+
type StreamType = "stderr" | "stdout";
|
|
4
|
+
/**
|
|
5
|
+
* Interactive Manager.
|
|
6
|
+
*
|
|
7
|
+
* Manages interactive terminal output by coordinating stdout and stderr streams.
|
|
8
|
+
* Enables features like progress bars, spinners, and dynamic updates by temporarily
|
|
9
|
+
* capturing and controlling terminal output. Supports suspending and resuming
|
|
10
|
+
* interactive mode for external output.
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* const manager = new InteractiveManager(stdoutHook, stderrHook);
|
|
14
|
+
*
|
|
15
|
+
* // Start interactive mode
|
|
16
|
+
* manager.hook();
|
|
17
|
+
*
|
|
18
|
+
* // Update output dynamically
|
|
19
|
+
* manager.update("stdout", ["Processing...", "50% complete"]);
|
|
20
|
+
*
|
|
21
|
+
* // Temporarily suspend for external output
|
|
22
|
+
* manager.suspend("stdout");
|
|
23
|
+
* console.log("External message");
|
|
24
|
+
* manager.resume("stdout");
|
|
25
|
+
*
|
|
26
|
+
* // End interactive mode and show final output
|
|
27
|
+
* manager.unhook();
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
declare class InteractiveManager {
|
|
31
|
+
#private;
|
|
32
|
+
/**
|
|
33
|
+
* Creates a new InteractiveManager with the given stream hooks.
|
|
34
|
+
* @param stdout Hook for stdout stream
|
|
35
|
+
* @param stderr Hook for stderr stream
|
|
36
|
+
*/
|
|
37
|
+
constructor(stdout: InteractiveStreamHook, stderr: InteractiveStreamHook);
|
|
38
|
+
/**
|
|
39
|
+
* Last printed rows count.
|
|
40
|
+
*
|
|
41
|
+
* Tracks the number of rows that were last written to the terminal.
|
|
42
|
+
* Used internally for managing cursor positioning and output updates.
|
|
43
|
+
*/
|
|
44
|
+
get lastLength(): number;
|
|
45
|
+
/**
|
|
46
|
+
* Rows count outside editable area.
|
|
47
|
+
*
|
|
48
|
+
* Tracks the number of rows that extend beyond the current terminal height.
|
|
49
|
+
* Used for managing scrolling and ensuring all output remains visible.
|
|
50
|
+
*/
|
|
51
|
+
get outside(): number;
|
|
52
|
+
/**
|
|
53
|
+
* Hook activity status.
|
|
54
|
+
*
|
|
55
|
+
* Indicates whether the interactive hooks are currently active.
|
|
56
|
+
* When true, streams are being intercepted for interactive output.
|
|
57
|
+
*/
|
|
58
|
+
get isHooked(): boolean;
|
|
59
|
+
/**
|
|
60
|
+
* Suspend status for active hooks.
|
|
61
|
+
*
|
|
62
|
+
* Indicates whether interactive mode is temporarily suspended.
|
|
63
|
+
* When suspended, external output can be written without interference.
|
|
64
|
+
*/
|
|
65
|
+
get isSuspended(): boolean;
|
|
66
|
+
/**
|
|
67
|
+
* Removes lines from the terminal output.
|
|
68
|
+
*
|
|
69
|
+
* Erases the specified number of lines from the bottom of the output,
|
|
70
|
+
* moving the cursor up and clearing the lines. Useful for removing
|
|
71
|
+
* previous interactive output before displaying new content.
|
|
72
|
+
* @param stream The stream to erase lines from ("stdout" or "stderr")
|
|
73
|
+
* @param count Number of lines to remove (defaults to lastLength)
|
|
74
|
+
* @throws {TypeError} If the specified stream is not available
|
|
75
|
+
*/
|
|
76
|
+
erase(stream: StreamType, count?: number): void;
|
|
77
|
+
/**
|
|
78
|
+
* Hook stdout and stderr streams.
|
|
79
|
+
* @returns Success status
|
|
80
|
+
*/
|
|
81
|
+
hook(): boolean;
|
|
82
|
+
/**
|
|
83
|
+
* Resume suspend hooks.
|
|
84
|
+
* @param stream Stream to resume
|
|
85
|
+
* @param eraseRowCount erase output rows count
|
|
86
|
+
*/
|
|
87
|
+
resume(stream: StreamType, eraseRowCount?: number): void;
|
|
88
|
+
/**
|
|
89
|
+
* Suspend active hooks for external output.
|
|
90
|
+
* @param stream Stream to suspend
|
|
91
|
+
* @param erase erase output
|
|
92
|
+
*/
|
|
93
|
+
suspend(stream: StreamType, erase?: boolean): void;
|
|
94
|
+
/**
|
|
95
|
+
* Unhooks both stdout and stderr streams and print their story of logs.
|
|
96
|
+
* @param separateHistory If `true`, will add an empty line to the history output for individual recorded lines and console logs
|
|
97
|
+
* @returns Success status
|
|
98
|
+
*/
|
|
99
|
+
unhook(separateHistory?: boolean): boolean;
|
|
100
|
+
/**
|
|
101
|
+
* Update output.
|
|
102
|
+
* @param stream Stream to write to
|
|
103
|
+
* @param rows Text lines to write to standard output
|
|
104
|
+
* @param from Index of the line starting from which the contents of the terminal are being overwritten
|
|
105
|
+
*/
|
|
106
|
+
update(stream: StreamType, rows: string[], from?: number): void;
|
|
107
|
+
}
|
|
108
|
+
export default InteractiveManager;
|