vite-plugin-solid-oxc 0.1.0-alpha.5 → 0.1.0-alpha.8
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/dist/index.js +25 -123
- package/package.json +7 -7
- package/dist/index.d.mts +0 -70
- package/dist/index.mjs +0 -168
package/dist/index.js
CHANGED
|
@@ -1,46 +1,5 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
|
|
30
1
|
// src/index.ts
|
|
31
|
-
|
|
32
|
-
__export(index_exports, {
|
|
33
|
-
default: () => solidOxc,
|
|
34
|
-
solidOxc: () => solidOxc
|
|
35
|
-
});
|
|
36
|
-
module.exports = __toCommonJS(index_exports);
|
|
37
|
-
var import_vite = require("vite");
|
|
38
|
-
var import_path = require("path");
|
|
39
|
-
var import_fs = require("fs");
|
|
40
|
-
var isVite6 = +import_vite.version.split(".")[0] >= 6;
|
|
41
|
-
var SOLID_PACKAGES_WITH_JSX = {
|
|
42
|
-
"solid-markdown": "dist/dev.js"
|
|
43
|
-
};
|
|
2
|
+
import { createFilter } from "vite";
|
|
44
3
|
var defaultOptions = {
|
|
45
4
|
include: /\.[jt]sx$/,
|
|
46
5
|
exclude: /node_modules/,
|
|
@@ -65,94 +24,23 @@ var defaultOptions = {
|
|
|
65
24
|
};
|
|
66
25
|
function solidOxc(options = {}) {
|
|
67
26
|
const opts = { ...defaultOptions, ...options };
|
|
68
|
-
const filter =
|
|
27
|
+
const filter = createFilter(opts.include, opts.exclude);
|
|
69
28
|
let isDev = false;
|
|
70
29
|
let isSSR = false;
|
|
71
|
-
let replaceDev = false;
|
|
72
30
|
let solidJsxOxc = null;
|
|
73
31
|
return {
|
|
74
32
|
name: "vite-plugin-solid-oxc",
|
|
75
33
|
enforce: "pre",
|
|
76
|
-
config(_userConfig, env) {
|
|
77
|
-
replaceDev = env.command === "serve";
|
|
78
|
-
const resolveConfig = {
|
|
79
|
-
dedupe: ["solid-js", "solid-js/web"]
|
|
80
|
-
};
|
|
81
|
-
if (!isVite6) {
|
|
82
|
-
resolveConfig.conditions = ["solid", ...replaceDev ? ["development"] : []];
|
|
83
|
-
}
|
|
84
|
-
return {
|
|
85
|
-
esbuild: {
|
|
86
|
-
// Let our plugin handle JSX, not esbuild
|
|
87
|
-
jsx: "preserve",
|
|
88
|
-
jsxImportSource: "solid-js"
|
|
89
|
-
},
|
|
90
|
-
resolve: resolveConfig
|
|
91
|
-
};
|
|
92
|
-
},
|
|
93
|
-
// @ts-ignore This hook only works in Vite 6+
|
|
94
|
-
async configEnvironment(name, config, env) {
|
|
95
|
-
if (!isVite6) {
|
|
96
|
-
return;
|
|
97
|
-
}
|
|
98
|
-
config.resolve ?? (config.resolve = {});
|
|
99
|
-
if (config.resolve.conditions == null) {
|
|
100
|
-
const { defaultClientConditions, defaultServerConditions } = await import("vite");
|
|
101
|
-
if (config.consumer === "client" || name === "client" || env.isSsrTargetWebworker) {
|
|
102
|
-
config.resolve.conditions = [...defaultClientConditions];
|
|
103
|
-
} else {
|
|
104
|
-
config.resolve.conditions = [...defaultServerConditions];
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
const extraConditions = ["solid", ...replaceDev ? ["development"] : []];
|
|
108
|
-
const currentConditions = config.resolve.conditions;
|
|
109
|
-
const prepend = [];
|
|
110
|
-
for (const condition of extraConditions) {
|
|
111
|
-
if (!currentConditions.includes(condition)) {
|
|
112
|
-
prepend.push(condition);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
config.resolve.conditions = [...prepend, ...currentConditions];
|
|
116
|
-
const dedupe = Array.isArray(config.resolve.dedupe) ? config.resolve.dedupe : [];
|
|
117
|
-
const nextDedupe = [...dedupe];
|
|
118
|
-
for (const pkg of ["solid-js", "solid-js/web"]) {
|
|
119
|
-
if (!nextDedupe.includes(pkg)) {
|
|
120
|
-
nextDedupe.push(pkg);
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
config.resolve.dedupe = nextDedupe;
|
|
124
|
-
},
|
|
125
34
|
configResolved(config) {
|
|
126
35
|
isDev = config.command === "serve";
|
|
127
36
|
isSSR = opts.ssr ?? (typeof config.build?.ssr === "boolean" ? config.build.ssr : !!config.build?.ssr);
|
|
128
37
|
},
|
|
129
|
-
resolveId(source, importer) {
|
|
130
|
-
const redirect = SOLID_PACKAGES_WITH_JSX[source];
|
|
131
|
-
if (redirect && importer && !importer.includes("node_modules/.vite")) {
|
|
132
|
-
try {
|
|
133
|
-
let dir = (0, import_path.dirname)(importer);
|
|
134
|
-
while (dir !== "/") {
|
|
135
|
-
const nmPath = (0, import_path.resolve)(dir, "node_modules", source, "package.json");
|
|
136
|
-
if ((0, import_fs.existsSync)(nmPath)) {
|
|
137
|
-
const pkgDir = (0, import_path.dirname)(nmPath);
|
|
138
|
-
const targetPath = (0, import_path.resolve)(pkgDir, redirect);
|
|
139
|
-
if ((0, import_fs.existsSync)(targetPath)) {
|
|
140
|
-
return targetPath;
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
dir = (0, import_path.dirname)(dir);
|
|
144
|
-
}
|
|
145
|
-
} catch {
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
return null;
|
|
149
|
-
},
|
|
150
38
|
async buildStart() {
|
|
151
39
|
try {
|
|
152
40
|
solidJsxOxc = await import("solid-jsx-oxc");
|
|
153
41
|
} catch (e) {
|
|
154
42
|
this.error(
|
|
155
|
-
"Failed to load solid-jsx-oxc. Make sure it is built for your platform
|
|
43
|
+
"Failed to load solid-jsx-oxc. Make sure it is built for your platform.\nRun: cd packages/solid-jsx-oxc && npm run build"
|
|
156
44
|
);
|
|
157
45
|
}
|
|
158
46
|
},
|
|
@@ -169,13 +57,13 @@ function solidOxc(options = {}) {
|
|
|
169
57
|
try {
|
|
170
58
|
const result = solidJsxOxc.transformJsx(code, {
|
|
171
59
|
filename: fileId,
|
|
172
|
-
|
|
60
|
+
moduleName: opts.module_name,
|
|
173
61
|
generate,
|
|
174
62
|
hydratable: opts.hydratable,
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
63
|
+
delegateEvents: opts.delegate_events,
|
|
64
|
+
wrapConditionals: opts.wrap_conditionals,
|
|
65
|
+
contextToCustomElements: opts.context_to_custom_elements,
|
|
66
|
+
sourceMap: true
|
|
179
67
|
});
|
|
180
68
|
if (isDev && opts.hot !== false) {
|
|
181
69
|
const hotCode = `
|
|
@@ -194,10 +82,24 @@ if (import.meta.hot) {
|
|
|
194
82
|
this.error(`Failed to transform ${id}: ${message}`);
|
|
195
83
|
return null;
|
|
196
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
|
+
};
|
|
197
99
|
}
|
|
198
100
|
};
|
|
199
101
|
}
|
|
200
|
-
|
|
201
|
-
|
|
102
|
+
export {
|
|
103
|
+
solidOxc as default,
|
|
202
104
|
solidOxc
|
|
203
|
-
}
|
|
105
|
+
};
|
package/package.json
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vite-plugin-solid-oxc",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.8",
|
|
4
4
|
"description": "Vite plugin for SolidJS using OXC-based compiler",
|
|
5
|
+
"type": "module",
|
|
5
6
|
"main": "dist/index.js",
|
|
6
|
-
"module": "dist/index.
|
|
7
|
+
"module": "dist/index.js",
|
|
7
8
|
"types": "dist/index.d.ts",
|
|
8
9
|
"exports": {
|
|
9
10
|
".": {
|
|
10
|
-
"
|
|
11
|
-
"
|
|
12
|
-
"types": "./dist/index.d.ts"
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js"
|
|
13
13
|
}
|
|
14
14
|
},
|
|
15
15
|
"files": [
|
|
16
16
|
"dist"
|
|
17
17
|
],
|
|
18
18
|
"scripts": {
|
|
19
|
-
"build": "tsup src/index.ts --format
|
|
20
|
-
"dev": "tsup src/index.ts --format
|
|
19
|
+
"build": "tsup src/index.ts --format esm --dts",
|
|
20
|
+
"dev": "tsup src/index.ts --format esm --dts --watch"
|
|
21
21
|
},
|
|
22
22
|
"keywords": [
|
|
23
23
|
"vite",
|
package/dist/index.d.mts
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
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.mjs
DELETED
|
@@ -1,168 +0,0 @@
|
|
|
1
|
-
// src/index.ts
|
|
2
|
-
import { createFilter, version } from "vite";
|
|
3
|
-
import { resolve, dirname } from "path";
|
|
4
|
-
import { existsSync } from "fs";
|
|
5
|
-
var isVite6 = +version.split(".")[0] >= 6;
|
|
6
|
-
var SOLID_PACKAGES_WITH_JSX = {
|
|
7
|
-
"solid-markdown": "dist/dev.js"
|
|
8
|
-
};
|
|
9
|
-
var defaultOptions = {
|
|
10
|
-
include: /\.[jt]sx$/,
|
|
11
|
-
exclude: /node_modules/,
|
|
12
|
-
module_name: "solid-js/web",
|
|
13
|
-
generate: "dom",
|
|
14
|
-
hydratable: false,
|
|
15
|
-
delegate_events: true,
|
|
16
|
-
wrap_conditionals: true,
|
|
17
|
-
context_to_custom_elements: true,
|
|
18
|
-
builtIns: [
|
|
19
|
-
"For",
|
|
20
|
-
"Show",
|
|
21
|
-
"Switch",
|
|
22
|
-
"Match",
|
|
23
|
-
"Suspense",
|
|
24
|
-
"SuspenseList",
|
|
25
|
-
"Portal",
|
|
26
|
-
"Index",
|
|
27
|
-
"Dynamic",
|
|
28
|
-
"ErrorBoundary"
|
|
29
|
-
]
|
|
30
|
-
};
|
|
31
|
-
function solidOxc(options = {}) {
|
|
32
|
-
const opts = { ...defaultOptions, ...options };
|
|
33
|
-
const filter = createFilter(opts.include, opts.exclude);
|
|
34
|
-
let isDev = false;
|
|
35
|
-
let isSSR = false;
|
|
36
|
-
let replaceDev = false;
|
|
37
|
-
let solidJsxOxc = null;
|
|
38
|
-
return {
|
|
39
|
-
name: "vite-plugin-solid-oxc",
|
|
40
|
-
enforce: "pre",
|
|
41
|
-
config(_userConfig, env) {
|
|
42
|
-
replaceDev = env.command === "serve";
|
|
43
|
-
const resolveConfig = {
|
|
44
|
-
dedupe: ["solid-js", "solid-js/web"]
|
|
45
|
-
};
|
|
46
|
-
if (!isVite6) {
|
|
47
|
-
resolveConfig.conditions = ["solid", ...replaceDev ? ["development"] : []];
|
|
48
|
-
}
|
|
49
|
-
return {
|
|
50
|
-
esbuild: {
|
|
51
|
-
// Let our plugin handle JSX, not esbuild
|
|
52
|
-
jsx: "preserve",
|
|
53
|
-
jsxImportSource: "solid-js"
|
|
54
|
-
},
|
|
55
|
-
resolve: resolveConfig
|
|
56
|
-
};
|
|
57
|
-
},
|
|
58
|
-
// @ts-ignore This hook only works in Vite 6+
|
|
59
|
-
async configEnvironment(name, config, env) {
|
|
60
|
-
if (!isVite6) {
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
config.resolve ?? (config.resolve = {});
|
|
64
|
-
if (config.resolve.conditions == null) {
|
|
65
|
-
const { defaultClientConditions, defaultServerConditions } = await import("vite");
|
|
66
|
-
if (config.consumer === "client" || name === "client" || env.isSsrTargetWebworker) {
|
|
67
|
-
config.resolve.conditions = [...defaultClientConditions];
|
|
68
|
-
} else {
|
|
69
|
-
config.resolve.conditions = [...defaultServerConditions];
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
const extraConditions = ["solid", ...replaceDev ? ["development"] : []];
|
|
73
|
-
const currentConditions = config.resolve.conditions;
|
|
74
|
-
const prepend = [];
|
|
75
|
-
for (const condition of extraConditions) {
|
|
76
|
-
if (!currentConditions.includes(condition)) {
|
|
77
|
-
prepend.push(condition);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
config.resolve.conditions = [...prepend, ...currentConditions];
|
|
81
|
-
const dedupe = Array.isArray(config.resolve.dedupe) ? config.resolve.dedupe : [];
|
|
82
|
-
const nextDedupe = [...dedupe];
|
|
83
|
-
for (const pkg of ["solid-js", "solid-js/web"]) {
|
|
84
|
-
if (!nextDedupe.includes(pkg)) {
|
|
85
|
-
nextDedupe.push(pkg);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
config.resolve.dedupe = nextDedupe;
|
|
89
|
-
},
|
|
90
|
-
configResolved(config) {
|
|
91
|
-
isDev = config.command === "serve";
|
|
92
|
-
isSSR = opts.ssr ?? (typeof config.build?.ssr === "boolean" ? config.build.ssr : !!config.build?.ssr);
|
|
93
|
-
},
|
|
94
|
-
resolveId(source, importer) {
|
|
95
|
-
const redirect = SOLID_PACKAGES_WITH_JSX[source];
|
|
96
|
-
if (redirect && importer && !importer.includes("node_modules/.vite")) {
|
|
97
|
-
try {
|
|
98
|
-
let dir = dirname(importer);
|
|
99
|
-
while (dir !== "/") {
|
|
100
|
-
const nmPath = resolve(dir, "node_modules", source, "package.json");
|
|
101
|
-
if (existsSync(nmPath)) {
|
|
102
|
-
const pkgDir = dirname(nmPath);
|
|
103
|
-
const targetPath = resolve(pkgDir, redirect);
|
|
104
|
-
if (existsSync(targetPath)) {
|
|
105
|
-
return targetPath;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
dir = dirname(dir);
|
|
109
|
-
}
|
|
110
|
-
} catch {
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
return null;
|
|
114
|
-
},
|
|
115
|
-
async buildStart() {
|
|
116
|
-
try {
|
|
117
|
-
solidJsxOxc = await import("solid-jsx-oxc");
|
|
118
|
-
} catch (e) {
|
|
119
|
-
this.error(
|
|
120
|
-
"Failed to load solid-jsx-oxc. Make sure it is built for your platform.\\nRun: cd packages/solid-jsx-oxc && npm run build"
|
|
121
|
-
);
|
|
122
|
-
}
|
|
123
|
-
},
|
|
124
|
-
async transform(code, id) {
|
|
125
|
-
const fileId = id.split("?", 1)[0];
|
|
126
|
-
if (!filter(fileId)) {
|
|
127
|
-
return null;
|
|
128
|
-
}
|
|
129
|
-
if (!solidJsxOxc) {
|
|
130
|
-
this.error("solid-jsx-oxc module not loaded");
|
|
131
|
-
return null;
|
|
132
|
-
}
|
|
133
|
-
const generate = isSSR ? "ssr" : opts.generate;
|
|
134
|
-
try {
|
|
135
|
-
const result = solidJsxOxc.transformJsx(code, {
|
|
136
|
-
filename: fileId,
|
|
137
|
-
module_name: opts.module_name,
|
|
138
|
-
generate,
|
|
139
|
-
hydratable: opts.hydratable,
|
|
140
|
-
delegate_events: opts.delegate_events,
|
|
141
|
-
wrap_conditionals: opts.wrap_conditionals,
|
|
142
|
-
context_to_custom_elements: opts.context_to_custom_elements,
|
|
143
|
-
source_map: true
|
|
144
|
-
});
|
|
145
|
-
if (isDev && opts.hot !== false) {
|
|
146
|
-
const hotCode = `
|
|
147
|
-
if (import.meta.hot) {
|
|
148
|
-
import.meta.hot.accept();
|
|
149
|
-
}
|
|
150
|
-
`;
|
|
151
|
-
result.code = result.code + hotCode;
|
|
152
|
-
}
|
|
153
|
-
return {
|
|
154
|
-
code: result.code,
|
|
155
|
-
map: result.map ? JSON.parse(result.map) : null
|
|
156
|
-
};
|
|
157
|
-
} catch (e) {
|
|
158
|
-
const message = e instanceof Error ? e.message : String(e);
|
|
159
|
-
this.error(`Failed to transform ${id}: ${message}`);
|
|
160
|
-
return null;
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
};
|
|
164
|
-
}
|
|
165
|
-
export {
|
|
166
|
-
solidOxc as default,
|
|
167
|
-
solidOxc
|
|
168
|
-
};
|