@visulima/pail 4.0.0-alpha.9 → 4.0.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.
Files changed (145) hide show
  1. package/CHANGELOG.md +519 -0
  2. package/LICENSE.md +270 -166
  3. package/README.md +53 -24
  4. package/dist/error.d.ts +95 -96
  5. package/dist/error.js +5 -76
  6. package/dist/index.browser.d.ts +568 -47
  7. package/dist/index.browser.js +19 -1499
  8. package/dist/index.server.d.ts +749 -65
  9. package/dist/index.server.js +32 -3179
  10. package/dist/middleware/elysia.d.ts +66 -63
  11. package/dist/middleware/elysia.js +1 -70
  12. package/dist/middleware/express.d.ts +74 -71
  13. package/dist/middleware/express.js +1 -29
  14. package/dist/middleware/fastify.d.ts +70 -67
  15. package/dist/middleware/fastify.js +1 -46
  16. package/dist/middleware/hono.d.ts +75 -72
  17. package/dist/middleware/hono.js +1 -33
  18. package/dist/middleware/next/handler.d.ts +102 -34
  19. package/dist/middleware/next/handler.js +1 -53
  20. package/dist/middleware/sveltekit.d.ts +101 -98
  21. package/dist/middleware/sveltekit.js +1 -43
  22. package/dist/object-tree.d.ts +67 -70
  23. package/dist/object-tree.js +2 -89
  24. package/dist/packem_shared/AbstractJsonReporter-Bp_JCrMQ.js +1 -0
  25. package/dist/packem_shared/AbstractJsonReporter-w_bGGiD-.js +1 -0
  26. package/dist/packem_shared/JsonReporter-Sd_lJGS-.js +2 -0
  27. package/dist/packem_shared/JsonReporter-bmem9lcg.js +1 -0
  28. package/dist/packem_shared/PailError-CbU1Ogfa.js +5 -0
  29. package/dist/packem_shared/PrettyReporter-CcDdPQSt.js +44 -0
  30. package/dist/packem_shared/PrettyReporter-DsHfKOU7.js +5 -0
  31. package/dist/packem_shared/abstract-json-reporter.d-wfESoEa-.d.ts +62 -0
  32. package/dist/packem_shared/abstract-pretty-reporter-DrLBJ6ds.js +57 -0
  33. package/dist/packem_shared/addKnownErrorConstructor-C1OJTj2D-0FlJMfXz.js +25 -0
  34. package/dist/packem_shared/constants-DKfCaSUR.js +1 -0
  35. package/dist/packem_shared/constants-ep2nsfdy.js +1 -0
  36. package/dist/packem_shared/create-middleware-logger.d-B-JmQ1Sl.d.ts +47 -0
  37. package/dist/packem_shared/headers-DH0H2s8W.js +1 -0
  38. package/dist/packem_shared/index-Q1764hvO.js +1 -0
  39. package/dist/packem_shared/index.d-T71KjNAr.d.ts +16 -0
  40. package/dist/packem_shared/pailMiddleware-B5DJoBYl.js +1 -0
  41. package/dist/packem_shared/serializeError-C-NFvZ8_-D0CA_Qlx.js +1 -0
  42. package/dist/packem_shared/storage-DaXAlpiO.js +1 -0
  43. package/dist/packem_shared/types.d-Cz9S7jZh.d.ts +201 -0
  44. package/dist/packem_shared/types.d-bWnqHJKL.d.ts +211 -0
  45. package/dist/packem_shared/types.d-xxE3FOD3.d.ts +229 -0
  46. package/dist/packem_shared/useLogger-DB34CuU5.js +1 -0
  47. package/dist/packem_shared/wide-event.d-D3ATYpoK.d.ts +717 -0
  48. package/dist/packem_shared/write-console-log-based-on-level-BqjxV016.js +1 -0
  49. package/dist/packem_shared/write-stream-C7jxLxIT.js +1 -0
  50. package/dist/processor/caller/caller-processor.d.ts +50 -47
  51. package/dist/processor/caller/caller-processor.js +1 -59
  52. package/dist/processor/environment-processor.d.ts +114 -113
  53. package/dist/processor/environment-processor.js +1 -78
  54. package/dist/processor/message-formatter-processor.d.ts +59 -49
  55. package/dist/processor/message-formatter-processor.js +1 -713
  56. package/dist/processor/opentelemetry-processor.d.ts +70 -66
  57. package/dist/processor/opentelemetry-processor.js +1 -52
  58. package/dist/processor/redact-processor.d.ts +99 -41
  59. package/dist/processor/redact-processor.js +1 -30
  60. package/dist/processor/sampling-processor.d.ts +103 -101
  61. package/dist/processor/sampling-processor.js +1 -59
  62. package/dist/reporter/file/json-file-reporter.d.ts +109 -42
  63. package/dist/reporter/file/json-file-reporter.js +2 -136
  64. package/dist/reporter/http/abstract-http-reporter.d.ts +256 -211
  65. package/dist/reporter/http/abstract-http-reporter.js +2 -435
  66. package/dist/reporter/http/http-reporter.d.ts +41 -36
  67. package/dist/reporter/http/http-reporter.edge-light.d.ts +487 -39
  68. package/dist/reporter/http/http-reporter.edge-light.js +2 -733
  69. package/dist/reporter/http/http-reporter.js +1 -13
  70. package/dist/reporter/json/index.browser.d.ts +98 -3
  71. package/dist/reporter/json/index.browser.js +1 -2
  72. package/dist/reporter/json/index.d.ts +53 -3
  73. package/dist/reporter/json/index.js +1 -2
  74. package/dist/reporter/pretty/index.browser.d.ts +105 -2
  75. package/dist/reporter/pretty/index.browser.js +1 -1
  76. package/dist/reporter/pretty/index.d.ts +270 -2
  77. package/dist/reporter/pretty/index.js +1 -1
  78. package/dist/reporter/simple/simple-reporter.server.d.ts +215 -18
  79. package/dist/reporter/simple/simple-reporter.server.js +8 -182
  80. package/dist/wide-event.d.ts +6 -300
  81. package/dist/wide-event.js +1 -281
  82. package/package.json +43 -58
  83. package/dist/constants.d.ts +0 -37
  84. package/dist/interactive/index.d.ts +0 -2
  85. package/dist/interactive/index.js +0 -2
  86. package/dist/interactive/interactive-manager.d.ts +0 -108
  87. package/dist/interactive/interactive-stream-hook.d.ts +0 -68
  88. package/dist/middleware/next/middleware.d.ts +0 -59
  89. package/dist/middleware/next/storage.d.ts +0 -14
  90. package/dist/middleware/shared/create-middleware-logger.d.ts +0 -82
  91. package/dist/middleware/shared/headers.d.ts +0 -14
  92. package/dist/middleware/shared/routes.d.ts +0 -30
  93. package/dist/middleware/shared/storage.d.ts +0 -29
  94. package/dist/packem_shared/AbstractJsonReporter-CGKHS8_M.js +0 -286
  95. package/dist/packem_shared/AbstractJsonReporter-DDjDkciI.js +0 -286
  96. package/dist/packem_shared/InteractiveManager-Cd6A14ZK.js +0 -172
  97. package/dist/packem_shared/InteractiveStreamHook-ePIURL_U.js +0 -133
  98. package/dist/packem_shared/JsonReporter-B3XX8GHN.js +0 -58
  99. package/dist/packem_shared/JsonReporter-p_BXg6Sj.js +0 -28
  100. package/dist/packem_shared/PrettyReporter-BYL3NrdA.js +0 -214
  101. package/dist/packem_shared/PrettyReporter-CvBn-hxP.js +0 -1459
  102. package/dist/packem_shared/Spinner-DIdVcfWq.js +0 -2183
  103. package/dist/packem_shared/abstract-pretty-reporter-jU8WL_6c.js +0 -2602
  104. package/dist/packem_shared/constants-B1RjD_ps.js +0 -99
  105. package/dist/packem_shared/constants-omsTHUWB.js +0 -119
  106. package/dist/packem_shared/createPailError-B11aRfrT.js +0 -76
  107. package/dist/packem_shared/getBarChar-BWj1UrH3.js +0 -404
  108. package/dist/packem_shared/headers-Cp4uLtr4.js +0 -123
  109. package/dist/packem_shared/index-DnkF86LQ.js +0 -658
  110. package/dist/packem_shared/index-frijFf5m.js +0 -1252
  111. package/dist/packem_shared/pailMiddleware-Ci88geIF.js +0 -24
  112. package/dist/packem_shared/storage-D0vqz8OX.js +0 -36
  113. package/dist/packem_shared/useLogger-D0rU3lcX.js +0 -33
  114. package/dist/packem_shared/write-console-log-based-on-level-DBmRYXpj.js +0 -14
  115. package/dist/packem_shared/write-stream-BG8fhcs3.js +0 -6
  116. package/dist/pail.browser.d.ts +0 -412
  117. package/dist/pail.server.d.ts +0 -233
  118. package/dist/processor/caller/get-caller-filename.d.ts +0 -23
  119. package/dist/progress-bar.d.ts +0 -136
  120. package/dist/progress-bar.js +0 -404
  121. package/dist/reporter/file/utils/rotating-file-stream.d.ts +0 -48
  122. package/dist/reporter/http/utils/compression.d.ts +0 -7
  123. package/dist/reporter/http/utils/log-size-error.d.ts +0 -30
  124. package/dist/reporter/http/utils/retry.d.ts +0 -27
  125. package/dist/reporter/json/abstract-json-reporter.d.ts +0 -61
  126. package/dist/reporter/json/json-reporter.browser.d.ts +0 -40
  127. package/dist/reporter/json/json-reporter.server.d.ts +0 -50
  128. package/dist/reporter/pretty/abstract-pretty-reporter.d.ts +0 -83
  129. package/dist/reporter/pretty/pretty-reporter.browser.d.ts +0 -36
  130. package/dist/reporter/pretty/pretty-reporter.server.d.ts +0 -70
  131. package/dist/reporter/raw/raw-reporter.browser.d.ts +0 -5
  132. package/dist/reporter/raw/raw-reporter.server.d.ts +0 -13
  133. package/dist/reporter/utils/default-inspector-config.d.ts +0 -3
  134. package/dist/reporter/utils/format-label.d.ts +0 -3
  135. package/dist/spinner.d.ts +0 -220
  136. package/dist/spinner.js +0 -2183
  137. package/dist/types.d.ts +0 -241
  138. package/dist/utils/ansi-escapes.d.ts +0 -4
  139. package/dist/utils/arrayify.d.ts +0 -2
  140. package/dist/utils/get-longest-badge.d.ts +0 -4
  141. package/dist/utils/get-longest-label.d.ts +0 -4
  142. package/dist/utils/merge-types.d.ts +0 -4
  143. package/dist/utils/stream/safe-stream-handler.d.ts +0 -21
  144. package/dist/utils/write-console-log-based-on-level.d.ts +0 -4
  145. package/dist/utils/write-stream.d.ts +0 -2
@@ -1,1459 +0,0 @@
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 __cjs_getBuiltinModule = (module) => {
8
- // Check if we're in Node.js and version supports getBuiltinModule
9
- if (typeof __cjs_getProcess !== "undefined" && __cjs_getProcess.versions && __cjs_getProcess.versions.node) {
10
- const [major, minor] = __cjs_getProcess.versions.node.split(".").map(Number);
11
- // Node.js 20.16.0+ and 22.3.0+
12
- if (major > 22 || (major === 22 && minor >= 3) || (major === 20 && minor >= 16)) {
13
- return __cjs_getProcess.getBuiltinModule(module);
14
- }
15
- }
16
- // Fallback to createRequire
17
- return __cjs_require(module);
18
- };
19
-
20
- const {
21
- stdout,
22
- stderr
23
- } = __cjs_getProcess;
24
- import colorize, { grey, green, cyan, red, yellow, bold, magenta, underline, greenBright, bgGrey, white } from '@visulima/colorize';
25
- import { t as terminalSize, g as getStringWidth, w as wordWrap, W as WrapMode } from './index-frijFf5m.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';
28
- const {
29
- createRequire
30
- } = __cjs_getBuiltinModule("node:module");
31
-
32
- const normalizeLF = (code) => code.replaceAll(/\r\n|\r(?!\n)|\n/gu, "\n");
33
- const _process = globalThis.process || /* @__PURE__ */ Object.create(null);
34
- const processShims = {
35
- versions: {}
36
- };
37
- const process$1 = /* @__PURE__ */ new Proxy(_process, {
38
- get(target, property) {
39
- if (property in target) {
40
- return target[property];
41
- }
42
- if (property in processShims) {
43
- return processShims[property];
44
- }
45
- return void 0;
46
- }
47
- });
48
- const getMarkerLines = (loc, source, linesAbove, linesBelow) => {
49
- const startLoc = {
50
- column: 0,
51
- // @ts-expect-error Can be overwritten
52
- line: -1,
53
- ...loc.start
54
- };
55
- const endLoc = {
56
- ...startLoc,
57
- ...loc.end
58
- };
59
- const startLine = startLoc.line;
60
- const startColumn = startLoc.column;
61
- const endLine = endLoc.line;
62
- const endColumn = endLoc.column;
63
- let start = Math.max(startLine - (linesAbove + 1), 0);
64
- let end = Math.min(source.length, endLine + linesBelow);
65
- if (startLine === -1) {
66
- start = 0;
67
- }
68
- if (endLine === -1) {
69
- end = source.length;
70
- }
71
- const lineDiff = endLine - startLine;
72
- const markerLines = {};
73
- if (lineDiff) {
74
- for (let index = 0; index <= lineDiff; index++) {
75
- const lineNumber = index + startLine;
76
- if (!startColumn) {
77
- markerLines[lineNumber] = true;
78
- } else if (index === 0) {
79
- const sourceLength = source[lineNumber - 1]?.length;
80
- markerLines[lineNumber] = [startColumn, (sourceLength ?? 0) - startColumn + 1];
81
- } else if (index === lineDiff) {
82
- markerLines[lineNumber] = [0, endColumn];
83
- } else {
84
- const sourceLength = source[lineNumber - index]?.length;
85
- markerLines[lineNumber] = [0, sourceLength];
86
- }
87
- }
88
- } else if (startColumn === endColumn) {
89
- markerLines[startLine] = startColumn ? [startColumn, 0] : true;
90
- } else {
91
- markerLines[startLine] = [startColumn, (endColumn ?? 0) - (startColumn ?? 0)];
92
- }
93
- return { end, markerLines, start };
94
- };
95
- const CODE_FRAME_POINTER = process$1.platform === "win32" && !process$1.env?.WT_SESSION ? ">" : "❯";
96
- const codeFrame = (source, loc, options) => {
97
- const config = {
98
- // grab 2 lines before, and 3 lines after focused line
99
- linesAbove: 2,
100
- linesBelow: 3,
101
- prefix: "",
102
- showGutter: true,
103
- tabWidth: 4,
104
- ...options,
105
- color: {
106
- gutter: (value) => value,
107
- marker: (value) => value,
108
- message: (value) => value,
109
- ...options?.color
110
- }
111
- };
112
- const hasColumns = loc.start && typeof loc.start.column === "number";
113
- let lines = normalizeLF(source).split("\n");
114
- if (typeof config?.tabWidth === "number") {
115
- lines = lines.map((ln) => ln.replaceAll(" ", " ".repeat(config.tabWidth)));
116
- }
117
- const { end, markerLines, start } = getMarkerLines(loc, lines, config.linesAbove, config.linesBelow);
118
- const numberMaxWidth = String(end).length;
119
- const { gutter: colorizeGutter, marker: colorizeMarker, message: colorizeMessage } = config.color;
120
- let frame = lines.slice(start, end).map((line, index) => {
121
- const number = start + 1 + index;
122
- const hasMarker = markerLines[number];
123
- const paddedNumber = ` ${number}`.slice(-numberMaxWidth);
124
- const lastMarkerLine = !markerLines[number + 1];
125
- const gutter = ` ${paddedNumber}${config.showGutter ? " |" : ""}`;
126
- if (hasMarker) {
127
- let markerLine = "";
128
- if (Array.isArray(hasMarker)) {
129
- const markerSpacing = line.replaceAll(/[^\t]/g, " ").slice(0, Math.max(hasMarker[0] - 1, 0));
130
- const numberOfMarkers = hasMarker[1] || 1;
131
- markerLine = [
132
- "\n ",
133
- config.prefix + colorizeGutter(gutter.replaceAll(/\d/g, " ")),
134
- " ",
135
- markerSpacing,
136
- colorizeMarker("^").repeat(numberOfMarkers)
137
- ].join("");
138
- if (lastMarkerLine && config.message) {
139
- markerLine += ` ${colorizeMessage(config.message)}`;
140
- }
141
- }
142
- return [config.prefix + colorizeMarker(CODE_FRAME_POINTER), colorizeGutter(gutter), line.length > 0 ? ` ${line}` : "", markerLine].join("");
143
- }
144
- return `${config.prefix} ${colorizeGutter(gutter)}${line.length > 0 ? ` ${line}` : ""}`;
145
- }).join("\n");
146
- if (config.message && !hasColumns) {
147
- frame = `${config.prefix + " ".repeat(numberMaxWidth + 1) + config.message}
148
- ${frame}`;
149
- }
150
- return frame;
151
- };
152
-
153
- const debugLog = (message, ...arguments_) => {
154
- if (process.env.DEBUG && String(process.env.DEBUG) === "true") {
155
- console.debug(`error:parse-stacktrace: ${message}`, ...arguments_);
156
- }
157
- };
158
- const UNKNOWN_FUNCTION = "<unknown>";
159
- const CHROMIUM_REGEX = /^.*?\s*at\s(?:(.+?\)(?:\s\[.+\])?|\(?.*?)\s?\((?:address\sat\s)?)?(?:async\s)?((?:<anonymous>|[-a-z]+:|.*bundle|\/)?.*?)(?::(\d+))?(?::(\d+))?\)?\s*$/i;
160
- const CHROMIUM_EVAL_REGEX = /\((\S+)\),\s(<[^>]+>)?:(\d+)?:(\d+)?\)?/;
161
- const CHROMIUM_MAPPED = /(.*?):(\d+):(\d+)(\s<-\s(.+):(\d+):(\d+))?/;
162
- const WINDOWS_EVAL_REGEX = /(eval)\sat\s(<anonymous>)\s\((.*)\)?:(\d+)?:(\d+)\),\s*(<anonymous>)?:(\d+)?:(\d+)/;
163
- const NODE_REGEX = /^\s*in\s(?:([^\\/]+(?:\s\[as\s\S+\])?)\s\(?)?\(at?\s?(.*?):(\d+)(?::(\d+))?\)?\s*$/;
164
- const NODE_NESTED_REGEX = /in\s(.*)\s\(at\s(.+)\)\sat/;
165
- const REACT_ANDROID_NATIVE_REGEX = /^(?:.*@)?(.*):(\d+):(\d+)$/;
166
- const GECKO_REGEX = /^\s*(.*?)(?:\((.*?)\))?(?:^|@)?((?:[-a-z]+)?:\/.*?|\[native code\]|[^@]*(?:bundle|\d+\.js)|\/[\w\-. \/=]+)(?::(\d+))?(?::(\d+))?\s*$/i;
167
- const GECKO_EVAL_REGEX = /(\S+) line (\d+)(?: > eval line \d+)* > eval/i;
168
- const FIREFOX_REGEX = /(\S[^\s[]*\[.*\]|.*?)@(.*):(\d+):(\d+)/;
169
- const WEBPACK_ERROR_REGEXP = /\(error: (.*)\)/;
170
- const extractSafariExtensionDetails = (methodName, url) => {
171
- const isSafariExtension = methodName.includes("safari-extension");
172
- const isSafariWebExtension = methodName.includes("safari-web-extension");
173
- return isSafariExtension || isSafariWebExtension ? [
174
- methodName.includes("@") ? methodName.split("@")[0] : UNKNOWN_FUNCTION,
175
- isSafariExtension ? `safari-extension:${url}` : `safari-web-extension:${url}`
176
- ] : [methodName, url];
177
- };
178
- const parseMapped = (trace, maybeMapped) => {
179
- const match = CHROMIUM_MAPPED.exec(maybeMapped);
180
- if (match) {
181
- trace.file = match[1];
182
- trace.line = +match[2];
183
- trace.column = +match[3];
184
- }
185
- };
186
- const parseNode = (line) => {
187
- const nestedNode = NODE_NESTED_REGEX.exec(line);
188
- if (nestedNode) {
189
- debugLog(`parse nested node error stack line: "${line}"`, `found: ${JSON.stringify(nestedNode)}`);
190
- const split = nestedNode[2].split(":");
191
- return {
192
- column: split[2] ? +split[2] : void 0,
193
- file: split[0],
194
- line: split[1] ? +split[1] : void 0,
195
- methodName: nestedNode[1] || UNKNOWN_FUNCTION,
196
- raw: line,
197
- type: void 0
198
- };
199
- }
200
- const node = NODE_REGEX.exec(line);
201
- if (node) {
202
- debugLog(`parse node error stack line: "${line}"`, `found: ${JSON.stringify(node)}`);
203
- const trace = {
204
- column: node[4] ? +node[4] : void 0,
205
- file: node[2] ? node[2].replace(/at\s/, "") : void 0,
206
- line: node[3] ? +node[3] : void 0,
207
- methodName: node[1] || UNKNOWN_FUNCTION,
208
- raw: line,
209
- type: line.startsWith("internal") ? "internal" : void 0
210
- };
211
- parseMapped(trace, `${node[2]}:${node[3]}:${node[4]}`);
212
- return trace;
213
- }
214
- return void 0;
215
- };
216
- const parseChromium = (line) => {
217
- const parts = CHROMIUM_REGEX.exec(line);
218
- if (parts) {
219
- debugLog(`parse chrome error stack line: "${line}"`, `found: ${JSON.stringify(parts)}`);
220
- const isNative = parts[2]?.startsWith("native");
221
- const isEval = parts[2]?.startsWith("eval") || parts[1]?.startsWith("eval");
222
- let evalOrigin;
223
- let windowsParts;
224
- if (isEval) {
225
- const subMatch = CHROMIUM_EVAL_REGEX.exec(line);
226
- if (subMatch) {
227
- const split = /^(\S+):(\d+):(\d+)$|^(\S+):(\d+)$/.exec(subMatch[1]);
228
- if (split) {
229
- parts[2] = split[4] ?? split[1];
230
- parts[3] = split[5] ?? split[2];
231
- parts[4] = split[3];
232
- } else if (subMatch[2]) {
233
- parts[2] = subMatch[1];
234
- }
235
- if (subMatch[2]) {
236
- evalOrigin = {
237
- column: subMatch[4] ? +subMatch[4] : void 0,
238
- file: subMatch[2],
239
- line: subMatch[3] ? +subMatch[3] : void 0,
240
- methodName: "eval",
241
- raw: line,
242
- type: "eval"
243
- };
244
- }
245
- } else {
246
- const windowsSubMatch = WINDOWS_EVAL_REGEX.exec(line);
247
- if (windowsSubMatch) {
248
- windowsParts = {
249
- column: windowsSubMatch[5] ? +windowsSubMatch[5] : void 0,
250
- file: windowsSubMatch[3],
251
- line: windowsSubMatch[4] ? +windowsSubMatch[4] : void 0
252
- };
253
- evalOrigin = {
254
- column: windowsSubMatch[8] ? +windowsSubMatch[8] : void 0,
255
- file: windowsSubMatch[2],
256
- line: windowsSubMatch[7] ? +windowsSubMatch[7] : void 0,
257
- methodName: "eval",
258
- raw: windowsSubMatch[0],
259
- type: "eval"
260
- };
261
- }
262
- }
263
- }
264
- const [methodName, file] = extractSafariExtensionDetails(
265
- // Normalize IE's 'Anonymous function'
266
- parts[1] ? parts[1].replace(/^Anonymous function$/, "<anonymous>") : UNKNOWN_FUNCTION,
267
- parts[2]
268
- );
269
- const trace = {
270
- column: parts[4] ? +parts[4] : void 0,
271
- evalOrigin,
272
- file,
273
- line: parts[3] ? +parts[3] : void 0,
274
- methodName,
275
- raw: line,
276
- // eslint-disable-next-line sonarjs/no-nested-conditional
277
- type: isEval ? "eval" : isNative ? "native" : void 0
278
- };
279
- if (windowsParts) {
280
- trace.column = windowsParts.column;
281
- trace.file = windowsParts.file;
282
- trace.line = windowsParts.line;
283
- } else {
284
- parseMapped(trace, `${file}:${parts[3]}:${parts[4]}`);
285
- }
286
- return trace;
287
- }
288
- return void 0;
289
- };
290
- const parseGecko = (line, topFrameMeta) => {
291
- const parts = GECKO_REGEX.exec(line);
292
- if (parts) {
293
- debugLog(`parse gecko error stack line: "${line}"`, `found: ${JSON.stringify(parts)}`);
294
- const isEval = parts[3]?.includes(" > eval");
295
- const subMatch = isEval && parts[3] && GECKO_EVAL_REGEX.exec(parts[3]);
296
- let evalOrigin;
297
- if (isEval && subMatch) {
298
- parts[3] = subMatch[1];
299
- evalOrigin = {
300
- column: parts[5] ? +parts[5] : void 0,
301
- file: parts[3],
302
- line: parts[4] ? +parts[4] : void 0,
303
- methodName: "eval",
304
- raw: line,
305
- type: "eval"
306
- };
307
- parts[4] = subMatch[2];
308
- }
309
- const [methodName, file] = extractSafariExtensionDetails(
310
- // Normalize IE's 'Anonymous function'
311
- parts[1] ? parts[1].replace(/^Anonymous function$/, "<anonymous>") : UNKNOWN_FUNCTION,
312
- parts[3]
313
- );
314
- let column;
315
- if ((topFrameMeta?.type === "safari" || !isEval && topFrameMeta?.type === "firefox") && topFrameMeta.column) {
316
- column = topFrameMeta.column;
317
- } else if (!isEval && parts[5]) {
318
- column = +parts[5];
319
- }
320
- let lineNumber;
321
- if ((topFrameMeta?.type === "safari" || !isEval && topFrameMeta?.type === "firefox") && topFrameMeta.line) {
322
- lineNumber = topFrameMeta.line;
323
- } else if (parts[4]) {
324
- lineNumber = +parts[4];
325
- }
326
- return {
327
- column,
328
- evalOrigin,
329
- file,
330
- line: lineNumber,
331
- methodName,
332
- raw: line,
333
- // eslint-disable-next-line sonarjs/no-nested-conditional
334
- type: isEval ? "eval" : file.includes("[native code]") ? "native" : void 0
335
- };
336
- }
337
- return void 0;
338
- };
339
- const parseFirefox = (line, topFrameMeta) => {
340
- const parts = FIREFOX_REGEX.exec(line);
341
- const isEval = parts ? parts[2].includes(" > eval") : false;
342
- if (!isEval && parts) {
343
- debugLog(`parse firefox error stack line: "${line}"`, `found: ${JSON.stringify(parts)}`);
344
- return {
345
- column: parts[4] ? +parts[4] : topFrameMeta?.column ?? void 0,
346
- file: parts[2],
347
- line: parts[3] ? +parts[3] : topFrameMeta?.line ?? void 0,
348
- methodName: parts[1] || UNKNOWN_FUNCTION,
349
- raw: line,
350
- type: void 0
351
- };
352
- }
353
- return void 0;
354
- };
355
- const parseReactAndroidNative = (line) => {
356
- const parts = REACT_ANDROID_NATIVE_REGEX.exec(line);
357
- if (parts) {
358
- debugLog(`parse react android native error stack line: "${line}"`, `found: ${JSON.stringify(parts)}`);
359
- return {
360
- column: parts[3] ? +parts[3] : void 0,
361
- file: parts[1],
362
- line: parts[2] ? +parts[2] : void 0,
363
- methodName: UNKNOWN_FUNCTION,
364
- raw: line,
365
- type: void 0
366
- };
367
- }
368
- return void 0;
369
- };
370
- const parseStacktrace = (error, { filter, frameLimit = 50 } = {}) => {
371
- let lines = (error.stacktrace ?? error.stack ?? "").split("\n").map((line) => {
372
- const cleanedLine = WEBPACK_ERROR_REGEXP.test(line) ? line.replace(WEBPACK_ERROR_REGEXP, "$1") : line;
373
- return cleanedLine.replace(/^\s+|\s+$/g, "");
374
- }).filter((line) => !/\S*(?:Error: |AggregateError:)/.test(line) && line !== "eval code");
375
- if (filter) {
376
- lines = lines.filter((element) => filter(element));
377
- }
378
- lines = lines.slice(0, frameLimit);
379
- return lines.reduce((stack, line, currentIndex) => {
380
- if (!line) {
381
- return stack;
382
- }
383
- if (line.length > 1024) {
384
- return stack;
385
- }
386
- let parseResult;
387
- if (/^\s*in\s.*/.test(line)) {
388
- parseResult = parseNode(line);
389
- } else if (/^.*?\s*at\s.*/.test(line)) {
390
- parseResult = parseChromium(line);
391
- } else if (/^.*?\s*@.*|\[native code\]/.test(line)) {
392
- let topFrameMeta;
393
- if (currentIndex === 0) {
394
- if (error.columnNumber || error.lineNumber) {
395
- topFrameMeta = {
396
- // @ts-expect-error columnNumber and columnNumber property only exists on Firefox
397
- column: error.columnNumber,
398
- // @ts-expect-error columnNumber and lineNumber property only exists on Firefox
399
- line: error.lineNumber,
400
- type: "firefox"
401
- };
402
- } else if (error.line || error.column) {
403
- topFrameMeta = {
404
- // @ts-expect-error column property only exists on safari
405
- column: error.column,
406
- // @ts-expect-error line property only exists on safari
407
- line: error.line,
408
- type: "safari"
409
- };
410
- }
411
- }
412
- parseResult = parseFirefox(line, topFrameMeta) || parseGecko(line, topFrameMeta);
413
- } else {
414
- parseResult = parseReactAndroidNative(line);
415
- }
416
- if (parseResult) {
417
- stack.push(parseResult);
418
- } else {
419
- debugLog(`parse error stack line: "${line}"`, "not parser found");
420
- }
421
- return stack;
422
- }, []);
423
- };
424
-
425
- const {
426
- existsSync,
427
- readFileSync
428
- } = __cjs_getBuiltinModule("node:fs");
429
- const {
430
- relative
431
- } = __cjs_getBuiltinModule("node:path");
432
- const {
433
- cwd
434
- } = __cjs_getProcess;
435
- const {
436
- fileURLToPath
437
- } = __cjs_getBuiltinModule("node:url");
438
- const getPrefix = (prefix, indentation, deep) => {
439
- if (deep === 0) {
440
- return prefix.toString();
441
- }
442
- if (indentation === " ") {
443
- return prefix + " ".repeat(deep);
444
- }
445
- return prefix + " ".repeat(indentation * deep);
446
- };
447
- const getRelativePath = (filePath, cwdPath) => {
448
- const path = filePath.replace("async file:", "file:");
449
- return relative(cwdPath, path.startsWith("file:") ? fileURLToPath(path) : path);
450
- };
451
- const getTitleText = (error, hideErrorTitle, color) => {
452
- if (hideErrorTitle) {
453
- return color.title(error.message);
454
- }
455
- const messagePart = error.message ? `: ${error.message}` : "";
456
- return color.title(error.name + messagePart);
457
- };
458
- const getMessage = (error, { color, hideErrorTitle, indentation, prefix }, deep) => `${getPrefix(prefix, indentation, deep)}${getTitleText(error, hideErrorTitle, color)}
459
- `;
460
- const getHint = (error, { color, indentation, prefix }, deep) => {
461
- if (error.hint === void 0) {
462
- return void 0;
463
- }
464
- const spaces = getPrefix(prefix, indentation, deep);
465
- let message = "";
466
- if (Array.isArray(error.hint)) {
467
- for (const line of error.hint) {
468
- message += `${(spaces + line).toString()}
469
- `;
470
- }
471
- } else {
472
- message += spaces + error.hint;
473
- }
474
- return color.hint(message);
475
- };
476
- const getMainFrame = (trace, { color, cwd: cwdPath, displayShortPath, indentation, prefix }, deep = 0) => {
477
- const filePath = displayShortPath ? getRelativePath(trace.file, cwdPath) : trace.file;
478
- const { fileLine, method } = color;
479
- return `${getPrefix(prefix, indentation, deep)}at ${trace.methodName ? `${method(trace.methodName)} ` : ""}${fileLine(filePath)}:${fileLine(
480
- trace.line?.toString() ?? ""
481
- )}`.toString();
482
- };
483
- const getCode = (trace, { color, indentation, linesAbove, linesBelow, prefix, showGutter, showLineNumbers, tabWidth }, deep) => {
484
- if (trace.file === void 0) {
485
- return void 0;
486
- }
487
- const filePath = trace.file.replace("file://", "");
488
- if (!existsSync(filePath)) {
489
- return void 0;
490
- }
491
- const fileContent = readFileSync(filePath, "utf8");
492
- return codeFrame(
493
- fileContent,
494
- {
495
- start: { column: trace.column, line: trace.line }
496
- },
497
- { color, linesAbove, linesBelow, prefix: getPrefix(prefix, indentation, deep), showGutter, showLineNumbers, tabWidth }
498
- );
499
- };
500
- const getErrors = (error, options, deep) => {
501
- if (error.errors.length === 0) {
502
- return void 0;
503
- }
504
- let message = `${getPrefix(options.prefix, options.indentation, deep)}Errors:
505
-
506
- `;
507
- let first = true;
508
- for (const error_ of error.errors) {
509
- if (first) {
510
- first = false;
511
- } else {
512
- message += "\n\n";
513
- }
514
- message += internalRenderError(error_, { ...options, framesMaxLimit: 1, hideErrorCodeView: options.hideErrorErrorsCodeView }, deep + 1);
515
- }
516
- return `
517
- ${message}`;
518
- };
519
- const getCause = (error, options, deep) => {
520
- let message = `${getPrefix(options.prefix, options.indentation, deep)}Caused by:
521
-
522
- `;
523
- const cause = error.cause;
524
- message += getMessage(cause, options, deep);
525
- const stacktrace = parseStacktrace(cause);
526
- const mainFrame = stacktrace.shift();
527
- const hint = getHint(cause, options, deep);
528
- if (hint) {
529
- message += `${hint}
530
- `;
531
- }
532
- if (mainFrame) {
533
- message += getMainFrame(mainFrame, options, deep);
534
- if (!options.hideErrorCauseCodeView) {
535
- const code = getCode(mainFrame, options, deep);
536
- if (code !== void 0) {
537
- message += `
538
- ${code}`;
539
- }
540
- }
541
- }
542
- if (cause.cause) {
543
- message += `
544
- ${getCause(cause, options, deep + 1)}`;
545
- } else if (cause instanceof AggregateError) {
546
- const errors = getErrors(cause, options, deep);
547
- if (errors !== void 0) {
548
- message += `
549
- ${errors}`;
550
- }
551
- }
552
- return `
553
- ${message}`;
554
- };
555
- const getStacktrace = (stack, options) => (stack.length > 0 ? "\n" : "") + stack.map((frame) => getMainFrame(frame, options)).join("\n");
556
- const internalRenderError = (error, options, deep) => {
557
- const config = {
558
- cwd: cwd(),
559
- displayShortPath: false,
560
- filterStacktrace: void 0,
561
- framesMaxLimit: Number.POSITIVE_INFINITY,
562
- hideErrorCauseCodeView: false,
563
- hideErrorCodeView: false,
564
- hideErrorErrorsCodeView: false,
565
- hideErrorTitle: false,
566
- hideMessage: false,
567
- indentation: 4,
568
- linesAbove: 2,
569
- linesBelow: 3,
570
- prefix: "",
571
- showGutter: true,
572
- showLineNumbers: true,
573
- tabWidth: 4,
574
- ...options,
575
- color: {
576
- fileLine: (value) => value,
577
- gutter: (value) => value,
578
- hint: (value) => value,
579
- marker: (value) => value,
580
- message: (value) => value,
581
- method: (value) => value,
582
- title: (value) => value,
583
- ...options.color
584
- }
585
- };
586
- const stack = parseStacktrace(error, {
587
- filter: options.filterStacktrace,
588
- frameLimit: config.framesMaxLimit
589
- });
590
- const mainFrame = stack.shift();
591
- return [
592
- options.hideMessage ? void 0 : getMessage(error, config, deep),
593
- getHint(error, config, deep),
594
- mainFrame ? getMainFrame(mainFrame, config, deep) : void 0,
595
- mainFrame && !config.hideErrorCodeView ? getCode(mainFrame, config, deep) : void 0,
596
- error instanceof AggregateError ? getErrors(error, config, deep) : void 0,
597
- error.cause === void 0 ? void 0 : getCause(error, config, deep),
598
- stack.length > 0 ? getStacktrace(stack, config) : void 0
599
- ].filter(Boolean).join("\n").replaceAll("\\", "/");
600
- };
601
- const renderError = (error, options = {}) => {
602
- if (options.framesMaxLimit !== void 0 && options.framesMaxLimit <= 0) {
603
- throw new RangeError("The 'framesMaxLimit' option must be a positive number");
604
- }
605
- return internalRenderError(error, options, 0);
606
- };
607
-
608
- const TRUNCATOR = "…";
609
- const inspectList = (list, from, options, inspect2, inspectItem, separator = ", ") => {
610
- const size = list.length;
611
- if (size === 0) {
612
- return "";
613
- }
614
- let inspect_ = inspect2;
615
- if (inspectItem !== void 0) {
616
- inspect_ = inspectItem;
617
- }
618
- const originalLength = options.truncate;
619
- let output = "";
620
- let peek = "";
621
- let truncated = "";
622
- for (let index = 0; index < size; index += 1) {
623
- const last = index + 1 === list.length;
624
- const secondToLast = index + 2 === list.length;
625
- truncated = `${TRUNCATOR}(${list.length - index})`;
626
- let value = list[index];
627
- options.truncate = originalLength - output.length - (last ? 0 : separator.length);
628
- const string = peek || inspect_(value, from, options, inspect2) + (last ? "" : separator);
629
- const nextLength = output.length + string.length;
630
- const truncatedLength = nextLength + truncated.length;
631
- if (last && nextLength > originalLength && output.length + truncated.length <= originalLength) {
632
- break;
633
- }
634
- if (!last && !secondToLast && truncatedLength > originalLength) {
635
- break;
636
- }
637
- value = list[index + 1];
638
- peek = last ? "" : inspect_(value, from, options, inspect2) + (secondToLast ? "" : separator);
639
- if (!last && secondToLast && truncatedLength > originalLength && nextLength + peek.length > originalLength) {
640
- break;
641
- }
642
- output += string;
643
- if (!last && !secondToLast && nextLength + peek.length >= originalLength) {
644
- truncated = `${TRUNCATOR}(${list.length - index - 1})`;
645
- break;
646
- }
647
- truncated = "";
648
- }
649
- return `${output}${truncated}`;
650
- };
651
- const inspectAttribute = ([key, value], _, options) => {
652
- options.truncate -= 3;
653
- if (!value) {
654
- return options.stylize(String(key), "yellow");
655
- }
656
- return `${options.stylize(String(key), "yellow")}=${options.stylize(`"${value}"`, "string")}`;
657
- };
658
- const inspectNode = (node, inspect2, options) => {
659
- switch (node.nodeType) {
660
- case 1: {
661
- return inspectHTMLElement(node, node, options, inspect2);
662
- }
663
- case 3: {
664
- return inspect2(node.data, inspect2, options);
665
- }
666
- default: {
667
- return inspect2(node, inspect2, options);
668
- }
669
- }
670
- };
671
- const inspectNodeCollection = (collection, options, inspect2, _) => inspectList(collection, collection, options, inspect2, inspectNode, "\n");
672
- const inspectHTMLElement = (element, object, options, inspect2) => {
673
- const properties = element.getAttributeNames();
674
- const name = element.tagName.toLowerCase();
675
- const head = options.stylize(`<${name}`, "special");
676
- const headClose = options.stylize(`>`, "special");
677
- const tail = options.stylize(`</${name}>`, "special");
678
- options.truncate -= name.length * 2 + 5;
679
- let propertyContents = "";
680
- if (properties.length > 0) {
681
- propertyContents += " ";
682
- propertyContents += inspectList(
683
- properties.map((key) => [key, element.getAttribute(key)]),
684
- object,
685
- options,
686
- inspect2,
687
- inspectAttribute,
688
- " "
689
- );
690
- }
691
- options.truncate -= propertyContents.length;
692
- const { truncate: truncate2 } = options;
693
- let children = inspectNodeCollection(element.children, options, inspect2);
694
- if (children && children.length > truncate2) {
695
- children = `${TRUNCATOR}(${element.children.length})`;
696
- }
697
- return `${head}${propertyContents}${headClose}${children}${tail}`;
698
- };
699
- const inspectArguments = (arguments_, options, inspect2) => {
700
- if (arguments_.length === 0) {
701
- return "Arguments []";
702
- }
703
- options.truncate -= 13;
704
- return `Arguments [ ${inspectList(arguments_, arguments_, options, inspect2)} ]`;
705
- };
706
- const getIndent = (indent, depth) => {
707
- let baseIndent;
708
- if (indent === " ") {
709
- baseIndent = " ";
710
- } else if (typeof indent === "number" && indent > 0) {
711
- baseIndent = Array.from({ length: indent + 1 }).join(" ");
712
- } else {
713
- return void 0;
714
- }
715
- return {
716
- base: baseIndent,
717
- prev: `
718
- ${Array.from({ length: depth + 1 }).join(baseIndent)}`
719
- };
720
- };
721
- const indentedJoin = (values, indent) => {
722
- if (values.length === 0) {
723
- return "";
724
- }
725
- const lineJoiner = indent.prev + indent.base;
726
- return lineJoiner + values.split(", ").join(`,${lineJoiner}`) + indent.prev;
727
- };
728
- const quoteComplexKey = (key, options) => {
729
- if (/^[a-z_]\w*$/i.test(key)) {
730
- return key;
731
- }
732
- const stringifiedKey = JSON.stringify(key);
733
- if (options.quoteStyle === "double") {
734
- return stringifiedKey.replaceAll('"', String.raw`\"`);
735
- }
736
- return stringifiedKey.replaceAll("'", String.raw`\'`).replaceAll(String.raw`\"`, '"').replaceAll(/^"|"$/g, "'");
737
- };
738
- const inspectProperty = ([key, value], object, options, inspect2) => {
739
- options.truncate -= 2;
740
- if (typeof key === "string") {
741
- key = quoteComplexKey(key, options);
742
- } else if (typeof key !== "number") {
743
- key = `[${inspect2(key, object, options)}]`;
744
- }
745
- options.truncate -= key.length;
746
- value = inspect2(value, object, options);
747
- return `${key}: ${value}`;
748
- };
749
- const multiLineValues = (values) => {
750
- for (const value of values) {
751
- if (Array.isArray(value) || typeof value === "object" && value !== null) {
752
- return true;
753
- }
754
- }
755
- return false;
756
- };
757
- const inspectArray = (array, options, inspect2, indent) => {
758
- const nonIndexProperties = Object.keys(array).slice(array.length);
759
- if (array.length === 0 && nonIndexProperties.length === 0) {
760
- return "[]";
761
- }
762
- options.truncate -= 4;
763
- let listContents = inspectList(array, array, options, inspect2);
764
- options.truncate -= listContents.length;
765
- let propertyContents = "";
766
- if (nonIndexProperties.length > 0) {
767
- propertyContents = inspectList(
768
- nonIndexProperties.map((key) => [key, array[key]]),
769
- array,
770
- options,
771
- inspect2,
772
- inspectProperty
773
- );
774
- }
775
- const hasIndent = indent && multiLineValues(array);
776
- if (hasIndent) {
777
- listContents = indentedJoin(listContents, indent);
778
- }
779
- return `[${hasIndent ? "" : " "}${listContents}${propertyContents ? `, ${propertyContents}` : ""}${hasIndent ? "" : " "}]`;
780
- };
781
- const addNumericSeparator = (number_, string_) => {
782
- if (number_ === Number.POSITIVE_INFINITY || number_ === Number.NEGATIVE_INFINITY || string_.includes("e")) {
783
- return string_;
784
- }
785
- const separatorRegex = /\d(?=(?:\d{3})+(?!\d))/g;
786
- if (typeof number_ === "number") {
787
- const int = number_ < 0 ? -Math.floor(-number_) : Math.floor(number_);
788
- if (int !== number_) {
789
- const intString = String(int);
790
- const dec = string_.slice(intString.length + 1);
791
- return (
792
- // eslint-disable-next-line unicorn/prefer-string-replace-all
793
- `${intString.replace(separatorRegex, "$&_")}.${dec.replace(/\d{3}/g, "$&_").replace(/_$/, "")}`
794
- );
795
- }
796
- }
797
- return string_.replace(separatorRegex, "$&_");
798
- };
799
- const isHighSurrogate = (char) => char >= "\uD800" && char <= "\uDBFF";
800
- const truncate = (string, length, tail = TRUNCATOR) => {
801
- string = String(string);
802
- const tailLength = tail.length;
803
- const stringLength = string.length;
804
- if (tailLength > length && stringLength > tailLength) {
805
- return tail;
806
- }
807
- if (stringLength > length && stringLength > tailLength) {
808
- let end = length - tailLength;
809
- if (end > 0 && isHighSurrogate(string[end - 1])) {
810
- end -= 1;
811
- }
812
- return `${string.slice(0, end)}${tail}`;
813
- }
814
- return string;
815
- };
816
- const inspectBigInt = (number, options) => {
817
- let nums = truncate(number.toString(), options.truncate - 1);
818
- if (nums !== TRUNCATOR) {
819
- nums += "n";
820
- }
821
- return options.stylize(options.numericSeparator ? addNumericSeparator(number, nums) : nums, "bigint");
822
- };
823
- const gPO = (typeof Reflect === "function" ? Reflect.getPrototypeOf : Object.getPrototypeOf) || ([].__proto__ === Array.prototype ? function(O) {
824
- return O.__proto__;
825
- } : null);
826
- const inspectObject$1 = (object, options, inspect2, indent) => {
827
- if (globalThis.window !== void 0 && object === globalThis) {
828
- return "{ [object Window] }";
829
- }
830
- if (typeof globalThis !== "undefined" && object === globalThis || globalThis.global !== void 0 && object === globalThis) {
831
- return "{ [object globalThis] }";
832
- }
833
- const properties = Object.getOwnPropertyNames(object);
834
- const symbols = Object.getOwnPropertySymbols ? Object.getOwnPropertySymbols(object) : [];
835
- const isPlainObject = gPO(object) === Object.prototype || object.constructor === Object;
836
- const protoTag = object instanceof Object ? "" : "null prototype";
837
- const stringTag = !isPlainObject && typeof Symbol !== "undefined" && Symbol.toStringTag in object ? object[Symbol.toStringTag] : protoTag ? "Object" : "";
838
- const tag = stringTag || protoTag ? `[${[stringTag, protoTag].filter(Boolean).join(": ")}] ` : "";
839
- if (properties.length === 0 && symbols.length === 0) {
840
- return `${tag}{}`;
841
- }
842
- options.truncate -= 4;
843
- const propertyContents = inspectList(
844
- properties.map((key) => [key, object[key]]),
845
- object,
846
- options,
847
- inspect2,
848
- inspectProperty
849
- );
850
- const symbolContents = inspectList(
851
- symbols.map((key) => [key, object[key]]),
852
- object,
853
- options,
854
- inspect2,
855
- inspectProperty
856
- );
857
- let separator = "";
858
- if (propertyContents && symbolContents) {
859
- separator = ", ";
860
- }
861
- if (indent) {
862
- return `${tag}{${indentedJoin(propertyContents + separator + symbolContents, indent)}}`;
863
- }
864
- return `${tag}{ ${propertyContents}${separator}${symbolContents} }`;
865
- };
866
- const inspectClass = (value, options, inspect2, indent) => {
867
- let name = "";
868
- name = name || value.constructor.name;
869
- if (!name || name === "_class") {
870
- name = "<Anonymous Class>";
871
- }
872
- options.truncate -= name.length;
873
- return `${name} ${inspectObject$1(value, options, inspect2, indent)}`;
874
- };
875
- const inspectDate = (dateObject, options) => {
876
- const stringRepresentation = dateObject.toJSON();
877
- if (stringRepresentation === null) {
878
- return "Invalid Date";
879
- }
880
- const split = stringRepresentation.split("T");
881
- const date = split[0];
882
- return options.stylize(`${date}T${truncate(split[1], options.truncate - date.length - 1)}`, "date");
883
- };
884
- const errorKeys = /* @__PURE__ */ new Set(["column", "columnNumber", "description", "fileName", "line", "lineNumber", "message", "name", "number", "stack"]);
885
- const inspectObject = (error, options, inspect2) => {
886
- const properties = Object.getOwnPropertyNames(error).filter((key) => !errorKeys.has(key));
887
- const { name } = error;
888
- options.truncate -= name.length;
889
- let message = "";
890
- if (typeof error.message === "string") {
891
- message = truncate(error.message, options.truncate);
892
- } else {
893
- properties.unshift("message");
894
- }
895
- message = message ? `: ${message}` : "";
896
- options.truncate -= message.length + 5;
897
- const propertyContents = inspectList(
898
- properties.map((key) => [key, error[key]]),
899
- error,
900
- options,
901
- inspect2,
902
- inspectProperty
903
- );
904
- return `${name}${message}${propertyContents ? ` { ${propertyContents} }` : ""}`;
905
- };
906
- const inspectFunction = (function_, options) => {
907
- const functionType = function_[Symbol.toStringTag] || "Function";
908
- const source = function_.toString();
909
- if (source.length < options.truncate - 12) {
910
- return options.stylize(`[${functionType}: ${source}]`, "special");
911
- }
912
- const { name } = function_;
913
- if (!name) {
914
- return options.stylize(`[${functionType}]`, "special");
915
- }
916
- return options.stylize(`[${functionType} ${truncate(name, options.truncate - 11)}]`, "special");
917
- };
918
- const inspectMapEntry = ([key, value], object, options, inspect2) => {
919
- options.truncate -= 4;
920
- key = inspect2(key, object, options);
921
- options.truncate -= key.length;
922
- return `${key} => ${inspect2(value, object, options)}`;
923
- };
924
- const inspectMap = (map, options, inspect2, indent) => {
925
- if (map.size <= 0) {
926
- return "Map (0) {}";
927
- }
928
- options.truncate -= 7;
929
- let returnValue = inspectList([...map.entries()], map, options, inspect2, inspectMapEntry);
930
- if (indent) {
931
- returnValue = indentedJoin(returnValue, indent);
932
- }
933
- return `Map (${map.size}) {${indent ? "" : " "}${returnValue}${indent ? "" : " "}}`;
934
- };
935
- function inspectNumber(number, options) {
936
- if (Number.isNaN(number)) {
937
- return options.stylize("NaN", "number");
938
- }
939
- if (number === Number.POSITIVE_INFINITY) {
940
- return options.stylize("Infinity", "number");
941
- }
942
- if (number === Number.NEGATIVE_INFINITY) {
943
- return options.stylize("-Infinity", "number");
944
- }
945
- if (number === 0) {
946
- return options.stylize(1 / number === Number.POSITIVE_INFINITY ? "+0" : "-0", "number");
947
- }
948
- return options.stylize(truncate(options.numericSeparator ? addNumericSeparator(number, number.toString()) : number.toString(), options.truncate), "number");
949
- }
950
- const getPromiseValue = () => "Promise{…}";
951
- const inspectRegExp = (regExp, options) => {
952
- const sourceLength = options.truncate - (2 + regExp.flags.length);
953
- return options.stylize(`/${truncate(regExp.source, sourceLength)}/${regExp.flags}`, "regexp");
954
- };
955
- const inspectSet = (set, options, inspect2, indent) => {
956
- if (set.size === 0) {
957
- return "Set (0) {}";
958
- }
959
- options.truncate -= 7;
960
- let returnValue = inspectList([...set], set, options, inspect2);
961
- if (indent) {
962
- returnValue = indentedJoin(returnValue, indent);
963
- }
964
- return `Set (${set.size}) {${indent ? "" : " "}${returnValue}${indent ? "" : " "}}`;
965
- };
966
- const wrapQuotes = (string_, options) => {
967
- const quoteChar = options.quoteStyle === "double" ? '"' : "'";
968
- if (options.quoteStyle === "double") {
969
- string_ = string_.replaceAll('"', '"');
970
- }
971
- return quoteChar + string_ + quoteChar;
972
- };
973
- const stringEscapeChars = new RegExp(
974
- String.raw`['\0-\u001f\u007f-\u009f\u00ad\u0600-\u0604\u070f\u17b4\u17b5` + String.raw`\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]`,
975
- "g"
976
- );
977
- const escapeCharacters = {
978
- " ": String.raw`\t`,
979
- "\n": String.raw`\n`,
980
- "\f": String.raw`\f`,
981
- "\r": String.raw`\r`,
982
- "\b": String.raw`\b`,
983
- "'": String.raw`\'`,
984
- "\\": "\\\\"
985
- };
986
- const hex = 16;
987
- const escape = (char) => escapeCharacters[char] || String.raw`\u${`0000${char.codePointAt(0).toString(hex)}`.slice(-4)}`;
988
- const inspectString = (string_, options) => {
989
- if (stringEscapeChars.test(string_)) {
990
- string_ = string_.replaceAll(stringEscapeChars, escape);
991
- }
992
- return options.stylize(wrapQuotes(truncate(string_, options.truncate - 2), options), "string");
993
- };
994
- const inspectSymbol = (value) => {
995
- if ("description" in Symbol.prototype) {
996
- return value.description ? `Symbol(${value.description})` : "Symbol()";
997
- }
998
- return value.toString();
999
- };
1000
- const getArrayName = (array) => {
1001
- if (typeof Buffer === "function" && array instanceof Buffer) {
1002
- return "Buffer";
1003
- }
1004
- if (array[Symbol.toStringTag]) {
1005
- return array[Symbol.toStringTag];
1006
- }
1007
- return array.constructor.name;
1008
- };
1009
- const inspectTypedArray = (array, options, inspect2) => {
1010
- const name = getArrayName(array);
1011
- options.truncate -= name.length + 4;
1012
- const nonIndexProperties = Object.keys(array).slice(array.length);
1013
- if (array.length === 0 && nonIndexProperties.length === 0) {
1014
- return `${name}[]`;
1015
- }
1016
- let output = "";
1017
- for (let index = 0; index < array.length; index++) {
1018
- const string = `${options.stylize(truncate(array[index], options.truncate), "number")}${index === array.length - 1 ? "" : ", "}`;
1019
- options.truncate -= string.length;
1020
- if (array[index] !== array.length && options.truncate <= 3) {
1021
- output += `${TRUNCATOR}(${array.length - array[index] + 1})`;
1022
- break;
1023
- }
1024
- output += string;
1025
- }
1026
- let propertyContents = "";
1027
- if (nonIndexProperties.length > 0) {
1028
- propertyContents = inspectList(
1029
- nonIndexProperties.map((key) => [key, array[key]]),
1030
- array,
1031
- options,
1032
- inspect2,
1033
- inspectProperty
1034
- );
1035
- }
1036
- return `${name}[ ${output}${propertyContents ? `, ${propertyContents}` : ""} ]`;
1037
- };
1038
- const constructorMap = /* @__PURE__ */ new WeakMap();
1039
- const stringTagMap = {};
1040
- const baseTypesMap = {
1041
- Arguments: inspectArguments,
1042
- Array: inspectArray,
1043
- ArrayBuffer: () => "",
1044
- BigInt: inspectBigInt,
1045
- bigint: inspectBigInt,
1046
- Boolean: (value, options) => options.stylize(String(value), "boolean"),
1047
- boolean: (value, options) => options.stylize(String(value), "boolean"),
1048
- DataView: () => "",
1049
- Date: inspectDate,
1050
- Error: inspectObject,
1051
- Float32Array: inspectTypedArray,
1052
- Float64Array: inspectTypedArray,
1053
- Function: inspectFunction,
1054
- function: inspectFunction,
1055
- Generator: () => "",
1056
- HTMLCollection: inspectNodeCollection,
1057
- Int8Array: inspectTypedArray,
1058
- Int16Array: inspectTypedArray,
1059
- Int32Array: inspectTypedArray,
1060
- Map: inspectMap,
1061
- NodeList: inspectNodeCollection,
1062
- null: (_value, options) => options.stylize("null", "null"),
1063
- Number: inspectNumber,
1064
- number: inspectNumber,
1065
- Promise: getPromiseValue,
1066
- RegExp: inspectRegExp,
1067
- Set: inspectSet,
1068
- String: inspectString,
1069
- string: inspectString,
1070
- // A Symbol polyfill will return `Symbol` not `symbol` from typedetect
1071
- Symbol: inspectSymbol,
1072
- symbol: inspectSymbol,
1073
- Uint8Array: inspectTypedArray,
1074
- Uint8ClampedArray: inspectTypedArray,
1075
- Uint16Array: inspectTypedArray,
1076
- Uint32Array: inspectTypedArray,
1077
- undefined: (_value, options) => options.stylize("undefined", "undefined"),
1078
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1079
- WeakMap: (_value, options) => options.stylize("WeakMap{…}", "special"),
1080
- // WeakSet, WeakMap are totally opaque to us
1081
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1082
- WeakSet: (_value, options) => options.stylize("WeakSet{…}", "special")
1083
- };
1084
- const inspectCustom = (value, options, type, depth) => {
1085
- if (globalThis.window === void 0 && typeof value[/* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom")] === "function") {
1086
- return value[/* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom")](depth, options);
1087
- }
1088
- if ("inspect" in value && typeof value.inspect === "function") {
1089
- return value.inspect(depth, options);
1090
- }
1091
- if ("constructor" in value && constructorMap.has(value.constructor)) {
1092
- return constructorMap.get(value.constructor)?.(value, options) ?? "unknown";
1093
- }
1094
- if (stringTagMap[type]) {
1095
- return stringTagMap[type](value, options);
1096
- }
1097
- return "";
1098
- };
1099
- const internalInspect = (value, options, depth, seen) => {
1100
- if (seen.includes(value)) {
1101
- return "[Circular]";
1102
- }
1103
- if (depth >= options.depth && options.depth > 0 && typeof value === "object") {
1104
- return Array.isArray(value) ? "[Array]" : "[Object]";
1105
- }
1106
- const inspect2 = (object, from, options2) => {
1107
- if (from) {
1108
- seen = [...seen, from];
1109
- }
1110
- return internalInspect(object, options2, depth + 1, seen);
1111
- };
1112
- const indent = options.indent ? getIndent(options.indent, depth) : void 0;
1113
- let type = value === null ? "null" : typeof value;
1114
- if (type === "object") {
1115
- type = Object.prototype.toString.call(value).slice(8, -1);
1116
- }
1117
- if (baseTypesMap[type] !== void 0) {
1118
- return baseTypesMap[type](value, options, inspect2, indent);
1119
- }
1120
- if (options.customInspect && value) {
1121
- const output = inspectCustom(value, options, type, options.depth - depth);
1122
- if (output) {
1123
- if (typeof output === "string") {
1124
- return output;
1125
- }
1126
- return inspect2(output, value, options);
1127
- }
1128
- }
1129
- const proto = value ? Object.getPrototypeOf(value) : false;
1130
- if (proto === Object.prototype || proto === null) {
1131
- return inspectObject$1(value, options, inspect2, indent);
1132
- }
1133
- if (value && typeof HTMLElement === "function" && value instanceof HTMLElement) {
1134
- return inspectHTMLElement(value, value, options, inspect2);
1135
- }
1136
- if ("constructor" in value) {
1137
- if (value.constructor !== Object) {
1138
- return inspectClass(value, options, inspect2, indent);
1139
- }
1140
- return inspectObject$1(value, options, inspect2, indent);
1141
- }
1142
- if (value === Object(value)) {
1143
- return inspectObject$1(value, options, inspect2, indent);
1144
- }
1145
- return options.stylize(String(value), type);
1146
- };
1147
- const inspect = (value, options_ = {}) => {
1148
- const options = {
1149
- breakLength: Number.POSITIVE_INFINITY,
1150
- customInspect: true,
1151
- depth: 5,
1152
- indent: void 0,
1153
- maxArrayLength: Number.POSITIVE_INFINITY,
1154
- numericSeparator: true,
1155
- quoteStyle: "single",
1156
- showHidden: false,
1157
- showProxy: false,
1158
- stylize: (s) => s.toString(),
1159
- truncate: Number.POSITIVE_INFINITY,
1160
- ...options_
1161
- };
1162
- if (options.indent !== void 0 && options.indent !== " " && !(Number.parseInt(options.indent, 10) === options.indent && options.indent > 0)) {
1163
- throw new TypeError('option "indent" must be "\\t", an integer > 0, or `undefined`');
1164
- }
1165
- return internalInspect(value, options, 0, []);
1166
- };
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
-
1184
- const defaultInspectorConfig = {
1185
- indent: 2,
1186
- quoteStyle: "single",
1187
- stylize: (string_, style) => {
1188
- const styles = {
1189
- bigint: yellow,
1190
- boolean: yellow,
1191
- date: magenta,
1192
- null: bold,
1193
- number: yellow,
1194
- regexp: red,
1195
- special: cyan,
1196
- string: green,
1197
- symbol: green,
1198
- undefined: grey
1199
- };
1200
- if (styles[style] === void 0) {
1201
- return string_;
1202
- }
1203
- return styles[style](string_);
1204
- }
1205
- };
1206
-
1207
- const formatLabel = (label, styles) => {
1208
- let formattedLabel = styles.uppercase.label ? label.toUpperCase() : label;
1209
- formattedLabel = styles.underline.label ? underline(formattedLabel) : formattedLabel;
1210
- if (styles.bold.label) {
1211
- formattedLabel = bold(formattedLabel);
1212
- }
1213
- return formattedLabel;
1214
- };
1215
-
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 PAIL_DIST_REGEX = /[\\/]pail[\\/]dist/;
1256
- const pailFileFilter = (line) => !PAIL_DIST_REGEX.test(line);
1257
- class PrettyReporter extends AbstractPrettyReporter {
1258
- #stdout;
1259
- #stderr;
1260
- #interactiveManager;
1261
- #interactive = false;
1262
- #inspectOptions;
1263
- #errorOptions;
1264
- /**
1265
- * Creates a new Server Pretty Reporter instance.
1266
- * @param options Configuration options for styling, error rendering, and object inspection
1267
- */
1268
- constructor(options = {}) {
1269
- const { error: errorOptions, inspect: inspectOptions, ...rest } = options;
1270
- super({
1271
- uppercase: {
1272
- label: true,
1273
- ...rest.uppercase
1274
- },
1275
- ...rest
1276
- });
1277
- this.#inspectOptions = { ...defaultInspectorConfig, ...inspectOptions };
1278
- this.#errorOptions = {
1279
- ...errorOptions,
1280
- color: {
1281
- fileLine: green,
1282
- hint: cyan,
1283
- marker: red,
1284
- message: red,
1285
- method: greenBright,
1286
- title: red
1287
- }
1288
- };
1289
- this.#stdout = stdout;
1290
- this.#stderr = stderr;
1291
- }
1292
- /**
1293
- * Sets the stdout stream for the reporter.
1294
- * @param stdout_ The writable stream to use for standard output
1295
- */
1296
- setStdout(stdout_) {
1297
- this.#stdout = stdout_;
1298
- }
1299
- /**
1300
- * Sets the stderr stream for the reporter.
1301
- * @param stderr_ The writable stream to use for error output
1302
- */
1303
- setStderr(stderr_) {
1304
- this.#stderr = stderr_;
1305
- }
1306
- /**
1307
- * Sets the interactive manager for handling interactive output.
1308
- * @param manager The interactive manager instance, or undefined to disable
1309
- */
1310
- setInteractiveManager(manager) {
1311
- this.#interactiveManager = manager;
1312
- }
1313
- /**
1314
- * Enables or disables interactive mode.
1315
- * @param interactive Whether to enable interactive terminal features
1316
- */
1317
- setIsInteractive(interactive) {
1318
- this.#interactive = interactive;
1319
- }
1320
- log(meta) {
1321
- this._log(this._formatMessage(meta), meta.type.level);
1322
- }
1323
- // eslint-disable-next-line sonarjs/cognitive-complexity, no-underscore-dangle
1324
- _formatMessage(data) {
1325
- const { columns } = terminalSize();
1326
- let size = columns;
1327
- if (typeof this.styles.messageLength === "number") {
1328
- size = this.styles.messageLength;
1329
- }
1330
- const { badge, context, date, error, file, groups, label, message, prefix, repeated, scope, suffix, traceError, type } = data;
1331
- const { color } = this.loggerTypes[type.name];
1332
- const colorized = color ? colorize[color] : white;
1333
- const groupSpaces = groups.map(() => " ").join("");
1334
- const items = [];
1335
- if (groups.length > 0) {
1336
- items.push(`${groupSpaces + grey(`[${groups.at(-1)}]`)} `);
1337
- }
1338
- if (date) {
1339
- items.push(`${grey(this.styles.dateFormatter(typeof date === "string" ? new Date(date) : date))} `);
1340
- }
1341
- if (badge) {
1342
- items.push(colorized(badge));
1343
- } else {
1344
- const longestBadge = getLongestBadge(this.loggerTypes);
1345
- if (longestBadge.length > 0) {
1346
- items.push(`${grey(".".repeat(longestBadge.length))} `);
1347
- }
1348
- }
1349
- const longestLabel = getLongestLabel(this.loggerTypes);
1350
- if (label) {
1351
- const longestLabelWidth = getStringWidth(longestLabel);
1352
- const labelWidth = getStringWidth(label);
1353
- items.push(`${colorized(formatLabel(label, this.styles))} `, grey(".".repeat(Math.max(0, longestLabelWidth - labelWidth))));
1354
- } else {
1355
- items.push(grey(".".repeat(longestLabel.length + 2)));
1356
- }
1357
- if (repeated) {
1358
- items.push(`${bgGrey.white(`[${repeated}x]`)} `);
1359
- }
1360
- if (Array.isArray(scope) && scope.length > 0) {
1361
- items.push(` ${grey(`[${scope.join(" > ")}]`)} `);
1362
- }
1363
- if (prefix) {
1364
- items.push(
1365
- `${grey(`${Array.isArray(scope) && scope.length > 0 ? ". " : " "}[${this.styles.underline.prefix ? underline(prefix) : prefix}]`)} `
1366
- );
1367
- }
1368
- const titleSize = getStringWidth(items.join(" "));
1369
- if (file) {
1370
- const fileMessage = file.name + (file.line ? `:${file.line}` : "");
1371
- const fileMessageSize = getStringWidth(fileMessage);
1372
- if (fileMessageSize + titleSize + 2 > size) {
1373
- items.push(grey(` ${fileMessage}`));
1374
- } else {
1375
- const dots = Math.max(0, size - titleSize - fileMessageSize - 2);
1376
- items.push(grey(`${".".repeat(dots)} ${fileMessage}`));
1377
- }
1378
- } else {
1379
- items.push(grey(".".repeat(Math.max(0, size - titleSize - 1))));
1380
- }
1381
- if (items.length > 0) {
1382
- items.push("\n\n");
1383
- }
1384
- if (message !== EMPTY_SYMBOL) {
1385
- const formattedMessage = typeof message === "string" ? message : inspect(message, this.#inspectOptions);
1386
- items.push(
1387
- groupSpaces + wordWrap(formattedMessage, {
1388
- trim: false,
1389
- width: size - 3,
1390
- wrapMode: WrapMode.STRICT_WIDTH
1391
- })
1392
- );
1393
- }
1394
- if (context) {
1395
- let hasError = false;
1396
- items.push(
1397
- ...context.map((value) => {
1398
- if (value instanceof Error) {
1399
- hasError = true;
1400
- return `
1401
-
1402
- ${renderError(value, {
1403
- ...this.#errorOptions,
1404
- filterStacktrace: pailFileFilter,
1405
- prefix: groupSpaces
1406
- })}`;
1407
- }
1408
- if (typeof value === "object") {
1409
- return ` ${inspect(value, this.#inspectOptions)}`;
1410
- }
1411
- const newValue = (hasError ? "\n\n" : " ") + value;
1412
- hasError = false;
1413
- return newValue;
1414
- })
1415
- );
1416
- }
1417
- if (error) {
1418
- items.push(
1419
- renderError(error, {
1420
- ...this.#errorOptions,
1421
- filterStacktrace: pailFileFilter,
1422
- prefix: groupSpaces
1423
- })
1424
- );
1425
- }
1426
- if (traceError) {
1427
- items.push(
1428
- `
1429
-
1430
- ${renderError(traceError, {
1431
- ...this.#errorOptions,
1432
- filterStacktrace: pailFileFilter,
1433
- hideErrorCauseCodeView: true,
1434
- hideErrorCodeView: true,
1435
- hideErrorErrorsCodeView: true,
1436
- hideMessage: true,
1437
- prefix: groupSpaces
1438
- })}`
1439
- );
1440
- }
1441
- if (suffix) {
1442
- items.push("\n", groupSpaces + grey(this.styles.underline.suffix ? underline(suffix) : suffix));
1443
- }
1444
- return items.join("");
1445
- }
1446
- // eslint-disable-next-line no-underscore-dangle
1447
- _log(message, logLevel) {
1448
- const streamType = ["error", "trace", "warn"].includes(logLevel) ? "stderr" : "stdout";
1449
- const stream = streamType === "stderr" ? this.#stderr : this.#stdout;
1450
- if (this.#interactive && this.#interactiveManager !== void 0 && stream.isTTY) {
1451
- this.#interactiveManager.update(streamType, message.split("\n"), 0);
1452
- } else {
1453
- writeStream(`${message}
1454
- `, stream);
1455
- }
1456
- }
1457
- }
1458
-
1459
- export { PrettyReporter };