{"version":3,"file":"index.d.ts","sources":["../src/types/Options.ts","../src/main.ts","../src/libs/getCallerDir.ts","../src/libs/getCallerFile.ts","../src/libs/getCallerSite.ts","../src/utils/extractFilePath.ts"],"sourcesContent":["/**\n * {@link https://github.com/mnrendra/stack-trace#stacktrace `stackTrace`}'s\n * {@link https://github.com/mnrendra/stack-trace#options options} interface.\n *\n * @see {@link https://github.com/mnrendra/stack-trace#options-1 documentation}\n */\ninterface Options {\n  /**\n   * Specifies the number of stack frames to be collected by a stack trace.\n   *\n   * The default value is `Infinity`, but may be set to any valid JavaScript\n   * number. Changes will affect any stack trace captured after the value has\n   * been changed.\n   *\n   * If set to a non-number value, or set to a negative number, stack traces\n   * will not capture any frames.\n   *\n   * @default Infinity\n   *\n   * @see https://nodejs.org/api/errors.html#errorstacktracelimit\n   */\n  limit?: number\n}\n\nexport default Options\n","import type { Options } from './types'\n\nimport { createTarget } from './helpers'\n\n/**\n * Captures {@link https://v8.dev/docs/stack-trace-api v8 stack trace} from a\n * specific caller.\n *\n * @param {((...args:any)=>any)|null} [callee] - Optional callee function to\n * specify the caller. If `undefined` or `null`, tracing starts from the current\n * caller.\n *\n * @param {Options} [options] - Optional options to affect the captured\n * frames.\n *\n * By default, the `limit` option is set to `Infinity` to capture all frames.\n * To capture only a specific number of frames, set the `limit` option to a\n * positive number.\n *\n * @returns {NodeJS.CallSite[]} Array of `CallSite` objects representing the\n * captured stack trace frames.\n *\n * @see {@link https://github.com/mnrendra/stack-trace#stacktrace documentation}\n */\nconst main = (\n  callee?: ((...args: any) => any) | null,\n  {\n    limit = Infinity\n  }: Options = {}\n): NodeJS.CallSite[] => {\n  const { stackTraceLimit, prepareStackTrace } = Error\n\n  Error.stackTraceLimit = limit\n  Error.prepareStackTrace = (_, stack) => stack\n\n  const target = createTarget()\n  Error.captureStackTrace(target, callee ?? main)\n  const { stack } = target\n\n  Error.prepareStackTrace = prepareStackTrace\n  Error.stackTraceLimit = stackTraceLimit\n\n  return stack\n}\n\nexport default main\n","import { dirname } from 'node:path'\n\nimport getCallerFile from './getCallerFile'\n\n/**\n * Gets the caller's directory extracted from the result of\n * {@link https://github.com/mnrendra/stack-trace#getcallerfile `getCallerFile`}.\n *\n * @param {((...args:any)=>any)|null} [callee] - Optional callee function to\n * specify the caller. If `undefined` or `null`, tracing starts from the current\n * caller.\n *\n * @returns {string} Absolute path of the caller's\n * directory.\n *\n * @throws If the extracted file name is not a string or not\n * absolute.\n *\n * @see {@link https://github.com/mnrendra/stack-trace#getcallerdir documentation}\n */\nconst getCallerDir = (\n  callee?: ((...args: any) => any) | null\n): string => {\n  const callerFile = getCallerFile(callee ?? getCallerDir)\n\n  return dirname(callerFile)\n}\n\nexport default getCallerDir\n","import getCallerSite from './getCallerSite'\n\nimport { extractFilePath } from '../utils'\n\n/**\n * Gets the caller's file extracted from the result of\n * {@link https://github.com/mnrendra/stack-trace#getcallersite `getCallerSite`}\n * and ensures it returns an absolute path using\n * {@link https://github.com/mnrendra/stack-trace#extractfilepath `extractFilePath`}.\n *\n * @param {((...args:any)=>any)|null} [callee] - Optional callee function to\n * specify the caller. If `undefined` or `null`, tracing starts from the current\n * caller.\n *\n * @returns {string} Absolute path of the caller's\n * file.\n *\n * @throws If the extracted file name is not a string or not\n * absolute.\n *\n * @see {@link https://github.com/mnrendra/stack-trace#getcallerfile documentation}\n */\nconst getCallerFile = (\n  callee?: ((...args: any) => any) | null\n): string => {\n  const callerSite = getCallerSite(callee ?? getCallerFile)\n\n  return extractFilePath(callerSite)\n}\n\nexport default getCallerFile\n","import main from '../main'\n\n/**\n * Gets the caller's `CallSite` object captured from\n * {@link https://github.com/mnrendra/stack-trace#stacktrace `stackTrace`}.\n *\n * @param {((...args:any)=>any)|null} [callee] - Optional callee function to\n * specify the caller. If `undefined` or `null`, tracing starts from the current\n * caller.\n *\n * @returns {NodeJS.CallSite} First `CallSite` object captured in the stack\n * trace.\n *\n * @see {@link https://github.com/mnrendra/stack-trace#getcallersite documentation}\n */\nconst getCallerSite = (\n  callee?: ((...args: any) => any) | null\n): NodeJS.CallSite => {\n  const [callSite] = main(callee ?? getCallerSite, { limit: 1 })\n\n  return callSite\n}\n\nexport default getCallerSite\n","import { isAbsolute } from 'node:path'\n\nimport { normalizePath } from '../helpers'\n\n/**\n * Extracts the file name from a `CallSite` object and converts it to a file\n * path if the value is a file URL.\n *\n * This utility ensures that the returned value is an absolute path.\n *\n * @param {NodeJS.CallSite} callSite - `CallSite` object captured from\n * {@link https://github.com/mnrendra/stack-trace#stacktrace `stackTrace`}.\n *\n * @returns {string} Absolute path of the file name extracted from a `CallSite`\n * object.\n *\n * @throws If the extracted file name is not a string or not\n * absolute.\n *\n * @see {@link https://github.com/mnrendra/stack-trace#extractfilepath documentation}\n */\nconst extractFilePath = (\n  callSite: NodeJS.CallSite\n): string => {\n  const fileName = callSite.getFileName()\n\n  const filePath = normalizePath(fileName)\n\n  if (!isAbsolute(filePath)) {\n    throw new Error(`Caller's file path is not absolute: \"${filePath}\"`)\n  }\n\n  return filePath\n}\n\nexport default extractFilePath\n"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACrBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACrBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AChBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AClBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACbA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;"}