Mark @opentui packages as external in build configuration#315
Conversation
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
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
No actionable comments were generated in the recent review. 🎉 Walkthrough
Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes 🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
package.json (1)
18-18: The--externalflag 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 thereactpackage (e.g.ReactNode) are erased at compile time and do not create runtime instances. No conflict arises from marking@opentui/reactas 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.
There was a problem hiding this comment.
🤖 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
Summary
Updated the build script to mark
@opentui/coreand@opentui/reactas external dependencies, preventing them from being bundled into the output.Changes
--external @opentui/core --external @opentui/reactflags to bothbun buildcommands forcli.tsxandindex.tsDetails
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