Files
anomalyco__opentui/packages/react/scripts/runtime-plugin-support.ts
T
Matt Simpson 4fc3fd3bf7 fix(react): correct runtime-plugin-support import path for published package (#962)
## Summary
- Fixed `runtime-plugin-support.ts` importing from `../src/index.js`
which doesn't exist in the published `dist/` (only `dist/index.js` does)
- Changed to `../index.js` to match the pattern `@opentui/solid` already
uses
- Added root `index.ts` barrel so the import resolves at dev time and
tsc can generate declarations

Fixes #960
2026-04-22 06:22:15 +02:00

43 lines
1.5 KiB
TypeScript

import { plugin as registerBunPlugin } from "bun"
import * as coreRuntime from "@opentui/core"
import { createRuntimePlugin, type RuntimeModuleEntry } from "@opentui/core/runtime-plugin"
import * as reactRuntime from "react"
import * as reactJsxRuntime from "react/jsx-runtime"
import * as reactJsxDevRuntime from "react/jsx-dev-runtime"
import * as opentuiReactRuntime from "../index.js"
const runtimePluginSupportInstalledKey = "__opentuiReactRuntimePluginSupportInstalled__"
type RuntimePluginSupportState = typeof globalThis & {
[runtimePluginSupportInstalledKey]?: boolean
}
const additionalRuntimeModules: Record<string, RuntimeModuleEntry> = {
"@opentui/react": opentuiReactRuntime as Record<string, unknown>,
"@opentui/react/jsx-runtime": reactJsxRuntime as Record<string, unknown>,
"@opentui/react/jsx-dev-runtime": reactJsxDevRuntime as Record<string, unknown>,
react: reactRuntime as Record<string, unknown>,
"react/jsx-runtime": reactJsxRuntime as Record<string, unknown>,
"react/jsx-dev-runtime": reactJsxDevRuntime as Record<string, unknown>,
}
export function ensureRuntimePluginSupport(): boolean {
const state = globalThis as RuntimePluginSupportState
if (state[runtimePluginSupportInstalledKey]) {
return false
}
registerBunPlugin(
createRuntimePlugin({
core: coreRuntime as Record<string, unknown>,
additional: additionalRuntimeModules,
}),
)
state[runtimePluginSupportInstalledKey] = true
return true
}
ensureRuntimePluginSupport()