From 48688030c3ca23cb4ccfed45ac394160ec1dc691 Mon Sep 17 00:00:00 2001 From: schickling-assistant <261620128+schickling-assistant@users.noreply.github.com> Date: Wed, 6 May 2026 11:28:39 +0200 Subject: [PATCH] feat(pty-effect): honor PTY_SERVER_MODULE_PATH env override MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `spawnDaemonViaNode` resolves `@myobie/pty/server` via `require.resolve` to find the script the daemon child runs. Inside a `bun build --compile` single-file binary that returns a `bunfs:` path the spawned `node` child can't read — it crashes with `Cannot find module '@myobie/pty/server' from '/\$bunfs/root/'`. Honor `PTY_SERVER_MODULE_PATH` first so consumers that need to point at a real on-disk copy (forge wraps its bun bundle and exports the env to the resolved path) can do so without changes to @overeng/pty-effect's public API. Falls back to the existing require.resolve when the env isn't set, preserving today's behavior for everyone else. Co-Authored-By: Claude Opus 4.7 (1M context) --- packages/@overeng/pty-effect/src/client.ts | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/packages/@overeng/pty-effect/src/client.ts b/packages/@overeng/pty-effect/src/client.ts index 7737e2275..c10712783 100644 --- a/packages/@overeng/pty-effect/src/client.ts +++ b/packages/@overeng/pty-effect/src/client.ts @@ -326,7 +326,23 @@ const withEnvOverrides = ({ }).pipe(Effect.flatMap((saved) => effect.pipe(Effect.ensuring(restore(saved))))) } -const resolvePtyServerModulePath = () => require.resolve('@myobie/pty/server') +/** + * Locate `@myobie/pty/server` for the spawned daemon child. + * + * Honors `PTY_SERVER_MODULE_PATH` first so consumers can pin the path + * explicitly. This is required when the consumer is a single-file + * `bun build --compile` binary: `require.resolve('@myobie/pty/server')` + * inside the bundle returns a `bunfs:` path that the spawned `node` + * child can't read, so the spawn fails with + * `Cannot find module '@myobie/pty/server' from '/$bunfs/root/'`. + * The wrapper script around the bundle sets the env var to a real + * on-disk path materialized in `node_modules/@myobie/pty/dist/server.js`. + * + * TODO(upstream): push this env-var override into a future + * `@overeng/pty-effect` release so consumers don't need to patch. + */ +const resolvePtyServerModulePath = () => + process.env['PTY_SERVER_MODULE_PATH'] ?? require.resolve('@myobie/pty/server') const spawnDaemonViaNode = (spec: PtyDaemonSpec) => wrapPromise({