@visulima/pail 4.0.0-alpha.4 → 4.0.0-alpha.5
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 +16 -0
- package/dist/index.browser.js +1488 -2
- package/dist/index.server.js +2656 -12
- package/dist/interactive/index.js +1 -1
- package/dist/packem_shared/AbstractJsonReporter-DWRpTtGw.js +204 -0
- package/dist/packem_shared/{interactive-stream-hook-DG4BtN12.js → InteractiveStreamHook-ePIURL_U.js} +1 -9
- package/dist/packem_shared/{JsonReporter-VzgyLEYz.js → JsonReporter-BV5lMnJX.js} +1 -1
- package/dist/packem_shared/{PrettyReporter-DySIXBjQ.js → PrettyReporter-BYL3NrdA.js} +49 -4
- package/dist/packem_shared/{format-label-De49vNPd.js → PrettyReporter-DLQtmATi.js} +267 -2
- package/dist/packem_shared/Spinner-B9JUdsbY.js +2150 -0
- package/dist/packem_shared/abstract-pretty-reporter-DckLMlGF.js +2496 -0
- package/dist/packem_shared/constants-B1RjD_ps.js +99 -0
- package/dist/packem_shared/getBarChar-BWj1UrH3.js +404 -0
- package/dist/packem_shared/{index-BomQ3E6J.js → index-DnkF86LQ.js} +9 -1
- package/dist/processor/message-formatter-processor.js +648 -1
- package/dist/reporter/file/json-file-reporter.js +1 -1
- package/dist/reporter/http/abstract-http-reporter.js +1 -1
- package/dist/reporter/json/index.js +2 -2
- package/dist/reporter/pretty/index.browser.js +1 -1
- package/dist/reporter/pretty/index.js +1 -1
- package/dist/reporter/simple/simple-reporter.server.js +1 -6
- package/package.json +4 -4
- package/dist/packem_shared/InteractiveStreamHook-DiSubbJ1.js +0 -21
- package/dist/packem_shared/PrettyReporter-C2wVB7yu.js +0 -222
- package/dist/packem_shared/abstract-pretty-reporter-Di_sdm2r.js +0 -50
- package/dist/packem_shared/get-longest-label-C9PWeyKq.js +0 -9
- package/dist/packem_shared/pail.browser-u2CSR_af.js +0 -1427
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { default as InteractiveManager } from '../packem_shared/InteractiveManager-CbE7d1kY.js';
|
|
2
|
-
export {
|
|
2
|
+
export { default as InteractiveStreamHook } from '../packem_shared/InteractiveStreamHook-ePIURL_U.js';
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
import { E as EMPTY_SYMBOL } from './constants-B1RjD_ps.js';
|
|
2
|
+
|
|
3
|
+
function isPlainObject(value) {
|
|
4
|
+
if (typeof value !== "object" || value === null) {
|
|
5
|
+
return false;
|
|
6
|
+
}
|
|
7
|
+
const prototype = Object.getPrototypeOf(value);
|
|
8
|
+
return (prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null) && !(Symbol.toStringTag in value) && !(Symbol.iterator in value);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const ErrorProto = Object.create(
|
|
12
|
+
{},
|
|
13
|
+
{
|
|
14
|
+
cause: {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
value: void 0,
|
|
17
|
+
writable: true
|
|
18
|
+
},
|
|
19
|
+
code: {
|
|
20
|
+
enumerable: true,
|
|
21
|
+
value: void 0,
|
|
22
|
+
writable: true
|
|
23
|
+
},
|
|
24
|
+
errors: {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
value: void 0,
|
|
27
|
+
writable: true
|
|
28
|
+
},
|
|
29
|
+
message: {
|
|
30
|
+
enumerable: true,
|
|
31
|
+
value: void 0,
|
|
32
|
+
writable: true
|
|
33
|
+
},
|
|
34
|
+
name: {
|
|
35
|
+
enumerable: true,
|
|
36
|
+
value: void 0,
|
|
37
|
+
writable: true
|
|
38
|
+
},
|
|
39
|
+
stack: {
|
|
40
|
+
enumerable: true,
|
|
41
|
+
value: void 0,
|
|
42
|
+
writable: true
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
);
|
|
46
|
+
const toJsonWasCalled = /* @__PURE__ */ new WeakSet();
|
|
47
|
+
const toJSON = (from) => {
|
|
48
|
+
toJsonWasCalled.add(from);
|
|
49
|
+
const json = from.toJSON();
|
|
50
|
+
toJsonWasCalled.delete(from);
|
|
51
|
+
return json;
|
|
52
|
+
};
|
|
53
|
+
const serializeValue = (value, seen, depth, options) => {
|
|
54
|
+
if (value && value instanceof Uint8Array && value.constructor.name === "Buffer") {
|
|
55
|
+
return "[object Buffer]";
|
|
56
|
+
}
|
|
57
|
+
if (value !== null && typeof value === "object" && typeof value.pipe === "function") {
|
|
58
|
+
return "[object Stream]";
|
|
59
|
+
}
|
|
60
|
+
if (value instanceof Error) {
|
|
61
|
+
if (seen.includes(value)) {
|
|
62
|
+
return "[Circular]";
|
|
63
|
+
}
|
|
64
|
+
depth += 1;
|
|
65
|
+
return _serialize(value, options, seen, depth);
|
|
66
|
+
}
|
|
67
|
+
if (options.useToJSON && typeof value.toJSON === "function") {
|
|
68
|
+
return value.toJSON();
|
|
69
|
+
}
|
|
70
|
+
if (typeof value === "object" && value instanceof Date) {
|
|
71
|
+
return value.toISOString();
|
|
72
|
+
}
|
|
73
|
+
if (typeof value === "function") {
|
|
74
|
+
return `[Function: ${value.name || "anonymous"}]`;
|
|
75
|
+
}
|
|
76
|
+
if (isPlainObject(value)) {
|
|
77
|
+
depth += 1;
|
|
78
|
+
if (options.maxDepth && depth >= options.maxDepth) {
|
|
79
|
+
return {};
|
|
80
|
+
}
|
|
81
|
+
const plainObject = {};
|
|
82
|
+
for (const key in value) {
|
|
83
|
+
plainObject[key] = serializeValue(value[key], seen, depth, options);
|
|
84
|
+
}
|
|
85
|
+
return plainObject;
|
|
86
|
+
}
|
|
87
|
+
try {
|
|
88
|
+
return value;
|
|
89
|
+
} catch {
|
|
90
|
+
return "[Not Available]";
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
const _serialize = (error, options, seen, depth) => {
|
|
94
|
+
seen.push(error);
|
|
95
|
+
if (options.maxDepth === 0) {
|
|
96
|
+
return {};
|
|
97
|
+
}
|
|
98
|
+
if (options.useToJSON && typeof error.toJSON === "function" && !toJsonWasCalled.has(error)) {
|
|
99
|
+
return toJSON(error);
|
|
100
|
+
}
|
|
101
|
+
const protoError = Object.create(ErrorProto);
|
|
102
|
+
protoError.name = Object.prototype.toString.call(error.constructor) === "[object Function]" ? error.constructor.name : error.name;
|
|
103
|
+
protoError.message = error.message;
|
|
104
|
+
protoError.stack = error.stack;
|
|
105
|
+
if (Array.isArray(error.errors)) {
|
|
106
|
+
const aggregateErrors = [];
|
|
107
|
+
for (const aggregateError of error.errors) {
|
|
108
|
+
if (!(aggregateError instanceof Error)) {
|
|
109
|
+
throw new TypeError("All errors in the 'errors' property must be instances of Error");
|
|
110
|
+
}
|
|
111
|
+
if (seen.includes(aggregateError)) {
|
|
112
|
+
protoError.errors = [];
|
|
113
|
+
return protoError;
|
|
114
|
+
}
|
|
115
|
+
aggregateErrors.push(_serialize(aggregateError, options, seen, depth));
|
|
116
|
+
}
|
|
117
|
+
protoError.errors = aggregateErrors;
|
|
118
|
+
}
|
|
119
|
+
if (error.cause instanceof Error && !seen.includes(error.cause)) {
|
|
120
|
+
protoError.cause = _serialize(error.cause, options, seen, depth);
|
|
121
|
+
}
|
|
122
|
+
for (const key in error) {
|
|
123
|
+
if (protoError[key] === void 0) {
|
|
124
|
+
const value = error[key];
|
|
125
|
+
protoError[key] = serializeValue(value, seen, depth, options);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
if (Array.isArray(options.exclude) && options.exclude.length > 0) {
|
|
129
|
+
for (const key of options.exclude) {
|
|
130
|
+
try {
|
|
131
|
+
delete protoError[key];
|
|
132
|
+
} catch {
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return protoError;
|
|
137
|
+
};
|
|
138
|
+
const serialize = (error, options = {}) => _serialize(
|
|
139
|
+
error,
|
|
140
|
+
{
|
|
141
|
+
exclude: options.exclude ?? [],
|
|
142
|
+
maxDepth: options.maxDepth ?? Number.POSITIVE_INFINITY,
|
|
143
|
+
useToJSON: options.useToJSON ?? false
|
|
144
|
+
},
|
|
145
|
+
[],
|
|
146
|
+
0
|
|
147
|
+
);
|
|
148
|
+
|
|
149
|
+
class AbstractJsonReporter {
|
|
150
|
+
/** Custom stringify function for object serialization */
|
|
151
|
+
stringify;
|
|
152
|
+
/** Error serialization options */
|
|
153
|
+
errorOptions;
|
|
154
|
+
/**
|
|
155
|
+
* Creates a new AbstractJsonReporter instance.
|
|
156
|
+
* @param options Configuration options for JSON formatting and error handling
|
|
157
|
+
*/
|
|
158
|
+
constructor(options = {}) {
|
|
159
|
+
this.errorOptions = options.error ?? {};
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Sets a custom stringify function for object serialization.
|
|
163
|
+
* @param function_ The stringify function to use for serialization
|
|
164
|
+
*/
|
|
165
|
+
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any
|
|
166
|
+
setStringify(function_) {
|
|
167
|
+
this.stringify = function_;
|
|
168
|
+
}
|
|
169
|
+
// eslint-disable-next-line sonarjs/cognitive-complexity
|
|
170
|
+
log(meta) {
|
|
171
|
+
const { context, error, file, message, type, ...rest } = meta;
|
|
172
|
+
if (rest.label) {
|
|
173
|
+
rest.label = rest.label.trim();
|
|
174
|
+
}
|
|
175
|
+
if (file) {
|
|
176
|
+
rest.file = `${file.name}:${file.line}${file.column ? `:${file.column}` : ""}`;
|
|
177
|
+
}
|
|
178
|
+
if (message === EMPTY_SYMBOL) {
|
|
179
|
+
rest.message = void 0;
|
|
180
|
+
} else {
|
|
181
|
+
rest.message = message;
|
|
182
|
+
}
|
|
183
|
+
if (error) {
|
|
184
|
+
rest.error = serialize(error, this.errorOptions);
|
|
185
|
+
}
|
|
186
|
+
if (context) {
|
|
187
|
+
const newContext = [];
|
|
188
|
+
for (const item of context) {
|
|
189
|
+
if (item === EMPTY_SYMBOL) {
|
|
190
|
+
continue;
|
|
191
|
+
}
|
|
192
|
+
if (item instanceof Error) {
|
|
193
|
+
newContext.push(serialize(item, this.errorOptions));
|
|
194
|
+
} else {
|
|
195
|
+
newContext.push(item);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
rest.context = newContext;
|
|
199
|
+
}
|
|
200
|
+
this._log(this.stringify(rest), type.level);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
export { AbstractJsonReporter };
|
package/dist/packem_shared/{interactive-stream-hook-DG4BtN12.js → InteractiveStreamHook-ePIURL_U.js}
RENAMED
|
@@ -22,17 +22,9 @@ const {
|
|
|
22
22
|
} = __cjs_getBuiltinModule("node:string_decoder");
|
|
23
23
|
|
|
24
24
|
const ESC = "\x1B[";
|
|
25
|
-
const eraseScreen = `${ESC}2J`;
|
|
26
25
|
const eraseLine = `${ESC}2K`;
|
|
27
26
|
const cursorLeft = `${ESC}G`;
|
|
28
27
|
const cursorUp = (count = 1) => `${ESC + count}A`;
|
|
29
|
-
const clearTerminal = process.platform === "win32" ? `${eraseScreen}${ESC}0f` : (
|
|
30
|
-
// 1. Erases the screen (Only done in case `2` is not supported)
|
|
31
|
-
// 2. Erases the whole screen including scrollback buffer
|
|
32
|
-
// 3. Moves cursor to the top-left position
|
|
33
|
-
// More info: https://www.real-world-systems.com/docs/ANSIcode.html
|
|
34
|
-
`${eraseScreen}${ESC}3J${ESC}H`
|
|
35
|
-
);
|
|
36
28
|
const cursorHide = `${ESC}?25l`;
|
|
37
29
|
const cursorShow = `${ESC}?25h`;
|
|
38
30
|
const eraseLines = (count) => {
|
|
@@ -138,4 +130,4 @@ class InteractiveStreamHook {
|
|
|
138
130
|
}
|
|
139
131
|
}
|
|
140
132
|
|
|
141
|
-
export { InteractiveStreamHook as
|
|
133
|
+
export { InteractiveStreamHook as default };
|
|
@@ -9,7 +9,7 @@ const {
|
|
|
9
9
|
stderr
|
|
10
10
|
} = __cjs_getProcess;
|
|
11
11
|
import { w as writeStream } from './write-stream-BG8fhcs3.js';
|
|
12
|
-
import { AbstractJsonReporter } from './AbstractJsonReporter-
|
|
12
|
+
import { AbstractJsonReporter } from './AbstractJsonReporter-DWRpTtGw.js';
|
|
13
13
|
|
|
14
14
|
class JsonReporter extends AbstractJsonReporter {
|
|
15
15
|
/** Standard output stream */
|
|
@@ -1,10 +1,55 @@
|
|
|
1
1
|
import colorize, { grey, white, underline, bold } from '@visulima/colorize/browser';
|
|
2
|
-
import { f as format } from './index-
|
|
3
|
-
import { E as EMPTY_SYMBOL } from './constants-omsTHUWB.js';
|
|
4
|
-
import { A as AbstractPrettyReporter, g as getLongestBadge } from './abstract-pretty-reporter-Di_sdm2r.js';
|
|
5
|
-
import { g as getLongestLabel } from './get-longest-label-C9PWeyKq.js';
|
|
2
|
+
import { f as format, g as getLongestLabel } from './index-DnkF86LQ.js';
|
|
3
|
+
import { L as LOG_TYPES, E as EMPTY_SYMBOL } from './constants-omsTHUWB.js';
|
|
6
4
|
import { w as writeConsoleLogBasedOnLevel } from './write-console-log-based-on-level-DBmRYXpj.js';
|
|
7
5
|
|
|
6
|
+
const getLongestBadge = (types) => {
|
|
7
|
+
const badges = Object.keys(types).map((x) => types[x].badge ?? "");
|
|
8
|
+
if (badges.length === 0) {
|
|
9
|
+
return "";
|
|
10
|
+
}
|
|
11
|
+
return badges.reduce((x, y) => x.length > y.length ? x : y);
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const dateFormatter = (date) => [date.getHours(), date.getMinutes(), date.getSeconds()].map((n) => String(n).padStart(2, "0")).join(":");
|
|
15
|
+
class AbstractPrettyReporter {
|
|
16
|
+
/** Styling options for pretty formatting */
|
|
17
|
+
styles;
|
|
18
|
+
/** Logger type configurations for styling */
|
|
19
|
+
loggerTypes;
|
|
20
|
+
/**
|
|
21
|
+
* Creates a new AbstractPrettyReporter instance.
|
|
22
|
+
* @param options Styling options for pretty formatting
|
|
23
|
+
* @protected
|
|
24
|
+
*/
|
|
25
|
+
constructor(options) {
|
|
26
|
+
this.styles = {
|
|
27
|
+
bold: {
|
|
28
|
+
label: false
|
|
29
|
+
},
|
|
30
|
+
dateFormatter,
|
|
31
|
+
underline: {
|
|
32
|
+
label: false,
|
|
33
|
+
message: false,
|
|
34
|
+
prefix: false,
|
|
35
|
+
suffix: false
|
|
36
|
+
},
|
|
37
|
+
uppercase: {
|
|
38
|
+
label: false
|
|
39
|
+
},
|
|
40
|
+
...options
|
|
41
|
+
};
|
|
42
|
+
this.loggerTypes = LOG_TYPES;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Sets the logger types configuration for styling.
|
|
46
|
+
* @param types Logger type configurations with colors and labels
|
|
47
|
+
*/
|
|
48
|
+
setLoggerTypes(types) {
|
|
49
|
+
this.loggerTypes = types;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
8
53
|
class PrettyReporter extends AbstractPrettyReporter {
|
|
9
54
|
/**
|
|
10
55
|
* Creates a new Browser Pretty Reporter instance.
|
|
@@ -17,10 +17,17 @@ const __cjs_getBuiltinModule = (module) => {
|
|
|
17
17
|
return __cjs_require(module);
|
|
18
18
|
};
|
|
19
19
|
|
|
20
|
+
const {
|
|
21
|
+
stdout,
|
|
22
|
+
stderr
|
|
23
|
+
} = __cjs_getProcess;
|
|
24
|
+
import colorize, { grey, green, cyan, red, yellow, bold, magenta, underline, greenBright, white, bgGrey } from '@visulima/colorize';
|
|
25
|
+
import { t as terminalSize, g as getStringWidth, w as wordWrap, W as WrapMode } from './index-EZ_WSQZS.js';
|
|
26
|
+
import { L as LOG_TYPES, E as EMPTY_SYMBOL } from './constants-B1RjD_ps.js';
|
|
27
|
+
import { w as writeStream } from './write-stream-BG8fhcs3.js';
|
|
20
28
|
const {
|
|
21
29
|
createRequire
|
|
22
30
|
} = __cjs_getBuiltinModule("node:module");
|
|
23
|
-
import { grey, green, cyan, red, yellow, bold, magenta, underline } from '@visulima/colorize';
|
|
24
31
|
|
|
25
32
|
const normalizeLF = (code) => code.replaceAll(/\r\n|\r(?!\n)|\n/gu, "\n");
|
|
26
33
|
const _process = globalThis.process || /* @__PURE__ */ Object.create(null);
|
|
@@ -1158,6 +1165,22 @@ const inspect = (value, options_ = {}) => {
|
|
|
1158
1165
|
return internalInspect(value, options, 0, []);
|
|
1159
1166
|
};
|
|
1160
1167
|
|
|
1168
|
+
const getLongestBadge = (types) => {
|
|
1169
|
+
const badges = Object.keys(types).map((x) => types[x].badge ?? "");
|
|
1170
|
+
if (badges.length === 0) {
|
|
1171
|
+
return "";
|
|
1172
|
+
}
|
|
1173
|
+
return badges.reduce((x, y) => x.length > y.length ? x : y);
|
|
1174
|
+
};
|
|
1175
|
+
|
|
1176
|
+
const getLongestLabel = (types) => {
|
|
1177
|
+
const labels = Object.keys(types).map((x) => types[x].label ?? "");
|
|
1178
|
+
if (labels.length === 0) {
|
|
1179
|
+
return "";
|
|
1180
|
+
}
|
|
1181
|
+
return labels.reduce((x, y) => x.length > y.length ? x : y);
|
|
1182
|
+
};
|
|
1183
|
+
|
|
1161
1184
|
const defaultInspectorConfig = {
|
|
1162
1185
|
indent: 2,
|
|
1163
1186
|
quoteStyle: "single",
|
|
@@ -1190,4 +1213,246 @@ const formatLabel = (label, styles) => {
|
|
|
1190
1213
|
return formattedLabel;
|
|
1191
1214
|
};
|
|
1192
1215
|
|
|
1193
|
-
|
|
1216
|
+
const dateFormatter = (date) => [date.getHours(), date.getMinutes(), date.getSeconds()].map((n) => String(n).padStart(2, "0")).join(":");
|
|
1217
|
+
class AbstractPrettyReporter {
|
|
1218
|
+
/** Styling options for pretty formatting */
|
|
1219
|
+
styles;
|
|
1220
|
+
/** Logger type configurations for styling */
|
|
1221
|
+
loggerTypes;
|
|
1222
|
+
/**
|
|
1223
|
+
* Creates a new AbstractPrettyReporter instance.
|
|
1224
|
+
* @param options Styling options for pretty formatting
|
|
1225
|
+
* @protected
|
|
1226
|
+
*/
|
|
1227
|
+
constructor(options) {
|
|
1228
|
+
this.styles = {
|
|
1229
|
+
bold: {
|
|
1230
|
+
label: false
|
|
1231
|
+
},
|
|
1232
|
+
dateFormatter,
|
|
1233
|
+
underline: {
|
|
1234
|
+
label: false,
|
|
1235
|
+
message: false,
|
|
1236
|
+
prefix: false,
|
|
1237
|
+
suffix: false
|
|
1238
|
+
},
|
|
1239
|
+
uppercase: {
|
|
1240
|
+
label: false
|
|
1241
|
+
},
|
|
1242
|
+
...options
|
|
1243
|
+
};
|
|
1244
|
+
this.loggerTypes = LOG_TYPES;
|
|
1245
|
+
}
|
|
1246
|
+
/**
|
|
1247
|
+
* Sets the logger types configuration for styling.
|
|
1248
|
+
* @param types Logger type configurations with colors and labels
|
|
1249
|
+
*/
|
|
1250
|
+
setLoggerTypes(types) {
|
|
1251
|
+
this.loggerTypes = types;
|
|
1252
|
+
}
|
|
1253
|
+
}
|
|
1254
|
+
|
|
1255
|
+
const pailFileFilter = (line) => !/[\\/]pail[\\/]dist/.test(line);
|
|
1256
|
+
class PrettyReporter extends AbstractPrettyReporter {
|
|
1257
|
+
#stdout;
|
|
1258
|
+
#stderr;
|
|
1259
|
+
#interactiveManager;
|
|
1260
|
+
#interactive = false;
|
|
1261
|
+
#inspectOptions;
|
|
1262
|
+
#errorOptions;
|
|
1263
|
+
/**
|
|
1264
|
+
* Creates a new Server Pretty Reporter instance.
|
|
1265
|
+
* @param options Configuration options for styling, error rendering, and object inspection
|
|
1266
|
+
*/
|
|
1267
|
+
constructor(options = {}) {
|
|
1268
|
+
const { error: errorOptions, inspect: inspectOptions, ...rest } = options;
|
|
1269
|
+
super({
|
|
1270
|
+
uppercase: {
|
|
1271
|
+
label: true,
|
|
1272
|
+
...rest.uppercase
|
|
1273
|
+
},
|
|
1274
|
+
...rest
|
|
1275
|
+
});
|
|
1276
|
+
this.#inspectOptions = { ...defaultInspectorConfig, ...inspectOptions };
|
|
1277
|
+
this.#errorOptions = {
|
|
1278
|
+
...errorOptions,
|
|
1279
|
+
color: {
|
|
1280
|
+
fileLine: green,
|
|
1281
|
+
hint: cyan,
|
|
1282
|
+
marker: red,
|
|
1283
|
+
message: red,
|
|
1284
|
+
method: greenBright,
|
|
1285
|
+
title: red
|
|
1286
|
+
}
|
|
1287
|
+
};
|
|
1288
|
+
this.#stdout = stdout;
|
|
1289
|
+
this.#stderr = stderr;
|
|
1290
|
+
}
|
|
1291
|
+
/**
|
|
1292
|
+
* Sets the stdout stream for the reporter.
|
|
1293
|
+
* @param stdout_ The writable stream to use for standard output
|
|
1294
|
+
*/
|
|
1295
|
+
setStdout(stdout_) {
|
|
1296
|
+
this.#stdout = stdout_;
|
|
1297
|
+
}
|
|
1298
|
+
/**
|
|
1299
|
+
* Sets the stderr stream for the reporter.
|
|
1300
|
+
* @param stderr_ The writable stream to use for error output
|
|
1301
|
+
*/
|
|
1302
|
+
setStderr(stderr_) {
|
|
1303
|
+
this.#stderr = stderr_;
|
|
1304
|
+
}
|
|
1305
|
+
/**
|
|
1306
|
+
* Sets the interactive manager for handling interactive output.
|
|
1307
|
+
* @param manager The interactive manager instance, or undefined to disable
|
|
1308
|
+
*/
|
|
1309
|
+
setInteractiveManager(manager) {
|
|
1310
|
+
this.#interactiveManager = manager;
|
|
1311
|
+
}
|
|
1312
|
+
/**
|
|
1313
|
+
* Enables or disables interactive mode.
|
|
1314
|
+
* @param interactive Whether to enable interactive terminal features
|
|
1315
|
+
*/
|
|
1316
|
+
setIsInteractive(interactive) {
|
|
1317
|
+
this.#interactive = interactive;
|
|
1318
|
+
}
|
|
1319
|
+
log(meta) {
|
|
1320
|
+
this._log(this._formatMessage(meta), meta.type.level);
|
|
1321
|
+
}
|
|
1322
|
+
// eslint-disable-next-line sonarjs/cognitive-complexity, no-underscore-dangle
|
|
1323
|
+
_formatMessage(data) {
|
|
1324
|
+
const { columns } = terminalSize();
|
|
1325
|
+
let size = columns;
|
|
1326
|
+
if (typeof this.styles.messageLength === "number") {
|
|
1327
|
+
size = this.styles.messageLength;
|
|
1328
|
+
}
|
|
1329
|
+
const { badge, context, date, error, file, groups, label, message, prefix, repeated, scope, suffix, traceError, type } = data;
|
|
1330
|
+
const { color } = this.loggerTypes[type.name];
|
|
1331
|
+
const colorized = color ? colorize[color] : white;
|
|
1332
|
+
const groupSpaces = groups.map(() => " ").join("");
|
|
1333
|
+
const items = [];
|
|
1334
|
+
if (groups.length > 0) {
|
|
1335
|
+
items.push(`${groupSpaces + grey(`[${groups.at(-1)}]`)} `);
|
|
1336
|
+
}
|
|
1337
|
+
if (date) {
|
|
1338
|
+
items.push(`${grey(this.styles.dateFormatter(typeof date === "string" ? new Date(date) : date))} `);
|
|
1339
|
+
}
|
|
1340
|
+
if (badge) {
|
|
1341
|
+
items.push(colorized(badge));
|
|
1342
|
+
} else {
|
|
1343
|
+
const longestBadge = getLongestBadge(this.loggerTypes);
|
|
1344
|
+
if (longestBadge.length > 0) {
|
|
1345
|
+
items.push(`${grey(".".repeat(longestBadge.length))} `);
|
|
1346
|
+
}
|
|
1347
|
+
}
|
|
1348
|
+
const longestLabel = getLongestLabel(this.loggerTypes);
|
|
1349
|
+
if (label) {
|
|
1350
|
+
const longestLabelWidth = getStringWidth(longestLabel);
|
|
1351
|
+
const labelWidth = getStringWidth(label);
|
|
1352
|
+
items.push(`${colorized(formatLabel(label, this.styles))} `, grey(".".repeat(Math.max(0, longestLabelWidth - labelWidth))));
|
|
1353
|
+
} else {
|
|
1354
|
+
items.push(grey(".".repeat(longestLabel.length + 2)));
|
|
1355
|
+
}
|
|
1356
|
+
if (repeated) {
|
|
1357
|
+
items.push(`${bgGrey.white(`[${repeated}x]`)} `);
|
|
1358
|
+
}
|
|
1359
|
+
if (Array.isArray(scope) && scope.length > 0) {
|
|
1360
|
+
items.push(` ${grey(`[${scope.join(" > ")}]`)} `);
|
|
1361
|
+
}
|
|
1362
|
+
if (prefix) {
|
|
1363
|
+
items.push(
|
|
1364
|
+
`${grey(`${Array.isArray(scope) && scope.length > 0 ? ". " : " "}[${this.styles.underline.prefix ? underline(prefix) : prefix}]`)} `
|
|
1365
|
+
);
|
|
1366
|
+
}
|
|
1367
|
+
const titleSize = getStringWidth(items.join(" "));
|
|
1368
|
+
if (file) {
|
|
1369
|
+
const fileMessage = file.name + (file.line ? `:${file.line}` : "");
|
|
1370
|
+
const fileMessageSize = getStringWidth(fileMessage);
|
|
1371
|
+
if (fileMessageSize + titleSize + 2 > size) {
|
|
1372
|
+
items.push(grey(` ${fileMessage}`));
|
|
1373
|
+
} else {
|
|
1374
|
+
const dots = Math.max(0, size - titleSize - fileMessageSize - 2);
|
|
1375
|
+
items.push(grey(`${".".repeat(dots)} ${fileMessage}`));
|
|
1376
|
+
}
|
|
1377
|
+
} else {
|
|
1378
|
+
items.push(grey(".".repeat(Math.max(0, size - titleSize - 1))));
|
|
1379
|
+
}
|
|
1380
|
+
if (items.length > 0) {
|
|
1381
|
+
items.push("\n\n");
|
|
1382
|
+
}
|
|
1383
|
+
if (message !== EMPTY_SYMBOL) {
|
|
1384
|
+
const formattedMessage = typeof message === "string" ? message : inspect(message, this.#inspectOptions);
|
|
1385
|
+
items.push(
|
|
1386
|
+
groupSpaces + wordWrap(formattedMessage, {
|
|
1387
|
+
trim: false,
|
|
1388
|
+
width: size - 3,
|
|
1389
|
+
wrapMode: WrapMode.STRICT_WIDTH
|
|
1390
|
+
})
|
|
1391
|
+
);
|
|
1392
|
+
}
|
|
1393
|
+
if (context) {
|
|
1394
|
+
let hasError = false;
|
|
1395
|
+
items.push(
|
|
1396
|
+
...context.map((value) => {
|
|
1397
|
+
if (value instanceof Error) {
|
|
1398
|
+
hasError = true;
|
|
1399
|
+
return `
|
|
1400
|
+
|
|
1401
|
+
${renderError(value, {
|
|
1402
|
+
...this.#errorOptions,
|
|
1403
|
+
filterStacktrace: pailFileFilter,
|
|
1404
|
+
prefix: groupSpaces
|
|
1405
|
+
})}`;
|
|
1406
|
+
}
|
|
1407
|
+
if (typeof value === "object") {
|
|
1408
|
+
return ` ${inspect(value, this.#inspectOptions)}`;
|
|
1409
|
+
}
|
|
1410
|
+
const newValue = (hasError ? "\n\n" : " ") + value;
|
|
1411
|
+
hasError = false;
|
|
1412
|
+
return newValue;
|
|
1413
|
+
})
|
|
1414
|
+
);
|
|
1415
|
+
}
|
|
1416
|
+
if (error) {
|
|
1417
|
+
items.push(
|
|
1418
|
+
renderError(error, {
|
|
1419
|
+
...this.#errorOptions,
|
|
1420
|
+
filterStacktrace: pailFileFilter,
|
|
1421
|
+
prefix: groupSpaces
|
|
1422
|
+
})
|
|
1423
|
+
);
|
|
1424
|
+
}
|
|
1425
|
+
if (traceError) {
|
|
1426
|
+
items.push(
|
|
1427
|
+
`
|
|
1428
|
+
|
|
1429
|
+
${renderError(traceError, {
|
|
1430
|
+
...this.#errorOptions,
|
|
1431
|
+
filterStacktrace: pailFileFilter,
|
|
1432
|
+
hideErrorCauseCodeView: true,
|
|
1433
|
+
hideErrorCodeView: true,
|
|
1434
|
+
hideErrorErrorsCodeView: true,
|
|
1435
|
+
hideMessage: true,
|
|
1436
|
+
prefix: groupSpaces
|
|
1437
|
+
})}`
|
|
1438
|
+
);
|
|
1439
|
+
}
|
|
1440
|
+
if (suffix) {
|
|
1441
|
+
items.push("\n", groupSpaces + grey(this.styles.underline.suffix ? underline(suffix) : suffix));
|
|
1442
|
+
}
|
|
1443
|
+
return items.join("");
|
|
1444
|
+
}
|
|
1445
|
+
// eslint-disable-next-line no-underscore-dangle
|
|
1446
|
+
_log(message, logLevel) {
|
|
1447
|
+
const streamType = ["error", "trace", "warn"].includes(logLevel) ? "stderr" : "stdout";
|
|
1448
|
+
const stream = streamType === "stderr" ? this.#stderr : this.#stdout;
|
|
1449
|
+
if (this.#interactive && this.#interactiveManager !== void 0 && stream.isTTY) {
|
|
1450
|
+
this.#interactiveManager.update(streamType, message.split("\n"), 0);
|
|
1451
|
+
} else {
|
|
1452
|
+
writeStream(`${message}
|
|
1453
|
+
`, stream);
|
|
1454
|
+
}
|
|
1455
|
+
}
|
|
1456
|
+
}
|
|
1457
|
+
|
|
1458
|
+
export { PrettyReporter };
|