@opentui/solid 0.2.0 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "main": "index.js",
5
5
  "types": "index.d.ts",
6
6
  "type": "module",
7
- "version": "0.2.0",
7
+ "version": "0.2.2",
8
8
  "description": "SolidJS renderer for OpenTUI",
9
9
  "license": "MIT",
10
10
  "repository": {
@@ -29,13 +29,17 @@
29
29
  "types": "./scripts/runtime-plugin-support.d.ts",
30
30
  "import": "./scripts/runtime-plugin-support.ts"
31
31
  },
32
+ "./runtime-plugin-support/configure": {
33
+ "types": "./scripts/runtime-plugin-support-configure.d.ts",
34
+ "import": "./scripts/runtime-plugin-support-configure.ts"
35
+ },
32
36
  "./jsx-runtime": "./jsx-runtime.d.ts",
33
37
  "./jsx-dev-runtime": "./jsx-runtime.d.ts"
34
38
  },
35
39
  "dependencies": {
36
40
  "@babel/core": "7.28.0",
37
41
  "@babel/preset-typescript": "7.27.1",
38
- "@opentui/core": "0.2.0",
42
+ "@opentui/core": "0.2.2",
39
43
  "babel-plugin-module-resolver": "5.0.2",
40
44
  "babel-preset-solid": "1.9.12",
41
45
  "entities": "7.0.1",
@@ -0,0 +1,7 @@
1
+ import { type RuntimeModuleEntry, type RuntimePluginRewriteOptions } from "@opentui/core/runtime-plugin";
2
+ export interface SolidRuntimePluginSupportOptions {
3
+ additional?: Record<string, RuntimeModuleEntry>;
4
+ core?: RuntimeModuleEntry;
5
+ rewrite?: RuntimePluginRewriteOptions;
6
+ }
7
+ export declare function ensureRuntimePluginSupport(options?: SolidRuntimePluginSupportOptions): boolean;
@@ -0,0 +1,109 @@
1
+ import { plugin as registerBunPlugin } from "bun"
2
+ import * as coreRuntime from "@opentui/core"
3
+ import {
4
+ createRuntimePlugin,
5
+ isCoreRuntimeModuleSpecifier,
6
+ runtimeModuleIdForSpecifier,
7
+ type RuntimeModuleEntry,
8
+ type RuntimePluginRewriteOptions,
9
+ } from "@opentui/core/runtime-plugin"
10
+ import * as solidJsRuntime from "solid-js"
11
+ import * as solidJsStoreRuntime from "solid-js/store"
12
+ import * as solidRuntime from "../index.js"
13
+ import { ensureSolidTransformPlugin } from "./solid-plugin.js"
14
+
15
+ const runtimePluginSupportInstalledKey = Symbol.for("opentui.solid.runtime-plugin-support")
16
+
17
+ export interface SolidRuntimePluginSupportOptions {
18
+ additional?: Record<string, RuntimeModuleEntry>
19
+ core?: RuntimeModuleEntry
20
+ rewrite?: RuntimePluginRewriteOptions
21
+ }
22
+
23
+ interface RuntimePluginSupportInstall {
24
+ specifiers: ReadonlySet<string>
25
+ core: RuntimeModuleEntry
26
+ rewriteKey: string
27
+ }
28
+
29
+ type RuntimePluginSupportState = typeof globalThis & {
30
+ [runtimePluginSupportInstalledKey]?: RuntimePluginSupportInstall
31
+ }
32
+
33
+ const defaultRuntimeModules: Record<string, RuntimeModuleEntry> = {
34
+ "@opentui/solid": solidRuntime as Record<string, unknown>,
35
+ "solid-js": solidJsRuntime as Record<string, unknown>,
36
+ "solid-js/store": solidJsStoreRuntime as Record<string, unknown>,
37
+ }
38
+
39
+ function normalizeRewriteKey(rewrite: RuntimePluginRewriteOptions | undefined): string {
40
+ return `${rewrite?.nodeModulesRuntimeSpecifiers ?? true}:${rewrite?.nodeModulesBareSpecifiers ?? false}`
41
+ }
42
+
43
+ function createRuntimeModules(options?: SolidRuntimePluginSupportOptions): Record<string, RuntimeModuleEntry> {
44
+ return {
45
+ ...defaultRuntimeModules,
46
+ ...(options?.additional ?? {}),
47
+ }
48
+ }
49
+
50
+ function assertCompatibleInstall(
51
+ install: RuntimePluginSupportInstall,
52
+ modules: Record<string, RuntimeModuleEntry>,
53
+ options?: SolidRuntimePluginSupportOptions,
54
+ ): void {
55
+ for (const specifier of Object.keys(modules)) {
56
+ if (!install.specifiers.has(specifier)) {
57
+ throw new Error(
58
+ `OpenTUI Solid runtime plugin support is already installed without ${specifier}. Call ensureRuntimePluginSupport({ additional }) from @opentui/solid/runtime-plugin-support/configure before importing @opentui/solid/runtime-plugin-support.`,
59
+ )
60
+ }
61
+ }
62
+
63
+ if (options?.core && options.core !== install.core) {
64
+ throw new Error("OpenTUI Solid runtime plugin support is already installed with a different core runtime module.")
65
+ }
66
+
67
+ if (options?.rewrite && normalizeRewriteKey(options.rewrite) !== install.rewriteKey) {
68
+ throw new Error("OpenTUI Solid runtime plugin support is already installed with different rewrite options.")
69
+ }
70
+ }
71
+
72
+ export function ensureRuntimePluginSupport(options: SolidRuntimePluginSupportOptions = {}): boolean {
73
+ const state = globalThis as RuntimePluginSupportState
74
+ const modules = createRuntimeModules(options)
75
+ const core = options.core ?? (coreRuntime as Record<string, unknown>)
76
+ const rewriteKey = normalizeRewriteKey(options.rewrite)
77
+
78
+ const install = state[runtimePluginSupportInstalledKey]
79
+ if (install) {
80
+ assertCompatibleInstall(install, modules, options)
81
+ return false
82
+ }
83
+
84
+ ensureSolidTransformPlugin({
85
+ moduleName: runtimeModuleIdForSpecifier("@opentui/solid"),
86
+ resolvePath(specifier) {
87
+ if (!isCoreRuntimeModuleSpecifier(specifier) && !modules[specifier]) {
88
+ return null
89
+ }
90
+
91
+ return runtimeModuleIdForSpecifier(specifier)
92
+ },
93
+ })
94
+
95
+ registerBunPlugin(
96
+ createRuntimePlugin({
97
+ core,
98
+ additional: modules,
99
+ rewrite: options.rewrite,
100
+ }),
101
+ )
102
+
103
+ state[runtimePluginSupportInstalledKey] = {
104
+ specifiers: new Set(Object.keys(modules)),
105
+ core,
106
+ rewriteKey,
107
+ }
108
+ return true
109
+ }
@@ -1 +1,3 @@
1
- export declare function ensureRuntimePluginSupport(): boolean;
1
+ import { ensureRuntimePluginSupport } from "./runtime-plugin-support-configure.js";
2
+ export { ensureRuntimePluginSupport };
3
+ export type { SolidRuntimePluginSupportOptions } from "./runtime-plugin-support-configure.js";
@@ -1,59 +1,6 @@
1
- import { plugin as registerBunPlugin } from "bun"
2
- import * as coreRuntime from "@opentui/core"
3
- import {
4
- createRuntimePlugin,
5
- isCoreRuntimeModuleSpecifier,
6
- runtimeModuleIdForSpecifier,
7
- type RuntimeModuleEntry,
8
- } from "@opentui/core/runtime-plugin"
9
- import * as solidJsRuntime from "solid-js"
10
- import * as solidJsStoreRuntime from "solid-js/store"
11
- import * as solidRuntime from "../index.js"
12
- import { ensureSolidTransformPlugin } from "./solid-plugin.js"
1
+ import { ensureRuntimePluginSupport } from "./runtime-plugin-support-configure.js"
13
2
 
14
- const runtimePluginSupportInstalledKey = Symbol.for("opentui.solid.runtime-plugin-support")
15
-
16
- type RuntimePluginSupportState = typeof globalThis & {
17
- [runtimePluginSupportInstalledKey]?: boolean
18
- }
19
-
20
- const additionalRuntimeModules: Record<string, RuntimeModuleEntry> = {
21
- "@opentui/solid": solidRuntime as Record<string, unknown>,
22
- "solid-js": solidJsRuntime as Record<string, unknown>,
23
- "solid-js/store": solidJsStoreRuntime as Record<string, unknown>,
24
- }
25
-
26
- const resolveRuntimeSpecifier = (specifier: string): string | null => {
27
- if (!isCoreRuntimeModuleSpecifier(specifier) && !additionalRuntimeModules[specifier]) {
28
- return null
29
- }
30
-
31
- return runtimeModuleIdForSpecifier(specifier)
32
- }
33
-
34
- export function ensureRuntimePluginSupport(): boolean {
35
- const state = globalThis as RuntimePluginSupportState
36
-
37
- if (state[runtimePluginSupportInstalledKey]) {
38
- return false
39
- }
40
-
41
- ensureSolidTransformPlugin({
42
- moduleName: runtimeModuleIdForSpecifier("@opentui/solid"),
43
- resolvePath(specifier) {
44
- return resolveRuntimeSpecifier(specifier)
45
- },
46
- })
47
-
48
- registerBunPlugin(
49
- createRuntimePlugin({
50
- core: coreRuntime as Record<string, unknown>,
51
- additional: additionalRuntimeModules,
52
- }),
53
- )
54
-
55
- state[runtimePluginSupportInstalledKey] = true
56
- return true
57
- }
3
+ export { ensureRuntimePluginSupport }
4
+ export type { SolidRuntimePluginSupportOptions } from "./runtime-plugin-support-configure.js"
58
5
 
59
6
  ensureRuntimePluginSupport()