Skip to content

Commit dca635c

Browse files
committed
fix: use computed import paths to prevent bun bundling ink
The issue was that bun's bundler statically analyzes dynamic imports and bundles them anyway. By using computed paths like: const inkPath = ['..', 'ui', 'ink', 'InkRenderer.js'].join('/'); await import(inkPath); bun cannot statically resolve the import and excludes it from the bundle. This reduces the bundle from 541 modules to 424 modules and fixes the 'Cannot find package react-devtools-core' error in compiled binaries.
1 parent 4f23e98 commit dca635c

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

src/core/agent.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,9 @@ import { ProjectAnalyzer } from '../skills/autoSkill.js';
6666
import { AUTOHAND_PATHS } from '../constants.js';
6767
import { PersistentInput, createPersistentInput } from '../ui/persistentInput.js';
6868
import { formatToolOutputForDisplay } from '../ui/toolOutput.js';
69-
// Dynamic import for InkRenderer to avoid bundling yoga-wasm in standalone binary
70-
type InkRenderer = import('../ui/ink/InkRenderer.js').InkRenderer;
69+
// InkRenderer type - using 'any' to avoid bun bundling ink at compile time
70+
// The actual type comes from dynamic import at runtime
71+
type InkRenderer = any;
7172
import { PermissionManager } from '../permissions/PermissionManager.js';
7273
import { HookManager, type HookContext } from './HookManager.js';
7374
import { confirm as unifiedConfirm, isExternalCallbackEnabled } from '../ui/promptCallback.js';
@@ -2810,7 +2811,9 @@ If lint or tests fail, report the issues but do NOT commit.`;
28102811
}
28112812

28122813
// Dynamic import to avoid bundling ink in standalone binary
2813-
const { showFilePalette } = await import('../ui/filePalette.js');
2814+
// Use computed path to prevent bun from statically analyzing the import
2815+
const palettePath = ['..', 'ui', 'filePalette.js'].join('/');
2816+
const { showFilePalette } = await import(/* @vite-ignore */ palettePath);
28142817
const selection = await showFilePalette({
28152818
files: this.workspaceFiles,
28162819
statusLine: this.formatStatusLine(),
@@ -3081,8 +3084,10 @@ If lint or tests fail, report the issues but do NOT commit.`;
30813084
private async initializeUI(abortController?: AbortController, onCancel?: () => void): Promise<void> {
30823085
if (this.useInkRenderer && process.stdout.isTTY && process.stdin.isTTY) {
30833086
// Dynamically import InkRenderer to avoid bundling yoga-wasm in standalone binary
3087+
// Use computed path to prevent bun from statically analyzing the import
30843088
try {
3085-
const { createInkRenderer } = await import('../ui/ink/InkRenderer.js');
3089+
const inkPath = ['..', 'ui', 'ink', 'InkRenderer.js'].join('/');
3090+
const { createInkRenderer } = await import(/* @vite-ignore */ inkPath);
30863091
// Create and start InkRenderer (only in TTY mode)
30873092
this.inkRenderer = createInkRenderer({
30883093
onInstruction: (text) => {

0 commit comments

Comments
 (0)