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