From 13b627e28a232dc0d076ae07e3f8d32f28bd329f Mon Sep 17 00:00:00 2001 From: cpacker Date: Thu, 29 Jan 2026 15:02:07 -0800 Subject: [PATCH] fix: USE_MAGICK build flag - use define instead of bun:bundle MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The bun:bundle module only exists at bundle time, not when running source directly (dev/tests). This caused CI failures with: error: Cannot find package 'bundle' Fix: Use Bun.build's define option to set __USE_MAGICK__ as a compile-time constant. At dev/test time it's undefined (defaults to false/sharp). At build time it's set based on USE_MAGICK env var. 👾 Generated with [Letta Code](https://letta.com) Co-Authored-By: Letta --- build.js | 1 + src/cli/helpers/imageResize.ts | 13 ++++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/build.js b/build.js index 41b2a67..4836cd9 100644 --- a/build.js +++ b/build.js @@ -39,6 +39,7 @@ await Bun.build({ define: { LETTA_VERSION: JSON.stringify(version), BUILD_TIME: JSON.stringify(new Date().toISOString()), + __USE_MAGICK__: useMagick ? "true" : "false", }, // Load text files as strings (for markdown, etc.) loader: { diff --git a/src/cli/helpers/imageResize.ts b/src/cli/helpers/imageResize.ts index b701d07..6d118e1 100644 --- a/src/cli/helpers/imageResize.ts +++ b/src/cli/helpers/imageResize.ts @@ -1,6 +1,5 @@ // Image resizing utilities for clipboard paste // Follows Codex CLI's approach (codex-rs/utils/image/src/lib.rs) -import { feature } from "bun:bundle"; export const MAX_IMAGE_WIDTH = 2000; export const MAX_IMAGE_HEIGHT = 2000; @@ -14,7 +13,15 @@ export interface ResizeResult { resized: boolean; } -// Import the correct implementation based on feature flag -export const resizeImageIfNeeded = feature("USE_MAGICK") +// Build-time constant for magick variant (set via Bun.build define when USE_MAGICK=1) +// At dev/test time this is undefined, at build time it's true/false +declare const __USE_MAGICK__: boolean | undefined; + +// Use magick implementation only when explicitly built with USE_MAGICK=1 +// typeof check handles dev/test case where __USE_MAGICK__ doesn't exist +const useMagick = + typeof __USE_MAGICK__ !== "undefined" && __USE_MAGICK__ === true; + +export const resizeImageIfNeeded = useMagick ? (await import("./imageResize.magick.js")).resizeImageIfNeeded : (await import("./imageResize.sharp.js")).resizeImageIfNeeded;