browser-runtime-octane 0.0.0-stage → 0.0.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/README.md +28 -2
- package/index.d.ts +1 -0
- package/package.json +39 -4
- package/src/index.d.ts +7 -0
- package/src/index.js +34 -0
package/README.md
CHANGED
|
@@ -1,3 +1,29 @@
|
|
|
1
|
-
#
|
|
1
|
+
# browser-runtime-octane
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Octane compiler and renderer plugin for [`browser-module-runtime`](https://www.npmjs.com/package/browser-module-runtime).
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
npm install browser-module-runtime@0.0.1 browser-runtime-octane@0.0.1 octane@0.2.3
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```js
|
|
14
|
+
import {createRuntime} from 'browser-module-runtime';
|
|
15
|
+
import {octane} from 'browser-runtime-octane';
|
|
16
|
+
|
|
17
|
+
const runtime = createRuntime({plugins:[octane({version:'0.2.3'})]});
|
|
18
|
+
runtime.define('/Counter.tsrx', `
|
|
19
|
+
import {useState} from 'octane';
|
|
20
|
+
export default function Counter() @{
|
|
21
|
+
const [count,setCount]=useState(0);
|
|
22
|
+
<button onClick={() => setCount(count+1)}>Count: {count}</button>
|
|
23
|
+
}
|
|
24
|
+
`, {type:'octane'});
|
|
25
|
+
const handle = await runtime.mount({module:'/Counter.tsrx',target:'#app'});
|
|
26
|
+
// Later: await handle.dispose(); await runtime.dispose();
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
`type="octane"` delegates JSX, TSX, and TSRX detection to Octane's browser compiler (`octane/compiler`). Rendering uses `octane.createRoot`; the returned mount handle owns cleanup. An exact Octane `version` contributes its package-root mapping so generated `octane/internal/*` imports resolve through the runtime linker.
|
package/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './src/index.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,41 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "browser-runtime-octane",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.0.2",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"exports": {
|
|
6
|
+
".": {
|
|
7
|
+
"types": "./index.d.ts",
|
|
8
|
+
"import": "./src/index.js"
|
|
9
|
+
}
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"src",
|
|
13
|
+
"index.d.ts",
|
|
14
|
+
"README.md"
|
|
15
|
+
],
|
|
16
|
+
"peerDependenciesMeta": {
|
|
17
|
+
"octane": {
|
|
18
|
+
"optional": true
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"engines": {
|
|
22
|
+
"node": ">=20"
|
|
23
|
+
},
|
|
24
|
+
"peerDependencies": {
|
|
25
|
+
"browser-module-runtime": "0.0.2",
|
|
26
|
+
"octane": "*"
|
|
27
|
+
},
|
|
28
|
+
"description": "Octane JSX, TSX, and TSRX compiler and renderer adapter for browser-module-runtime.",
|
|
29
|
+
"publishConfig": {
|
|
30
|
+
"access": "public"
|
|
31
|
+
},
|
|
32
|
+
"keywords": [
|
|
33
|
+
"browser",
|
|
34
|
+
"esm",
|
|
35
|
+
"runtime",
|
|
36
|
+
"modules",
|
|
37
|
+
"compiler",
|
|
38
|
+
"adapter",
|
|
39
|
+
"octane"
|
|
40
|
+
]
|
|
41
|
+
}
|
package/src/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type {RuntimePlugin} from 'browser-module-runtime';
|
|
2
|
+
export interface OctaneAdapterOptions {
|
|
3
|
+
compiler?: ((source:string,filename:string,options?:Record<string,unknown>)=>unknown)|{compile(source:string,filename:string,options?:Record<string,unknown>):unknown};
|
|
4
|
+
renderer?: {createRoot(target:Element):{render(component:unknown,props:Record<string,unknown>):unknown;unmount():unknown}};
|
|
5
|
+
version?:string;provider?:string;compilerOptions?:Record<string,unknown>;
|
|
6
|
+
}
|
|
7
|
+
export declare function octane(options?:OctaneAdapterOptions):RuntimePlugin;
|
package/src/index.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/** Official Octane browser compiler uses compile(source, filename, options).
|
|
2
|
+
* Compiled TSRX/TSX/JSX is owned by Octane, not by the generic runtime. */
|
|
3
|
+
export function octane({compiler,renderer,version='unverified',provider='esm.sh',compilerOptions={}}={}) {
|
|
4
|
+
let octaneRenderer=renderer;
|
|
5
|
+
let octaneCompiler=compiler;
|
|
6
|
+
let ownerRuntime;
|
|
7
|
+
const packageEntries=/^\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.-]+)?$/.test(String(version))
|
|
8
|
+
? {octane:{provider,version:String(version)}} : {};
|
|
9
|
+
return {
|
|
10
|
+
name:'octane',version:String(version),packageEntries,
|
|
11
|
+
configure({runtime}){ownerRuntime=runtime;},
|
|
12
|
+
compilers:[{
|
|
13
|
+
types:['octane'],extensions:['.tsrx','.tsx','.jsx'],
|
|
14
|
+
async compile(source,{id}) {
|
|
15
|
+
octaneCompiler ||= await (ownerRuntime ? ownerRuntime.import('octane/compiler') : import('octane/compiler'));
|
|
16
|
+
const invoke=typeof octaneCompiler==='function'?octaneCompiler:octaneCompiler.compile?.bind(octaneCompiler);
|
|
17
|
+
if(typeof invoke!=='function')throw new Error('octane/compiler must expose compile(source, filename, options)');
|
|
18
|
+
const result=await invoke(source,id,{mode:'client',...compilerOptions});
|
|
19
|
+
if(typeof result==='string')return {code:result};
|
|
20
|
+
if(!result||typeof result.code!=='string')throw new TypeError('Octane compiler must return a code string or {code, assets}.');
|
|
21
|
+
return result;
|
|
22
|
+
}
|
|
23
|
+
}],
|
|
24
|
+
renderers:[{
|
|
25
|
+
name:'octane',types:['octane'],
|
|
26
|
+
async mount({component,target,props}) {
|
|
27
|
+
octaneRenderer ||= await (ownerRuntime ? ownerRuntime.import('octane') : import('octane'));
|
|
28
|
+
const root=octaneRenderer.createRoot(target);
|
|
29
|
+
root.render(component,props);
|
|
30
|
+
return {dispose:()=>root.unmount()};
|
|
31
|
+
}
|
|
32
|
+
}]
|
|
33
|
+
};
|
|
34
|
+
}
|