bun-plugin-solid-oxc 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.
Files changed (3) hide show
  1. package/package.json +44 -0
  2. package/register.ts +18 -0
  3. package/src/index.ts +146 -0
package/package.json ADDED
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "bun-plugin-solid-oxc",
3
+ "version": "0.1.0",
4
+ "description": "Bun plugin for SolidJS using OXC-based compiler",
5
+ "main": "src/index.ts",
6
+ "module": "src/index.ts",
7
+ "types": "src/index.ts",
8
+ "exports": {
9
+ ".": {
10
+ "import": "./src/index.ts",
11
+ "require": "./src/index.ts",
12
+ "types": "./src/index.ts"
13
+ },
14
+ "./register": {
15
+ "import": "./register.ts",
16
+ "require": "./register.ts"
17
+ }
18
+ },
19
+ "files": [
20
+ "src",
21
+ "register.ts"
22
+ ],
23
+ "scripts": {
24
+ "typecheck": "bun x tsc --noEmit"
25
+ },
26
+ "keywords": [
27
+ "bun",
28
+ "bun-plugin",
29
+ "solid",
30
+ "solidjs",
31
+ "jsx",
32
+ "oxc"
33
+ ],
34
+ "author": "SolidJS Contributors",
35
+ "license": "MIT",
36
+ "peerDependencies": {
37
+ "solid-jsx-oxc": ">=0.1.0"
38
+ },
39
+ "devDependencies": {
40
+ "solid-jsx-oxc": "0.1.0-alpha.1",
41
+ "@types/bun": "latest",
42
+ "typescript": "^5.0.0"
43
+ }
44
+ }
package/register.ts ADDED
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Register the Solid OXC plugin for Bun runtime
3
+ *
4
+ * Usage in bunfig.toml:
5
+ * ```toml
6
+ * preload = ["bun-plugin-solid-oxc/register"]
7
+ * ```
8
+ *
9
+ * Or via CLI:
10
+ * ```bash
11
+ * bun --preload bun-plugin-solid-oxc/register ./src/index.tsx
12
+ * ```
13
+ */
14
+
15
+ import { plugin } from 'bun';
16
+ import solidOxc from './src/index';
17
+
18
+ plugin(solidOxc());
package/src/index.ts ADDED
@@ -0,0 +1,146 @@
1
+ /**
2
+ * Bun plugin for SolidJS using OXC-based compiler
3
+ *
4
+ * Since both Bun and this plugin use native code, this provides optimal performance.
5
+ *
6
+ * Usage with Bun.build():
7
+ * ```ts
8
+ * import solidPlugin from 'bun-plugin-solid-oxc';
9
+ *
10
+ * await Bun.build({
11
+ * entrypoints: ['./src/index.tsx'],
12
+ * outdir: './dist',
13
+ * plugins: [solidPlugin()],
14
+ * });
15
+ * ```
16
+ *
17
+ * Usage with bunfig.toml (runtime):
18
+ * ```toml
19
+ * [bunfig]
20
+ * preload = ["bun-plugin-solid-oxc/register"]
21
+ * ```
22
+ */
23
+
24
+ import type { BunPlugin } from 'bun';
25
+
26
+ export interface SolidOxcOptions {
27
+ /**
28
+ * Filter which files to transform (regex pattern)
29
+ * @default /\.[jt]sx$/
30
+ */
31
+ include?: RegExp;
32
+
33
+ /**
34
+ * Filter which files to exclude (regex pattern)
35
+ * @default /node_modules/
36
+ */
37
+ exclude?: RegExp;
38
+
39
+ /**
40
+ * The module to import runtime helpers from
41
+ * @default 'solid-js/web'
42
+ */
43
+ moduleName?: string;
44
+
45
+ /**
46
+ * Generate mode
47
+ * @default 'dom'
48
+ */
49
+ generate?: 'dom' | 'ssr' | 'universal';
50
+
51
+ /**
52
+ * Enable hydration support
53
+ * @default false
54
+ */
55
+ hydratable?: boolean;
56
+
57
+ /**
58
+ * Delegate events for better performance
59
+ * @default true
60
+ */
61
+ delegateEvents?: boolean;
62
+
63
+ /**
64
+ * Wrap conditionals in memos
65
+ * @default true
66
+ */
67
+ wrapConditionals?: boolean;
68
+
69
+ /**
70
+ * Pass context to custom elements
71
+ * @default true
72
+ */
73
+ contextToCustomElements?: boolean;
74
+
75
+ /**
76
+ * Enable SSR mode
77
+ * @default false
78
+ */
79
+ ssr?: boolean;
80
+ }
81
+
82
+ const defaultOptions: SolidOxcOptions = {
83
+ include: /\.[jt]sx$/,
84
+ exclude: /node_modules/,
85
+ moduleName: 'solid-js/web',
86
+ generate: 'dom',
87
+ hydratable: false,
88
+ delegateEvents: true,
89
+ wrapConditionals: true,
90
+ contextToCustomElements: true,
91
+ };
92
+
93
+ /**
94
+ * Bun plugin for SolidJS using OXC-based compiler
95
+ */
96
+ export default function solidOxc(options: SolidOxcOptions = {}): BunPlugin {
97
+ const opts = { ...defaultOptions, ...options };
98
+
99
+ return {
100
+ name: 'bun-plugin-solid-oxc',
101
+
102
+ async setup(build) {
103
+ // Load the native module once
104
+ const solidJsxOxc = await import('solid-jsx-oxc');
105
+
106
+ // Use Bun's onLoad hook with filter
107
+ build.onLoad({ filter: opts.include! }, async (args) => {
108
+ // Skip excluded files
109
+ if (opts.exclude?.test(args.path)) {
110
+ return undefined;
111
+ }
112
+
113
+ // Read the source file
114
+ const source = await Bun.file(args.path).text();
115
+
116
+ const generate = opts.ssr ? 'ssr' : opts.generate;
117
+
118
+ try {
119
+ const result = solidJsxOxc.transformJsx(source, {
120
+ filename: args.path,
121
+ moduleName: opts.moduleName,
122
+ generate,
123
+ hydratable: opts.hydratable,
124
+ delegateEvents: opts.delegateEvents,
125
+ wrapConditionals: opts.wrapConditionals,
126
+ contextToCustomElements: opts.contextToCustomElements,
127
+ sourceMap: false, // Bun handles source maps
128
+ });
129
+
130
+ // Return as 'ts' - JSX is transformed but TypeScript syntax remains
131
+ // Using 'ts' prevents Bun's JSX transform while handling TS syntax
132
+ return {
133
+ contents: result.code,
134
+ loader: 'ts',
135
+ };
136
+ } catch (e: unknown) {
137
+ const message = e instanceof Error ? e.message : String(e);
138
+ throw new Error(`Failed to transform ${args.path}: ${message}`);
139
+ }
140
+ });
141
+ },
142
+ };
143
+ }
144
+
145
+ // Named export for compatibility
146
+ export { solidOxc };