fix: USE_MAGICK build flag - use define instead of bun:bundle
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 <noreply@letta.com>
This commit is contained in:
1
build.js
1
build.js
@@ -39,6 +39,7 @@ await Bun.build({
|
|||||||
define: {
|
define: {
|
||||||
LETTA_VERSION: JSON.stringify(version),
|
LETTA_VERSION: JSON.stringify(version),
|
||||||
BUILD_TIME: JSON.stringify(new Date().toISOString()),
|
BUILD_TIME: JSON.stringify(new Date().toISOString()),
|
||||||
|
__USE_MAGICK__: useMagick ? "true" : "false",
|
||||||
},
|
},
|
||||||
// Load text files as strings (for markdown, etc.)
|
// Load text files as strings (for markdown, etc.)
|
||||||
loader: {
|
loader: {
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
// Image resizing utilities for clipboard paste
|
// Image resizing utilities for clipboard paste
|
||||||
// Follows Codex CLI's approach (codex-rs/utils/image/src/lib.rs)
|
// 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_WIDTH = 2000;
|
||||||
export const MAX_IMAGE_HEIGHT = 2000;
|
export const MAX_IMAGE_HEIGHT = 2000;
|
||||||
@@ -14,7 +13,15 @@ export interface ResizeResult {
|
|||||||
resized: boolean;
|
resized: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Import the correct implementation based on feature flag
|
// Build-time constant for magick variant (set via Bun.build define when USE_MAGICK=1)
|
||||||
export const resizeImageIfNeeded = feature("USE_MAGICK")
|
// 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.magick.js")).resizeImageIfNeeded
|
||||||
: (await import("./imageResize.sharp.js")).resizeImageIfNeeded;
|
: (await import("./imageResize.sharp.js")).resizeImageIfNeeded;
|
||||||
|
|||||||
Reference in New Issue
Block a user