Files
oh-my-pi/packages/coding-agent/scripts/dev-launch-preload.ts
T
can1357 ead5cf6871 fix(coding-agent/scripts): fixed CLI startup by launching through a bunfig-free shim script
- Updated `install:dev` to symlink `packages/coding-agent/scripts/dev-launch` into Bun's global bin directory as `omp`.
- Added a `dev-launch` shell script that launches Bun from an isolated directory and preserves the caller's working directory for restoration.
- Added a preload shim that restores `OMP_LAUNCH_CWD` before CLI execution so external project `bunfig.toml` preloads are not used.
2026-06-06 19:05:20 +02:00

20 lines
856 B
TypeScript

/**
* Bun `--preload` shim for the omp dev launcher (`scripts/dev-launch`).
*
* The launcher starts Bun from an empty, bunfig-free directory so a foreign
* project's `bunfig.toml` `preload` cannot run inside the omp CLI: Bun reads
* `bunfig.toml` from the *current working directory* on startup and evaluates
* its `preload` entries before the entrypoint, so a bun-shebang bin inherits
* whatever `preload` the directory you launched from declares (and crashes if
* that preload can't resolve). This shim is loaded before the entrypoint's
* imports run, so it restores the user's real working directory in time for
* import-time snapshots (e.g. `getProjectDir()` in `@oh-my-pi/pi-utils/dirs`).
*/
const launchCwd = process.env.OMP_LAUNCH_CWD;
if (launchCwd) {
delete process.env.OMP_LAUNCH_CWD;
try {
process.chdir(launchCwd);
} catch {}
}