@effectweb/compiler 0.1.1
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/LICENSE +21 -0
- package/README.md +18 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/snapshotJsx.d.ts +20 -0
- package/dist/snapshotJsx.js +9 -0
- package/dist/vite.d.ts +4 -0
- package/dist/vite.js +27 -0
- package/native.cjs +23 -0
- package/native.d.cts +1 -0
- package/package.json +54 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 TeleVecha contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# @effectweb/compiler
|
|
2
|
+
|
|
3
|
+
Native Rust/Oxc compiler for EffectWeb snapshot JSX.
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
import { defineConfig } from 'vite';
|
|
7
|
+
import { snapshotCompiler } from '@effectweb/compiler/vite';
|
|
8
|
+
|
|
9
|
+
export default defineConfig({ plugins: [snapshotCompiler()] });
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
Install `effectweb` and its required Effect version in the application. Set TypeScript `jsx` to `preserve` and `jsxImportSource` to `effectweb`.
|
|
13
|
+
|
|
14
|
+
For direct compilation, import `compileSnapshot` from `@effectweb/compiler`; the result contains generated code, a source map, and diagnostics. The Vite plugin reports diagnostics and enables development instrumentation during serve.
|
|
15
|
+
|
|
16
|
+
Requires Node.js 22.14+. Optional packages provide binaries for glibc Linux x64/arm64, macOS x64/arm64, and Windows x64. Keep optional dependencies enabled. Installation does not compile Rust. Framework contributors build from source using Rust 1.96+.
|
|
17
|
+
|
|
18
|
+
See [EffectWeb](https://github.com/DerpyCrabs/EffectWeb) for authoring and development instructions.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { compileSnapshot, type SnapshotCompilerOptions, type SnapshotCompilerResult, type SnapshotDiagnostic, } from './snapshotJsx.js';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { compileSnapshot, } from './snapshotJsx.js';
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export interface SnapshotDiagnostic {
|
|
2
|
+
readonly file: string;
|
|
3
|
+
readonly line: number;
|
|
4
|
+
readonly column: number;
|
|
5
|
+
readonly message: string;
|
|
6
|
+
}
|
|
7
|
+
export interface SnapshotCompilerOptions {
|
|
8
|
+
/** An additional public module exporting view; relative imports ending in /mvu also work. */
|
|
9
|
+
importSource?: string;
|
|
10
|
+
runtimeModule?: string;
|
|
11
|
+
development?: boolean;
|
|
12
|
+
onDiagnostic?: (diagnostic: SnapshotDiagnostic) => void;
|
|
13
|
+
}
|
|
14
|
+
export interface SnapshotCompilerResult {
|
|
15
|
+
readonly code: string;
|
|
16
|
+
readonly map: string | null;
|
|
17
|
+
readonly diagnostics: readonly SnapshotDiagnostic[];
|
|
18
|
+
}
|
|
19
|
+
/** JSX analysis and lowering run in Rust/Oxc; this boundary only transports options and results. */
|
|
20
|
+
export declare function compileSnapshot(source: string, filename: string, options?: SnapshotCompilerOptions): SnapshotCompilerResult;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { compile } from '../native.cjs';
|
|
2
|
+
/** JSX analysis and lowering run in Rust/Oxc; this boundary only transports options and results. */
|
|
3
|
+
export function compileSnapshot(source, filename, options = {}) {
|
|
4
|
+
const { onDiagnostic, ...nativeOptions } = { importSource: 'effectweb', ...options };
|
|
5
|
+
const result = JSON.parse(compile(source, filename, JSON.stringify(nativeOptions)));
|
|
6
|
+
for (const diagnostic of result.diagnostics)
|
|
7
|
+
onDiagnostic?.(diagnostic);
|
|
8
|
+
return result;
|
|
9
|
+
}
|
package/dist/vite.d.ts
ADDED
package/dist/vite.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { compileSnapshot } from './snapshotJsx.js';
|
|
2
|
+
/** Rust/Oxc lowers snapshot JSX before Vite's TypeScript pass. */
|
|
3
|
+
export function snapshotCompiler(options = {}) {
|
|
4
|
+
let development = false;
|
|
5
|
+
return {
|
|
6
|
+
config() {
|
|
7
|
+
return { resolve: { dedupe: ['effect'] } };
|
|
8
|
+
},
|
|
9
|
+
configResolved(config) {
|
|
10
|
+
development = config.command === 'serve';
|
|
11
|
+
},
|
|
12
|
+
name: 'effectweb-jsx',
|
|
13
|
+
enforce: 'pre',
|
|
14
|
+
transform(code, id) {
|
|
15
|
+
const filename = id.split('?')[0];
|
|
16
|
+
if (!filename?.endsWith('.tsx'))
|
|
17
|
+
return;
|
|
18
|
+
const result = compileSnapshot(code, filename, {
|
|
19
|
+
...options,
|
|
20
|
+
development,
|
|
21
|
+
onDiagnostic: options.onDiagnostic ??
|
|
22
|
+
((diagnostic) => this.warn(`${diagnostic.file}:${diagnostic.line}:${diagnostic.column} ${diagnostic.message}`)),
|
|
23
|
+
});
|
|
24
|
+
return { code: result.code, map: result.map };
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
}
|
package/native.cjs
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
const { existsSync } = require('node:fs');
|
|
2
|
+
const { join } = require('node:path');
|
|
3
|
+
const { name } = require('./package.json');
|
|
4
|
+
const local = join(__dirname, 'native', 'snapshot-compiler.node');
|
|
5
|
+
let suffix;
|
|
6
|
+
if (existsSync(local)) suffix = 'local';
|
|
7
|
+
else if (process.platform === 'linux') {
|
|
8
|
+
if (!process.report.getReport().header.glibcVersionRuntime) {
|
|
9
|
+
throw new Error(`${name} currently supports glibc Linux. musl requires a source build.`);
|
|
10
|
+
}
|
|
11
|
+
suffix = `linux-${process.arch}-gnu`;
|
|
12
|
+
} else if (process.platform === 'darwin') suffix = `darwin-${process.arch}`;
|
|
13
|
+
else if (process.platform === 'win32') suffix = `win32-${process.arch}-msvc`;
|
|
14
|
+
else throw new Error(`${name}: unsupported platform ${process.platform}/${process.arch}`);
|
|
15
|
+
try {
|
|
16
|
+
const binding = existsSync(local) ? require(local) : require(`${name}-${suffix}`);
|
|
17
|
+
exports.compile = binding.compile;
|
|
18
|
+
} catch (error) {
|
|
19
|
+
throw new Error(
|
|
20
|
+
`Cannot load ${name} for ${suffix}. Install optional dependencies; framework contributors should run npm run build:compiler.`,
|
|
21
|
+
{ cause: error },
|
|
22
|
+
);
|
|
23
|
+
}
|
package/native.d.cts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export function compile(source: string, filename: string, options: string): string;
|
package/package.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@effectweb/compiler",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Native Oxc compiler and Vite plugin for effectweb",
|
|
5
|
+
"homepage": "https://github.com/DerpyCrabs/EffectWeb",
|
|
6
|
+
"bugs": {
|
|
7
|
+
"url": "https://github.com/DerpyCrabs/EffectWeb/issues"
|
|
8
|
+
},
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "git+https://github.com/DerpyCrabs/EffectWeb.git",
|
|
13
|
+
"directory": "packages/compiler"
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"native.cjs",
|
|
18
|
+
"native.d.cts",
|
|
19
|
+
"LICENSE",
|
|
20
|
+
"README.md"
|
|
21
|
+
],
|
|
22
|
+
"type": "module",
|
|
23
|
+
"exports": {
|
|
24
|
+
".": {
|
|
25
|
+
"types": "./dist/index.d.ts",
|
|
26
|
+
"import": "./dist/index.js"
|
|
27
|
+
},
|
|
28
|
+
"./vite": {
|
|
29
|
+
"types": "./dist/vite.d.ts",
|
|
30
|
+
"import": "./dist/vite.js"
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
"publishConfig": {
|
|
34
|
+
"access": "public"
|
|
35
|
+
},
|
|
36
|
+
"peerDependencies": {
|
|
37
|
+
"vite": "*"
|
|
38
|
+
},
|
|
39
|
+
"peerDependenciesMeta": {
|
|
40
|
+
"vite": {
|
|
41
|
+
"optional": true
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
"optionalDependencies": {
|
|
45
|
+
"@effectweb/compiler-darwin-arm64": "0.1.1",
|
|
46
|
+
"@effectweb/compiler-darwin-x64": "0.1.1",
|
|
47
|
+
"@effectweb/compiler-linux-arm64-gnu": "0.1.1",
|
|
48
|
+
"@effectweb/compiler-linux-x64-gnu": "0.1.1",
|
|
49
|
+
"@effectweb/compiler-win32-x64-msvc": "0.1.1"
|
|
50
|
+
},
|
|
51
|
+
"engines": {
|
|
52
|
+
"node": ">=22.14"
|
|
53
|
+
}
|
|
54
|
+
}
|