* Capture the file that invoked bench.add() so we can build a stable URI * for CodSpeed to identify the benchmark. * @returns {string} calling file path relative to the repo root
()
| 40 | * @returns {string} calling file path relative to the repo root |
| 41 | */ |
| 42 | function getCallingFile() { |
| 43 | const dummy = {}; |
| 44 | const prev = Error.prepareStackTrace; |
| 45 | const prevLimit = Error.stackTraceLimit; |
| 46 | Error.stackTraceLimit = 10; |
| 47 | Error.prepareStackTrace = (_err, trace) => trace; |
| 48 | Error.captureStackTrace(dummy, getCallingFile); |
| 49 | const trace = /** @type {NodeJS.CallSite[]} */ ( |
| 50 | /** @type {{ stack: unknown }} */ (dummy).stack |
| 51 | ); |
| 52 | Error.prepareStackTrace = prev; |
| 53 | Error.stackTraceLimit = prevLimit; |
| 54 | |
| 55 | let file = /** @type {string} */ (trace[1].getFileName() || ""); |
| 56 | if (file.startsWith("file://")) file = fileURLToPath(file); |
| 57 | if (!file) return "<unknown>"; |
| 58 | return path.relative(repoRoot, file); |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * @typedef {{ uri: string, fn: Fn, opts: object | undefined }} TaskMeta |
no outgoing calls
no test coverage detected
searching dependent graphs…