@demiurgejs/core 0.0.0 → 0.1.1
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/LICENSE +21 -0
- package/README.md +75 -2
- package/dist/adapter/index.d.ts +20 -0
- package/dist/adapter/index.d.ts.map +1 -0
- package/dist/browser/file-router.d.ts +35 -0
- package/dist/browser/file-router.d.ts.map +1 -0
- package/dist/browser/index.d.ts +3 -0
- package/dist/browser/index.d.ts.map +1 -0
- package/dist/chunks/index-BnX9Qxbm.js +44 -0
- package/dist/chunks/index-BnX9Qxbm.js.map +1 -0
- package/dist/chunks/ssr-BJejKlkZ.js +275 -0
- package/dist/chunks/ssr-BJejKlkZ.js.map +1 -0
- package/dist/chunks/static-files-DUjHw-4H.js +11 -0
- package/dist/chunks/static-files-DUjHw-4H.js.map +1 -0
- package/dist/chunks/streaming-DN1DnbRE.js +343 -0
- package/dist/chunks/streaming-DN1DnbRE.js.map +1 -0
- package/dist/chunks/testing-DR3eQAvY.js +2872 -0
- package/dist/chunks/testing-DR3eQAvY.js.map +1 -0
- package/dist/data/cache.d.ts +95 -0
- package/dist/data/cache.d.ts.map +1 -0
- package/dist/data/idempotency.d.ts +24 -0
- package/dist/data/idempotency.d.ts.map +1 -0
- package/dist/data/index.d.ts +5 -0
- package/dist/data/index.d.ts.map +1 -0
- package/dist/data/testing.d.ts +7 -0
- package/dist/data/testing.d.ts.map +1 -0
- package/dist/data/testing.js +134 -0
- package/dist/data/testing.js.map +1 -0
- package/dist/document/hydration.d.ts +13 -0
- package/dist/document/hydration.d.ts.map +1 -0
- package/dist/document/index.d.ts +13 -0
- package/dist/document/index.d.ts.map +1 -0
- package/dist/document/links.d.ts +17 -0
- package/dist/document/links.d.ts.map +1 -0
- package/dist/document/metadata.d.ts +62 -0
- package/dist/document/metadata.d.ts.map +1 -0
- package/dist/document/render.d.ts +29 -0
- package/dist/document/render.d.ts.map +1 -0
- package/dist/document/scripts.d.ts +24 -0
- package/dist/document/scripts.d.ts.map +1 -0
- package/dist/document/seo.d.ts +42 -0
- package/dist/document/seo.d.ts.map +1 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1328 -0
- package/dist/index.js.map +1 -0
- package/dist/internal/testing.d.ts +3 -0
- package/dist/internal/testing.d.ts.map +1 -0
- package/dist/internal/testing.js +22 -0
- package/dist/internal/testing.js.map +1 -0
- package/dist/node/http.d.ts +28 -0
- package/dist/node/http.d.ts.map +1 -0
- package/dist/node/index.d.ts +45 -0
- package/dist/node/index.d.ts.map +1 -0
- package/dist/node/index.js +386 -0
- package/dist/node/index.js.map +1 -0
- package/dist/node/static.d.ts +9 -0
- package/dist/node/static.d.ts.map +1 -0
- package/dist/node/streaming.d.ts +5 -0
- package/dist/node/streaming.d.ts.map +1 -0
- package/dist/package-name.d.ts +2 -0
- package/dist/package-name.d.ts.map +1 -0
- package/dist/platform/analytics.d.ts +20 -0
- package/dist/platform/analytics.d.ts.map +1 -0
- package/dist/platform/fonts.d.ts +35 -0
- package/dist/platform/fonts.d.ts.map +1 -0
- package/dist/platform/images.d.ts +49 -0
- package/dist/platform/images.d.ts.map +1 -0
- package/dist/platform/index.d.ts +9 -0
- package/dist/platform/index.d.ts.map +1 -0
- package/dist/platform/observability.d.ts +60 -0
- package/dist/platform/observability.d.ts.map +1 -0
- package/dist/route/action.d.ts +33 -0
- package/dist/route/action.d.ts.map +1 -0
- package/dist/route/http-error.d.ts +24 -0
- package/dist/route/http-error.d.ts.map +1 -0
- package/dist/route/index.d.ts +10 -0
- package/dist/route/index.d.ts.map +1 -0
- package/dist/route/page.d.ts +5 -0
- package/dist/route/page.d.ts.map +1 -0
- package/dist/route/response.d.ts +100 -0
- package/dist/route/response.d.ts.map +1 -0
- package/dist/route/types.d.ts +186 -0
- package/dist/route/types.d.ts.map +1 -0
- package/dist/route/webhook.d.ts +25 -0
- package/dist/route/webhook.d.ts.map +1 -0
- package/dist/router/index.d.ts +5 -0
- package/dist/router/index.d.ts.map +1 -0
- package/dist/router/manifest.d.ts +119 -0
- package/dist/router/manifest.d.ts.map +1 -0
- package/dist/router/navigation-data.d.ts +9 -0
- package/dist/router/navigation-data.d.ts.map +1 -0
- package/dist/routing/generate.d.ts +14 -0
- package/dist/routing/generate.d.ts.map +1 -0
- package/dist/routing/index.d.ts +3 -0
- package/dist/routing/index.d.ts.map +1 -0
- package/dist/routing/types.d.ts +38 -0
- package/dist/routing/types.d.ts.map +1 -0
- package/dist/security/audit.d.ts +16 -0
- package/dist/security/audit.d.ts.map +1 -0
- package/dist/security/cors.d.ts +7 -0
- package/dist/security/cors.d.ts.map +1 -0
- package/dist/security/csrf.d.ts +15 -0
- package/dist/security/csrf.d.ts.map +1 -0
- package/dist/security/env.d.ts +69 -0
- package/dist/security/env.d.ts.map +1 -0
- package/dist/security/index.d.ts +17 -0
- package/dist/security/index.d.ts.map +1 -0
- package/dist/security/policy.d.ts +18 -0
- package/dist/security/policy.d.ts.map +1 -0
- package/dist/security/rate-limit.d.ts +6 -0
- package/dist/security/rate-limit.d.ts.map +1 -0
- package/dist/security/report.d.ts +13 -0
- package/dist/security/report.d.ts.map +1 -0
- package/dist/security/request.d.ts +11 -0
- package/dist/security/request.d.ts.map +1 -0
- package/dist/security/types.d.ts +137 -0
- package/dist/security/types.d.ts.map +1 -0
- package/dist/security/upload.d.ts +23 -0
- package/dist/security/upload.d.ts.map +1 -0
- package/dist/security/websocket.d.ts +13 -0
- package/dist/security/websocket.d.ts.map +1 -0
- package/dist/server/errors.d.ts +13 -0
- package/dist/server/errors.d.ts.map +1 -0
- package/dist/server/failure-site.d.ts +2 -0
- package/dist/server/failure-site.d.ts.map +1 -0
- package/dist/server/fallbacks.d.ts +10 -0
- package/dist/server/fallbacks.d.ts.map +1 -0
- package/dist/server/index.d.ts +14 -0
- package/dist/server/index.d.ts.map +1 -0
- package/dist/server/negotiate.d.ts +3 -0
- package/dist/server/negotiate.d.ts.map +1 -0
- package/dist/server/not-found.d.ts +11 -0
- package/dist/server/not-found.d.ts.map +1 -0
- package/dist/server/problem.d.ts +18 -0
- package/dist/server/problem.d.ts.map +1 -0
- package/dist/server/render-tree.d.ts +4 -0
- package/dist/server/render-tree.d.ts.map +1 -0
- package/dist/server/request-handler.d.ts +40 -0
- package/dist/server/request-handler.d.ts.map +1 -0
- package/dist/server/request-metadata.d.ts +7 -0
- package/dist/server/request-metadata.d.ts.map +1 -0
- package/dist/server/ssr.d.ts +17 -0
- package/dist/server/ssr.d.ts.map +1 -0
- package/dist/static/index.d.ts +28 -0
- package/dist/static/index.d.ts.map +1 -0
- package/dist/static/index.js +377 -0
- package/dist/static/index.js.map +1 -0
- package/dist/static-files.d.ts +5 -0
- package/dist/static-files.d.ts.map +1 -0
- package/dist/vite/index.d.ts +4 -0
- package/dist/vite/index.d.ts.map +1 -0
- package/dist/vite/index.js +746 -0
- package/dist/vite/index.js.map +1 -0
- package/dist/vite/plugin.d.ts +37 -0
- package/dist/vite/plugin.d.ts.map +1 -0
- package/package.json +93 -4
|
@@ -0,0 +1,746 @@
|
|
|
1
|
+
import { existsSync as U } from "node:fs";
|
|
2
|
+
import { mkdir as tt, writeFile as et, readdir as B, readFile as rt } from "node:fs/promises";
|
|
3
|
+
import { dirname as G, resolve as p, relative as g, sep as $, join as nt } from "node:path";
|
|
4
|
+
import ot from "magic-string";
|
|
5
|
+
import { parseAst as Y } from "vite";
|
|
6
|
+
import { b as st, d as it } from "../chunks/ssr-BJejKlkZ.js";
|
|
7
|
+
import { e as x, r as at, f as ct, h as ut, c as lt } from "../chunks/testing-DR3eQAvY.js";
|
|
8
|
+
import "react";
|
|
9
|
+
import "react-dom/server";
|
|
10
|
+
import "react/jsx-runtime";
|
|
11
|
+
import { t as I, U as O, w as _, b as F, c as ft } from "../chunks/streaming-DN1DnbRE.js";
|
|
12
|
+
const h = "@demiurgejs/core";
|
|
13
|
+
async function dt(t) {
|
|
14
|
+
const n = (await pt(t.routesDir)).map((r) => mt(t.routesDir, r)).filter((r) => !!r).sort((r, s) => r.pattern.localeCompare(s.pattern)), o = yt(n);
|
|
15
|
+
return await tt(G(t.outputFile), { recursive: !0 }), await et(t.outputFile, o), {
|
|
16
|
+
routes: n,
|
|
17
|
+
source: o
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
async function pt(t) {
|
|
21
|
+
return (await B(t, {
|
|
22
|
+
recursive: !0,
|
|
23
|
+
withFileTypes: !0
|
|
24
|
+
})).filter((n) => n.isFile() && /\.tsx?$/.test(n.name)).map((n) => p(n.parentPath, n.name));
|
|
25
|
+
}
|
|
26
|
+
function mt(t, e) {
|
|
27
|
+
const o = g(t, e).split($).join("/").replace(/\.tsx?$/, "").split("/");
|
|
28
|
+
if (o.at(-1)?.startsWith("@"))
|
|
29
|
+
return null;
|
|
30
|
+
const s = o.flatMap((i) => P(i) ? [] : i === "index" ? [] : i.startsWith("[...") && i.endsWith("]") ? [i] : i.startsWith("[") && i.endsWith("]") ? [i] : [i]);
|
|
31
|
+
return {
|
|
32
|
+
pathVars: o.flatMap((i) => P(i) ? [] : i.startsWith("[...") && i.endsWith("]") ? [i.slice(4, -1)] : i.startsWith("[") && i.endsWith("]") ? [i.slice(1, -1)] : []),
|
|
33
|
+
pattern: `/${s.join("/")}`.replace(/\/$/, "") || "/"
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
function P(t) {
|
|
37
|
+
return t.startsWith("(") && t.endsWith(")");
|
|
38
|
+
}
|
|
39
|
+
function yt(t) {
|
|
40
|
+
return `// Generated by Demiurge. Do not edit by hand.
|
|
41
|
+
import "${h}";
|
|
42
|
+
import type { PathValue } from "${h}";
|
|
43
|
+
|
|
44
|
+
declare module "${h}" {
|
|
45
|
+
interface RoutePathVars {
|
|
46
|
+
${t.map(ht).join(`
|
|
47
|
+
`)}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
interface RouteConcretePaths {
|
|
51
|
+
${t.map(gt).join(`
|
|
52
|
+
`)}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export {};
|
|
57
|
+
`;
|
|
58
|
+
}
|
|
59
|
+
function ht(t) {
|
|
60
|
+
if (t.pathVars.length === 0)
|
|
61
|
+
return ` ${JSON.stringify(t.pattern)}: {};`;
|
|
62
|
+
const e = t.pathVars.map((n) => `${n}: PathValue`).join("; ");
|
|
63
|
+
return ` ${JSON.stringify(t.pattern)}: { ${e} };`;
|
|
64
|
+
}
|
|
65
|
+
function gt(t) {
|
|
66
|
+
return ` ${JSON.stringify(t.pattern)}: ${Rt(t.pattern)};`;
|
|
67
|
+
}
|
|
68
|
+
function Rt(t) {
|
|
69
|
+
return t.includes("[") ? `\`${t.split(/(\[\.\.\.[^\]]+\]|\[[^\]]+\])/g).filter(Boolean).map((n) => n.startsWith("[") ? "${PathValue}" : wt(n)).join("")}\`` : JSON.stringify(t);
|
|
70
|
+
}
|
|
71
|
+
function wt(t) {
|
|
72
|
+
return t.replace(/[`$\\]/g, "\\$&");
|
|
73
|
+
}
|
|
74
|
+
const E = "virtual:demiurge/client-entry", v = `/@id/${E}`, D = `\0${E}`, q = "virtual:demiurge/server-entry", M = `\0${q}`, C = ".demiurge/route-manifest.d.ts";
|
|
75
|
+
function ue(t = {}) {
|
|
76
|
+
let e = process.cwd(), n = !1;
|
|
77
|
+
const o = `demiurge-${x()}`;
|
|
78
|
+
return {
|
|
79
|
+
enforce: "post",
|
|
80
|
+
name: "demiurge",
|
|
81
|
+
config(r, s) {
|
|
82
|
+
return It(r, s, o);
|
|
83
|
+
},
|
|
84
|
+
configResolved(r) {
|
|
85
|
+
e = r.root, n = r.command === "build";
|
|
86
|
+
},
|
|
87
|
+
resolveId(r) {
|
|
88
|
+
return r === E ? D : r === q ? M : null;
|
|
89
|
+
},
|
|
90
|
+
load(r) {
|
|
91
|
+
return r === D ? Ot(e, t) : r === M ? _t(e, t) : null;
|
|
92
|
+
},
|
|
93
|
+
transform: {
|
|
94
|
+
order: "post",
|
|
95
|
+
handler(r, s, a) {
|
|
96
|
+
if (!Et(e, t, s))
|
|
97
|
+
return null;
|
|
98
|
+
if (a?.ssr)
|
|
99
|
+
return n ? null : $t(r, s);
|
|
100
|
+
const i = bt(r);
|
|
101
|
+
return i === r ? null : { code: i, map: null };
|
|
102
|
+
}
|
|
103
|
+
},
|
|
104
|
+
generateBundle(r, s) {
|
|
105
|
+
const a = Object.values(s).find(
|
|
106
|
+
(c) => c.type === "chunk" && c.isEntry && c.facadeModuleId === D
|
|
107
|
+
);
|
|
108
|
+
if (!a)
|
|
109
|
+
return;
|
|
110
|
+
const i = Object.values(s).filter(
|
|
111
|
+
(c) => c.type === "asset" && c.fileName.endsWith(".css")
|
|
112
|
+
).map((c) => `/${c.fileName}`), u = `/${a.fileName}`;
|
|
113
|
+
this.emitFile({
|
|
114
|
+
fileName: "index.html",
|
|
115
|
+
source: qt({
|
|
116
|
+
entrySrc: u,
|
|
117
|
+
lang: t.document?.lang,
|
|
118
|
+
styles: i,
|
|
119
|
+
title: t.document?.title
|
|
120
|
+
}),
|
|
121
|
+
type: "asset"
|
|
122
|
+
}), this.emitFile({
|
|
123
|
+
fileName: "demiurge-manifest.json",
|
|
124
|
+
source: JSON.stringify({ clientEntry: u, styles: i }, null, 2),
|
|
125
|
+
type: "asset"
|
|
126
|
+
});
|
|
127
|
+
},
|
|
128
|
+
async buildStart() {
|
|
129
|
+
n && await Ht(e, t), t.typedRoutes && await w(e, t);
|
|
130
|
+
},
|
|
131
|
+
configureServer(r) {
|
|
132
|
+
if (t.typedRoutes) {
|
|
133
|
+
const s = p(
|
|
134
|
+
r.config.root,
|
|
135
|
+
t.routesDir ?? "src/routes"
|
|
136
|
+
);
|
|
137
|
+
w(r.config.root, t), r.watcher.add(s), r.watcher.on("add", (a) => {
|
|
138
|
+
N(s, a) && w(r.config.root, t);
|
|
139
|
+
}), r.watcher.on("change", (a) => {
|
|
140
|
+
N(s, a) && w(r.config.root, t);
|
|
141
|
+
}), r.watcher.on("unlink", (a) => {
|
|
142
|
+
N(s, a) && w(r.config.root, t);
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
return r.middlewares.use(async (s, a, i) => {
|
|
146
|
+
try {
|
|
147
|
+
let u;
|
|
148
|
+
try {
|
|
149
|
+
u = I(s, {
|
|
150
|
+
// Vite performs its own configured host allowlist check before
|
|
151
|
+
// Demiurge's middleware runs. Production Node listeners require
|
|
152
|
+
// an explicit application allowlist instead.
|
|
153
|
+
allowedHosts: [s.headers.host ?? "localhost"]
|
|
154
|
+
});
|
|
155
|
+
} catch (R) {
|
|
156
|
+
if (R instanceof O) {
|
|
157
|
+
_(a);
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
throw R;
|
|
161
|
+
}
|
|
162
|
+
const c = p(
|
|
163
|
+
r.config.root,
|
|
164
|
+
t.routesDir ?? "src/routes"
|
|
165
|
+
), l = await k(r, s, c), d = j(
|
|
166
|
+
r,
|
|
167
|
+
o
|
|
168
|
+
), y = await zt(
|
|
169
|
+
l,
|
|
170
|
+
u,
|
|
171
|
+
Tt(t, d.transform)
|
|
172
|
+
);
|
|
173
|
+
if (y === "next") {
|
|
174
|
+
i();
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
W(y, d.nonce), await F(a, y);
|
|
178
|
+
} catch (u) {
|
|
179
|
+
i(u);
|
|
180
|
+
}
|
|
181
|
+
}), () => {
|
|
182
|
+
r.middlewares.use(async (s, a, i) => {
|
|
183
|
+
try {
|
|
184
|
+
let u;
|
|
185
|
+
try {
|
|
186
|
+
u = I(s, {
|
|
187
|
+
allowedHosts: [s.headers.host ?? "localhost"]
|
|
188
|
+
});
|
|
189
|
+
} catch (R) {
|
|
190
|
+
if (R instanceof O) {
|
|
191
|
+
_(a);
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
throw R;
|
|
195
|
+
}
|
|
196
|
+
const c = p(
|
|
197
|
+
r.config.root,
|
|
198
|
+
t.routesDir ?? "src/routes"
|
|
199
|
+
), l = await k(r, s, c);
|
|
200
|
+
kt(l, c);
|
|
201
|
+
const d = j(
|
|
202
|
+
r,
|
|
203
|
+
o
|
|
204
|
+
), y = await at(
|
|
205
|
+
l,
|
|
206
|
+
u,
|
|
207
|
+
Lt(t, d.transform)
|
|
208
|
+
);
|
|
209
|
+
W(
|
|
210
|
+
y,
|
|
211
|
+
d.nonce
|
|
212
|
+
), await F(a, y);
|
|
213
|
+
} catch (u) {
|
|
214
|
+
i(u);
|
|
215
|
+
}
|
|
216
|
+
});
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
function $t(t, e) {
|
|
222
|
+
if (!t.includes("import.meta"))
|
|
223
|
+
return null;
|
|
224
|
+
const n = Y(t), o = m(n.body).find(
|
|
225
|
+
(c) => c.type === "ImportDeclaration" && m(c.specifiers).some(
|
|
226
|
+
(l) => f(l.local)?.type === "Identifier" && f(l.local)?.name === "meta"
|
|
227
|
+
)
|
|
228
|
+
), r = o && m(o.specifiers).find(
|
|
229
|
+
(c) => f(c.local)?.type === "Identifier" && f(c.local)?.name === "meta"
|
|
230
|
+
), s = r && f(r.local);
|
|
231
|
+
if (!o || !r || !s)
|
|
232
|
+
return null;
|
|
233
|
+
let a = "__demiurge_imported_meta__";
|
|
234
|
+
for (; new RegExp(`\\b${a}\\b`).test(t); )
|
|
235
|
+
a += "_";
|
|
236
|
+
const i = new ot(t), u = f(r.imported);
|
|
237
|
+
return i.overwrite(
|
|
238
|
+
s.start,
|
|
239
|
+
s.end,
|
|
240
|
+
u?.start === s.start ? `meta as ${a}` : a
|
|
241
|
+
), i.appendLeft(o.end, `
|
|
242
|
+
const meta = ${a};`), {
|
|
243
|
+
code: i.toString(),
|
|
244
|
+
map: i.generateMap({
|
|
245
|
+
hires: "boundary",
|
|
246
|
+
includeContent: !0,
|
|
247
|
+
source: e
|
|
248
|
+
})
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
function bt(t) {
|
|
252
|
+
const e = Y(t), n = [], o = St(e), r = [];
|
|
253
|
+
b(e, (i) => {
|
|
254
|
+
if (i.type === "ImportDeclaration" && Nt(i)) {
|
|
255
|
+
r.push(i);
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
if (i.type !== "CallExpression" || !Dt(i.callee))
|
|
259
|
+
return;
|
|
260
|
+
const u = m(i.arguments)[0];
|
|
261
|
+
if (u?.type === "ObjectExpression")
|
|
262
|
+
for (const c of m(u.properties))
|
|
263
|
+
c.type === "Property" && S(c.key) === "data" && n.push({ end: c.end, start: c.start });
|
|
264
|
+
});
|
|
265
|
+
const s = [...n, ...o];
|
|
266
|
+
if (s.length === 0)
|
|
267
|
+
return t;
|
|
268
|
+
const a = [...s];
|
|
269
|
+
for (const i of r) {
|
|
270
|
+
const u = m(i.specifiers).map((d) => f(d.local)).filter((d) => d?.type === "Identifier").map((d) => String(d.name)), c = xt(t, [
|
|
271
|
+
...s,
|
|
272
|
+
{ end: i.end, start: i.start }
|
|
273
|
+
]), l = u.find(
|
|
274
|
+
(d) => new RegExp(`\\b${K(d)}\\b`).test(c)
|
|
275
|
+
);
|
|
276
|
+
if (l)
|
|
277
|
+
throw new Error(
|
|
278
|
+
`Server-only import ${JSON.stringify(l)} is used by client route code. Move that use into page data, a document contribution, or a client-safe module.`
|
|
279
|
+
);
|
|
280
|
+
a.push({ end: i.end, start: i.start });
|
|
281
|
+
}
|
|
282
|
+
return vt(
|
|
283
|
+
t,
|
|
284
|
+
a,
|
|
285
|
+
(i) => n.includes(i) ? "data: undefined" : o.includes(i) ? "undefined" : ""
|
|
286
|
+
);
|
|
287
|
+
}
|
|
288
|
+
const T = /* @__PURE__ */ new Set(["links", "metadata", "scripts"]);
|
|
289
|
+
function St(t) {
|
|
290
|
+
const e = /* @__PURE__ */ new Set();
|
|
291
|
+
for (const o of m(t.body)) {
|
|
292
|
+
if (o.type !== "ExportNamedDeclaration") continue;
|
|
293
|
+
const r = f(o.declaration);
|
|
294
|
+
if (r?.type === "VariableDeclaration")
|
|
295
|
+
for (const s of m(r.declarations)) {
|
|
296
|
+
const a = f(s.id);
|
|
297
|
+
a?.type === "Identifier" && T.has(String(a.name)) && e.add(String(a.name));
|
|
298
|
+
}
|
|
299
|
+
for (const s of m(o.specifiers)) {
|
|
300
|
+
const a = S(s.exported), i = S(s.local);
|
|
301
|
+
a && i && T.has(a) && e.add(i);
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
const n = [];
|
|
305
|
+
return b(t, (o) => {
|
|
306
|
+
if (o.type !== "VariableDeclarator") return;
|
|
307
|
+
const r = f(o.id), s = f(o.init);
|
|
308
|
+
r?.type === "Identifier" && e.has(String(r.name)) && s && n.push({ end: s.end, start: s.start });
|
|
309
|
+
}), n;
|
|
310
|
+
}
|
|
311
|
+
function Et(t, e, n) {
|
|
312
|
+
const o = n.split("?", 1)[0] ?? n, r = p(t, e.routesDir ?? "src/routes"), s = g(r, o);
|
|
313
|
+
return s !== "" && s !== ".." && !s.startsWith(`..${$}`);
|
|
314
|
+
}
|
|
315
|
+
function b(t, e) {
|
|
316
|
+
if (!t || typeof t != "object") return;
|
|
317
|
+
if (Array.isArray(t)) {
|
|
318
|
+
for (const o of t) b(o, e);
|
|
319
|
+
return;
|
|
320
|
+
}
|
|
321
|
+
const n = t;
|
|
322
|
+
if (typeof n.type == "string") {
|
|
323
|
+
e(n);
|
|
324
|
+
for (const [o, r] of Object.entries(n))
|
|
325
|
+
(/* @__PURE__ */ new Set(["end", "loc", "start", "type"])).has(o) || b(r, e);
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
function f(t) {
|
|
329
|
+
return t && typeof t == "object" && "type" in t ? t : void 0;
|
|
330
|
+
}
|
|
331
|
+
function m(t) {
|
|
332
|
+
return Array.isArray(t) ? t.map(f).filter((e) => !!e) : [];
|
|
333
|
+
}
|
|
334
|
+
function Dt(t) {
|
|
335
|
+
const e = f(t);
|
|
336
|
+
return e?.type === "Identifier" ? e.name === "page" : e?.type === "MemberExpression" && S(e.property) === "page";
|
|
337
|
+
}
|
|
338
|
+
function S(t) {
|
|
339
|
+
const e = f(t);
|
|
340
|
+
return e?.type === "Identifier" || e?.type === "Literal" ? String(e.name ?? e.value) : void 0;
|
|
341
|
+
}
|
|
342
|
+
function Nt(t) {
|
|
343
|
+
const e = f(t.source)?.value;
|
|
344
|
+
return typeof e == "string" && /(?:^|[/.-])server(?:[/.-]|$)/.test(e);
|
|
345
|
+
}
|
|
346
|
+
function xt(t, e) {
|
|
347
|
+
const n = [...t];
|
|
348
|
+
for (const { end: o, start: r } of e)
|
|
349
|
+
n.fill(" ", r, o);
|
|
350
|
+
return n.join("");
|
|
351
|
+
}
|
|
352
|
+
function vt(t, e, n) {
|
|
353
|
+
return [...e].sort((o, r) => r.start - o.start).reduce(
|
|
354
|
+
(o, r) => `${o.slice(0, r.start)}${n(r)}${o.slice(r.end)}`,
|
|
355
|
+
t
|
|
356
|
+
);
|
|
357
|
+
}
|
|
358
|
+
function K(t) {
|
|
359
|
+
return t.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
360
|
+
}
|
|
361
|
+
function It(t, e, n) {
|
|
362
|
+
return {
|
|
363
|
+
appType: "custom",
|
|
364
|
+
build: {
|
|
365
|
+
assetsInlineLimit: t.build?.assetsInlineLimit ?? 0,
|
|
366
|
+
...e.isSsrBuild && t.build?.target === void 0 && t.ssr?.target !== "webworker" ? { target: "node22.13" } : {},
|
|
367
|
+
rollupOptions: {
|
|
368
|
+
input: t.build?.rollupOptions?.input ?? E
|
|
369
|
+
}
|
|
370
|
+
},
|
|
371
|
+
...e.command === "serve" ? { html: { cspNonce: n } } : {}
|
|
372
|
+
};
|
|
373
|
+
}
|
|
374
|
+
function Ot(t, e = {}) {
|
|
375
|
+
const n = e.routesDir ?? "src/routes", o = Ct(t, e);
|
|
376
|
+
return `import { hydrateFileRouter } from "${h}";
|
|
377
|
+
${o}
|
|
378
|
+
|
|
379
|
+
${z(n, {
|
|
380
|
+
exportRoutes: !1,
|
|
381
|
+
includeServerOnly: !1
|
|
382
|
+
})}
|
|
383
|
+
|
|
384
|
+
void hydrateFileRouter({ routes });
|
|
385
|
+
`;
|
|
386
|
+
}
|
|
387
|
+
function _t(t, e = {}) {
|
|
388
|
+
const n = e.routesDir ?? "src/routes";
|
|
389
|
+
return `import { createRequestHandler } from "${h}";
|
|
390
|
+
|
|
391
|
+
${z(n, {
|
|
392
|
+
exportRoutes: !0,
|
|
393
|
+
includeServerOnly: !0
|
|
394
|
+
})}
|
|
395
|
+
|
|
396
|
+
export function createHandler(options = {}) {
|
|
397
|
+
const { clientEntry, lang, styles, title, ...handlerOptions } = options;
|
|
398
|
+
|
|
399
|
+
return createRequestHandler({
|
|
400
|
+
...handlerOptions,
|
|
401
|
+
routes,
|
|
402
|
+
ssr: {
|
|
403
|
+
clientEntry,
|
|
404
|
+
lang: lang ?? ${JSON.stringify(e.document?.lang)},
|
|
405
|
+
styles,
|
|
406
|
+
title: title ?? ${JSON.stringify(e.document?.title)},
|
|
407
|
+
},
|
|
408
|
+
});
|
|
409
|
+
}
|
|
410
|
+
`;
|
|
411
|
+
}
|
|
412
|
+
function z(t, {
|
|
413
|
+
exportRoutes: e,
|
|
414
|
+
includeServerOnly: n
|
|
415
|
+
}) {
|
|
416
|
+
const o = Pt(t, n), r = Mt(t);
|
|
417
|
+
return `const routeModules = import.meta.glob(${JSON.stringify(o)});
|
|
418
|
+
const routePrefix = ${JSON.stringify(r)};
|
|
419
|
+
${e ? "export " : ""}const routes = Object.fromEntries(
|
|
420
|
+
Object.entries(routeModules).map(([file, load]) => [
|
|
421
|
+
\`./routes/\${file.slice(routePrefix.length)}\`,
|
|
422
|
+
load,
|
|
423
|
+
]),
|
|
424
|
+
);`;
|
|
425
|
+
}
|
|
426
|
+
const Ft = ["@middleware.ts", "@policy.ts"];
|
|
427
|
+
function Pt(t, e) {
|
|
428
|
+
const n = `/${t.replace(/^\/|\/$/g, "")}`, o = [`${n}/**/*.{ts,tsx}`];
|
|
429
|
+
return e || o.push(
|
|
430
|
+
...Ft.flatMap((r) => [
|
|
431
|
+
`!${n}/${r}`,
|
|
432
|
+
`!${n}/**/${r}`
|
|
433
|
+
])
|
|
434
|
+
), o;
|
|
435
|
+
}
|
|
436
|
+
function Mt(t) {
|
|
437
|
+
return `/${t.replace(/^\/|\/$/g, "")}/`;
|
|
438
|
+
}
|
|
439
|
+
function Ct(t, e) {
|
|
440
|
+
if (e.styles === !1)
|
|
441
|
+
return "";
|
|
442
|
+
const n = e.styles ?? "src/styles.css", o = p(t, n);
|
|
443
|
+
return U(o) ? `import ${JSON.stringify(`/${n.replace(/^\/+/, "")}`)};` : "";
|
|
444
|
+
}
|
|
445
|
+
function Tt(t, e) {
|
|
446
|
+
return {
|
|
447
|
+
dev: !0,
|
|
448
|
+
ssr: X(t),
|
|
449
|
+
transformDocument: e,
|
|
450
|
+
renderPage: async (n, o) => {
|
|
451
|
+
if (n.render.mode === "streaming")
|
|
452
|
+
return await ft(n, {
|
|
453
|
+
...o,
|
|
454
|
+
clientEntry: v,
|
|
455
|
+
transformDocument: e
|
|
456
|
+
});
|
|
457
|
+
const r = await e(
|
|
458
|
+
it(n, {
|
|
459
|
+
...o,
|
|
460
|
+
clientEntry: v
|
|
461
|
+
})
|
|
462
|
+
);
|
|
463
|
+
return new Response(r, {
|
|
464
|
+
headers: { "content-type": "text/html; charset=utf-8" }
|
|
465
|
+
});
|
|
466
|
+
}
|
|
467
|
+
};
|
|
468
|
+
}
|
|
469
|
+
function j(t, e) {
|
|
470
|
+
const n = x(), o = x();
|
|
471
|
+
return {
|
|
472
|
+
nonce: n,
|
|
473
|
+
transform: async (r) => {
|
|
474
|
+
const s = jt(r, o), a = await t.transformIndexHtml("/", s);
|
|
475
|
+
return A(
|
|
476
|
+
A(a, o),
|
|
477
|
+
e,
|
|
478
|
+
n
|
|
479
|
+
);
|
|
480
|
+
}
|
|
481
|
+
};
|
|
482
|
+
}
|
|
483
|
+
function jt(t, e) {
|
|
484
|
+
const n = t.toLowerCase();
|
|
485
|
+
let o = 0, r = "";
|
|
486
|
+
for (; o < t.length; ) {
|
|
487
|
+
const s = t.indexOf("<", o);
|
|
488
|
+
if (s === -1)
|
|
489
|
+
return r + t.slice(o);
|
|
490
|
+
if (r += t.slice(o, s), n.startsWith("<!--", s)) {
|
|
491
|
+
const c = n.indexOf("-->", s + 4), l = c === -1 ? t.length : c + 3;
|
|
492
|
+
r += t.slice(s, l), o = l;
|
|
493
|
+
continue;
|
|
494
|
+
}
|
|
495
|
+
const a = n.slice(s).match(/^<\s*(script|style|link)\b/)?.[1];
|
|
496
|
+
if (!a) {
|
|
497
|
+
r += "<", o = s + 1;
|
|
498
|
+
continue;
|
|
499
|
+
}
|
|
500
|
+
const i = At(t, s);
|
|
501
|
+
if (i === -1)
|
|
502
|
+
return r + t.slice(s);
|
|
503
|
+
const u = t.slice(s, i + 1);
|
|
504
|
+
if (r += /(?:^|\s)nonce(?:\s|=|>)/i.test(u) ? u : Wt(u, e), o = i + 1, a === "script" || a === "style") {
|
|
505
|
+
const c = n.indexOf(`</${a}`, o);
|
|
506
|
+
if (c === -1)
|
|
507
|
+
return r + t.slice(o);
|
|
508
|
+
r += t.slice(o, c), o = c;
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
return r;
|
|
512
|
+
}
|
|
513
|
+
function At(t, e) {
|
|
514
|
+
let n;
|
|
515
|
+
for (let o = e + 1; o < t.length; o++) {
|
|
516
|
+
const r = t[o];
|
|
517
|
+
if (n) {
|
|
518
|
+
r === n && (n = void 0);
|
|
519
|
+
continue;
|
|
520
|
+
}
|
|
521
|
+
if (r === '"' || r === "'")
|
|
522
|
+
n = r;
|
|
523
|
+
else if (r === ">")
|
|
524
|
+
return o;
|
|
525
|
+
}
|
|
526
|
+
return -1;
|
|
527
|
+
}
|
|
528
|
+
function Wt(t, e) {
|
|
529
|
+
const n = /\/\s*>$/.test(t) ? t.lastIndexOf("/") : t.length - 1;
|
|
530
|
+
return `${t.slice(0, n)} nonce="${e}"${t.slice(n)}`;
|
|
531
|
+
}
|
|
532
|
+
function A(t, e, n) {
|
|
533
|
+
const o = new RegExp(
|
|
534
|
+
`(\\snonce\\s*=\\s*)(["'])${K(e)}\\2`,
|
|
535
|
+
"g"
|
|
536
|
+
);
|
|
537
|
+
return t.replace(
|
|
538
|
+
o,
|
|
539
|
+
n ? `$1"${n}"` : ""
|
|
540
|
+
);
|
|
541
|
+
}
|
|
542
|
+
function W(t, e) {
|
|
543
|
+
const n = t.headers.get("content-type"), o = t.headers.get("content-security-policy");
|
|
544
|
+
if (!n?.toLowerCase().startsWith("text/html") || !o)
|
|
545
|
+
return;
|
|
546
|
+
const r = `'nonce-${e}'`, s = V(
|
|
547
|
+
o,
|
|
548
|
+
["script-src-elem", "script-src"],
|
|
549
|
+
"script-src",
|
|
550
|
+
r
|
|
551
|
+
), a = Vt(
|
|
552
|
+
s,
|
|
553
|
+
["style-src-elem", "style-src"]
|
|
554
|
+
) ? s : V(
|
|
555
|
+
s,
|
|
556
|
+
["style-src-elem", "style-src"],
|
|
557
|
+
"style-src",
|
|
558
|
+
r
|
|
559
|
+
);
|
|
560
|
+
t.headers.set("content-security-policy", a), t.headers.set("cache-control", "private, no-store");
|
|
561
|
+
}
|
|
562
|
+
function V(t, e, n, o) {
|
|
563
|
+
const r = t.split(";").map((l) => l.trim()), s = Q(r, e), a = r.find(
|
|
564
|
+
(l) => l.split(/\s+/, 1)[0]?.toLowerCase() === "default-src"
|
|
565
|
+
);
|
|
566
|
+
if (s === -1 && !a) return t;
|
|
567
|
+
const [i, ...u] = (s === -1 ? a : r[s]).split(/\s+/), c = [
|
|
568
|
+
s === -1 ? n : i,
|
|
569
|
+
.../* @__PURE__ */ new Set([
|
|
570
|
+
...u.filter((l) => l !== "'none'"),
|
|
571
|
+
o
|
|
572
|
+
])
|
|
573
|
+
].join(" ");
|
|
574
|
+
return s === -1 ? r.push(c) : r[s] = c, r.join("; ");
|
|
575
|
+
}
|
|
576
|
+
function Vt(t, e) {
|
|
577
|
+
const n = t.split(";").map((a) => a.trim()), o = Q(n, e), s = (o === -1 ? n.find(
|
|
578
|
+
(a) => a.split(/\s+/, 1)[0]?.toLowerCase() === "default-src"
|
|
579
|
+
) : n[o])?.split(/\s+/).slice(1) ?? [];
|
|
580
|
+
return s.includes("'unsafe-inline'") && !s.some((a) => /^'(?:nonce-|sha(?:256|384|512)-)/i.test(a));
|
|
581
|
+
}
|
|
582
|
+
function Q(t, e) {
|
|
583
|
+
for (const n of e) {
|
|
584
|
+
const o = t.findIndex(
|
|
585
|
+
(r) => r.split(/\s+/, 1)[0]?.toLowerCase() === n
|
|
586
|
+
);
|
|
587
|
+
if (o !== -1) return o;
|
|
588
|
+
}
|
|
589
|
+
return -1;
|
|
590
|
+
}
|
|
591
|
+
const L = Symbol.for("demiurge.devManifest");
|
|
592
|
+
async function k(t, e, n) {
|
|
593
|
+
const o = e, r = o[L];
|
|
594
|
+
if (r)
|
|
595
|
+
return r;
|
|
596
|
+
const s = lt(
|
|
597
|
+
await Kt(t, n)
|
|
598
|
+
);
|
|
599
|
+
return o[L] = s, s;
|
|
600
|
+
}
|
|
601
|
+
function X(t) {
|
|
602
|
+
return {
|
|
603
|
+
clientEntry: v,
|
|
604
|
+
lang: t.document?.lang,
|
|
605
|
+
title: t.document?.title
|
|
606
|
+
};
|
|
607
|
+
}
|
|
608
|
+
function Lt(t, e) {
|
|
609
|
+
return {
|
|
610
|
+
...X(t),
|
|
611
|
+
dev: !0,
|
|
612
|
+
transformDocument: e
|
|
613
|
+
};
|
|
614
|
+
}
|
|
615
|
+
const H = /* @__PURE__ */ new Set();
|
|
616
|
+
function kt(t, e) {
|
|
617
|
+
H.has(e) || t.fallbacks.notFound.some(
|
|
618
|
+
(n) => n.fileSegments.length === 0
|
|
619
|
+
) || (H.add(e), console.warn(Yt(nt(e, "@not-found.tsx"))));
|
|
620
|
+
}
|
|
621
|
+
async function Ht(t, e = {}) {
|
|
622
|
+
const n = e.routesDir ?? "src/routes", o = p(t, n);
|
|
623
|
+
if (!U(o))
|
|
624
|
+
return;
|
|
625
|
+
const r = await Z(o);
|
|
626
|
+
if (r.map(
|
|
627
|
+
(i) => g(o, i).split($).join("/")
|
|
628
|
+
).some((i) => /^@not-found\.tsx?$/.test(i)))
|
|
629
|
+
return;
|
|
630
|
+
const a = await Jt(r);
|
|
631
|
+
if (a)
|
|
632
|
+
throw new Error(
|
|
633
|
+
Gt(
|
|
634
|
+
n,
|
|
635
|
+
g(o, a).split($).join("/")
|
|
636
|
+
)
|
|
637
|
+
);
|
|
638
|
+
}
|
|
639
|
+
async function Jt(t) {
|
|
640
|
+
for (const e of t)
|
|
641
|
+
if (!g(G(e), e).startsWith("@") && Bt(await rt(e, "utf8")))
|
|
642
|
+
return e;
|
|
643
|
+
}
|
|
644
|
+
const Ut = h.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), J = new RegExp(
|
|
645
|
+
`import\\s*\\{([^}]*)\\}\\s*from\\s*["']${Ut}["']`,
|
|
646
|
+
"g"
|
|
647
|
+
);
|
|
648
|
+
function Bt(t) {
|
|
649
|
+
const e = [...t.matchAll(J)].flatMap(
|
|
650
|
+
(o) => o[1].split(",").flatMap((r) => {
|
|
651
|
+
const [s, a] = r.trim().split(/\s+as\s+/);
|
|
652
|
+
return s.replace(/^type\s+/, "") === "page" ? [a ?? s] : [];
|
|
653
|
+
})
|
|
654
|
+
);
|
|
655
|
+
if (e.length === 0)
|
|
656
|
+
return !1;
|
|
657
|
+
const n = t.replace(J, "");
|
|
658
|
+
return e.some((o) => new RegExp(`\\b${o}\\s*\\(`).test(n));
|
|
659
|
+
}
|
|
660
|
+
function Gt(t, e) {
|
|
661
|
+
return `Demiurge will not build an app with page routes and no ${t}/@not-found.tsx.
|
|
662
|
+
|
|
663
|
+
"${e}" declares a page, so a browser can reach a path this app does not serve. Decide what that looks like rather than shipping the framework built-in.
|
|
664
|
+
|
|
665
|
+
Create ${t}/@not-found.tsx:
|
|
666
|
+
|
|
667
|
+
export default function NotFound({ pathname }: { pathname: string }) {
|
|
668
|
+
return <h1>Nothing at {pathname}</h1>;
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
It renders inside the layouts above the requested path. Opt out with "export const layout = false".`;
|
|
672
|
+
}
|
|
673
|
+
function Yt(t) {
|
|
674
|
+
return `Demiurge is serving its built-in 404 because ${t} does not exist.
|
|
675
|
+
|
|
676
|
+
Create it before building for production:
|
|
677
|
+
|
|
678
|
+
export default function NotFound({ pathname }: { pathname: string }) {
|
|
679
|
+
return <h1>Nothing at {pathname}</h1>;
|
|
680
|
+
}
|
|
681
|
+
`;
|
|
682
|
+
}
|
|
683
|
+
function qt({
|
|
684
|
+
entrySrc: t,
|
|
685
|
+
lang: e,
|
|
686
|
+
links: n,
|
|
687
|
+
metadata: o,
|
|
688
|
+
nonce: r,
|
|
689
|
+
scripts: s,
|
|
690
|
+
styles: a,
|
|
691
|
+
title: i
|
|
692
|
+
}) {
|
|
693
|
+
return st({
|
|
694
|
+
entrySrc: t,
|
|
695
|
+
lang: e,
|
|
696
|
+
links: n,
|
|
697
|
+
metadata: o,
|
|
698
|
+
nonce: r,
|
|
699
|
+
scripts: s,
|
|
700
|
+
styles: a,
|
|
701
|
+
title: i
|
|
702
|
+
});
|
|
703
|
+
}
|
|
704
|
+
async function w(t, e) {
|
|
705
|
+
const n = p(t, e.routesDir ?? "src/routes"), o = p(
|
|
706
|
+
t,
|
|
707
|
+
typeof e.typedRoutes == "object" ? e.typedRoutes.outputFile ?? C : C
|
|
708
|
+
);
|
|
709
|
+
await dt({ outputFile: o, routesDir: n });
|
|
710
|
+
}
|
|
711
|
+
function N(t, e) {
|
|
712
|
+
return e.startsWith(t) && /\.tsx?$/.test(e);
|
|
713
|
+
}
|
|
714
|
+
async function Kt(t, e) {
|
|
715
|
+
const n = await Z(e), o = {};
|
|
716
|
+
for (const r of n) {
|
|
717
|
+
const s = Qt(e, r);
|
|
718
|
+
o[s] = async () => await t.ssrLoadModule(r);
|
|
719
|
+
}
|
|
720
|
+
return o;
|
|
721
|
+
}
|
|
722
|
+
async function zt(t, e, n = {}) {
|
|
723
|
+
const o = new URL(e.url);
|
|
724
|
+
return ct(t.routes, o.pathname) ? await ut(t, e, n) : "next";
|
|
725
|
+
}
|
|
726
|
+
async function Z(t) {
|
|
727
|
+
return (await B(t, {
|
|
728
|
+
recursive: !0,
|
|
729
|
+
withFileTypes: !0
|
|
730
|
+
})).filter((n) => n.isFile() && /\.tsx?$/.test(n.name)).map((n) => p(n.parentPath, n.name));
|
|
731
|
+
}
|
|
732
|
+
function Qt(t, e) {
|
|
733
|
+
return `./routes/${g(t, e).split($).join("/")}`;
|
|
734
|
+
}
|
|
735
|
+
export {
|
|
736
|
+
ue as demiurge,
|
|
737
|
+
Ht as unstable_assertRootNotFoundRoute,
|
|
738
|
+
Ot as unstable_createClientEntrySource,
|
|
739
|
+
Kt as unstable_createDevRouteImporters,
|
|
740
|
+
qt as unstable_createDocumentHtml,
|
|
741
|
+
_t as unstable_createServerEntrySource,
|
|
742
|
+
Bt as unstable_declaresPageRoute,
|
|
743
|
+
zt as unstable_handleDevRequest,
|
|
744
|
+
bt as unstable_stripClientPageData
|
|
745
|
+
};
|
|
746
|
+
//# sourceMappingURL=index.js.map
|