@k8ordo/framework 2.0.0 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +25 -12
- package/dist/generated.d.mts +2 -1
- package/dist/headers-BxB_jJVk.mjs +73 -0
- package/dist/index.d.mts +2 -1
- package/dist/paths-type-DtsL8JuC.d.mts +19 -0
- package/dist/runtime/app-router.mjs +20 -7
- package/dist/runtime/client-files.d.mts +6 -5
- package/dist/runtime/client-files.mjs +17 -9
- package/dist/runtime/client-ready.d.mts +7 -1
- package/dist/runtime/client-ready.mjs +2 -1
- package/dist/runtime/entry.rsc.d.mts +27 -1
- package/dist/runtime/entry.rsc.mjs +66 -9
- package/dist/runtime/entry.ssr.d.mts +6 -1
- package/dist/runtime/entry.ssr.mjs +8 -3
- package/dist/runtime/payload.d.mts +19 -4
- package/dist/runtime/payload.mjs +20 -5
- package/dist/runtime/prefetch.d.mts +29 -8
- package/dist/runtime/prefetch.mjs +95 -24
- package/dist/serve.mjs +5 -3
- package/dist/{static-DnbgGIoy.d.mts → static-c-nX9Juk.d.mts} +11 -17
- package/dist/{static-file-BAjwBMMl.mjs → static-file-BEk_xO5y.mjs} +157 -24
- package/dist/{static-host-B-1fAfAw.mjs → static-host-CyAmsL_7.mjs} +1 -1
- package/dist/vercel.d.mts +1 -1
- package/dist/vercel.mjs +30 -15
- package/dist/vite.d.mts +2 -2
- package/dist/vite.mjs +231 -111
- package/docs/GUIDE.md +26 -27
- package/docs/llms.txt +37 -28
- package/docs/references/deploy.md +69 -9
- package/docs/references/errors.md +39 -2
- package/docs/references/params.md +166 -127
- package/docs/references/routing.md +192 -49
- package/package.json +9 -9
- package/dist/shared-dir-CNXFRZgP.mjs +0 -9
package/dist/vercel.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { t as isFile, u as isParamSegment } from "./static-file-BEk_xO5y.mjs";
|
|
2
|
+
import { a as sharedDir, t as declaredHeaders } from "./headers-BxB_jJVk.mjs";
|
|
3
3
|
import { withBase } from "@k8ordo/router";
|
|
4
4
|
import { cp, rm, writeFile } from "node:fs/promises";
|
|
5
5
|
import path from "node:path";
|
|
@@ -20,10 +20,21 @@ const immutableAssets = (base) => ({
|
|
|
20
20
|
continue: true,
|
|
21
21
|
important: true
|
|
22
22
|
});
|
|
23
|
+
/**
|
|
24
|
+
* The headers `framework()` declared, ahead of every other route: a route
|
|
25
|
+
* that only adds headers and goes on, so they are on whatever the routes
|
|
26
|
+
* after it lead to. None declared, no route.
|
|
27
|
+
*/
|
|
28
|
+
const declaredRoutes = (headers) => Object.keys(headers).length === 0 ? [] : [{
|
|
29
|
+
src: "^/.*$",
|
|
30
|
+
headers,
|
|
31
|
+
continue: true
|
|
32
|
+
}];
|
|
23
33
|
/** Files first, and whatever names none goes to the handler. */
|
|
24
|
-
const configFor = (base) => ({
|
|
34
|
+
const configFor = (base, headers) => ({
|
|
25
35
|
version: 3,
|
|
26
36
|
routes: [
|
|
37
|
+
...declaredRoutes(headers),
|
|
27
38
|
{ handle: "filesystem" },
|
|
28
39
|
{
|
|
29
40
|
src: "^/.*$",
|
|
@@ -61,7 +72,8 @@ const routeOf = (rule) => {
|
|
|
61
72
|
};
|
|
62
73
|
};
|
|
63
74
|
/**
|
|
64
|
-
* The application's `beforeFiles`, then the files
|
|
75
|
+
* The declared headers, the application's `beforeFiles`, then the files — a
|
|
76
|
+
* `beforeFiles` route may write a declared name over; only what names none is
|
|
65
77
|
* rewritten — a value the build did not write to its shell, the payload URL
|
|
66
78
|
* of a built URL that is not a page to HTML — and what nothing rewrote goes
|
|
67
79
|
* through the application's `beforeNotFound` to the build's `404.html`. A
|
|
@@ -69,9 +81,10 @@ const routeOf = (rule) => {
|
|
|
69
81
|
* where the extension says the same, so no file is left to the types Vercel
|
|
70
82
|
* gives an extension.
|
|
71
83
|
*/
|
|
72
|
-
const staticConfigFor = (base, { rewrites, notFound, types }, { beforeFiles = [], beforeNotFound = [] }) => ({
|
|
84
|
+
const staticConfigFor = (base, { rewrites, notFound, types }, { beforeFiles = [], beforeNotFound = [] }, headers) => ({
|
|
73
85
|
version: 3,
|
|
74
86
|
routes: [
|
|
87
|
+
...declaredRoutes(headers),
|
|
75
88
|
...beforeFiles,
|
|
76
89
|
{ handle: "filesystem" },
|
|
77
90
|
...rewrites.map((rule) => routeOf(rule)),
|
|
@@ -112,7 +125,7 @@ const json = (value) => `${JSON.stringify(value, null, 2)}\n`;
|
|
|
112
125
|
* and the request handler as the one function behind them. Only `output/` is
|
|
113
126
|
* replaced — `vercel pull` keeps the project's link and settings beside it.
|
|
114
127
|
*/
|
|
115
|
-
const writeVercelOutput = async (root, dirs, base) => {
|
|
128
|
+
const writeVercelOutput = async (root, dirs, base, headers = {}) => {
|
|
116
129
|
const output = path.join(root, ".vercel", "output");
|
|
117
130
|
await rm(output, {
|
|
118
131
|
recursive: true,
|
|
@@ -129,27 +142,27 @@ const writeVercelOutput = async (root, dirs, base) => {
|
|
|
129
142
|
await writeFile(path.join(func, "index.mjs"), `import handler from './${entry}';\n\nexport default { fetch: handler };\n`);
|
|
130
143
|
await writeFile(path.join(func, "package.json"), json({ type: "module" }));
|
|
131
144
|
await writeFile(path.join(func, ".vc-config.json"), json(FUNCTION_CONFIG));
|
|
132
|
-
await writeFile(path.join(output, "config.json"), json(configFor(base)));
|
|
145
|
+
await writeFile(path.join(output, "config.json"), json(configFor(base, headers)));
|
|
133
146
|
};
|
|
134
147
|
/**
|
|
135
148
|
* A static build laid out as Vercel's Build Output API (v3) reads it: the
|
|
136
149
|
* client build as static files at Vite's `base`, and the rewrites a host
|
|
137
150
|
* applies once no file answered as routes, around them the application's
|
|
138
|
-
* own — no function. `_redirects`
|
|
139
|
-
* would serve
|
|
151
|
+
* own — no function. `_redirects` and `_headers` stay behind: Vercel reads
|
|
152
|
+
* neither, and would serve them as files.
|
|
140
153
|
*/
|
|
141
|
-
const writeStaticVercelOutput = async ({ root, client, base }, output, routes = {}) => {
|
|
154
|
+
const writeStaticVercelOutput = async ({ root, client, base }, output, routes = {}, headers = {}) => {
|
|
142
155
|
const dir = path.join(root, ".vercel", "output");
|
|
143
156
|
await rm(dir, {
|
|
144
157
|
recursive: true,
|
|
145
158
|
force: true
|
|
146
159
|
});
|
|
147
|
-
const
|
|
160
|
+
const left = new Set(["_redirects", "_headers"].map((name) => path.join(client, name)));
|
|
148
161
|
await cp(client, path.join(dir, "static", base), {
|
|
149
162
|
recursive: true,
|
|
150
|
-
filter: (source) => source
|
|
163
|
+
filter: (source) => !left.has(source)
|
|
151
164
|
});
|
|
152
|
-
await writeFile(path.join(dir, "config.json"), json(staticConfigFor(base, output, routes)));
|
|
165
|
+
await writeFile(path.join(dir, "config.json"), json(staticConfigFor(base, output, routes, headers)));
|
|
153
166
|
};
|
|
154
167
|
// src/vercel.ts
|
|
155
168
|
/**
|
|
@@ -173,12 +186,14 @@ const vercel = (options = {}) => {
|
|
|
173
186
|
let root = "";
|
|
174
187
|
let base = "/";
|
|
175
188
|
let client = "";
|
|
189
|
+
let headers = {};
|
|
176
190
|
return {
|
|
177
191
|
name: "k8ordo:vercel",
|
|
178
192
|
apply: "build",
|
|
179
193
|
configResolved(config) {
|
|
180
194
|
isStatic = config.plugins.some((plugin) => plugin.name === "k8ordo:static");
|
|
181
195
|
({logger, root, base} = config);
|
|
196
|
+
headers = declaredHeaders(config.plugins);
|
|
182
197
|
client = path.resolve(root, config.environments.client?.build.outDir ?? "dist/client");
|
|
183
198
|
if (!isStatic && (beforeFiles !== void 0 || beforeNotFound !== void 0)) throw new Error("vercel() takes beforeFiles and beforeNotFound under mode: 'static' only — under mode: 'server' the handler answers every URL no file names");
|
|
184
199
|
},
|
|
@@ -187,7 +202,7 @@ const vercel = (options = {}) => {
|
|
|
187
202
|
root,
|
|
188
203
|
client,
|
|
189
204
|
base
|
|
190
|
-
}, output, options);
|
|
205
|
+
}, output, options, headers);
|
|
191
206
|
logger?.info("k8ordo: wrote .vercel/output");
|
|
192
207
|
} },
|
|
193
208
|
buildApp: {
|
|
@@ -203,7 +218,7 @@ const vercel = (options = {}) => {
|
|
|
203
218
|
client: dirOf("client"),
|
|
204
219
|
rsc: dirOf("rsc"),
|
|
205
220
|
ssr: dirOf("ssr")
|
|
206
|
-
}, builder.config.base);
|
|
221
|
+
}, builder.config.base, headers);
|
|
207
222
|
builder.config.logger.info("k8ordo: wrote .vercel/output");
|
|
208
223
|
}
|
|
209
224
|
}
|
package/dist/vite.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as ContentSecurityPolicy, r as EngineOptions, t as StaticOptions } from "./static-
|
|
1
|
+
import { n as ContentSecurityPolicy, r as EngineOptions, t as StaticOptions } from "./static-c-nX9Juk.mjs";
|
|
2
2
|
import { PluginOption } from "vite";
|
|
3
3
|
export type ServerOptions = EngineOptions & {
|
|
4
4
|
/**
|
|
@@ -7,7 +7,7 @@ export type ServerOptions = EngineOptions & {
|
|
|
7
7
|
*/
|
|
8
8
|
readonly mode: 'server';
|
|
9
9
|
};
|
|
10
|
-
/** `
|
|
10
|
+
/** `site` and `csp` describe files, so only `mode: 'static'` takes them. */
|
|
11
11
|
export type FrameworkOptions = StaticOptions | ServerOptions;
|
|
12
12
|
/**
|
|
13
13
|
* The application: `routes/` compiled into a route table and a request
|