UNPKG

redis-smq-common

Version:

RedisSMQ Common Library provides many components that are mainly used by RedisSMQ and RedisSMQ Monitor.

32 lines 1.13 kB
import { dirname } from 'path'; function isStackTraces(stack) { return Array.isArray(stack); } export function getCurrentDir() { const originalPrepareStackTrace = Error.prepareStackTrace; try { Error.prepareStackTrace = (_, stackTraces) => stackTraces; const err = new Error(); const stack = err.stack; if (!isStackTraces(stack) || stack.length < 2) { throw new Error('Invalid stack trace'); } const callSite = stack[1]; const filename = callSite.getFileName(); if (!filename) { throw new Error('Unable to determine filename from stack trace'); } const cleanFilename = filename.startsWith('file://') ? filename.slice(7) : filename; return dirname(cleanFilename); } catch (error) { const errorMessage = error instanceof Error ? error.message : String(error); throw new Error(`Failed to get current directory: ${errorMessage}`); } finally { Error.prepareStackTrace = originalPrepareStackTrace; } } //# sourceMappingURL=current-dir.js.map