rolldown-plugin-dom-expressions-compiler 0.1.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 +152 -0
- package/dist/index.d.mts +20 -0
- package/dist/index.mjs +72 -0
- package/package.json +93 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 pekochan069
|
|
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,152 @@
|
|
|
1
|
+
# rolldown-plugin-dom-expressions-jsx-compiler
|
|
2
|
+
|
|
3
|
+
rolldown-plugin-dom-expressions-jsx-compiler is a plugin library for [Rolldown](https://rolldown.rs/) that transforms JSX and TSX into regular JavaScript.
|
|
4
|
+
|
|
5
|
+
This plugin uses [@dom-expressions/jsx-compiler](https://github.com/ryansolid/dom-expressions/tree/next/packages/jsx-compiler) under the hood, which is also used in [vite-plugin-solid](https://github.com/solidjs/vite-plugin-solid) when in `native` mode.
|
|
6
|
+
|
|
7
|
+
It exports two factories:
|
|
8
|
+
|
|
9
|
+
- `jsx` is renderer-agnostic and requires a `moduleName`.
|
|
10
|
+
- `solid` applies the Solid 2 defaults for `@solidjs/web`.
|
|
11
|
+
|
|
12
|
+
## How to use
|
|
13
|
+
|
|
14
|
+
### Install rolldown-plugin-dom-expressions-jsx-compiler
|
|
15
|
+
|
|
16
|
+
The first command installs the generic plugin. Install `solid-js` and `@solidjs/web` only when using `solid()`.
|
|
17
|
+
|
|
18
|
+
npm
|
|
19
|
+
|
|
20
|
+
```sh
|
|
21
|
+
npm install -D rolldown rolldown-plugin-dom-expressions-jsx-compiler
|
|
22
|
+
npm install solid-js@next @solidjs/web@next # When targeting Solid.js
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
yarn
|
|
26
|
+
|
|
27
|
+
```sh
|
|
28
|
+
yarn add -D rolldown rolldown-plugin-dom-expressions-jsx-compiler
|
|
29
|
+
yarn add solid-js@next @solidjs/web@next # When targeting Solid.js
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
pnpm
|
|
33
|
+
|
|
34
|
+
```sh
|
|
35
|
+
pnpm add -D rolldown rolldown-plugin-dom-expressions-jsx-compiler
|
|
36
|
+
pnpm add solid-js@next @solidjs/web@next # When targeting Solid.js
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
bun
|
|
40
|
+
|
|
41
|
+
```sh
|
|
42
|
+
bun add -D rolldown rolldown-plugin-dom-expressions-jsx-compiler
|
|
43
|
+
bun add solid-js@next @solidjs/web@next # When targeting Solid.js
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
deno
|
|
47
|
+
|
|
48
|
+
```sh
|
|
49
|
+
deno add --dev npm:rolldown npm:rolldown-plugin-dom-expressions-jsx-compiler
|
|
50
|
+
deno add npm:solid-js@next npm:@solidjs/web@next # When targeting Solid.js
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
vp
|
|
54
|
+
|
|
55
|
+
```sh
|
|
56
|
+
vp add -D rolldown rolldown-plugin-dom-expressions-jsx-compiler
|
|
57
|
+
vp add solid-js@next @solidjs/web@next # When targeting Solid.js
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
nub
|
|
61
|
+
|
|
62
|
+
```sh
|
|
63
|
+
nub add -D rolldown rolldown-plugin-dom-expressions-jsx-compiler
|
|
64
|
+
nub add solid-js@next @solidjs/web@next # When targeting Solid.js
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### Basic config for Solid.js
|
|
68
|
+
|
|
69
|
+
```ts
|
|
70
|
+
import { defineConfig } from "rolldown";
|
|
71
|
+
import { solid } from "rolldown-plugin-dom-expressions-jsx-compiler";
|
|
72
|
+
|
|
73
|
+
export default defineConfig({
|
|
74
|
+
input: "src/App.tsx",
|
|
75
|
+
plugins: [solid()],
|
|
76
|
+
output: { sourcemap: true },
|
|
77
|
+
});
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### Basic config for a custom renderer
|
|
81
|
+
|
|
82
|
+
```ts
|
|
83
|
+
import { defineConfig } from "rolldown";
|
|
84
|
+
import jsx from "rolldown-plugin-dom-expressions-jsx-compiler";
|
|
85
|
+
|
|
86
|
+
export default defineConfig({
|
|
87
|
+
input: "src/App.tsx",
|
|
88
|
+
plugins: [jsx({ jsx: { generate: "universal", moduleName: "my-renderer" } })],
|
|
89
|
+
output: { sourcemap: true },
|
|
90
|
+
});
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## API
|
|
94
|
+
|
|
95
|
+
```ts
|
|
96
|
+
jsx(options?: JsxPluginOptions)
|
|
97
|
+
solid(options?: JsxPluginOptions)
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
`JsxPluginOptions` supports `include`, `exclude`, and `jsx`. The `jsx` field accepts native compiler options except plugin-owned `filename` and `sourceMap`.
|
|
101
|
+
|
|
102
|
+
`solid()` applies its preset first, then shallowly applies `options.jsx`. Array options such as `builtIns` replace the preset array.
|
|
103
|
+
|
|
104
|
+
### Compiler modes
|
|
105
|
+
|
|
106
|
+
```ts
|
|
107
|
+
// Universal renderer
|
|
108
|
+
jsx({ jsx: { generate: "universal", moduleName: "my-renderer" } });
|
|
109
|
+
|
|
110
|
+
// SSR renderer
|
|
111
|
+
jsx({ jsx: { generate: "ssr", moduleName: "my-renderer/server" } });
|
|
112
|
+
|
|
113
|
+
// Dynamic renderer with selected DOM elements
|
|
114
|
+
jsx({
|
|
115
|
+
jsx: {
|
|
116
|
+
generate: "dynamic",
|
|
117
|
+
moduleName: "my-renderer",
|
|
118
|
+
renderers: [
|
|
119
|
+
{
|
|
120
|
+
name: "dom",
|
|
121
|
+
moduleName: "@solidjs/web",
|
|
122
|
+
elements: ["article", "button", "div"],
|
|
123
|
+
},
|
|
124
|
+
],
|
|
125
|
+
},
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
// Solid SSR
|
|
129
|
+
solid({ jsx: { generate: "ssr", hydratable: true } });
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
## Component integration tests
|
|
133
|
+
|
|
134
|
+
`packages/component-tests` is an independent consumer package. It imports the built plugin by package name and compiles real multi-file component graphs through Rolldown.
|
|
135
|
+
|
|
136
|
+
The suite covers Solid DOM, generic universal/SSR/dynamic modes, `@solidjs/universal` custom renderers, and `@solidjs/h` coexistence. It verifies generated imports, mode-specific output, TypeScript removal, and source maps without executing a renderer.
|
|
137
|
+
|
|
138
|
+
```sh
|
|
139
|
+
vp run --filter ./packages/component-tests check
|
|
140
|
+
vp run --filter ./packages/component-tests test
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
## Development
|
|
144
|
+
|
|
145
|
+
[vite plus](https://viteplus.dev/) and [bun](https://bun.sh/) are required.
|
|
146
|
+
|
|
147
|
+
```sh
|
|
148
|
+
vp install
|
|
149
|
+
vp run check
|
|
150
|
+
vp run test
|
|
151
|
+
vp run build
|
|
152
|
+
```
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { TransformOptions } from "@dom-expressions/compiler";
|
|
2
|
+
import { Plugin } from "rolldown";
|
|
3
|
+
|
|
4
|
+
//#region src/options.d.ts
|
|
5
|
+
type FilterPattern = string | RegExp | readonly (string | RegExp)[];
|
|
6
|
+
type CompilerOptions = Omit<TransformOptions, "filename" | "sourceMap">;
|
|
7
|
+
interface JsxPluginOptions {
|
|
8
|
+
/** Rolldown id patterns to transform. */
|
|
9
|
+
include?: FilterPattern;
|
|
10
|
+
/** Rolldown id patterns to skip. */
|
|
11
|
+
exclude?: FilterPattern;
|
|
12
|
+
/** Native DOM Expressions compiler options. */
|
|
13
|
+
jsx?: CompilerOptions;
|
|
14
|
+
}
|
|
15
|
+
//#endregion
|
|
16
|
+
//#region src/index.d.ts
|
|
17
|
+
declare function jsx(options?: JsxPluginOptions): Plugin;
|
|
18
|
+
declare function solid(options?: JsxPluginOptions): Plugin;
|
|
19
|
+
//#endregion
|
|
20
|
+
export { type CompilerOptions as JsxCompilerOptions, type JsxPluginOptions, jsx as default, jsx, solid };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { transformAsync } from "@dom-expressions/compiler";
|
|
2
|
+
import { makeIdFiltersToMatchWithQuery } from "rolldown/filter";
|
|
3
|
+
//#region src/constants.ts
|
|
4
|
+
const pluginName = "rolldown-plugin-dom-expressions-compiler";
|
|
5
|
+
const solidPreset = {
|
|
6
|
+
moduleName: "@solidjs/web",
|
|
7
|
+
builtIns: [
|
|
8
|
+
"For",
|
|
9
|
+
"Show",
|
|
10
|
+
"Switch",
|
|
11
|
+
"Match",
|
|
12
|
+
"Loading",
|
|
13
|
+
"Reveal",
|
|
14
|
+
"Portal",
|
|
15
|
+
"Repeat",
|
|
16
|
+
"Dynamic",
|
|
17
|
+
"Errored"
|
|
18
|
+
],
|
|
19
|
+
contextToCustomElements: true,
|
|
20
|
+
wrapConditionals: true,
|
|
21
|
+
generate: "dom",
|
|
22
|
+
hydratable: false,
|
|
23
|
+
dev: false
|
|
24
|
+
};
|
|
25
|
+
//#endregion
|
|
26
|
+
//#region src/index.ts
|
|
27
|
+
const defaultInclude = /\.[cm]?[jt]sx$/i;
|
|
28
|
+
function cleanUrl(id) {
|
|
29
|
+
return id.replace(/[?#].*$/, "");
|
|
30
|
+
}
|
|
31
|
+
function compilerFilename(id) {
|
|
32
|
+
return cleanUrl(id).replace(/\.mjsx$/i, ".jsx").replace(/\.cjsx$/i, ".jsx").replace(/\.mtsx$/i, ".tsx").replace(/\.ctsx$/i, ".tsx");
|
|
33
|
+
}
|
|
34
|
+
function createPlugin(options, preset = {}) {
|
|
35
|
+
return {
|
|
36
|
+
name: pluginName,
|
|
37
|
+
transform: {
|
|
38
|
+
filter: { id: {
|
|
39
|
+
include: makeIdFiltersToMatchWithQuery(options.include ?? defaultInclude),
|
|
40
|
+
exclude: options.exclude === void 0 ? void 0 : makeIdFiltersToMatchWithQuery(options.exclude)
|
|
41
|
+
} },
|
|
42
|
+
async handler(code, id) {
|
|
43
|
+
try {
|
|
44
|
+
const result = await transformAsync(code, {
|
|
45
|
+
...preset,
|
|
46
|
+
...options.jsx,
|
|
47
|
+
filename: compilerFilename(id),
|
|
48
|
+
sourceMap: true
|
|
49
|
+
});
|
|
50
|
+
return {
|
|
51
|
+
code: result.code,
|
|
52
|
+
map: result.map
|
|
53
|
+
};
|
|
54
|
+
} catch (error) {
|
|
55
|
+
this.error({
|
|
56
|
+
id,
|
|
57
|
+
message: `[${pluginName}] ${error instanceof Error ? error.message : String(error)}`,
|
|
58
|
+
pluginCode: "JSX_COMPILER"
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
function jsx(options = {}) {
|
|
66
|
+
return createPlugin(options);
|
|
67
|
+
}
|
|
68
|
+
function solid(options = {}) {
|
|
69
|
+
return createPlugin(options, solidPreset);
|
|
70
|
+
}
|
|
71
|
+
//#endregion
|
|
72
|
+
export { jsx as default, jsx, solid };
|
package/package.json
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "rolldown-plugin-dom-expressions-compiler",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Rolldown transform plugin for the native DOM Expressions compiler.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"dom-expressions",
|
|
7
|
+
"jsx",
|
|
8
|
+
"rolldown",
|
|
9
|
+
"rolldown-plugin",
|
|
10
|
+
"solid",
|
|
11
|
+
"solidjs"
|
|
12
|
+
],
|
|
13
|
+
"homepage": "https://github.com/pekochan069/rolldown-plugin-dom-expressions-compiler#readme",
|
|
14
|
+
"bugs": {
|
|
15
|
+
"url": "https://github.com/pekochan069/rolldown-plugin-dom-expressions-compiler/issues"
|
|
16
|
+
},
|
|
17
|
+
"license": "MIT",
|
|
18
|
+
"author": "pekochan069 <pekochan069@gmail.com>",
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "git+https://github.com/pekochan069/rolldown-plugin-dom-expressions-compiler.git"
|
|
22
|
+
},
|
|
23
|
+
"workspaces": [
|
|
24
|
+
"packages/*"
|
|
25
|
+
],
|
|
26
|
+
"files": [
|
|
27
|
+
"dist",
|
|
28
|
+
"README.md",
|
|
29
|
+
"LICENSE"
|
|
30
|
+
],
|
|
31
|
+
"type": "module",
|
|
32
|
+
"sideEffects": false,
|
|
33
|
+
"types": "./dist/index.d.mts",
|
|
34
|
+
"exports": {
|
|
35
|
+
".": {
|
|
36
|
+
"types": "./dist/index.d.mts",
|
|
37
|
+
"import": "./dist/index.mjs",
|
|
38
|
+
"default": "./dist/index.mjs"
|
|
39
|
+
},
|
|
40
|
+
"./package.json": "./package.json"
|
|
41
|
+
},
|
|
42
|
+
"publishConfig": {
|
|
43
|
+
"access": "public"
|
|
44
|
+
},
|
|
45
|
+
"scripts": {
|
|
46
|
+
"build": "vp pack",
|
|
47
|
+
"dev": "vp pack --watch",
|
|
48
|
+
"test": "vp test && vp run --filter ./packages/component-tests test",
|
|
49
|
+
"check": "vp check && vp run --filter ./packages/component-tests check",
|
|
50
|
+
"prepublishOnly": "vp run build",
|
|
51
|
+
"prepare": "vp config"
|
|
52
|
+
},
|
|
53
|
+
"dependencies": {
|
|
54
|
+
"@dom-expressions/compiler": ">=0.50.0-next.22"
|
|
55
|
+
},
|
|
56
|
+
"devDependencies": {
|
|
57
|
+
"@solidjs/web": "^2.0.0-beta.16",
|
|
58
|
+
"@types/node": "^26.1.1",
|
|
59
|
+
"bumpp": "^11.1.0",
|
|
60
|
+
"rolldown": "1",
|
|
61
|
+
"solid-js": "^2.0.0-beta.16",
|
|
62
|
+
"typescript": "^7",
|
|
63
|
+
"vite": "npm:@voidzero-dev/vite-plus-core@0.2.4",
|
|
64
|
+
"vite-plus": "^0.2.4"
|
|
65
|
+
},
|
|
66
|
+
"peerDependencies": {
|
|
67
|
+
"@solidjs/web": ">=2.0.0-beta.16",
|
|
68
|
+
"rolldown": "^1.0.0",
|
|
69
|
+
"solid-js": ">=2.0.0-beta.16"
|
|
70
|
+
},
|
|
71
|
+
"peerDependenciesMeta": {
|
|
72
|
+
"@solidjs/web": {
|
|
73
|
+
"optional": true
|
|
74
|
+
},
|
|
75
|
+
"solid-js": {
|
|
76
|
+
"optional": true
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
"overrides": {
|
|
80
|
+
"vite": "npm:@voidzero-dev/vite-plus-core@0.2.4"
|
|
81
|
+
},
|
|
82
|
+
"devEngines": {
|
|
83
|
+
"packageManager": {
|
|
84
|
+
"name": "bun",
|
|
85
|
+
"version": "1.3.14",
|
|
86
|
+
"onFail": "download"
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
"engines": {
|
|
90
|
+
"node": "^20.19.0 || >=22.12.0"
|
|
91
|
+
},
|
|
92
|
+
"packageManager": "bun@1.3.14"
|
|
93
|
+
}
|