vite-plugin-solid-oxc 0.1.0-alpha.7 → 0.1.0-alpha.9

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.
@@ -0,0 +1,70 @@
1
+ import { FilterPattern, Plugin } from 'vite';
2
+ export { Plugin } from 'vite';
3
+
4
+ interface SolidOxcOptions {
5
+ /**
6
+ * Filter which files to transform
7
+ * @default /\.[jt]sx$/
8
+ */
9
+ include?: FilterPattern;
10
+ /**
11
+ * Filter which files to exclude
12
+ * @default /node_modules/
13
+ */
14
+ exclude?: FilterPattern;
15
+ /**
16
+ * The module to import runtime helpers from
17
+ * @default 'solid-js/web'
18
+ */
19
+ module_name?: string;
20
+ /**
21
+ * Generate mode
22
+ * @default 'dom'
23
+ */
24
+ generate?: 'dom' | 'ssr' | 'universal';
25
+ /**
26
+ * Enable hydration support
27
+ * @default false
28
+ */
29
+ hydratable?: boolean;
30
+ /**
31
+ * Delegate events for better performance
32
+ * @default true
33
+ */
34
+ delegate_events?: boolean;
35
+ /**
36
+ * Wrap conditionals in memos
37
+ * @default true
38
+ */
39
+ wrap_conditionals?: boolean;
40
+ /**
41
+ * Pass context to custom elements
42
+ * @default true
43
+ */
44
+ context_to_custom_elements?: boolean;
45
+ /**
46
+ * Built-in components that should be passed through
47
+ */
48
+ builtIns?: string[];
49
+ /**
50
+ * Enable SSR mode (shorthand for generate: 'ssr')
51
+ * @default false
52
+ */
53
+ ssr?: boolean;
54
+ /**
55
+ * Dev mode - enables additional debugging
56
+ * @default based on vite mode
57
+ */
58
+ dev?: boolean;
59
+ /**
60
+ * Hot module replacement
61
+ * @default true in dev mode
62
+ */
63
+ hot?: boolean;
64
+ }
65
+ /**
66
+ * Vite plugin for SolidJS using OXC-based compiler
67
+ */
68
+ declare function solidOxc(options?: SolidOxcOptions): Plugin;
69
+
70
+ export { type SolidOxcOptions, solidOxc as default, solidOxc };
package/dist/index.js ADDED
@@ -0,0 +1,105 @@
1
+ // src/index.ts
2
+ import { createFilter } from "vite";
3
+ var defaultOptions = {
4
+ include: /\.[jt]sx$/,
5
+ exclude: /node_modules/,
6
+ module_name: "solid-js/web",
7
+ generate: "dom",
8
+ hydratable: false,
9
+ delegate_events: true,
10
+ wrap_conditionals: true,
11
+ context_to_custom_elements: true,
12
+ builtIns: [
13
+ "For",
14
+ "Show",
15
+ "Switch",
16
+ "Match",
17
+ "Suspense",
18
+ "SuspenseList",
19
+ "Portal",
20
+ "Index",
21
+ "Dynamic",
22
+ "ErrorBoundary"
23
+ ]
24
+ };
25
+ function solidOxc(options = {}) {
26
+ const opts = { ...defaultOptions, ...options };
27
+ const filter = createFilter(opts.include, opts.exclude);
28
+ let isDev = false;
29
+ let isSSR = false;
30
+ let solidJsxOxc = null;
31
+ return {
32
+ name: "vite-plugin-solid-oxc",
33
+ enforce: "pre",
34
+ configResolved(config) {
35
+ isDev = config.command === "serve";
36
+ isSSR = opts.ssr ?? (typeof config.build?.ssr === "boolean" ? config.build.ssr : !!config.build?.ssr);
37
+ },
38
+ async buildStart() {
39
+ try {
40
+ solidJsxOxc = await import("solid-jsx-oxc");
41
+ } catch (e) {
42
+ this.error(
43
+ "Failed to load solid-jsx-oxc. Make sure it is built for your platform.\nRun: cd packages/solid-jsx-oxc && npm run build"
44
+ );
45
+ }
46
+ },
47
+ async transform(code, id) {
48
+ const fileId = id.split("?", 1)[0];
49
+ if (!filter(fileId)) {
50
+ return null;
51
+ }
52
+ if (!solidJsxOxc) {
53
+ this.error("solid-jsx-oxc module not loaded");
54
+ return null;
55
+ }
56
+ const generate = isSSR ? "ssr" : opts.generate;
57
+ try {
58
+ const result = solidJsxOxc.transformJsx(code, {
59
+ filename: fileId,
60
+ moduleName: opts.module_name,
61
+ generate,
62
+ hydratable: opts.hydratable,
63
+ delegateEvents: opts.delegate_events,
64
+ wrapConditionals: opts.wrap_conditionals,
65
+ contextToCustomElements: opts.context_to_custom_elements,
66
+ sourceMap: true
67
+ });
68
+ if (isDev && opts.hot !== false) {
69
+ const hotCode = `
70
+ if (import.meta.hot) {
71
+ import.meta.hot.accept();
72
+ }
73
+ `;
74
+ result.code = result.code + hotCode;
75
+ }
76
+ return {
77
+ code: result.code,
78
+ map: result.map ? JSON.parse(result.map) : null
79
+ };
80
+ } catch (e) {
81
+ const message = e instanceof Error ? e.message : String(e);
82
+ this.error(`Failed to transform ${id}: ${message}`);
83
+ return null;
84
+ }
85
+ },
86
+ // Handle Solid's JSX types
87
+ config() {
88
+ return {
89
+ esbuild: {
90
+ // Let our plugin handle JSX, not esbuild
91
+ jsx: "preserve",
92
+ jsxImportSource: "solid-js"
93
+ },
94
+ resolve: {
95
+ conditions: ["solid"],
96
+ dedupe: ["solid-js", "solid-js/web"]
97
+ }
98
+ };
99
+ }
100
+ };
101
+ }
102
+ export {
103
+ solidOxc as default,
104
+ solidOxc
105
+ };
package/package.json CHANGED
@@ -1,22 +1,23 @@
1
1
  {
2
2
  "name": "vite-plugin-solid-oxc",
3
- "version": "0.1.0-alpha.7",
3
+ "version": "0.1.0-alpha.9",
4
4
  "description": "Vite plugin for SolidJS using OXC-based compiler",
5
5
  "type": "module",
6
- "main": "dist/index.mjs",
7
- "types": "dist/index.d.mts",
6
+ "main": "dist/index.js",
7
+ "module": "dist/index.js",
8
+ "types": "dist/index.d.ts",
8
9
  "exports": {
9
10
  ".": {
10
- "types": "./dist/index.d.mts",
11
- "default": "./dist/index.mjs"
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.js"
12
13
  }
13
14
  },
14
15
  "files": [
15
16
  "dist"
16
17
  ],
17
18
  "scripts": {
18
- "build": "tsdown src/index.ts --format esm --dts",
19
- "dev": "tsdown src/index.ts --format esm --dts --watch"
19
+ "build": "tsup src/index.ts --format esm --dts",
20
+ "dev": "tsup src/index.ts --format esm --dts --watch"
20
21
  },
21
22
  "keywords": [
22
23
  "vite",
@@ -34,12 +35,9 @@
34
35
  "vite": "^5.0.0 || ^6.0.0 || ^7.0.0"
35
36
  },
36
37
  "devDependencies": {
37
- "@types/node": "^22.0.0",
38
- "tsdown": "^0.19.0",
39
- "typescript": "^5.9.0",
40
- "vite": "^7.0.0"
41
- },
42
- "engines": {
43
- "node": ">= 22"
38
+ "@types/node": "^20.0.0",
39
+ "tsup": "^8.5.1",
40
+ "typescript": "^5.0.0",
41
+ "vite": "^6.0.0"
44
42
  }
45
43
  }
package/dist/index.d.mts DELETED
@@ -1,77 +0,0 @@
1
- import { FilterPattern, Plugin } from "vite";
2
-
3
- //#region src/index.d.ts
4
- interface SolidOxcOptions {
5
- /**
6
- * Filter which files to transform
7
- * @default /\.[jt]sx$/
8
- */
9
- include?: FilterPattern;
10
- /**
11
- * Filter which files to exclude
12
- * @default /node_modules/
13
- */
14
- exclude?: FilterPattern;
15
- /**
16
- * The module to import runtime helpers from
17
- * @default 'solid-js/web'
18
- */
19
- module_name?: string;
20
- /**
21
- * Generate mode
22
- * @default 'dom'
23
- */
24
- generate?: 'dom' | 'ssr' | 'universal';
25
- /**
26
- * Enable hydration support
27
- * @default false
28
- */
29
- hydratable?: boolean;
30
- /**
31
- * Delegate events for better performance
32
- * @default true
33
- */
34
- delegate_events?: boolean;
35
- /**
36
- * Wrap conditionals in memos
37
- * @default true
38
- */
39
- wrap_conditionals?: boolean;
40
- /**
41
- * Pass context to custom elements
42
- * @default true
43
- */
44
- context_to_custom_elements?: boolean;
45
- /**
46
- * Built-in components that should be passed through
47
- */
48
- builtIns?: string[];
49
- /**
50
- * Enable SSR mode (shorthand for generate: 'ssr')
51
- * @default false
52
- */
53
- ssr?: boolean;
54
- /**
55
- * Dev mode - enables additional debugging
56
- * @default based on vite mode
57
- */
58
- dev?: boolean;
59
- /**
60
- * Hot module replacement
61
- * @default true in dev mode
62
- */
63
- hot?: boolean;
64
- /**
65
- * Redirect packages that ship JSX under "solid" condition to pre-compiled JS.
66
- * Keys are package names, values are paths relative to the package root.
67
- * Set to `false` to disable all redirects, or provide your own map.
68
- * @default { 'solid-markdown': 'dist/dev.js' }
69
- */
70
- jsxPackageRedirects?: Record<string, string> | false;
71
- }
72
- /**
73
- * Vite plugin for SolidJS using OXC-based compiler
74
- */
75
- declare function solidOxc(options?: SolidOxcOptions): Plugin;
76
- //#endregion
77
- export { type Plugin, SolidOxcOptions, solidOxc as default, solidOxc };
package/dist/index.mjs DELETED
@@ -1,170 +0,0 @@
1
- import { createFilter, version } from "vite";
2
- import { dirname, resolve } from "path";
3
- import { existsSync } from "fs";
4
-
5
- //#region src/index.ts
6
- const isVite6 = +version.split(".")[0] >= 6;
7
- /**
8
- * Default packages that ship JSX under "solid" condition but also have pre-compiled JS.
9
- * We redirect these to their pre-compiled versions to avoid needing to transform node_modules.
10
- */
11
- const DEFAULT_JSX_PACKAGE_REDIRECTS = {
12
- "solid-markdown": "dist/dev.js",
13
- "@corvu/resizable": "dist/index.js"
14
- };
15
- const defaultOptions = {
16
- include: /\.[jt]sx$/,
17
- exclude: /node_modules/,
18
- module_name: "solid-js/web",
19
- generate: "dom",
20
- hydratable: false,
21
- delegate_events: true,
22
- wrap_conditionals: true,
23
- context_to_custom_elements: true,
24
- builtIns: [...[
25
- "For",
26
- "Show",
27
- "Switch",
28
- "Match",
29
- "Suspense",
30
- "SuspenseList",
31
- "Portal",
32
- "Index",
33
- "Dynamic",
34
- "ErrorBoundary"
35
- ]]
36
- };
37
- /**
38
- * Vite plugin for SolidJS using OXC-based compiler
39
- */
40
- function solidOxc(options = {}) {
41
- const opts = {
42
- ...defaultOptions,
43
- ...options
44
- };
45
- const filter = createFilter(opts.include, opts.exclude);
46
- let isDev = false;
47
- let isSSR = false;
48
- let replaceDev = false;
49
- let viteRoot = process.cwd();
50
- const resolveRedirectTarget = (pkgName, redirectPath) => {
51
- let dir = viteRoot;
52
- while (true) {
53
- const pkgJsonPath = resolve(dir, "node_modules", pkgName, "package.json");
54
- if (existsSync(pkgJsonPath)) {
55
- const targetPath = resolve(dirname(pkgJsonPath), redirectPath);
56
- return existsSync(targetPath) ? targetPath : null;
57
- }
58
- const parentDir = dirname(dir);
59
- if (parentDir === dir) break;
60
- dir = parentDir;
61
- }
62
- return null;
63
- };
64
- const resolveCorvuRedirect = (source) => {
65
- if (!source.startsWith("@corvu/")) return null;
66
- const parts = source.split("/");
67
- if (parts.length < 2) return null;
68
- const pkgName = parts.slice(0, 2).join("/");
69
- const subpath = parts.slice(2).join("/");
70
- if (!subpath) return resolveRedirectTarget(pkgName, "dist/index.js");
71
- const candidates = [`dist/${subpath}/index.js`, `dist/${subpath}.js`];
72
- for (const candidate of candidates) {
73
- const targetPath = resolveRedirectTarget(pkgName, candidate);
74
- if (targetPath) return targetPath;
75
- }
76
- return null;
77
- };
78
- let solidJsxOxc = null;
79
- return {
80
- name: "vite-plugin-solid-oxc",
81
- enforce: "pre",
82
- config(_userConfig, env) {
83
- replaceDev = env.command === "serve";
84
- const resolveConfig = { dedupe: ["solid-js", "solid-js/web"] };
85
- if (!isVite6) resolveConfig.conditions = ["solid", ...replaceDev ? ["development"] : []];
86
- return {
87
- esbuild: {
88
- jsx: "preserve",
89
- jsxImportSource: "solid-js"
90
- },
91
- resolve: resolveConfig
92
- };
93
- },
94
- async configEnvironment(name, config, env) {
95
- if (!isVite6) return;
96
- config.resolve ??= {};
97
- if (config.resolve.conditions == null) {
98
- const { defaultClientConditions, defaultServerConditions } = await import("vite");
99
- const isClient = config.consumer === "client" || name === "client" || env.isSsrTargetWebworker;
100
- config.resolve.conditions = [...isClient ? defaultClientConditions : defaultServerConditions];
101
- }
102
- const missingConditions = ["solid", ...replaceDev ? ["development"] : []].filter((c) => !config.resolve.conditions.includes(c));
103
- config.resolve.conditions = [...missingConditions, ...config.resolve.conditions];
104
- const dedupe = Array.isArray(config.resolve.dedupe) ? config.resolve.dedupe : [];
105
- const packagesToDedupe = ["solid-js", "solid-js/web"].filter((pkg) => !dedupe.includes(pkg));
106
- config.resolve.dedupe = [...dedupe, ...packagesToDedupe];
107
- },
108
- configResolved(config) {
109
- isDev = config.command === "serve";
110
- isSSR = opts.ssr ?? (typeof config.build?.ssr === "boolean" ? config.build.ssr : !!config.build?.ssr);
111
- viteRoot = resolve(config.root);
112
- },
113
- resolveId(source, importer) {
114
- if (opts.jsxPackageRedirects === false) return null;
115
- const redirect = (opts.jsxPackageRedirects ?? DEFAULT_JSX_PACKAGE_REDIRECTS)[source];
116
- if (importer && importer.includes("node_modules/.vite")) return null;
117
- if (redirect) {
118
- const targetPath = resolveRedirectTarget(source, redirect);
119
- if (targetPath) return targetPath;
120
- }
121
- const corvuTarget = resolveCorvuRedirect(source);
122
- if (corvuTarget) return corvuTarget;
123
- return null;
124
- },
125
- async buildStart() {
126
- try {
127
- solidJsxOxc = await import("solid-jsx-oxc");
128
- } catch (e) {
129
- this.error("Failed to load solid-jsx-oxc. Make sure it is built for your platform.\\nRun: cd packages/solid-jsx-oxc && npm run build");
130
- }
131
- },
132
- async transform(code, id) {
133
- const fileId = id.split("?", 1)[0];
134
- if (!filter(fileId)) return null;
135
- if (!solidJsxOxc) {
136
- this.error("solid-jsx-oxc module not loaded");
137
- return null;
138
- }
139
- const generate = isSSR ? "ssr" : opts.generate;
140
- try {
141
- const result = solidJsxOxc.transformJsx(code, {
142
- filename: fileId,
143
- module_name: opts.module_name,
144
- generate,
145
- hydratable: opts.hydratable,
146
- delegate_events: opts.delegate_events,
147
- wrap_conditionals: opts.wrap_conditionals,
148
- context_to_custom_elements: opts.context_to_custom_elements,
149
- source_map: true
150
- });
151
- if (isDev && opts.hot !== false) result.code = result.code + `
152
- if (import.meta.hot) {
153
- import.meta.hot.accept();
154
- }
155
- `;
156
- return {
157
- code: result.code,
158
- map: result.map ? JSON.parse(result.map) : null
159
- };
160
- } catch (e) {
161
- const message = e instanceof Error ? e.message : String(e);
162
- this.error(`Failed to transform ${id}: ${message}`);
163
- return null;
164
- }
165
- }
166
- };
167
- }
168
-
169
- //#endregion
170
- export { solidOxc as default, solidOxc };