@withl5e/l5e 0.2.2 → 0.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/dist/entry-server.js +175 -10
  2. package/dist/entry-server.js.map +1 -1
  3. package/dist/{generateMetadata-DLMaI0EO.js → generateMetadata-CIFVlViV.js} +4 -4
  4. package/dist/{generateMetadata-DLMaI0EO.js.map → generateMetadata-CIFVlViV.js.map} +1 -1
  5. package/dist/index-BlfNBupp.js +318 -0
  6. package/dist/index-BlfNBupp.js.map +1 -0
  7. package/dist/index.js +37 -36
  8. package/dist/index.js.map +1 -1
  9. package/dist/island/runtime.js +9 -8
  10. package/dist/island/runtime.js.map +1 -1
  11. package/dist/island.js +36 -23
  12. package/dist/island.js.map +1 -1
  13. package/dist/{jsx-runtime-DVQ9eOji.js → jsx-runtime-Bokflh8Q.js} +68 -55
  14. package/dist/jsx-runtime-Bokflh8Q.js.map +1 -0
  15. package/dist/jsx-runtime.js +12 -10
  16. package/dist/middleware.js +3 -5
  17. package/dist/render-DTXfJu0d.js +202 -0
  18. package/dist/render-DTXfJu0d.js.map +1 -0
  19. package/dist/seo.js +2 -2
  20. package/dist/server.js +250 -244
  21. package/dist/server.js.map +1 -1
  22. package/dist/vite-plugin.js +110 -108
  23. package/dist/vite-plugin.js.map +1 -1
  24. package/package.json +20 -1
  25. package/src/core/entry-server.ts +83 -8
  26. package/src/core/index.ts +0 -2
  27. package/src/core/jsx-runtime.ts +33 -0
  28. package/src/core/render.ts +36 -0
  29. package/src/core/request.ts +11 -10
  30. package/src/core/server.ts +23 -9
  31. package/src/core/vite-plugin.ts +25 -0
  32. package/src/island/ClientIsland.ts +36 -1
  33. package/src/island/runtime.ts +10 -3
  34. package/src/island/types.ts +1 -0
  35. package/src/middleware/index.ts +0 -48
  36. package/dist/entry-server-DJzzhCmz.js +0 -224
  37. package/dist/entry-server-DJzzhCmz.js.map +0 -1
  38. package/dist/index-BIt7MJT9.js +0 -163
  39. package/dist/index-BIt7MJT9.js.map +0 -1
  40. package/dist/jsx-runtime-DVQ9eOji.js.map +0 -1
package/dist/server.js CHANGED
@@ -1,28 +1,29 @@
1
- import { existsSync as z } from "fs";
2
- import L from "node:fs/promises";
3
- import l from "node:path";
4
- import { pathToFileURL as N } from "node:url";
1
+ import { existsSync as G } from "fs";
2
+ import M from "node:fs/promises";
3
+ import u from "node:path";
4
+ import { pathToFileURL as H } from "node:url";
5
5
  import K from "request-ip";
6
- import { p as J, c as Y, a as Z } from "./index-BIt7MJT9.js";
7
- import { createHash as q } from "node:crypto";
8
- import { createRequire as Q } from "node:module";
6
+ import { a as Z, s as B } from "./render-DTXfJu0d.js";
7
+ import { p as z, c as Q, a as q } from "./index-BlfNBupp.js";
8
+ import { createHash as ee } from "node:crypto";
9
+ import { createRequire as te } from "node:module";
9
10
  let D = null;
10
- function ee() {
11
+ function ne() {
11
12
  return D || (D = (async () => {
12
- const e = Q(import.meta.url), t = e.resolve("vite"), n = e.resolve("rollup", { paths: [l.dirname(t)] });
13
- return await import(N(n).href);
13
+ const e = te(import.meta.url), t = e.resolve("vite"), n = e.resolve("rollup", { paths: [u.dirname(t)] });
14
+ return await import(H(n).href);
14
15
  })()), D;
15
16
  }
16
- const H = /* @__PURE__ */ new Map(), B = /* @__PURE__ */ new Map(), V = /* @__PURE__ */ new Map();
17
+ const I = /* @__PURE__ */ new Map(), J = /* @__PURE__ */ new Map(), V = /* @__PURE__ */ new Map();
17
18
  function U(e) {
18
- return q("sha256").update(e).digest("hex").substring(0, 16);
19
+ return ee("sha256").update(e).digest("hex").substring(0, 16);
19
20
  }
20
- async function te(e, t, n) {
21
+ async function se(e, t, n) {
21
22
  if (e.length === 0)
22
23
  return { hash: "", filename: "", content: "" };
23
- const o = [...new Set(e)], f = `scripts:${o.sort().join(",")}`, h = B.get(f);
24
- if (h) {
25
- const a = H.get(h);
24
+ const o = [...new Set(e)], l = `scripts:${o.sort().join(",")}`, d = J.get(l);
25
+ if (d) {
26
+ const a = I.get(d);
26
27
  if (a)
27
28
  return {
28
29
  hash: a.hash,
@@ -33,30 +34,30 @@ async function te(e, t, n) {
33
34
  let c = null;
34
35
  try {
35
36
  const a = U(o.join(`
36
- `)), g = l.join(t, ".temp-bundle");
37
- await L.mkdir(g, { recursive: !0 }).catch(() => {
38
- }), c = l.join(g, `entry-${a}.js`);
39
- const v = o.map((s, u) => {
40
- const y = s.startsWith("/") ? l.join(n, s.substring(1)) : l.join(n, s);
41
- return `import ${JSON.stringify(y)};`;
37
+ `)), g = u.join(t, ".temp-bundle");
38
+ await M.mkdir(g, { recursive: !0 }).catch(() => {
39
+ }), c = u.join(g, `entry-${a}.js`);
40
+ const $ = o.map((s, h) => {
41
+ const v = s.startsWith("/") ? u.join(n, s.substring(1)) : u.join(n, s);
42
+ return `import ${JSON.stringify(v)};`;
42
43
  }).join(`
43
44
  `);
44
- await L.writeFile(c, v, "utf-8"), console.log(`[bundler] Wrote entry file to ${c}`), console.log(`[bundler] Entry content: ${v}`);
45
+ await M.writeFile(c, $, "utf-8"), console.log(`[bundler] Wrote entry file to ${c}`), console.log(`[bundler] Entry content: ${$}`);
45
46
  const R = {
46
47
  input: c,
47
48
  plugins: [
48
49
  {
49
50
  name: "vendor-path-rewriter",
50
- resolveId(s, u, y) {
51
+ resolveId(s, h, v) {
51
52
  if (s.includes("vendor-") || s.includes("chunk-") || s.includes(".global")) {
52
- if (console.log(`[bundler] Resolving source: ${s}`), l.isAbsolute(s))
53
- return console.log(`[bundler] Resolving absolute path: ${s}`), { id: "/" + l.relative(n, s).replace(/\\/g, "/"), external: !0 };
54
- if (u && s.startsWith(".")) {
53
+ if (console.log(`[bundler] Resolving source: ${s}`), u.isAbsolute(s))
54
+ return console.log(`[bundler] Resolving absolute path: ${s}`), { id: "/" + u.relative(n, s).replace(/\\/g, "/"), external: !0 };
55
+ if (h && s.startsWith(".")) {
55
56
  console.log(
56
- `[bundler] Resolving relative path: ${s} from importer: ${u}`
57
+ `[bundler] Resolving relative path: ${s} from importer: ${h}`
57
58
  );
58
- const b = l.resolve(l.dirname(u), s);
59
- return { id: "/" + l.relative(n, b).replace(/\\/g, "/"), external: !0 };
59
+ const y = u.resolve(u.dirname(h), s);
60
+ return { id: "/" + u.relative(n, y).replace(/\\/g, "/"), external: !0 };
60
61
  } else
61
62
  console.log(`[bundler] Resolving source: ${s}`);
62
63
  }
@@ -64,43 +65,43 @@ async function te(e, t, n) {
64
65
  }
65
66
  }
66
67
  ],
67
- external: (s) => !s.startsWith(".") && !l.isAbsolute(s) ? !0 : (s.includes("vendor-") || s.includes("chunk-") || s.includes(".global"), !1)
68
- }, S = {
68
+ external: (s) => !s.startsWith(".") && !u.isAbsolute(s) ? !0 : (s.includes("vendor-") || s.includes("chunk-") || s.includes(".global"), !1)
69
+ }, j = {
69
70
  format: "es",
70
71
  inlineDynamicImports: !1,
71
72
  entryFileNames: "bundle-[hash].js",
72
73
  chunkFileNames: "bundle-[hash].js"
73
- }, { rollup: P } = await ee(), C = await P(R), { output: i } = await C.generate(S);
74
- await C.close(), i.forEach((s) => {
74
+ }, { rollup: P } = await ne(), C = await P(R), { output: r } = await C.generate(j);
75
+ await C.close(), r.forEach((s) => {
75
76
  if (s.type !== "chunk")
76
77
  return;
77
- const u = {
78
+ const h = {
78
79
  content: s.code || "",
79
80
  hash: U(s.code || ""),
80
81
  filename: s.fileName,
81
82
  mimeType: "application/javascript"
82
83
  };
83
- H.set(s.fileName, u);
84
+ I.set(s.fileName, h);
84
85
  });
85
- const d = i[0];
86
- return d?.type === "chunk" && B.set(f, d.fileName), {
87
- hash: U(i[0]?.code || ""),
88
- filename: i[0]?.fileName || "",
89
- content: i[0]?.code || ""
86
+ const f = r[0];
87
+ return f?.type === "chunk" && J.set(l, f.fileName), {
88
+ hash: U(r[0]?.code || ""),
89
+ filename: r[0]?.fileName || "",
90
+ content: r[0]?.code || ""
90
91
  };
91
92
  } catch (a) {
92
93
  return console.error("[bundler] Error bundling scripts:", a), { hash: "", filename: "", content: "" };
93
94
  } finally {
94
- c && await L.unlink(c).catch(() => {
95
+ c && await M.unlink(c).catch(() => {
95
96
  });
96
97
  }
97
98
  }
98
- async function ne(e, t, n) {
99
+ async function oe(e, t, n) {
99
100
  if (e.length === 0)
100
101
  return { hash: "", filename: "", content: "" };
101
- const o = [...new Set(e)], f = `css:${o.sort().join(",")}`, h = V.get(f);
102
- if (h) {
103
- const c = H.get(h);
102
+ const o = [...new Set(e)], l = `css:${o.sort().join(",")}`, d = V.get(l);
103
+ if (d) {
104
+ const c = I.get(d);
104
105
  if (c)
105
106
  return {
106
107
  hash: c.hash,
@@ -110,81 +111,82 @@ async function ne(e, t, n) {
110
111
  }
111
112
  try {
112
113
  const c = [];
113
- for (const S of o) {
114
- const P = S.startsWith("/") ? l.join(n, S.substring(1)) : l.join(n, S);
114
+ for (const j of o) {
115
+ const P = j.startsWith("/") ? u.join(n, j.substring(1)) : u.join(n, j);
115
116
  try {
116
- const C = await L.readFile(P, "utf-8");
117
- c.push(`/* ${S} */
117
+ const C = await M.readFile(P, "utf-8");
118
+ c.push(`/* ${j} */
118
119
  ${C}
119
120
  `);
120
121
  } catch (C) {
121
- console.warn(`[bundler] Failed to read CSS file: ${S}`, C);
122
+ console.warn(`[bundler] Failed to read CSS file: ${j}`, C);
122
123
  }
123
124
  }
124
125
  const a = c.join(`
125
126
 
126
- `), g = U(a), v = `bundle-${g}.css`, R = {
127
+ `), g = U(a), $ = `bundle-${g}.css`, R = {
127
128
  content: a,
128
129
  hash: g,
129
- filename: v,
130
+ filename: $,
130
131
  mimeType: "text/css"
131
132
  };
132
- return H.set(v, R), V.set(f, v), { hash: g, filename: v, content: a };
133
+ return I.set($, R), V.set(l, $), { hash: g, filename: $, content: a };
133
134
  } catch (c) {
134
135
  return console.error("[bundler] Error bundling CSS:", c), { hash: "", filename: "", content: "" };
135
136
  }
136
137
  }
137
- function se(e) {
138
- return H.get(e);
138
+ function re(e) {
139
+ return I.get(e);
139
140
  }
140
- function oe(e, t) {
141
- return e.replace(/<html\b([^>]*)>/i, (n, o) => /\blang\s*=/i.test(o) ? n.replace(/lang\s*=\s*"[^"]*"/i, `lang="${t}"`) : `<html lang="${t}"${o}>`);
141
+ function ie(e, t) {
142
+ const n = Z(t);
143
+ return e.replace(/<html\b([^>]*)>/i, (o, l) => /\blang\s*=/i.test(l) ? o.replace(/lang\s*=\s*"[^"]*"/i, () => `lang="${n}"`) : `<html lang="${n}"${l}>`);
142
144
  }
143
- function re(e) {
145
+ function ae(e) {
144
146
  return new URL(`${e.protocol}://${e.get("host")}${e.originalUrl}`);
145
147
  }
146
- function G(e, t) {
148
+ function X(e, t) {
147
149
  return `${e.pathname}${e.search}`.replace(t, "") || "/";
148
150
  }
149
- function ie(e) {
151
+ function ce(e) {
150
152
  const t = {
151
153
  method: e.method,
152
- headers: Z(e)
154
+ headers: q(e)
153
155
  };
154
- return e.method !== "GET" && e.method !== "HEAD" && (t.body = e, t.duplex = "half"), new globalThis.Request(re(e).href, t);
156
+ return e.method !== "GET" && e.method !== "HEAD" && (t.body = e, t.duplex = "half"), new globalThis.Request(ae(e).href, t);
155
157
  }
156
158
  function W(e, t, n, o) {
157
- const f = new URL(t.url), h = G(f, n), c = h.startsWith("/") ? h : `/${h}`, a = {};
158
- return t.headers.forEach((g, v) => {
159
- a[v] = g;
159
+ const l = new URL(t.url), d = X(l, n), c = d.startsWith("/") ? d : `/${d}`, a = {};
160
+ return t.headers.forEach((g, $) => {
161
+ a[$] = g;
160
162
  }), {
161
- url: f,
163
+ url: l,
162
164
  path: c,
163
- pathname: f.pathname,
165
+ pathname: l.pathname,
164
166
  method: t.method,
165
167
  headers: a,
166
- cookies: J(t.headers.get("cookie") ?? void 0),
167
- query: Object.fromEntries(f.searchParams.entries()),
168
+ cookies: z(t.headers.get("cookie") ?? void 0),
169
+ query: Object.fromEntries(l.searchParams.entries()),
168
170
  ip: K.getClientIp(e) ?? void 0,
169
171
  locals: o
170
172
  };
171
173
  }
172
- function ae(e, t, n) {
174
+ function le(e, t, n) {
173
175
  return e ? e instanceof globalThis.Request ? e : e instanceof URL ? new globalThis.Request(e.href, t.clone()) : new globalThis.Request(new URL(e, n).href, t.clone()) : t;
174
176
  }
175
- async function ce(e, t, n) {
177
+ async function ue(e, t, n) {
176
178
  t.status(n.status);
177
- const o = le(n.headers);
178
- if (n.headers.forEach((h, c) => {
179
- c.toLowerCase() !== "set-cookie" && t.setHeader(c, h);
179
+ const o = fe(n.headers);
180
+ if (n.headers.forEach((d, c) => {
181
+ c.toLowerCase() !== "set-cookie" && t.setHeader(c, d);
180
182
  }), o.length > 0 && t.setHeader("Set-Cookie", o), e.method === "HEAD") {
181
183
  t.end();
182
184
  return;
183
185
  }
184
- const f = Buffer.from(await n.arrayBuffer());
185
- t.send(f);
186
+ const l = Buffer.from(await n.arrayBuffer());
187
+ t.send(l);
186
188
  }
187
- function le(e) {
189
+ function fe(e) {
188
190
  const t = e.getSetCookie;
189
191
  if (typeof t == "function")
190
192
  return t.call(e);
@@ -192,36 +194,36 @@ function le(e) {
192
194
  if (n?.["set-cookie"])
193
195
  return n["set-cookie"];
194
196
  const o = e.get("set-cookie");
195
- return o ? ue(o) : [];
197
+ return o ? he(o) : [];
196
198
  }
197
- function ue(e) {
199
+ function he(e) {
198
200
  const t = [];
199
201
  let n = 0;
200
202
  for (let o = 0; o < e.length; o++) {
201
203
  if (e[o] !== ",") continue;
202
- const f = e.slice(o + 1);
203
- /^\s*[^=;,]+=/.test(f) && (t.push(e.slice(n, o).trim()), n = o + 1);
204
+ const l = e.slice(o + 1);
205
+ /^\s*[^=;,]+=/.test(l) && (t.push(e.slice(n, o).trim()), n = o + 1);
204
206
  }
205
207
  return t.push(e.slice(n).trim()), t.filter(Boolean);
206
208
  }
207
- function fe(e) {
209
+ function de(e) {
208
210
  if (!e.rawResponse)
209
211
  return null;
210
- const { body: t, contentType: n, statusCode: o, headers: f } = e.rawResponse, h = new Headers(f);
211
- return h.set("Content-Type", n), new globalThis.Response(t, {
212
+ const { body: t, contentType: n, statusCode: o, headers: l } = e.rawResponse, d = new Headers(l);
213
+ return d.set("Content-Type", n), new globalThis.Response(t, {
212
214
  status: o || 200,
213
- headers: h
215
+ headers: d
214
216
  });
215
217
  }
216
- async function he({
218
+ async function pe({
217
219
  rendered: e,
218
220
  template: t,
219
221
  manifest: n,
220
222
  root: o,
221
- distClientDir: f,
222
- isProduction: h
223
+ distClientDir: l,
224
+ isProduction: d
223
225
  }) {
224
- const c = fe(e);
226
+ const c = de(e);
225
227
  if (c)
226
228
  return c;
227
229
  if (e.redirect)
@@ -232,104 +234,104 @@ async function he({
232
234
  }
233
235
  });
234
236
  let a = e.scripts || [], g = e.styles || [];
235
- const v = e.islands || [];
237
+ const $ = e.islands || [];
236
238
  let R = e.cacheTags || [];
237
- const S = e.maxAge, P = e.sMaxAge, C = e.swr;
238
- let i = "", d = [], s = "";
239
- if (h && n) {
240
- let j = function(r) {
241
- const m = n[r];
242
- return m ? (m.css && m.css.forEach((x) => w.add(x)), m.imports && m.imports.forEach((x) => {
243
- const _ = n[x];
244
- _?.file && E.add(_.file), _?.css && _.css.forEach((O) => w.add(O)), _?.imports && _.imports.forEach((O) => {
245
- const I = n[O];
246
- I?.file && E.add(I.file), I?.css && I.css.forEach((X) => w.add(X));
239
+ const j = e.maxAge, P = e.sMaxAge, C = e.swr;
240
+ let r = "", f = [], s = "";
241
+ if (d && n) {
242
+ let k = function(i) {
243
+ const p = n[i];
244
+ return p ? (p.css && p.css.forEach((b) => w.add(b)), p.imports && p.imports.forEach((b) => {
245
+ const _ = n[b];
246
+ _?.file && F.add(_.file), _?.css && _.css.forEach((O) => w.add(O)), _?.imports && _.imports.forEach((O) => {
247
+ const N = n[O];
248
+ N?.file && F.add(N.file), N?.css && N.css.forEach((Y) => w.add(Y));
247
249
  });
248
- }), { file: m.file }) : { file: null };
250
+ }), { file: p.file }) : { file: null };
249
251
  };
250
- a = a.filter((r) => !r.includes(".global.")), g = g.filter((r) => !r.includes(".global."));
251
- const w = /* @__PURE__ */ new Set(), E = /* @__PURE__ */ new Set(), T = [];
252
- for (const r of a) {
253
- const m = r.replace(/^\//, ""), { file: x } = j(m);
254
- x && T.push(`/${x}`);
252
+ a = a.filter((i) => !i.includes(".global.")), g = g.filter((i) => !i.includes(".global."));
253
+ const w = /* @__PURE__ */ new Set(), F = /* @__PURE__ */ new Set(), T = [];
254
+ for (const i of a) {
255
+ const p = i.replace(/^\//, ""), { file: b } = k(p);
256
+ b && T.push(`/${b}`);
255
257
  }
256
- const M = [];
257
- for (const r of g) {
258
- const m = r.replace(/^\//, ""), { file: x } = j(m);
259
- x && (M.push(`/${x}`), w.add(x));
258
+ const L = [];
259
+ for (const i of g) {
260
+ const p = i.replace(/^\//, ""), { file: b } = k(p);
261
+ b && (L.push(`/${b}`), w.add(b));
260
262
  }
261
263
  if (T.length > 0) {
262
- const r = await te(T, o, f);
263
- a = r.filename ? [`/${r.filename}`] : T;
264
+ const i = await se(T, o, l);
265
+ a = i.filename ? [`/${i.filename}`] : T;
264
266
  }
265
- if (M.length > 0) {
266
- const r = await ne(M, o, f);
267
- r.filename && (g = [`/${r.filename}`]);
267
+ if (L.length > 0) {
268
+ const i = await oe(L, o, l);
269
+ i.filename && (g = [`/${i.filename}`]);
268
270
  }
269
- const p = n["src/client.global.ts"];
270
- if (p && (p.css && p.css.length > 0 && p.css.forEach((r) => {
271
- i += `<link rel="stylesheet" crossorigin href="/${r}">`;
272
- }), p.file && d.push(`/${p.file}`)), v.length > 0) {
273
- const r = {};
274
- for (const m of v) {
275
- const x = n[m.src];
276
- x?.file && (r[m.key] = `/${x.file}`);
271
+ const m = n["src/client.global.ts"];
272
+ if (m && (m.css && m.css.length > 0 && m.css.forEach((i) => {
273
+ r += `<link rel="stylesheet" crossorigin href="/${i}">`;
274
+ }), m.file && f.push(`/${m.file}`)), $.length > 0) {
275
+ const i = {};
276
+ for (const p of $) {
277
+ const b = n[p.src];
278
+ b?.file && (i[p.key] = `/${b.file}`);
277
279
  }
278
- Object.keys(r).length > 0 && (s = `<script>window.__L5E_ISLANDS__=${JSON.stringify(r)}<\/script>`);
280
+ Object.keys(i).length > 0 && (s = `<script>window.__L5E_ISLANDS__=${B(i)}<\/script>`);
279
281
  }
280
- g.length > 0 && (i += g.map((r) => `<link rel="stylesheet" crossorigin href="${r}">`).join(""));
282
+ g.length > 0 && (r += g.map((i) => `<link rel="stylesheet" crossorigin href="${i}">`).join(""));
281
283
  }
282
- let u = "";
283
- h || (u = g.map((j) => `<link rel="stylesheet" href="${j}">`).join(""));
284
- let y = [...d, ...a];
285
- if (!h) {
286
- const j = l.join(o, "src", "client.global.ts");
287
- if (z(j) && (y = ["/src/client.global.ts", ...y]), v.length > 0) {
284
+ let h = "";
285
+ d || (h = g.map((k) => `<link rel="stylesheet" href="${k}">`).join(""));
286
+ let v = [...f, ...a];
287
+ if (!d) {
288
+ const k = u.join(o, "src", "client.global.ts");
289
+ if (G(k) && (v = ["/src/client.global.ts", ...v]), $.length > 0) {
288
290
  const w = {};
289
- for (const E of v)
290
- w[E.key] = `/${E.src}`;
291
- s = `<script>window.__L5E_ISLANDS__=${JSON.stringify(w)}<\/script>`;
291
+ for (const F of $)
292
+ w[F.key] = `/${F.src}`;
293
+ s = `<script>window.__L5E_ISLANDS__=${B(w)}<\/script>`;
292
294
  }
293
295
  }
294
- const b = s + y.map((j) => `<script type="module" src="${j}"><\/script>`).join(""), A = e.lang ? oe(t, e.lang) : t, $ = e.rawHtml ? e.html || "" : A.replace("<!--app-head-->", (e.head ?? "") + i + u).replace("<!--app-html-->", e.html ?? "").replace("<!--app-scripts-->", b), F = new Headers({
296
+ const y = s + v.map((k) => `<script type="module" src="${k}"><\/script>`).join(""), A = e.lang ? ie(t, e.lang) : t, x = e.rawHtml ? e.html || "" : A.replace("<!--app-head-->", (e.head ?? "") + r + h).replace("<!--app-html-->", e.html ?? "").replace("<!--app-scripts-->", y), E = new Headers({
295
297
  "Content-Type": "text/html"
296
- }), k = ["public"];
297
- return S !== void 0 && k.push(`max-age=${S}`), P !== void 0 && k.push(`s-maxage=${P}`), C !== void 0 && k.push(`stale-while-revalidate=${C}`), k.length > 1 && h && F.set("Cache-Control", k.join(", ")), process.env.NODE_ENV === "production" && (R = ge(R)), F.set("Cache-Tag", ["global", ...R].join(",")), new globalThis.Response($, {
298
+ }), S = ["public"];
299
+ return j !== void 0 && S.push(`max-age=${j}`), P !== void 0 && S.push(`s-maxage=${P}`), C !== void 0 && S.push(`stale-while-revalidate=${C}`), S.length > 1 && d && E.set("Cache-Control", S.join(", ")), process.env.NODE_ENV === "production" && (R = ye(R)), E.set("Cache-Tag", ["global", ...R].join(",")), new globalThis.Response(x, {
298
300
  status: e.statusCode || 200,
299
- headers: F
301
+ headers: E
300
302
  });
301
303
  }
302
- async function de(e = {}) {
303
- const t = e.root || process.cwd(), n = e.base || "/", o = process.env.NODE_ENV === "production", f = o ? await L.readFile(l.join(t, "./index.html"), "utf-8") : "", h = (await import("express")).default, c = e.app || h();
304
+ async function me(e = {}) {
305
+ const t = e.root || process.cwd(), n = e.base || "/", o = process.env.NODE_ENV === "production", l = o ? await M.readFile(u.join(t, "./index.html"), "utf-8") : "", d = (await import("express")).default, c = e.app || d();
304
306
  if (e.publicDir) {
305
- const i = l.isAbsolute(e.publicDir) ? e.publicDir : l.join(t, e.publicDir);
306
- z(i) && c.use(h.static(i));
307
+ const r = u.isAbsolute(e.publicDir) ? e.publicDir : u.join(t, e.publicDir);
308
+ G(r) && c.use(d.static(r));
307
309
  }
308
310
  let a;
309
- const g = l.join(t, "./dist/client");
311
+ const g = u.join(t, "./dist/client");
310
312
  if (o) {
311
- const i = (await import("compression")).default, d = (await import("sirv")).default;
312
- c.use(i()), c.use(n, d(g, { extensions: [] })), c.get(
313
+ const r = (await import("compression")).default, f = (await import("sirv")).default;
314
+ c.use(r()), c.use(n, f(g, { extensions: [] })), c.get(
313
315
  `${n === "/" ? "" : n}/bundle-:hash.:ext`,
314
- async (s, u) => {
316
+ async (s, h) => {
315
317
  try {
316
- const { hash: y, ext: b } = s.params, A = `bundle-${y}.${b}`, $ = se(A);
317
- if (!$)
318
- return u.status(404).send("Bundled file not found");
319
- u.set({
320
- "Content-Type": $.mimeType,
318
+ const { hash: v, ext: y } = s.params, A = `bundle-${v}.${y}`, x = re(A);
319
+ if (!x)
320
+ return h.status(404).send("Bundled file not found");
321
+ h.set({
322
+ "Content-Type": x.mimeType,
321
323
  "Cache-Control": "public, max-age=31536000, immutable"
322
- }), u.send($.content);
323
- } catch (y) {
324
- console.error("[server] Error serving bundled file:", y), u.status(500).end(y.message);
324
+ }), h.send(x.content);
325
+ } catch (v) {
326
+ console.error("[server] Error serving bundled file:", v), h.status(500).end("Internal server error");
325
327
  }
326
328
  }
327
329
  );
328
330
  } else {
329
- const { createServer: i } = await import("vite"), d = l.join(t, "vite.config.js");
330
- a = await i({
331
+ const { createServer: r } = await import("vite"), f = u.join(t, "vite.config.js");
332
+ a = await r({
331
333
  root: t,
332
- configFile: d,
334
+ configFile: f,
333
335
  server: { middlewareMode: !0 },
334
336
  appType: "custom",
335
337
  base: n,
@@ -346,135 +348,138 @@ async function de(e = {}) {
346
348
  }
347
349
  }), c.use(a.middlewares);
348
350
  }
349
- c.use("/_l5e/action", h.json({ limit: "100kb" }));
350
- const v = /^[a-zA-Z]\w+_[0-9a-f]{1,4}$/;
351
- let R = null, S = null;
351
+ c.use("/_l5e/action", d.json({ limit: "100kb" }));
352
+ const $ = /^[a-zA-Z]\w+_[0-9a-f]{1,4}$/;
353
+ let R = null, j = null;
352
354
  async function P() {
353
355
  if (!o)
354
356
  return (await a.ssrLoadModule("virtual:l5e-actions")).actionRegistry || {};
355
357
  if (!R) {
356
- const i = l.join(t, "./dist/server/action-registry.json"), d = await L.readFile(i, "utf-8");
357
- R = JSON.parse(d);
358
+ const r = u.join(t, "./dist/server/action-registry.json"), f = await M.readFile(r, "utf-8");
359
+ R = JSON.parse(f);
358
360
  }
359
361
  return R;
360
362
  }
361
363
  async function C() {
362
364
  if (!o)
363
365
  return (await a.ssrLoadModule("virtual:l5e-actions")).viewActions || {};
364
- if (!S) {
365
- const i = l.join(t, "./dist/server/entry-server.js");
366
- S = (await import(N(i).href)).viewActions || {};
366
+ if (!j) {
367
+ const r = u.join(t, "./dist/server/entry-server.js");
368
+ j = (await import(H(r).href)).viewActions || {};
367
369
  }
368
- return S;
370
+ return j;
369
371
  }
370
- return c.all("/_l5e/action/:actionKey", async (i, d) => {
372
+ return c.all("/_l5e/action/:actionKey", async (r, f) => {
371
373
  try {
372
- const { actionKey: s } = i.params;
373
- if (!v.test(s))
374
- return d.status(400).send("Invalid action key");
375
- const y = (await P())[s];
376
- if (!y)
377
- return d.status(404).send("Action not found");
378
- const { modulePath: b, actionName: A } = y;
379
- let $;
374
+ const { actionKey: s } = r.params;
375
+ if (!$.test(s))
376
+ return f.status(400).send("Invalid action key");
377
+ const v = (await P())[s];
378
+ if (!v)
379
+ return f.status(404).send("Action not found");
380
+ const { modulePath: y, actionName: A } = v;
381
+ let x;
380
382
  if (o) {
381
- const r = await C(), m = r[`/src/${b}/actions.tsx`] ? `/src/${b}/actions.tsx` : r[`/src/${b}/actions.ts`] ? `/src/${b}/actions.ts` : null;
382
- if (!m)
383
- return d.status(404).send("Action module not found");
384
- $ = await r[m]();
383
+ const p = await C(), b = p[`/src/${y}/actions.tsx`] ? `/src/${y}/actions.tsx` : p[`/src/${y}/actions.ts`] ? `/src/${y}/actions.ts` : null;
384
+ if (!b)
385
+ return f.status(404).send("Action module not found");
386
+ x = await p[b]();
385
387
  } else
386
388
  try {
387
- $ = await a.ssrLoadModule(`/src/${b}/actions.tsx`);
389
+ x = await a.ssrLoadModule(`/src/${y}/actions.tsx`);
388
390
  } catch {
389
- $ = await a.ssrLoadModule(`/src/${b}/actions.ts`);
391
+ x = await a.ssrLoadModule(`/src/${y}/actions.ts`);
390
392
  }
391
- if (!Object.prototype.hasOwnProperty.call($, A))
392
- return d.status(404).send("Action not found");
393
- const F = $[A];
394
- if (!F || !F.handler)
395
- return d.status(404).send("Action not found");
396
- const k = `${i.protocol}://${i.get("host")}${i.originalUrl}`, j = new URL(k), w = {
397
- url: j,
398
- path: i.originalUrl,
399
- pathname: j.pathname,
400
- method: i.method,
401
- headers: i.headers,
402
- cookies: J(i.headers.cookie),
403
- query: i.query || {},
404
- body: i.body,
405
- ip: K.getClientIp(i)
406
- }, E = l.join(t, "./dist/server/entry-server.js"), { runInRenderContext: T } = await (o ? import(N(E).href) : a.ssrLoadModule("@withl5e/l5e/jsx-runtime")), { renderJsxToHtmlString: M } = await (o ? import(N(E).href) : a.ssrLoadModule("@withl5e/l5e")), p = await T(
393
+ if (!Object.prototype.hasOwnProperty.call(x, A))
394
+ return f.status(404).send("Action not found");
395
+ const E = x[A];
396
+ if (!E || !E.handler)
397
+ return f.status(404).send("Action not found");
398
+ const S = (E.method || "GET").toUpperCase();
399
+ if (r.method.toUpperCase() !== S)
400
+ return f.status(405).set("Allow", S).send("Method Not Allowed");
401
+ const k = `${r.protocol}://${r.get("host")}${r.originalUrl}`, w = new URL(k), F = {
402
+ url: w,
403
+ path: r.originalUrl,
404
+ pathname: w.pathname,
405
+ method: r.method,
406
+ headers: r.headers,
407
+ cookies: z(r.headers.cookie),
408
+ query: r.query || {},
409
+ body: r.body,
410
+ ip: K.getClientIp(r)
411
+ }, T = u.join(t, "./dist/server/entry-server.js"), { runInRenderContext: L } = await (o ? import(H(T).href) : a.ssrLoadModule("@withl5e/l5e/jsx-runtime")), { renderJsxToHtmlString: m } = await (o ? import(H(T).href) : a.ssrLoadModule("@withl5e/l5e")), i = await L(
407
412
  async () => {
408
- const r = await F.handler(w);
409
- return M(r);
413
+ const p = await E.handler(F);
414
+ return m(p);
410
415
  },
411
- w,
412
- b
416
+ F,
417
+ y
413
418
  );
414
- d.set("Content-Type", "text/html").send(p);
419
+ f.set("Content-Type", "text/html").send(i);
415
420
  } catch (s) {
416
- a?.ssrFixStacktrace?.(s), console.error("[l5e] Action error:", s.stack || s), d.status(500).send("Internal server error");
421
+ a?.ssrFixStacktrace?.(s), console.error("[l5e] Action error:", s.stack || s), f.status(500).send("Internal server error");
417
422
  }
418
- }), c.use(async (i, d) => {
423
+ }), c.use(async (r, f) => {
419
424
  try {
420
- const s = i.originalUrl.replace(n, "");
421
- let u, y, b, A;
425
+ const s = r.originalUrl.replace(n, "");
426
+ let h, v, y, A;
422
427
  if (o) {
423
- u = f;
424
- const p = l.join(t, "./dist/server/entry-server.js"), r = await import(N(p).href);
425
- y = r.render, b = r.loadMiddleware;
426
- const m = await L.readFile(
427
- l.join(t, "./dist/client/.vite/manifest.json"),
428
+ h = l;
429
+ const m = u.join(t, "./dist/server/entry-server.js"), i = await import(H(m).href);
430
+ v = i.render, y = i.loadMiddleware;
431
+ const p = await M.readFile(
432
+ u.join(t, "./dist/client/.vite/manifest.json"),
428
433
  "utf-8"
429
434
  );
430
- A = JSON.parse(m);
435
+ A = JSON.parse(p);
431
436
  } else {
432
- u = await L.readFile(l.join(t, "./index.html"), "utf-8"), u = await a.transformIndexHtml(s, u), u.includes("@vite/client") || (u = u.replace(
437
+ h = await M.readFile(u.join(t, "./index.html"), "utf-8"), h = await a.transformIndexHtml(s, h), h.includes("@vite/client") || (h = h.replace(
433
438
  "</head>",
434
439
  '<script type="module" src="/@vite/client"><\/script></head>'
435
440
  ));
436
- const p = await a.ssrLoadModule(
441
+ const m = await a.ssrLoadModule(
437
442
  "@withl5e/l5e/entry-server"
438
443
  );
439
- y = p.render, b = p.loadMiddleware;
444
+ v = m.render, y = m.loadMiddleware;
440
445
  }
441
- const $ = await b?.(), F = typeof $ == "function" ? $ : (p, r) => r(), k = {}, j = ie(i), w = Y({
442
- request: j,
443
- requestInfo: W(i, j, n, k),
444
- locals: k,
445
- clientAddress: K.getClientIp(i)
446
- }), E = async (p) => {
447
- const r = W(i, p, n, k), m = G(r.url, n), x = await y(m, r);
448
- return he({
449
- rendered: x,
450
- template: u,
446
+ const x = await y?.(), E = typeof x == "function" ? x : (m, i) => i(), S = {}, k = ce(r), w = Q({
447
+ request: k,
448
+ requestInfo: W(r, k, n, S),
449
+ locals: S,
450
+ clientAddress: K.getClientIp(r)
451
+ }), F = async (m) => {
452
+ const i = W(r, m, n, S), p = X(i.url, n), b = await v(p, i);
453
+ return pe({
454
+ rendered: b,
455
+ template: h,
451
456
  manifest: A,
452
457
  root: t,
453
458
  distClientDir: g,
454
459
  isProduction: o
455
460
  });
456
- }, T = async (p) => {
457
- const r = ae(p, w.request, w.url);
458
- return w.request = r, w.url = new URL(r.url), w.cookies = J(r.headers.get("cookie") ?? void 0), w.requestInfo = W(i, r, n, k), E(r);
461
+ }, T = async (m) => {
462
+ const i = le(m, w.request, w.url);
463
+ return w.request = i, w.url = new URL(i.url), w.cookies = z(i.headers.get("cookie") ?? void 0), w.requestInfo = W(r, i, n, S), F(i);
459
464
  };
460
- w.rewrite = (p) => T(p);
461
- const M = await F(w, T);
462
- await ce(i, d, M);
465
+ w.rewrite = (m) => T(m);
466
+ const L = await E(w, T);
467
+ await ue(r, f, L);
463
468
  } catch (s) {
464
- a?.ssrFixStacktrace?.(s), console.log(s.stack), d.status(500).end(s.stack);
469
+ a?.ssrFixStacktrace?.(s), console.error(s.stack), f.status(500).end(o ? "Internal Server Error" : s.stack);
465
470
  }
466
471
  }), { app: c, vite: a };
467
472
  }
468
- async function ke(e = {}) {
473
+ async function Ae(e = {}) {
469
474
  const t = e.port || 5173, n = (await import("express")).default, o = n();
470
475
  e.setupApp && (console.log("setupApp"), await e.setupApp(o));
471
- const { app: f } = await de({ ...e, app: o });
472
- f.listen(t, () => {
476
+ const { app: l } = await me({ ...e, app: o });
477
+ l.listen(t, () => {
473
478
  console.log(`Server started at http://localhost:${t}`);
474
479
  });
475
480
  }
476
- const pe = 1e3;
477
- function me(e) {
481
+ const ge = 1e3;
482
+ function we(e) {
478
483
  if (e === "global")
479
484
  return "global";
480
485
  let t = 0;
@@ -484,13 +489,14 @@ function me(e) {
484
489
  }
485
490
  return Math.abs(t).toString(36).substring(0, 8);
486
491
  }
487
- function ge(e) {
488
- return (Array.isArray(e) ? e : [...e]).slice(0, pe).map(me);
492
+ function ye(e) {
493
+ return (Array.isArray(e) ? e : [...e]).slice(0, ge).map(we);
489
494
  }
490
495
  export {
491
- de as createServer,
492
- me as hashTag,
493
- ge as optimizeCacheTags,
494
- ke as startServer
496
+ ie as applyHtmlLang,
497
+ me as createServer,
498
+ we as hashTag,
499
+ ye as optimizeCacheTags,
500
+ Ae as startServer
495
501
  };
496
502
  //# sourceMappingURL=server.js.map