@teyik0/furin 0.3.0-alpha.1 → 0.4.0-alpha.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/dist/adapter/bun.d.ts +2 -18
- package/dist/adapter/package.d.ts +2 -2
- package/dist/adapter/runtime-build.d.ts +33 -0
- package/dist/adapter/vercel.d.ts +3 -0
- package/dist/build/client.d.ts +2 -2
- package/dist/build/compile-entry.d.ts +4 -3
- package/dist/build/compile-entry.ts +24 -69
- package/dist/build/entry-template.d.ts +8 -2
- package/dist/build/entry-template.ts +48 -11
- package/dist/build/index.d.ts +2 -2
- package/dist/build/index.js +11720 -7840
- package/dist/build/route-types.d.ts +2 -22
- package/dist/build/shared.d.ts +1 -1
- package/dist/build/ssg-cache.d.ts +14 -1
- package/dist/build/types.d.ts +26 -3
- package/dist/build/virtual-entry.d.ts +8 -0
- package/dist/cache.d.ts +5 -0
- package/dist/cache.js +97 -0
- package/dist/cli/index.js +11815 -7793
- package/dist/cli/preview.d.ts +7 -0
- package/dist/client/boundaries.d.ts +3 -0
- package/dist/client/browser-events-runtime.d.ts +2 -0
- package/dist/client/browser-events.d.ts +2 -0
- package/dist/client/define-route.d.ts +36 -0
- package/dist/client/dev-error-overlay.d.ts +1 -0
- package/dist/client/dev-error-overlay.ts +201 -0
- package/dist/client/document.d.ts +27 -0
- package/dist/client/hmr.d.ts +12 -0
- package/dist/client/internal/runtime-types.d.ts +3 -1
- package/dist/client/link.js +1392 -940
- package/dist/client/router/index.d.ts +1 -1
- package/dist/client/router/link-utils.d.ts +9 -0
- package/dist/client/router/provider.d.ts +1 -1
- package/dist/client/router/search/index.d.ts +3 -7
- package/dist/client/router/sync-catch-up.d.ts +1 -1
- package/dist/client/router/types.d.ts +40 -34
- package/dist/client.d.ts +4 -159
- package/dist/client.js +197 -21
- package/dist/config.d.ts +25 -8
- package/dist/config.js +15 -7
- package/dist/define-route.d.ts +1358 -0
- package/dist/devtools/protocol.d.ts +2 -2
- package/dist/furin.d.ts +18 -34
- package/dist/furin.js +16038 -9395
- package/dist/plugin/index.js +1401 -223
- package/dist/plugin/route-config-autofix.d.ts +31 -0
- package/dist/plugin/routes.d.ts +28 -0
- package/dist/routes.d.ts +6 -0
- package/dist/routes.js +1 -0
- package/dist/rsc/build/index.d.ts +6 -2
- package/dist/rsc.js +3 -3
- package/dist/server/browser-events/plugin.d.ts +11 -0
- package/dist/server/browser-events/types.d.ts +9 -0
- package/dist/server/cache/invalidation.d.ts +1 -2
- package/dist/server/cache/isr.d.ts +1 -0
- package/dist/server/cache/purger.d.ts +7 -0
- package/dist/server/cache/runtime-cache.d.ts +21 -0
- package/dist/server/dev/browser-events.d.ts +4 -0
- package/dist/server/dev/diagnostics.d.ts +39 -0
- package/dist/server/dev/error.d.ts +17 -0
- package/dist/server/dev/graph.d.ts +86 -0
- package/dist/server/dev/plugin.d.ts +9 -0
- package/dist/server/dev/request-security.d.ts +1 -0
- package/dist/server/dev/rewrite-module-specifiers.d.ts +7 -0
- package/dist/server/dev/runtime.production.d.ts +5 -0
- package/dist/server/dev/symbolicate.d.ts +11 -0
- package/dist/server/dev/transform-failure.d.ts +4 -0
- package/dist/server/dev-page-plugin.d.ts +7 -5
- package/dist/server/dev-page-plugin.production.d.ts +1 -0
- package/dist/server/devtools/hub.d.ts +3 -2
- package/dist/server/devtools/instrumentation.d.ts +2 -2
- package/dist/server/devtools/instrumentation.production.d.ts +2 -2
- package/dist/server/devtools/plugin.d.ts +2 -2
- package/dist/server/external-prerender.d.ts +2 -0
- package/dist/server/instance.d.ts +2 -2
- package/dist/server/internal.d.ts +17 -2
- package/dist/server/internal.js +436 -1
- package/dist/server/logger.d.ts +4 -0
- package/dist/server/render/assemble.d.ts +0 -9
- package/dist/server/render/document.d.ts +4 -0
- package/dist/server/render/element.d.ts +3 -1
- package/dist/server/render/index.d.ts +2 -2
- package/dist/server/render/index.ts +1 -2
- package/dist/server/render/isr.d.ts +1 -1
- package/dist/server/render/loaders.d.ts +1 -1
- package/dist/server/render/not-found.d.ts +1 -1
- package/dist/server/render/ppr-document.d.ts +21 -0
- package/dist/server/render/ppr-request.d.ts +26 -0
- package/dist/server/render/ppr-route.d.ts +4 -2
- package/dist/server/render/shell.ts +0 -12
- package/dist/server/render/ssg.d.ts +3 -1
- package/dist/server/render/ssr.d.ts +23 -11
- package/dist/server/render/template.d.ts +4 -0
- package/dist/server/router/defined-route.d.ts +24 -0
- package/dist/server/router/hmr.d.ts +16 -8
- package/dist/server/router/hmr.production.d.ts +2 -0
- package/dist/server/router/patterns.d.ts +7 -0
- package/dist/server/router/plugin.d.ts +6 -3
- package/dist/server/router/schema-merge.d.ts +2 -2
- package/dist/server/router/schemas.d.ts +5 -5
- package/dist/server/router/source-version.d.ts +2 -0
- package/dist/server/router/types.d.ts +1 -0
- package/dist/server/sync/adapter.d.ts +13 -0
- package/dist/server/sync/config.d.ts +5 -5
- package/dist/server/sync/index.d.ts +6 -6
- package/dist/server/sync/index.js +1115 -985
- package/dist/server/sync/notifier.d.ts +1 -0
- package/dist/server/sync/postgres/index.d.ts +12 -1
- package/dist/server/sync/postgres/index.js +101 -6
- package/dist/server/sync/postgres/migrate.js +3 -2
- package/dist/server/sync/stream.d.ts +4 -13
- package/dist/shared/await.d.ts +4 -5
- package/dist/shared/browser-events.d.ts +22 -0
- package/dist/shared/compact-json.d.ts +8 -0
- package/dist/shared/deferred-ndjson.d.ts +6 -5
- package/dist/shared/dev-diagnostics.d.ts +36 -0
- package/dist/shared/elysia-contract.d.ts +41 -0
- package/dist/shared/prefix.d.ts +2 -0
- package/dist/shared/route-map.d.ts +5 -0
- package/dist/shared/utils/index.d.ts +1 -3
- package/package.json +55 -43
- package/src/adapter/README.md +45 -0
- package/src/adapter/bun.ts +62 -265
- package/src/adapter/package.ts +34 -22
- package/src/adapter/runtime-build.ts +375 -0
- package/src/adapter/static.ts +83 -5
- package/src/adapter/vercel.ts +857 -0
- package/src/build/client.ts +58 -16
- package/src/build/compile-entry.ts +24 -69
- package/src/build/entry-template.ts +48 -11
- package/src/build/hydrate.ts +147 -37
- package/src/build/index.ts +21 -7
- package/src/build/production-instrumentation.ts +56 -4
- package/src/build/route-types.ts +19 -114
- package/src/build/shared.ts +3 -2
- package/src/build/ssg-cache.ts +99 -16
- package/src/build/types.ts +32 -3
- package/src/build/virtual-entry.ts +27 -0
- package/src/cache.ts +14 -0
- package/src/cli/config.ts +3 -3
- package/src/cli/index.ts +62 -10
- package/src/cli/preview.ts +90 -0
- package/src/client/boundaries.tsx +19 -2
- package/src/client/browser-events-runtime.ts +204 -0
- package/src/client/browser-events.ts +22 -0
- package/src/client/define-route.ts +38 -0
- package/src/client/dev-error-overlay.ts +201 -0
- package/src/client/document.tsx +162 -0
- package/src/client/hmr.ts +63 -0
- package/src/client/internal/runtime-types.ts +3 -1
- package/src/client/link.tsx +21 -6
- package/src/client/router/boundary-tree.tsx +4 -4
- package/src/client/router/index.ts +1 -0
- package/src/client/router/link-utils.ts +26 -0
- package/src/client/router/provider.tsx +190 -65
- package/src/client/router/search/index.ts +4 -12
- package/src/client/router/sync-catch-up.ts +3 -4
- package/src/client/router/types.ts +56 -30
- package/src/client.ts +14 -316
- package/src/config.ts +35 -10
- package/src/define-route.ts +972 -0
- package/src/devtools/devtools-element.js +67 -87
- package/src/devtools/protocol.ts +2 -2
- package/src/furin.ts +431 -101
- package/src/plugin/route-config-autofix.ts +1140 -0
- package/src/plugin/routes.ts +1061 -0
- package/src/plugin/transform-client.ts +776 -228
- package/src/plugin/transform-isomorphic.ts +1 -1
- package/src/react-dom-edge.d.ts +6 -0
- package/src/routes.ts +6 -0
- package/src/rsc/build/index.ts +16 -4
- package/src/server/auto-invalidate/registry.ts +2 -2
- package/src/server/auto-invalidate/runtime.ts +5 -2
- package/src/server/browser-events/plugin.ts +168 -0
- package/src/server/browser-events/types.ts +11 -0
- package/src/server/cache/dev-loader.ts +30 -29
- package/src/server/cache/invalidation.ts +13 -22
- package/src/server/cache/isr.ts +9 -0
- package/src/server/cache/purger.ts +41 -0
- package/src/server/cache/runtime-cache.ts +137 -0
- package/src/server/dev/browser-events.ts +54 -0
- package/src/server/dev/diagnostics.ts +297 -0
- package/src/server/dev/error.ts +148 -0
- package/src/server/dev/graph.ts +438 -0
- package/src/server/dev/plugin.ts +130 -0
- package/src/server/dev/request-security.ts +38 -0
- package/src/server/dev/rewrite-module-specifiers.ts +81 -0
- package/src/server/dev/runtime.production.ts +24 -0
- package/src/server/dev/symbolicate.ts +135 -0
- package/src/server/dev/transform-failure.ts +8 -0
- package/src/server/dev-page-plugin.production.ts +3 -0
- package/src/server/dev-page-plugin.ts +110 -52
- package/src/server/devtools/hub.ts +6 -5
- package/src/server/devtools/instrumentation.production.ts +3 -3
- package/src/server/devtools/instrumentation.ts +14 -8
- package/src/server/devtools/plugin.ts +12 -153
- package/src/server/external-prerender.ts +10 -0
- package/src/server/instance.ts +5 -5
- package/src/server/internal.ts +42 -2
- package/src/server/logger.ts +21 -0
- package/src/server/render/assemble.ts +4 -45
- package/src/server/render/document.tsx +34 -0
- package/src/server/render/element.tsx +31 -15
- package/src/server/render/index.ts +1 -2
- package/src/server/render/isr.ts +70 -24
- package/src/server/render/loaders.ts +43 -8
- package/src/server/render/not-found.ts +77 -29
- package/src/server/render/ppr-document.ts +239 -0
- package/src/server/render/ppr-request.ts +104 -0
- package/src/server/render/ppr-route.ts +153 -32
- package/src/server/render/shell.ts +0 -12
- package/src/server/render/ssg.ts +39 -21
- package/src/server/render/ssr.ts +429 -143
- package/src/server/render/template.ts +128 -2
- package/src/server/router/defined-route.ts +78 -0
- package/src/server/router/discovery.ts +129 -29
- package/src/server/router/hmr.production.ts +7 -0
- package/src/server/router/hmr.ts +177 -67
- package/src/server/router/patterns.ts +45 -13
- package/src/server/router/plugin.ts +184 -78
- package/src/server/router/schema-merge.ts +4 -14
- package/src/server/router/schemas.ts +11 -8
- package/src/server/router/source-version.ts +9 -0
- package/src/server/router/types.ts +2 -0
- package/src/server/sync/adapter.ts +13 -0
- package/src/server/sync/config.ts +12 -12
- package/src/server/sync/index.ts +8 -8
- package/src/server/sync/notifier.ts +1 -0
- package/src/server/sync/plugin.ts +4 -1
- package/src/server/sync/postgres/index.ts +111 -5
- package/src/server/sync/postgres/migrate.ts +3 -2
- package/src/server/sync/response.ts +14 -10
- package/src/server/sync/runtime.ts +12 -0
- package/src/server/sync/stream.ts +78 -113
- package/src/shared/await.tsx +4 -5
- package/src/shared/browser-events.ts +28 -0
- package/src/shared/compact-json.ts +77 -0
- package/src/shared/deferred-ndjson.ts +20 -6
- package/src/shared/dev-diagnostics.ts +44 -0
- package/src/shared/elysia-contract.ts +63 -0
- package/src/shared/prefix.ts +8 -0
- package/src/shared/route-map.ts +46 -0
- package/src/shared/utils/index.ts +2 -20
- package/dist/build/server-routes-entry.d.ts +0 -13
- package/dist/build/server-routes-entry.ts +0 -30
- package/dist/server/router/index.d.ts +0 -7
- package/dist/server/router/index.js +0 -27
- package/dist/server/router/index.ts +0 -28
- package/src/build/server-routes-entry.ts +0 -30
- package/src/server/router/index.ts +0 -28
package/src/build/ssg-cache.ts
CHANGED
|
@@ -1,41 +1,124 @@
|
|
|
1
1
|
// biome-ignore-all lint/performance/noAwaitInLoops: SSG cache generation runs routes sequentially for deterministic cache output
|
|
2
2
|
import type { SsgCacheEntry } from "../server/cache/index.ts";
|
|
3
3
|
import { resolvePath } from "../server/render/assemble.ts";
|
|
4
|
-
import { prerenderSSG } from "../server/render/index.ts";
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
} from "../server/router/index.ts";
|
|
4
|
+
import { prerenderRoute, prerenderSSG } from "../server/render/index.ts";
|
|
5
|
+
import { hasRequestLoader } from "../server/render/loaders.ts";
|
|
6
|
+
import { buildRouteMatcher } from "../server/router/patterns.ts";
|
|
7
|
+
import { createSearchRouteMetadata } from "../server/router/schemas.ts";
|
|
8
|
+
import type { ResolvedRoute, RootLayout } from "../server/router/types.ts";
|
|
10
9
|
|
|
11
10
|
export type SSGCacheSnapshot = Record<string, SsgCacheEntry>;
|
|
12
11
|
|
|
12
|
+
export interface RoutePrerender {
|
|
13
|
+
path: string;
|
|
14
|
+
/** PPR targets are materialized later by the exact production bundle. */
|
|
15
|
+
result?: SsgCacheEntry | Response;
|
|
16
|
+
route: ResolvedRoute;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const DYNAMIC_SEGMENT_RE = /\/:[^/]+|\/\*/;
|
|
20
|
+
|
|
21
|
+
function hasRequestDependentInput(route: ResolvedRoute, root: RootLayout): boolean {
|
|
22
|
+
return [root.route, ...route.routeChain].some(
|
|
23
|
+
(routeConfig) =>
|
|
24
|
+
routeConfig.query !== undefined
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Renders every selected route URL known at build time. Fixed routes are always
|
|
30
|
+
* known; dynamic routes contribute the values returned by staticParams(). ISR
|
|
31
|
+
* routes with query schemas stay on-demand. PPR paths are collected here, then
|
|
32
|
+
* rendered by the production bundle so React's postponed tree matches at runtime.
|
|
33
|
+
*/
|
|
34
|
+
export async function buildRoutePrerenders(
|
|
35
|
+
routes: ResolvedRoute[],
|
|
36
|
+
root: RootLayout,
|
|
37
|
+
origin: string,
|
|
38
|
+
basePath: string
|
|
39
|
+
): Promise<RoutePrerender[]> {
|
|
40
|
+
const prerenders: RoutePrerender[] = [];
|
|
41
|
+
const searchRoutes = createSearchRouteMetadata(routes);
|
|
42
|
+
const matchRoute = buildRouteMatcher(routes);
|
|
43
|
+
|
|
44
|
+
for (const route of routes) {
|
|
45
|
+
if (route.mode === "ssr") {
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
if (hasRequestDependentInput(route, root)) {
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
let paramSets: Record<string, string>[];
|
|
53
|
+
if (!DYNAMIC_SEGMENT_RE.test(route.pattern)) {
|
|
54
|
+
paramSets = [{}];
|
|
55
|
+
} else if (route.page.staticParams) {
|
|
56
|
+
const resolvedParams = await route.page.staticParams();
|
|
57
|
+
if (!Array.isArray(resolvedParams)) {
|
|
58
|
+
throw new TypeError(
|
|
59
|
+
`[furin] staticParams() for "${route.pattern}" must return an array.`
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
paramSets = resolvedParams;
|
|
63
|
+
} else {
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
for (const params of paramSets) {
|
|
68
|
+
const path = resolvePath(route.pattern, params);
|
|
69
|
+
if (matchRoute(path)?.route !== route) {
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
if (root.route.requestLoader !== undefined || hasRequestLoader(route)) {
|
|
73
|
+
prerenders.push({ path, route });
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
const result =
|
|
77
|
+
route.mode === "ssg"
|
|
78
|
+
? await prerenderSSG(route, params, root, origin, basePath, searchRoutes)
|
|
79
|
+
: await prerenderRoute(
|
|
80
|
+
route,
|
|
81
|
+
params,
|
|
82
|
+
root,
|
|
83
|
+
origin,
|
|
84
|
+
"isr",
|
|
85
|
+
basePath,
|
|
86
|
+
searchRoutes
|
|
87
|
+
);
|
|
88
|
+
prerenders.push({ path, result, route });
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return prerenders;
|
|
93
|
+
}
|
|
94
|
+
|
|
13
95
|
export async function buildSSGCacheSnapshot(
|
|
14
96
|
routes: ResolvedRoute[],
|
|
15
97
|
root: RootLayout,
|
|
16
98
|
origin: string,
|
|
17
|
-
// Build-time renders run OUTSIDE any instance scope (default bucket), so a
|
|
18
|
-
// prefixed app's mount prefix must be passed explicitly — otherwise the
|
|
19
|
-
// snapshot HTML bakes in basePath "" and prerendered <Link> hrefs lose it.
|
|
20
99
|
basePath?: string
|
|
21
100
|
): Promise<SSGCacheSnapshot> {
|
|
22
101
|
const snapshot: SSGCacheSnapshot = {};
|
|
23
102
|
const searchRoutes = createSearchRouteMetadata(routes);
|
|
24
103
|
|
|
25
104
|
for (const route of routes) {
|
|
26
|
-
if (route.mode !== "ssg" || !route.page.staticParams) {
|
|
105
|
+
if (route.mode !== "ssg" || !route.page.staticParams || hasRequestLoader(route)) {
|
|
27
106
|
continue;
|
|
28
107
|
}
|
|
29
|
-
|
|
30
108
|
const paramSets = await route.page.staticParams();
|
|
31
109
|
for (const params of paramSets) {
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
110
|
+
const result = await prerenderSSG(
|
|
111
|
+
route,
|
|
112
|
+
params,
|
|
113
|
+
root,
|
|
114
|
+
origin,
|
|
115
|
+
basePath,
|
|
116
|
+
searchRoutes
|
|
117
|
+
);
|
|
118
|
+
if (!(result instanceof Response)) {
|
|
119
|
+
snapshot[resolvePath(route.pattern, params)] = result;
|
|
35
120
|
}
|
|
36
|
-
snapshot[resolvePath(route.pattern, params)] = entry;
|
|
37
121
|
}
|
|
38
122
|
}
|
|
39
|
-
|
|
40
123
|
return snapshot;
|
|
41
124
|
}
|
package/src/build/types.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
1
|
+
import type {
|
|
2
|
+
BuildTarget,
|
|
3
|
+
StaticExportConfig,
|
|
4
|
+
VercelDeploymentConfig,
|
|
5
|
+
} from "../config";
|
|
6
|
+
import type { ResolvedRoute } from "../server/router/types.ts";
|
|
3
7
|
|
|
4
8
|
export interface BuildClientOptions {
|
|
5
9
|
/**
|
|
@@ -15,9 +19,15 @@ export interface BuildClientOptions {
|
|
|
15
19
|
clientDirName?: string;
|
|
16
20
|
/** Inject the evlog client logger into the hydrate entry. Off by default. */
|
|
17
21
|
clientLogging: boolean;
|
|
22
|
+
/** Write Bun's complete build metafile to this path when provided. */
|
|
23
|
+
metafilePath?: string;
|
|
24
|
+
/** Package barrels Bun should parse on demand instead of loading in full. */
|
|
25
|
+
optimizeImports?: string[];
|
|
18
26
|
outDir: string;
|
|
19
27
|
pagesDir?: string;
|
|
20
28
|
plugins?: Bun.BunPlugin[];
|
|
29
|
+
/** Enable Bun's native Rust React Compiler. Defaults to true. */
|
|
30
|
+
reactCompiler?: boolean;
|
|
21
31
|
/**
|
|
22
32
|
* Public path prefix for all emitted JS/CSS chunks.
|
|
23
33
|
* Pass "/_client/" for root deployments; override for basePath deployments,
|
|
@@ -64,7 +74,8 @@ export interface PackageTargetBuildManifest {
|
|
|
64
74
|
export type AnyTargetManifest =
|
|
65
75
|
| TargetBuildManifest
|
|
66
76
|
| StaticTargetBuildManifest
|
|
67
|
-
| PackageTargetBuildManifest
|
|
77
|
+
| PackageTargetBuildManifest
|
|
78
|
+
| VercelTargetBuildManifest;
|
|
68
79
|
|
|
69
80
|
/** One mounted app in a multi-instance build. */
|
|
70
81
|
export interface BuildAppSpec {
|
|
@@ -87,6 +98,8 @@ export interface BuildManifest {
|
|
|
87
98
|
}
|
|
88
99
|
|
|
89
100
|
export interface BuildAppOptions {
|
|
101
|
+
/** Emit Bun metafiles for client and supported server bundle analysis. */
|
|
102
|
+
analyze?: boolean;
|
|
90
103
|
/**
|
|
91
104
|
* Explicit multi-app build (furin.config.ts `apps`). Overrides `pagesDir`
|
|
92
105
|
* and server-entry auto-detection.
|
|
@@ -95,13 +108,19 @@ export interface BuildAppOptions {
|
|
|
95
108
|
/** Inject the evlog client logger into the hydrate entry. Defaults to false. */
|
|
96
109
|
clientLogging?: boolean;
|
|
97
110
|
compile?: "server" | "embed";
|
|
111
|
+
/** Package barrels Bun should parse on demand in production client bundles. */
|
|
112
|
+
optimizeImports?: string[];
|
|
98
113
|
pagesDir?: string;
|
|
99
114
|
plugins?: Bun.BunPlugin[];
|
|
115
|
+
/** Enable Bun's native Rust React Compiler for client bundles. Defaults to true. */
|
|
116
|
+
reactCompiler?: boolean;
|
|
100
117
|
rootDir?: string;
|
|
101
118
|
serverEntry?: string;
|
|
102
119
|
/** Configuration for the `static` build target. */
|
|
103
120
|
staticConfig?: StaticExportConfig;
|
|
104
121
|
target: BuildTarget | "all";
|
|
122
|
+
/** Configuration for the Vercel build target. */
|
|
123
|
+
vercelConfig?: VercelDeploymentConfig;
|
|
105
124
|
}
|
|
106
125
|
|
|
107
126
|
/** Build manifest entry produced by the `static` adapter. */
|
|
@@ -113,6 +132,16 @@ export interface StaticTargetBuildManifest {
|
|
|
113
132
|
skippedRoutes: string[];
|
|
114
133
|
}
|
|
115
134
|
|
|
135
|
+
/** Build manifest entry produced by the Vercel Build Output API adapter. */
|
|
136
|
+
export interface VercelTargetBuildManifest {
|
|
137
|
+
buildId: string;
|
|
138
|
+
generatedAt: string;
|
|
139
|
+
isrRoutes: string[];
|
|
140
|
+
outputDir: string;
|
|
141
|
+
serverPath: string;
|
|
142
|
+
ssgRoutes: string[];
|
|
143
|
+
}
|
|
144
|
+
|
|
116
145
|
export interface BuildAppResult {
|
|
117
146
|
manifest: BuildManifest;
|
|
118
147
|
targets: Partial<Record<BuildTarget, AnyTargetManifest>>;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
const REGEX_SPECIAL_CHARACTERS_RE = /[.*+?^${}()|[\]\\]/g;
|
|
2
|
+
|
|
3
|
+
export interface VirtualBuildEntry {
|
|
4
|
+
entrypoint: string;
|
|
5
|
+
files: { [path: string]: string };
|
|
6
|
+
plugin: Bun.BunPlugin;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function createVirtualBuildEntry(
|
|
10
|
+
entrypoint: string,
|
|
11
|
+
source: string,
|
|
12
|
+
loader: Bun.Loader
|
|
13
|
+
): VirtualBuildEntry {
|
|
14
|
+
const entrypointFilter = new RegExp(
|
|
15
|
+
`^${entrypoint.replace(REGEX_SPECIAL_CHARACTERS_RE, "\\$&")}$`
|
|
16
|
+
);
|
|
17
|
+
return {
|
|
18
|
+
entrypoint,
|
|
19
|
+
files: { [entrypoint]: source },
|
|
20
|
+
plugin: {
|
|
21
|
+
name: `furin-virtual-entry:${entrypoint}`,
|
|
22
|
+
setup(build) {
|
|
23
|
+
build.onLoad({ filter: entrypointFilter }, () => ({ contents: source, loader }));
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
}
|
package/src/cache.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getCache as getRuntimeCache,
|
|
3
|
+
type RuntimeCache as RuntimeCacheContract,
|
|
4
|
+
type RuntimeCacheOptions as RuntimeCacheOptionsContract,
|
|
5
|
+
type RuntimeCacheSetOptions as RuntimeCacheSetOptionsContract,
|
|
6
|
+
} from "./server/cache/runtime-cache.ts";
|
|
7
|
+
|
|
8
|
+
export type RuntimeCache = RuntimeCacheContract;
|
|
9
|
+
export type RuntimeCacheOptions = RuntimeCacheOptionsContract;
|
|
10
|
+
export type RuntimeCacheSetOptions = RuntimeCacheSetOptionsContract;
|
|
11
|
+
|
|
12
|
+
export function getCache(options?: RuntimeCacheOptions): RuntimeCache {
|
|
13
|
+
return getRuntimeCache(options);
|
|
14
|
+
}
|
package/src/cli/config.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { existsSync } from "node:fs";
|
|
2
2
|
import { resolve } from "node:path";
|
|
3
3
|
import { pathToFileURL } from "node:url";
|
|
4
|
-
import { TypeCompiler } from "elysia/type-system";
|
|
5
4
|
import { configSchema, type FurinConfig } from "../config.ts";
|
|
5
|
+
import { TypeCompiler } from "../shared/elysia-contract.ts";
|
|
6
6
|
|
|
7
7
|
const compiledConfigSchema = TypeCompiler.Compile(configSchema);
|
|
8
8
|
|
|
@@ -64,11 +64,11 @@ export async function loadCliConfig(
|
|
|
64
64
|
const resolvedRootDir = resolve(rootDir, configToValidate.rootDir ?? ".");
|
|
65
65
|
return {
|
|
66
66
|
...configToValidate,
|
|
67
|
-
plugins,
|
|
68
67
|
configPath,
|
|
69
|
-
rootDir: resolvedRootDir,
|
|
70
68
|
pagesDir: configToValidate.pagesDir
|
|
71
69
|
? resolve(resolvedRootDir, configToValidate.pagesDir)
|
|
72
70
|
: undefined,
|
|
71
|
+
plugins,
|
|
72
|
+
rootDir: resolvedRootDir,
|
|
73
73
|
};
|
|
74
74
|
}
|
package/src/cli/index.ts
CHANGED
|
@@ -6,6 +6,7 @@ import { buildApp } from "../build/index.ts";
|
|
|
6
6
|
import { BUILD_TARGETS, type BuildTarget } from "../config.ts";
|
|
7
7
|
import { normalizePrefix } from "../server/instance.ts";
|
|
8
8
|
import { loadCliConfig } from "./config.ts";
|
|
9
|
+
import { normalizeStaticPreviewBasePath, startStaticPreview } from "./preview.ts";
|
|
9
10
|
|
|
10
11
|
const argv = process.argv.slice(2);
|
|
11
12
|
const [command] = argv;
|
|
@@ -70,7 +71,43 @@ function extractCompileFlag(args: string[]): {
|
|
|
70
71
|
return { compileFlag, parseableArgs };
|
|
71
72
|
}
|
|
72
73
|
|
|
73
|
-
if (command === "
|
|
74
|
+
if (command === "preview") {
|
|
75
|
+
let rawValues: ReturnType<typeof parseArgs>["values"];
|
|
76
|
+
try {
|
|
77
|
+
rawValues = parseArgs({
|
|
78
|
+
args: argv.slice(1),
|
|
79
|
+
options: {
|
|
80
|
+
basePath: { type: "string" },
|
|
81
|
+
config: { type: "string" },
|
|
82
|
+
dir: { type: "string" },
|
|
83
|
+
port: { type: "string" },
|
|
84
|
+
},
|
|
85
|
+
strict: true,
|
|
86
|
+
}).values;
|
|
87
|
+
} catch (error) {
|
|
88
|
+
bail(error instanceof Error ? error.message : String(error));
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const values = rawValues as {
|
|
92
|
+
basePath?: string;
|
|
93
|
+
config?: string;
|
|
94
|
+
dir?: string;
|
|
95
|
+
port?: string;
|
|
96
|
+
};
|
|
97
|
+
const config = await loadCliConfig(process.cwd(), values.config);
|
|
98
|
+
const port = values.port === undefined ? 3000 : Number(values.port);
|
|
99
|
+
if (!(Number.isInteger(port) && port > 0 && port <= 65_535)) {
|
|
100
|
+
bail(`Invalid preview port "${values.port}". Expected an integer between 1 and 65535.`);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const distDir = resolve(config.rootDir, values.dir ?? config.static?.outDir ?? "dist");
|
|
104
|
+
const basePath = normalizeStaticPreviewBasePath(values.basePath ?? config.static?.basePath ?? "");
|
|
105
|
+
const server = startStaticPreview({ basePath, distDir, port });
|
|
106
|
+
log("Static preview ready");
|
|
107
|
+
console.log(` Local: ${new URL(`${basePath || ""}/`, server.url)}`);
|
|
108
|
+
console.log(` Serves: ${distDir}`);
|
|
109
|
+
console.log(" Press Ctrl+C to stop\n");
|
|
110
|
+
} else if (command === "build") {
|
|
74
111
|
const buildArgv = argv.slice(1);
|
|
75
112
|
const { compileFlag, parseableArgs } = extractCompileFlag(buildArgv);
|
|
76
113
|
let rawValues: ReturnType<typeof parseArgs>["values"];
|
|
@@ -78,10 +115,11 @@ if (command === "build") {
|
|
|
78
115
|
rawValues = parseArgs({
|
|
79
116
|
args: parseableArgs,
|
|
80
117
|
options: {
|
|
81
|
-
|
|
118
|
+
analyze: { type: "boolean" },
|
|
119
|
+
config: { type: "string" },
|
|
82
120
|
pagesDir: { type: "string" },
|
|
83
121
|
prefix: { type: "string" },
|
|
84
|
-
|
|
122
|
+
target: { type: "string" },
|
|
85
123
|
},
|
|
86
124
|
strict: true,
|
|
87
125
|
}).values;
|
|
@@ -90,6 +128,7 @@ if (command === "build") {
|
|
|
90
128
|
}
|
|
91
129
|
|
|
92
130
|
const values = rawValues as {
|
|
131
|
+
analyze?: boolean;
|
|
93
132
|
target?: string;
|
|
94
133
|
pagesDir?: string;
|
|
95
134
|
prefix?: string;
|
|
@@ -120,9 +159,7 @@ if (command === "build") {
|
|
|
120
159
|
log(`Building Furin for ${target}…`);
|
|
121
160
|
|
|
122
161
|
const result = await buildApp({
|
|
123
|
-
|
|
124
|
-
compile: resolveCompileMode(compileFlag, config.bun?.compile),
|
|
125
|
-
rootDir: config.rootDir,
|
|
162
|
+
analyze: values.analyze,
|
|
126
163
|
// --pagesDir/--prefix build a single explicit app; otherwise fall back to
|
|
127
164
|
// the config's `apps` list (then to server.ts scanning inside buildApp).
|
|
128
165
|
// normalizePrefix here so a bad --prefix fails before buildApp starts
|
|
@@ -136,11 +173,17 @@ if (command === "build") {
|
|
|
136
173
|
},
|
|
137
174
|
]
|
|
138
175
|
: config.apps,
|
|
176
|
+
clientLogging: config.clientLogging ?? false,
|
|
177
|
+
compile: resolveCompileMode(compileFlag, config.bun?.compile),
|
|
178
|
+
optimizeImports: config.optimizeImports,
|
|
139
179
|
pagesDir: undefined,
|
|
140
|
-
serverEntry: resolvedServerEntry,
|
|
141
180
|
plugins: config.plugins,
|
|
181
|
+
reactCompiler: config.reactCompiler,
|
|
182
|
+
rootDir: config.rootDir,
|
|
183
|
+
serverEntry: resolvedServerEntry,
|
|
142
184
|
staticConfig: config.static,
|
|
143
|
-
|
|
185
|
+
target: target as BuildTarget | "all",
|
|
186
|
+
vercelConfig: config.vercel,
|
|
144
187
|
});
|
|
145
188
|
|
|
146
189
|
const built = Object.keys(result.targets).join(", ") || "none";
|
|
@@ -149,15 +192,24 @@ if (command === "build") {
|
|
|
149
192
|
console.log(
|
|
150
193
|
`Furin CLI
|
|
151
194
|
|
|
152
|
-
USAGE
|
|
195
|
+
USAGE
|
|
196
|
+
furin build [options]
|
|
197
|
+
furin preview [options]
|
|
153
198
|
|
|
154
|
-
OPTIONS
|
|
199
|
+
BUILD OPTIONS
|
|
155
200
|
--target ${BUILD_TARGETS.join(" | ")} | all (default: bun)
|
|
156
201
|
"package" builds a publishable Elysia-plugin artifact (register.js + factory + client assets)
|
|
157
202
|
--pagesDir Pages directory
|
|
158
203
|
--prefix Mount prefix for the built app (e.g. /admin) — pairs with --pagesDir
|
|
159
204
|
--config Config file path
|
|
160
205
|
--compile server | embed Compile to binary: "server" keeps client on disk, "embed" is self-contained
|
|
206
|
+
--analyze Write complete bundle metafiles to .furin/build/analysis
|
|
207
|
+
|
|
208
|
+
PREVIEW OPTIONS
|
|
209
|
+
--dir Static export directory (default: static.outDir or dist)
|
|
210
|
+
--basePath Static export base path (default: static.basePath or "")
|
|
211
|
+
--port Listening port (default: 3000)
|
|
212
|
+
--config Config file path
|
|
161
213
|
`
|
|
162
214
|
);
|
|
163
215
|
} else {
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import { isAbsolute, join, relative, resolve } from "node:path";
|
|
3
|
+
|
|
4
|
+
const LEADING_SLASHES_RE = /^\/+/;
|
|
5
|
+
const TRAILING_SLASHES_RE = /\/+$/;
|
|
6
|
+
|
|
7
|
+
export interface StaticPreviewOptions {
|
|
8
|
+
basePath: string;
|
|
9
|
+
distDir: string;
|
|
10
|
+
port: number;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function normalizeStaticPreviewBasePath(basePath: string): string {
|
|
14
|
+
if (basePath === "" || basePath === "/") {
|
|
15
|
+
return "";
|
|
16
|
+
}
|
|
17
|
+
if (!basePath.startsWith("/")) {
|
|
18
|
+
throw new Error(`[furin] preview: basePath must start with "/" (received "${basePath}").`);
|
|
19
|
+
}
|
|
20
|
+
return basePath.replace(TRAILING_SLASHES_RE, "");
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function startStaticPreview({
|
|
24
|
+
basePath: rawBasePath,
|
|
25
|
+
distDir: rawDistDir,
|
|
26
|
+
port,
|
|
27
|
+
}: StaticPreviewOptions): Bun.Server<undefined> {
|
|
28
|
+
const basePath = normalizeStaticPreviewBasePath(rawBasePath);
|
|
29
|
+
const distDir = resolve(rawDistDir);
|
|
30
|
+
const indexPath = join(distDir, "index.html");
|
|
31
|
+
const notFoundPath = join(distDir, "404.html");
|
|
32
|
+
const faviconPath = join(distDir, "favicon.ico");
|
|
33
|
+
|
|
34
|
+
if (!(existsSync(indexPath) && existsSync(notFoundPath))) {
|
|
35
|
+
throw new Error(
|
|
36
|
+
`[furin] preview: "${distDir}" is not a Furin static export. Run \`furin build --target static\` first.`
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const notFound = (): Response => new Response(Bun.file(notFoundPath), { status: 404 });
|
|
41
|
+
const clientDir = join(distDir, "_client");
|
|
42
|
+
const fetchStaticFile = async (request: Request): Promise<Response> => {
|
|
43
|
+
const encodedPathname = new URL(request.url).pathname;
|
|
44
|
+
let pathname: string;
|
|
45
|
+
try {
|
|
46
|
+
pathname = decodeURIComponent(encodedPathname);
|
|
47
|
+
} catch {
|
|
48
|
+
return notFound();
|
|
49
|
+
}
|
|
50
|
+
if (basePath && pathname !== basePath && !pathname.startsWith(`${basePath}/`)) {
|
|
51
|
+
return notFound();
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const logicalPath = pathname.slice(basePath.length).replace(LEADING_SLASHES_RE, "");
|
|
55
|
+
const exactPath = resolve(distDir, logicalPath);
|
|
56
|
+
const relativePath = relative(distDir, exactPath);
|
|
57
|
+
if (relativePath.startsWith("..") || isAbsolute(relativePath)) {
|
|
58
|
+
return notFound();
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const exactFile = Bun.file(exactPath);
|
|
62
|
+
if (!pathname.endsWith("/") && (await exactFile.exists())) {
|
|
63
|
+
return new Response(exactFile);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const indexFile = Bun.file(join(exactPath, "index.html"));
|
|
67
|
+
if (await indexFile.exists()) {
|
|
68
|
+
return new Response(indexFile);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return notFound();
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
const entryRoutes = basePath
|
|
75
|
+
? {
|
|
76
|
+
"/": (request: Request) => Response.redirect(new URL(`${basePath}/`, request.url), 302),
|
|
77
|
+
[basePath]: Bun.file(indexPath),
|
|
78
|
+
}
|
|
79
|
+
: { "/": Bun.file(indexPath) };
|
|
80
|
+
|
|
81
|
+
return Bun.serve({
|
|
82
|
+
fetch: fetchStaticFile,
|
|
83
|
+
port,
|
|
84
|
+
routes: {
|
|
85
|
+
...entryRoutes,
|
|
86
|
+
[`${basePath}/_client/*`]: { dir: clientDir },
|
|
87
|
+
"/favicon.ico": existsSync(faviconPath) ? Bun.file(faviconPath) : notFound(),
|
|
88
|
+
},
|
|
89
|
+
});
|
|
90
|
+
}
|
|
@@ -3,6 +3,7 @@ import { computeErrorDigest } from "../shared/digest.ts";
|
|
|
3
3
|
import { type ErrorComponent, getPublicErrorMessage } from "../shared/error.ts";
|
|
4
4
|
import { isNotFoundError, type NotFoundComponent } from "../shared/not-found.ts";
|
|
5
5
|
import { DefaultErrorFallback, DefaultNotFoundFallback } from "./default-screens.tsx";
|
|
6
|
+
import { FurinDocumentFallback } from "./document.tsx";
|
|
6
7
|
import { isFurinServerError } from "./server-error.ts";
|
|
7
8
|
|
|
8
9
|
/**
|
|
@@ -50,6 +51,8 @@ interface ErrorBoundaryProps {
|
|
|
50
51
|
* keep distinct IDs.
|
|
51
52
|
*/
|
|
52
53
|
digest?: string;
|
|
54
|
+
/** @internal Preserve a valid document when the outer root boundary catches. */
|
|
55
|
+
document?: boolean;
|
|
53
56
|
/** Component rendered when an error is caught. Omit to use the built-in default. */
|
|
54
57
|
fallback?: ErrorComponent;
|
|
55
58
|
/**
|
|
@@ -87,7 +90,6 @@ interface ErrorBoundaryState {
|
|
|
87
90
|
* Must be a class: React error catching (`getDerivedStateFromError`,
|
|
88
91
|
* `componentDidCatch`) has no function-component equivalent.
|
|
89
92
|
*/
|
|
90
|
-
// biome-ignore lint/style/useReactFunctionComponents: React error boundaries require a class component.
|
|
91
93
|
export class FurinErrorBoundary extends Component<ErrorBoundaryProps, ErrorBoundaryState> {
|
|
92
94
|
override state: ErrorBoundaryState = {
|
|
93
95
|
digest: null,
|
|
@@ -105,6 +107,16 @@ export class FurinErrorBoundary extends Component<ErrorBoundaryProps, ErrorBound
|
|
|
105
107
|
};
|
|
106
108
|
}
|
|
107
109
|
|
|
110
|
+
override componentDidCatch(error: Error): void {
|
|
111
|
+
if (import.meta.hot && typeof window !== "undefined") {
|
|
112
|
+
window.dispatchEvent(
|
|
113
|
+
new CustomEvent("furin:client-error", {
|
|
114
|
+
detail: { error, phase: "client-render" },
|
|
115
|
+
})
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
108
120
|
override componentDidUpdate(prevProps: ErrorBoundaryProps) {
|
|
109
121
|
if (prevProps.resetKey !== this.props.resetKey && this.state.error) {
|
|
110
122
|
this.reset();
|
|
@@ -151,12 +163,17 @@ export class FurinErrorBoundary extends Component<ErrorBoundaryProps, ErrorBound
|
|
|
151
163
|
// (or the loader's computed 500 for non-Response throws); everything else
|
|
152
164
|
// collapses to the default 500.
|
|
153
165
|
const status = isFurinServerError(error) ? error.status : DEFAULT_ERROR_STATUS;
|
|
154
|
-
|
|
166
|
+
const fallback = (
|
|
155
167
|
<Fallback
|
|
156
168
|
error={{ digest: finalDigest, message, status }}
|
|
157
169
|
reset={typeof window === "undefined" ? SERVER_RESET_NOOP : this.reset}
|
|
158
170
|
/>
|
|
159
171
|
);
|
|
172
|
+
return this.props.document ? (
|
|
173
|
+
<FurinDocumentFallback>{fallback}</FurinDocumentFallback>
|
|
174
|
+
) : (
|
|
175
|
+
fallback
|
|
176
|
+
);
|
|
160
177
|
}
|
|
161
178
|
// The `key` trick ensures that after a reset, children remount fresh
|
|
162
179
|
// rather than retaining stale state from the failed render.
|