@opentui/solid 0.2.1 → 0.2.3
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.
|
|
7
|
+
"version": "0.2.3",
|
|
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.
|
|
42
|
+
"@opentui/core": "0.2.3",
|
|
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
|
-
|
|
1
|
+
import { ensureRuntimePluginSupport } from "./runtime-plugin-support-configure.js";
|
|
2
|
+
export { ensureRuntimePluginSupport };
|
|
3
|
+
export type { SolidRuntimePluginSupportOptions } from "./runtime-plugin-support-configure.js";
|
|
@@ -1,76 +1,6 @@
|
|
|
1
|
-
import {
|
|
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
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
type RuntimePluginSupportState = typeof globalThis & {
|
|
18
|
-
[runtimePluginSupportInstalledKey]?: boolean
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
const loadThreeRuntimeModule = async (): Promise<Record<string, unknown>> => {
|
|
22
|
-
try {
|
|
23
|
-
return (await importRuntimeModule(THREE_RUNTIME_SPECIFIER)) as Record<string, unknown>
|
|
24
|
-
} catch (error) {
|
|
25
|
-
const message = error instanceof Error ? error.message : String(error)
|
|
26
|
-
throw new Error(
|
|
27
|
-
`Failed to load @opentui/three runtime module. Install @opentui/three in the host app before loading 3D plugins. ${message}`,
|
|
28
|
-
)
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
function importRuntimeModule(specifier: string): Promise<Record<string, unknown>> {
|
|
33
|
-
return import(specifier) as Promise<Record<string, unknown>>
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const additionalRuntimeModules: Record<string, RuntimeModuleEntry> = {
|
|
37
|
-
[THREE_RUNTIME_SPECIFIER]: loadThreeRuntimeModule,
|
|
38
|
-
"@opentui/solid": solidRuntime as Record<string, unknown>,
|
|
39
|
-
"solid-js": solidJsRuntime as Record<string, unknown>,
|
|
40
|
-
"solid-js/store": solidJsStoreRuntime as Record<string, unknown>,
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
const resolveRuntimeSpecifier = (specifier: string): string | null => {
|
|
44
|
-
if (!isCoreRuntimeModuleSpecifier(specifier) && !additionalRuntimeModules[specifier]) {
|
|
45
|
-
return null
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
return runtimeModuleIdForSpecifier(specifier)
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
export function ensureRuntimePluginSupport(): boolean {
|
|
52
|
-
const state = globalThis as RuntimePluginSupportState
|
|
53
|
-
|
|
54
|
-
if (state[runtimePluginSupportInstalledKey]) {
|
|
55
|
-
return false
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
ensureSolidTransformPlugin({
|
|
59
|
-
moduleName: runtimeModuleIdForSpecifier("@opentui/solid"),
|
|
60
|
-
resolvePath(specifier) {
|
|
61
|
-
return resolveRuntimeSpecifier(specifier)
|
|
62
|
-
},
|
|
63
|
-
})
|
|
64
|
-
|
|
65
|
-
registerBunPlugin(
|
|
66
|
-
createRuntimePlugin({
|
|
67
|
-
core: coreRuntime as Record<string, unknown>,
|
|
68
|
-
additional: additionalRuntimeModules,
|
|
69
|
-
}),
|
|
70
|
-
)
|
|
71
|
-
|
|
72
|
-
state[runtimePluginSupportInstalledKey] = true
|
|
73
|
-
return true
|
|
74
|
-
}
|
|
3
|
+
export { ensureRuntimePluginSupport }
|
|
4
|
+
export type { SolidRuntimePluginSupportOptions } from "./runtime-plugin-support-configure.js"
|
|
75
5
|
|
|
76
6
|
ensureRuntimePluginSupport()
|