UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

31 lines (30 loc) • 1.02 kB
import { n as tryProcessCwd } from "./safe-cwd-CZqaxroH.mjs"; import fs from "node:fs"; import path from "node:path"; //#region src/infra/is-main.ts function normalizePathCandidate(e, t) { if (!e) return; const n = path.resolve(t, e); try { return fs.realpathSync.native(n); } catch { return n; } } /** Detects whether a module is executing as the process entrypoint, including wrapper launches. */ function isMainModule({ currentFile: e, argv: t = process.argv, env: n = process.env, wrapperEntryPairs: r = [] }) { const i = tryProcessCwd() ?? path.dirname(e); const a = normalizePathCandidate(e, i); const o = normalizePathCandidate(t[1], i); if (a && o && a === o) return true; const s = normalizePathCandidate(n.pm_exec_path, i); if (a && s && a === s) return true; if (a && o && r.length > 0) { const e = path.basename(a); const t = path.basename(o); return r.some(({ wrapperBasename: n, entryBasename: r }) => e === r && t === n); } return false; } //#endregion export { isMainModule as t };