UNPKG

@sentry/node

Version:

Sentry Node SDK using OpenTelemetry for performance instrumentation

38 lines (37 loc) • 1.62 kB
import { defaultStackParser } from "../sdk/api.js"; import { resolve } from "node:path"; // src/utils/entry-point.ts /** * Parses the process arguments to determine the app path, import paths, and require paths. */ function parseProcessPaths(proc) { const { execArgv, argv, cwd: getCwd } = proc; const cwd = getCwd(); const appPath = resolve(cwd, argv[1] || ""); const joinedArgs = execArgv.join(" "); return { appPath, importPaths: Array.from(joinedArgs.matchAll(/--import[ =](\S+)/g)).map((e) => resolve(cwd, e[1] || "")), requirePaths: Array.from(joinedArgs.matchAll(/(?:--require|-r)[ =](\S+)/g)).map((e) => resolve(cwd, e[1] || "")) }; } /** * Gets the current entry point type. * * `app` means this function was most likely called via the app entry point. * `import` means this function was most likely called from an --import cli arg. * `require` means this function was most likely called from a --require cli arg. * `unknown` means we couldn't determine for sure. */ function getEntryPointType(proc = process) { const filenames = defaultStackParser((/* @__PURE__ */ new Error()).stack || "").map((f) => f.filename).filter(Boolean); const { appPath, importPaths, requirePaths } = parseProcessPaths(proc); const output = []; if (appPath && filenames.includes(appPath)) output.push("app"); if (importPaths.some((p) => filenames.includes(p))) output.push("import"); if (requirePaths.some((p) => filenames.includes(p))) output.push("require"); if (output.length === 1) return output[0]; return "unknown"; } export { getEntryPointType, parseProcessPaths }; //# sourceMappingURL=entry-point.js.map