| 41 | .join('\n'); |
| 42 | } |
| 43 | |
| 44 | function formatStackTrace(s: string): string { |
| 45 | const curDir = __dirname; |
| 46 | const parentDir = curDir.match(/(.*)\/([^\/]*)$/)?.[1]; |
| 47 | if (!parentDir || !curDir) return s; |
| 48 | s = s |
| 49 | .replace(new RegExp(parentDir, 'g'), '..') |
| 50 | .replace(new RegExp(curDir, 'g'), '.'); |
| 51 | |
| 52 | const lines = s.split('\n').map((line) => { |
| 53 | if (/\.\.\/node_modules/.test(line)) return ''; |
| 54 | if (/\(node:internal/.test(line)) return ''; |
| 55 | |
| 56 | line = line.replace(' at ', ' > '); |
| 57 | |
| 58 | const [_, prefix, filename, suffix] = |
| 59 | line.match(/(?:(.+)\()([^:]+)(\:[^)]+)/) ?? []; |
| 60 | if (!prefix) return line; |
| 61 | if (/Object.<anonymous>/.test(prefix) || prefix.startsWith(' > console.')) |
| 62 | return GREY + ' > ' + CYAN + filename + GREY + suffix; |
| 63 | return GREY + prefix + CYAN + filename + GREY + suffix; |
| 64 | }); |
| 65 | lines[0] = ''; |
| 66 | lines[1] = ''; |
| 67 | return RESET + lines.filter((line) => line.length > 0).join('\n') + RESET; |
| 68 | } |
| 69 | |
| 70 | /** |