UNPKG

@opengis/fastify-table

Version:

core-plugins

26 lines (18 loc) 593 B
import path from 'node:path'; export default function getCallerDir() { const originalFunc = Error.prepareStackTrace; let callerfile; try { const err = new Error(); // let currentfile; Error.prepareStackTrace = function (err, stack) { return stack; }; const currentfile = err.stack.shift().getFileName(); while (err.stack.length) { callerfile = err.stack.shift().getFileName(); if (currentfile !== callerfile) break; } } catch (err) { } Error.prepareStackTrace = originalFunc; return path.dirname(callerfile); }