@solidnative-dev/compiler 0.0.0-stage → 0.1.0-beta.0
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 +19 -2
- package/index.d.ts +29 -0
- package/index.js +120 -0
- package/package.json +34 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Solid Native 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
CHANGED
|
@@ -1,3 +1,20 @@
|
|
|
1
|
-
#
|
|
1
|
+
# `@solidnative-dev/compiler`
|
|
2
2
|
|
|
3
|
-
This
|
|
3
|
+
This package is the single Solid-aware OXC compiler boundary used by Solid
|
|
4
|
+
Native build integrations. It pins `@solidjs/compiler`, targets the
|
|
5
|
+
universal renderer module, owns the shared built-in list, requests source maps,
|
|
6
|
+
and fails closed when either compiler cannot transform its input.
|
|
7
|
+
|
|
8
|
+
`transformSolidNativeJsx` leaves React Native-specific TypeScript, module,
|
|
9
|
+
platform, and Hermes lowering to Metro. `compileSolidNativeModule` additionally
|
|
10
|
+
uses `oxc-transform` to erase TypeScript and composes both source maps for a
|
|
11
|
+
standalone Babel-free build.
|
|
12
|
+
|
|
13
|
+
```js
|
|
14
|
+
import { compileSolidNativeModule } from "@solidnative-dev/compiler";
|
|
15
|
+
|
|
16
|
+
const result = compileSolidNativeModule(source, "/app/Counter.tsx");
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Plain `oxc-transform` is not a replacement for the Solid compiler: it does not
|
|
20
|
+
implement Solid's fine-grained JSX ownership and reactivity semantics.
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export interface SolidNativeSourceMap {
|
|
2
|
+
readonly version: number;
|
|
3
|
+
readonly sources: readonly string[];
|
|
4
|
+
readonly sourcesContent?: readonly (string | null)[];
|
|
5
|
+
readonly names: readonly string[];
|
|
6
|
+
readonly mappings: string;
|
|
7
|
+
file?: string;
|
|
8
|
+
readonly [key: string]: unknown;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface SolidNativeTransformResult {
|
|
12
|
+
readonly code: string;
|
|
13
|
+
readonly map: SolidNativeSourceMap;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export declare const SOLID_NATIVE_BUILT_INS: readonly string[];
|
|
17
|
+
export declare const solidNativeCompilerCacheKey: string;
|
|
18
|
+
|
|
19
|
+
/** Runs the Solid-aware OXC universal JSX transform without erasing TypeScript. */
|
|
20
|
+
export declare function transformSolidNativeJsx(
|
|
21
|
+
source: string,
|
|
22
|
+
filename: string,
|
|
23
|
+
): SolidNativeTransformResult;
|
|
24
|
+
|
|
25
|
+
/** Runs Solid universal compilation, OXC TypeScript erasure, and map composition. */
|
|
26
|
+
export declare function compileSolidNativeModule(
|
|
27
|
+
source: string,
|
|
28
|
+
filename: string,
|
|
29
|
+
): SolidNativeTransformResult;
|
package/index.js
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const crypto = require("node:crypto");
|
|
4
|
+
const fs = require("node:fs");
|
|
5
|
+
const path = require("node:path");
|
|
6
|
+
const { transform: transformSolid } = require("@solidjs/compiler");
|
|
7
|
+
const remapping = require("@jridgewell/remapping");
|
|
8
|
+
const { transformSync: transformOxc } = require("oxc-transform");
|
|
9
|
+
|
|
10
|
+
const SOLID_NATIVE_BUILT_INS = Object.freeze([
|
|
11
|
+
"For",
|
|
12
|
+
"Show",
|
|
13
|
+
"Switch",
|
|
14
|
+
"Match",
|
|
15
|
+
"Loading",
|
|
16
|
+
"Reveal",
|
|
17
|
+
"Portal",
|
|
18
|
+
"Repeat",
|
|
19
|
+
"Dynamic",
|
|
20
|
+
"Errored",
|
|
21
|
+
]);
|
|
22
|
+
|
|
23
|
+
function dependencyManifest(name) {
|
|
24
|
+
let directory = path.dirname(require.resolve(name));
|
|
25
|
+
for (;;) {
|
|
26
|
+
const manifest = path.join(directory, "package.json");
|
|
27
|
+
if (fs.existsSync(manifest)) return fs.readFileSync(manifest);
|
|
28
|
+
const parent = path.dirname(directory);
|
|
29
|
+
if (parent === directory) {
|
|
30
|
+
throw new Error(`Could not locate the package manifest for ${name}.`);
|
|
31
|
+
}
|
|
32
|
+
directory = parent;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const solidNativeCompilerCacheKey = crypto
|
|
37
|
+
.createHash("sha256")
|
|
38
|
+
.update(fs.readFileSync(__filename))
|
|
39
|
+
.update(dependencyManifest("@solidjs/compiler"))
|
|
40
|
+
.update(dependencyManifest("oxc-transform"))
|
|
41
|
+
.digest("hex");
|
|
42
|
+
|
|
43
|
+
function sourceText(value) {
|
|
44
|
+
if (typeof value !== "string") {
|
|
45
|
+
throw new TypeError("Solid Native compiler source must be a string.");
|
|
46
|
+
}
|
|
47
|
+
return value;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function sourceFilename(value) {
|
|
51
|
+
if (typeof value !== "string" || value.length === 0 || value.includes("\0")) {
|
|
52
|
+
throw new TypeError(
|
|
53
|
+
"Solid Native compiler filename must be a non-empty string without null bytes.",
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
return value;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function parseSourceMap(map, compiler) {
|
|
60
|
+
if (map === null || map === undefined) {
|
|
61
|
+
throw new Error(`${compiler} did not return the requested source map.`);
|
|
62
|
+
}
|
|
63
|
+
return typeof map === "string" ? JSON.parse(map) : map;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function assertTransformSucceeded(result, filename) {
|
|
67
|
+
const errors = result.errors ?? [];
|
|
68
|
+
if (errors.length === 0) return;
|
|
69
|
+
const details = errors
|
|
70
|
+
.map((error) => error.message ?? error.toString())
|
|
71
|
+
.join("\n");
|
|
72
|
+
throw new Error(`OXC could not transform ${filename}:\n${details}`);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function transformSolidNativeJsx(source, filename) {
|
|
76
|
+
const normalizedSource = sourceText(source);
|
|
77
|
+
const normalizedFilename = sourceFilename(filename);
|
|
78
|
+
const result = transformSolid(normalizedSource, {
|
|
79
|
+
filename: normalizedFilename,
|
|
80
|
+
moduleName: "@solidnative-dev/renderer",
|
|
81
|
+
generate: "universal",
|
|
82
|
+
builtIns: SOLID_NATIVE_BUILT_INS,
|
|
83
|
+
contextToCustomElements: true,
|
|
84
|
+
wrapConditionals: true,
|
|
85
|
+
sourceMap: true,
|
|
86
|
+
});
|
|
87
|
+
return Object.freeze({
|
|
88
|
+
code: result.code,
|
|
89
|
+
map: parseSourceMap(result.map, "@solidjs/compiler"),
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function compileSolidNativeModule(source, filename) {
|
|
94
|
+
const normalizedFilename = sourceFilename(filename);
|
|
95
|
+
const solid = transformSolidNativeJsx(source, normalizedFilename);
|
|
96
|
+
const javascript = transformOxc(normalizedFilename, solid.code, {
|
|
97
|
+
lang: normalizedFilename.endsWith("x") ? "tsx" : "ts",
|
|
98
|
+
sourceType: "module",
|
|
99
|
+
jsx: "preserve",
|
|
100
|
+
sourcemap: true,
|
|
101
|
+
target: "node22",
|
|
102
|
+
typescript: {
|
|
103
|
+
onlyRemoveTypeImports: true,
|
|
104
|
+
},
|
|
105
|
+
});
|
|
106
|
+
assertTransformSucceeded(javascript, normalizedFilename);
|
|
107
|
+
|
|
108
|
+
const map = remapping(
|
|
109
|
+
[parseSourceMap(javascript.map, "oxc-transform"), solid.map],
|
|
110
|
+
() => null,
|
|
111
|
+
);
|
|
112
|
+
return Object.freeze({ code: javascript.code, map });
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
module.exports = {
|
|
116
|
+
SOLID_NATIVE_BUILT_INS,
|
|
117
|
+
compileSolidNativeModule,
|
|
118
|
+
solidNativeCompilerCacheKey,
|
|
119
|
+
transformSolidNativeJsx,
|
|
120
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,37 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@solidnative-dev/compiler",
|
|
3
|
-
"version": "0.0.0
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.0-beta.0",
|
|
4
|
+
"description": "Shared OXC compiler pipeline for Solid Native universal JSX.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"homepage": "https://solidnative.dev",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/solid-native/solid-native.git",
|
|
10
|
+
"directory": "packages/compiler"
|
|
11
|
+
},
|
|
12
|
+
"publishConfig": {
|
|
13
|
+
"access": "public"
|
|
14
|
+
},
|
|
15
|
+
"engines": {
|
|
16
|
+
"node": "^22.13.0 || ^24.3.0 || >=26.0.0"
|
|
17
|
+
},
|
|
18
|
+
"exports": {
|
|
19
|
+
".": {
|
|
20
|
+
"types": "./index.d.ts",
|
|
21
|
+
"default": "./index.js"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"files": [
|
|
25
|
+
"index.d.ts",
|
|
26
|
+
"index.js"
|
|
27
|
+
],
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"@jridgewell/remapping": "2.3.5",
|
|
30
|
+
"@solidjs/compiler": "2.0.3",
|
|
31
|
+
"oxc-transform": "0.146.0"
|
|
32
|
+
},
|
|
33
|
+
"scripts": {
|
|
34
|
+
"check": "node --check index.js",
|
|
35
|
+
"test": "node --test test/*.test.mjs"
|
|
36
|
+
}
|
|
6
37
|
}
|