UNPKG

redis-smq-common

Version:

Provides essential components and utilities shared across RedisSMQ packages.

35 lines 1.25 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getCurrentDir = getCurrentDir; const path_1 = require("path"); function isStackTraces(stack) { return Array.isArray(stack); } 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 (0, path_1.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