@opentui/solid
Version:
SolidJS renderer for OpenTUI
60 lines (48 loc) • 1.77 kB
text/typescript
import { plugin as registerBunPlugin } from "bun"
import * as coreRuntime from "@opentui/core"
import {
createRuntimePlugin,
isCoreRuntimeModuleSpecifier,
runtimeModuleIdForSpecifier,
type RuntimeModuleEntry,
} from "@opentui/core/runtime-plugin"
import * as solidJsRuntime from "solid-js"
import * as solidJsStoreRuntime from "solid-js/store"
import * as solidRuntime from "../index.js"
import { ensureSolidTransformPlugin } from "./solid-plugin.js"
const runtimePluginSupportInstalledKey = Symbol.for("opentui.solid.runtime-plugin-support")
type RuntimePluginSupportState = typeof globalThis & {
[runtimePluginSupportInstalledKey]?: boolean
}
const additionalRuntimeModules: Record<string, RuntimeModuleEntry> = {
"@opentui/solid": solidRuntime as Record<string, unknown>,
"solid-js": solidJsRuntime as Record<string, unknown>,
"solid-js/store": solidJsStoreRuntime as Record<string, unknown>,
}
const resolveRuntimeSpecifier = (specifier: string): string | null => {
if (!isCoreRuntimeModuleSpecifier(specifier) && !additionalRuntimeModules[specifier]) {
return null
}
return runtimeModuleIdForSpecifier(specifier)
}
export function ensureRuntimePluginSupport(): boolean {
const state = globalThis as RuntimePluginSupportState
if (state[runtimePluginSupportInstalledKey]) {
return false
}
ensureSolidTransformPlugin({
moduleName: runtimeModuleIdForSpecifier("@opentui/solid"),
resolvePath(specifier) {
return resolveRuntimeSpecifier(specifier)
},
})
registerBunPlugin(
createRuntimePlugin({
core: coreRuntime as Record<string, unknown>,
additional: additionalRuntimeModules,
}),
)
state[runtimePluginSupportInstalledKey] = true
return true
}
ensureRuntimePluginSupport()