solid-tag-runtime 0.0.12 → 0.0.14

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.
@@ -0,0 +1,79 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <title>solid-tag-runtime rendering</title>
6
+ </head>
7
+ <body>
8
+ <div id="app"></div>
9
+
10
+ <!-- Define a reusable runtime module. -->
11
+ <script type="solid-jsx" data-solid-runtime="main" module="/Counter.jsx">
12
+ import { createSignal } from "solid-js";
13
+
14
+ export default function Counter(props) {
15
+ const [count, setCount] = createSignal(0);
16
+ return (
17
+ <button onClick={() => setCount(value => value + 1)}>
18
+ {props.label}: {count()}
19
+ </button>
20
+ );
21
+ }
22
+ </script>
23
+
24
+ <!-- Define + mount one declaration-owned instance into #app. -->
25
+ <script
26
+ type="solid-jsx"
27
+ data-solid-runtime="main"
28
+ module="/App.jsx"
29
+ render="#app"
30
+ >
31
+ export default function App() {
32
+ return <h1>Mounted by &lt;script render&gt;</h1>;
33
+ }
34
+ </script>
35
+
36
+ <!-- Reference the already-defined Counter module and create independent instances. -->
37
+ <solid-render
38
+ data-solid-runtime="main"
39
+ module="/Counter.jsx"
40
+ prop:label="Counter A"
41
+ ></solid-render>
42
+
43
+ <solid-render
44
+ data-solid-runtime="main"
45
+ module="/Counter.jsx"
46
+ prop:label="Counter B"
47
+ ></solid-render>
48
+
49
+ <!--
50
+ This bootstrap is ordinary JavaScript. The surrounding application/import
51
+ map is responsible for resolving Solid and solid-tag-runtime bare imports.
52
+ -->
53
+ <script type="module">
54
+ import * as Solid from "solid-js";
55
+ import * as SolidWeb from "@solidjs/web";
56
+ import html from "@solidjs/html";
57
+ import { createRuntime } from "solid-tag-runtime";
58
+ import { createHTMLRuntime } from "solid-tag-runtime/html";
59
+
60
+ const runtime = createRuntime({
61
+ modules: {
62
+ "solid-js": Solid,
63
+ "@solidjs/web": SolidWeb,
64
+ "@solidjs/html": { default: html },
65
+ },
66
+ });
67
+
68
+ const htmlRuntime = createHTMLRuntime(runtime, {
69
+ scope: "main",
70
+ root: document,
71
+ appendTo: document.body,
72
+ acceptUnscoped: false,
73
+ });
74
+
75
+ await htmlRuntime.register();
76
+ await htmlRuntime.observe({ registerExisting: false });
77
+ </script>
78
+ </body>
79
+ </html>
@@ -0,0 +1,24 @@
1
+ import { createSolidRuntime } from "solid-tag-runtime/solid";
2
+
3
+ const runtime = await createSolidRuntime({
4
+ solid: {
5
+ source: "auto",
6
+ // Optional when the host/import map cannot resolve the complete family:
7
+ fallbackProvider: "esm.sh",
8
+ },
9
+ modules: {
10
+ "@app/config": {
11
+ greeting: "Hello",
12
+ },
13
+ },
14
+ });
15
+
16
+ runtime.define("/Greeting.jsx", `
17
+ import { greeting } from "@app/config";
18
+
19
+ export default function Greeting() {
20
+ return <p>{greeting} from createSolidRuntime()</p>;
21
+ }
22
+ `);
23
+
24
+ export default runtime;
package/index.d.ts CHANGED
@@ -1,30 +1,58 @@
1
1
  export type ModuleFormat = "jsx" | "js";
2
+ export type CompileCacheMode = "use" | "refresh" | "bypass";
2
3
 
3
4
  export interface ModuleNamespaceLike {
4
5
  readonly [key: string]: unknown;
5
6
  }
6
7
 
8
+ export interface CompileContext {
9
+ id?: string;
10
+ format?: ModuleFormat;
11
+ }
12
+
7
13
  export interface CompilerImportReference {
8
14
  specifier: string;
9
15
  start: number;
10
16
  end: number;
11
- kind?: string;
17
+ kind?: "static" | "dynamic" | "export" | string;
18
+ }
19
+
20
+ export interface CompiledArtifact {
21
+ schema?: number;
22
+ code: string;
23
+ imports: CompilerImportReference[];
24
+ diagnostics?: unknown[];
25
+ sourceMap?: string;
26
+ changed?: boolean;
12
27
  }
13
28
 
14
29
  export interface RuntimeCompiler {
15
- analyze(source: string, context?: { id?: string; format?: ModuleFormat }): {
30
+ /** Stable identity required for persistent compile-cache reuse. */
31
+ fingerprint?: string | ((context: CompileContext) => string | Promise<string>);
32
+ /** Additional compile-affecting context to include in persistent cache identity. */
33
+ cacheContext?: (context: CompileContext) => unknown | Promise<unknown>;
34
+ /** Preferred compiler boundary: return a linker-ready pre-link artifact. */
35
+ compile?(source: string, context?: CompileContext): CompiledArtifact | Promise<CompiledArtifact>;
36
+ /** Transitional compiler API retained for compatibility. */
37
+ analyze?(source: string, context?: CompileContext): {
38
+ imports?: CompilerImportReference[];
39
+ needsHtmlRuntime?: boolean;
40
+ } | Promise<{
16
41
  imports?: CompilerImportReference[];
17
42
  needsHtmlRuntime?: boolean;
18
- };
19
- transform(source: string, context?: {
20
- id?: string;
21
- format?: ModuleFormat;
22
- htmlImportSource?: string;
23
- }): {
43
+ }>;
44
+ /** Transitional compiler API retained for compatibility. */
45
+ transform?(source: string, context?: CompileContext & { htmlImportSource?: string }): {
46
+ code: string;
47
+ diagnostics?: unknown[];
48
+ changed?: boolean;
49
+ sourceMap?: string;
50
+ } | Promise<{
24
51
  code: string;
25
52
  diagnostics?: unknown[];
26
53
  changed?: boolean;
27
- };
54
+ sourceMap?: string;
55
+ }>;
28
56
  }
29
57
 
30
58
  export interface ModuleUrlBackend {
@@ -33,6 +61,53 @@ export interface ModuleUrlBackend {
33
61
  revoke?(url: string): void;
34
62
  }
35
63
 
64
+ export interface CachedCompileRecord {
65
+ schema: number;
66
+ key: string;
67
+ artifactAbi: string;
68
+ sourceHash: string;
69
+ format: string;
70
+ compilerFingerprint: string;
71
+ compileContextHash: string;
72
+ artifact: CompiledArtifact;
73
+ createdAt: number;
74
+ lastUsedAt?: number;
75
+ byteSize?: number;
76
+ artifactHash?: string;
77
+ }
78
+
79
+ export interface CompileCacheStore {
80
+ readonly kind?: string;
81
+ get(key: string): Promise<CachedCompileRecord | undefined>;
82
+ set(key: string, value: CachedCompileRecord): Promise<void>;
83
+ delete(key: string): Promise<boolean | void>;
84
+ clear?(options?: { prefix?: string }): Promise<number | void>;
85
+ entries?(options?: { prefix?: string }): Promise<Array<[string, CachedCompileRecord]>>;
86
+ }
87
+
88
+ export interface CompileCacheOptions {
89
+ enabled?: boolean;
90
+ store: CompileCacheStore;
91
+ namespace?: string;
92
+ version?: string;
93
+ maxEntries?: number;
94
+ maxBytes?: number;
95
+ /** Maximum record age in milliseconds. */
96
+ maxAge?: number;
97
+ }
98
+
99
+ export interface LocalStorageLike {
100
+ readonly length: number;
101
+ key(index: number): string | null;
102
+ getItem(key: string): string | null;
103
+ setItem(key: string, value: string): void;
104
+ removeItem(key: string): void;
105
+ }
106
+
107
+ export interface IndexedDBFactoryLike {
108
+ open(name: string, version?: number): any;
109
+ }
110
+
36
111
  export interface RuntimeOptions {
37
112
  compiler?: RuntimeCompiler;
38
113
  compilerOptions?: Record<string, unknown>;
@@ -41,6 +116,8 @@ export interface RuntimeOptions {
41
116
  allowNativeImports?: boolean;
42
117
  resolve?: (specifier: string, importer: string | null, runtime: SolidTagRuntime) => string | void;
43
118
  moduleUrlBackend?: ModuleUrlBackend;
119
+ /** Opt-in persistent pre-link compile artifact cache. */
120
+ compileCache?: CompileCacheOptions | false;
44
121
  }
45
122
 
46
123
  export interface DefineOptions {
@@ -55,6 +132,20 @@ export interface ToComponentOptions extends ToModuleOptions {
55
132
  exportName?: string;
56
133
  }
57
134
 
135
+ export interface CompileOptions {
136
+ cache?: CompileCacheMode;
137
+ }
138
+
139
+ export interface CompileCacheInfo {
140
+ enabled: boolean;
141
+ status: "none" | "hit" | "miss" | "refresh" | "bypass";
142
+ source?: string;
143
+ key?: string;
144
+ compilerFingerprint?: string;
145
+ sourceHash?: string;
146
+ compileContextHash?: string;
147
+ }
148
+
58
149
  export interface ModuleInfo {
59
150
  id: string;
60
151
  kind: "source" | "host" | "url";
@@ -65,6 +156,7 @@ export interface ModuleInfo {
65
156
  dependents: string[];
66
157
  url?: string;
67
158
  diagnostics: unknown[];
159
+ compileCache?: CompileCacheInfo;
68
160
  }
69
161
 
70
162
  export interface CompileResult {
@@ -91,6 +183,23 @@ export interface ClearRuntimeOptions {
91
183
  preserveHostModules?: boolean;
92
184
  }
93
185
 
186
+ export interface InvalidateOptions {
187
+ dependents?: boolean;
188
+ /** Force only the requested source module to compile fresh on its next link. */
189
+ compile?: boolean;
190
+ }
191
+
192
+ export interface RuntimeCompileCache {
193
+ readonly enabled: boolean;
194
+ readonly namespace?: string;
195
+ readonly version?: string;
196
+ readonly store?: string;
197
+ /** Delete the current module's stored compiler artifact without graph invalidation. */
198
+ invalidate(id: string): Promise<boolean>;
199
+ /** Clear current namespace/version, or all versions within the current namespace. */
200
+ clear(options?: { allVersions?: boolean }): Promise<number>;
201
+ }
202
+
94
203
  export type ModuleResolutionKind =
95
204
  | "custom"
96
205
  | "registered"
@@ -113,28 +222,57 @@ export interface LinkedDependency {
113
222
  resolvedId: string;
114
223
  }
115
224
 
225
+ export type CompileCacheErrorOperation =
226
+ | "identity"
227
+ | "fingerprint"
228
+ | "read"
229
+ | "write"
230
+ | "delete"
231
+ | "clear"
232
+ | "prune";
233
+
234
+ interface RuntimeEventBase {
235
+ runtimeId: string;
236
+ timestamp: number;
237
+ }
238
+
239
+ interface CompileCacheEventBase extends RuntimeEventBase {
240
+ id?: string;
241
+ key?: string;
242
+ store?: string;
243
+ source?: string;
244
+ durationMs?: number;
245
+ byteSize?: number;
246
+ }
247
+
116
248
  export type RuntimeLifecycleEvent =
117
- | { runtimeId: string; timestamp: number; type: "module-defined"; id: string; kind: ModuleInfo["kind"]; version: number; operation: "define" | "defineMany" | "update" | "defineModule" | "defineUrl"; replaced: boolean; module: ModuleInfo }
118
- | { runtimeId: string; timestamp: number; type: "module-updated"; id: string; kind: ModuleInfo["kind"]; previousVersion: number; version: number; format?: ModuleFormat; module: ModuleInfo }
119
- | { runtimeId: string; timestamp: number; type: "modules-defined"; ids: string[]; modules: ModuleInfo[] }
120
- | { runtimeId: string; timestamp: number; type: "module-resolving"; specifier: string; importer: string | null }
121
- | { runtimeId: string; timestamp: number; type: "module-resolved"; specifier: string; importer: string | null; resolvedId: string; resolutionKind: ModuleResolutionKind }
122
- | { runtimeId: string; timestamp: number; type: "module-linking"; id: string; kind: ModuleInfo["kind"]; version: number }
123
- | { runtimeId: string; timestamp: number; type: "module-linked"; id: string; kind: ModuleInfo["kind"]; version: number; dependencies: LinkedDependency[]; module: ModuleInfo }
124
- | { runtimeId: string; timestamp: number; type: "module-invalidated"; id: string; kind: ModuleInfo["kind"]; version: number; reason: string }
125
- | { runtimeId: string; timestamp: number; type: "module-compiled"; id: string; kind: ModuleInfo["kind"]; version: number; module: ModuleInfo }
126
- | { runtimeId: string; timestamp: number; type: "module-evaluating"; id: string; kind: ModuleInfo["kind"]; version: number }
127
- | { runtimeId: string; timestamp: number; type: "module-evaluated"; id: string; kind: ModuleInfo["kind"]; version: number; module: ModuleInfo }
128
- | { runtimeId: string; timestamp: number; type: "module-removed"; id: string; kind: ModuleInfo["kind"]; version: number; invalidateDependents: boolean }
129
- | { runtimeId: string; timestamp: number; type: "module-error"; id?: string; kind?: ModuleInfo["kind"]; version?: number; phase: ModuleErrorPhase; error: unknown }
130
- | { runtimeId: string; timestamp: number; type: "runtime-cleared"; ids: string[]; preserveHostModules: boolean }
131
- | { runtimeId: string; timestamp: number; type: "runtime-disposed" };
249
+ | (RuntimeEventBase & { type: "module-defined"; id: string; kind: ModuleInfo["kind"]; version: number; operation: "define" | "defineMany" | "update" | "defineModule" | "defineUrl"; replaced: boolean; module: ModuleInfo })
250
+ | (RuntimeEventBase & { type: "module-updated"; id: string; kind: ModuleInfo["kind"]; previousVersion: number; version: number; format?: ModuleFormat; module: ModuleInfo })
251
+ | (RuntimeEventBase & { type: "modules-defined"; ids: string[]; modules: ModuleInfo[] })
252
+ | (RuntimeEventBase & { type: "module-resolving"; specifier: string; importer: string | null })
253
+ | (RuntimeEventBase & { type: "module-resolved"; specifier: string; importer: string | null; resolvedId: string; resolutionKind: ModuleResolutionKind })
254
+ | (RuntimeEventBase & { type: "module-linking"; id: string; kind: ModuleInfo["kind"]; version: number })
255
+ | (RuntimeEventBase & { type: "module-linked"; id: string; kind: ModuleInfo["kind"]; version: number; dependencies: LinkedDependency[]; module: ModuleInfo })
256
+ | (RuntimeEventBase & { type: "module-invalidated"; id: string; kind: ModuleInfo["kind"]; version: number; reason: string })
257
+ | (RuntimeEventBase & { type: "module-compiled"; id: string; kind: ModuleInfo["kind"]; version: number; module: ModuleInfo })
258
+ | (RuntimeEventBase & { type: "module-evaluating"; id: string; kind: ModuleInfo["kind"]; version: number })
259
+ | (RuntimeEventBase & { type: "module-evaluated"; id: string; kind: ModuleInfo["kind"]; version: number; module: ModuleInfo })
260
+ | (RuntimeEventBase & { type: "module-removed"; id: string; kind: ModuleInfo["kind"]; version: number; invalidateDependents: boolean })
261
+ | (RuntimeEventBase & { type: "module-error"; id?: string; kind?: ModuleInfo["kind"]; version?: number; phase: ModuleErrorPhase; error: unknown })
262
+ | (RuntimeEventBase & { type: "runtime-cleared"; ids: string[]; preserveHostModules: boolean })
263
+ | (RuntimeEventBase & { type: "runtime-disposed" })
264
+ | (CompileCacheEventBase & { type: "compile-cache-hit" })
265
+ | (CompileCacheEventBase & { type: "compile-cache-miss" })
266
+ | (CompileCacheEventBase & { type: "compile-cache-write" })
267
+ | (CompileCacheEventBase & { type: "compile-cache-refresh" })
268
+ | (CompileCacheEventBase & { type: "compile-cache-bypass"; reason?: "requested" | "missing-compiler-fingerprint" | string })
269
+ | (CompileCacheEventBase & { type: "compile-cache-evict"; reason: "maxAge" | "maxEntries" | "maxBytes" | "invalid" | string })
270
+ | (CompileCacheEventBase & { type: "compile-cache-error"; operation: CompileCacheErrorOperation | string; error: unknown });
132
271
 
133
272
  export type RuntimeLifecycleEventType = RuntimeLifecycleEvent["type"];
134
273
  export type RuntimeLifecycleEventOfType<T extends RuntimeLifecycleEventType> =
135
274
  Extract<RuntimeLifecycleEvent, { type: T }>;
136
275
 
137
-
138
276
  export interface SolidTagRuntime {
139
277
  define(id: string, source: string, options?: DefineOptions): string;
140
278
  defineMany(definitions: SourceModuleDefinition[]): string[];
@@ -142,13 +280,15 @@ export interface SolidTagRuntime {
142
280
  defineModule(id: string, namespace: ModuleNamespaceLike | Function): string;
143
281
  defineUrl(id: string, url: string): string;
144
282
  import(id: string): Promise<ModuleNamespaceLike>;
145
- compile(id: string): Promise<CompileResult>;
283
+ /** Returns the current linked/executable representation; cache controls affect compiler artifact lookup only. */
284
+ compile(id: string, options?: CompileOptions): Promise<CompileResult>;
146
285
  toModule(source: string, options?: ToModuleOptions): Promise<ModuleNamespaceLike>;
147
286
  toComponent<T extends Function = Function>(source: string, options?: ToComponentOptions): Promise<T>;
148
287
  has(id: string): boolean;
149
- invalidate(id: string, options?: { dependents?: boolean }): string[];
288
+ invalidate(id: string, options?: InvalidateOptions): string[];
150
289
  remove(id: string, options?: RemoveModuleOptions): boolean;
151
290
  clear(options?: ClearRuntimeOptions): string[];
291
+ readonly compileCache: RuntimeCompileCache;
152
292
  subscribe(listener: (event: RuntimeLifecycleEvent) => void): () => boolean;
153
293
  subscribe<T extends RuntimeLifecycleEventType>(
154
294
  type: T,
@@ -173,6 +313,22 @@ export declare function createSolidTagCompiler(options?: {
173
313
  transformOptions?: Record<string, unknown>;
174
314
  }): RuntimeCompiler;
175
315
 
316
+ export declare function createMemoryCompileCache(options?: {
317
+ records?: Map<string, CachedCompileRecord>;
318
+ }): CompileCacheStore;
319
+
320
+ export declare function createLocalStorageCompileCache(options?: {
321
+ storage?: LocalStorageLike;
322
+ prefix?: string;
323
+ }): CompileCacheStore;
324
+
325
+ export declare function createIndexedDBCompileCache(options?: {
326
+ database?: string;
327
+ storeName?: string;
328
+ databaseVersion?: number;
329
+ indexedDB?: IndexedDBFactoryLike;
330
+ }): CompileCacheStore;
331
+
176
332
  export declare function createDefaultModuleUrlBackend(): ModuleUrlBackend;
177
333
  export declare function createBlobModuleUrlBackend(): ModuleUrlBackend;
178
334
  export declare function createDataModuleUrlBackend(): ModuleUrlBackend;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "solid-tag-runtime",
3
- "version": "0.0.12",
3
+ "version": "0.0.14",
4
4
  "description": "Runtime module system for JSX modules compiled with solid-tag and executed through @solidjs/html",
5
5
  "type": "module",
6
6
  "exports": {
@@ -23,6 +23,11 @@
23
23
  "types": "./html.d.ts",
24
24
  "import": "./src/html.js",
25
25
  "default": "./src/html.js"
26
+ },
27
+ "./solid": {
28
+ "types": "./solid.d.ts",
29
+ "import": "./src/solid/index.js",
30
+ "default": "./src/solid/index.js"
26
31
  }
27
32
  },
28
33
  "main": "./src/index.js",
@@ -32,12 +37,15 @@
32
37
  "src",
33
38
  "index.d.ts",
34
39
  "html.d.ts",
40
+ "solid.d.ts",
35
41
  "README.md",
36
- "ARCHITECTURE.md"
42
+ "ARCHITECTURE.md",
43
+ "docs",
44
+ "examples"
37
45
  ],
38
46
  "sideEffects": false,
39
47
  "dependencies": {
40
- "solid-tag": "^0.0.1"
48
+ "solid-tag": "0.0.1"
41
49
  },
42
50
  "scripts": {
43
51
  "test": "node ./test/run.mjs",
package/solid.d.ts ADDED
@@ -0,0 +1,77 @@
1
+ import type {
2
+ ModuleNamespaceLike,
3
+ RuntimeOptions,
4
+ SolidTagRuntime,
5
+ } from "./index.js";
6
+
7
+ export type SolidRuntimePackageName =
8
+ | "solid-js"
9
+ | "@solidjs/web"
10
+ | "@solidjs/html"
11
+ | "@solidjs/signals";
12
+
13
+ export type SolidModuleProviderId = "esm.sh" | "jsdelivr";
14
+ export type SolidModuleSource = "auto" | "host" | SolidModuleProviderId;
15
+
16
+ export interface SolidRuntimeModules {
17
+ "solid-js": ModuleNamespaceLike | Function;
18
+ "@solidjs/web": ModuleNamespaceLike | Function;
19
+ "@solidjs/html": ModuleNamespaceLike | Function;
20
+ "@solidjs/signals": ModuleNamespaceLike | Function;
21
+ }
22
+
23
+ export interface LoadSolidModulesOptions {
24
+ /** Resolution policy. `auto` prefers the existing host/page resolver first. */
25
+ source?: SolidModuleSource;
26
+ /** CDN used only when `auto` cannot complete the family through the host. */
27
+ fallbackProvider?: SolidModuleProviderId;
28
+ /** Version used for provider-generated URLs when no versioned Solid anchor exists. */
29
+ version?: string;
30
+ /** Already-resolved namespaces. Provided entries are never re-imported. */
31
+ modules?: Partial<SolidRuntimeModules>;
32
+ /** Explicit URL/specifier overrides. Exact values are preserved. */
33
+ specifiers?: Partial<Record<SolidRuntimePackageName, string>>;
34
+ /** Optional Document used for read-only import-map/provider inspection. */
35
+ document?: Document;
36
+ }
37
+
38
+ export interface CreateSolidRuntimeOptions extends Omit<RuntimeOptions, "modules"> {
39
+ /** Application/host modules. User entries override automatically loaded defaults. */
40
+ modules?: RuntimeOptions["modules"] & Partial<SolidRuntimeModules>;
41
+ /** Options for resolving the standard Solid package family. */
42
+ solid?: LoadSolidModulesOptions;
43
+ }
44
+
45
+ export interface SolidResolutionInspection {
46
+ pageMappings: Map<string, string>;
47
+ authoritativeMappings: Map<string, string>;
48
+ provider?: SolidModuleProviderId;
49
+ version?: string;
50
+ }
51
+
52
+ export declare class SolidModuleResolutionError extends Error {
53
+ provider?: string;
54
+ version?: string;
55
+ missing?: string[];
56
+ }
57
+
58
+ export declare const SOLID_RUNTIME_PACKAGES: readonly [
59
+ "solid-js",
60
+ "@solidjs/web",
61
+ "@solidjs/html",
62
+ "@solidjs/signals",
63
+ ];
64
+
65
+ export declare const TESTED_SOLID_VERSION: string;
66
+
67
+ export declare function loadSolidModules(
68
+ options?: LoadSolidModulesOptions,
69
+ ): Promise<SolidRuntimeModules>;
70
+
71
+ export declare function createSolidRuntime(
72
+ options?: CreateSolidRuntimeOptions,
73
+ ): Promise<SolidTagRuntime>;
74
+
75
+ export declare function inspectSolidResolution(
76
+ options?: Pick<LoadSolidModulesOptions, "specifiers" | "document">,
77
+ ): SolidResolutionInspection;