/** * ============================================================ * src/utils/greenRoot.ts —— 绿色版(bun --compile 单文件)资源探测锚点 * ------------------------------------------------------------ * 问题:`bun build --compile` 把运行时 + 全部 JS 焊进单个可执行文件, * 此时 `import.meta.url` 指向嵌入式虚拟路径(`/$bunfs/...`),磁盘上 * 既没有 package.json 也没有源码树 —— `findPackageRoot` 会抛错,靠它 * 定位的 `vendor/ripgrep/`、`skills/`、`plugins/`、`workflows/` 全失效。 * * 方案:绿色版把这些外部资产与可执行文件**放在同一目录**,运行时用 * `dirname(process.execPath)` 找回来(exe 同级)。 * * 为什么 dev / npm 模式零影响: * - dev(`bun run src/main.tsx`):execPath = bun 二进制,其同级目录 * (如 `~/.bun/bin/`)没有 vendor/skills/plugins。 * - npm 全局安装(`node dist/main.js`):execPath = node 二进制,其 * 同级目录同样没有这些资源目录。 * - 故调用方一律对返回值做 `existsSync` 过滤:dev/npm 下命不中 → 被 * 丢弃 → 行为与现状逐字节一致。只有真·绿色版(资产摆在 exe 旁边) * 才会命中。因此这里**无条件返回** execPath 目录即可,无需判别 * "是否 compiled"。 * ============================================================ */ import { dirname } from 'node:path'; /** * 返回可执行文件所在目录(绿色版资产的同级锚点)。 * * 调用方必须用 existsSync 过滤返回路径下的目标子目录 —— dev/npm 模式 * execPath 指向 node/bun 二进制,其同级没有资源目录,过滤后无副作用。 */ export function execSiblingDir(): string { return dirname(process.execPath); }