@visulima/pail 4.0.0-alpha.1 → 4.0.0-alpha.11

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