@kasperrt/smolter 0.3.1 → 0.3.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.
- package/.generated/client/deployment-check.ts +70 -0
- package/.generated/client/deployment.ts +21 -58
- package/.generated/client/index.ts +8 -2
- package/.generated/core/responses.ts +8 -3
- package/.generated/core/router.ts +32 -0
- package/.generated/core/types.ts +2 -0
- package/.generated/preact/client.tsx +48 -6
- package/.generated/preact/document.tsx +4 -2
- package/.generated/preact/lazy-route.ts +2 -0
- package/.generated/preact/root-context.ts +2 -0
- package/.generated/preact/route-types.ts +1 -0
- package/.generated/preact/router.tsx +9 -3
- package/.generated/server/application.tsx +83 -19
- package/.generated/server/handler.ts +8 -2
- package/.generated/server/http.ts +24 -2
- package/.generated/server/index.ts +17 -5
- package/.generated/server/preact.ts +1 -0
- package/.generated/server/private-response.ts +11 -0
- package/.generated/server/stream-document.ts +121 -0
- package/.generated/vite/application/lazy-files.ts +8 -2
- package/.generated/vite/application/vite.ts +9 -3
- package/.generated/vite/index.ts +4 -2
- package/.generated/vite/transport.ts +4 -1
- package/CHANGELOG.md +10 -0
- package/README.md +29 -11
- package/dist/client/deployment-check.d.ts +6 -0
- package/dist/client/deployment-check.js +51 -0
- package/dist/client/deployment.d.ts +2 -0
- package/dist/client/deployment.js +11 -39
- package/dist/client/index.d.ts +3 -1
- package/dist/client/index.js +3 -3
- package/dist/core/responses.d.ts +1 -1
- package/dist/core/responses.js +3 -3
- package/dist/core/router.js +16 -0
- package/dist/core/types.d.ts +2 -0
- package/dist/preact/client.d.ts +6 -1
- package/dist/preact/client.js +27 -8
- package/dist/preact/document.js +4 -2
- package/dist/preact/lazy-route.d.ts +1 -0
- package/dist/preact/lazy-route.js +2 -1
- package/dist/preact/root-context.d.ts +2 -0
- package/dist/preact/route-types.d.ts +1 -0
- package/dist/preact/router.d.ts +1 -1
- package/dist/preact/router.js +3 -3
- package/dist/server/application.d.ts +4 -1
- package/dist/server/application.js +47 -13
- package/dist/server/handler.d.ts +3 -1
- package/dist/server/handler.js +5 -3
- package/dist/server/http.d.ts +5 -1
- package/dist/server/http.js +10 -1
- package/dist/server/index.d.ts +1 -1
- package/dist/server/index.js +12 -2
- package/dist/server/preact.d.ts +1 -1
- package/dist/server/private-response.d.ts +2 -0
- package/dist/server/private-response.js +13 -0
- package/dist/server/stream-document.d.ts +9 -0
- package/dist/server/stream-document.js +78 -0
- package/dist/vite/application/lazy-files.d.ts +1 -1
- package/dist/vite/application/lazy-files.js +5 -2
- package/dist/vite/application/vite.d.ts +2 -1
- package/dist/vite/application/vite.js +7 -4
- package/dist/vite/index.d.ts +2 -1
- package/dist/vite/index.js +6 -3
- package/dist/vite/transport.d.ts +1 -1
- package/dist/vite/transport.js +3 -2
- package/jsr.json +1 -1
- package/package.json +2 -2
|
@@ -3,7 +3,7 @@ import { readFile } from "node:fs/promises";
|
|
|
3
3
|
import { resolve } from "node:path";
|
|
4
4
|
import { transformWithOxc } from "vite";
|
|
5
5
|
//#region .generated/vite/application/lazy-files.ts
|
|
6
|
-
function lazyFiles(directory) {
|
|
6
|
+
function lazyFiles(directory, dataEndpoint = "/_smolter") {
|
|
7
7
|
let root;
|
|
8
8
|
const modules = /* @__PURE__ */ new Map();
|
|
9
9
|
return {
|
|
@@ -52,7 +52,10 @@ function lazyFiles(directory) {
|
|
|
52
52
|
const source = await readFile(route.file, "utf8");
|
|
53
53
|
const transformed = await transformWithOxc(source, route.file);
|
|
54
54
|
const ast = this.parse(transformed.code);
|
|
55
|
-
const fields = {
|
|
55
|
+
const fields = {
|
|
56
|
+
path: route.path,
|
|
57
|
+
dataEndpoint
|
|
58
|
+
};
|
|
56
59
|
for (const statement of ast.body) {
|
|
57
60
|
if (statement.type === "ExportDefaultDeclaration") {
|
|
58
61
|
fields.default = true;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import type { Plugin, UserConfig } from "vite";
|
|
2
2
|
export interface ApplicationOptions {
|
|
3
3
|
directory?: string;
|
|
4
|
+
dataEndpoint?: string;
|
|
4
5
|
ssr?: boolean;
|
|
5
6
|
splitRoutes?: boolean;
|
|
6
7
|
resourceRequest?: (url: string) => boolean;
|
|
7
8
|
}
|
|
8
9
|
export declare const preactConfig: UserConfig;
|
|
9
|
-
export declare function applicationPlugins({ directory, ssr, splitRoutes, resourceRequest, }?: ApplicationOptions): Plugin[];
|
|
10
|
+
export declare function applicationPlugins({ directory, dataEndpoint, ssr, splitRoutes, resourceRequest, }?: ApplicationOptions): Plugin[];
|
|
@@ -43,7 +43,7 @@ var preactConfig = {
|
|
|
43
43
|
"@kasperrt/smolter/preact/lazy-route"
|
|
44
44
|
] }
|
|
45
45
|
};
|
|
46
|
-
function applicationPlugins({ directory = "src/routes", ssr = true, splitRoutes = true, resourceRequest } = {}) {
|
|
46
|
+
function applicationPlugins({ directory = "src/routes", dataEndpoint = "/_smolter", ssr = true, splitRoutes = true, resourceRequest } = {}) {
|
|
47
47
|
return [
|
|
48
48
|
{
|
|
49
49
|
name: "smolter-application",
|
|
@@ -60,7 +60,8 @@ function applicationPlugins({ directory = "src/routes", ssr = true, splitRoutes
|
|
|
60
60
|
},
|
|
61
61
|
configureServer(server) {
|
|
62
62
|
server.middlewares.use((incoming, outgoing, next) => {
|
|
63
|
-
if (!incoming.url?.startsWith(
|
|
63
|
+
if (!incoming.url?.startsWith(`${dataEndpoint}?`)) return next();
|
|
64
|
+
outgoing.setHeader("Cache-Control", "private, no-store");
|
|
64
65
|
const run = async () => {
|
|
65
66
|
const target = new URL(incoming.url, "http://local").searchParams.get("url");
|
|
66
67
|
if (!target?.startsWith("/") || target.startsWith("//")) return send(new Response("Invalid route URL", { status: 400 }), outgoing);
|
|
@@ -74,6 +75,7 @@ function applicationPlugins({ directory = "src/routes", ssr = true, splitRoutes
|
|
|
74
75
|
return () => {
|
|
75
76
|
server.middlewares.use((incoming, outgoing, next) => {
|
|
76
77
|
if (!incoming.headers.accept?.includes("text/html") && !resourceRequest?.(incoming.originalUrl ?? incoming.url ?? "")) return next();
|
|
78
|
+
outgoing.setHeader("Cache-Control", "private, no-store");
|
|
77
79
|
const run = async () => {
|
|
78
80
|
const request = await webRequest(incoming, outgoing);
|
|
79
81
|
const response = await (await server.ssrLoadModule("/src/entry.server.tsx")).default(request, "/src/entry.client.tsx");
|
|
@@ -90,10 +92,11 @@ function applicationPlugins({ directory = "src/routes", ssr = true, splitRoutes
|
|
|
90
92
|
}
|
|
91
93
|
},
|
|
92
94
|
browserBoundary(),
|
|
93
|
-
...splitRoutes ? [lazyFiles(directory)] : [],
|
|
95
|
+
...splitRoutes ? [lazyFiles(directory, dataEndpoint)] : [],
|
|
94
96
|
routerPlugin({
|
|
95
97
|
directory,
|
|
96
|
-
framework: "preact"
|
|
98
|
+
framework: "preact",
|
|
99
|
+
dataEndpoint
|
|
97
100
|
})
|
|
98
101
|
];
|
|
99
102
|
}
|
package/dist/vite/index.d.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { type Plugin } from "vite";
|
|
2
2
|
export interface FileRouterOptions {
|
|
3
3
|
directory?: string;
|
|
4
|
+
dataEndpoint?: string;
|
|
4
5
|
clientRoutes?: string;
|
|
5
6
|
serverRoutes?: string;
|
|
6
7
|
framework?: "react" | "preact";
|
|
7
8
|
}
|
|
8
9
|
/** Build-time flat route discovery and the optional server data transport. */
|
|
9
|
-
export declare function routerPlugin({ directory, clientRoutes, serverRoutes, framework, }?: FileRouterOptions): Plugin;
|
|
10
|
+
export declare function routerPlugin({ directory, dataEndpoint, clientRoutes, serverRoutes, framework, }?: FileRouterOptions): Plugin;
|
|
10
11
|
/** File routing is the default; this alias keeps configuration explicit. */
|
|
11
12
|
export declare const fileRouter: typeof routerPlugin;
|
package/dist/vite/index.js
CHANGED
|
@@ -5,7 +5,7 @@ import { relative, resolve } from "node:path";
|
|
|
5
5
|
import { transformWithOxc } from "vite";
|
|
6
6
|
//#region .generated/vite/index.ts
|
|
7
7
|
/** Build-time flat route discovery and the optional server data transport. */
|
|
8
|
-
function routerPlugin({ directory = "src/routes", clientRoutes, serverRoutes, framework = "react" } = {}) {
|
|
8
|
+
function routerPlugin({ directory = "src/routes", dataEndpoint = "/_smolter", clientRoutes, serverRoutes, framework = "react" } = {}) {
|
|
9
9
|
let root;
|
|
10
10
|
let projectRoot;
|
|
11
11
|
const publicId = "virtual:smolter/routes";
|
|
@@ -75,7 +75,10 @@ function routerPlugin({ directory = "src/routes", clientRoutes, serverRoutes, fr
|
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
77
|
imports.push(`import * as route${index} from ${JSON.stringify(file + (options?.ssr ? "" : suffix))};`);
|
|
78
|
-
definitions.push(options?.ssr || !Object.keys(handlers).length ? `{ ...route${index}, path: ${JSON.stringify(route.path)} }` : `serverRoute(${JSON.stringify(route.path)}, route${index}, ${JSON.stringify(
|
|
78
|
+
definitions.push(options?.ssr || !Object.keys(handlers).length ? `{ ...route${index}, path: ${JSON.stringify(route.path)} }` : `serverRoute(${JSON.stringify(route.path)}, route${index}, ${JSON.stringify({
|
|
79
|
+
...handlers,
|
|
80
|
+
dataEndpoint
|
|
81
|
+
})})`);
|
|
79
82
|
}
|
|
80
83
|
if (!options?.ssr && definitions.some((definition) => definition.startsWith("serverRoute("))) imports.unshift(`import { serverRoute } from "@kasperrt/smolter/${framework}/client";`);
|
|
81
84
|
return `${imports.join("\n")}\nexport default [${definitions.join(",\n")}];\n`;
|
|
@@ -101,7 +104,7 @@ function routerPlugin({ directory = "src/routes", clientRoutes, serverRoutes, fr
|
|
|
101
104
|
server.watcher.off("change", refresh);
|
|
102
105
|
server.watcher.off("unlink", refresh);
|
|
103
106
|
});
|
|
104
|
-
configureTransport(server, publicId, framework);
|
|
107
|
+
configureTransport(server, publicId, framework, dataEndpoint);
|
|
105
108
|
}
|
|
106
109
|
};
|
|
107
110
|
}
|
package/dist/vite/transport.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { ViteDevServer } from "vite";
|
|
2
|
-
export declare function configureTransport(server: ViteDevServer, publicId: string, framework?: "react" | "preact"): void;
|
|
2
|
+
export declare function configureTransport(server: ViteDevServer, publicId: string, framework?: "react" | "preact", dataEndpoint?: string): void;
|
package/dist/vite/transport.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
//#region .generated/vite/transport.ts
|
|
2
|
-
function configureTransport(server, publicId, framework = "react") {
|
|
2
|
+
function configureTransport(server, publicId, framework = "react", dataEndpoint = "/_smolter") {
|
|
3
3
|
server.middlewares.use((incoming, outgoing, next) => {
|
|
4
|
-
if (!incoming.url?.startsWith(
|
|
4
|
+
if (!incoming.url?.startsWith(`${dataEndpoint}?`)) return next();
|
|
5
|
+
outgoing.setHeader("Cache-Control", "private, no-store");
|
|
5
6
|
const dispatch = async () => {
|
|
6
7
|
const origin = `http://${incoming.headers.host}`;
|
|
7
8
|
const target = new URL(incoming.url, origin).searchParams.get("url");
|
package/jsr.json
CHANGED
package/package.json
CHANGED
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
"wouter": "3.13.0",
|
|
57
57
|
"wouter-preact": "3.13.0"
|
|
58
58
|
},
|
|
59
|
-
"version": "0.3.
|
|
59
|
+
"version": "0.3.2",
|
|
60
60
|
"description": "A tiny typed data router for React and Preact.",
|
|
61
61
|
"sideEffects": false,
|
|
62
62
|
"license": "MIT",
|
|
@@ -138,7 +138,7 @@
|
|
|
138
138
|
"react": ">=18",
|
|
139
139
|
"preact": ">=11.0.1",
|
|
140
140
|
"vite": ">=8",
|
|
141
|
-
"preact-render-to-string": ">=6"
|
|
141
|
+
"preact-render-to-string": ">=6.8.1"
|
|
142
142
|
},
|
|
143
143
|
"peerDependenciesMeta": {
|
|
144
144
|
"react": {
|