Skip to content

Mark @opentui packages as external in build configuration#315

Merged
subsy merged 4 commits intomainfrom
claude/fix-pr-313-root-cause-IZrZB
Feb 18, 2026
Merged

Mark @opentui packages as external in build configuration#315
subsy merged 4 commits intomainfrom
claude/fix-pr-313-root-cause-IZrZB

Conversation

@subsy
Copy link
Copy Markdown
Owner

@subsy subsy commented Feb 18, 2026

Summary

Updated the build script to mark @opentui/core and @opentui/react as external dependencies, preventing them from being bundled into the output.

Changes

  • Added --external @opentui/core --external @opentui/react flags to both bun build commands for cli.tsx and index.ts
  • This ensures these packages are treated as external dependencies rather than being included in the final bundle

Details

This change optimizes the build output by excluding the OpenTUI packages from bundling. These dependencies will now be resolved at runtime from the host environment rather than being duplicated in the bundle, reducing bundle size and avoiding potential conflicts with other versions of these packages.

https://claude.ai/code/session_013PHqBfJgh6hsm4nhV8Ksfp

Summary by CodeRabbit

  • Chores
    • Updated build configuration to treat certain external libraries as external, improving build reliability and consistency across CLI and standard builds.
    • Moved the main UI library to runtime dependencies to ensure it is available in production and reduce runtime issues, lowering bundle size and preventing missing-dependency problems.

The build was bundling @opentui/core's JavaScript (including FFI symbol
definitions) into dist/cli.js, while the native library (.so/.dylib)
was resolved at runtime from node_modules. When ^0.1.72 resolved to
0.1.80—which renamed setCursorStyle to setCursorStyleOptions in the
native binary—the baked-in JS referenced a symbol that no longer
existed, causing a crash on startup.

By marking @opentui/core and @opentui/react as --external in bun build,
both the JS FFI wrapper and the native library are always loaded from
the same installed version, eliminating the version skew entirely.

Closes #312

https://claude.ai/code/session_013PHqBfJgh6hsm4nhV8Ksfp
@vercel
Copy link
Copy Markdown

vercel bot commented Feb 18, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
ralph-tui Ready Ready Preview, Comment Feb 18, 2026 8:12am

Request Review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Feb 18, 2026

No actionable comments were generated in the recent review. 🎉


Walkthrough

package.json was updated: the Bun build scripts now mark @opentui/core, @opentui/react, and react as externals for CLI and index builds, and react was moved from devDependencies to dependencies.

Changes

Cohort / File(s) Summary
Build & Dependencies
package.json
Added --external @opentui/core--external@opentui/react --external react to Bun build scripts for both CLI and index; moved react from devDependencies into dependencies.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarises the main change: marking @opentui packages as external in the build configuration.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch claude/fix-pr-313-root-cause-IZrZB

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@subsy
Copy link
Copy Markdown
Owner Author

subsy commented Feb 18, 2026

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Feb 18, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
package.json (1)

18-18: The --external flag syntax is correct; consider using a wildcard to simplify the build script.

The space-separated form --external @opentui/core`` is the correct syntax for Bun 1.3.6 (as documented in Bun's bundler-compat guide). No syntax changes are needed.

The optional wildcard simplification remains valid:

♻️ Optional simplification using a wildcard
-"build": "bun build ./src/cli.tsx --outdir ./dist --target bun --sourcemap=external --external `@opentui/core` --external `@opentui/react` && bun build ./src/index.ts --outdir ./dist --target bun --sourcemap=external --external `@opentui/core` --external `@opentui/react` && ...",
+"build": "bun build ./src/cli.tsx --outdir ./dist --target bun --sourcemap=external --external '@opentui/*' && bun build ./src/index.ts --outdir ./dist --target bun --sourcemap=external --external '@opentui/*' && ...",

This future-proofs the build against additional @opentui/* packages without requiring further edits.

Regarding dual-React instances: the codebase uses jsxImportSource: "@opentui/react" in tsconfig.json, which directs all JSX to @opentui/react's runtime. Type-only imports from the react package (e.g. ReactNode) are erased at compile time and do not create runtime instances. No conflict arises from marking @opentui/react as external.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@package.json` at line 18, Update the "build" npm script to use a wildcard for
externals to future-proof bundling: locate the "build" script in package.json
(the value containing the bun build invocations) and replace the repeated
`--external `@opentui/core` --external `@opentui/react`` tokens with a single
wildcard external such as `--external '@opentui/*'` so any `@opentui/`* packages
are treated as externals without needing future edits.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@package.json`:
- Line 18: The build script in package.json currently externals `@opentui/core`
and `@opentui/react` but still bundles React into ./dist/cli.js and
./dist/index.js, creating a dual-React instance; update the "build" script so
both bun build invocations (for ./src/cli.tsx and ./src/index.ts) include
--external react, and move "react" from devDependencies into dependencies so
runtime and `@opentui/react` resolve to the same React instance (ensure command
handlers like run.tsx, resume.tsx, create-prd.tsx and TUI components import the
same package).

---

Nitpick comments:
In `@package.json`:
- Line 18: Update the "build" npm script to use a wildcard for externals to
future-proof bundling: locate the "build" script in package.json (the value
containing the bun build invocations) and replace the repeated `--external
`@opentui/core` --external `@opentui/react`` tokens with a single wildcard external
such as `--external '@opentui/*'` so any `@opentui/`* packages are treated as
externals without needing future edits.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Duplicate comments:
In `@package.json`:
- Line 18: The build script currently bundles React into both outputs and leaves
react in devDependencies; update the "build" script so both bun build
invocations include the --external react flag (in addition to the existing
--external `@opentui/react`) to prevent bundling React, and move "react" from
devDependencies into dependencies in package.json so consumers get a single
installed React instance at runtime; ensure both occurrences of the bun build
command in the script are modified.

With @opentui/core and @opentui/react externalized, React was still
being bundled into dist/cli.js. At runtime @opentui/react imports React
from node_modules while the app code used the bundled copy—two separate
instances in memory, which breaks hooks and reconciliation.

Add --external react to both bun build invocations and move react from
devDependencies to dependencies so a single instance is resolved.

https://claude.ai/code/session_013PHqBfJgh6hsm4nhV8Ksfp
@subsy subsy merged commit 07ea6fc into main Feb 18, 2026
9 checks passed
@subsy subsy deleted the claude/fix-pr-313-root-cause-IZrZB branch February 18, 2026 08:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants