@withl5e/l5e 0.2.2 → 0.2.3
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/entry-server.js +142 -10
- package/dist/entry-server.js.map +1 -1
- package/dist/index-BlfNBupp.js +318 -0
- package/dist/index-BlfNBupp.js.map +1 -0
- package/dist/index.js +31 -32
- package/dist/index.js.map +1 -1
- package/dist/middleware.js +3 -5
- package/dist/render-BF7iTagJ.js +202 -0
- package/dist/render-BF7iTagJ.js.map +1 -0
- package/dist/server.js +250 -244
- package/dist/server.js.map +1 -1
- package/dist/vite-plugin.js +97 -97
- package/dist/vite-plugin.js.map +1 -1
- package/package.json +4 -1
- package/src/core/entry-server.ts +16 -7
- package/src/core/index.ts +0 -2
- package/src/core/render.ts +36 -0
- package/src/core/request.ts +11 -10
- package/src/core/server.ts +23 -9
- package/src/core/vite-plugin.ts +13 -0
- package/src/middleware/index.ts +0 -48
- package/dist/entry-server-DJzzhCmz.js +0 -224
- package/dist/entry-server-DJzzhCmz.js.map +0 -1
- package/dist/index-BIt7MJT9.js +0 -163
- package/dist/index-BIt7MJT9.js.map +0 -1
package/dist/vite-plugin.js
CHANGED
|
@@ -1,41 +1,41 @@
|
|
|
1
1
|
import { transform as z } from "esbuild";
|
|
2
|
-
import { existsSync as w, mkdirSync as
|
|
3
|
-
import { join as b, relative as
|
|
4
|
-
const
|
|
5
|
-
function
|
|
2
|
+
import { existsSync as w, mkdirSync as U, writeFileSync as J, rmSync as D, statSync as C, readFileSync as T, readdirSync as N } from "fs";
|
|
3
|
+
import { join as b, relative as S, resolve as y, dirname as G } from "path";
|
|
4
|
+
const j = "virtual:l5e-views", v = "virtual:l5e-route", _ = "virtual:l5e-ssr-entry", E = "virtual:l5e-global-loader", R = "virtual:l5e-island-strategies", $ = "virtual:l5e-actions", P = "virtual:l5e-middleware", F = /* @__PURE__ */ new Set(["MODE", "BASE_URL", "PROD", "DEV", "SSR", "LEGACY"]);
|
|
5
|
+
function O(s, o = []) {
|
|
6
6
|
const l = N(s);
|
|
7
7
|
for (const i of l) {
|
|
8
8
|
const t = b(s, i);
|
|
9
|
-
if (
|
|
9
|
+
if (C(t).isDirectory()) {
|
|
10
10
|
if (i === "node_modules" || i === "dist" || i === ".git")
|
|
11
11
|
continue;
|
|
12
|
-
|
|
13
|
-
} else (i.endsWith(".tsx") || i.endsWith(".ts")) &&
|
|
12
|
+
O(t, o);
|
|
13
|
+
} else (i.endsWith(".tsx") || i.endsWith(".ts")) && o.push(t);
|
|
14
14
|
}
|
|
15
|
-
return
|
|
15
|
+
return o;
|
|
16
16
|
}
|
|
17
17
|
function I(s) {
|
|
18
|
-
let
|
|
18
|
+
let o = 0;
|
|
19
19
|
for (let l = 0; l < s.length; l++)
|
|
20
|
-
|
|
21
|
-
return Math.abs(
|
|
20
|
+
o = (o << 5) - o + s.charCodeAt(l), o = o & o;
|
|
21
|
+
return Math.abs(o).toString(16).slice(0, 4);
|
|
22
22
|
}
|
|
23
23
|
function k(s) {
|
|
24
|
-
const
|
|
25
|
-
let l =
|
|
24
|
+
const o = s.split("/");
|
|
25
|
+
let l = o[o.length - 1];
|
|
26
26
|
return l = l.replace(/\.(tsx?|jsx?)$/, ""), l;
|
|
27
27
|
}
|
|
28
|
-
function
|
|
28
|
+
function K(s) {
|
|
29
29
|
return `${k(s)}_${I(s)}`;
|
|
30
30
|
}
|
|
31
|
-
function H(s,
|
|
32
|
-
const l = s.replace(/^\//, ""), i = y(
|
|
31
|
+
function H(s, o) {
|
|
32
|
+
const l = s.replace(/^\//, ""), i = y(o, l);
|
|
33
33
|
for (const t of [".tsx", ".ts", ".jsx", ".js"])
|
|
34
34
|
if (w(i + t))
|
|
35
35
|
return l + t;
|
|
36
36
|
return w(i) ? l : null;
|
|
37
37
|
}
|
|
38
|
-
function
|
|
38
|
+
function B(s, o) {
|
|
39
39
|
const l = T(s, "utf-8"), i = [], t = /<ClientIsland\s[^>]*?from\s*=\s*"([^"]+)"/g, n = /* @__PURE__ */ new Set();
|
|
40
40
|
let c;
|
|
41
41
|
for (; (c = t.exec(l)) !== null; ) {
|
|
@@ -46,29 +46,29 @@ function D(s, r) {
|
|
|
46
46
|
else if (a.startsWith("/src/"))
|
|
47
47
|
e = a;
|
|
48
48
|
else if (a.startsWith("./") || a.startsWith("../")) {
|
|
49
|
-
const
|
|
50
|
-
e = "/" +
|
|
49
|
+
const r = y(s, "..", a);
|
|
50
|
+
e = "/" + S(o, r).replace(/\\/g, "/");
|
|
51
51
|
} else
|
|
52
52
|
e = a;
|
|
53
|
-
const d = H(e,
|
|
53
|
+
const d = H(e, o);
|
|
54
54
|
if (!d) {
|
|
55
55
|
console.warn(
|
|
56
56
|
`[l5e] Island component not found: ${e} (from ${a} in ${s})`
|
|
57
57
|
);
|
|
58
58
|
continue;
|
|
59
59
|
}
|
|
60
|
-
const
|
|
61
|
-
n.has(
|
|
60
|
+
const f = K(e);
|
|
61
|
+
n.has(f) || (n.add(f), i.push({
|
|
62
62
|
component: k(e),
|
|
63
63
|
resolvedPath: e,
|
|
64
64
|
src: d,
|
|
65
65
|
// "src/views/.../Counter.tsx" — matches manifest key format
|
|
66
|
-
key:
|
|
66
|
+
key: f
|
|
67
67
|
}));
|
|
68
68
|
}
|
|
69
69
|
return i;
|
|
70
70
|
}
|
|
71
|
-
function
|
|
71
|
+
function Y(s, o) {
|
|
72
72
|
const l = T(s, "utf-8"), i = [], t = [], n = /useCss\s*\(\s*['"]([^'"]+)['"]\s*,?\s*\)/g, c = /useClientJs\s*\(\s*['"]([^'"]+)['"]\s*,?\s*\)/g;
|
|
73
73
|
let a;
|
|
74
74
|
for (; (a = n.exec(l)) !== null; ) {
|
|
@@ -76,8 +76,8 @@ function B(s, r) {
|
|
|
76
76
|
if (e.startsWith("/src/"))
|
|
77
77
|
i.push(e);
|
|
78
78
|
else if (e.startsWith("./") || e.startsWith("../")) {
|
|
79
|
-
const d = y(s, "..", e),
|
|
80
|
-
i.push(
|
|
79
|
+
const d = y(s, "..", e), f = "/" + S(o, d).replace(/\\/g, "/");
|
|
80
|
+
i.push(f);
|
|
81
81
|
} else
|
|
82
82
|
i.push(e);
|
|
83
83
|
}
|
|
@@ -86,96 +86,96 @@ function B(s, r) {
|
|
|
86
86
|
if (e.startsWith("/src/"))
|
|
87
87
|
t.push(e);
|
|
88
88
|
else if (e.startsWith("./") || e.startsWith("../")) {
|
|
89
|
-
const d = y(s, "..", e),
|
|
90
|
-
t.push(
|
|
89
|
+
const d = y(s, "..", e), f = "/" + S(o, d).replace(/\\/g, "/");
|
|
90
|
+
t.push(f);
|
|
91
91
|
} else
|
|
92
92
|
t.push(e);
|
|
93
93
|
}
|
|
94
94
|
return { css: i, js: t };
|
|
95
95
|
}
|
|
96
|
-
function
|
|
97
|
-
const
|
|
96
|
+
function L(s) {
|
|
97
|
+
const o = {}, l = b(s, "src"), i = /* @__PURE__ */ new Map(), t = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Map(), c = /* @__PURE__ */ new Map();
|
|
98
98
|
try {
|
|
99
|
-
if (!
|
|
100
|
-
return { input:
|
|
99
|
+
if (!C(l).isDirectory())
|
|
100
|
+
return { input: o, islandRegistry: i, pathToKey: t, keyToSrc: n, actionRegistry: c };
|
|
101
101
|
const a = b(s, "src", "client.global.ts");
|
|
102
|
-
w(a) && (
|
|
103
|
-
const e =
|
|
104
|
-
for (const
|
|
105
|
-
const { css: u, js:
|
|
106
|
-
u.forEach((p) => d.add(p)),
|
|
107
|
-
const m =
|
|
102
|
+
w(a) && (o.global = a, console.log("[l5e] Detected src/client.global.ts and added as entry"));
|
|
103
|
+
const e = O(l), d = /* @__PURE__ */ new Set(), f = /* @__PURE__ */ new Set();
|
|
104
|
+
for (const r of e) {
|
|
105
|
+
const { css: u, js: h } = Y(r, s);
|
|
106
|
+
u.forEach((p) => d.add(p)), h.forEach((p) => f.add(p));
|
|
107
|
+
const m = B(r, s);
|
|
108
108
|
for (const p of m)
|
|
109
109
|
i.set(p.key, p.resolvedPath), t.set(p.resolvedPath, p.key), n.set(p.key, p.src);
|
|
110
|
-
const g =
|
|
110
|
+
const g = r.replace(/\\/g, "/");
|
|
111
111
|
if (/\/actions\.(ts|tsx)$/.test(g)) {
|
|
112
|
-
const p = T(
|
|
112
|
+
const p = T(r, "utf-8"), x = /export\s+const\s+(\w+)\s*=\s*defineAction\s*\(/g;
|
|
113
113
|
let W;
|
|
114
|
-
const A =
|
|
114
|
+
const A = S(l, G(r)).replace(/\\/g, "/") || ".";
|
|
115
115
|
for (; (W = x.exec(p)) !== null; ) {
|
|
116
|
-
const
|
|
117
|
-
c.set(
|
|
116
|
+
const M = W[1], V = `${M}_${I(A)}`;
|
|
117
|
+
c.set(V, { modulePath: A, actionName: M });
|
|
118
118
|
}
|
|
119
119
|
}
|
|
120
120
|
}
|
|
121
|
-
for (const
|
|
122
|
-
const u =
|
|
123
|
-
if (!w(
|
|
124
|
-
console.warn(`[l5e] CSS file not found: ${
|
|
121
|
+
for (const r of d) {
|
|
122
|
+
const u = r.startsWith("/src/") || r.startsWith("/") ? r.substring(1) : r, h = y(s, u);
|
|
123
|
+
if (!w(h)) {
|
|
124
|
+
console.warn(`[l5e] CSS file not found: ${h} (from ${r})`);
|
|
125
125
|
continue;
|
|
126
126
|
}
|
|
127
127
|
const m = u.replace(/^src\//, "").replace(/\.css$/, "").replace(/\//g, "-").replace(/\\/g, "-");
|
|
128
|
-
|
|
128
|
+
o[m] = h;
|
|
129
129
|
}
|
|
130
|
-
for (const
|
|
131
|
-
const u =
|
|
132
|
-
if (!w(
|
|
133
|
-
console.warn(`[l5e] JS/TS file not found: ${
|
|
130
|
+
for (const r of f) {
|
|
131
|
+
const u = r.startsWith("/src/") || r.startsWith("/") ? r.substring(1) : r, h = y(s, u);
|
|
132
|
+
if (!w(h)) {
|
|
133
|
+
console.warn(`[l5e] JS/TS file not found: ${h} (from ${r})`);
|
|
134
134
|
continue;
|
|
135
135
|
}
|
|
136
136
|
const m = u.replace(/^src\//, "").replace(/\.(ts|tsx|js|jsx)$/, "").replace(/\//g, "-").replace(/\\/g, "-");
|
|
137
|
-
|
|
137
|
+
o[m] = h;
|
|
138
138
|
}
|
|
139
|
-
for (const [
|
|
140
|
-
const
|
|
141
|
-
|
|
139
|
+
for (const [r, u] of n) {
|
|
140
|
+
const h = y(s, u);
|
|
141
|
+
o[`island-${r}`] = h;
|
|
142
142
|
}
|
|
143
143
|
i.size > 0 && console.log(`[l5e] Detected ${i.size} island(s)`), c.size > 0 && console.log(`[l5e] Detected ${c.size} action(s)`);
|
|
144
144
|
} catch (a) {
|
|
145
145
|
console.warn("[l5e] Failed to discover rollup input:", a);
|
|
146
146
|
}
|
|
147
|
-
return { input:
|
|
147
|
+
return { input: o, islandRegistry: i, pathToKey: t, keyToSrc: n, actionRegistry: c };
|
|
148
148
|
}
|
|
149
|
-
function Z(s,
|
|
149
|
+
function Z(s, o, l, i, t) {
|
|
150
150
|
const n = [];
|
|
151
151
|
let c = 0;
|
|
152
152
|
const a = /ClientIsland\s*,\s*\{/g;
|
|
153
153
|
let e;
|
|
154
154
|
for (; (e = a.exec(s)) !== null; ) {
|
|
155
|
-
const d = e.index + e[0].length,
|
|
156
|
-
if (!
|
|
157
|
-
const u =
|
|
158
|
-
let
|
|
155
|
+
const d = e.index + e[0].length, f = s.substring(d, d + 500), r = /from:\s*"([^"]+)"/.exec(f);
|
|
156
|
+
if (!r) continue;
|
|
157
|
+
const u = r[1];
|
|
158
|
+
let h;
|
|
159
159
|
if (u.startsWith("~/"))
|
|
160
|
-
|
|
160
|
+
h = "/src/" + u.substring(2);
|
|
161
161
|
else if (u.startsWith("/src/"))
|
|
162
|
-
|
|
162
|
+
h = u;
|
|
163
163
|
else if (u.startsWith("./") || u.startsWith("../")) {
|
|
164
|
-
const x = y(
|
|
165
|
-
|
|
164
|
+
const x = y(o, "..", u);
|
|
165
|
+
h = "/" + S(l, x).replace(/\\/g, "/");
|
|
166
166
|
} else
|
|
167
|
-
|
|
168
|
-
const m = i.get(
|
|
167
|
+
h = u;
|
|
168
|
+
const m = i.get(h);
|
|
169
169
|
if (!m) continue;
|
|
170
170
|
const g = t.get(m);
|
|
171
171
|
if (!g) continue;
|
|
172
|
-
const p = d +
|
|
172
|
+
const p = d + r.index + r[0].length;
|
|
173
173
|
n.push(s.substring(c, p)), n.push(`, __key: "${m}", __src: "${g}"`), c = p;
|
|
174
174
|
}
|
|
175
175
|
return n.push(s.substring(c)), n.join("");
|
|
176
176
|
}
|
|
177
|
-
function
|
|
178
|
-
let s = process.cwd(),
|
|
177
|
+
function et() {
|
|
178
|
+
let s = process.cwd(), o = /* @__PURE__ */ new Map(), l = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Map();
|
|
179
179
|
return {
|
|
180
180
|
name: "l5e-jsx-classic",
|
|
181
181
|
enforce: "pre",
|
|
@@ -183,10 +183,10 @@ function tt() {
|
|
|
183
183
|
s = t.root || process.cwd();
|
|
184
184
|
},
|
|
185
185
|
handleHotUpdate({ file: t, server: n }) {
|
|
186
|
-
const c =
|
|
186
|
+
const c = S(s, t);
|
|
187
187
|
if (/actions\.(ts|tsx)$/.test(t)) {
|
|
188
|
-
i =
|
|
189
|
-
const e = n.moduleGraph.getModuleById("\0" +
|
|
188
|
+
i = L(s).actionRegistry;
|
|
189
|
+
const e = n.moduleGraph.getModuleById("\0" + $);
|
|
190
190
|
e && n.moduleGraph.invalidateModule(e), console.log(
|
|
191
191
|
`[l5e] Action file changed: ${c} — re-scanned ${i.size} action(s)`
|
|
192
192
|
);
|
|
@@ -209,7 +209,7 @@ function tt() {
|
|
|
209
209
|
const t = b(s, ".l5e-temp");
|
|
210
210
|
if (w(t))
|
|
211
211
|
try {
|
|
212
|
-
|
|
212
|
+
D(t, { recursive: !0, force: !0 }), console.log("[l5e] Cleaned up temporary files");
|
|
213
213
|
} catch (n) {
|
|
214
214
|
console.warn("[l5e] Failed to cleanup temporary files:", n);
|
|
215
215
|
}
|
|
@@ -217,14 +217,14 @@ function tt() {
|
|
|
217
217
|
writeBundle(t, n) {
|
|
218
218
|
if (i.size > 0) {
|
|
219
219
|
const c = b(s, "dist", "server");
|
|
220
|
-
w(c) ||
|
|
220
|
+
w(c) || U(c, { recursive: !0 });
|
|
221
221
|
const a = Object.fromEntries(i);
|
|
222
|
-
|
|
222
|
+
J(b(c, "action-registry.json"), JSON.stringify(a), "utf-8"), console.log(`[l5e] Wrote action-registry.json (${i.size} actions)`);
|
|
223
223
|
}
|
|
224
224
|
},
|
|
225
225
|
config(t) {
|
|
226
|
-
const n = t.root || process.cwd(), c =
|
|
227
|
-
c.islandRegistry,
|
|
226
|
+
const n = t.root || process.cwd(), c = L(n);
|
|
227
|
+
c.islandRegistry, o = c.pathToKey, l = c.keyToSrc, i = c.actionRegistry;
|
|
228
228
|
const a = t.build?.rollupOptions?.input || {}, e = typeof a == "object" && !Array.isArray(a) ? { ...c.input, ...a } : c.input;
|
|
229
229
|
return {
|
|
230
230
|
build: {
|
|
@@ -241,7 +241,7 @@ function tt() {
|
|
|
241
241
|
};
|
|
242
242
|
},
|
|
243
243
|
resolveId(t) {
|
|
244
|
-
return t ===
|
|
244
|
+
return t === j ? "\0" + j : t === v ? "\0" + v : t === _ ? "\0" + _ : t === E ? "\0" + E : t === R ? "\0" + R : t === $ ? "\0" + $ : t === P ? "\0" + P : null;
|
|
245
245
|
},
|
|
246
246
|
async transform(t, n, c) {
|
|
247
247
|
if (n.replace(/\\/g, "/").endsWith("src/client.global.ts") && !c?.ssr)
|
|
@@ -253,16 +253,16 @@ ${t}`,
|
|
|
253
253
|
if (!c?.ssr) {
|
|
254
254
|
const d = n.replace(/\\/g, "/").match(/\/src\/(.+)\/actions\.(ts|tsx)$/);
|
|
255
255
|
if (d) {
|
|
256
|
-
const
|
|
257
|
-
let
|
|
258
|
-
for (; (
|
|
259
|
-
const m =
|
|
256
|
+
const f = d[1], r = /export\s+const\s+(\w+)\s*=\s*defineAction\s*\(/g, u = [];
|
|
257
|
+
let h;
|
|
258
|
+
for (; (h = r.exec(t)) !== null; ) {
|
|
259
|
+
const m = h[1], p = t.substring(h.index, h.index + 500).match(/method:\s*['"](\w+)['"]/), x = p ? p[1].toUpperCase() : "GET";
|
|
260
260
|
u.push({ name: m, method: x });
|
|
261
261
|
}
|
|
262
262
|
if (u.length > 0)
|
|
263
263
|
return {
|
|
264
264
|
code: u.map(({ name: g, method: p }) => {
|
|
265
|
-
const x = `${g}_${I(
|
|
265
|
+
const x = `${g}_${I(f)}`;
|
|
266
266
|
return p === "GET" ? `export async function ${g}(params) {
|
|
267
267
|
const res = await fetch('/_l5e/action/${x}?' + new URLSearchParams(params));
|
|
268
268
|
if (!res.ok) throw Object.assign(new Error('HTTP ' + res.status), { status: res.status });
|
|
@@ -297,9 +297,9 @@ ${t}`, d = await z(e, {
|
|
|
297
297
|
sourcefile: n,
|
|
298
298
|
target: "es2020"
|
|
299
299
|
});
|
|
300
|
-
let
|
|
301
|
-
return
|
|
302
|
-
code:
|
|
300
|
+
let f = d.code;
|
|
301
|
+
return f.includes("ClientIsland") && (f = Z(f, n, s, o, l)), {
|
|
302
|
+
code: f,
|
|
303
303
|
map: d.map || null
|
|
304
304
|
};
|
|
305
305
|
} catch (e) {
|
|
@@ -309,10 +309,10 @@ ${t}`, d = await z(e, {
|
|
|
309
309
|
let e = t, d = !1;
|
|
310
310
|
if (e = e.replace(
|
|
311
311
|
/import\.meta\.env\.([a-zA-Z_][a-zA-Z0-9_]*)/g,
|
|
312
|
-
(
|
|
312
|
+
(f, r) => F.has(r) ? f : (d = !0, `process.env.${r}`)
|
|
313
313
|
), e = e.replace(
|
|
314
314
|
/import\.meta\.env\[(['"`])([^'"`]+)\1\]/g,
|
|
315
|
-
(
|
|
315
|
+
(f, r, u) => F.has(u) ? f : (d = !0, `process.env[${r}${u}${r}]`)
|
|
316
316
|
), d)
|
|
317
317
|
return {
|
|
318
318
|
code: e,
|
|
@@ -323,24 +323,24 @@ ${t}`, d = await z(e, {
|
|
|
323
323
|
return null;
|
|
324
324
|
},
|
|
325
325
|
load(t) {
|
|
326
|
-
if (t === "\0" +
|
|
326
|
+
if (t === "\0" + j)
|
|
327
327
|
return `
|
|
328
328
|
export const viewLoaders = import.meta.glob('/src/views/*/loader.{ts,tsx}');
|
|
329
329
|
export const viewComponents = import.meta.glob('/src/views/*/index.tsx');
|
|
330
330
|
`;
|
|
331
|
-
if (t === "\0" +
|
|
331
|
+
if (t === "\0" + v)
|
|
332
332
|
return "export { default } from '/src/route.ts';";
|
|
333
333
|
if (t === "\0" + _)
|
|
334
334
|
return `export { render } from '@withl5e/l5e/entry-server';
|
|
335
335
|
export { viewActions } from 'virtual:l5e-actions';`;
|
|
336
|
-
if (t === "\0" +
|
|
336
|
+
if (t === "\0" + E)
|
|
337
337
|
return "export const globalLoader = import.meta.glob('/src/global-loader.{ts,tsx}', { eager: false });";
|
|
338
|
-
if (t === "\0" +
|
|
338
|
+
if (t === "\0" + $) {
|
|
339
339
|
const n = Object.fromEntries(i);
|
|
340
340
|
return `export const viewActions = import.meta.glob('/src/**/actions.{ts,tsx}');
|
|
341
341
|
export const actionRegistry = ${JSON.stringify(n)};`;
|
|
342
342
|
}
|
|
343
|
-
if (t === "\0" +
|
|
343
|
+
if (t === "\0" + P)
|
|
344
344
|
return `
|
|
345
345
|
const middlewareModules = import.meta.glob([
|
|
346
346
|
'/src/middleware.{ts,tsx,js,jsx}',
|
|
@@ -375,7 +375,7 @@ export async function loadMiddleware() {
|
|
|
375
375
|
};
|
|
376
376
|
}
|
|
377
377
|
export {
|
|
378
|
-
|
|
379
|
-
|
|
378
|
+
et as coreVite,
|
|
379
|
+
et as default
|
|
380
380
|
};
|
|
381
381
|
//# sourceMappingURL=vite-plugin.js.map
|
package/dist/vite-plugin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vite-plugin.js","sources":["../src/core/vite-plugin.ts"],"sourcesContent":["import { transform } from 'esbuild';\nimport {\n existsSync,\n mkdirSync,\n readdirSync,\n readFileSync,\n rmSync,\n statSync,\n writeFileSync,\n} from 'fs';\nimport { dirname, join, relative, resolve } from 'path';\nimport type { Plugin, UserConfig } from 'vite';\n\nconst VIRTUAL_L5E_VIEWS = 'virtual:l5e-views';\nconst VIRTUAL_L5E_ROUTE = 'virtual:l5e-route';\nconst VIRTUAL_L5E_SSR_ENTRY = 'virtual:l5e-ssr-entry';\nconst VIRTUAL_L5E_GLOBAL_LOADER = 'virtual:l5e-global-loader';\nconst VIRTUAL_L5E_ISLAND_STRATEGIES = 'virtual:l5e-island-strategies';\nconst VIRTUAL_L5E_ACTIONS = 'virtual:l5e-actions';\nconst VIRTUAL_L5E_MIDDLEWARE = 'virtual:l5e-middleware';\n\n/**\n * Recursively scan directory for .tsx and .ts files\n */\nfunction scanTsFiles(dir: string, fileList: string[] = []): string[] {\n const files = readdirSync(dir);\n\n for (const file of files) {\n const filePath = join(dir, file);\n const stat = statSync(filePath);\n\n if (stat.isDirectory()) {\n // Skip node_modules and dist directories\n if (file === 'node_modules' || file === 'dist' || file === '.git') {\n continue;\n }\n scanTsFiles(filePath, fileList);\n } else if (file.endsWith('.tsx') || file.endsWith('.ts')) {\n fileList.push(filePath);\n }\n }\n\n return fileList;\n}\n\n/**\n * Short hash function for island keys\n */\nfunction shortHash(str: string): string {\n let hash = 0;\n for (let i = 0; i < str.length; i++) {\n hash = (hash << 5) - hash + str.charCodeAt(i);\n hash = hash & hash;\n }\n return Math.abs(hash).toString(16).slice(0, 4);\n}\n\n/**\n * Derive component name from path: \"./react/Counter\" → \"Counter\"\n */\nfunction deriveComponentName(fromPath: string): string {\n const segments = fromPath.split('/');\n let filename = segments[segments.length - 1];\n // Remove extension if present\n filename = filename.replace(/\\.(tsx?|jsx?)$/, '');\n return filename;\n}\n\n/**\n * Create island registry key: \"/src/views/test-island/react/Counter\" → \"Counter_a3f2\"\n */\nfunction makeIslandKey(resolvedPath: string): string {\n const name = deriveComponentName(resolvedPath);\n return `${name}_${shortHash(resolvedPath)}`;\n}\n\n/**\n * Resolve file path with extension (.tsx, .ts, .jsx, .js)\n * Returns the relative path with extension (e.g., \"src/views/.../Counter.tsx\")\n * or null if file not found\n */\nfunction resolveWithExtension(resolvedPath: string, rootDir: string): string | null {\n // resolvedPath: \"/src/views/test-island/react/Counter\" (no extension, leading /)\n const relPath = resolvedPath.replace(/^\\//, ''); // \"src/views/.../Counter\"\n const absBase = resolve(rootDir, relPath);\n\n // Check with extensions\n for (const ext of ['.tsx', '.ts', '.jsx', '.js']) {\n if (existsSync(absBase + ext)) {\n return relPath + ext; // \"src/views/.../Counter.tsx\"\n }\n }\n // Check without extension (file might already have one)\n if (existsSync(absBase)) {\n return relPath;\n }\n return null;\n}\n\n/**\n * Extract island entries from file using regex on JSX source\n */\nfunction extractIslandEntries(\n filePath: string,\n rootDir: string,\n): Array<{ component: string; resolvedPath: string; src: string; key: string }> {\n const content = readFileSync(filePath, 'utf-8');\n const entries: Array<{ component: string; resolvedPath: string; src: string; key: string }> = [];\n\n // Regex scan JSX source (NOT post-transform code).\n // Just find <ClientIsland ... from=\"Y\" ...> — component name derived from path.\n const regex = /<ClientIsland\\s[^>]*?from\\s*=\\s*\"([^\"]+)\"/g;\n\n const seen = new Set<string>();\n let match;\n\n while ((match = regex.exec(content)) !== null) {\n const fromPath = match[1];\n\n // Resolve relative path → absolute\n let resolvedPath: string;\n if (fromPath.startsWith('~/')) {\n // Alias ~/ → /src/ (project convention)\n resolvedPath = '/src/' + fromPath.substring(2);\n } else if (fromPath.startsWith('/src/')) {\n resolvedPath = fromPath;\n } else if (fromPath.startsWith('./') || fromPath.startsWith('../')) {\n const abs = resolve(filePath, '..', fromPath);\n resolvedPath = '/' + relative(rootDir, abs).replace(/\\\\/g, '/');\n } else {\n resolvedPath = fromPath;\n }\n\n // Resolve file extension for manifest compatibility\n const src = resolveWithExtension(resolvedPath, rootDir);\n if (!src) {\n console.warn(\n `[l5e] Island component not found: ${resolvedPath} (from ${fromPath} in ${filePath})`,\n );\n continue;\n }\n\n const key = makeIslandKey(resolvedPath);\n if (!seen.has(key)) {\n seen.add(key);\n entries.push({\n component: deriveComponentName(resolvedPath),\n resolvedPath,\n src, // \"src/views/.../Counter.tsx\" — matches manifest key format\n key,\n });\n }\n }\n return entries;\n}\n\n/**\n * Extract paths from useCss and useClientJs calls using regex\n */\nfunction extractPathsFromFile(filePath: string, rootDir: string): { css: string[]; js: string[] } {\n const content = readFileSync(filePath, 'utf-8');\n const css: string[] = [];\n const js: string[] = [];\n\n // Regex patterns to match useCss('path') or useCss(\"path\")\n // Handles single and double quotes, and escaped quotes\n const useCssPattern = /useCss\\s*\\(\\s*['\"]([^'\"]+)['\"]\\s*,?\\s*\\)/g;\n const useClientJsPattern = /useClientJs\\s*\\(\\s*['\"]([^'\"]+)['\"]\\s*,?\\s*\\)/g;\n\n let match;\n\n // Extract CSS paths\n while ((match = useCssPattern.exec(content)) !== null) {\n const path = match[1];\n // Convert relative path to absolute if needed\n if (path.startsWith('/src/')) {\n css.push(path);\n } else if (path.startsWith('./') || path.startsWith('../')) {\n // Resolve relative path\n const absolutePath = resolve(filePath, '..', path);\n const relativePath = '/' + relative(rootDir, absolutePath).replace(/\\\\/g, '/');\n css.push(relativePath);\n } else {\n css.push(path);\n }\n }\n\n // Extract JS paths\n while ((match = useClientJsPattern.exec(content)) !== null) {\n const path = match[1];\n if (path.startsWith('/src/')) {\n js.push(path);\n } else if (path.startsWith('./') || path.startsWith('../')) {\n const absolutePath = resolve(filePath, '..', path);\n const relativePath = '/' + relative(rootDir, absolutePath).replace(/\\\\/g, '/');\n js.push(relativePath);\n } else {\n js.push(path);\n }\n }\n\n return { css, js };\n}\n\n/**\n * Auto-discover rollup input entries from useCss and useClientJs calls\n */\nfunction discoverRollupInput(rootDir: string): {\n input: Record<string, string>;\n islandRegistry: Map<string, string>;\n pathToKey: Map<string, string>;\n keyToSrc: Map<string, string>;\n actionRegistry: Map<string, { modulePath: string; actionName: string }>;\n} {\n const input: Record<string, string> = {};\n const srcDir = join(rootDir, 'src');\n\n // Island registries\n const islandRegistry = new Map<string, string>(); // key → resolvedPath\n const pathToKey = new Map<string, string>(); // resolvedPath → key\n const keyToSrc = new Map<string, string>(); // key → src (manifest-compatible path with extension)\n\n // Action registry: actionKey → { modulePath, actionName }\n const actionRegistry = new Map<string, { modulePath: string; actionName: string }>();\n\n try {\n // Check if src directory exists\n if (!statSync(srcDir).isDirectory()) {\n return { input, islandRegistry, pathToKey, keyToSrc, actionRegistry };\n }\n\n // Check if src/client.global.ts exists and add it as an entry\n const globalTsPath = join(rootDir, 'src', 'client.global.ts');\n if (existsSync(globalTsPath)) {\n input['global'] = globalTsPath;\n console.log('[l5e] Detected src/client.global.ts and added as entry');\n }\n\n // Scan all .tsx and .ts files\n const tsFiles = scanTsFiles(srcDir);\n\n // Extract all paths\n const allCssPaths = new Set<string>();\n const allJsPaths = new Set<string>();\n\n for (const file of tsFiles) {\n const { css, js } = extractPathsFromFile(file, rootDir);\n css.forEach((path) => allCssPaths.add(path));\n js.forEach((path) => allJsPaths.add(path));\n\n // Extract island entries\n const islandEntries = extractIslandEntries(file, rootDir);\n for (const entry of islandEntries) {\n islandRegistry.set(entry.key, entry.resolvedPath);\n pathToKey.set(entry.resolvedPath, entry.key);\n keyToSrc.set(entry.key, entry.src);\n }\n\n // Extract action entries from actions.ts/tsx files\n const normalizedFile = file.replace(/\\\\/g, '/');\n if (/\\/actions\\.(ts|tsx)$/.test(normalizedFile)) {\n const content = readFileSync(file, 'utf-8');\n const actionExportRegex = /export\\s+const\\s+(\\w+)\\s*=\\s*defineAction\\s*\\(/g;\n let actionMatch;\n\n // Compute modulePath: relative path from src/ to parent dir\n const relFromSrc = relative(srcDir, dirname(file)).replace(/\\\\/g, '/');\n const modulePath = relFromSrc || '.';\n\n while ((actionMatch = actionExportRegex.exec(content)) !== null) {\n const actionName = actionMatch[1];\n const actionKey = `${actionName}_${shortHash(modulePath)}`;\n actionRegistry.set(actionKey, { modulePath, actionName });\n }\n }\n }\n\n // Convert paths to rollup input entries\n // CSS files\n for (const cssPath of allCssPaths) {\n // Remove leading /src/ and convert to relative path\n const relativePath = cssPath.startsWith('/src/')\n ? cssPath.substring(1) // Remove leading /\n : cssPath.startsWith('/')\n ? cssPath.substring(1)\n : cssPath;\n\n const absolutePath = resolve(rootDir, relativePath);\n\n // Only add if file exists\n if (!existsSync(absolutePath)) {\n console.warn(`[l5e] CSS file not found: ${absolutePath} (from ${cssPath})`);\n continue;\n }\n\n // Generate entry name from path (e.g., /src/views/home/home.css -> views-home-home)\n const entryName = relativePath\n .replace(/^src\\//, '')\n .replace(/\\.css$/, '')\n .replace(/\\//g, '-')\n .replace(/\\\\/g, '-');\n\n input[entryName] = absolutePath;\n }\n\n // JS/TS files\n for (const jsPath of allJsPaths) {\n const relativePath = jsPath.startsWith('/src/')\n ? jsPath.substring(1)\n : jsPath.startsWith('/')\n ? jsPath.substring(1)\n : jsPath;\n\n const absolutePath = resolve(rootDir, relativePath);\n\n // Only add if file exists\n if (!existsSync(absolutePath)) {\n console.warn(`[l5e] JS/TS file not found: ${absolutePath} (from ${jsPath})`);\n continue;\n }\n\n // Generate entry name from path\n const entryName = relativePath\n .replace(/^src\\//, '')\n .replace(/\\.(ts|tsx|js|jsx)$/, '')\n .replace(/\\//g, '-')\n .replace(/\\\\/g, '-');\n\n input[entryName] = absolutePath;\n }\n\n // Add island component files to rollup input so they appear in manifest.\n // server.ts looks up manifest at runtime to resolve per-page island URLs.\n for (const [key, src] of keyToSrc) {\n const absolutePath = resolve(rootDir, src);\n input[`island-${key}`] = absolutePath;\n }\n\n if (islandRegistry.size > 0) {\n console.log(`[l5e] Detected ${islandRegistry.size} island(s)`);\n }\n if (actionRegistry.size > 0) {\n console.log(`[l5e] Detected ${actionRegistry.size} action(s)`);\n }\n } catch (error) {\n // Silently fail if directory doesn't exist or other errors\n console.warn('[l5e] Failed to discover rollup input:', error);\n }\n\n return { input, islandRegistry, pathToKey, keyToSrc, actionRegistry };\n}\n\n/**\n * Inject __key prop into ClientIsland calls\n * Use anchor-based approach to avoid fragile regex with nested objects\n */\nfunction injectIslandKeys(\n code: string,\n fileId: string,\n rootDir: string,\n pathToKey: Map<string, string>,\n keyToSrc: Map<string, string>,\n): string {\n // After esbuild, code has form:\n // jsxFactory(ClientIsland, { from: \"./react/Counter\", props: { n: 5 } })\n // ^anchor ^find from here\n\n const result: string[] = [];\n let lastIndex = 0;\n\n // Find each position \"ClientIsland,\" (anchor)\n const anchorRegex = /ClientIsland\\s*,\\s*\\{/g;\n let anchorMatch;\n\n while ((anchorMatch = anchorRegex.exec(code)) !== null) {\n const searchStart = anchorMatch.index + anchorMatch[0].length;\n\n // Scan for from: \"...\" in window ~500 chars after anchor\n const window = code.substring(searchStart, searchStart + 500);\n const fromMatch = /from:\\s*\"([^\"]+)\"/.exec(window);\n\n if (!fromMatch) continue;\n\n const fromPath = fromMatch[1];\n\n // Resolve path (handle ~/ alias)\n let resolved: string;\n if (fromPath.startsWith('~/')) {\n resolved = '/src/' + fromPath.substring(2);\n } else if (fromPath.startsWith('/src/')) {\n resolved = fromPath;\n } else if (fromPath.startsWith('./') || fromPath.startsWith('../')) {\n const abs = resolve(fileId, '..', fromPath);\n resolved = '/' + relative(rootDir, abs).replace(/\\\\/g, '/');\n } else {\n resolved = fromPath;\n }\n\n const key = pathToKey.get(resolved);\n if (!key) continue;\n\n const src = keyToSrc.get(key);\n if (!src) continue;\n\n // Inject __key and __src right after from: \"...\"\n const insertPos = searchStart + fromMatch.index + fromMatch[0].length;\n result.push(code.substring(lastIndex, insertPos));\n result.push(`, __key: \"${key}\", __src: \"${src}\"`);\n lastIndex = insertPos;\n }\n\n result.push(code.substring(lastIndex));\n return result.join('');\n}\n\nexport function coreVite(): Plugin {\n let rootDir: string = process.cwd();\n let islandRegistry = new Map<string, string>();\n let pathToKey = new Map<string, string>();\n let keyToSrc = new Map<string, string>();\n let actionRegistry = new Map<string, { modulePath: string; actionName: string }>();\n\n return {\n name: 'l5e-jsx-classic',\n enforce: 'pre',\n\n configResolved(resolvedConfig) {\n // Store root directory for later use\n rootDir = resolvedConfig.root || process.cwd();\n },\n\n handleHotUpdate({ file, server }) {\n const relPath = relative(rootDir, file);\n\n // Re-scan action registry when an actions file changes\n if (/actions\\.(ts|tsx)$/.test(file)) {\n const discovered = discoverRollupInput(rootDir);\n actionRegistry = discovered.actionRegistry;\n // Invalidate the virtual:l5e-actions module so server picks up new registry\n const mod = server.moduleGraph.getModuleById('\\0' + VIRTUAL_L5E_ACTIONS);\n if (mod) {\n server.moduleGraph.invalidateModule(mod);\n }\n console.log(\n `[l5e] Action file changed: ${relPath} — re-scanned ${actionRegistry.size} action(s)`,\n );\n }\n\n // Allow Vite's default HMR for CSS and client-side JS files\n if (file.endsWith('.css')) {\n console.log(`[l5e] CSS changed: ${relPath} - using Vite HMR`);\n return; // Let Vite handle CSS HMR\n }\n\n if (file.includes('client.ts')) {\n console.log(`[l5e] Client JS changed: ${relPath} - using Vite HMR`);\n return; // Let Vite handle client JS HMR\n }\n\n // Trigger full page reload for SSR-related file changes (components, loaders, routes)\n // This ensures that server-side rendered components update properly\n if (file.includes('/src/') || file.includes('\\\\src\\\\')) {\n console.log(`[l5e] SSR file changed: ${relPath} - triggering full reload`);\n server.ws.send({\n type: 'full-reload',\n path: '*',\n });\n return []; // Prevent Vite's default HMR behavior\n }\n },\n\n buildEnd() {\n // Cleanup temporary files after build\n const tempDir = join(rootDir, '.l5e-temp');\n if (existsSync(tempDir)) {\n try {\n rmSync(tempDir, { recursive: true, force: true });\n console.log('[l5e] Cleaned up temporary files');\n } catch (error) {\n console.warn('[l5e] Failed to cleanup temporary files:', error);\n }\n }\n },\n\n writeBundle(_options, _bundle) {\n // Emit action registry JSON for production server\n if (actionRegistry.size > 0) {\n const outDir = join(rootDir, 'dist', 'server');\n if (!existsSync(outDir)) {\n mkdirSync(outDir, { recursive: true });\n }\n const registryObj = Object.fromEntries(actionRegistry);\n writeFileSync(join(outDir, 'action-registry.json'), JSON.stringify(registryObj), 'utf-8');\n console.log(`[l5e] Wrote action-registry.json (${actionRegistry.size} actions)`);\n }\n },\n\n config(userConfig) {\n // Auto-discover rollup input from useCss and useClientJs\n const projectRoot = userConfig.root || process.cwd();\n const discovered = discoverRollupInput(projectRoot);\n\n // Store island registries for use in other hooks\n islandRegistry = discovered.islandRegistry;\n pathToKey = discovered.pathToKey;\n keyToSrc = discovered.keyToSrc;\n actionRegistry = discovered.actionRegistry;\n\n // Merge with existing rollupOptions.input if any\n const existingInput = userConfig.build?.rollupOptions?.input || {};\n const mergedInput =\n typeof existingInput === 'object' && !Array.isArray(existingInput)\n ? { ...discovered.input, ...existingInput }\n : discovered.input;\n\n return {\n build: {\n ...userConfig.build,\n rollupOptions: {\n ...userConfig.build?.rollupOptions,\n input: Object.keys(mergedInput).length > 0 ? mergedInput : undefined,\n // Preserve exports for island component entries — without this,\n // Rollup tree-shakes their exports since nothing in the bundle imports them\n // (they're loaded at runtime via dynamic import from the island runtime).\n preserveEntrySignatures: 'exports-only',\n },\n },\n } satisfies UserConfig;\n },\n\n resolveId(id) {\n if (id === VIRTUAL_L5E_VIEWS) {\n return '\\0' + VIRTUAL_L5E_VIEWS;\n }\n if (id === VIRTUAL_L5E_ROUTE) {\n return '\\0' + VIRTUAL_L5E_ROUTE;\n }\n if (id === VIRTUAL_L5E_SSR_ENTRY) {\n return '\\0' + VIRTUAL_L5E_SSR_ENTRY;\n }\n if (id === VIRTUAL_L5E_GLOBAL_LOADER) {\n return '\\0' + VIRTUAL_L5E_GLOBAL_LOADER;\n }\n if (id === VIRTUAL_L5E_ISLAND_STRATEGIES) {\n return '\\0' + VIRTUAL_L5E_ISLAND_STRATEGIES;\n }\n if (id === VIRTUAL_L5E_ACTIONS) {\n return '\\0' + VIRTUAL_L5E_ACTIONS;\n }\n if (id === VIRTUAL_L5E_MIDDLEWARE) {\n return '\\0' + VIRTUAL_L5E_MIDDLEWARE;\n }\n return null;\n },\n\n async transform(code, id, options) {\n // Auto-inject island runtime into client.global.ts so it's always loaded globally\n if (id.replace(/\\\\/g, '/').endsWith('src/client.global.ts') && !options?.ssr) {\n return {\n code: `import '@withl5e/l5e/island/runtime';\\n${code}`,\n map: null,\n };\n }\n\n // Client-side action transform: replace defineAction exports with fetch stubs\n // Supports actions anywhere under src/ (e.g., src/views/*, src/features/*, etc.)\n if (!options?.ssr) {\n const normalizedId = id.replace(/\\\\/g, '/');\n const actionMatch = normalizedId.match(/\\/src\\/(.+)\\/actions\\.(ts|tsx)$/);\n if (actionMatch) {\n const modulePath = actionMatch[1];\n\n // Parse exported action names\n const exportRegex = /export\\s+const\\s+(\\w+)\\s*=\\s*defineAction\\s*\\(/g;\n const actions: Array<{ name: string; method: string }> = [];\n let m;\n while ((m = exportRegex.exec(code)) !== null) {\n const name = m[1];\n // Find method for this action — scan from the defineAction( position\n const chunk = code.substring(m.index, m.index + 500);\n const methodMatch = chunk.match(/method:\\s*['\"](\\w+)['\"]/);\n const method = methodMatch ? methodMatch[1].toUpperCase() : 'GET';\n actions.push({ name, method });\n }\n\n if (actions.length > 0) {\n const stubs = actions.map(({ name, method }) => {\n const actionKey = `${name}_${shortHash(modulePath)}`;\n if (method === 'GET') {\n return `export async function ${name}(params) {\n const res = await fetch('/_l5e/action/${actionKey}?' + new URLSearchParams(params));\n if (!res.ok) throw Object.assign(new Error('HTTP ' + res.status), { status: res.status });\n return res;\n}`;\n }\n return `export async function ${name}(body) {\n const res = await fetch('/_l5e/action/${actionKey}', {\n method: '${method}',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify(body),\n });\n if (!res.ok) throw Object.assign(new Error('HTTP ' + res.status), { status: res.status });\n return res;\n}`;\n });\n\n return {\n code: stubs.join('\\n\\n'),\n map: null,\n };\n }\n }\n }\n\n // Skip node_modules\n if (id.includes('node_modules')) {\n return null;\n }\n\n // Skip files in /react/ directories\n if (id.includes('/react/') || id.includes('\\\\react\\\\')) {\n return null;\n }\n\n // Check if this is a JSX/TSX file that needs L5E JSX transformation\n const isJsxFile = /\\.(tsx|jsx)$/.test(id);\n\n if (isJsxFile) {\n try {\n const injected = `import { Fragment as __Fragment, jsxFactory } from \"@withl5e/l5e/jsx-runtime\"\\n${code}`;\n\n // Transform JSX using esbuild with L5E's JSX runtime (async)\n const result = await transform(injected, {\n loader: id.endsWith('.tsx') ? 'tsx' : 'jsx',\n jsx: 'transform',\n jsxFactory: 'jsxFactory',\n jsxFragment: '__Fragment',\n sourcemap: true,\n sourcefile: id,\n target: 'es2020',\n });\n\n let transformedCode = result.code;\n\n // Inject __key and __src for ALL ClientIsland calls\n if (transformedCode.includes('ClientIsland')) {\n transformedCode = injectIslandKeys(transformedCode, id, rootDir, pathToKey, keyToSrc);\n }\n\n return {\n code: transformedCode,\n map: result.map || null,\n };\n } catch (error) {\n // Log error but let Vite handle it\n console.error(`[l5e] Failed to transform JSX in ${id}:`, error);\n throw error;\n }\n }\n\n // Transform import.meta.env thà nh process.env ở server side\n // Server side có thể access tất cả env variables\n // Client side chỉ access được VITE_ env variables\n // Transform nà y chạy ở runtime khi module được load trong SSR context\n if (options?.ssr) {\n let transformedCode = code;\n let hasChanges = false;\n\n // Thay thế import.meta.env.VARIABLE_NAME thà nh process.env.VARIABLE_NAME\n // Match: import.meta.env.VITE_EVENT_CATEGORY_SLUG\n transformedCode = transformedCode.replace(\n /import\\.meta\\.env\\.([a-zA-Z_][a-zA-Z0-9_]*)/g,\n (match, varName) => {\n hasChanges = true;\n return `process.env.${varName}`;\n },\n );\n\n // Thay thế import.meta.env['VARIABLE_NAME'] hoặc import.meta.env[\"VARIABLE_NAME\"]\n // thà nh process.env['VARIABLE_NAME'] hoặc process.env[\"VARIABLE_NAME\"]\n // Match: import.meta.env['VITE_EVENT_CATEGORY_SLUG'] hoặc import.meta.env[\"VITE_EVENT_CATEGORY_SLUG\"]\n transformedCode = transformedCode.replace(\n /import\\.meta\\.env\\[(['\"`])([^'\"`]+)\\1\\]/g,\n (match, quote, varName) => {\n hasChanges = true;\n return `process.env[${quote}${varName}${quote}]`;\n },\n );\n\n if (hasChanges) {\n return {\n code: transformedCode,\n map: null, // Không cần source map cho env transform\n };\n }\n }\n return null;\n },\n\n load(id) {\n // Virtual module: l5e-views\n if (id === '\\0' + VIRTUAL_L5E_VIEWS) {\n return `\nexport const viewLoaders = import.meta.glob('/src/views/*/loader.{ts,tsx}');\nexport const viewComponents = import.meta.glob('/src/views/*/index.tsx');\n`;\n }\n\n // Virtual module: l5e-route\n if (id === '\\0' + VIRTUAL_L5E_ROUTE) {\n // Always use TypeScript\n return `export { default } from '/src/route.ts';`;\n }\n\n // Virtual module: l5e-ssr-entry\n if (id === '\\0' + VIRTUAL_L5E_SSR_ENTRY) {\n return `export { render } from '@withl5e/l5e/entry-server';\nexport { viewActions } from 'virtual:l5e-actions';`;\n }\n\n // Virtual module: l5e-global-loader\n if (id === '\\0' + VIRTUAL_L5E_GLOBAL_LOADER) {\n return `export const globalLoader = import.meta.glob('/src/global-loader.{ts,tsx}', { eager: false });`;\n }\n\n // Virtual module: l5e-actions\n if (id === '\\0' + VIRTUAL_L5E_ACTIONS) {\n const registryObj = Object.fromEntries(actionRegistry);\n return `export const viewActions = import.meta.glob('/src/**/actions.{ts,tsx}');\nexport const actionRegistry = ${JSON.stringify(registryObj)};`;\n }\n\n // Virtual module: l5e-middleware\n if (id === '\\0' + VIRTUAL_L5E_MIDDLEWARE) {\n return `\nconst middlewareModules = import.meta.glob([\n '/src/middleware.{ts,tsx,js,jsx}',\n '/src/middleware/index.{ts,tsx,js,jsx}',\n]);\n\nconst middlewarePaths = [\n '/src/middleware.ts',\n '/src/middleware.tsx',\n '/src/middleware.js',\n '/src/middleware.jsx',\n '/src/middleware/index.ts',\n '/src/middleware/index.tsx',\n '/src/middleware/index.js',\n '/src/middleware/index.jsx',\n];\n\nexport async function loadMiddleware() {\n const middlewarePath = middlewarePaths.find((path) => middlewareModules[path]);\n if (!middlewarePath) return undefined;\n\n const mod = await middlewareModules[middlewarePath]();\n return mod.onRequest;\n}\n`;\n }\n\n // Virtual module: l5e-island-strategies\n if (id === '\\0' + VIRTUAL_L5E_ISLAND_STRATEGIES) {\n // Check if src/island-strategies.ts exists\n const strategiesFile = join(rootDir, 'src', 'island-strategies.ts');\n if (existsSync(strategiesFile)) {\n // Re-export user's file → Vite will build this file\n return `import '/src/island-strategies.ts';`;\n }\n // No file → empty module, no error\n return `/* no custom island strategies */`;\n }\n\n return null;\n },\n };\n}\n\nexport default coreVite;\n"],"names":["VIRTUAL_L5E_VIEWS","VIRTUAL_L5E_ROUTE","VIRTUAL_L5E_SSR_ENTRY","VIRTUAL_L5E_GLOBAL_LOADER","VIRTUAL_L5E_ISLAND_STRATEGIES","VIRTUAL_L5E_ACTIONS","VIRTUAL_L5E_MIDDLEWARE","scanTsFiles","dir","fileList","files","readdirSync","file","filePath","join","statSync","shortHash","str","hash","i","deriveComponentName","fromPath","segments","filename","makeIslandKey","resolvedPath","resolveWithExtension","rootDir","relPath","absBase","resolve","ext","existsSync","extractIslandEntries","content","readFileSync","entries","regex","seen","match","abs","relative","src","key","extractPathsFromFile","css","js","useCssPattern","useClientJsPattern","path","absolutePath","relativePath","discoverRollupInput","input","srcDir","islandRegistry","pathToKey","keyToSrc","actionRegistry","globalTsPath","tsFiles","allCssPaths","allJsPaths","islandEntries","entry","normalizedFile","actionExportRegex","actionMatch","modulePath","dirname","actionName","actionKey","cssPath","entryName","jsPath","error","injectIslandKeys","code","fileId","result","lastIndex","anchorRegex","anchorMatch","searchStart","window","fromMatch","resolved","insertPos","coreVite","resolvedConfig","server","mod","tempDir","rmSync","_options","_bundle","outDir","mkdirSync","registryObj","writeFileSync","userConfig","projectRoot","discovered","existingInput","mergedInput","id","options","exportRegex","actions","m","name","methodMatch","method","injected","transform","transformedCode","hasChanges","varName","quote","strategiesFile"],"mappings":";;;AAaA,MAAMA,IAAoB,qBACpBC,IAAoB,qBACpBC,IAAwB,yBACxBC,IAA4B,6BAC5BC,IAAgC,iCAChCC,IAAsB,uBACtBC,IAAyB;AAK/B,SAASC,EAAYC,GAAaC,IAAqB,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AAOpG,GAAqB;AACrC,cAAM6F,IAAc,OAAO,YAAYxC,CAAc;AACrD,eAAO;AAAA,gCACiB,KAAK,UAAUwC,CAAW,CAAC;AAAA,MACrD;AAGA,UAAIO,MAAO,OAAOnG;AAChB,eAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA4BT,UAAImG,MAAO,OAAOrG,GAA+B;AAE/C,cAAMmH,IAAiBzG,EAAKa,GAAS,OAAO,sBAAsB;AAClE,eAAIK,EAAWuF,CAAc,IAEpB,wCAGF;AAAA,MACT;AAEA,aAAO;AAAA,IACT;AAAA,EAAA;AAEJ;"}
|
|
1
|
+
{"version":3,"file":"vite-plugin.js","sources":["../src/core/vite-plugin.ts"],"sourcesContent":["import { transform } from 'esbuild';\nimport {\n existsSync,\n mkdirSync,\n readdirSync,\n readFileSync,\n rmSync,\n statSync,\n writeFileSync,\n} from 'fs';\nimport { dirname, join, relative, resolve } from 'path';\nimport type { Plugin, UserConfig } from 'vite';\n\nconst VIRTUAL_L5E_VIEWS = 'virtual:l5e-views';\nconst VIRTUAL_L5E_ROUTE = 'virtual:l5e-route';\nconst VIRTUAL_L5E_SSR_ENTRY = 'virtual:l5e-ssr-entry';\nconst VIRTUAL_L5E_GLOBAL_LOADER = 'virtual:l5e-global-loader';\nconst VIRTUAL_L5E_ISLAND_STRATEGIES = 'virtual:l5e-island-strategies';\nconst VIRTUAL_L5E_ACTIONS = 'virtual:l5e-actions';\nconst VIRTUAL_L5E_MIDDLEWARE = 'virtual:l5e-middleware';\n\n/**\n * Vite's built-in env vars on `import.meta.env`. These are statically replaced\n * by Vite itself (DEV/PROD/SSR are booleans, MODE/BASE_URL strings), so the SSR\n * `import.meta.env.* -> process.env.*` rewrite must skip them — otherwise it\n * clobbers Vite defaults (e.g. `import.meta.env.DEV` would become the undefined\n * `process.env.DEV`).\n */\nconst VITE_RESERVED_ENV = new Set(['MODE', 'BASE_URL', 'PROD', 'DEV', 'SSR', 'LEGACY']);\n\n/**\n * Recursively scan directory for .tsx and .ts files\n */\nfunction scanTsFiles(dir: string, fileList: string[] = []): string[] {\n const files = readdirSync(dir);\n\n for (const file of files) {\n const filePath = join(dir, file);\n const stat = statSync(filePath);\n\n if (stat.isDirectory()) {\n // Skip node_modules and dist directories\n if (file === 'node_modules' || file === 'dist' || file === '.git') {\n continue;\n }\n scanTsFiles(filePath, fileList);\n } else if (file.endsWith('.tsx') || file.endsWith('.ts')) {\n fileList.push(filePath);\n }\n }\n\n return fileList;\n}\n\n/**\n * Short hash function for island keys\n */\nfunction shortHash(str: string): string {\n let hash = 0;\n for (let i = 0; i < str.length; i++) {\n hash = (hash << 5) - hash + str.charCodeAt(i);\n hash = hash & hash;\n }\n return Math.abs(hash).toString(16).slice(0, 4);\n}\n\n/**\n * Derive component name from path: \"./react/Counter\" → \"Counter\"\n */\nfunction deriveComponentName(fromPath: string): string {\n const segments = fromPath.split('/');\n let filename = segments[segments.length - 1];\n // Remove extension if present\n filename = filename.replace(/\\.(tsx?|jsx?)$/, '');\n return filename;\n}\n\n/**\n * Create island registry key: \"/src/views/test-island/react/Counter\" → \"Counter_a3f2\"\n */\nfunction makeIslandKey(resolvedPath: string): string {\n const name = deriveComponentName(resolvedPath);\n return `${name}_${shortHash(resolvedPath)}`;\n}\n\n/**\n * Resolve file path with extension (.tsx, .ts, .jsx, .js)\n * Returns the relative path with extension (e.g., \"src/views/.../Counter.tsx\")\n * or null if file not found\n */\nfunction resolveWithExtension(resolvedPath: string, rootDir: string): string | null {\n // resolvedPath: \"/src/views/test-island/react/Counter\" (no extension, leading /)\n const relPath = resolvedPath.replace(/^\\//, ''); // \"src/views/.../Counter\"\n const absBase = resolve(rootDir, relPath);\n\n // Check with extensions\n for (const ext of ['.tsx', '.ts', '.jsx', '.js']) {\n if (existsSync(absBase + ext)) {\n return relPath + ext; // \"src/views/.../Counter.tsx\"\n }\n }\n // Check without extension (file might already have one)\n if (existsSync(absBase)) {\n return relPath;\n }\n return null;\n}\n\n/**\n * Extract island entries from file using regex on JSX source\n */\nfunction extractIslandEntries(\n filePath: string,\n rootDir: string,\n): Array<{ component: string; resolvedPath: string; src: string; key: string }> {\n const content = readFileSync(filePath, 'utf-8');\n const entries: Array<{ component: string; resolvedPath: string; src: string; key: string }> = [];\n\n // Regex scan JSX source (NOT post-transform code).\n // Just find <ClientIsland ... from=\"Y\" ...> — component name derived from path.\n const regex = /<ClientIsland\\s[^>]*?from\\s*=\\s*\"([^\"]+)\"/g;\n\n const seen = new Set<string>();\n let match;\n\n while ((match = regex.exec(content)) !== null) {\n const fromPath = match[1];\n\n // Resolve relative path → absolute\n let resolvedPath: string;\n if (fromPath.startsWith('~/')) {\n // Alias ~/ → /src/ (project convention)\n resolvedPath = '/src/' + fromPath.substring(2);\n } else if (fromPath.startsWith('/src/')) {\n resolvedPath = fromPath;\n } else if (fromPath.startsWith('./') || fromPath.startsWith('../')) {\n const abs = resolve(filePath, '..', fromPath);\n resolvedPath = '/' + relative(rootDir, abs).replace(/\\\\/g, '/');\n } else {\n resolvedPath = fromPath;\n }\n\n // Resolve file extension for manifest compatibility\n const src = resolveWithExtension(resolvedPath, rootDir);\n if (!src) {\n console.warn(\n `[l5e] Island component not found: ${resolvedPath} (from ${fromPath} in ${filePath})`,\n );\n continue;\n }\n\n const key = makeIslandKey(resolvedPath);\n if (!seen.has(key)) {\n seen.add(key);\n entries.push({\n component: deriveComponentName(resolvedPath),\n resolvedPath,\n src, // \"src/views/.../Counter.tsx\" — matches manifest key format\n key,\n });\n }\n }\n return entries;\n}\n\n/**\n * Extract paths from useCss and useClientJs calls using regex\n */\nfunction extractPathsFromFile(filePath: string, rootDir: string): { css: string[]; js: string[] } {\n const content = readFileSync(filePath, 'utf-8');\n const css: string[] = [];\n const js: string[] = [];\n\n // Regex patterns to match useCss('path') or useCss(\"path\")\n // Handles single and double quotes, and escaped quotes\n const useCssPattern = /useCss\\s*\\(\\s*['\"]([^'\"]+)['\"]\\s*,?\\s*\\)/g;\n const useClientJsPattern = /useClientJs\\s*\\(\\s*['\"]([^'\"]+)['\"]\\s*,?\\s*\\)/g;\n\n let match;\n\n // Extract CSS paths\n while ((match = useCssPattern.exec(content)) !== null) {\n const path = match[1];\n // Convert relative path to absolute if needed\n if (path.startsWith('/src/')) {\n css.push(path);\n } else if (path.startsWith('./') || path.startsWith('../')) {\n // Resolve relative path\n const absolutePath = resolve(filePath, '..', path);\n const relativePath = '/' + relative(rootDir, absolutePath).replace(/\\\\/g, '/');\n css.push(relativePath);\n } else {\n css.push(path);\n }\n }\n\n // Extract JS paths\n while ((match = useClientJsPattern.exec(content)) !== null) {\n const path = match[1];\n if (path.startsWith('/src/')) {\n js.push(path);\n } else if (path.startsWith('./') || path.startsWith('../')) {\n const absolutePath = resolve(filePath, '..', path);\n const relativePath = '/' + relative(rootDir, absolutePath).replace(/\\\\/g, '/');\n js.push(relativePath);\n } else {\n js.push(path);\n }\n }\n\n return { css, js };\n}\n\n/**\n * Auto-discover rollup input entries from useCss and useClientJs calls\n */\nfunction discoverRollupInput(rootDir: string): {\n input: Record<string, string>;\n islandRegistry: Map<string, string>;\n pathToKey: Map<string, string>;\n keyToSrc: Map<string, string>;\n actionRegistry: Map<string, { modulePath: string; actionName: string }>;\n} {\n const input: Record<string, string> = {};\n const srcDir = join(rootDir, 'src');\n\n // Island registries\n const islandRegistry = new Map<string, string>(); // key → resolvedPath\n const pathToKey = new Map<string, string>(); // resolvedPath → key\n const keyToSrc = new Map<string, string>(); // key → src (manifest-compatible path with extension)\n\n // Action registry: actionKey → { modulePath, actionName }\n const actionRegistry = new Map<string, { modulePath: string; actionName: string }>();\n\n try {\n // Check if src directory exists\n if (!statSync(srcDir).isDirectory()) {\n return { input, islandRegistry, pathToKey, keyToSrc, actionRegistry };\n }\n\n // Check if src/client.global.ts exists and add it as an entry\n const globalTsPath = join(rootDir, 'src', 'client.global.ts');\n if (existsSync(globalTsPath)) {\n input['global'] = globalTsPath;\n console.log('[l5e] Detected src/client.global.ts and added as entry');\n }\n\n // Scan all .tsx and .ts files\n const tsFiles = scanTsFiles(srcDir);\n\n // Extract all paths\n const allCssPaths = new Set<string>();\n const allJsPaths = new Set<string>();\n\n for (const file of tsFiles) {\n const { css, js } = extractPathsFromFile(file, rootDir);\n css.forEach((path) => allCssPaths.add(path));\n js.forEach((path) => allJsPaths.add(path));\n\n // Extract island entries\n const islandEntries = extractIslandEntries(file, rootDir);\n for (const entry of islandEntries) {\n islandRegistry.set(entry.key, entry.resolvedPath);\n pathToKey.set(entry.resolvedPath, entry.key);\n keyToSrc.set(entry.key, entry.src);\n }\n\n // Extract action entries from actions.ts/tsx files\n const normalizedFile = file.replace(/\\\\/g, '/');\n if (/\\/actions\\.(ts|tsx)$/.test(normalizedFile)) {\n const content = readFileSync(file, 'utf-8');\n const actionExportRegex = /export\\s+const\\s+(\\w+)\\s*=\\s*defineAction\\s*\\(/g;\n let actionMatch;\n\n // Compute modulePath: relative path from src/ to parent dir\n const relFromSrc = relative(srcDir, dirname(file)).replace(/\\\\/g, '/');\n const modulePath = relFromSrc || '.';\n\n while ((actionMatch = actionExportRegex.exec(content)) !== null) {\n const actionName = actionMatch[1];\n const actionKey = `${actionName}_${shortHash(modulePath)}`;\n actionRegistry.set(actionKey, { modulePath, actionName });\n }\n }\n }\n\n // Convert paths to rollup input entries\n // CSS files\n for (const cssPath of allCssPaths) {\n // Remove leading /src/ and convert to relative path\n const relativePath = cssPath.startsWith('/src/')\n ? cssPath.substring(1) // Remove leading /\n : cssPath.startsWith('/')\n ? cssPath.substring(1)\n : cssPath;\n\n const absolutePath = resolve(rootDir, relativePath);\n\n // Only add if file exists\n if (!existsSync(absolutePath)) {\n console.warn(`[l5e] CSS file not found: ${absolutePath} (from ${cssPath})`);\n continue;\n }\n\n // Generate entry name from path (e.g., /src/views/home/home.css -> views-home-home)\n const entryName = relativePath\n .replace(/^src\\//, '')\n .replace(/\\.css$/, '')\n .replace(/\\//g, '-')\n .replace(/\\\\/g, '-');\n\n input[entryName] = absolutePath;\n }\n\n // JS/TS files\n for (const jsPath of allJsPaths) {\n const relativePath = jsPath.startsWith('/src/')\n ? jsPath.substring(1)\n : jsPath.startsWith('/')\n ? jsPath.substring(1)\n : jsPath;\n\n const absolutePath = resolve(rootDir, relativePath);\n\n // Only add if file exists\n if (!existsSync(absolutePath)) {\n console.warn(`[l5e] JS/TS file not found: ${absolutePath} (from ${jsPath})`);\n continue;\n }\n\n // Generate entry name from path\n const entryName = relativePath\n .replace(/^src\\//, '')\n .replace(/\\.(ts|tsx|js|jsx)$/, '')\n .replace(/\\//g, '-')\n .replace(/\\\\/g, '-');\n\n input[entryName] = absolutePath;\n }\n\n // Add island component files to rollup input so they appear in manifest.\n // server.ts looks up manifest at runtime to resolve per-page island URLs.\n for (const [key, src] of keyToSrc) {\n const absolutePath = resolve(rootDir, src);\n input[`island-${key}`] = absolutePath;\n }\n\n if (islandRegistry.size > 0) {\n console.log(`[l5e] Detected ${islandRegistry.size} island(s)`);\n }\n if (actionRegistry.size > 0) {\n console.log(`[l5e] Detected ${actionRegistry.size} action(s)`);\n }\n } catch (error) {\n // Silently fail if directory doesn't exist or other errors\n console.warn('[l5e] Failed to discover rollup input:', error);\n }\n\n return { input, islandRegistry, pathToKey, keyToSrc, actionRegistry };\n}\n\n/**\n * Inject __key prop into ClientIsland calls\n * Use anchor-based approach to avoid fragile regex with nested objects\n */\nfunction injectIslandKeys(\n code: string,\n fileId: string,\n rootDir: string,\n pathToKey: Map<string, string>,\n keyToSrc: Map<string, string>,\n): string {\n // After esbuild, code has form:\n // jsxFactory(ClientIsland, { from: \"./react/Counter\", props: { n: 5 } })\n // ^anchor ^find from here\n\n const result: string[] = [];\n let lastIndex = 0;\n\n // Find each position \"ClientIsland,\" (anchor)\n const anchorRegex = /ClientIsland\\s*,\\s*\\{/g;\n let anchorMatch;\n\n while ((anchorMatch = anchorRegex.exec(code)) !== null) {\n const searchStart = anchorMatch.index + anchorMatch[0].length;\n\n // Scan for from: \"...\" in window ~500 chars after anchor\n const window = code.substring(searchStart, searchStart + 500);\n const fromMatch = /from:\\s*\"([^\"]+)\"/.exec(window);\n\n if (!fromMatch) continue;\n\n const fromPath = fromMatch[1];\n\n // Resolve path (handle ~/ alias)\n let resolved: string;\n if (fromPath.startsWith('~/')) {\n resolved = '/src/' + fromPath.substring(2);\n } else if (fromPath.startsWith('/src/')) {\n resolved = fromPath;\n } else if (fromPath.startsWith('./') || fromPath.startsWith('../')) {\n const abs = resolve(fileId, '..', fromPath);\n resolved = '/' + relative(rootDir, abs).replace(/\\\\/g, '/');\n } else {\n resolved = fromPath;\n }\n\n const key = pathToKey.get(resolved);\n if (!key) continue;\n\n const src = keyToSrc.get(key);\n if (!src) continue;\n\n // Inject __key and __src right after from: \"...\"\n const insertPos = searchStart + fromMatch.index + fromMatch[0].length;\n result.push(code.substring(lastIndex, insertPos));\n result.push(`, __key: \"${key}\", __src: \"${src}\"`);\n lastIndex = insertPos;\n }\n\n result.push(code.substring(lastIndex));\n return result.join('');\n}\n\nexport function coreVite(): Plugin {\n let rootDir: string = process.cwd();\n let islandRegistry = new Map<string, string>();\n let pathToKey = new Map<string, string>();\n let keyToSrc = new Map<string, string>();\n let actionRegistry = new Map<string, { modulePath: string; actionName: string }>();\n\n return {\n name: 'l5e-jsx-classic',\n enforce: 'pre',\n\n configResolved(resolvedConfig) {\n // Store root directory for later use\n rootDir = resolvedConfig.root || process.cwd();\n },\n\n handleHotUpdate({ file, server }) {\n const relPath = relative(rootDir, file);\n\n // Re-scan action registry when an actions file changes\n if (/actions\\.(ts|tsx)$/.test(file)) {\n const discovered = discoverRollupInput(rootDir);\n actionRegistry = discovered.actionRegistry;\n // Invalidate the virtual:l5e-actions module so server picks up new registry\n const mod = server.moduleGraph.getModuleById('\\0' + VIRTUAL_L5E_ACTIONS);\n if (mod) {\n server.moduleGraph.invalidateModule(mod);\n }\n console.log(\n `[l5e] Action file changed: ${relPath} — re-scanned ${actionRegistry.size} action(s)`,\n );\n }\n\n // Allow Vite's default HMR for CSS and client-side JS files\n if (file.endsWith('.css')) {\n console.log(`[l5e] CSS changed: ${relPath} - using Vite HMR`);\n return; // Let Vite handle CSS HMR\n }\n\n if (file.includes('client.ts')) {\n console.log(`[l5e] Client JS changed: ${relPath} - using Vite HMR`);\n return; // Let Vite handle client JS HMR\n }\n\n // Trigger full page reload for SSR-related file changes (components, loaders, routes)\n // This ensures that server-side rendered components update properly\n if (file.includes('/src/') || file.includes('\\\\src\\\\')) {\n console.log(`[l5e] SSR file changed: ${relPath} - triggering full reload`);\n server.ws.send({\n type: 'full-reload',\n path: '*',\n });\n return []; // Prevent Vite's default HMR behavior\n }\n },\n\n buildEnd() {\n // Cleanup temporary files after build\n const tempDir = join(rootDir, '.l5e-temp');\n if (existsSync(tempDir)) {\n try {\n rmSync(tempDir, { recursive: true, force: true });\n console.log('[l5e] Cleaned up temporary files');\n } catch (error) {\n console.warn('[l5e] Failed to cleanup temporary files:', error);\n }\n }\n },\n\n writeBundle(_options, _bundle) {\n // Emit action registry JSON for production server\n if (actionRegistry.size > 0) {\n const outDir = join(rootDir, 'dist', 'server');\n if (!existsSync(outDir)) {\n mkdirSync(outDir, { recursive: true });\n }\n const registryObj = Object.fromEntries(actionRegistry);\n writeFileSync(join(outDir, 'action-registry.json'), JSON.stringify(registryObj), 'utf-8');\n console.log(`[l5e] Wrote action-registry.json (${actionRegistry.size} actions)`);\n }\n },\n\n config(userConfig) {\n // Auto-discover rollup input from useCss and useClientJs\n const projectRoot = userConfig.root || process.cwd();\n const discovered = discoverRollupInput(projectRoot);\n\n // Store island registries for use in other hooks\n islandRegistry = discovered.islandRegistry;\n pathToKey = discovered.pathToKey;\n keyToSrc = discovered.keyToSrc;\n actionRegistry = discovered.actionRegistry;\n\n // Merge with existing rollupOptions.input if any\n const existingInput = userConfig.build?.rollupOptions?.input || {};\n const mergedInput =\n typeof existingInput === 'object' && !Array.isArray(existingInput)\n ? { ...discovered.input, ...existingInput }\n : discovered.input;\n\n return {\n build: {\n ...userConfig.build,\n rollupOptions: {\n ...userConfig.build?.rollupOptions,\n input: Object.keys(mergedInput).length > 0 ? mergedInput : undefined,\n // Preserve exports for island component entries — without this,\n // Rollup tree-shakes their exports since nothing in the bundle imports them\n // (they're loaded at runtime via dynamic import from the island runtime).\n preserveEntrySignatures: 'exports-only',\n },\n },\n } satisfies UserConfig;\n },\n\n resolveId(id) {\n if (id === VIRTUAL_L5E_VIEWS) {\n return '\\0' + VIRTUAL_L5E_VIEWS;\n }\n if (id === VIRTUAL_L5E_ROUTE) {\n return '\\0' + VIRTUAL_L5E_ROUTE;\n }\n if (id === VIRTUAL_L5E_SSR_ENTRY) {\n return '\\0' + VIRTUAL_L5E_SSR_ENTRY;\n }\n if (id === VIRTUAL_L5E_GLOBAL_LOADER) {\n return '\\0' + VIRTUAL_L5E_GLOBAL_LOADER;\n }\n if (id === VIRTUAL_L5E_ISLAND_STRATEGIES) {\n return '\\0' + VIRTUAL_L5E_ISLAND_STRATEGIES;\n }\n if (id === VIRTUAL_L5E_ACTIONS) {\n return '\\0' + VIRTUAL_L5E_ACTIONS;\n }\n if (id === VIRTUAL_L5E_MIDDLEWARE) {\n return '\\0' + VIRTUAL_L5E_MIDDLEWARE;\n }\n return null;\n },\n\n async transform(code, id, options) {\n // Auto-inject island runtime into client.global.ts so it's always loaded globally\n if (id.replace(/\\\\/g, '/').endsWith('src/client.global.ts') && !options?.ssr) {\n return {\n code: `import '@withl5e/l5e/island/runtime';\\n${code}`,\n map: null,\n };\n }\n\n // Client-side action transform: replace defineAction exports with fetch stubs\n // Supports actions anywhere under src/ (e.g., src/views/*, src/features/*, etc.)\n if (!options?.ssr) {\n const normalizedId = id.replace(/\\\\/g, '/');\n const actionMatch = normalizedId.match(/\\/src\\/(.+)\\/actions\\.(ts|tsx)$/);\n if (actionMatch) {\n const modulePath = actionMatch[1];\n\n // Parse exported action names\n const exportRegex = /export\\s+const\\s+(\\w+)\\s*=\\s*defineAction\\s*\\(/g;\n const actions: Array<{ name: string; method: string }> = [];\n let m;\n while ((m = exportRegex.exec(code)) !== null) {\n const name = m[1];\n // Find method for this action — scan from the defineAction( position\n const chunk = code.substring(m.index, m.index + 500);\n const methodMatch = chunk.match(/method:\\s*['\"](\\w+)['\"]/);\n const method = methodMatch ? methodMatch[1].toUpperCase() : 'GET';\n actions.push({ name, method });\n }\n\n if (actions.length > 0) {\n const stubs = actions.map(({ name, method }) => {\n const actionKey = `${name}_${shortHash(modulePath)}`;\n if (method === 'GET') {\n return `export async function ${name}(params) {\n const res = await fetch('/_l5e/action/${actionKey}?' + new URLSearchParams(params));\n if (!res.ok) throw Object.assign(new Error('HTTP ' + res.status), { status: res.status });\n return res;\n}`;\n }\n return `export async function ${name}(body) {\n const res = await fetch('/_l5e/action/${actionKey}', {\n method: '${method}',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify(body),\n });\n if (!res.ok) throw Object.assign(new Error('HTTP ' + res.status), { status: res.status });\n return res;\n}`;\n });\n\n return {\n code: stubs.join('\\n\\n'),\n map: null,\n };\n }\n }\n }\n\n // Skip node_modules\n if (id.includes('node_modules')) {\n return null;\n }\n\n // Skip files in /react/ directories\n if (id.includes('/react/') || id.includes('\\\\react\\\\')) {\n return null;\n }\n\n // Check if this is a JSX/TSX file that needs L5E JSX transformation\n const isJsxFile = /\\.(tsx|jsx)$/.test(id);\n\n if (isJsxFile) {\n try {\n const injected = `import { Fragment as __Fragment, jsxFactory } from \"@withl5e/l5e/jsx-runtime\"\\n${code}`;\n\n // Transform JSX using esbuild with L5E's JSX runtime (async)\n const result = await transform(injected, {\n loader: id.endsWith('.tsx') ? 'tsx' : 'jsx',\n jsx: 'transform',\n jsxFactory: 'jsxFactory',\n jsxFragment: '__Fragment',\n sourcemap: true,\n sourcefile: id,\n target: 'es2020',\n });\n\n let transformedCode = result.code;\n\n // Inject __key and __src for ALL ClientIsland calls\n if (transformedCode.includes('ClientIsland')) {\n transformedCode = injectIslandKeys(transformedCode, id, rootDir, pathToKey, keyToSrc);\n }\n\n return {\n code: transformedCode,\n map: result.map || null,\n };\n } catch (error) {\n // Log error but let Vite handle it\n console.error(`[l5e] Failed to transform JSX in ${id}:`, error);\n throw error;\n }\n }\n\n // Transform import.meta.env thà nh process.env ở server side\n // Server side có thể access tất cả env variables\n // Client side chỉ access được VITE_ env variables\n // Transform nà y chạy ở runtime khi module được load trong SSR context\n if (options?.ssr) {\n let transformedCode = code;\n let hasChanges = false;\n\n // Thay thế import.meta.env.VARIABLE_NAME thà nh process.env.VARIABLE_NAME\n // Match: import.meta.env.VITE_EVENT_CATEGORY_SLUG\n transformedCode = transformedCode.replace(\n /import\\.meta\\.env\\.([a-zA-Z_][a-zA-Z0-9_]*)/g,\n (match, varName) => {\n // Leave Vite's built-in env vars for Vite to handle.\n if (VITE_RESERVED_ENV.has(varName)) return match;\n hasChanges = true;\n return `process.env.${varName}`;\n },\n );\n\n // Thay thế import.meta.env['VARIABLE_NAME'] hoặc import.meta.env[\"VARIABLE_NAME\"]\n // thà nh process.env['VARIABLE_NAME'] hoặc process.env[\"VARIABLE_NAME\"]\n // Match: import.meta.env['VITE_EVENT_CATEGORY_SLUG'] hoặc import.meta.env[\"VITE_EVENT_CATEGORY_SLUG\"]\n transformedCode = transformedCode.replace(\n /import\\.meta\\.env\\[(['\"`])([^'\"`]+)\\1\\]/g,\n (match, quote, varName) => {\n // Leave Vite's built-in env vars for Vite to handle.\n if (VITE_RESERVED_ENV.has(varName)) return match;\n hasChanges = true;\n return `process.env[${quote}${varName}${quote}]`;\n },\n );\n\n if (hasChanges) {\n return {\n code: transformedCode,\n map: null, // Không cần source map cho env transform\n };\n }\n }\n return null;\n },\n\n load(id) {\n // Virtual module: l5e-views\n if (id === '\\0' + VIRTUAL_L5E_VIEWS) {\n return `\nexport const viewLoaders = import.meta.glob('/src/views/*/loader.{ts,tsx}');\nexport const viewComponents = import.meta.glob('/src/views/*/index.tsx');\n`;\n }\n\n // Virtual module: l5e-route\n if (id === '\\0' + VIRTUAL_L5E_ROUTE) {\n // Always use TypeScript\n return `export { default } from '/src/route.ts';`;\n }\n\n // Virtual module: l5e-ssr-entry\n if (id === '\\0' + VIRTUAL_L5E_SSR_ENTRY) {\n return `export { render } from '@withl5e/l5e/entry-server';\nexport { viewActions } from 'virtual:l5e-actions';`;\n }\n\n // Virtual module: l5e-global-loader\n if (id === '\\0' + VIRTUAL_L5E_GLOBAL_LOADER) {\n return `export const globalLoader = import.meta.glob('/src/global-loader.{ts,tsx}', { eager: false });`;\n }\n\n // Virtual module: l5e-actions\n if (id === '\\0' + VIRTUAL_L5E_ACTIONS) {\n const registryObj = Object.fromEntries(actionRegistry);\n return `export const viewActions = import.meta.glob('/src/**/actions.{ts,tsx}');\nexport const actionRegistry = ${JSON.stringify(registryObj)};`;\n }\n\n // Virtual module: l5e-middleware\n if (id === '\\0' + VIRTUAL_L5E_MIDDLEWARE) {\n return `\nconst middlewareModules = import.meta.glob([\n '/src/middleware.{ts,tsx,js,jsx}',\n '/src/middleware/index.{ts,tsx,js,jsx}',\n]);\n\nconst middlewarePaths = [\n '/src/middleware.ts',\n '/src/middleware.tsx',\n '/src/middleware.js',\n '/src/middleware.jsx',\n '/src/middleware/index.ts',\n '/src/middleware/index.tsx',\n '/src/middleware/index.js',\n '/src/middleware/index.jsx',\n];\n\nexport async function loadMiddleware() {\n const middlewarePath = middlewarePaths.find((path) => middlewareModules[path]);\n if (!middlewarePath) return undefined;\n\n const mod = await middlewareModules[middlewarePath]();\n return mod.onRequest;\n}\n`;\n }\n\n // Virtual module: l5e-island-strategies\n if (id === '\\0' + VIRTUAL_L5E_ISLAND_STRATEGIES) {\n // Check if src/island-strategies.ts exists\n const strategiesFile = join(rootDir, 'src', 'island-strategies.ts');\n if (existsSync(strategiesFile)) {\n // Re-export user's file → Vite will build this file\n return `import '/src/island-strategies.ts';`;\n }\n // No file → empty module, no error\n return `/* no custom island strategies */`;\n }\n\n return null;\n },\n };\n}\n\nexport default coreVite;\n"],"names":["VIRTUAL_L5E_VIEWS","VIRTUAL_L5E_ROUTE","VIRTUAL_L5E_SSR_ENTRY","VIRTUAL_L5E_GLOBAL_LOADER","VIRTUAL_L5E_ISLAND_STRATEGIES","VIRTUAL_L5E_ACTIONS","VIRTUAL_L5E_MIDDLEWARE","VITE_RESERVED_ENV","scanTsFiles","dir","fileList","files","readdirSync","file","filePath","join","statSync","shortHash","str","hash","i","deriveComponentName","fromPath","segments","filename","makeIslandKey","resolvedPath","resolveWithExtension","rootDir","relPath","absBase","resolve","ext","existsSync","extractIslandEntries","content","readFileSync","entries","regex","seen","match","abs","relative","src","key","extractPathsFromFile","css","js","useCssPattern","useClientJsPattern","path","absolutePath","relativePath","discoverRollupInput","input","srcDir","islandRegistry","pathToKey","keyToSrc","actionRegistry","globalTsPath","tsFiles","allCssPaths","allJsPaths","islandEntries","entry","normalizedFile","actionExportRegex","actionMatch","modulePath","dirname","actionName","actionKey","cssPath","entryName","jsPath","error","injectIslandKeys","code","fileId","result","lastIndex","anchorRegex","anchorMatch","searchStart","window","fromMatch","resolved","insertPos","coreVite","resolvedConfig","server","mod","tempDir","rmSync","_options","_bundle","outDir","mkdirSync","registryObj","writeFileSync","userConfig","projectRoot","discovered","existingInput","mergedInput","id","options","exportRegex","actions","m","name","methodMatch","method","injected","transform","transformedCode","hasChanges","varName","quote","strategiesFile"],"mappings":";;;AAaA,MAAMA,IAAoB,qBACpBC,IAAoB,qBACpBC,IAAwB,yBACxBC,IAA4B,6BAC5BC,IAAgC,iCAChCC,IAAsB,uBACtBC,IAAyB,0BASzBC,IAAoB,oBAAI,IAAI,CAAC,QAAQ,YAAY,QAAQ,OAAO,OAAO,QAAQ,CAAC;AAKtF,SAASC,EAAYC,GAAaC,IAAqB,IAAc;AACnE,QAAMC,IAAQC,EAAYH,CAAG;AAE7B,aAAWI,KAAQF,GAAO;AACxB,UAAMG,IAAWC,EAAKN,GAAKI,C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C,cAAM8F,IAAc,OAAO,YAAYxC,CAAc;AACrD,eAAO;AAAA,gCACiB,KAAK,UAAUwC,CAAW,CAAC;AAAA,MACrD;AAGA,UAAIO,MAAO,OAAOpG;AAChB,eAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA4BT,UAAIoG,MAAO,OAAOtG,GAA+B;AAE/C,cAAMoH,IAAiBzG,EAAKa,GAAS,OAAO,sBAAsB;AAClE,eAAIK,EAAWuF,CAAc,IAEpB,wCAGF;AAAA,MACT;AAEA,aAAO;AAAA,IACT;AAAA,EAAA;AAEJ;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@withl5e/l5e",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
4
4
|
"description": "HTML-first SSR MPA framework with loaders, middleware, islands, actions, swap, SEO and cache controls.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -83,11 +83,13 @@
|
|
|
83
83
|
"dependencies": {
|
|
84
84
|
"@floating-ui/dom": "1.7.4",
|
|
85
85
|
"compression": "^1.7.4",
|
|
86
|
+
"cookie": "^1.1.1",
|
|
86
87
|
"esbuild": "^0.24.2",
|
|
87
88
|
"express": "^4.18.2",
|
|
88
89
|
"path-to-regexp": "^8.4.2",
|
|
89
90
|
"request-ip": "^3.3.0",
|
|
90
91
|
"rollup": "^4.0.0",
|
|
92
|
+
"serialize-javascript": "^7.0.5",
|
|
91
93
|
"sirv": "^2.0.3"
|
|
92
94
|
},
|
|
93
95
|
"peerDependencies": {
|
|
@@ -100,6 +102,7 @@
|
|
|
100
102
|
"@types/react": "^19.0.0",
|
|
101
103
|
"@types/react-dom": "^19.0.0",
|
|
102
104
|
"@types/request-ip": "0.0.41",
|
|
105
|
+
"@types/serialize-javascript": "^5.0.4",
|
|
103
106
|
"react": "^19.0.0",
|
|
104
107
|
"react-dom": "^19.0.0",
|
|
105
108
|
"typescript": "^5.6.3",
|