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;