From 7be017016cc96f4b305ce8537844d9d090cab8bd Mon Sep 17 00:00:00 2001 From: Aiden Cline Date: Sun, 10 May 2026 23:18:54 -0500 Subject: [PATCH] simplify code --- packages/opencode/script/build.ts | 12 +----------- packages/opencode/src/image/image.ts | 21 +++++++++------------ 2 files changed, 10 insertions(+), 23 deletions(-) diff --git a/packages/opencode/script/build.ts b/packages/opencode/script/build.ts index f449c4b822..2f2edb4ff5 100755 --- a/packages/opencode/script/build.ts +++ b/packages/opencode/script/build.ts @@ -188,10 +188,6 @@ for (const item of targets) { const localPath = path.resolve(dir, "node_modules/@opentui/core/parser.worker.js") const rootPath = path.resolve(dir, "../../node_modules/@opentui/core/parser.worker.js") const parserWorker = fs.realpathSync(fs.existsSync(localPath) ? localPath : rootPath) - const photonWasm = path.relative( - dir, - fileURLToPath(import.meta.resolve("@silvia-odwyer/photon-node/photon_rs_bg.wasm")), - ).replaceAll("\\", "/") const workerPath = "./src/cli/cmd/tui/worker.ts" // Use platform-specific bunfs root path based on target OS @@ -218,13 +214,7 @@ for (const item of targets) { windows: {}, }, files: embeddedFileMap ? { "opencode-web-ui.gen.ts": embeddedFileMap } : {}, - entrypoints: [ - "./src/index.ts", - parserWorker, - workerPath, - photonWasm, - ...(embeddedFileMap ? ["opencode-web-ui.gen.ts"] : []), - ], + entrypoints: ["./src/index.ts", parserWorker, workerPath, ...(embeddedFileMap ? ["opencode-web-ui.gen.ts"] : [])], define: { OPENCODE_VERSION: `'${Script.version}'`, OPENCODE_MIGRATIONS: JSON.stringify(migrations), diff --git a/packages/opencode/src/image/image.ts b/packages/opencode/src/image/image.ts index bc87f91661..aec8e2b1ff 100644 --- a/packages/opencode/src/image/image.ts +++ b/packages/opencode/src/image/image.ts @@ -60,17 +60,15 @@ export const layer = Layer.effect( Effect.gen(function* () { const config = yield* Config.Service const loadPhoton = yield* Effect.cached( - Effect.promise(async () => { - try { - // Patched photon-node reads this during module init so Bun compiled binaries use the embedded wasm path. - ;(globalThis as typeof globalThis & { __OPENCODE_PHOTON_WASM_PATH?: string }).__OPENCODE_PHOTON_WASM_PATH = - photonWasm - return await import("@silvia-odwyer/photon-node") - } catch (error) { - log.warn("failed to load photon", { error }) - return null - } - }), + Effect.sync(() => { + // Patched photon-node reads this during module init so Bun compiled binaries use the embedded wasm path. + ;(globalThis as typeof globalThis & { __OPENCODE_PHOTON_WASM_PATH?: string }).__OPENCODE_PHOTON_WASM_PATH = + photonWasm + }).pipe( + Effect.andThen(() => Effect.tryPromise(() => import("@silvia-odwyer/photon-node"))), + Effect.tapError((error) => Effect.sync(() => log.warn("failed to load photon", { error }))), + Effect.mapError(() => new ResizerUnavailableError()), + ), ) const normalize = Effect.fn("Image.normalize")(function* (input: MessageV2.FilePart) { @@ -89,7 +87,6 @@ export const layer = Layer.effect( if (bytes <= info.maxBase64Bytes) return input const photon = yield* loadPhoton - if (!photon) return yield* new ResizerUnavailableError() const decoded = yield* Effect.try({ try: () => photon.PhotonImage.new_from_byteslice(Buffer.from(base64, "base64")),