@withl5e/l5e 1.0.0 → 1.0.1-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{global-style-BhiGjxVU.js → global-style-Cgno-yNl.js} +2 -2
- package/dist/{global-style-BhiGjxVU.js.map → global-style-Cgno-yNl.js.map} +1 -1
- package/dist/index.js +1 -1
- package/dist/server-DPBLtja1.js +505 -0
- package/dist/server-DPBLtja1.js.map +1 -0
- package/dist/server.js +1 -1
- package/dist/vite-plugin.js +1 -1
- package/package.json +1 -1
- package/src/core/bundler.ts +30 -49
- package/src/core/script-bundle-policy.ts +77 -0
- package/src/core/server.ts +43 -21
- package/dist/server-5BEwGAL4.js +0 -461
- package/dist/server-5BEwGAL4.js.map +0 -1
|
@@ -16,6 +16,6 @@ function o({ root: e, manifest: t, isProduction: o, base: s }) {
|
|
|
16
16
|
return typeof c == "string" ? a(s, c) : null;
|
|
17
17
|
}
|
|
18
18
|
//#endregion
|
|
19
|
-
export { o as n, i as t };
|
|
19
|
+
export { o as n, a as r, i as t };
|
|
20
20
|
|
|
21
|
-
//# sourceMappingURL=global-style-
|
|
21
|
+
//# sourceMappingURL=global-style-Cgno-yNl.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"global-style-
|
|
1
|
+
{"version":3,"file":"global-style-Cgno-yNl.js","names":[],"sources":["../src/core/global-style.ts"],"sourcesContent":["import { existsSync } from 'node:fs';\nimport { join } from 'node:path';\n\nexport const GLOBAL_STYLE_SOURCE = '/src/global.css';\nexport const GLOBAL_STYLE_MANIFEST_KEY = 'src/global.css';\n\nexport function findGlobalStyleInput(root: string): string | null {\n const absolutePath = join(root, GLOBAL_STYLE_MANIFEST_KEY);\n return existsSync(absolutePath) ? absolutePath : null;\n}\n\nexport function withAssetBase(base: string, assetPath: string): string {\n const cleanPath = assetPath.replace(/^\\/+/, '');\n const normalizedBase = base.endsWith('/') ? base : `${base}/`;\n return `${normalizedBase}${cleanPath}`;\n}\n\nexport function resolveGlobalStyleHref({\n root,\n manifest,\n isProduction,\n base,\n}: {\n root: string;\n manifest?: Record<string, any>;\n isProduction: boolean;\n base: string;\n}): string | null {\n if (!isProduction) {\n return findGlobalStyleInput(root) ? withAssetBase(base, GLOBAL_STYLE_SOURCE) : null;\n }\n\n const file = manifest?.[GLOBAL_STYLE_MANIFEST_KEY]?.file;\n return typeof file === 'string' ? withAssetBase(base, file) : null;\n}\n"],"mappings":";;;AAGA,IAAa,IAAsB,mBACtB,IAA4B;AAEzC,SAAgB,EAAqB,GAA6B;CAChE,IAAM,IAAe,EAAK,GAAM,CAAyB;CACzD,OAAO,EAAW,CAAY,IAAI,IAAe;AACnD;AAEA,SAAgB,EAAc,GAAc,GAA2B;CACrE,IAAM,IAAY,EAAU,QAAQ,QAAQ,EAAE;CAE9C,OAAO,GADgB,EAAK,SAAS,GAAG,IAAI,IAAO,GAAG,EAAK,KAChC;AAC7B;AAEA,SAAgB,EAAuB,EACrC,SACA,aACA,iBACA,WAMgB;CAChB,IAAI,CAAC,GACH,OAAO,EAAqB,CAAI,IAAI,EAAc,GAAM,CAAmB,IAAI;CAGjF,IAAM,IAAO,IAAW,EAA0B,EAAE;CACpD,OAAO,OAAO,KAAS,WAAW,EAAc,GAAM,CAAI,IAAI;AAChE"}
|
package/dist/index.js
CHANGED
|
@@ -4,6 +4,6 @@ import { a as j, i as M, n as N, o as P, r as F, t as I } from "./exceptions-D4O
|
|
|
4
4
|
import { render as L } from "./entry-server.js";
|
|
5
5
|
import { n as R, t as z } from "./middleware-CnDqZobD.js";
|
|
6
6
|
import { t as B } from "./defineMiddleware-D017PWDc.js";
|
|
7
|
-
import { a as V, n as H } from "./server-
|
|
7
|
+
import { a as V, n as H } from "./server-DPBLtja1.js";
|
|
8
8
|
import { coreVite as U } from "./vite-plugin.js";
|
|
9
9
|
export { I as BadRequestException, T as Fragment, _ as HEAD_PRIORITY, b as Head, N as HttpException, F as InternalServerErrorException, M as NotFoundException, j as RedirectException, P as ServiceUnavailableException, C as addCacheTag, g as cloneElement, U as coreVite, z as createContext, H as createServer, B as defineMiddleware, r as escapeHTML, t as escapeProp, l as getCacheTags, x as getClientJsEntries, w as getCssEntries, d as getHeadContent, v as getIslandEntries, E as getIslandProps, f as getSchemas, p as getSsrIslands, S as isIslandPropsExternalized, y as isValidElement, h as jsxFactory, m as pushIslandProps, c as pushMetadata, D as pushSchema, A as registerIsland, u as registerSsrIsland, L as render, n as renderJsxToHtmlString, e as renderToRenderedNode, k as resolveMetadata, o as runInRenderContext, R as sequence, i as setViewName, V as startServer, O as useClientJs, s as useCss, a as useRequest };
|
|
@@ -0,0 +1,505 @@
|
|
|
1
|
+
import { r as e } from "./rolldown-runtime-B0aSnxlc.js";
|
|
2
|
+
import { a as t, n } from "./render-hUQUreah.js";
|
|
3
|
+
import { i as r, r as i, t as a } from "./middleware-CnDqZobD.js";
|
|
4
|
+
import { n as o, r as s } from "./global-style-Cgno-yNl.js";
|
|
5
|
+
import { existsSync as c } from "fs";
|
|
6
|
+
import l from "node:fs/promises";
|
|
7
|
+
import u from "node:path";
|
|
8
|
+
import { pathToFileURL as d } from "node:url";
|
|
9
|
+
import f from "request-ip";
|
|
10
|
+
import { createHash as p } from "node:crypto";
|
|
11
|
+
import { createRequire as m } from "node:module";
|
|
12
|
+
import { realpathSync as h } from "node:fs";
|
|
13
|
+
//#region src/core/bundler.ts
|
|
14
|
+
var g = /* @__PURE__ */ e(t(), 1), _ = null;
|
|
15
|
+
function v() {
|
|
16
|
+
return _ ||= (async () => {
|
|
17
|
+
let e = m(import.meta.url).resolve("@withl5e/l5e/server"), t = m(e).resolve("rolldown");
|
|
18
|
+
return await import(
|
|
19
|
+
/* @vite-ignore */
|
|
20
|
+
d(t).href
|
|
21
|
+
);
|
|
22
|
+
})(), _;
|
|
23
|
+
}
|
|
24
|
+
var y = {
|
|
25
|
+
hash: "",
|
|
26
|
+
filename: "",
|
|
27
|
+
content: ""
|
|
28
|
+
}, b = /* @__PURE__ */ new Map(), x = /* @__PURE__ */ new Map();
|
|
29
|
+
function S(e, t) {
|
|
30
|
+
let n = x.get(e);
|
|
31
|
+
if (n) return n;
|
|
32
|
+
let r = t().catch((t) => {
|
|
33
|
+
throw x.delete(e), t;
|
|
34
|
+
});
|
|
35
|
+
return x.set(e, r), r;
|
|
36
|
+
}
|
|
37
|
+
function C(e) {
|
|
38
|
+
return p("sha256").update(e).digest("hex").substring(0, 16);
|
|
39
|
+
}
|
|
40
|
+
var w = "\0l5e:bundle-entry";
|
|
41
|
+
function T(e) {
|
|
42
|
+
return {
|
|
43
|
+
name: "l5e-virtual-entry",
|
|
44
|
+
resolveId(e) {
|
|
45
|
+
return e === w ? w : null;
|
|
46
|
+
},
|
|
47
|
+
load(t) {
|
|
48
|
+
return t === w ? e : null;
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
function E(e) {
|
|
53
|
+
return {
|
|
54
|
+
name: "preserve-build-chunks",
|
|
55
|
+
resolveId(t, n) {
|
|
56
|
+
if (!n || t === w) return null;
|
|
57
|
+
let r = u.isAbsolute(t) ? u.normalize(t) : t.startsWith(".") ? u.resolve(u.dirname(n), t) : null;
|
|
58
|
+
return !r || n === w && !e.isPreserved(r) ? null : {
|
|
59
|
+
id: e.assetUrl(r),
|
|
60
|
+
external: "absolute"
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
async function D(e, t) {
|
|
66
|
+
let n = {
|
|
67
|
+
input: w,
|
|
68
|
+
plugins: [T(e.map((e) => {
|
|
69
|
+
let n = t.fileForScript(e);
|
|
70
|
+
return `import ${JSON.stringify(n)};`;
|
|
71
|
+
}).join("\n")), E(t)],
|
|
72
|
+
platform: "neutral",
|
|
73
|
+
tsconfig: !1,
|
|
74
|
+
treeshake: { moduleSideEffects: () => !0 },
|
|
75
|
+
external: (e) => !e.startsWith(".") && !u.isAbsolute(e) && e !== w
|
|
76
|
+
}, r = {
|
|
77
|
+
format: "es",
|
|
78
|
+
codeSplitting: !0,
|
|
79
|
+
minify: !1,
|
|
80
|
+
entryFileNames: "bundle-[hash].js",
|
|
81
|
+
chunkFileNames: "bundle-[hash].js"
|
|
82
|
+
}, { rolldown: i } = await v(), a = await i(n), o;
|
|
83
|
+
try {
|
|
84
|
+
({output: o} = await a.generate(r));
|
|
85
|
+
} finally {
|
|
86
|
+
await a.close();
|
|
87
|
+
}
|
|
88
|
+
for (let e of o) e.type === "chunk" && b.set(e.fileName, {
|
|
89
|
+
content: e.code || "",
|
|
90
|
+
hash: C(e.code || ""),
|
|
91
|
+
filename: e.fileName,
|
|
92
|
+
mimeType: "application/javascript"
|
|
93
|
+
});
|
|
94
|
+
let s = o.find((e) => e.type === "chunk" && e.isEntry && e.facadeModuleId === w);
|
|
95
|
+
if (!s) throw Error("[bundler] rolldown produced no entry chunk");
|
|
96
|
+
return {
|
|
97
|
+
hash: C(s.code || ""),
|
|
98
|
+
filename: s.fileName,
|
|
99
|
+
content: s.code || ""
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
async function O(e, t, n) {
|
|
103
|
+
if (e.length === 0) return y;
|
|
104
|
+
if (!n || n.directory !== u.resolve(t)) return console.warn("[bundler] No matching build manifest; serving original script entries."), y;
|
|
105
|
+
let r = [...new Set(e)].sort(), i = `scripts:${n.cacheKey}:${JSON.stringify(r)}`;
|
|
106
|
+
try {
|
|
107
|
+
return await S(i, () => D(r, n));
|
|
108
|
+
} catch (e) {
|
|
109
|
+
return console.error("[bundler] Error bundling scripts:", e), y;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
async function k(e, t) {
|
|
113
|
+
let n = [];
|
|
114
|
+
for (let r of e) {
|
|
115
|
+
let e = r.startsWith("/") ? u.join(t, r.substring(1)) : u.join(t, r);
|
|
116
|
+
try {
|
|
117
|
+
let t = await l.readFile(e, "utf-8");
|
|
118
|
+
n.push(`/* ${r} */\n${t}\n`);
|
|
119
|
+
} catch (e) {
|
|
120
|
+
console.warn(`[bundler] Failed to read CSS file: ${r}`, e);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
let r = n.join("\n\n"), i = C(r), a = `bundle-${i}.css`;
|
|
124
|
+
return b.set(a, {
|
|
125
|
+
content: r,
|
|
126
|
+
hash: i,
|
|
127
|
+
filename: a,
|
|
128
|
+
mimeType: "text/css"
|
|
129
|
+
}), {
|
|
130
|
+
hash: i,
|
|
131
|
+
filename: a,
|
|
132
|
+
content: r
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
async function A(e, t) {
|
|
136
|
+
if (e.length === 0) return y;
|
|
137
|
+
let n = [...new Set(e)].sort(), r = `css:${JSON.stringify([u.resolve(t), n])}`;
|
|
138
|
+
try {
|
|
139
|
+
return await S(r, () => k(n, t));
|
|
140
|
+
} catch (e) {
|
|
141
|
+
return console.error("[bundler] Error bundling CSS:", e), y;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
function j(e) {
|
|
145
|
+
return b.get(e);
|
|
146
|
+
}
|
|
147
|
+
//#endregion
|
|
148
|
+
//#region src/core/script-bundle-policy.ts
|
|
149
|
+
function M(e, t, n = "/") {
|
|
150
|
+
let r = u.resolve(t), i = h(r), a = /* @__PURE__ */ new Set(), o = /* @__PURE__ */ new Set(), c = Object.entries(e).filter(([, e]) => /\.[cm]?js$/.test(e.file));
|
|
151
|
+
function l(e) {
|
|
152
|
+
let t = u.resolve(i, e), n = u.relative(i, t);
|
|
153
|
+
if (!n || n === ".." || n.startsWith(`..${u.sep}`) || u.isAbsolute(n)) throw Error(`[bundler] Asset is outside the client output: ${e}`);
|
|
154
|
+
return t;
|
|
155
|
+
}
|
|
156
|
+
for (let [e, t] of c) {
|
|
157
|
+
let n = l(t.file);
|
|
158
|
+
a.add(n), (!t.isEntry || t.isDynamicEntry || e === "src/client.global.ts" || /(?:^|\/)react\//.test(t.src || e)) && o.add(n);
|
|
159
|
+
}
|
|
160
|
+
for (let [, t] of c) for (let n of [...t.imports || [], ...t.dynamicImports || []]) {
|
|
161
|
+
let t = e[n];
|
|
162
|
+
if (!t || !a.has(l(t.file))) throw Error(`[bundler] Missing JavaScript manifest dependency: ${n}`);
|
|
163
|
+
o.add(l(t.file));
|
|
164
|
+
}
|
|
165
|
+
return {
|
|
166
|
+
cacheKey: p("sha256").update(JSON.stringify([
|
|
167
|
+
r,
|
|
168
|
+
i,
|
|
169
|
+
n,
|
|
170
|
+
e
|
|
171
|
+
])).digest("hex"),
|
|
172
|
+
directory: r,
|
|
173
|
+
fileForScript(e) {
|
|
174
|
+
let t = l(e.replace(/^\/+/, ""));
|
|
175
|
+
if (!a.has(t)) throw Error(`[bundler] Script is missing from manifest: ${e}`);
|
|
176
|
+
return t;
|
|
177
|
+
},
|
|
178
|
+
isPreserved(e) {
|
|
179
|
+
return o.has(e);
|
|
180
|
+
},
|
|
181
|
+
assetUrl(e) {
|
|
182
|
+
if (!a.has(e)) throw Error(`[bundler] Import is missing from manifest: ${e}`);
|
|
183
|
+
return s(n, u.relative(i, e).replace(/\\/g, "/"));
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
//#endregion
|
|
188
|
+
//#region src/core/server.ts
|
|
189
|
+
function N(e, t) {
|
|
190
|
+
let r = n(t);
|
|
191
|
+
return e.replace(/<html\b([^>]*)>/i, (e, t) => /\blang\s*=/i.test(t) ? e.replace(/lang\s*=\s*"[^"]*"/i, () => `lang="${r}"`) : `<html lang="${r}"${t}>`);
|
|
192
|
+
}
|
|
193
|
+
function P(e) {
|
|
194
|
+
return new URL(`${e.protocol}://${e.get("host")}${e.originalUrl}`);
|
|
195
|
+
}
|
|
196
|
+
function F(e, t) {
|
|
197
|
+
return `${e.pathname}${e.search}`.replace(t, "") || "/";
|
|
198
|
+
}
|
|
199
|
+
function I(e) {
|
|
200
|
+
let t = {
|
|
201
|
+
method: e.method,
|
|
202
|
+
headers: i(e)
|
|
203
|
+
};
|
|
204
|
+
return e.method !== "GET" && e.method !== "HEAD" && (t.body = e, t.duplex = "half"), new globalThis.Request(P(e).href, t);
|
|
205
|
+
}
|
|
206
|
+
function L(e, t, n, i) {
|
|
207
|
+
let a = new URL(t.url), o = F(a, n), s = o.startsWith("/") ? o : `/${o}`, c = {};
|
|
208
|
+
return t.headers.forEach((e, t) => {
|
|
209
|
+
c[t] = e;
|
|
210
|
+
}), {
|
|
211
|
+
url: a,
|
|
212
|
+
path: s,
|
|
213
|
+
pathname: a.pathname,
|
|
214
|
+
method: t.method,
|
|
215
|
+
headers: c,
|
|
216
|
+
cookies: r(t.headers.get("cookie") ?? void 0),
|
|
217
|
+
query: Object.fromEntries(a.searchParams.entries()),
|
|
218
|
+
ip: f.getClientIp(e) ?? void 0,
|
|
219
|
+
locals: i
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
function R(e, t, n) {
|
|
223
|
+
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;
|
|
224
|
+
}
|
|
225
|
+
async function z(e, t, n) {
|
|
226
|
+
t.status(n.status);
|
|
227
|
+
let r = B(n.headers);
|
|
228
|
+
if (n.headers.forEach((e, n) => {
|
|
229
|
+
n.toLowerCase() !== "set-cookie" && t.setHeader(n, e);
|
|
230
|
+
}), r.length > 0 && t.setHeader("Set-Cookie", r), e.method === "HEAD") {
|
|
231
|
+
t.end();
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
let i = Buffer.from(await n.arrayBuffer());
|
|
235
|
+
t.send(i);
|
|
236
|
+
}
|
|
237
|
+
function B(e) {
|
|
238
|
+
let t = e.getSetCookie;
|
|
239
|
+
if (typeof t == "function") return t.call(e);
|
|
240
|
+
let n = e.raw?.();
|
|
241
|
+
if (n?.["set-cookie"]) return n["set-cookie"];
|
|
242
|
+
let r = e.get("set-cookie");
|
|
243
|
+
return r ? V(r) : [];
|
|
244
|
+
}
|
|
245
|
+
function V(e) {
|
|
246
|
+
let t = [], n = 0;
|
|
247
|
+
for (let r = 0; r < e.length; r++) {
|
|
248
|
+
if (e[r] !== ",") continue;
|
|
249
|
+
let i = e.slice(r + 1);
|
|
250
|
+
/^\s*[^=;,]+=/.test(i) && (t.push(e.slice(n, r).trim()), n = r + 1);
|
|
251
|
+
}
|
|
252
|
+
return t.push(e.slice(n).trim()), t.filter(Boolean);
|
|
253
|
+
}
|
|
254
|
+
function H(e) {
|
|
255
|
+
if (!e.rawResponse) return null;
|
|
256
|
+
let { body: t, contentType: n, statusCode: r, headers: i } = e.rawResponse, a = new Headers(i);
|
|
257
|
+
return a.set("Content-Type", n), new globalThis.Response(t, {
|
|
258
|
+
status: r || 200,
|
|
259
|
+
headers: a
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
async function U({ rendered: e, template: t, manifest: r, root: i, distClientDir: a, isProduction: l, assetBase: d, scriptPolicy: f }) {
|
|
263
|
+
let p = H(e);
|
|
264
|
+
if (p) return p;
|
|
265
|
+
if (e.redirect) return new globalThis.Response(null, {
|
|
266
|
+
status: e.redirect.statusCode,
|
|
267
|
+
headers: { Location: e.redirect.url }
|
|
268
|
+
});
|
|
269
|
+
let m = e.scripts || [], h = e.styles || [], _ = e.islands || [], v = e.cacheTags || [], y = e.maxAge, b = e.sMaxAge, x = e.swr, S = "", C = /* @__PURE__ */ new Set(), w = (e, t = !1) => {
|
|
270
|
+
C.has(e) || (C.add(e), S += `<link rel="stylesheet"${t ? " crossorigin" : ""} href="${n(e)}">`);
|
|
271
|
+
}, T = [], E = "", D = o({
|
|
272
|
+
root: i,
|
|
273
|
+
manifest: r,
|
|
274
|
+
isProduction: l,
|
|
275
|
+
base: d
|
|
276
|
+
});
|
|
277
|
+
D && w(D, l);
|
|
278
|
+
let k = "";
|
|
279
|
+
if (e.islandData && e.islandData.length > 0 && (k = `<script type="application/json" id="_l5e_data_">${(0, g.default)(e.islandData, { isJSON: !0 })}<\/script>`), l && r) {
|
|
280
|
+
m = m.filter((e) => e.replace(/^\//, "") !== "src/client.global.ts"), h = h.filter((e) => !e.includes(".global."));
|
|
281
|
+
let e = /* @__PURE__ */ new Set(), t = /* @__PURE__ */ new Set();
|
|
282
|
+
function n(n) {
|
|
283
|
+
let i = r[n];
|
|
284
|
+
return i ? (i.css && i.css.forEach((t) => e.add(t)), i.imports && i.imports.forEach((n) => {
|
|
285
|
+
let i = r[n];
|
|
286
|
+
i?.file && t.add(i.file), i?.css && i.css.forEach((t) => e.add(t)), i?.imports && i.imports.forEach((n) => {
|
|
287
|
+
let i = r[n];
|
|
288
|
+
i?.file && t.add(i.file), i?.css && i.css.forEach((t) => e.add(t));
|
|
289
|
+
});
|
|
290
|
+
}), { file: i.file }) : { file: null };
|
|
291
|
+
}
|
|
292
|
+
let i = [];
|
|
293
|
+
for (let e of m) {
|
|
294
|
+
let { file: t } = n(e.replace(/^\//, ""));
|
|
295
|
+
t && i.push(`/${t}`);
|
|
296
|
+
}
|
|
297
|
+
let o = [];
|
|
298
|
+
for (let t of h) {
|
|
299
|
+
let { file: r } = n(t.replace(/^\//, ""));
|
|
300
|
+
r && (o.push(`/${r}`), e.add(r));
|
|
301
|
+
}
|
|
302
|
+
if (i.length > 0) {
|
|
303
|
+
let e = await O(i, a, f);
|
|
304
|
+
m = e.filename ? [s(d, e.filename)] : i.map((e) => s(d, e));
|
|
305
|
+
}
|
|
306
|
+
if (o.length > 0) {
|
|
307
|
+
let e = await A(o, a);
|
|
308
|
+
e.filename && (h = [s(d, e.filename)]);
|
|
309
|
+
}
|
|
310
|
+
let c = r["src/client.global.ts"];
|
|
311
|
+
if (c && (c.css && c.css.length > 0 && c.css.forEach((e) => {
|
|
312
|
+
w(s(d, e), !0);
|
|
313
|
+
}), c.file && T.push(s(d, c.file))), _.length > 0) {
|
|
314
|
+
let e = {};
|
|
315
|
+
for (let t of _) {
|
|
316
|
+
let n = r[t.src];
|
|
317
|
+
n?.file && (e[t.key] = s(d, n.file));
|
|
318
|
+
}
|
|
319
|
+
Object.keys(e).length > 0 && (E = `<script>window.__L5E_ISLANDS__=${(0, g.default)(e)}<\/script>`);
|
|
320
|
+
}
|
|
321
|
+
h.length > 0 && h.forEach((e) => w(e, !0));
|
|
322
|
+
}
|
|
323
|
+
l || [...new Set(h)].forEach((e) => w(e));
|
|
324
|
+
let j = [...T, ...m];
|
|
325
|
+
if (!l) {
|
|
326
|
+
let e = u.join(i, "src", "client.global.ts");
|
|
327
|
+
if (c(e) && (j = ["/src/client.global.ts", ...j]), j = [...new Set(j)], _.length > 0) {
|
|
328
|
+
let e = {};
|
|
329
|
+
for (let t of _) e[t.key] = `/${t.src}`;
|
|
330
|
+
E = `<script>window.__L5E_ISLANDS__=${(0, g.default)(e)}<\/script>`;
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
let M = k + E + j.map((e) => `<script type="module" src="${e}"><\/script>`).join(""), P = e.lang ? N(t, e.lang) : t, F = e.rawHtml ? e.html || "" : P.replace("<!--app-head-->", () => (e.head ?? "") + S).replace("<!--app-html-->", () => e.html ?? "").replace("<!--app-scripts-->", () => M), I = new Headers({ "Content-Type": "text/html" }), L = [], R = [];
|
|
334
|
+
return y !== void 0 && (L.push(`max-age=${y}`), R.push(`max-age=${y}`)), b !== void 0 && R.push(`s-maxage=${b}`), x !== void 0 && R.push(`stale-while-revalidate=${x}`), (L.length > 0 || R.length > 0) && l && (L.push("public"), L.push("must-revalidate"), R.push("public"), I.set("Cache-Control", L.join(", ")), I.set("CDN-Cache-Control", R.join(", "))), process.env.NODE_ENV === "production" && (v = J(v)), I.set("Cache-Tag", ["global", ...v].join(",")), new globalThis.Response(F, {
|
|
335
|
+
status: e.statusCode || 200,
|
|
336
|
+
headers: I
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
async function W(e = {}) {
|
|
340
|
+
let t = e.root || process.cwd(), n = e.base || "/", i = process.env.NODE_ENV === "production", o = e.externalizeIslandProps ?? !0, p = i ? await l.readFile(u.join(t, "./index.html"), "utf-8") : "", m = (await import("express")).default, h = e.app || m();
|
|
341
|
+
if (e.publicDir) {
|
|
342
|
+
let n = u.isAbsolute(e.publicDir) ? e.publicDir : u.join(t, e.publicDir);
|
|
343
|
+
c(n) && h.use(m.static(n));
|
|
344
|
+
}
|
|
345
|
+
let g, _ = u.join(t, "./dist/client"), v = i ? JSON.parse(await l.readFile(u.join(_, ".vite/manifest.json"), "utf-8")) : void 0, y;
|
|
346
|
+
if (v) try {
|
|
347
|
+
y = M(v, _, n);
|
|
348
|
+
} catch (e) {
|
|
349
|
+
console.warn("[bundler] Invalid build manifest; serving original script entries.", e);
|
|
350
|
+
}
|
|
351
|
+
if (i) {
|
|
352
|
+
let e = (await import("compression")).default, t = (await import("sirv")).default;
|
|
353
|
+
h.use(e()), h.use(n, t(_, { extensions: [] })), h.get(s(n, "bundle-:hash.:ext"), async (e, t) => {
|
|
354
|
+
try {
|
|
355
|
+
let { hash: n, ext: r } = e.params, i = j(`bundle-${n}.${r}`);
|
|
356
|
+
if (!i) return t.status(404).send("Bundled file not found");
|
|
357
|
+
t.set({
|
|
358
|
+
"Content-Type": i.mimeType,
|
|
359
|
+
"Cache-Control": "public, max-age=31536000, immutable"
|
|
360
|
+
}), t.send(i.content);
|
|
361
|
+
} catch (e) {
|
|
362
|
+
console.error("[server] Error serving bundled file:", e), t.status(500).end("Internal server error");
|
|
363
|
+
}
|
|
364
|
+
});
|
|
365
|
+
} else {
|
|
366
|
+
let { createServer: e } = await import("vite");
|
|
367
|
+
g = await e({
|
|
368
|
+
root: t,
|
|
369
|
+
configFile: u.join(t, "vite.config.js"),
|
|
370
|
+
server: { middlewareMode: !0 },
|
|
371
|
+
appType: "custom",
|
|
372
|
+
base: n,
|
|
373
|
+
optimizeDeps: { exclude: ["@withl5e/l5e", "file-type"] },
|
|
374
|
+
ssr: { resolve: { conditions: ["development", "default"] } },
|
|
375
|
+
resolve: { conditions: ["development", "default"] }
|
|
376
|
+
}), h.use(g.middlewares);
|
|
377
|
+
}
|
|
378
|
+
h.use("/_l5e/action", m.json({ limit: "100kb" }));
|
|
379
|
+
let b = /^[a-zA-Z]\w+_[0-9a-f]{1,4}$/, x = null, S = null;
|
|
380
|
+
async function C() {
|
|
381
|
+
if (!i) return (await g.ssrLoadModule("virtual:l5e-actions")).actionRegistry || {};
|
|
382
|
+
if (!x) {
|
|
383
|
+
let e = u.join(t, "./dist/server/action-registry.json"), n = await l.readFile(e, "utf-8");
|
|
384
|
+
x = JSON.parse(n);
|
|
385
|
+
}
|
|
386
|
+
return x;
|
|
387
|
+
}
|
|
388
|
+
async function w() {
|
|
389
|
+
if (!i) return (await g.ssrLoadModule("virtual:l5e-actions")).viewActions || {};
|
|
390
|
+
if (!S) {
|
|
391
|
+
let e = u.join(t, "./dist/server/entry-server.js");
|
|
392
|
+
S = (await import(d(e).href)).viewActions || {};
|
|
393
|
+
}
|
|
394
|
+
return S;
|
|
395
|
+
}
|
|
396
|
+
return h.all("/_l5e/action/:actionKey", async (e, r) => {
|
|
397
|
+
try {
|
|
398
|
+
let { actionKey: o } = e.params;
|
|
399
|
+
if (!b.test(o)) return r.status(400).send("Invalid action key");
|
|
400
|
+
let s = (await C())[o];
|
|
401
|
+
if (!s) return r.status(404).send("Action not found");
|
|
402
|
+
let { modulePath: c, actionName: l } = s, p;
|
|
403
|
+
if (i) {
|
|
404
|
+
let e = await w(), t = e[`/src/${c}/actions.tsx`] ? `/src/${c}/actions.tsx` : e[`/src/${c}/actions.ts`] ? `/src/${c}/actions.ts` : null;
|
|
405
|
+
if (!t) return r.status(404).send("Action module not found");
|
|
406
|
+
p = await e[t]();
|
|
407
|
+
} else try {
|
|
408
|
+
p = await g.ssrLoadModule(`/src/${c}/actions.tsx`);
|
|
409
|
+
} catch {
|
|
410
|
+
p = await g.ssrLoadModule(`/src/${c}/actions.ts`);
|
|
411
|
+
}
|
|
412
|
+
if (!Object.prototype.hasOwnProperty.call(p, l)) return r.status(404).send("Action not found");
|
|
413
|
+
let m = p[l];
|
|
414
|
+
if (!m || !m.handler) return r.status(404).send("Action not found");
|
|
415
|
+
let h = (m.method || "GET").toUpperCase();
|
|
416
|
+
if (e.method.toUpperCase() !== h) return r.status(405).set("Allow", h).send("Method Not Allowed");
|
|
417
|
+
let _ = u.join(t, "./dist/server/entry-server.js"), v = i ? await import(d(_).href) : await g.ssrLoadModule("@withl5e/l5e/entry-server"), { runInRenderContext: y } = await (i ? import(d(_).href) : g.ssrLoadModule("@withl5e/l5e/jsx-runtime")), { renderJsxToHtmlString: x } = await (i ? import(d(_).href) : g.ssrLoadModule("@withl5e/l5e")), S = {}, T = I(e), E = a({
|
|
418
|
+
request: T,
|
|
419
|
+
locals: S,
|
|
420
|
+
clientAddress: f.getClientIp(e) ?? void 0
|
|
421
|
+
}), D = await v.loadMiddleware?.();
|
|
422
|
+
await z(e, r, await (typeof D == "function" ? D : (e, t) => t())(E, async (t) => {
|
|
423
|
+
let r = {
|
|
424
|
+
...L(e, R(t, E.request, E.url), n, S),
|
|
425
|
+
path: e.originalUrl,
|
|
426
|
+
body: e.body
|
|
427
|
+
}, i = await y(async () => {
|
|
428
|
+
let e = await m.handler(r);
|
|
429
|
+
return x(e);
|
|
430
|
+
}, r, c);
|
|
431
|
+
return new Response(i, { headers: { "Content-Type": "text/html" } });
|
|
432
|
+
}));
|
|
433
|
+
} catch (e) {
|
|
434
|
+
g?.ssrFixStacktrace?.(e), console.error("[l5e] Action error:", e.stack || e), r.status(500).send("Internal server error");
|
|
435
|
+
}
|
|
436
|
+
}), h.use(async (e, s) => {
|
|
437
|
+
try {
|
|
438
|
+
let c = e.originalUrl.replace(n, ""), m, h, b, x;
|
|
439
|
+
if (i) {
|
|
440
|
+
m = p;
|
|
441
|
+
let e = u.join(t, "./dist/server/entry-server.js"), n = await import(d(e).href);
|
|
442
|
+
h = n.render, b = n.loadMiddleware, x = v;
|
|
443
|
+
} else {
|
|
444
|
+
m = await l.readFile(u.join(t, "./index.html"), "utf-8"), m = await g.transformIndexHtml(c, m), m.includes("@vite/client") || (m = m.replace("</head>", "<script type=\"module\" src=\"/@vite/client\"><\/script></head>"));
|
|
445
|
+
let e = await g.ssrLoadModule("@withl5e/l5e/entry-server");
|
|
446
|
+
h = e.render, b = e.loadMiddleware;
|
|
447
|
+
}
|
|
448
|
+
let S = await b?.(), C = typeof S == "function" ? S : (e, t) => t(), w = {}, T = I(e), E = a({
|
|
449
|
+
request: T,
|
|
450
|
+
requestInfo: L(e, T, n, w),
|
|
451
|
+
locals: w,
|
|
452
|
+
clientAddress: f.getClientIp(e)
|
|
453
|
+
}), D = async (r) => {
|
|
454
|
+
let a = L(e, r, n, w), s = F(a.url, n);
|
|
455
|
+
return U({
|
|
456
|
+
rendered: await h(s, a, { externalizeIslandProps: o }),
|
|
457
|
+
template: m,
|
|
458
|
+
manifest: x,
|
|
459
|
+
root: t,
|
|
460
|
+
distClientDir: _,
|
|
461
|
+
isProduction: i,
|
|
462
|
+
assetBase: i ? n : g.config.base,
|
|
463
|
+
scriptPolicy: y
|
|
464
|
+
});
|
|
465
|
+
}, O = async (t) => {
|
|
466
|
+
let i = R(t, E.request, E.url);
|
|
467
|
+
return E.request = i, E.url = new URL(i.url), E.cookies = r(i.headers.get("cookie") ?? void 0), E.requestInfo = L(e, i, n, w), D(i);
|
|
468
|
+
};
|
|
469
|
+
E.rewrite = (e) => O(e), await z(e, s, await C(E, O));
|
|
470
|
+
} catch (e) {
|
|
471
|
+
g?.ssrFixStacktrace?.(e), console.error(e.stack), s.status(500).end(i ? "Internal Server Error" : e.stack);
|
|
472
|
+
}
|
|
473
|
+
}), {
|
|
474
|
+
app: h,
|
|
475
|
+
vite: g
|
|
476
|
+
};
|
|
477
|
+
}
|
|
478
|
+
async function G(e = {}) {
|
|
479
|
+
let t = e.port || 5173, n = (await import("express")).default, r = n();
|
|
480
|
+
e.setupApp && (console.log("setupApp"), await e.setupApp(r));
|
|
481
|
+
let { app: i } = await W({
|
|
482
|
+
...e,
|
|
483
|
+
app: r
|
|
484
|
+
});
|
|
485
|
+
i.listen(t, () => {
|
|
486
|
+
console.log(`Server started at http://localhost:${t}`);
|
|
487
|
+
});
|
|
488
|
+
}
|
|
489
|
+
var K = 1e3;
|
|
490
|
+
function q(e) {
|
|
491
|
+
if (e === "global") return "global";
|
|
492
|
+
let t = 0;
|
|
493
|
+
for (let n = 0; n < e.length; n++) {
|
|
494
|
+
let r = e.charCodeAt(n);
|
|
495
|
+
t = (t << 5) - t + r, t &= t;
|
|
496
|
+
}
|
|
497
|
+
return Math.abs(t).toString(36).substring(0, 8);
|
|
498
|
+
}
|
|
499
|
+
function J(e) {
|
|
500
|
+
return (Array.isArray(e) ? e : [...e]).slice(0, K).map(q);
|
|
501
|
+
}
|
|
502
|
+
//#endregion
|
|
503
|
+
export { G as a, J as i, W as n, q as r, N as t };
|
|
504
|
+
|
|
505
|
+
//# sourceMappingURL=server-DPBLtja1.js.map
|