Files
Kit LangtonandSimon Klee 665233f72e feat(core): preserve host-provided bare specifiers in runtime plugin (#1569)
## Why

Host applications such as OpenCode register shared host packages (for
example `effect`, `effect/*`, and `@opencode/plugin/*`) via Bun's
`build.module(specifier, ...)`. When an external TUI plugin imports
`@opentui/*` or `solid-js` alongside those packages, OpenTUI's runtime
plugin rewrites remaining bare specifiers through
`import.meta.resolve(specifier, resolveParent)` to `file://` URLs.
Because `import.meta.resolve` ignores `build.module` registrations and
resolves on the filesystem, any plugin with its own
`node_modules/effect` gets pinned to the duplicate disk copy instead of
the host's `build.module` instance unless the host installs a fragile
`file://` `onResolve` reverse-mapping hook.

## What Changes

- Add `preserve?: RuntimeSpecifierPreserve` (`Iterable<string> |
((specifier: string) => boolean)`) to `CreateRuntimePluginOptions`,
`SolidRuntimePluginSupportOptions`, and
`ReactRuntimePluginSupportOptions`.
- Keep `core` and `additional` (`runtimeModuleIdsBySpecifier`) higher
precedence than `preserve`, then skip bare specifiers matched by
`preserve` during parent-based bare-specifier rewriting
(`rewriteImportsFromResolveParents`), `node_modules` ESM prescanning
(`collectNodeModulesRuntimeRewritePaths`), and rewrite-loader
installation when a file's only bare imports are preserved specifiers.
- Validate `preserve` compatibility across repeated
`ensureRuntimePluginSupport()` calls in `@opentui/core`,
`@opentui/solid`, and `@opentui/react`.
- Document `preserve` in
`packages/web/src/content/docs/extend/runtime-plugins.mdx`.

## Verification

- `cd packages/core && bun run typecheck && bun test
src/tests/runtime-plugin.test.ts
src/tests/runtime-plugin-support.test.ts`
- `cd packages/solid && bun test tests/runtime-plugin-support.test.ts
tests/runtime-plugin-support-preload.test.ts
tests/runtime-plugin-support-node-modules.test.ts`
- `cd packages/react && bun test tests/runtime-plugin-support.test.ts`
- `cd packages/web && bun run validate:docs && bun run
validate:docs:examples -- extend/runtime-plugins.mdx`
- `bun run fmt:check && bun run lint:ci`

---------

Co-authored-by: Simon Klee <hello@simonklee.dk>
2026-10-07 08:40:21 +02:00
..