@demiurgejs/core 0.1.1 → 0.2.0-beta.2

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 (151) hide show
  1. package/README.md +5 -0
  2. package/bin/demiurge.mjs +51 -0
  3. package/dist/adapter/testing.d.ts +33 -0
  4. package/dist/adapter/testing.d.ts.map +1 -0
  5. package/dist/adapter/testing.js +251 -0
  6. package/dist/adapter/testing.js.map +1 -0
  7. package/dist/browser/file-router.d.ts.map +1 -1
  8. package/dist/chunks/document-shell-D1xo6cEA.js +35 -0
  9. package/dist/chunks/document-shell-D1xo6cEA.js.map +1 -0
  10. package/dist/chunks/image-codec-BGTx_t5K.js +141 -0
  11. package/dist/chunks/image-codec-BGTx_t5K.js.map +1 -0
  12. package/dist/chunks/images-B9MqcjSA.js +339 -0
  13. package/dist/chunks/images-B9MqcjSA.js.map +1 -0
  14. package/dist/chunks/request-metadata-D5NrT8ks.js +642 -0
  15. package/dist/chunks/request-metadata-D5NrT8ks.js.map +1 -0
  16. package/dist/chunks/streaming-BQ1bykDo.js +469 -0
  17. package/dist/chunks/streaming-BQ1bykDo.js.map +1 -0
  18. package/dist/chunks/{testing-DR3eQAvY.js → testing-B_iMFYz_.js} +2376 -1927
  19. package/dist/chunks/testing-B_iMFYz_.js.map +1 -0
  20. package/dist/cli.d.ts +42 -0
  21. package/dist/cli.d.ts.map +1 -0
  22. package/dist/cli.js +173 -0
  23. package/dist/cli.js.map +1 -0
  24. package/dist/document/deferred-scripts.d.ts +11 -0
  25. package/dist/document/deferred-scripts.d.ts.map +1 -0
  26. package/dist/document/index.d.ts +4 -2
  27. package/dist/document/index.d.ts.map +1 -1
  28. package/dist/document/render.d.ts +1 -1
  29. package/dist/document/render.d.ts.map +1 -1
  30. package/dist/document/scripts.d.ts +34 -1
  31. package/dist/document/scripts.d.ts.map +1 -1
  32. package/dist/edge/assets.d.ts +14 -0
  33. package/dist/edge/assets.d.ts.map +1 -0
  34. package/dist/edge/index.d.ts +19 -0
  35. package/dist/edge/index.d.ts.map +1 -0
  36. package/dist/edge/index.js +286 -0
  37. package/dist/edge/index.js.map +1 -0
  38. package/dist/edge/stores.d.ts +8 -0
  39. package/dist/edge/stores.d.ts.map +1 -0
  40. package/dist/edge/streaming.d.ts +7 -0
  41. package/dist/edge/streaming.d.ts.map +1 -0
  42. package/dist/index.d.ts +9 -9
  43. package/dist/index.d.ts.map +1 -1
  44. package/dist/index.js +894 -1043
  45. package/dist/index.js.map +1 -1
  46. package/dist/internal/testing.js +12 -11
  47. package/dist/internal/testing.js.map +1 -1
  48. package/dist/kv/index.d.ts +3 -0
  49. package/dist/kv/index.d.ts.map +1 -0
  50. package/dist/kv/index.js +103 -0
  51. package/dist/kv/index.js.map +1 -0
  52. package/dist/kv/store.d.ts +28 -0
  53. package/dist/kv/store.d.ts.map +1 -0
  54. package/dist/node/font.d.ts +5 -0
  55. package/dist/node/font.d.ts.map +1 -0
  56. package/dist/node/image.d.ts +15 -0
  57. package/dist/node/image.d.ts.map +1 -0
  58. package/dist/node/index.d.ts +4 -0
  59. package/dist/node/index.d.ts.map +1 -1
  60. package/dist/node/index.js +25 -23
  61. package/dist/node/index.js.map +1 -1
  62. package/dist/node/streaming.d.ts +2 -0
  63. package/dist/node/streaming.d.ts.map +1 -1
  64. package/dist/platform/analytics.d.ts +58 -5
  65. package/dist/platform/analytics.d.ts.map +1 -1
  66. package/dist/platform/font-assets.d.ts +19 -0
  67. package/dist/platform/font-assets.d.ts.map +1 -0
  68. package/dist/platform/fonts.d.ts +14 -4
  69. package/dist/platform/fonts.d.ts.map +1 -1
  70. package/dist/platform/image-codec.d.ts +15 -0
  71. package/dist/platform/image-codec.d.ts.map +1 -0
  72. package/dist/platform/image-url.d.ts +17 -0
  73. package/dist/platform/image-url.d.ts.map +1 -0
  74. package/dist/platform/image.d.ts +8 -0
  75. package/dist/platform/image.d.ts.map +1 -0
  76. package/dist/platform/images.d.ts +15 -0
  77. package/dist/platform/images.d.ts.map +1 -1
  78. package/dist/platform/index.d.ts +8 -5
  79. package/dist/platform/index.d.ts.map +1 -1
  80. package/dist/redis/index.d.ts +3 -0
  81. package/dist/redis/index.d.ts.map +1 -0
  82. package/dist/redis/index.js +171 -0
  83. package/dist/redis/index.js.map +1 -0
  84. package/dist/redis/store.d.ts +8 -0
  85. package/dist/redis/store.d.ts.map +1 -0
  86. package/dist/route/action.d.ts +11 -11
  87. package/dist/route/action.d.ts.map +1 -1
  88. package/dist/route/index.d.ts +2 -1
  89. package/dist/route/index.d.ts.map +1 -1
  90. package/dist/route/middleware.d.ts +7 -0
  91. package/dist/route/middleware.d.ts.map +1 -0
  92. package/dist/route/page.d.ts +2 -2
  93. package/dist/route/page.d.ts.map +1 -1
  94. package/dist/route/response.d.ts +19 -19
  95. package/dist/route/response.d.ts.map +1 -1
  96. package/dist/route/types.d.ts +55 -31
  97. package/dist/route/types.d.ts.map +1 -1
  98. package/dist/route/webhook.d.ts +1 -1
  99. package/dist/router/manifest.d.ts +1 -0
  100. package/dist/router/manifest.d.ts.map +1 -1
  101. package/dist/routing/generate.d.ts +2 -0
  102. package/dist/routing/generate.d.ts.map +1 -1
  103. package/dist/routing/index.d.ts +1 -1
  104. package/dist/routing/index.d.ts.map +1 -1
  105. package/dist/routing/types.d.ts +2 -0
  106. package/dist/routing/types.d.ts.map +1 -1
  107. package/dist/security/cors.d.ts.map +1 -1
  108. package/dist/security/index.d.ts +4 -2
  109. package/dist/security/index.d.ts.map +1 -1
  110. package/dist/security/policy.d.ts +5 -1
  111. package/dist/security/policy.d.ts.map +1 -1
  112. package/dist/security/types.d.ts +34 -13
  113. package/dist/security/types.d.ts.map +1 -1
  114. package/dist/security/verification.d.ts +8 -0
  115. package/dist/security/verification.d.ts.map +1 -0
  116. package/dist/server/document-shell.d.ts +12 -0
  117. package/dist/server/document-shell.d.ts.map +1 -0
  118. package/dist/server/errors.d.ts.map +1 -1
  119. package/dist/server/not-found.d.ts.map +1 -1
  120. package/dist/server/render-tree.d.ts +6 -1
  121. package/dist/server/render-tree.d.ts.map +1 -1
  122. package/dist/server/request-handler.d.ts +4 -1
  123. package/dist/server/request-handler.d.ts.map +1 -1
  124. package/dist/server/ssr.d.ts +1 -0
  125. package/dist/server/ssr.d.ts.map +1 -1
  126. package/dist/static/images.d.ts +13 -0
  127. package/dist/static/images.d.ts.map +1 -0
  128. package/dist/static/index.d.ts +18 -0
  129. package/dist/static/index.d.ts.map +1 -1
  130. package/dist/static/index.js +677 -129
  131. package/dist/static/index.js.map +1 -1
  132. package/dist/static/preview.d.ts +8 -0
  133. package/dist/static/preview.d.ts.map +1 -0
  134. package/dist/static/vercel.d.ts +34 -0
  135. package/dist/static/vercel.d.ts.map +1 -0
  136. package/dist/vite/index.d.ts +3 -2
  137. package/dist/vite/index.d.ts.map +1 -1
  138. package/dist/vite/index.js +782 -329
  139. package/dist/vite/index.js.map +1 -1
  140. package/dist/vite/plugin.d.ts +20 -0
  141. package/dist/vite/plugin.d.ts.map +1 -1
  142. package/dist/vite/policy-verification.d.ts +10 -0
  143. package/dist/vite/policy-verification.d.ts.map +1 -0
  144. package/package.json +38 -2
  145. package/dist/chunks/index-BnX9Qxbm.js +0 -44
  146. package/dist/chunks/index-BnX9Qxbm.js.map +0 -1
  147. package/dist/chunks/ssr-BJejKlkZ.js +0 -275
  148. package/dist/chunks/ssr-BJejKlkZ.js.map +0 -1
  149. package/dist/chunks/streaming-DN1DnbRE.js +0 -343
  150. package/dist/chunks/streaming-DN1DnbRE.js.map +0 -1
  151. package/dist/chunks/testing-DR3eQAvY.js.map +0 -1
@@ -1,81 +1,559 @@
1
- import { mkdir as p, mkdtemp as k, writeFile as E, cp as P, rm as g, readFile as b } from "node:fs/promises";
2
- import { resolve as w, dirname as O, join as m, relative as M, sep as H } from "node:path";
3
- import { d as I } from "../chunks/index-BnX9Qxbm.js";
4
- import { S as $ } from "../chunks/ssr-BJejKlkZ.js";
5
- import { c as _, a as D, b as U, h as j, r as q, d as x } from "../chunks/testing-DR3eQAvY.js";
1
+ import { readFile as O, mkdir as T, mkdtemp as k, cp as D, writeFile as b, rm as A, rename as nt } from "node:fs/promises";
2
+ import { resolve as h, relative as w, sep as S, extname as it, dirname as C, join as y } from "node:path";
3
+ import { d as ot, S as P } from "../chunks/request-metadata-D5NrT8ks.js";
4
+ import { v as st, a as at, b as ct, d as ut, h as lt, r as ft, m as dt, e as _, f as ht } from "../chunks/testing-B_iMFYz_.js";
6
5
  import "react-dom/server";
7
6
  import "react";
8
7
  import "react/jsx-runtime";
9
- import { C as W, I as B, R as G } from "../chunks/static-files-DUjHw-4H.js";
10
- const C = "demiurge-static-manifest.json", yt = I({
8
+ import { C as U, I as pt, R as mt } from "../chunks/static-files-DUjHw-4H.js";
9
+ import { t as wt, n as gt, r as yt } from "../chunks/image-codec-BGTx_t5K.js";
10
+ import { e as V, g as St, p as Et, h as $t } from "../chunks/images-B9MqcjSA.js";
11
+ import { createServer as vt } from "node:http";
12
+ import { normalizeRoutes as Ot, getTransformedRoutes as Rt } from "@vercel/routing-utils";
13
+ async function Tt(t) {
14
+ const e = h(t.outDir), r = t.policy ?? {}, n = r.optimizerPath ?? V, o = new Set(
15
+ t.documents.flatMap(
16
+ (a) => St(a, n)
17
+ )
18
+ ), s = [], c = /* @__PURE__ */ new Map();
19
+ for (const a of [...o].sort()) {
20
+ const i = Et(a, n);
21
+ if (!i)
22
+ throw new Error(
23
+ `Static output references image variant ${JSON.stringify(a)}, which does not describe a transform the build can emit.`
24
+ );
25
+ if (!$t(i.src, r))
26
+ throw new Error(
27
+ `Image source ${JSON.stringify(i.src)} is not allowed by the image policy.`
28
+ );
29
+ const u = Ft(e, i.src);
30
+ let f = c.get(u);
31
+ f || (f = await Nt(u, i.src), c.set(u, f));
32
+ const E = await wt(f, {
33
+ format: gt(i, null),
34
+ quality: i.quality,
35
+ width: i.width
36
+ });
37
+ s.push({ body: E.body, file: a.slice(1) });
38
+ }
39
+ return s;
40
+ }
41
+ function At(t, e = {}) {
42
+ const r = e.optimizerPath ?? V, n = new RegExp(`${r.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}\\?`);
43
+ for (const o of t)
44
+ if (n.test(o))
45
+ throw new Error(
46
+ 'Static output references the request-time image optimizer, which a static build cannot serve. Set loader: "static" in the image policy, or deploy a runtime adapter.'
47
+ );
48
+ }
49
+ async function Nt(t, e) {
50
+ try {
51
+ return new Uint8Array(await O(t));
52
+ } catch (r) {
53
+ throw new Error(
54
+ `Demiurge could not read the source image ${JSON.stringify(e)} from the build output.`,
55
+ { cause: r }
56
+ );
57
+ }
58
+ }
59
+ function Ft(t, e) {
60
+ let r;
61
+ try {
62
+ r = decodeURIComponent(e);
63
+ } catch {
64
+ throw new Error(`Image source is not valid UTF-8: ${JSON.stringify(e)}.`);
65
+ }
66
+ const n = h(t, `.${r}`);
67
+ if (w(t, n).split(S).includes(".."))
68
+ throw new Error(
69
+ `Image source escaped the build output directory: ${JSON.stringify(e)}.`
70
+ );
71
+ return n;
72
+ }
73
+ const xt = "demiurge-static-manifest.json", bt = {
74
+ ".avif": "image/avif",
75
+ ".css": "text/css; charset=utf-8",
76
+ ".gif": "image/gif",
77
+ ".html": "text/html; charset=utf-8",
78
+ ".ico": "image/x-icon",
79
+ ".jpeg": "image/jpeg",
80
+ ".jpg": "image/jpeg",
81
+ ".js": "text/javascript; charset=utf-8",
82
+ ".json": "application/json; charset=utf-8",
83
+ ".mjs": "text/javascript; charset=utf-8",
84
+ ".png": "image/png",
85
+ ".svg": "image/svg+xml",
86
+ ".txt": "text/plain; charset=utf-8",
87
+ ".webmanifest": "application/manifest+json",
88
+ ".webp": "image/webp",
89
+ ".woff": "font/woff",
90
+ ".woff2": "font/woff2"
91
+ };
92
+ async function Ne(t) {
93
+ const e = h(t.outDir), r = Pt(
94
+ await O(h(e, xt), "utf8")
95
+ ), n = new Map(
96
+ r.entries.map((a) => [a.pathname, a])
97
+ ), o = new Map(
98
+ r.entries.map((a) => [a.file, a])
99
+ ), s = r.fileHeaderRules.map((a) => ({
100
+ ...a,
101
+ expression: new RegExp(a.pattern)
102
+ })), c = vt(async (a, i) => {
103
+ try {
104
+ if (a.method !== "GET" && a.method !== "HEAD") {
105
+ i.writeHead(405, { allow: "GET, HEAD" }), i.end();
106
+ return;
107
+ }
108
+ const u = new URL(a.url ?? "/", "http://demiurge.local");
109
+ let f;
110
+ try {
111
+ f = decodeURIComponent(u.pathname);
112
+ } catch {
113
+ i.writeHead(400, {
114
+ "content-type": "text/plain; charset=utf-8"
115
+ }), i.end("The request path is not valid UTF-8.");
116
+ return;
117
+ }
118
+ const E = f.replace(/\/$/, "") || "/", $ = n.get(E);
119
+ if ($) {
120
+ await F(e, $, a.method, i);
121
+ return;
122
+ }
123
+ const p = Ct(e, f);
124
+ if (p)
125
+ try {
126
+ const m = w(e, p).split(S).join("/"), l = o.get(m);
127
+ if (l) {
128
+ await F(e, l, a.method, i);
129
+ return;
130
+ }
131
+ const d = await O(p), v = bt[it(p).toLowerCase()];
132
+ v && i.setHeader("content-type", v);
133
+ const tt = f.split("/").at(-1) ?? "", et = s.find(({ expression: rt }) => rt.test(tt));
134
+ z(i, et?.headers ?? {}), i.writeHead(200), i.end(a.method === "HEAD" ? void 0 : d);
135
+ return;
136
+ } catch (m) {
137
+ if (!Ht(m)) throw m;
138
+ }
139
+ const g = n.get("*");
140
+ if (!g) {
141
+ i.writeHead(404), i.end();
142
+ return;
143
+ }
144
+ await F(e, g, a.method, i);
145
+ } catch {
146
+ i.writeHead(500, {
147
+ "content-type": "text/plain; charset=utf-8"
148
+ }), i.end("Demiurge could not serve the static output.");
149
+ }
150
+ });
151
+ return await new Promise((a, i) => {
152
+ const u = (f) => i(f);
153
+ c.once("error", u), c.listen(
154
+ t.port ?? 4173,
155
+ t.host ?? "localhost",
156
+ () => {
157
+ c.off("error", u), a();
158
+ }
159
+ );
160
+ }), c;
161
+ }
162
+ async function F(t, e, r, n) {
163
+ const o = q(t, e.file), s = await O(o);
164
+ z(n, e.headers), n.writeHead(e.status), n.end(r === "HEAD" ? void 0 : s);
165
+ }
166
+ function z(t, e) {
167
+ for (const [r, n] of Object.entries(e))
168
+ t.setHeader(r, n);
169
+ }
170
+ function Ct(t, e) {
171
+ if (!e.endsWith("/"))
172
+ return B(t, `.${e}`);
173
+ }
174
+ function q(t, e) {
175
+ const r = B(t, e);
176
+ if (!r)
177
+ throw new Error(`Static preview file is outside the output directory: ${JSON.stringify(e)}.`);
178
+ return r;
179
+ }
180
+ function B(t, e) {
181
+ if (!e || e.startsWith("/") || e.startsWith("\\") || e.split(/[\\/]/).includes(".."))
182
+ return;
183
+ const r = h(t, e), n = w(t, r);
184
+ return n !== ".." && !n.startsWith(`..${S}`) ? r : void 0;
185
+ }
186
+ function Pt(t) {
187
+ let e;
188
+ try {
189
+ e = JSON.parse(t);
190
+ } catch {
191
+ throw new Error("The static output manifest is not valid JSON.");
192
+ }
193
+ if (!N(e) || e.adapter !== "static" || e.version !== 1)
194
+ throw new Error("The static output manifest has an unsupported format.");
195
+ if (!Array.isArray(e.entries) || !Array.isArray(e.fileHeaderRules))
196
+ throw new Error("The static output manifest does not contain header rules and entries.");
197
+ const r = e.entries.map(It), n = e.fileHeaderRules.map(jt), o = /* @__PURE__ */ new Set();
198
+ for (const s of r) {
199
+ if (o.has(s.pathname))
200
+ throw new Error(`The static output manifest repeats pathname ${JSON.stringify(s.pathname)}.`);
201
+ o.add(s.pathname);
202
+ }
203
+ return { adapter: "static", entries: r, fileHeaderRules: n, version: 1 };
204
+ }
205
+ function It(t) {
206
+ if (!N(t) || typeof t.file != "string" || typeof t.pathname != "string" || t.status !== 200 && t.status !== 404 || !G(t.headers))
207
+ throw new Error("The static output manifest contains an invalid entry.");
208
+ return q("/demiurge-manifest-root", t.file), {
209
+ file: t.file,
210
+ headers: t.headers,
211
+ pathname: t.pathname,
212
+ status: t.status
213
+ };
214
+ }
215
+ function jt(t) {
216
+ if (!N(t) || typeof t.pattern != "string" || !G(t.headers))
217
+ throw new Error("The static output manifest contains an invalid file header rule.");
218
+ try {
219
+ new RegExp(t.pattern);
220
+ } catch {
221
+ throw new Error("The static output manifest contains an invalid file header pattern.");
222
+ }
223
+ return { headers: t.headers, pattern: t.pattern };
224
+ }
225
+ function N(t) {
226
+ return !!t && typeof t == "object" && !Array.isArray(t);
227
+ }
228
+ function G(t) {
229
+ return N(t) && Object.values(t).every(
230
+ (e) => typeof e == "string"
231
+ );
232
+ }
233
+ function Ht(t) {
234
+ return t instanceof Error && "code" in t && (t.code === "EISDIR" || t.code === "ENOENT");
235
+ }
236
+ const Jt = "demiurge-manifest.json", Mt = "demiurge-static-manifest.json";
237
+ function Fe(t = {}) {
238
+ return {
239
+ adapter: "vercel",
240
+ cache: t.cache?.map((e) => ({
241
+ source: e.source,
242
+ value: e.value
243
+ })) ?? [],
244
+ cors: t.cors
245
+ };
246
+ }
247
+ async function xe(t) {
248
+ Vt(t.deployment);
249
+ const e = h(t.projectRoot), r = h(t.outDir), n = h(e, ".vercel/output");
250
+ if (zt(r, n))
251
+ throw new Error(
252
+ "The static output directory must not overlap the Vercel output directory."
253
+ );
254
+ const o = C(n);
255
+ await T(o, { recursive: !0 });
256
+ const s = await k(y(o, "output-demiurge-"));
257
+ try {
258
+ const c = y(s, "static");
259
+ await D(r, c, {
260
+ filter: (a) => {
261
+ const i = w(r, a).split(S).join("/");
262
+ return i !== Jt && i !== Mt;
263
+ },
264
+ recursive: !0
265
+ }), await b(
266
+ y(s, "config.json"),
267
+ `${JSON.stringify(Lt(
268
+ t.manifest,
269
+ t.deployment
270
+ ), null, 2)}
271
+ `
272
+ ), await A(n, { force: !0, recursive: !0 }), await nt(s, n);
273
+ } catch (c) {
274
+ throw await A(s, { force: !0, recursive: !0 }), c;
275
+ }
276
+ return n;
277
+ }
278
+ function Lt(t, e) {
279
+ const r = t.entries.find((i) => i.pathname === "*");
280
+ if (!r)
281
+ throw new Error("Vercel output requires a static fallback entry.");
282
+ const n = _t(e.cache), s = [
283
+ {
284
+ continue: !0,
285
+ headers: { "access-control-allow-origin": Ut(e.cors, t.origin) },
286
+ src: "^/.*$"
287
+ }
288
+ ];
289
+ for (const i of t.entries) {
290
+ if (i.pathname === "*") continue;
291
+ const u = `/${i.file}`;
292
+ u !== i.pathname && s.push({
293
+ continue: !0,
294
+ dest: i.pathname,
295
+ src: R(u)
296
+ });
297
+ }
298
+ for (const i of t.entries) {
299
+ const u = I(i.headers);
300
+ if (Object.keys(u).length === 0) continue;
301
+ const f = i.pathname === "*" ? `/${i.file}` : i.pathname;
302
+ s.push({
303
+ continue: !0,
304
+ headers: u,
305
+ src: R(f)
306
+ });
307
+ }
308
+ s.push(...n);
309
+ for (const i of t.entries) {
310
+ if (i.pathname === "*") {
311
+ s.push({
312
+ dest: `/${i.file}`,
313
+ src: R(`/${i.file}`),
314
+ status: 404
315
+ });
316
+ continue;
317
+ }
318
+ s.push({
319
+ dest: i.pathname === "/" ? `/${i.file}` : i.pathname,
320
+ src: R(i.pathname)
321
+ });
322
+ }
323
+ s.push({ handle: "hit" });
324
+ for (const i of [...t.fileHeaderRules].reverse())
325
+ s.push({
326
+ continue: !0,
327
+ headers: { ...i.headers },
328
+ src: kt(i.pattern)
329
+ });
330
+ s.push(...n.map((i) => ({ ...i }))), s.push({ handle: "error" });
331
+ const c = I(r.headers);
332
+ Object.keys(c).length > 0 && s.push({
333
+ continue: !0,
334
+ headers: c,
335
+ src: "^/.*$"
336
+ }), s.push(...n.map((i) => ({ ...i }))), s.push({ dest: `/${r.file}`, src: "^/.*$", status: 404 });
337
+ const a = Ot(s);
338
+ if (a.error || !a.routes)
339
+ throw new Error(
340
+ `Vercel rejected the generated routes: ${a.error?.message ?? "The route list is empty."}`
341
+ );
342
+ return {
343
+ overrides: Object.fromEntries(
344
+ t.entries.map((i) => [i.file, Wt(i)])
345
+ ),
346
+ routes: a.routes,
347
+ version: 3
348
+ };
349
+ }
350
+ function Wt(t) {
351
+ const e = {}, r = t.headers["content-type"];
352
+ if (r && (e.contentType = r), t.pathname !== "*") {
353
+ const n = t.file === "index.html" ? "/" : `/${t.file}`;
354
+ t.pathname !== n && (e.path = t.pathname.slice(1));
355
+ }
356
+ return e;
357
+ }
358
+ function R(t) {
359
+ const e = t.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
360
+ return t === "/" ? "^/$" : `^${e}/?$`;
361
+ }
362
+ function I(t) {
363
+ return Object.fromEntries(
364
+ Object.entries(t).filter(([e]) => e.toLowerCase() !== "content-type")
365
+ );
366
+ }
367
+ function kt(t) {
368
+ return t === ".*" ? "^/.*$" : t === U.source ? "^/(?:.*/)?[^/]*-[A-Za-z0-9_-]{8,}\\.[A-Za-z0-9]+$" : `^/${Dt(t)}$`;
369
+ }
370
+ function Dt(t) {
371
+ const e = t.startsWith("^"), r = t.endsWith("$") && !t.endsWith("\\$"), n = t.slice(
372
+ e ? 1 : 0,
373
+ r ? -1 : void 0
374
+ );
375
+ return `${e ? "(?:.*/)?" : "(?:.*/)?[^/]*"}(?:${n})${r ? "" : "[^/]*"}`;
376
+ }
377
+ function _t(t) {
378
+ const e = t.map((n) => ({
379
+ headers: [{ key: "cache-control", value: n.value }],
380
+ source: n.source
381
+ })), r = Rt({ headers: e });
382
+ if (r.error || !r.routes)
383
+ throw new Error(
384
+ `A Vercel static header rule is not valid: ${r.error?.message ?? "The route list is empty."}`
385
+ );
386
+ return r.routes;
387
+ }
388
+ function Ut(t, e) {
389
+ if (t) {
390
+ if (st(t), t.origins === "*")
391
+ return "*";
392
+ if (t.origins.length === 1)
393
+ return t.origins[0];
394
+ throw new Error(
395
+ "A Vercel static CORS policy must declare the wildcard origin or exactly one origin. A static response cannot vary access-control-allow-origin by request."
396
+ );
397
+ }
398
+ if (!e)
399
+ throw new Error(
400
+ "Vercel static output requires a build origin to emit access-control-allow-origin. Pass --origin, set SITE_ORIGIN, or declare a Vercel CORS policy."
401
+ );
402
+ return e;
403
+ }
404
+ function Vt(t) {
405
+ if (t.adapter !== "vercel" || !Array.isArray(t.cache))
406
+ throw new Error("The Vercel static adapter configuration is not valid.");
407
+ for (const e of t.cache)
408
+ if (!e || typeof e != "object" || typeof e.source != "string" || !e.source || typeof e.value != "string" || !e.value)
409
+ throw new Error("A Vercel static header rule is not valid.");
410
+ }
411
+ function zt(t, e) {
412
+ const r = w(t, e), n = w(e, t);
413
+ return j(r) || j(n);
414
+ }
415
+ function j(t) {
416
+ return !t || t !== ".." && !t.startsWith(`..${S}`) && !t.startsWith("/");
417
+ }
418
+ const K = "demiurge-static-manifest.json", qt = ot({
11
419
  name: "static",
12
420
  capabilities: {
13
421
  staticOutput: !0
14
422
  }
15
- });
16
- async function Et(t) {
17
- const e = z(t.origin), r = w(t.outDir), n = _(t.routes), o = await Q(n), i = await D(n, {
423
+ }), Bt = 8;
424
+ async function Gt(t) {
425
+ const e = Object.entries(t), r = new Array(e.length);
426
+ let n = 0;
427
+ const o = Array.from(
428
+ { length: Math.min(Bt, e.length) },
429
+ async () => {
430
+ for (; n < e.length; ) {
431
+ const s = n++, [c, a] = e[s];
432
+ try {
433
+ r[s] = [c, await a()];
434
+ } catch (i) {
435
+ throw new Error(
436
+ `Demiurge could not load route module ${JSON.stringify(c)}.`,
437
+ { cause: i }
438
+ );
439
+ }
440
+ }
441
+ }
442
+ );
443
+ return await Promise.all(o), Object.fromEntries(r);
444
+ }
445
+ async function be(t) {
446
+ const e = await Gt(t.routes), r = at(e, {
447
+ adapter: qt
448
+ }), n = Xt(t.origin), o = h(t.outDir), s = await te(r), c = await ct(r, {
18
449
  includeResources: !0
19
450
  });
20
- V(
21
- n,
22
- i.filter((u) => o.get(u.file) === "document").length
451
+ Yt(
452
+ r,
453
+ c.filter((l) => s.get(l.file) === "document").length
23
454
  );
24
- const c = Z(
25
- i.map((u) => ({
26
- kind: o.get(u.file) ?? "resource",
27
- pathname: u.pathname
455
+ const a = ne(
456
+ c.map((l) => ({
457
+ kind: s.get(l.file) ?? "resource",
458
+ pathname: l.pathname
28
459
  }))
29
- ), a = U(), s = [], f = { ...t.ssr, navigation: "document" };
30
- for (const u of c) {
31
- const l = v(e, u.pathname, u.kind), y = await j(n, l, {
460
+ ), i = ut(), u = [], f = { ...t.ssr, navigation: "document" };
461
+ for (const l of a) {
462
+ const d = J(n, l.pathname, l.kind), v = await lt(r, d, {
32
463
  onError: t.onError,
33
- rateLimitStore: a,
464
+ rateLimitStore: i,
34
465
  ssr: f
35
466
  });
36
- s.push(
37
- u.kind === "document" ? await T(u, y, 200) : await rt(u, y)
467
+ u.push(
468
+ l.kind === "document" ? await M(l, v, 200) : await se(l, v)
38
469
  );
39
470
  }
40
- const d = await q(
41
- n,
42
- v(e, "/404", "document"),
471
+ const E = await ft(
472
+ r,
473
+ J(n, "/404", "document"),
43
474
  {
44
475
  ...f,
45
- onError: (u, l) => t.onError?.(u, { pathname: "/404", site: l })
476
+ onError: (l, d) => t.onError?.(l, { pathname: "/404", site: d })
46
477
  }
47
478
  );
48
- s.push(
49
- await T(
479
+ u.push(
480
+ await M(
50
481
  {
51
482
  file: "404.html",
52
483
  pathname: "*"
53
484
  },
54
- d,
485
+ E,
55
486
  404
56
487
  )
57
- ), s.sort((u, l) => u.file.localeCompare(l.file));
58
- const S = {
488
+ );
489
+ const $ = u.map((l) => l.body);
490
+ At($, t.images);
491
+ const p = await Tt({
492
+ documents: $,
493
+ outDir: o,
494
+ policy: t.images
495
+ }), g = await yt({
496
+ fonts: t.fonts,
497
+ root: t.root ?? process.cwd()
498
+ });
499
+ u.sort((l, d) => l.file.localeCompare(d.file)), p.sort((l, d) => l.file.localeCompare(d.file)), g.sort((l, d) => l.file.localeCompare(d.file));
500
+ const m = {
59
501
  adapter: "static",
60
- entries: s.map(({ body: u, ...l }) => l),
61
- fileHeaderRules: K(),
502
+ entries: u.map(({ body: l, ...d }) => d),
503
+ fileHeaderRules: await Kt(
504
+ r,
505
+ t.staticFileHeaders ?? []
506
+ ),
507
+ fontFiles: g.map((l) => l.file),
508
+ imageFiles: p.map((l) => l.file),
509
+ origin: n,
62
510
  version: 1
63
511
  };
64
- return await at(r, s, S), S;
512
+ return await he(o, u, [...p, ...g], m), m;
65
513
  }
66
- function K() {
514
+ async function Kt(t, e) {
515
+ const r = await Zt(t), n = H(r);
67
516
  return [
517
+ ...e.map((o) => (Qt(o.pattern), {
518
+ headers: H(
519
+ dt(r, { headers: o.headers })
520
+ ),
521
+ pattern: o.pattern
522
+ })),
68
523
  {
69
- headers: { "cache-control": B },
70
- pattern: W.source
524
+ headers: {
525
+ ...n,
526
+ "cache-control": pt
527
+ },
528
+ pattern: U.source
71
529
  },
72
530
  {
73
- headers: { "cache-control": G },
531
+ headers: {
532
+ ...n,
533
+ "cache-control": mt
534
+ },
74
535
  pattern: ".*"
75
536
  }
76
537
  ];
77
538
  }
78
- function z(t) {
539
+ async function Zt(t) {
540
+ return { headers: (await t.policies.find(
541
+ (n) => n.fileSegments.length === 0
542
+ )?.load())?.policy?.document?.headers };
543
+ }
544
+ function H(t) {
545
+ return Object.fromEntries(ht(t, {}).entries());
546
+ }
547
+ function Qt(t) {
548
+ try {
549
+ new RegExp(t);
550
+ } catch {
551
+ throw new Error(
552
+ `Static file header pattern is not a valid regular expression: ${JSON.stringify(t)}.`
553
+ );
554
+ }
555
+ }
556
+ function Xt(t) {
79
557
  let e;
80
558
  try {
81
559
  e = new URL(t ?? "http://demiurge.local");
@@ -90,7 +568,7 @@ function z(t) {
90
568
  );
91
569
  return e.origin;
92
570
  }
93
- function V(t, e) {
571
+ function Yt(t, e) {
94
572
  if (e === 0)
95
573
  throw new Error("Static output requires at least one page route.");
96
574
  if (!t.fallbacks.notFound.some(
@@ -100,10 +578,10 @@ function V(t, e) {
100
578
  "Static output requires a root @not-found.tsx so 404.html is app-owned."
101
579
  );
102
580
  }
103
- async function Q(t) {
581
+ async function te(t) {
104
582
  const e = /* @__PURE__ */ new Map();
105
583
  for (const r of t.routes) {
106
- const n = await r.load(), o = X(n);
584
+ const n = await r.load(), o = ee(n);
107
585
  if (o.length > 0)
108
586
  throw new Error(
109
587
  `Static route ${JSON.stringify(r.file)} exports unsupported methods ${o.join(", ")}. Deploy a runtime adapter for request-time methods.`
@@ -116,14 +594,14 @@ async function Q(t) {
116
594
  e.set(r.file, "document");
117
595
  continue;
118
596
  }
119
- Y(r.file, n.GET), e.set(r.file, "resource");
597
+ re(r.file, n.GET), e.set(r.file, "resource");
120
598
  }
121
599
  return e;
122
600
  }
123
- function X(t) {
601
+ function ee(t) {
124
602
  return ["POST", "PUT", "PATCH", "DELETE", "OPTIONS", "HEAD"].filter((e) => t[e] !== void 0);
125
603
  }
126
- function Y(t, e) {
604
+ function re(t, e) {
127
605
  if ((e.kind === "text" || e.kind === "html" || e.kind === "json") && typeof e.value != "function")
128
606
  return;
129
607
  const r = "value" in e && typeof e.value == "function" ? `uses a request-dependent ${e.kind} value` : `uses the ${e.kind} response helper`;
@@ -131,23 +609,23 @@ function Y(t, e) {
131
609
  `Static route ${JSON.stringify(t)} ${r} and cannot produce a fixed output file. Use a fixed text, html, or json value, or deploy a runtime adapter.`
132
610
  );
133
611
  }
134
- function Z(t) {
612
+ function ne(t) {
135
613
  const e = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Set();
136
614
  return t.map(({ kind: n, pathname: o }) => {
137
615
  if (r.has(o))
138
616
  throw new Error(`Static output collected duplicate pathname ${JSON.stringify(o)}.`);
139
617
  r.add(o);
140
- const i = n === "document" ? J(o) : tt(o), c = i.toLocaleLowerCase("en-US"), a = [...e.entries()].find(
141
- ([s]) => s === c || s.startsWith(`${c}/`) || c.startsWith(`${s}/`)
618
+ const s = n === "document" ? Z(o) : ie(o), c = s.toLocaleLowerCase("en-US"), a = [...e.entries()].find(
619
+ ([i]) => i === c || i.startsWith(`${c}/`) || c.startsWith(`${i}/`)
142
620
  );
143
621
  if (a)
144
622
  throw new Error(
145
623
  `Static paths ${JSON.stringify(a[1])} and ${JSON.stringify(o)} map to the same portable output file or to a file and directory conflict.`
146
624
  );
147
- return e.set(c, o), { file: i, kind: n, pathname: o };
625
+ return e.set(c, o), { file: s, kind: n, pathname: o };
148
626
  });
149
627
  }
150
- function J(t) {
628
+ function Z(t) {
151
629
  if (!t.startsWith("/") || t.includes("?") || t.includes("#"))
152
630
  throw new Error(`Static output received invalid pathname ${JSON.stringify(t)}.`);
153
631
  return t === "/" ? "index.html" : [...t.split("/").slice(1).map((r) => {
@@ -157,27 +635,27 @@ function J(t) {
157
635
  } catch {
158
636
  throw new Error(`Static output pathname is not valid UTF-8: ${JSON.stringify(t)}.`);
159
637
  }
160
- return et(n, t), n;
638
+ return oe(n, t), n;
161
639
  }), "index.html"].join("/");
162
640
  }
163
- function tt(t) {
641
+ function ie(t) {
164
642
  if (t === "/")
165
643
  throw new Error("A static resource route cannot own the root pathname.");
166
- return J(t).slice(0, -11);
644
+ return Z(t).slice(0, -11);
167
645
  }
168
- function et(t, e) {
646
+ function oe(t, e) {
169
647
  const r = /[<>:"|?*]/.test(t) || [...t].some((n) => n.charCodeAt(0) <= 31) || /[. ]$/.test(t) || /^(con|prn|aux|nul|com[1-9]|lpt[1-9])(?:\.|$)/i.test(t);
170
648
  if (!t || t === "." || t === ".." || t.includes("/") || t.includes("\\") || r)
171
649
  throw new Error(
172
650
  `Static pathname ${JSON.stringify(e)} contains a segment that is unsafe or not portable as a file name: ${JSON.stringify(t)}.`
173
651
  );
174
652
  }
175
- function v(t, e, r) {
653
+ function J(t, e, r) {
176
654
  return new Request(`${t}${e}`, {
177
655
  headers: { accept: r === "document" ? "text/html" : "*/*" }
178
656
  });
179
657
  }
180
- async function T(t, e, r) {
658
+ async function M(t, e, r) {
181
659
  if (e.status !== r)
182
660
  throw new Error(
183
661
  `Static output for ${JSON.stringify(t.pathname)} returned status ${e.status}; expected ${r}.`
@@ -191,19 +669,19 @@ async function T(t, e, r) {
191
669
  throw new Error(
192
670
  `Static output for ${JSON.stringify(t.pathname)} attempted to set a cookie. Build artifacts cannot contain per-user response state.`
193
671
  );
194
- const o = await nt(
672
+ const o = await ae(
195
673
  await e.text(),
196
674
  e.headers
197
675
  );
198
- return await it(t.pathname, o, e.headers), {
676
+ return await ue(t.pathname, o, e.headers), {
199
677
  file: t.file,
200
- headers: A(e.headers),
678
+ headers: X(e.headers),
201
679
  body: o,
202
680
  pathname: t.pathname,
203
681
  status: r
204
682
  };
205
683
  }
206
- async function rt(t, e) {
684
+ async function se(t, e) {
207
685
  if (e.status !== 200)
208
686
  throw new Error(
209
687
  `Static output for ${JSON.stringify(t.pathname)} returned status ${e.status}; expected 200.`
@@ -214,48 +692,48 @@ async function rt(t, e) {
214
692
  );
215
693
  return {
216
694
  file: t.file,
217
- headers: A(e.headers),
695
+ headers: X(e.headers),
218
696
  body: await e.text(),
219
697
  pathname: t.pathname,
220
698
  status: 200
221
699
  };
222
700
  }
223
- async function nt(t, e) {
701
+ async function ae(t, e) {
224
702
  const r = new RegExp(
225
- `(?:^|\\s)${$}(?:\\s|$)`
226
- ), n = F(t, "script").filter((i) => r.test(i.attributes));
703
+ `(?:^|\\s)${P}(?:\\s|$)`
704
+ ), n = Q(t, "script").filter((s) => r.test(s.attributes));
227
705
  if (n.length === 0)
228
706
  return t;
229
707
  const o = await Promise.all(
230
- n.map((i) => x(i.content))
708
+ n.map((s) => _(s.content))
231
709
  );
232
- for (const i of [
710
+ for (const s of [
233
711
  "content-security-policy",
234
712
  "content-security-policy-report-only"
235
713
  ]) {
236
- const c = e.get(i);
237
- c && e.set(i, ot(c, o));
714
+ const c = e.get(s);
715
+ c && e.set(s, ce(c, o));
238
716
  }
239
717
  return t.replace(
240
- new RegExp(`\\s${$}(?=\\s|>)`, "g"),
718
+ new RegExp(`\\s${P}(?=\\s|>)`, "g"),
241
719
  ""
242
720
  );
243
721
  }
244
- function ot(t, e) {
245
- const r = t.split(";").map((s) => s.trim()).filter(Boolean), n = r.findIndex(
246
- (s) => s.split(/\s+/, 1)[0]?.toLowerCase() === "script-src"
722
+ function ce(t, e) {
723
+ const r = t.split(";").map((i) => i.trim()).filter(Boolean), n = r.findIndex(
724
+ (i) => i.split(/\s+/, 1)[0]?.toLowerCase() === "script-src"
247
725
  ), o = r.find(
248
- (s) => s.split(/\s+/, 1)[0]?.toLowerCase() === "default-src"
249
- ), i = n === -1 ? o : r[n];
250
- if (!i)
726
+ (i) => i.split(/\s+/, 1)[0]?.toLowerCase() === "default-src"
727
+ ), s = n === -1 ? o : r[n];
728
+ if (!s)
251
729
  return t;
252
- const c = i.split(/\s+/).slice(1).filter((s) => s !== "'none'"), a = [
730
+ const c = s.split(/\s+/).slice(1).filter((i) => i !== "'none'"), a = [
253
731
  "script-src",
254
732
  .../* @__PURE__ */ new Set([...c, ...e])
255
733
  ].join(" ");
256
734
  return n === -1 ? r.push(a) : r[n] = a, r.join("; ");
257
735
  }
258
- async function it(t, e, r) {
736
+ async function ue(t, e, r) {
259
737
  const n = r.get("content-security-policy");
260
738
  if (!n)
261
739
  return;
@@ -263,25 +741,35 @@ async function it(t, e, r) {
263
741
  throw new Error(
264
742
  `Static output for ${JSON.stringify(t)} uses a nonce-backed CSP. Use security.static() with stable hashes or a runtime adapter that injects a fresh nonce.`
265
743
  );
266
- const o = st(n);
267
- await N(
744
+ const o = le(n);
745
+ await L(
268
746
  t,
269
747
  e,
270
748
  "script",
271
- h(o, "script-src")
272
- ), await N(
749
+ x(o, "script-src", "default-src")
750
+ ), await L(
273
751
  t,
274
752
  e,
275
753
  "style",
276
- h(o, "style-src")
754
+ x(
755
+ o,
756
+ "style-src-elem",
757
+ "style-src",
758
+ "default-src"
759
+ )
277
760
  );
278
- const i = h(o, "style-src");
279
- if (i && /\sstyle\s*=/i.test(e) && !i.includes("'unsafe-inline'"))
761
+ const s = x(
762
+ o,
763
+ "style-src-attr",
764
+ "style-src",
765
+ "default-src"
766
+ );
767
+ if (s && /\sstyle\s*=/i.test(e) && !s.includes("'unsafe-inline'"))
280
768
  throw new Error(
281
769
  `Static output for ${JSON.stringify(t)} contains an inline style attribute that its CSP does not allow. Move the style into a stylesheet or explicitly allow inline styles.`
282
770
  );
283
771
  }
284
- function st(t) {
772
+ function le(t) {
285
773
  const e = /* @__PURE__ */ new Map();
286
774
  for (const r of t.split(";")) {
287
775
  const [n, ...o] = r.trim().split(/\s+/);
@@ -289,89 +777,149 @@ function st(t) {
289
777
  }
290
778
  return e;
291
779
  }
292
- function h(t, e) {
293
- return t.get(e) ?? t.get("default-src");
780
+ function x(t, ...e) {
781
+ for (const r of e) {
782
+ const n = t.get(r);
783
+ if (n)
784
+ return n;
785
+ }
294
786
  }
295
- async function N(t, e, r, n) {
787
+ async function L(t, e, r, n) {
296
788
  if (!(!n || n.includes("'unsafe-inline'")))
297
- for (const o of F(e, r)) {
298
- if (r === "script" && /(?:^|\s)src\s*=/i.test(o.attributes) || !o.content)
789
+ for (const o of Q(e, r)) {
790
+ if (r === "script") {
791
+ const c = fe(o.attributes, "src");
792
+ if (c) {
793
+ if (!de(n, c))
794
+ throw new Error(
795
+ `Static output for ${JSON.stringify(t)} contains script ${JSON.stringify(c)} that the effective script-src directive does not allow. Add its origin to security.needs.script or the route CSP policy.`
796
+ );
797
+ continue;
798
+ }
799
+ }
800
+ if (!o.content)
299
801
  continue;
300
- const i = await x(o.content);
301
- if (!n.includes(i))
802
+ const s = await _(o.content);
803
+ if (!n.includes(s))
302
804
  throw new Error(
303
- `Static output for ${JSON.stringify(t)} contains an inline ${r} without the required CSP hash ${i}.`
805
+ `Static output for ${JSON.stringify(t)} contains an inline ${r} without the required CSP hash ${s}.`
304
806
  );
305
807
  }
306
808
  }
307
- function F(t, e) {
308
- const r = t.toLowerCase(), n = [], o = `<${e}`, i = `</${e}`;
809
+ function fe(t, e) {
810
+ return t.match(
811
+ new RegExp(`(?:^|\\s)${e}\\s*=\\s*["']([^"']+)["']`, "i")
812
+ )?.[1]?.replaceAll("&amp;", "&");
813
+ }
814
+ function de(t, e) {
815
+ if (!t)
816
+ return !0;
817
+ if (t.includes("'none'") || t.includes("'strict-dynamic'") && t.some(
818
+ (n) => n.startsWith("'nonce-") || /^'sha(?:256|384|512)-/.test(n)
819
+ ))
820
+ return !1;
821
+ if (t.includes("*") || t.includes("'self'") && e.startsWith("/") && !e.startsWith("//") || e.startsWith("https:") && t.includes("https:") || e.startsWith("http:") && t.includes("http:"))
822
+ return !0;
823
+ let r;
824
+ try {
825
+ r = new URL(e, "https://demiurge.invalid");
826
+ } catch {
827
+ return !1;
828
+ }
829
+ return t.some((n) => {
830
+ if (n.startsWith("'"))
831
+ return !1;
832
+ let o;
833
+ try {
834
+ o = new URL(n);
835
+ } catch {
836
+ return !1;
837
+ }
838
+ const s = o.hostname.startsWith("*.") ? r.hostname.endsWith(o.hostname.slice(1)) && r.hostname !== o.hostname.slice(2) : r.hostname === o.hostname, c = o.pathname === "/" || o.pathname.endsWith("/") ? r.pathname.startsWith(o.pathname) : r.pathname === o.pathname;
839
+ return r.protocol === o.protocol && s && r.port === o.port && c;
840
+ });
841
+ }
842
+ function Q(t, e) {
843
+ const r = t.toLowerCase(), n = [], o = `<${e}`, s = `</${e}`;
309
844
  let c = 0;
310
845
  for (; c < t.length; ) {
311
846
  const a = r.indexOf(o, c);
312
847
  if (a === -1)
313
848
  break;
314
- const s = r.indexOf(">", a + o.length), f = s === -1 ? -1 : r.indexOf(i, s + 1), d = f === -1 ? -1 : r.indexOf(">", f + i.length);
315
- if (s === -1 || f === -1 || d === -1)
849
+ const i = r.indexOf(">", a + o.length), u = i === -1 ? -1 : r.indexOf(s, i + 1), f = u === -1 ? -1 : r.indexOf(">", u + s.length);
850
+ if (i === -1 || u === -1 || f === -1)
316
851
  throw new Error(`Static output contains an unclosed <${e}> element.`);
317
852
  n.push({
318
- attributes: t.slice(a + o.length, s),
319
- content: t.slice(s + 1, f)
320
- }), c = d + 1;
853
+ attributes: t.slice(a + o.length, i),
854
+ content: t.slice(i + 1, u)
855
+ }), c = f + 1;
321
856
  }
322
857
  return n;
323
858
  }
324
- function A(t) {
859
+ function X(t) {
325
860
  return Object.fromEntries(
326
861
  [...t.entries()].sort(([e], [r]) => e.localeCompare(r))
327
862
  );
328
863
  }
329
- async function at(t, e, r) {
330
- const n = O(t);
331
- await p(n, { recursive: !0 });
332
- const o = await k(m(n, ".demiurge-static-"));
864
+ async function he(t, e, r, n) {
865
+ const o = C(t);
866
+ await T(o, { recursive: !0 });
867
+ const s = await k(y(o, ".demiurge-static-"));
333
868
  try {
334
- for (const a of e) {
335
- const s = R(o, a.file);
336
- await p(O(s), { recursive: !0 }), await E(s, a.body);
869
+ for (const i of [...e, ...r]) {
870
+ const u = W(s, i.file);
871
+ await T(C(u), { recursive: !0 }), await b(u, i.body);
337
872
  }
338
- await E(
339
- m(o, C),
340
- `${JSON.stringify(r, null, 2)}
873
+ await b(
874
+ y(s, K),
875
+ `${JSON.stringify(n, null, 2)}
341
876
  `
342
877
  );
343
- const i = await ct(t);
344
- await p(t, { recursive: !0 }), await P(o, t, { recursive: !0, force: !0 });
345
- const c = new Set(e.map((a) => a.file));
346
- for (const a of i)
347
- c.has(a) || await g(R(t, a), { force: !0 });
878
+ const c = await pe(t);
879
+ await T(t, { recursive: !0 }), await D(s, t, { recursive: !0, force: !0 });
880
+ const a = new Set(
881
+ [...e, ...r].map((i) => i.file)
882
+ );
883
+ for (const i of c)
884
+ a.has(i) || await A(W(t, i), { force: !0 });
348
885
  } finally {
349
- await g(o, { force: !0, recursive: !0 });
886
+ await A(s, { force: !0, recursive: !0 });
350
887
  }
351
888
  }
352
- async function ct(t) {
889
+ async function pe(t) {
353
890
  try {
354
- const e = await b(m(t, C), "utf8"), r = JSON.parse(e);
355
- return r.adapter !== "static" || r.version !== 1 || !Array.isArray(r.entries) ? [] : r.entries.flatMap(
356
- (n) => typeof n.file == "string" && L(n.file) ? [n.file] : []
891
+ const e = await O(y(t, K), "utf8"), r = JSON.parse(e);
892
+ if (r.adapter !== "static" || r.version !== 1 || !Array.isArray(r.entries))
893
+ return [];
894
+ const n = Array.isArray(r.fontFiles) ? r.fontFiles : [], o = Array.isArray(r.imageFiles) ? r.imageFiles : [];
895
+ return [
896
+ ...r.entries.map((s) => s.file),
897
+ ...n,
898
+ ...o
899
+ ].flatMap(
900
+ (s) => typeof s == "string" && Y(s) ? [s] : []
357
901
  );
358
902
  } catch {
359
903
  return [];
360
904
  }
361
905
  }
362
- function R(t, e) {
363
- if (!L(e))
906
+ function W(t, e) {
907
+ if (!Y(e))
364
908
  throw new Error(`Static output file must stay inside the output directory: ${JSON.stringify(e)}.`);
365
- const r = w(t), n = w(r, e);
366
- if (M(r, n).split(H).includes(".."))
909
+ const r = h(t), n = h(r, e);
910
+ if (w(r, n).split(S).includes(".."))
367
911
  throw new Error(`Static output file escaped the output directory: ${JSON.stringify(e)}.`);
368
912
  return n;
369
913
  }
370
- function L(t) {
914
+ function Y(t) {
371
915
  return !!t && !t.startsWith("/") && !t.startsWith("\\") && !t.split(/[\\/]/).includes("..");
372
916
  }
373
917
  export {
374
- Et as generateStaticOutput,
375
- yt as staticAdapter
918
+ Ne as createStaticPreviewServer,
919
+ Lt as createVercelOutputConfig,
920
+ be as generateStaticOutput,
921
+ xe as generateVercelStaticOutput,
922
+ qt as staticAdapter,
923
+ Fe as vercelStatic
376
924
  };
377
925
  //# sourceMappingURL=index.js.map