MCPcopy
hub / github.com/webpack/tapable / getCallingFile

Function getCallingFile

benchmark/with-codspeed.mjs:42–59  ·  view source on GitHub ↗

* 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

()

Source from the content-addressed store, hash-verified

40 * @returns {string} calling file path relative to the repo root
41 */
42function 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

Callers 1

withCodSpeedFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…