@k8ordo/framework 1.4.2 → 1.4.4
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 +1 -1
- package/dist/runtime/document-root.d.mts +13 -0
- package/dist/runtime/document-root.mjs +18 -0
- package/dist/runtime/entry.browser.mjs +3 -2
- package/dist/runtime/entry.ssr.mjs +7 -8
- package/dist/{static-6z8_6B1U.d.mts → static-DnbgGIoy.d.mts} +2 -1
- package/dist/vercel.d.mts +1 -1
- package/dist/vite.d.mts +1 -1
- package/dist/vite.mjs +70 -17
- package/docs/GUIDE.md +3 -1
- package/docs/references/routing.md +21 -0
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -35,7 +35,7 @@ dependencies in either mode: the build bundles what the application runs.
|
|
|
35
35
|
|
|
36
36
|
| Package | Version | Required | Needed for |
|
|
37
37
|
| --------------------- | -------- | -------- | ------------------------------------------ |
|
|
38
|
-
| `@k8ordo/router` | ^1.4.
|
|
38
|
+
| `@k8ordo/router` | ^1.4.4 | yes | routing, re-exported by the framework |
|
|
39
39
|
| `react` | ≥19.3.0 | yes | rendering |
|
|
40
40
|
| `react-dom` | ≥19.3.0 | yes | rendering |
|
|
41
41
|
| `vite` | ≥8.1.0 | yes | the build (`framework()` is a Vite plugin) |
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ReactNode } from "react";
|
|
2
|
+
/**
|
|
3
|
+
* What the HTML render and the browser both render at the root, around the
|
|
4
|
+
* application. `useId` derives an id from where its component sits among its
|
|
5
|
+
* siblings all the way up, so a sibling only one side rendered here would
|
|
6
|
+
* give every id below another value in the browser than in the HTML, whose
|
|
7
|
+
* attributes hydration keeps.
|
|
8
|
+
*/
|
|
9
|
+
export declare function DocumentRoot({ children, styleNonce }: {
|
|
10
|
+
children: ReactNode;
|
|
11
|
+
/** The HTML render's, under a server. The browser finds the style written. */
|
|
12
|
+
styleNonce?: string | undefined;
|
|
13
|
+
}): ReactNode;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { SERVER_STYLESHEETS, STYLESHEET_ORDER_HREF } from "./payload.mjs";
|
|
2
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
// src/runtime/document-root.tsx
|
|
4
|
+
/**
|
|
5
|
+
* What the HTML render and the browser both render at the root, around the
|
|
6
|
+
* application. `useId` derives an id from where its component sits among its
|
|
7
|
+
* siblings all the way up, so a sibling only one side rendered here would
|
|
8
|
+
* give every id below another value in the browser than in the HTML, whose
|
|
9
|
+
* attributes hydration keeps.
|
|
10
|
+
*/
|
|
11
|
+
function DocumentRoot({ children, styleNonce }) {
|
|
12
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("style", {
|
|
13
|
+
href: STYLESHEET_ORDER_HREF,
|
|
14
|
+
precedence: SERVER_STYLESHEETS,
|
|
15
|
+
nonce: styleNonce
|
|
16
|
+
}), children] });
|
|
17
|
+
}
|
|
18
|
+
export { DocumentRoot };
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { whenClientReady } from "./client-ready.mjs";
|
|
2
2
|
import { AppRouter, setDocumentClient } from "./app-router.mjs";
|
|
3
3
|
import { connectAppRouter } from "./browser-payloads.mjs";
|
|
4
|
+
import { DocumentRoot } from "./document-root.mjs";
|
|
4
5
|
import { mount } from "./mount.mjs";
|
|
5
6
|
import { reportCaught } from "./page-boundary.mjs";
|
|
6
7
|
import { whenRevealed } from "./revealed.mjs";
|
|
@@ -14,12 +15,12 @@ const start = async () => {
|
|
|
14
15
|
setDocumentClient(payload.client);
|
|
15
16
|
await whenRevealed();
|
|
16
17
|
await whenClientReady([payload.tree, payload.notFound], { rows: "wait" });
|
|
17
|
-
mount(document, /* @__PURE__ */ jsx(AppRouter, {
|
|
18
|
+
mount(document, /* @__PURE__ */ jsx(DocumentRoot, { children: /* @__PURE__ */ jsx(AppRouter, {
|
|
18
19
|
notFound: payload.notFound,
|
|
19
20
|
pathname: payload.pathname,
|
|
20
21
|
search: payload.search,
|
|
21
22
|
tree: payload.tree
|
|
22
|
-
}), payload.pathname, {
|
|
23
|
+
}) }), payload.pathname, {
|
|
23
24
|
formState: payload.formState,
|
|
24
25
|
onCaughtError: reportCaught
|
|
25
26
|
});
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { SERVER_STYLESHEETS, STYLESHEET_ORDER_HREF } from "./payload.mjs";
|
|
2
1
|
import { whenClientReady } from "./client-ready.mjs";
|
|
3
2
|
import { AppRouter } from "./app-router.mjs";
|
|
4
3
|
import { noticeCancel } from "./cancel.mjs";
|
|
4
|
+
import { DocumentRoot } from "./document-root.mjs";
|
|
5
5
|
import { PageShownContext } from "./page-shown.mjs";
|
|
6
6
|
import { use } from "react";
|
|
7
|
-
import { jsx
|
|
7
|
+
import { jsx } from "react/jsx-runtime";
|
|
8
8
|
import { createFromReadableStream, getClientEntryUrl } from "@vitejs/plugin-rsc/ssr";
|
|
9
9
|
import { preinit, preloadModule } from "react-dom";
|
|
10
10
|
import { renderToReadableStream } from "react-dom/server.edge";
|
|
@@ -76,13 +76,12 @@ async function renderHtml(rscStream, nonce, showsPage, carriesFormState, named)
|
|
|
76
76
|
const shown = Promise.withResolvers();
|
|
77
77
|
let readerLeft = false;
|
|
78
78
|
const styleNonce = import.meta.env.K8ORDO_MODE === "static" ? void 0 : nonce;
|
|
79
|
-
const htmlStream = await renderToReadableStream(/* @__PURE__ */
|
|
79
|
+
const htmlStream = await renderToReadableStream(/* @__PURE__ */ jsx(PageShownContext, {
|
|
80
80
|
value: () => shown.resolve(void 0),
|
|
81
|
-
children:
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
}), /* @__PURE__ */ jsx(Root, {})]
|
|
81
|
+
children: /* @__PURE__ */ jsx(DocumentRoot, {
|
|
82
|
+
styleNonce,
|
|
83
|
+
children: /* @__PURE__ */ jsx(Root, {})
|
|
84
|
+
})
|
|
86
85
|
}), {
|
|
87
86
|
bootstrapModules: [clientEntry],
|
|
88
87
|
nonce: styleNonce === void 0 ? nonce : {
|
|
@@ -43,7 +43,8 @@ type StaticOptions = EngineOptions & {
|
|
|
43
43
|
* The origin the site is served from — `https://example.com`. With it the
|
|
44
44
|
* build also writes `sitemap.xml`, listing every page it rendered at its
|
|
45
45
|
* URL, Vite's `base` included; without it, no sitemap, because a sitemap of
|
|
46
|
-
* relative URLs is not one.
|
|
46
|
+
* relative URLs is not one. A `route.ts` that writes `sitemap.xml` as well
|
|
47
|
+
* stops the build, naming both: keep one of them.
|
|
47
48
|
*/
|
|
48
49
|
readonly site?: string;
|
|
49
50
|
/**
|
package/dist/vercel.d.mts
CHANGED
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-DnbgGIoy.mjs";
|
|
2
2
|
import { PluginOption } from "vite";
|
|
3
3
|
export type ServerOptions = EngineOptions & {
|
|
4
4
|
/**
|
package/dist/vite.mjs
CHANGED
|
@@ -1974,17 +1974,13 @@ const dirFor = (pathname) => {
|
|
|
1974
1974
|
return decoded;
|
|
1975
1975
|
};
|
|
1976
1976
|
/**
|
|
1977
|
-
*
|
|
1978
|
-
*
|
|
1979
|
-
*
|
|
1980
|
-
*/
|
|
1981
|
-
const
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
if (new URLPattern({ pathname: each.pattern }).test({ pathname })) return each.kind === "route";
|
|
1985
|
-
}
|
|
1986
|
-
return false;
|
|
1987
|
-
};
|
|
1977
|
+
* What answers a pathname the build writes: the first declared pattern that
|
|
1978
|
+
* matches it, in the matcher's order. The catch-all never answers a pathname
|
|
1979
|
+
* the build was given.
|
|
1980
|
+
*/
|
|
1981
|
+
const answering = (dir, pathname) => declaredPatterns(dir).find((each) => each.kind !== "notFound" && new URLPattern({ pathname: each.pattern }).test({ pathname }));
|
|
1982
|
+
/** Whether a route.ts answers a pathname the build writes, rather than a page. */
|
|
1983
|
+
const answeredByRoute = (dir, pathname) => answering(dir, pathname)?.kind === "route";
|
|
1988
1984
|
// src/static.ts
|
|
1989
1985
|
const NO_SHELLS = {
|
|
1990
1986
|
paths: /* @__PURE__ */ new Set(),
|
|
@@ -2034,6 +2030,50 @@ const routeRefusal = (routes) => `static build writes a route.ts as the file its
|
|
|
2034
2030
|
const reexportRefusal = (files) => `static build reads a route.ts's methods and a page's search by name, and export * names none of them — ${files.length === 1 ? "this re-exports" : "these re-export"} another module whole:\n${files.map((file) => ` ${file}`).join("\n")}\nname what ${files.length === 1 ? "it exports" : "they export"}, as export { GET } from '../../lib/feed' does`;
|
|
2035
2031
|
/** The route files whose exports static mode reads. */
|
|
2036
2032
|
const READ_BY_NAME = /* @__PURE__ */ new Set(["route", "page"]);
|
|
2033
|
+
/** Where a pathname's file lands inside the client build, `/`-separated. */
|
|
2034
|
+
const fileAt = (pathname, name = "") => path.posix.join(dirFor(pathname), name).slice(1);
|
|
2035
|
+
/**
|
|
2036
|
+
* Each route.ts whose file the build also writes for something else — a
|
|
2037
|
+
* page's or a redirect's HTML, a page's payload, `404.html`, `sitemap.xml`,
|
|
2038
|
+
* `_redirects` — as a line naming both. The build writes its own files after
|
|
2039
|
+
* the routes', and a page's beside them, so one would replace the other
|
|
2040
|
+
* without a word.
|
|
2041
|
+
*/
|
|
2042
|
+
const takenFiles = (tree, pathnames, { site, shells, named }) => {
|
|
2043
|
+
const own = /* @__PURE__ */ new Map();
|
|
2044
|
+
const claim = (file, by) => {
|
|
2045
|
+
own.set(file.toLowerCase(), {
|
|
2046
|
+
file,
|
|
2047
|
+
by
|
|
2048
|
+
});
|
|
2049
|
+
};
|
|
2050
|
+
const routes = [];
|
|
2051
|
+
for (const pathname of pathnames) {
|
|
2052
|
+
const answer = answering(tree, pathname);
|
|
2053
|
+
if (answer?.kind === "route") routes.push({
|
|
2054
|
+
file: fileAt(pathname),
|
|
2055
|
+
route: answer.file,
|
|
2056
|
+
supplied: isConcrete(answer.pattern) ? void 0 : pathname
|
|
2057
|
+
});
|
|
2058
|
+
else if (answer !== void 0) {
|
|
2059
|
+
const page = `${named(answer.file)} is written there`;
|
|
2060
|
+
claim(fileAt(pathname, "index.html"), page);
|
|
2061
|
+
if (answer.kind === "page") claim(fileAt(pathname, "index.rsc"), page);
|
|
2062
|
+
}
|
|
2063
|
+
}
|
|
2064
|
+
const notFound = declaredPatterns(tree).find((each) => each.kind === "notFound");
|
|
2065
|
+
if (notFound !== void 0) claim("404.html", `${named(notFound.file)} is written there`);
|
|
2066
|
+
if (site) claim("sitemap.xml", "the \"site\" option writes it");
|
|
2067
|
+
if (shells.length > 0) claim("_redirects", `the shells of ${shells.map((file) => named(file)).join(", ")} are reached through it — rules of your own go in public/_redirects, which the build adds to its own`);
|
|
2068
|
+
return routes.flatMap(({ file, route, supplied }) => {
|
|
2069
|
+
const taken = own.get(file.toLowerCase());
|
|
2070
|
+
if (taken === void 0) return [];
|
|
2071
|
+
const sameAs = taken.file === file ? "" : ` (the same file as ${taken.file} on macOS and Windows)`;
|
|
2072
|
+
const unlisted = supplied === void 0 ? "" : `; or leave ${supplied} out of "paths"`;
|
|
2073
|
+
return [`${file}${sameAs}: ${named(route)}, and ${taken.by}${unlisted}`];
|
|
2074
|
+
}).toSorted();
|
|
2075
|
+
};
|
|
2076
|
+
const takenRefusal = (lines) => `static build writes a file of its own where these route.ts files write theirs, and one would replace the other — remove the route.ts, or what else writes the file:\n${lines.map((line) => ` ${line}`).join("\n")}`;
|
|
2037
2077
|
/**
|
|
2038
2078
|
* Static mode: the same request handler the server mode runs per request is
|
|
2039
2079
|
* called at build time — for each route's HTML and again for its payload —
|
|
@@ -2056,13 +2096,21 @@ const staticMode = (options) => {
|
|
|
2056
2096
|
let suppliedFor;
|
|
2057
2097
|
let suppliedInDev = Promise.resolve([]);
|
|
2058
2098
|
const noticed = /* @__PURE__ */ new Set();
|
|
2099
|
+
const fromRoot = (file) => path.relative(root, path.join(routesDir, file));
|
|
2059
2100
|
const devRoutes = () => routesRead ??= (async () => {
|
|
2060
2101
|
const { tree, problems } = parseRouteTree(await scanRoutes(routesDir));
|
|
2061
2102
|
const failed = problems.length > 0;
|
|
2103
|
+
const shapes = failed ? [] : fallbackShapes(tree);
|
|
2104
|
+
const taken = failed ? [] : takenFiles(tree, patternsOf(tree).filter((pattern) => isConcrete(pattern)), {
|
|
2105
|
+
site: options.site !== void 0,
|
|
2106
|
+
shells: shapes.map((shape) => shape.file),
|
|
2107
|
+
named: fromRoot
|
|
2108
|
+
});
|
|
2109
|
+
if (taken.length > 0) logger?.warn(`k8ordo: the build will stop: ${takenRefusal(taken)}`);
|
|
2062
2110
|
return {
|
|
2063
2111
|
tree,
|
|
2064
2112
|
failed,
|
|
2065
|
-
shapes
|
|
2113
|
+
shapes
|
|
2066
2114
|
};
|
|
2067
2115
|
})();
|
|
2068
2116
|
const devShells = () => shellsRead ??= (async () => {
|
|
@@ -2172,12 +2220,11 @@ const staticMode = (options) => {
|
|
|
2172
2220
|
order: "pre",
|
|
2173
2221
|
async handler() {
|
|
2174
2222
|
const files = await scanRoutes(routesDir);
|
|
2175
|
-
const
|
|
2176
|
-
const guards = files.filter((file) => slotOf(file) === "guard").map((file) => named(file));
|
|
2223
|
+
const guards = files.filter((file) => slotOf(file) === "guard").map((file) => fromRoot(file));
|
|
2177
2224
|
const exported = await readExports(routesDir, files);
|
|
2178
|
-
const routes = [...exported].filter(([file]) => slotOf(file) === "route").map(([file, names]) => [
|
|
2179
|
-
const searching = [...pagesReadingSearch(exported)].map((file) =>
|
|
2180
|
-
const reexporting = [...exported].filter(([file, names]) => READ_BY_NAME.has(slotOf(file) ?? "") && names.has("*")).map(([file]) =>
|
|
2225
|
+
const routes = [...exported].filter(([file]) => slotOf(file) === "route").map(([file, names]) => [fromRoot(file), unwritable(names)]).filter(([, methods]) => methods.length > 0);
|
|
2226
|
+
const searching = [...pagesReadingSearch(exported)].map((file) => fromRoot(file));
|
|
2227
|
+
const reexporting = [...exported].filter(([file, names]) => READ_BY_NAME.has(slotOf(file) ?? "") && names.has("*")).map(([file]) => fromRoot(file));
|
|
2181
2228
|
const refusals = [
|
|
2182
2229
|
...guards.length > 0 ? [guardRefusal(guards)] : [],
|
|
2183
2230
|
...routes.length > 0 ? [routeRefusal(routes)] : [],
|
|
@@ -2304,6 +2351,12 @@ const staticMode = (options) => {
|
|
|
2304
2351
|
return below === void 0 ? [] : [`${route} — ${below} is written below it, as a directory`];
|
|
2305
2352
|
});
|
|
2306
2353
|
if (unfileable.length > 0) throw new Error(`static build cannot write a route.ts as a file at ${unfileable.join("; ")}`);
|
|
2354
|
+
const taken = takenFiles(tree, plan.paths, {
|
|
2355
|
+
site: options.site !== void 0,
|
|
2356
|
+
shells: fallbackShapes(tree).filter((shape) => plan.shells.some((shell) => shell.pattern === shape.pattern)).map((shape) => shape.file),
|
|
2357
|
+
named: fromRoot
|
|
2358
|
+
});
|
|
2359
|
+
if (taken.length > 0) throw new Error(takenRefusal(taken));
|
|
2307
2360
|
const entry = path.resolve(root, rscOut, "index.js");
|
|
2308
2361
|
const handler = (await import(pathToFileURL(entry).href)).default;
|
|
2309
2362
|
const refused = [];
|
package/docs/GUIDE.md
CHANGED
|
@@ -285,7 +285,9 @@ them with `mode: 'server'` is a type error:
|
|
|
285
285
|
- `site` — the origin the site is served from, `https://example.com`. With
|
|
286
286
|
it the build also writes `sitemap.xml`, listing every page it rendered;
|
|
287
287
|
without it there is no sitemap, because a sitemap of relative URLs is not
|
|
288
|
-
one.
|
|
288
|
+
one. A `route.ts` that writes `sitemap.xml` as well stops the build,
|
|
289
|
+
naming both — keep one
|
|
290
|
+
([Routing](references/routing.md#under-static-mode)).
|
|
289
291
|
- `csp` — the Content-Security-Policy each page carries
|
|
290
292
|
([Content Security Policy](references/csp.md#static-mode-hashes-in-a-meta)).
|
|
291
293
|
|
|
@@ -353,6 +353,27 @@ A `route.ts` at `/` cannot be a file (the host serves `/` from `index.html`),
|
|
|
353
353
|
nor one with pages written below it, which would need a directory of the same
|
|
354
354
|
name. What it writes is not a page, so `sitemap.xml` leaves it out.
|
|
355
355
|
|
|
356
|
+
Nor can a `route.ts` write a file the build writes itself — `sitemap.xml`
|
|
357
|
+
when `site` is given, `404.html` beside a `not-found.tsx`, `_redirects` when
|
|
358
|
+
there are shells, a page's `index.html` or `index.rsc` — since one would
|
|
359
|
+
replace the other. Names that differ only in case count as the same file, as
|
|
360
|
+
they are on macOS and Windows, so the build stops the same on every system.
|
|
361
|
+
It stops before it renders anything, naming both:
|
|
362
|
+
|
|
363
|
+
```
|
|
364
|
+
static build writes a file of its own where these route.ts files write theirs, and one would replace the other — remove the route.ts, or what else writes the file:
|
|
365
|
+
sitemap.xml: src/routes/sitemap.xml/route.ts, and the "site" option writes it
|
|
366
|
+
```
|
|
367
|
+
|
|
368
|
+
For a sitemap of your own, keep the `route.ts` and drop `site`; the requests
|
|
369
|
+
the build hands every `route.ts` then carry no origin of the site's, so write
|
|
370
|
+
its absolute URLs from one of your own. A `route.ts` with params writes there
|
|
371
|
+
only for a pathname `paths` gave it, and its line ends with that pathname to
|
|
372
|
+
leave out of `paths`. Rules of your own for a host go in `public/_redirects`,
|
|
373
|
+
which the build adds to its own. `vite dev` does not stop: it warns of what
|
|
374
|
+
the build will refuse, for a `route.ts` whose URL has no params; the
|
|
375
|
+
pathnames `paths` gives one with params only the build sees.
|
|
376
|
+
|
|
356
377
|
Name the type in the `Response`. A string body with none is sent as
|
|
357
378
|
`text/plain;charset=UTF-8` — the `Response` sets it — so a `sitemap.xml`
|
|
358
379
|
returned that way is plain text on Vercel and in `vite dev`, whatever its
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@k8ordo/framework",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.4",
|
|
4
4
|
"description": "The k8ordo framework: routes/ compiled into React Server Components, run with or without a server.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"k8ordo",
|
|
@@ -76,7 +76,7 @@
|
|
|
76
76
|
"devDependencies": {
|
|
77
77
|
"@arethetypeswrong/cli": "0.18.5",
|
|
78
78
|
"@k8ordo/framework-engine": "^0.1.1",
|
|
79
|
-
"@k8ordo/router": "^1.4.
|
|
79
|
+
"@k8ordo/router": "^1.4.4",
|
|
80
80
|
"@types/compressible": "2.0.3",
|
|
81
81
|
"@types/fresh": "0.5.3",
|
|
82
82
|
"@types/mime-types": "3.0.1",
|
|
@@ -92,7 +92,7 @@
|
|
|
92
92
|
"vitest": "5.0.5"
|
|
93
93
|
},
|
|
94
94
|
"peerDependencies": {
|
|
95
|
-
"@k8ordo/router": "^1.4.
|
|
95
|
+
"@k8ordo/router": "^1.4.4",
|
|
96
96
|
"oxc-transform-react": "^0.152.0",
|
|
97
97
|
"react": ">=19.3.0",
|
|
98
98
|
"react-dom": ">=19.3.0",
|