@rebask/core 0.2.1 → 0.4.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/dist/components/head.d.ts +2 -11
- package/dist/components/head.d.ts.map +1 -1
- package/dist/components/head.js +12 -24
- package/dist/components/image.d.ts +16 -3
- package/dist/components/image.d.ts.map +1 -1
- package/dist/components/image.js +50 -68
- package/dist/components/link.d.ts.map +1 -1
- package/dist/components/link.js +6 -2
- package/dist/entry.browser.js +2 -2
- package/dist/entry.ssr.d.ts.map +1 -1
- package/dist/entry.ssr.js +12 -7
- package/dist/handlers/rsc/background-render.js +2 -2
- package/dist/handlers/rsc/render-request.js +2 -2
- package/dist/handlers/rsc/render-to-response.js +2 -2
- package/dist/handlers/rsc/state.d.ts.map +1 -1
- package/dist/handlers/rsc/state.js +11 -5
- package/dist/lib/client-route-prediction.d.ts +1 -1
- package/dist/lib/client-route-prediction.d.ts.map +1 -1
- package/dist/lib/client-route-prediction.js +2 -7
- package/dist/lib/head/head-manager.d.ts +9 -0
- package/dist/lib/head/head-manager.d.ts.map +1 -0
- package/dist/lib/head/head-manager.js +98 -0
- package/dist/lib/head/head-script.js +8 -13
- package/dist/lib/image-optimization/fetch-remote-image.d.ts +17 -0
- package/dist/lib/image-optimization/fetch-remote-image.d.ts.map +1 -0
- package/dist/lib/image-optimization/fetch-remote-image.js +157 -0
- package/dist/lib/image-optimization/get-img-props.d.ts +3 -5
- package/dist/lib/image-optimization/get-img-props.d.ts.map +1 -1
- package/dist/lib/image-optimization/get-img-props.js +66 -40
- package/dist/lib/image-optimization/handler.d.ts +0 -3
- package/dist/lib/image-optimization/handler.d.ts.map +1 -1
- package/dist/lib/image-optimization/handler.js +339 -124
- package/dist/lib/image-optimization/image-config.d.ts +31 -4
- package/dist/lib/image-optimization/image-config.d.ts.map +1 -1
- package/dist/lib/image-optimization/image-config.js +6 -0
- package/dist/lib/image-optimization/image-error.d.ts +8 -0
- package/dist/lib/image-optimization/image-error.d.ts.map +1 -0
- package/dist/lib/image-optimization/image-error.js +10 -0
- package/dist/lib/image-optimization/image-plugin.d.ts +2 -0
- package/dist/lib/image-optimization/image-plugin.d.ts.map +1 -1
- package/dist/lib/image-optimization/image-plugin.js +36 -16
- package/dist/lib/image-optimization/is-private-ip.d.ts +2 -0
- package/dist/lib/image-optimization/is-private-ip.d.ts.map +1 -0
- package/dist/lib/image-optimization/is-private-ip.js +43 -0
- package/dist/lib/image-optimization/match-patterns.d.ts +4 -0
- package/dist/lib/image-optimization/match-patterns.d.ts.map +1 -0
- package/dist/lib/image-optimization/match-patterns.js +39 -0
- package/dist/lib/image-optimization/read-body.d.ts +2 -0
- package/dist/lib/image-optimization/read-body.d.ts.map +1 -0
- package/dist/lib/image-optimization/read-body.js +27 -0
- package/dist/lib/image-optimization/static-image-loader.d.ts +2 -0
- package/dist/lib/image-optimization/static-image-loader.d.ts.map +1 -0
- package/dist/lib/image-optimization/static-image-loader.js +60 -0
- package/dist/lib/plugin-names.d.ts +3 -0
- package/dist/lib/plugin-names.d.ts.map +1 -0
- package/dist/lib/plugin-names.js +2 -0
- package/dist/lib/proxy/build-proxy.d.ts +1 -1
- package/dist/lib/proxy/build-proxy.d.ts.map +1 -1
- package/dist/lib/proxy/build-proxy.js +4 -11
- package/dist/lib/proxy/pattern.d.ts +7 -0
- package/dist/lib/proxy/pattern.d.ts.map +1 -0
- package/dist/lib/proxy/pattern.js +18 -0
- package/dist/lib/proxy/types.d.ts +3 -1
- package/dist/lib/proxy/types.d.ts.map +1 -1
- package/dist/lib/route-prediction.d.ts.map +1 -1
- package/dist/lib/rsc-request.d.ts.map +1 -1
- package/dist/lib/rsc-request.js +6 -4
- package/dist/lib/server-router/build-entries.d.ts +76 -0
- package/dist/lib/server-router/build-entries.d.ts.map +1 -0
- package/dist/lib/server-router/build-entries.js +74 -0
- package/dist/lib/server-router/get-router.d.ts.map +1 -1
- package/dist/lib/server-router/get-router.js +55 -105
- package/dist/lib/server-router/rou3.d.ts +20 -0
- package/dist/lib/server-router/rou3.d.ts.map +1 -0
- package/dist/lib/server-router/rou3.js +55 -0
- package/dist/lib/server-router/route-entries.d.ts +16 -0
- package/dist/lib/server-router/route-entries.d.ts.map +1 -0
- package/dist/lib/server-router/route-entries.js +67 -0
- package/dist/lib/server-router/types.d.ts +24 -33
- package/dist/lib/server-router/types.d.ts.map +1 -1
- package/dist/lib/server-router/types.js +1 -6
- package/dist/lib/types.d.ts +2 -2
- package/dist/lib/types.d.ts.map +1 -1
- package/dist/plugins/prerender.d.ts +3 -4
- package/dist/plugins/prerender.d.ts.map +1 -1
- package/dist/plugins/prerender.js +31 -0
- package/dist/plugins/proxy.d.ts.map +1 -1
- package/dist/plugins/proxy.js +7 -1
- package/dist/plugins/router/rou3-compiled.d.ts +9 -0
- package/dist/plugins/router/rou3-compiled.d.ts.map +1 -0
- package/dist/plugins/router/rou3-compiled.js +14 -0
- package/dist/plugins/router/rou3-router.d.ts +3 -0
- package/dist/plugins/router/rou3-router.d.ts.map +1 -0
- package/dist/plugins/router/rou3-router.js +16 -0
- package/dist/plugins/router/router-plugin.d.ts +6 -16
- package/dist/plugins/router/router-plugin.d.ts.map +1 -1
- package/dist/plugins/router/router-plugin.js +43 -22
- package/dist/proxy.d.ts +1 -0
- package/dist/proxy.d.ts.map +1 -1
- package/dist/proxy.js +1 -0
- package/dist/request-context.d.ts +0 -2
- package/dist/request-context.d.ts.map +1 -1
- package/dist/request-context.js +0 -4
- package/dist/router.d.ts +1 -1
- package/dist/router.d.ts.map +1 -1
- package/dist/router.js +4 -4
- package/dist/server-router.d.ts +3 -3
- package/dist/server-router.d.ts.map +1 -1
- package/dist/server-router.js +2 -2
- package/dist/vite.d.ts +8 -3
- package/dist/vite.d.ts.map +1 -1
- package/dist/vite.js +72 -33
- package/package.json +6 -4
- package/dist/components/error-boundary-client.d.ts +0 -49
- package/dist/components/error-boundary-client.d.ts.map +0 -1
- package/dist/components/error-boundary-client.js +0 -71
- package/dist/components/error-boundary.browser.d.ts +0 -8
- package/dist/components/error-boundary.browser.d.ts.map +0 -1
- package/dist/components/error-boundary.browser.js +0 -6
- package/dist/components/error.d.ts +0 -2
- package/dist/components/error.d.ts.map +0 -1
- package/dist/components/error.js +0 -5
- package/dist/components/not-found-activator.d.ts +0 -11
- package/dist/components/not-found-activator.d.ts.map +0 -1
- package/dist/components/not-found-activator.js +0 -26
- package/dist/components/not-found-boundary-client.d.ts +0 -3
- package/dist/components/not-found-boundary-client.d.ts.map +0 -1
- package/dist/components/not-found-boundary-client.js +0 -20
- package/dist/components/not-found-boundary.browser.d.ts +0 -8
- package/dist/components/not-found-boundary.browser.d.ts.map +0 -1
- package/dist/components/not-found-boundary.browser.js +0 -4
- package/dist/components/not-found-boundary.d.ts +0 -8
- package/dist/components/not-found-boundary.d.ts.map +0 -1
- package/dist/components/not-found-boundary.js +0 -9
- package/dist/components/not-found-thrower.d.ts +0 -2
- package/dist/components/not-found-thrower.d.ts.map +0 -1
- package/dist/components/not-found-thrower.js +0 -7
- package/dist/components/not-found.d.ts +0 -2
- package/dist/components/not-found.d.ts.map +0 -1
- package/dist/components/not-found.js +0 -5
- package/dist/components/status-page.d.ts +0 -6
- package/dist/components/status-page.d.ts.map +0 -1
- package/dist/components/status-page.js +0 -61
- package/dist/handler.d.ts +0 -12
- package/dist/handler.d.ts.map +0 -1
- package/dist/handler.js +0 -21
- package/dist/handlers/rsc/constants.d.ts +0 -3
- package/dist/handlers/rsc/constants.d.ts.map +0 -1
- package/dist/handlers/rsc/constants.js +0 -2
- package/dist/handlers/rsc/create-response.d.ts +0 -3
- package/dist/handlers/rsc/create-response.d.ts.map +0 -1
- package/dist/handlers/rsc/create-response.js +0 -378
- package/dist/handlers/rsc/render-with-retries.d.ts +0 -4
- package/dist/handlers/rsc/render-with-retries.d.ts.map +0 -1
- package/dist/handlers/rsc/render-with-retries.js +0 -154
- package/dist/handlers/rsc/retry-loop.d.ts +0 -3
- package/dist/handlers/rsc/retry-loop.d.ts.map +0 -1
- package/dist/handlers/rsc/retry-loop.js +0 -145
- package/dist/handlers/rsc/stream-rsc-payload.d.ts +0 -9
- package/dist/handlers/rsc/stream-rsc-payload.d.ts.map +0 -1
- package/dist/handlers/rsc/stream-rsc-payload.js +0 -20
- package/dist/handlers/rsc/types.d.ts +0 -26
- package/dist/handlers/rsc/types.d.ts.map +0 -1
- package/dist/handlers/rsc/types.js +0 -7
- package/dist/handlers/rsc.d.ts +0 -20
- package/dist/handlers/rsc.d.ts.map +0 -1
- package/dist/handlers/rsc.js +0 -872
- package/dist/integration.d.ts +0 -14
- package/dist/integration.d.ts.map +0 -1
- package/dist/integration.js +0 -9
- package/dist/lib/dev-module-load-race.d.ts +0 -8
- package/dist/lib/dev-module-load-race.d.ts.map +0 -1
- package/dist/lib/dev-module-load-race.js +0 -31
- package/dist/lib/dev-page-exports.d.ts +0 -5
- package/dist/lib/dev-page-exports.d.ts.map +0 -1
- package/dist/lib/dev-page-exports.js +0 -14
- package/dist/lib/environment-names.d.ts +0 -11
- package/dist/lib/environment-names.d.ts.map +0 -1
- package/dist/lib/environment-names.js +0 -10
- package/dist/lib/initial-hash-scroll.d.ts.map +0 -1
- package/dist/lib/not-found.d.ts +0 -5
- package/dist/lib/not-found.d.ts.map +0 -1
- package/dist/lib/not-found.js +0 -7
- package/dist/lib/page-exports.d.ts +0 -9
- package/dist/lib/page-exports.d.ts.map +0 -1
- package/dist/lib/page-exports.js +0 -47
- package/dist/lib/pattern-segments.d.ts +0 -8
- package/dist/lib/pattern-segments.d.ts.map +0 -1
- package/dist/lib/pattern-segments.js +0 -22
- package/dist/lib/ppr/cache-status.d.ts +0 -3
- package/dist/lib/ppr/cache-status.d.ts.map +0 -1
- package/dist/lib/ppr/cache-status.js +0 -5
- package/dist/lib/server-router-contract.d.ts +0 -42
- package/dist/lib/server-router-contract.d.ts.map +0 -1
- package/dist/lib/server-router-contract.js +0 -6
- package/dist/lib/server-router-loader.d.ts +0 -10
- package/dist/lib/server-router-loader.d.ts.map +0 -1
- package/dist/lib/server-router-loader.js +0 -180
- package/dist/lib/server-router.d.ts +0 -8
- package/dist/lib/server-router.d.ts.map +0 -1
- package/dist/lib/server-router.js +0 -173
- package/dist/plugins/ppr-upgrade.d.ts +0 -36
- package/dist/plugins/ppr-upgrade.d.ts.map +0 -1
- package/dist/plugins/ppr-upgrade.js +0 -32
- package/dist/plugins/server-router-fallback.d.ts +0 -15
- package/dist/plugins/server-router-fallback.d.ts.map +0 -1
- package/dist/plugins/server-router-fallback.js +0 -30
- package/dist/server.d.ts +0 -10
- package/dist/server.d.ts.map +0 -1
- package/dist/server.js +0 -57
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { stat } from "node:fs/promises";
|
|
2
|
-
import { isAbsolute, join } from "node:path";
|
|
2
|
+
import { isAbsolute, join, relative, sep } from "node:path";
|
|
3
3
|
import { imageConfigDefault } from "./image-config.js";
|
|
4
|
+
import { createStaticImageModule } from "./static-image-loader.js";
|
|
4
5
|
const IMAGE_HANDLER_EXTENSIONS = ["ts", "js"];
|
|
6
|
+
const IMAGE_EXTENSIONS = new Set(["jpg", "jpeg", "png", "gif", "webp", "avif", "svg"]);
|
|
5
7
|
/** The `name` of the Vite plugin. */
|
|
6
8
|
export const REBASK_IMAGE_PLUGIN_NAME = "rebask:image";
|
|
7
9
|
async function findImageHandler(root, customPath) {
|
|
@@ -13,7 +15,7 @@ async function findImageHandler(root, customPath) {
|
|
|
13
15
|
}
|
|
14
16
|
catch {
|
|
15
17
|
console.warn(`[rebask] Image handler not found at path: ${customPath}`);
|
|
16
|
-
return
|
|
18
|
+
return;
|
|
17
19
|
}
|
|
18
20
|
}
|
|
19
21
|
// Look for default rebask.image.{ts,js} in project root
|
|
@@ -27,7 +29,6 @@ async function findImageHandler(root, customPath) {
|
|
|
27
29
|
// File doesn't exist, try next extension
|
|
28
30
|
}
|
|
29
31
|
}
|
|
30
|
-
return null;
|
|
31
32
|
}
|
|
32
33
|
export function rebaskImage(options) {
|
|
33
34
|
const imageConfig = {
|
|
@@ -37,8 +38,16 @@ export function rebaskImage(options) {
|
|
|
37
38
|
let publicDir;
|
|
38
39
|
let projectRoot;
|
|
39
40
|
let disabled = false;
|
|
41
|
+
let resolvedHandlerPath;
|
|
42
|
+
async function resolveHandlerPath() {
|
|
43
|
+
if (resolvedHandlerPath === undefined) {
|
|
44
|
+
resolvedHandlerPath = (await findImageHandler(projectRoot, imageConfig.handler)) ?? null;
|
|
45
|
+
}
|
|
46
|
+
return resolvedHandlerPath;
|
|
47
|
+
}
|
|
40
48
|
const api = {
|
|
41
49
|
getImageConfig: () => imageConfig,
|
|
50
|
+
hasHandler: async () => !disabled && (await resolveHandlerPath()) !== null,
|
|
42
51
|
disableHandler: () => {
|
|
43
52
|
disabled = true;
|
|
44
53
|
},
|
|
@@ -47,25 +56,22 @@ export function rebaskImage(options) {
|
|
|
47
56
|
name: REBASK_IMAGE_PLUGIN_NAME,
|
|
48
57
|
enforce: "pre", // Run before Vite's import analysis to handle virtual module
|
|
49
58
|
api,
|
|
50
|
-
|
|
51
|
-
// Prepare image config for injection
|
|
52
|
-
const clientImageConfig = {
|
|
53
|
-
deviceSizes: imageConfig.deviceSizes,
|
|
54
|
-
imageSizes: imageConfig.imageSizes,
|
|
55
|
-
qualities: imageConfig.qualities,
|
|
56
|
-
path: imageConfig.path,
|
|
57
|
-
unoptimized: imageConfig.unoptimized,
|
|
58
|
-
};
|
|
59
|
+
config() {
|
|
59
60
|
return {
|
|
60
61
|
define: {
|
|
61
|
-
__REBASK_IMAGE_OPTS: JSON.stringify(
|
|
62
|
+
__REBASK_IMAGE_OPTS: JSON.stringify({
|
|
63
|
+
deviceSizes: imageConfig.deviceSizes,
|
|
64
|
+
imageSizes: imageConfig.imageSizes,
|
|
65
|
+
qualities: imageConfig.qualities,
|
|
66
|
+
path: imageConfig.path,
|
|
67
|
+
unoptimized: imageConfig.unoptimized,
|
|
68
|
+
}),
|
|
62
69
|
},
|
|
63
70
|
};
|
|
64
71
|
},
|
|
65
72
|
configResolved(config) {
|
|
66
73
|
projectRoot = config.root;
|
|
67
|
-
|
|
68
|
-
publicDir = config.publicDir;
|
|
74
|
+
publicDir = config.publicDir || undefined;
|
|
69
75
|
},
|
|
70
76
|
resolveId(id) {
|
|
71
77
|
if (id === "virtual:rebask/image-config") {
|
|
@@ -81,7 +87,7 @@ export function rebaskImage(options) {
|
|
|
81
87
|
}
|
|
82
88
|
if (id === "\0virtual:rebask/image-handler") {
|
|
83
89
|
// The handler can be disabled by other plugins (e.g., platform adapter)
|
|
84
|
-
const handlerPath =
|
|
90
|
+
const handlerPath = disabled ? null : await resolveHandlerPath();
|
|
85
91
|
if (!handlerPath) {
|
|
86
92
|
return `export const loadImageHandler = undefined;`;
|
|
87
93
|
}
|
|
@@ -92,6 +98,20 @@ export async function loadImageHandler() {
|
|
|
92
98
|
}
|
|
93
99
|
`;
|
|
94
100
|
}
|
|
101
|
+
// Only unadorned imports are transformed.
|
|
102
|
+
if (id.includes("?"))
|
|
103
|
+
return;
|
|
104
|
+
const extension = id.split(".").pop()?.toLowerCase();
|
|
105
|
+
if (!extension || !IMAGE_EXTENSIONS.has(extension))
|
|
106
|
+
return;
|
|
107
|
+
const relativePath = relative(projectRoot, id);
|
|
108
|
+
if (relativePath === ".." ||
|
|
109
|
+
relativePath.startsWith(`..${sep}`) ||
|
|
110
|
+
isAbsolute(relativePath) ||
|
|
111
|
+
relativePath.split(sep).includes("node_modules")) {
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
return createStaticImageModule(id, projectRoot);
|
|
95
115
|
},
|
|
96
116
|
};
|
|
97
117
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"is-private-ip.d.ts","sourceRoot":"","sources":["../../../src/lib/image-optimization/is-private-ip.ts"],"names":[],"mappings":"AAqCA,wBAAgB,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAWpD"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { BlockList, isIP } from "node:net";
|
|
2
|
+
const privateAddresses = new BlockList();
|
|
3
|
+
privateAddresses.addSubnet("0.0.0.0", 8, "ipv4");
|
|
4
|
+
privateAddresses.addSubnet("10.0.0.0", 8, "ipv4");
|
|
5
|
+
privateAddresses.addSubnet("100.64.0.0", 10, "ipv4");
|
|
6
|
+
privateAddresses.addSubnet("127.0.0.0", 8, "ipv4");
|
|
7
|
+
privateAddresses.addSubnet("169.254.0.0", 16, "ipv4");
|
|
8
|
+
privateAddresses.addSubnet("172.16.0.0", 12, "ipv4");
|
|
9
|
+
privateAddresses.addSubnet("192.0.0.0", 24, "ipv4");
|
|
10
|
+
privateAddresses.addSubnet("192.0.2.0", 24, "ipv4");
|
|
11
|
+
privateAddresses.addSubnet("192.31.196.0", 24, "ipv4");
|
|
12
|
+
privateAddresses.addSubnet("192.52.193.0", 24, "ipv4");
|
|
13
|
+
privateAddresses.addSubnet("192.88.99.0", 24, "ipv4");
|
|
14
|
+
privateAddresses.addSubnet("192.168.0.0", 16, "ipv4");
|
|
15
|
+
privateAddresses.addSubnet("192.175.48.0", 24, "ipv4");
|
|
16
|
+
privateAddresses.addSubnet("198.18.0.0", 15, "ipv4");
|
|
17
|
+
privateAddresses.addSubnet("198.51.100.0", 24, "ipv4");
|
|
18
|
+
privateAddresses.addSubnet("203.0.113.0", 24, "ipv4");
|
|
19
|
+
privateAddresses.addSubnet("224.0.0.0", 4, "ipv4");
|
|
20
|
+
privateAddresses.addSubnet("240.0.0.0", 4, "ipv4");
|
|
21
|
+
privateAddresses.addSubnet("::", 96, "ipv6");
|
|
22
|
+
privateAddresses.addSubnet("::ffff:0:0.0.0.0", 96, "ipv6");
|
|
23
|
+
privateAddresses.addSubnet("64:ff9b::", 96, "ipv6");
|
|
24
|
+
privateAddresses.addSubnet("64:ff9b:1::", 48, "ipv6");
|
|
25
|
+
privateAddresses.addSubnet("100::", 64, "ipv6");
|
|
26
|
+
privateAddresses.addSubnet("2001::", 23, "ipv6");
|
|
27
|
+
privateAddresses.addSubnet("2001:db8::", 32, "ipv6");
|
|
28
|
+
privateAddresses.addSubnet("2002::", 16, "ipv6");
|
|
29
|
+
privateAddresses.addSubnet("2620:4f:8000::", 48, "ipv6");
|
|
30
|
+
privateAddresses.addSubnet("fc00::", 7, "ipv6");
|
|
31
|
+
privateAddresses.addSubnet("fec0::", 10, "ipv6");
|
|
32
|
+
privateAddresses.addSubnet("fe80::", 10, "ipv6");
|
|
33
|
+
privateAddresses.addSubnet("ff00::", 8, "ipv6");
|
|
34
|
+
export function isPrivateIp(address) {
|
|
35
|
+
const family = isIP(address);
|
|
36
|
+
if (family === 4) {
|
|
37
|
+
return privateAddresses.check(address, "ipv4");
|
|
38
|
+
}
|
|
39
|
+
if (family === 6) {
|
|
40
|
+
return privateAddresses.check(address, "ipv6");
|
|
41
|
+
}
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { LocalPattern, RemotePattern } from "./image-config.js";
|
|
2
|
+
export declare function hasLocalMatch(localPatterns: LocalPattern[] | undefined, pathname: string, search: string): boolean;
|
|
3
|
+
export declare function hasRemoteMatch(remotePatterns: RemotePattern[], url: URL): boolean;
|
|
4
|
+
//# sourceMappingURL=match-patterns.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"match-patterns.d.ts","sourceRoot":"","sources":["../../../src/lib/image-optimization/match-patterns.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AAyBpE,wBAAgB,aAAa,CAC5B,aAAa,EAAE,YAAY,EAAE,GAAG,SAAS,EACzC,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,GACZ,OAAO,CAIT;AAgBD,wBAAgB,cAAc,CAAC,cAAc,EAAE,aAAa,EAAE,EAAE,GAAG,EAAE,GAAG,GAAG,OAAO,CAEjF"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { isHostAllowed } from "../csrf-protection.js";
|
|
2
|
+
function matchPathname(pathname, pattern) {
|
|
3
|
+
const normalized = pattern.startsWith("/") ? pattern : `/${pattern}`;
|
|
4
|
+
let source = "";
|
|
5
|
+
for (const segment of normalized.split("/").slice(1)) {
|
|
6
|
+
if (segment === "**") {
|
|
7
|
+
source += "(?:/.*)?";
|
|
8
|
+
continue;
|
|
9
|
+
}
|
|
10
|
+
source += `/${segment.replace(/[.+?^${}()|[\]\\]/g, "\\$&").replace(/\*/g, "[^/]*")}`;
|
|
11
|
+
}
|
|
12
|
+
return new RegExp(`^${source}$`).test(pathname);
|
|
13
|
+
}
|
|
14
|
+
function matchPathAndSearch(pattern, pathname, search) {
|
|
15
|
+
if (pattern.search !== undefined && pattern.search !== search) {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
return matchPathname(pathname, pattern.pathname ?? "**");
|
|
19
|
+
}
|
|
20
|
+
export function hasLocalMatch(localPatterns, pathname, search) {
|
|
21
|
+
if (!localPatterns)
|
|
22
|
+
return true;
|
|
23
|
+
return localPatterns.some((pattern) => matchPathAndSearch(pattern, pathname, search));
|
|
24
|
+
}
|
|
25
|
+
function matchRemotePattern(pattern, url) {
|
|
26
|
+
if (pattern.protocol !== undefined && pattern.protocol !== url.protocol.slice(0, -1)) {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
if (pattern.port !== undefined && pattern.port !== url.port) {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
if (!isHostAllowed(url.hostname, pattern.hostname)) {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
return matchPathAndSearch(pattern, url.pathname, url.search);
|
|
36
|
+
}
|
|
37
|
+
export function hasRemoteMatch(remotePatterns, url) {
|
|
38
|
+
return remotePatterns.some((pattern) => matchRemotePattern(pattern, url));
|
|
39
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"read-body.d.ts","sourceRoot":"","sources":["../../../src/lib/image-optimization/read-body.ts"],"names":[],"mappings":"AAEA,wBAAsB,QAAQ,CAC7B,IAAI,EAAE,aAAa,CAAC,UAAU,CAAC,EAC/B,mBAAmB,EAAE,MAAM,EAC3B,MAAM,EAAE,WAAW,GACjB,OAAO,CAAC,MAAM,CAAC,CA2BjB"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { ImageError, INVALID_UPSTREAM, TIMED_OUT } from "./image-error.js";
|
|
2
|
+
export async function readBody(body, maximumResponseBody, signal) {
|
|
3
|
+
const chunks = [];
|
|
4
|
+
let size = 0;
|
|
5
|
+
try {
|
|
6
|
+
for await (const chunk of body) {
|
|
7
|
+
size += chunk.byteLength;
|
|
8
|
+
if (size > maximumResponseBody) {
|
|
9
|
+
throw new ImageError(413, INVALID_UPSTREAM);
|
|
10
|
+
}
|
|
11
|
+
chunks.push(chunk);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
catch (error) {
|
|
15
|
+
if (signal.aborted) {
|
|
16
|
+
throw new ImageError(504, TIMED_OUT);
|
|
17
|
+
}
|
|
18
|
+
if (error instanceof ImageError) {
|
|
19
|
+
throw error;
|
|
20
|
+
}
|
|
21
|
+
throw new ImageError(400, INVALID_UPSTREAM);
|
|
22
|
+
}
|
|
23
|
+
if (size === 0) {
|
|
24
|
+
throw new ImageError(400, INVALID_UPSTREAM);
|
|
25
|
+
}
|
|
26
|
+
return Buffer.concat(chunks, size);
|
|
27
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"static-image-loader.d.ts","sourceRoot":"","sources":["../../../src/lib/image-optimization/static-image-loader.ts"],"names":[],"mappings":"AAgDA,wBAAsB,uBAAuB,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CA+B7F"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
import { createRequire } from "node:module";
|
|
3
|
+
import { join, relative, sep } from "node:path";
|
|
4
|
+
const BLUR_IMG_SIZE = 8;
|
|
5
|
+
const BLUR_QUALITY = 70;
|
|
6
|
+
const BLUR_EXTENSIONS = new Set(["jpg", "jpeg", "png", "webp", "avif"]);
|
|
7
|
+
async function getBlurPlaceholder(source, width, height, extension, root) {
|
|
8
|
+
if (!BLUR_EXTENSIONS.has(extension))
|
|
9
|
+
return;
|
|
10
|
+
let sharp;
|
|
11
|
+
try {
|
|
12
|
+
sharp = createRequire(join(root, "package.json"))("sharp");
|
|
13
|
+
}
|
|
14
|
+
catch {
|
|
15
|
+
// `sharp` is optional. Static imports still work without blur placeholders.
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
const blurWidth = width >= height ? BLUR_IMG_SIZE : Math.max(Math.round((width / height) * BLUR_IMG_SIZE), 1);
|
|
19
|
+
const blurHeight = height >= width ? BLUR_IMG_SIZE : Math.max(Math.round((height / width) * BLUR_IMG_SIZE), 1);
|
|
20
|
+
try {
|
|
21
|
+
const buffer = await sharp(source)
|
|
22
|
+
.rotate()
|
|
23
|
+
.resize(blurWidth, blurHeight)
|
|
24
|
+
.webp({ quality: BLUR_QUALITY })
|
|
25
|
+
.toBuffer();
|
|
26
|
+
return {
|
|
27
|
+
dataURL: `data:image/webp;base64,${buffer.toString("base64")}`,
|
|
28
|
+
width: blurWidth,
|
|
29
|
+
height: blurHeight,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
export async function createStaticImageModule(filePath, root) {
|
|
37
|
+
const [{ imageSize }, source] = await Promise.all([import("image-size"), readFile(filePath)]);
|
|
38
|
+
const relativePath = relative(root, filePath);
|
|
39
|
+
const extension = filePath.split(".").pop().toLowerCase();
|
|
40
|
+
let size;
|
|
41
|
+
try {
|
|
42
|
+
size = imageSize(source);
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
throw new Error(`Could not read the dimensions of "${relativePath}". Static image imports require a supported image format.`);
|
|
46
|
+
}
|
|
47
|
+
if (!size.width || !size.height) {
|
|
48
|
+
throw new Error(`Could not read the dimensions of "${relativePath}". Add width and height to the image.`);
|
|
49
|
+
}
|
|
50
|
+
// EXIF orientations 5-8 rotate by 90 or 270 degrees, swapping the dimensions.
|
|
51
|
+
const rotated = size.orientation !== undefined && size.orientation >= 5;
|
|
52
|
+
const width = rotated ? size.height : size.width;
|
|
53
|
+
const height = rotated ? size.width : size.height;
|
|
54
|
+
const blur = await getBlurPlaceholder(source, width, height, extension, root);
|
|
55
|
+
const data = { width, height, ...(blur ? { blur } : {}) };
|
|
56
|
+
const url = `/${relativePath.split(sep).join("/")}?url`;
|
|
57
|
+
return `import src from ${JSON.stringify(url)}
|
|
58
|
+
export default { ...${JSON.stringify(data)}, src }
|
|
59
|
+
`;
|
|
60
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin-names.d.ts","sourceRoot":"","sources":["../../src/lib/plugin-names.ts"],"names":[],"mappings":"AAAA,kDAAkD;AAClD,eAAO,MAAM,kBAAkB,sBAAsB,CAAA"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { ProxyRouter, ProxyRoutes } from "./types.js";
|
|
2
|
-
/** Build a
|
|
2
|
+
/** Build a proxy router. The proxy is small, so it keeps the rou3 interpreter. */
|
|
3
3
|
export declare function buildProxy(routes: ProxyRoutes): ProxyRouter | null;
|
|
4
4
|
//# sourceMappingURL=build-proxy.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build-proxy.d.ts","sourceRoot":"","sources":["../../../src/lib/proxy/build-proxy.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"build-proxy.d.ts","sourceRoot":"","sources":["../../../src/lib/proxy/build-proxy.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAE1D,kFAAkF;AAClF,wBAAgB,UAAU,CAAC,MAAM,EAAE,WAAW,GAAG,WAAW,GAAG,IAAI,CAgBlE"}
|
|
@@ -1,24 +1,17 @@
|
|
|
1
|
-
import { createMatcher } from "
|
|
1
|
+
import { createMatcher } from "../../plugins/router/rou3-router.js";
|
|
2
2
|
import { HTTP_METHODS } from "../route-matcher.js";
|
|
3
|
-
|
|
4
|
-
/** Build a compiled proxy router. */
|
|
3
|
+
/** Build a proxy router. The proxy is small, so it keeps the rou3 interpreter. */
|
|
5
4
|
export function buildProxy(routes) {
|
|
6
5
|
const entries = Object.entries(routes);
|
|
7
6
|
if (entries.length === 0)
|
|
8
7
|
return null;
|
|
9
|
-
const
|
|
10
|
-
type: RouteType.PROXY,
|
|
11
|
-
methods: [...HTTP_METHODS],
|
|
12
|
-
pattern,
|
|
13
|
-
handler,
|
|
14
|
-
}));
|
|
15
|
-
const matcher = createMatcher(matchEntries);
|
|
8
|
+
const matcher = createMatcher(entries.map(([pattern, handler]) => ({ methods: [...HTTP_METHODS], pattern, handler })));
|
|
16
9
|
return {
|
|
17
10
|
find(request) {
|
|
18
11
|
const match = matcher.find(request.method, request.url);
|
|
19
12
|
if (!match)
|
|
20
13
|
return null;
|
|
21
|
-
return match;
|
|
14
|
+
return (req) => match.entry.handler(req, match.params ?? {});
|
|
22
15
|
},
|
|
23
16
|
};
|
|
24
17
|
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Consumers that only match paths never read captures. Named groups are unnecessary, and duplicate
|
|
3
|
+
* names across alternatives can fail engines that don't support them.
|
|
4
|
+
*/
|
|
5
|
+
export declare function proxyPatternToRegExpSource(pattern: string): string;
|
|
6
|
+
export declare function proxyPatternToClientSource(pattern: string): string;
|
|
7
|
+
//# sourceMappingURL=pattern.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pattern.d.ts","sourceRoot":"","sources":["../../../src/lib/proxy/pattern.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,wBAAgB,0BAA0B,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAElE;AAGD,wBAAgB,0BAA0B,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CASlE"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { routeToRegExp } from "rou3";
|
|
2
|
+
/**
|
|
3
|
+
* Consumers that only match paths never read captures. Named groups are unnecessary, and duplicate
|
|
4
|
+
* names across alternatives can fail engines that don't support them.
|
|
5
|
+
*/
|
|
6
|
+
export function proxyPatternToRegExpSource(pattern) {
|
|
7
|
+
return routeToRegExp(pattern).source.replace(/\(\?<[^>]+>/g, "(?:");
|
|
8
|
+
}
|
|
9
|
+
// Helps with failures in Node 20/22 if some pattern can't be converted to a regexp.
|
|
10
|
+
export function proxyPatternToClientSource(pattern) {
|
|
11
|
+
try {
|
|
12
|
+
return proxyPatternToRegExpSource(pattern);
|
|
13
|
+
}
|
|
14
|
+
catch (error) {
|
|
15
|
+
console.error(`[rebask] Could not generate a proxy match source for "${pattern}". Client route prediction is disabled for it. ${error instanceof Error ? error.message : String(error)}`);
|
|
16
|
+
return "^/.*$";
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -10,7 +10,7 @@ import type { RouteParams } from "../route-matcher.js";
|
|
|
10
10
|
*/
|
|
11
11
|
export type ProxyHandler = (request: Request, params: RouteParams) => Response | void | Promise<Response | void>;
|
|
12
12
|
/**
|
|
13
|
-
* An object mapping
|
|
13
|
+
* An object mapping rou3 route patterns to proxy handler functions.
|
|
14
14
|
*
|
|
15
15
|
* @example
|
|
16
16
|
* ```ts
|
|
@@ -43,6 +43,8 @@ export interface ProxyBundle {
|
|
|
43
43
|
proxyRouter: ProxyRouter | null;
|
|
44
44
|
/** The route patterns, or `null` if there are no proxy routes. */
|
|
45
45
|
proxyPatterns: string[] | null;
|
|
46
|
+
/** Match-only regex sources for the route patterns, or `null` if there are no proxy routes. */
|
|
47
|
+
proxyRegexps: string[] | null;
|
|
46
48
|
}
|
|
47
49
|
/** Standalone proxy bundle path, relative to the project root. */
|
|
48
50
|
export declare const REBASK_PROXY_BUNDLE_PATH = "dist/proxy/index.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/lib/proxy/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AAEtD;;;;;;;;GAQG;AACH,MAAM,MAAM,YAAY,GAAG,CAC1B,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,WAAW,KACf,QAAQ,GAAG,IAAI,GAAG,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC,CAAA;AAE/C;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,MAAM,WAAW,GAAG;IAAE,CAAC,OAAO,EAAE,MAAM,GAAG,YAAY,CAAA;CAAE,CAAA;AAE7D,+BAA+B;AAC/B,MAAM,WAAW,WAAW;IAC3B;;;OAGG;IACH,IAAI,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,CAAC,CAAC,OAAO,EAAE,OAAO,KAAK,UAAU,CAAC,YAAY,CAAC,CAAC,GAAG,IAAI,CAAA;CACnF;AAED,8CAA8C;AAC9C,MAAM,WAAW,WAAW;IAC3B,mEAAmE;IACnE,WAAW,EAAE,WAAW,GAAG,IAAI,CAAA;IAC/B,kEAAkE;IAClE,aAAa,EAAE,MAAM,EAAE,GAAG,IAAI,CAAA;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/lib/proxy/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AAEtD;;;;;;;;GAQG;AACH,MAAM,MAAM,YAAY,GAAG,CAC1B,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,WAAW,KACf,QAAQ,GAAG,IAAI,GAAG,OAAO,C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eAAe,CAAA;IACjC,uEAAuE;IACvE,GAAG,EAAE,MAAM,CAAA;CACX,CAAA;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,QAAQ,EAAE,iBAAiB,GAAG,GAAG,CAEhE;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,sBAAsB,CACrC,KAAK,EAAE,SAAS,EAChB,MAAM,EAAE,WAAW,EACnB,OAAO,UAAQ,GACb,MAAM,CA+BR"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rsc-request.d.ts","sourceRoot":"","sources":["../../src/lib/rsc-request.ts"],"names":[],"mappings":"AAKA,OAAO,
|
|
1
|
+
{"version":3,"file":"rsc-request.d.ts","sourceRoot":"","sources":["../../src/lib/rsc-request.ts"],"names":[],"mappings":"AAKA,OAAO,EAKN,KAAK,kBAAkB,EAIvB,MAAM,uBAAuB,CAAA;AAK9B,OAAO,EAAkB,KAAK,aAAa,EAAU,MAAM,oBAAoB,CAAA;AAS/E,OAAO,EAKN,iBAAiB,EACjB,MAAM,kBAAkB,CAAA;AACzB,OAAO,EAAE,KAAK,aAAa,EAAiB,MAAM,qBAAqB,CAAA;AACvE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAIrD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAI5C,wBAAsB,aAAa,CAAC,CAAC,EACpC,cAAc,EAAE,kBAAkB,EAClC,aAAa,EAAE,aAAa,EAC5B,OAAO,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GACvB,OAAO,CAAC,CAAC,CAAC,CAUZ;AAcD,wBAAgB,SAAS,CACxB,OAAO,EAAE,UAAU,EACnB,OAAO,GAAE;IAAE,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAAC,MAAM,CAAC,EAAE,WAAW,CAAA;CAAO,EACrE,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,+CAclC;AAED,wBAAgB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,EAAE,aAAa,CAAA;CAAE,CAAC,CAyBrE;AAED,wBAAgB,cAAc,CAC7B,KAAK,EAAE,aAAa,EACpB,MAAM,EAAE,cAAc,CAAC,UAAU,CAAC,EAClC,UAAU,EAAE,GAAG,EACf,MAAM,SAAM,GACV,QAAQ,CAmCV;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,SAAS,EAAE,cAAc,CAAC,UAAU,CAAC,EAAE,MAAM,SAAM,YA2BxF;AAED,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,aAAa,QAExD;AAED,wBAAsB,kBAAkB,CACvC,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,WAAW,EACnB,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,OAAO,CAAC,cAAc,CAAC,UAAU,CAAC,GAAG,IAAI,CAAC,GACtD,OAAO,CAAC,IAAI,CAAC,CAoBf"}
|
package/dist/lib/rsc-request.js
CHANGED
|
@@ -3,7 +3,7 @@ import { createClientManifest, renderToReadableStream } from "@vitejs/plugin-rsc
|
|
|
3
3
|
import { prerender } from "@vitejs/plugin-rsc/vendor/react-server-dom/static.edge";
|
|
4
4
|
import { hooks, hooksOptions } from "virtual:rebask/hooks";
|
|
5
5
|
import { pprConfig } from "virtual:rebask/ppr-config";
|
|
6
|
-
import { getCacheLife,
|
|
6
|
+
import { getCacheLife, hasNotFoundMark, isUncacheable, mergeResponseHeaders, RequestStorage, withRequestStorage, OutgoingResponseHeaders, } from "../request-context.js";
|
|
7
7
|
import { CacheKeyTag } from "./cache-key-tags.js";
|
|
8
8
|
import { getCacheKey } from "./cache-keys.js";
|
|
9
9
|
import { streamFromCachePayload, streamToCachePayload } from "./cache-payload.js";
|
|
@@ -59,13 +59,15 @@ export function createRscResponse(rscStream, options = {}) {
|
|
|
59
59
|
const tagHeader = pprConfig?.cacheTagsHeader;
|
|
60
60
|
let trailerNonce;
|
|
61
61
|
if (trailer && rscStream) {
|
|
62
|
+
// `flush()` can run after the request scope exits, so keep the state instead of looking it
|
|
63
|
+
// up in AsyncLocalStorage. `trackSearchParam()` fills `usedSearch` lazily during the render.
|
|
64
|
+
const requestState = RequestStorage.getStore().state;
|
|
62
65
|
trailerNonce = randomBytes(16).toString("hex");
|
|
63
66
|
rscStream = rscStream.pipeThrough(new TransformStream({
|
|
64
67
|
flush(controller) {
|
|
65
68
|
const used = {};
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
for (const [key, value] of usedSearch)
|
|
69
|
+
if (requestState.usedSearch) {
|
|
70
|
+
for (const [key, value] of requestState.usedSearch)
|
|
69
71
|
used[key] = value;
|
|
70
72
|
}
|
|
71
73
|
controller.enqueue(TEXT_ENCODER.encode(`\r\n--${trailerNonce}\r\n${JSON.stringify({ used })}`));
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { type LayoutRoute, type PageRoute, type RouteHandlerRoute } from "../route-matcher.js";
|
|
2
|
+
import { RouteType, type ProxyEntry, type RouteEntry } from "./types.js";
|
|
3
|
+
type Handler = (request: Request, params: Record<string, string | string[] | undefined>) => Promise<Response>;
|
|
4
|
+
export interface EntryHandlers {
|
|
5
|
+
page: (route: PageRoute) => Handler;
|
|
6
|
+
markdown: (route: PageRoute) => Handler;
|
|
7
|
+
routeHandler: (route: RouteHandlerRoute) => Handler;
|
|
8
|
+
layout: (route: LayoutRoute) => Handler;
|
|
9
|
+
}
|
|
10
|
+
export declare function buildEntries(pageRoutes: PageRoute[], routeHandlerRoutes: RouteHandlerRoute[], layoutRoutes: LayoutRoute[], imageEntry: Exclude<RouteEntry, ProxyEntry> | null, handlers: EntryHandlers): {
|
|
11
|
+
appEntries: ({
|
|
12
|
+
type: RouteType.IMAGE;
|
|
13
|
+
methods: import("../route-matcher.js").HttpMethod[];
|
|
14
|
+
pattern: string;
|
|
15
|
+
handler: (request: Request, params: import("../route-matcher.js").RouteParams) => Promise<Response>;
|
|
16
|
+
} | {
|
|
17
|
+
methods: import("../route-matcher.js").HttpMethod[];
|
|
18
|
+
type: RouteType.APP;
|
|
19
|
+
route: LayoutRoute;
|
|
20
|
+
handler: (request: Request, params: import("../route-matcher.js").RouteParams) => Promise<Response>;
|
|
21
|
+
} | {
|
|
22
|
+
methods: import("../route-matcher.js").HttpMethod[];
|
|
23
|
+
type: RouteType.APP;
|
|
24
|
+
route: import("../route-matcher.js").Route;
|
|
25
|
+
handler: (request: Request, params: import("../route-matcher.js").RouteParams) => Promise<Response>;
|
|
26
|
+
} | {
|
|
27
|
+
methods: import("../route-matcher.js").HttpMethod[];
|
|
28
|
+
type: RouteType.APP;
|
|
29
|
+
route: RouteHandlerRoute;
|
|
30
|
+
handler: (request: Request, params: import("../route-matcher.js").RouteParams) => Promise<Response>;
|
|
31
|
+
})[];
|
|
32
|
+
layoutEntries: ({
|
|
33
|
+
type: RouteType.IMAGE;
|
|
34
|
+
methods: import("../route-matcher.js").HttpMethod[];
|
|
35
|
+
pattern: string;
|
|
36
|
+
handler: (request: Request, params: import("../route-matcher.js").RouteParams) => Promise<Response>;
|
|
37
|
+
} | {
|
|
38
|
+
methods: import("../route-matcher.js").HttpMethod[];
|
|
39
|
+
type: RouteType.APP;
|
|
40
|
+
route: LayoutRoute;
|
|
41
|
+
handler: (request: Request, params: import("../route-matcher.js").RouteParams) => Promise<Response>;
|
|
42
|
+
} | {
|
|
43
|
+
methods: import("../route-matcher.js").HttpMethod[];
|
|
44
|
+
type: RouteType.APP;
|
|
45
|
+
route: import("../route-matcher.js").Route;
|
|
46
|
+
handler: (request: Request, params: import("../route-matcher.js").RouteParams) => Promise<Response>;
|
|
47
|
+
} | {
|
|
48
|
+
methods: import("../route-matcher.js").HttpMethod[];
|
|
49
|
+
type: RouteType.APP;
|
|
50
|
+
route: RouteHandlerRoute;
|
|
51
|
+
handler: (request: Request, params: import("../route-matcher.js").RouteParams) => Promise<Response>;
|
|
52
|
+
})[];
|
|
53
|
+
markdownEntries: ({
|
|
54
|
+
type: RouteType.IMAGE;
|
|
55
|
+
methods: import("../route-matcher.js").HttpMethod[];
|
|
56
|
+
pattern: string;
|
|
57
|
+
handler: (request: Request, params: import("../route-matcher.js").RouteParams) => Promise<Response>;
|
|
58
|
+
} | {
|
|
59
|
+
methods: import("../route-matcher.js").HttpMethod[];
|
|
60
|
+
type: RouteType.APP;
|
|
61
|
+
route: LayoutRoute;
|
|
62
|
+
handler: (request: Request, params: import("../route-matcher.js").RouteParams) => Promise<Response>;
|
|
63
|
+
} | {
|
|
64
|
+
methods: import("../route-matcher.js").HttpMethod[];
|
|
65
|
+
type: RouteType.APP;
|
|
66
|
+
route: import("../route-matcher.js").Route;
|
|
67
|
+
handler: (request: Request, params: import("../route-matcher.js").RouteParams) => Promise<Response>;
|
|
68
|
+
} | {
|
|
69
|
+
methods: import("../route-matcher.js").HttpMethod[];
|
|
70
|
+
type: RouteType.APP;
|
|
71
|
+
route: RouteHandlerRoute;
|
|
72
|
+
handler: (request: Request, params: import("../route-matcher.js").RouteParams) => Promise<Response>;
|
|
73
|
+
})[];
|
|
74
|
+
};
|
|
75
|
+
export {};
|
|
76
|
+
//# sourceMappingURL=build-entries.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build-entries.d.ts","sourceRoot":"","sources":["../../../src/lib/server-router/build-entries.ts"],"names":[],"mappings":"AAAA,OAAO,EAEN,KAAK,WAAW,EAChB,KAAK,SAAS,EACd,KAAK,iBAAiB,EAEtB,MAAM,qBAAqB,CAAA;AAE5B,OAAO,EAAE,SAAS,EAAE,KAAK,UAAU,EAAE,KAAK,UAAU,EAAE,MAAM,YAAY,CAAA;AAExE,KAAK,OAAO,GAAG,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,CAAC,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAA;AAE7G,MAAM,WAAW,aAAa;IAC7B,IAAI,EAAE,CAAC,KAAK,EAAE,SAAS,KAAK,OAAO,CAAA;IACnC,QAAQ,EAAE,CAAC,KAAK,EAAE,SAAS,KAAK,OAAO,CAAA;IACvC,YAAY,EAAE,CAAC,KAAK,EAAE,iBAAiB,KAAK,OAAO,CAAA;IACnD,MAAM,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,OAAO,CAAA;CACvC;AAaD,wBAAgB,YAAY,CAC3B,UAAU,EAAE,SAAS,EAAE,EACvB,kBAAkB,EAAE,iBAAiB,EAAE,EACvC,YAAY,EAAE,WAAW,EAAE,EAC3B,UAAU,EAAE,OAAO,CAAC,UAAU,EAAE,UAAU,CAAC,GAAG,IAAI,EAClD,QAAQ,EAAE,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA4EvB"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { HTTP_METHODS, } from "../route-matcher.js";
|
|
2
|
+
import { appPattern, setEntryParams } from "./rou3.js";
|
|
3
|
+
import { RouteType } from "./types.js";
|
|
4
|
+
function setAppParams(entry) {
|
|
5
|
+
if (entry.type !== RouteType.APP)
|
|
6
|
+
return entry;
|
|
7
|
+
setEntryParams(entry, appPattern(entry.route.segments, entry.route.type === "layout"));
|
|
8
|
+
return entry;
|
|
9
|
+
}
|
|
10
|
+
export function buildEntries(pageRoutes, routeHandlerRoutes, layoutRoutes, imageEntry, handlers) {
|
|
11
|
+
const appEntries = [];
|
|
12
|
+
const layoutEntries = [];
|
|
13
|
+
const markdownEntries = [];
|
|
14
|
+
const hasMarkdownRoutes = pageRoutes.some((route) => route.markdownFilePath);
|
|
15
|
+
if (imageEntry) {
|
|
16
|
+
setAppParams(imageEntry);
|
|
17
|
+
appEntries.push(imageEntry);
|
|
18
|
+
if (hasMarkdownRoutes)
|
|
19
|
+
markdownEntries.push(imageEntry);
|
|
20
|
+
}
|
|
21
|
+
for (const route of pageRoutes) {
|
|
22
|
+
if (route.hasPage !== false) {
|
|
23
|
+
appEntries.push(setAppParams({
|
|
24
|
+
type: RouteType.APP,
|
|
25
|
+
methods: ["GET", "POST"],
|
|
26
|
+
route,
|
|
27
|
+
handler: handlers.page(route),
|
|
28
|
+
}));
|
|
29
|
+
}
|
|
30
|
+
if (!hasMarkdownRoutes)
|
|
31
|
+
continue;
|
|
32
|
+
if (route.markdownFilePath) {
|
|
33
|
+
markdownEntries.push(setAppParams({
|
|
34
|
+
type: RouteType.APP,
|
|
35
|
+
methods: ["GET", "HEAD"],
|
|
36
|
+
route,
|
|
37
|
+
handler: handlers.markdown(route),
|
|
38
|
+
}));
|
|
39
|
+
}
|
|
40
|
+
else if (route.hasPage !== false) {
|
|
41
|
+
markdownEntries.push(setAppParams({
|
|
42
|
+
type: RouteType.APP,
|
|
43
|
+
methods: ["GET"],
|
|
44
|
+
route,
|
|
45
|
+
handler: handlers.page(route),
|
|
46
|
+
}));
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
for (const route of routeHandlerRoutes) {
|
|
50
|
+
const entry = setAppParams({
|
|
51
|
+
type: RouteType.APP,
|
|
52
|
+
methods: [...HTTP_METHODS],
|
|
53
|
+
route,
|
|
54
|
+
handler: handlers.routeHandler(route),
|
|
55
|
+
});
|
|
56
|
+
appEntries.push(entry);
|
|
57
|
+
if (hasMarkdownRoutes)
|
|
58
|
+
markdownEntries.push(entry);
|
|
59
|
+
}
|
|
60
|
+
for (const route of layoutRoutes) {
|
|
61
|
+
const segments = [
|
|
62
|
+
{ type: "static", value: "_rebask" },
|
|
63
|
+
{ type: "static", value: "1" },
|
|
64
|
+
...route.segments,
|
|
65
|
+
];
|
|
66
|
+
layoutEntries.push(setAppParams({
|
|
67
|
+
type: RouteType.APP,
|
|
68
|
+
methods: ["GET"],
|
|
69
|
+
route: { ...route, segments },
|
|
70
|
+
handler: handlers.layout(route),
|
|
71
|
+
}));
|
|
72
|
+
}
|
|
73
|
+
return { appEntries, layoutEntries, markdownEntries };
|
|
74
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-router.d.ts","sourceRoot":"","sources":["../../../src/lib/server-router/get-router.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"get-router.d.ts","sourceRoot":"","sources":["../../../src/lib/server-router/get-router.ts"],"names":[],"mappings":"AAgCA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AA4L9C,yDAAyD;AACzD,wBAAsB,SAAS,IAAI,OAAO,CAAC,YAAY,CAAC,CA4BvD"}
|