@teyik0/furin 0.2.0-alpha.5 → 0.3.0-alpha.1
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 +2 -3
- package/dist/adapter/static.d.ts +1 -1
- package/dist/build/bun-build.d.ts +3 -0
- package/dist/build/entry-template.d.ts +2 -0
- package/dist/build/entry-template.ts +3 -0
- package/dist/build/hydrate.d.ts +1 -1
- package/dist/build/index.js +6944 -5067
- package/dist/build/production-instrumentation.d.ts +1 -0
- package/dist/build/route-types.d.ts +1 -1
- package/dist/build/types.d.ts +1 -0
- package/dist/cli/index.js +7874 -5971
- package/dist/client/boundaries.d.ts +4 -4
- package/dist/client/internal/runtime-types.d.ts +30 -0
- package/dist/client/link.d.ts +2 -1
- package/dist/client/link.js +712 -338
- package/dist/client/router/boundary-tree.d.ts +1 -1
- package/dist/client/router/index.d.ts +1 -1
- package/dist/client/router/link-utils.d.ts +5 -1
- package/dist/client/router/sync-catch-up.d.ts +4 -4
- package/dist/client/router/types.d.ts +2 -2
- package/dist/client-only.d.ts +1 -0
- package/dist/client-only.js +1 -0
- package/dist/client.d.ts +108 -111
- package/dist/client.js +16 -17
- package/dist/config.d.ts +1 -1
- package/dist/config.js +2 -2
- package/dist/devtools/devtools-element.d.ts +1 -0
- package/dist/devtools/protocol.d.ts +119 -0
- package/dist/furin.d.ts +7 -6
- package/dist/furin.js +6547 -3187
- package/dist/isomorphic.d.ts +18 -0
- package/dist/plugin/binding-scope.d.ts +2 -0
- package/dist/plugin/dead-code-elimination.d.ts +3 -0
- package/dist/plugin/index.js +933 -423
- package/dist/plugin/transform-client.d.ts +0 -2
- package/dist/plugin/transform-isomorphic.d.ts +9 -0
- package/dist/rsc/build/environment.d.ts +2 -0
- package/dist/rsc/build/index.d.ts +15 -0
- package/dist/rsc/client-codec.d.ts +1 -0
- package/dist/rsc/codec.d.ts +4 -0
- package/dist/rsc/flight-drain.d.ts +11 -0
- package/dist/rsc/render-error.d.ts +17 -0
- package/dist/rsc/server-codec.d.ts +2 -0
- package/dist/rsc/server-codec.js +24 -0
- package/dist/rsc/shared.d.ts +30 -0
- package/dist/rsc/symbols.d.ts +2 -0
- package/dist/rsc/transport-benchmark.d.ts +13 -0
- package/dist/rsc/version.d.ts +7 -0
- package/dist/rsc-client.d.ts +4 -0
- package/dist/rsc-client.js +166 -0
- package/dist/rsc-server.d.ts +11 -0
- package/dist/rsc.d.ts +11 -0
- package/dist/rsc.js +353 -0
- package/dist/server/cache/index.d.ts +2 -2
- package/dist/server/cache/invalidation.d.ts +2 -3
- package/dist/server/cache/isr-ssg.d.ts +5 -1
- package/dist/server/cache/isr.d.ts +9 -0
- package/dist/server/cache/route-cache.d.ts +10 -8
- package/dist/server/cache/store-view.d.ts +7 -7
- package/dist/server/dev-page-plugin.d.ts +4 -0
- package/dist/server/devtools/hub.d.ts +11 -0
- package/dist/server/devtools/instrumentation.d.ts +22 -0
- package/dist/server/devtools/instrumentation.production.d.ts +44 -0
- package/dist/server/devtools/plugin.d.ts +3 -0
- package/dist/server/devtools/request-context.d.ts +6 -0
- package/dist/server/internal.d.ts +2 -0
- package/dist/server/internal.js +3 -3
- package/dist/server/lang-detect.d.ts +1 -0
- package/dist/server/render/assemble.d.ts +4 -0
- package/dist/server/render/element.d.ts +1 -1
- package/dist/server/render/index.d.ts +2 -2
- package/dist/server/render/index.ts +6 -2
- package/dist/server/render/loaders.d.ts +8 -0
- package/dist/server/render/not-found.d.ts +1 -1
- package/dist/server/render/ppr-route.d.ts +8 -0
- package/dist/server/render/route-frame-transport.d.ts +2 -0
- package/dist/server/render/shell.ts +0 -1
- package/dist/server/render/ssr.d.ts +2 -3
- package/dist/server/router/discovery.d.ts +1 -1
- package/dist/server/router/hmr.d.ts +1 -1
- package/dist/server/router/index.d.ts +2 -1
- package/dist/server/router/index.js +23 -23
- package/dist/server/router/index.ts +1 -1
- package/dist/server/router/patterns.d.ts +1 -1
- package/dist/server/router/plugin.d.ts +4 -7
- package/dist/server/router/schema-merge.d.ts +3 -0
- package/dist/server/router/schemas.d.ts +12 -7
- package/dist/server/router/types.d.ts +1 -1
- package/dist/server/runtime-env.js +2 -2
- package/dist/server/sync/adapter.d.ts +45 -26
- package/dist/server/sync/config.d.ts +5 -9
- package/dist/server/sync/fingerprint.d.ts +2 -1
- package/dist/server/sync/index.d.ts +15 -4
- package/dist/server/sync/index.js +2868 -0
- package/dist/server/sync/notifier.d.ts +18 -0
- package/dist/server/sync/plugin.d.ts +53 -54
- package/dist/server/sync/postgres/index.d.ts +19 -0
- package/dist/server/sync/postgres/index.js +252 -0
- package/dist/server/sync/postgres/migrate.d.ts +2 -0
- package/dist/server/sync/postgres/migrate.js +16 -0
- package/dist/server/sync/postgres/migration.sql +66 -0
- package/dist/server/sync/redis/index.d.ts +30 -0
- package/dist/server/sync/redis/index.js +336 -0
- package/dist/server/sync/redis/scripts.d.ts +4 -0
- package/dist/server/sync/response.d.ts +10 -1
- package/dist/server/sync/runtime.d.ts +6 -0
- package/dist/server/sync/sqlite/index.d.ts +20 -0
- package/dist/server/sync/sqlite/index.js +250 -0
- package/dist/server/sync/stream.d.ts +12 -11
- package/dist/server-only.d.ts +1 -0
- package/dist/server-only.js +1 -0
- package/dist/shared/parser.d.ts +2 -0
- package/dist/shared/route-frame.d.ts +49 -0
- package/dist/shared/utils/index.d.ts +1 -1
- package/package.json +54 -12
- package/src/adapter/bun.ts +73 -16
- package/src/adapter/package.ts +3 -1
- package/src/adapter/static.ts +94 -48
- package/src/build/bun-build.ts +11 -0
- package/src/build/client.ts +22 -24
- package/src/build/entry-template.ts +3 -0
- package/src/build/hydrate.ts +33 -8
- package/src/build/index.ts +12 -0
- package/src/build/production-instrumentation.ts +14 -0
- package/src/build/route-types.ts +7 -8
- package/src/build/scan-server.ts +3 -2
- package/src/build/ssg-cache.ts +7 -2
- package/src/build/types.ts +1 -0
- package/src/cli/index.ts +53 -22
- package/src/client/boundaries.tsx +42 -18
- package/src/client/default-screens.tsx +4 -4
- package/src/client/internal/runtime-types.ts +31 -0
- package/src/client/link.tsx +35 -37
- package/src/client/router/boundary-tree.tsx +2 -2
- package/src/client/router/context.ts +13 -9
- package/src/client/router/index.ts +3 -0
- package/src/client/router/link-utils.ts +66 -3
- package/src/client/router/navigation.ts +9 -15
- package/src/client/router/provider.tsx +74 -52
- package/src/client/router/search/index.ts +5 -7
- package/src/client/router/search-store.ts +5 -1
- package/src/client/router/spa-response.ts +3 -4
- package/src/client/router/sync-catch-up.ts +9 -8
- package/src/client/router/types.ts +2 -2
- package/src/client/sync.ts +3 -2
- package/src/client-only.ts +1 -0
- package/src/client.ts +221 -174
- package/src/devtools/devtools-element.js +884 -0
- package/src/devtools/protocol.ts +139 -0
- package/src/furin.ts +185 -96
- package/src/isomorphic.ts +66 -0
- package/src/plugin/binding-scope.ts +158 -0
- package/src/plugin/dead-code-elimination.ts +202 -0
- package/src/plugin/index.ts +14 -18
- package/src/plugin/transform-client.ts +237 -273
- package/src/plugin/transform-isomorphic.ts +464 -0
- package/src/rsc/build/environment.ts +30 -0
- package/src/rsc/build/index.ts +94 -0
- package/src/rsc/client-codec.ts +11 -0
- package/src/rsc/codec.ts +85 -0
- package/src/rsc/flight-drain.ts +68 -0
- package/src/rsc/react-server-dom-webpack.d.ts +23 -0
- package/src/rsc/render-error.ts +120 -0
- package/src/rsc/server-codec.ts +25 -0
- package/src/rsc/shared.tsx +113 -0
- package/src/rsc/symbols.ts +2 -0
- package/src/rsc/transport-benchmark.ts +73 -0
- package/src/rsc/version.ts +57 -0
- package/src/rsc-client.ts +12 -0
- package/src/rsc-server.tsx +91 -0
- package/src/rsc.tsx +75 -0
- package/src/server/auto-invalidate/runtime.ts +32 -6
- package/src/server/cache/dev-loader.ts +70 -10
- package/src/server/cache/index.ts +7 -3
- package/src/server/cache/invalidation.ts +33 -15
- package/src/server/cache/isr-ssg.ts +12 -3
- package/src/server/cache/isr.ts +84 -9
- package/src/server/cache/route-cache.ts +49 -36
- package/src/server/cache/store-view.ts +7 -7
- package/src/server/context-logger.ts +7 -7
- package/src/server/dev-page-plugin.ts +8 -6
- package/src/server/devtools/hub.ts +64 -0
- package/src/server/devtools/instrumentation.production.ts +80 -0
- package/src/server/devtools/instrumentation.ts +72 -0
- package/src/server/devtools/plugin.ts +267 -0
- package/src/server/devtools/request-context.ts +76 -0
- package/src/server/instance.ts +1 -1
- package/src/server/internal.ts +2 -0
- package/src/server/lang-detect.ts +14 -10
- package/src/server/render/assemble.ts +73 -10
- package/src/server/render/element.tsx +11 -8
- package/src/server/render/index.ts +6 -2
- package/src/server/render/isr.ts +154 -110
- package/src/server/render/loaders.ts +259 -45
- package/src/server/render/not-found.ts +10 -15
- package/src/server/render/ppr-route.ts +146 -0
- package/src/server/render/route-frame-transport.ts +62 -0
- package/src/server/render/shell.ts +0 -1
- package/src/server/render/ssg.ts +6 -5
- package/src/server/render/ssr.ts +155 -67
- package/src/server/render/template.ts +2 -1
- package/src/server/router/discovery.ts +39 -22
- package/src/server/router/hmr.ts +15 -13
- package/src/server/router/index.ts +1 -1
- package/src/server/router/patterns.ts +16 -15
- package/src/server/router/plugin.ts +151 -158
- package/src/server/router/schema-merge.ts +52 -0
- package/src/server/router/schemas.ts +55 -73
- package/src/server/router/types.ts +1 -1
- package/src/server/sync/adapter.ts +44 -28
- package/src/server/sync/config.ts +9 -27
- package/src/server/sync/fingerprint.ts +8 -3
- package/src/server/sync/index.ts +37 -13
- package/src/server/sync/notifier.ts +109 -0
- package/src/server/sync/plugin.ts +184 -89
- package/src/server/sync/postgres/index.ts +301 -0
- package/src/server/sync/postgres/migrate.ts +15 -0
- package/src/server/sync/postgres/migration.sql +66 -0
- package/src/server/sync/redis/index.ts +342 -0
- package/src/server/sync/redis/scripts.ts +74 -0
- package/src/server/sync/response.ts +141 -16
- package/src/server/sync/runtime.ts +27 -0
- package/src/server/sync/sql.d.ts +4 -0
- package/src/server/sync/sqlite/index.ts +337 -0
- package/src/server/sync/sqlite/migration.sql +70 -0
- package/src/server/sync/stream.ts +137 -81
- package/src/server-only.ts +1 -0
- package/src/shared/await.tsx +4 -4
- package/src/shared/deferred-ndjson.ts +34 -6
- package/src/shared/digest.ts +2 -2
- package/src/shared/parser.ts +5 -0
- package/src/shared/route-frame.ts +429 -0
- package/src/shared/search-params.ts +7 -7
- package/src/shared/utils/index.ts +5 -3
- package/dist/server/dev-inspector.d.ts +0 -89
- package/dist/server/sync/memory-adapter.d.ts +0 -17
- package/src/server/dev-inspector.ts +0 -60
- package/src/server/sync/memory-adapter.ts +0 -196
package/src/build/client.ts
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import { existsSync, mkdirSync, writeFileSync } from "node:fs";
|
|
2
2
|
import { basename, join } from "node:path";
|
|
3
3
|
import { transformForClient } from "../plugin/transform-client";
|
|
4
|
+
import { environmentGuardPlugin } from "../rsc/build/environment.ts";
|
|
5
|
+
import { detectLoaderFromPath } from "../server/lang-detect.ts";
|
|
4
6
|
import type { ResolvedRoute } from "../server/router/index.ts";
|
|
7
|
+
import { runBunBuild } from "./bun-build.ts";
|
|
5
8
|
import { generateHydrateEntry } from "./hydrate";
|
|
6
9
|
import { CLIENT_MODULE_PATH, LINK_MODULE_PATH, SEARCH_MODULE_PATH } from "./shared";
|
|
7
10
|
import type { BuildClientOptions, BunBuildAliasConfig } from "./types";
|
|
8
11
|
|
|
9
|
-
const
|
|
12
|
+
const SCRIPT_FILE_FILTER = /\.(tsx?|jsx?)$/;
|
|
10
13
|
|
|
11
14
|
export interface BuildClientResult {
|
|
12
15
|
/** Public paths of all CSS chunks, e.g. `["/_client/chunk-abc.css"]` */
|
|
@@ -59,34 +62,29 @@ export async function buildClient(
|
|
|
59
62
|
const transformPlugin: Bun.BunPlugin = {
|
|
60
63
|
name: "furin-transform-client",
|
|
61
64
|
setup(build) {
|
|
62
|
-
build.onLoad({ filter:
|
|
65
|
+
build.onLoad({ filter: SCRIPT_FILE_FILTER }, async (args) => {
|
|
63
66
|
const { path } = args;
|
|
64
67
|
if (path.includes("node_modules")) {
|
|
65
68
|
return;
|
|
66
69
|
}
|
|
67
70
|
|
|
68
71
|
const code = await Bun.file(path).text();
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
.replaceAll(`'furin/search'`, JSON.stringify(SEARCH_MODULE_PATH));
|
|
72
|
+
const result = transformForClient(code, path);
|
|
73
|
+
// transformForClient now emits TS/TSX directly (no pre-transpile),
|
|
74
|
+
// so JSX → React handling is delegated to Bun.build's loader, which
|
|
75
|
+
// applies the project tsconfig's automatic runtime by default.
|
|
76
|
+
const transformed = result.code
|
|
77
|
+
.replaceAll(`"@teyik0/furin/client"`, JSON.stringify(CLIENT_MODULE_PATH))
|
|
78
|
+
.replaceAll(`'furin/client'`, JSON.stringify(CLIENT_MODULE_PATH))
|
|
79
|
+
.replaceAll(`"@teyik0/furin/link"`, JSON.stringify(LINK_MODULE_PATH))
|
|
80
|
+
.replaceAll(`'furin/link'`, JSON.stringify(LINK_MODULE_PATH))
|
|
81
|
+
.replaceAll(`"@teyik0/furin/search"`, JSON.stringify(SEARCH_MODULE_PATH))
|
|
82
|
+
.replaceAll(`'furin/search'`, JSON.stringify(SEARCH_MODULE_PATH));
|
|
81
83
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
} catch (error) {
|
|
87
|
-
console.error(`[furin] Transform error for ${path}:`, error);
|
|
88
|
-
return;
|
|
89
|
-
}
|
|
84
|
+
return {
|
|
85
|
+
contents: transformed,
|
|
86
|
+
loader: detectLoaderFromPath(path),
|
|
87
|
+
};
|
|
90
88
|
});
|
|
91
89
|
},
|
|
92
90
|
};
|
|
@@ -114,7 +112,7 @@ export async function buildClient(
|
|
|
114
112
|
// Overridable via the `publicPath` option (e.g. "/furin/_client/" for basePath builds).
|
|
115
113
|
publicPath,
|
|
116
114
|
// User plugins run before the internal transform so they pre-process files first
|
|
117
|
-
plugins: plugins
|
|
115
|
+
plugins: [...(plugins ?? []), environmentGuardPlugin("client"), transformPlugin],
|
|
118
116
|
alias: {
|
|
119
117
|
"@teyik0/furin/client": CLIENT_MODULE_PATH,
|
|
120
118
|
"@teyik0/furin/link": LINK_MODULE_PATH,
|
|
@@ -125,7 +123,7 @@ export async function buildClient(
|
|
|
125
123
|
},
|
|
126
124
|
};
|
|
127
125
|
|
|
128
|
-
const result = await
|
|
126
|
+
const result = await runBunBuild(clientBuildConfig);
|
|
129
127
|
for (const output of result.outputs) {
|
|
130
128
|
console.log(`[furin] ${output.path} (${(output.size / 1024).toFixed(1)} KB)`);
|
|
131
129
|
}
|
|
@@ -20,6 +20,8 @@ const RUNTIME_ENV_MODULE_PATH = `${_pkgSrcDir}/server/runtime-env${_ext}`;
|
|
|
20
20
|
/** One app's compile context payload — the generated entry can carry several. */
|
|
21
21
|
export interface EntryAppContext {
|
|
22
22
|
buildId?: string;
|
|
23
|
+
/** Whether the emitted hydration client sends browser log batches. */
|
|
24
|
+
clientLogging?: boolean;
|
|
23
25
|
/** Extra lines injected inside this app's `__setCompileContext({...})` call. */
|
|
24
26
|
extraContext?: string[];
|
|
25
27
|
/** Extra import lines this app needs (embedded asset imports). */
|
|
@@ -140,6 +142,7 @@ function buildAppContextBlock(
|
|
|
140
142
|
const contextLines = [
|
|
141
143
|
"__setCompileContext({",
|
|
142
144
|
` buildId: ${JSON.stringify(app.buildId ?? "")},`,
|
|
145
|
+
` clientLogging: ${JSON.stringify(app.clientLogging ?? false)},`,
|
|
143
146
|
` prefix: ${JSON.stringify(app.prefix ?? "")},`,
|
|
144
147
|
` rootPath: ${JSON.stringify(app.rootPath.replace(/\\/g, "/"))},`,
|
|
145
148
|
rootConventionsLine,
|
package/src/build/hydrate.ts
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
2
2
|
import { join } from "node:path";
|
|
3
3
|
import { generateIndexHtml } from "../server/render/shell.ts";
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
import {
|
|
5
|
+
buildRouteRegex,
|
|
6
|
+
compareRouteSpecificity,
|
|
7
|
+
} from "../server/router/patterns.ts";
|
|
8
|
+
import { mergeRouteSchemas } from "../server/router/schema-merge.ts";
|
|
9
|
+
import type { ResolvedRoute } from "../server/router/types.ts";
|
|
7
10
|
import { collectSearchDefaults } from "../shared/search-params.ts";
|
|
8
11
|
import { writeRouteTypes } from "./route-types";
|
|
9
12
|
import type { BuildClientOptions } from "./types";
|
|
@@ -43,10 +46,16 @@ export function generateHydrateEntry(
|
|
|
43
46
|
|
|
44
47
|
const routeEntries: string[] = [];
|
|
45
48
|
|
|
46
|
-
|
|
49
|
+
const clientRoutes = [...routes].sort((a, b) =>
|
|
50
|
+
compareRouteSpecificity(b.pattern, a.pattern),
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
for (const route of clientRoutes) {
|
|
47
54
|
const resolvedPage = route.path.replace(/\\/g, "/");
|
|
48
55
|
const regexPattern = buildRouteRegex(route.pattern).regex.source;
|
|
49
|
-
const searchDefaults = collectSearchDefaults(
|
|
56
|
+
const searchDefaults = collectSearchDefaults(
|
|
57
|
+
mergeRouteSchemas(route.routeChain ?? [], "query")
|
|
58
|
+
);
|
|
50
59
|
const boundaryIdents = new Map<string, string>();
|
|
51
60
|
|
|
52
61
|
// Emit one boundary literal per segment that actually carries a convention
|
|
@@ -77,7 +86,9 @@ export function generateHydrateEntry(
|
|
|
77
86
|
boundaryLiterals.length > 0
|
|
78
87
|
? `Promise.all([${lazyImports.join(", ")}]).then(([__furin_page, ${[
|
|
79
88
|
...boundaryIdents.values(),
|
|
80
|
-
].join(
|
|
89
|
+
].join(
|
|
90
|
+
", "
|
|
91
|
+
)}]) => ({ default: __furin_page.default, segmentBoundaries: [${boundaryLiterals.join(", ")}] }))`
|
|
81
92
|
: `import("${resolvedPage}")`;
|
|
82
93
|
|
|
83
94
|
const searchDefaultsEntry = searchDefaults
|
|
@@ -121,7 +132,7 @@ export function generateHydrateEntry(
|
|
|
121
132
|
return `import { hydrateRoot, createRoot } from "react-dom/client";
|
|
122
133
|
import { createElement } from "react";
|
|
123
134
|
${loggingImports}import { RouterProvider } from "@teyik0/furin/link";
|
|
124
|
-
import { fromCrossJSON } from "@teyik0/furin/link";
|
|
135
|
+
import { fromCrossJSON, parseDeferredNdjson } from "@teyik0/furin/link";
|
|
125
136
|
import type { SerovalNode } from "seroval";
|
|
126
137
|
import { route as root } from "${rootLayout.replace(/\\/g, "/")}";
|
|
127
138
|
|
|
@@ -142,7 +153,7 @@ const _match = routes.find((r) => r.regex.test(pathname));
|
|
|
142
153
|
// a matched loader threw notFound(). The latter still has a _match; the
|
|
143
154
|
// former does not — so the two cases fork on _match below.
|
|
144
155
|
const dataEl = document.getElementById("__FURIN_DATA__");
|
|
145
|
-
|
|
156
|
+
let loaderData = dataEl ? JSON.parse(dataEl.textContent || "{}") : {};
|
|
146
157
|
const syncEl = document.getElementById("__FURIN_SYNC__");
|
|
147
158
|
const syncConfig = syncEl ? JSON.parse(syncEl.textContent || "{}") : {};
|
|
148
159
|
const syncStream = typeof syncConfig.stream === "string" ? syncConfig.stream : undefined;
|
|
@@ -166,6 +177,9 @@ interface FurinDeferredRegistry {
|
|
|
166
177
|
reject: (key: string, chunk: SerovalNode) => void;
|
|
167
178
|
resolve: (key: string, chunk: SerovalNode) => void;
|
|
168
179
|
}
|
|
180
|
+
interface FurinRouteFrameStream {
|
|
181
|
+
stream: (initial: string) => ReadableStream<Uint8Array>;
|
|
182
|
+
}
|
|
169
183
|
const __deferred = (window as unknown as { __FURIN_DEFERRED__?: FurinDeferredRegistry })
|
|
170
184
|
.__FURIN_DEFERRED__;
|
|
171
185
|
const deferredData: Record<string, Promise<unknown>> = {};
|
|
@@ -217,6 +231,17 @@ const rootEl = document.getElementById("root") as HTMLElement;
|
|
|
217
231
|
// Wrapped in an async IIFE to avoid top-level await, which causes Bun's HTML
|
|
218
232
|
// bundler to misidentify which chunk to reference as the entry in index.html.
|
|
219
233
|
(async () => {
|
|
234
|
+
const frameTemplate = document.getElementById("__FURIN_ROUTE_FRAMES__") as HTMLTemplateElement | null;
|
|
235
|
+
if (frameTemplate) {
|
|
236
|
+
const payload = frameTemplate.content.textContent || "";
|
|
237
|
+
const routeFrameStream = (window as unknown as { __FURIN_ROUTE_FRAME_STREAM__?: FurinRouteFrameStream })
|
|
238
|
+
.__FURIN_ROUTE_FRAME_STREAM__;
|
|
239
|
+
const parsed = await parseDeferredNdjson(
|
|
240
|
+
routeFrameStream ? routeFrameStream.stream(payload) : new Blob([payload]).stream(),
|
|
241
|
+
undefined
|
|
242
|
+
);
|
|
243
|
+
loaderData = { ...parsed.syncData, ...parsed.deferredPromises };
|
|
244
|
+
}
|
|
220
245
|
let app;
|
|
221
246
|
if (_match) {
|
|
222
247
|
const _mod = await _match.load();
|
package/src/build/index.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
// biome-ignore-all lint/performance/noAwaitInLoops: build phases run in sequence because later phases consume prior artifacts
|
|
1
2
|
import { existsSync, writeFileSync } from "node:fs";
|
|
2
3
|
import { join, relative, resolve } from "node:path";
|
|
3
4
|
import { buildBunTarget, type BunTargetApp } from "../adapter/bun";
|
|
4
5
|
import { buildPackageTarget } from "../adapter/package";
|
|
5
6
|
import { buildStaticTarget } from "../adapter/static";
|
|
6
7
|
import { BUILD_TARGETS, type BuildTarget, type FurinPlugin } from "../config";
|
|
8
|
+
import { isomorphicTransformPlugin } from "../plugin/transform-isomorphic.ts";
|
|
7
9
|
import { normalizePrefix } from "../server/instance.ts";
|
|
8
10
|
import { scanPages } from "../server/router/index.ts";
|
|
9
11
|
import { assertNoPrefixSlugCollisions } from "../shared/prefix.ts";
|
|
@@ -29,6 +31,15 @@ export type {
|
|
|
29
31
|
// alternative packaging of ONE app, not an additional deploy target.
|
|
30
32
|
const IMPLEMENTED_TARGETS = ["bun", "static"] as const satisfies BuildTarget[];
|
|
31
33
|
export const BUILD_OUTPUT_DIR = ".furin/build";
|
|
34
|
+
let isomorphicRuntimePluginRegistered = false;
|
|
35
|
+
|
|
36
|
+
function registerIsomorphicRuntimePlugin(): void {
|
|
37
|
+
if (isomorphicRuntimePluginRegistered) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
Bun.plugin(isomorphicTransformPlugin("server"));
|
|
41
|
+
isomorphicRuntimePluginRegistered = true;
|
|
42
|
+
}
|
|
32
43
|
|
|
33
44
|
/**
|
|
34
45
|
* Resolves the list of apps to build, in priority order:
|
|
@@ -109,6 +120,7 @@ export async function buildApp(options: BuildAppOptions): Promise<BuildAppResult
|
|
|
109
120
|
console.debug("[furin] Skipped plugin at runtime:", err);
|
|
110
121
|
}
|
|
111
122
|
}
|
|
123
|
+
registerIsomorphicRuntimePlugin();
|
|
112
124
|
|
|
113
125
|
const appSpecs = resolveAppSpecs(options, serverEntry, rootDir);
|
|
114
126
|
const duplicatePrefix = appSpecs.find(
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { resolve } from "node:path";
|
|
2
|
+
|
|
3
|
+
const INSTRUMENTATION_IMPORT = /(?:^|[/\\])devtools[/\\]instrumentation(?:\.ts|\.js)?$/;
|
|
4
|
+
|
|
5
|
+
export function productionInstrumentationPlugin(): Bun.BunPlugin {
|
|
6
|
+
return {
|
|
7
|
+
name: "furin-production-instrumentation",
|
|
8
|
+
setup(build) {
|
|
9
|
+
build.onResolve({ filter: INSTRUMENTATION_IMPORT }, () => ({
|
|
10
|
+
path: resolve(import.meta.dir, "../server/devtools/instrumentation.production.ts"),
|
|
11
|
+
}));
|
|
12
|
+
},
|
|
13
|
+
};
|
|
14
|
+
}
|
package/src/build/route-types.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
|
2
2
|
import { join } from "node:path";
|
|
3
|
-
import { mergeRouteSchemas
|
|
3
|
+
import { mergeRouteSchemas } from "../server/router/schema-merge.ts";
|
|
4
|
+
import type { ResolvedRoute } from "../server/router/types.ts";
|
|
4
5
|
|
|
5
6
|
/** @internal Exported for unit testing only. */
|
|
6
7
|
export function patternToTypeString(pattern: string): string {
|
|
@@ -29,7 +30,9 @@ function schemaToTypeStringWithDefaults(schema: unknown, defaultsAreRequired: bo
|
|
|
29
30
|
const parts: string[] = [];
|
|
30
31
|
for (const item of s.anyOf as unknown[]) {
|
|
31
32
|
const t = schemaToTypeStringWithDefaults(item, defaultsAreRequired);
|
|
32
|
-
if (t !== "null")
|
|
33
|
+
if (t !== "null") {
|
|
34
|
+
parts.push(t);
|
|
35
|
+
}
|
|
33
36
|
}
|
|
34
37
|
return parts.join(" | ") || "unknown";
|
|
35
38
|
}
|
|
@@ -54,8 +57,7 @@ function schemaToTypeStringWithDefaults(schema: unknown, defaultsAreRequired: bo
|
|
|
54
57
|
const required = new Set<string>(Array.isArray(s.required) ? (s.required as string[]) : []);
|
|
55
58
|
const props = Object.entries(s.properties as Record<string, unknown>)
|
|
56
59
|
.map(([k, v]) => {
|
|
57
|
-
const isPresent =
|
|
58
|
-
required.has(k) || (defaultsAreRequired && hasNonNullSchemaDefault(v));
|
|
60
|
+
const isPresent = required.has(k) || (defaultsAreRequired && hasNonNullSchemaDefault(v));
|
|
59
61
|
return `${k}${isPresent ? "" : "?"}: ${schemaToTypeStringWithDefaults(v, defaultsAreRequired)}`;
|
|
60
62
|
})
|
|
61
63
|
.join("; ");
|
|
@@ -76,10 +78,7 @@ function hasNonNullSchemaDefault(schema: unknown): boolean {
|
|
|
76
78
|
return false;
|
|
77
79
|
}
|
|
78
80
|
const s = schema as Record<string, unknown>;
|
|
79
|
-
return
|
|
80
|
-
"default" in s &&
|
|
81
|
-
s.default != null
|
|
82
|
-
);
|
|
81
|
+
return "default" in s && s.default !== null;
|
|
83
82
|
}
|
|
84
83
|
|
|
85
84
|
function tagKeyToPropertyName(tag: string): string {
|
package/src/build/scan-server.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { readFileSync } from "node:fs";
|
|
2
|
-
import {
|
|
2
|
+
import type { CallExpression, ObjectExpression, ObjectProperty } from "@yuku-toolchain/types";
|
|
3
3
|
import { normalizePrefix } from "../server/instance.ts";
|
|
4
4
|
import { detectLangFromPath, unwrapTSExpression } from "../server/lang-detect.ts";
|
|
5
5
|
import { walkAST } from "../shared/utils/ast-walk.ts";
|
|
6
|
+
import { parseSource } from "../shared/parser.ts";
|
|
6
7
|
|
|
7
8
|
export interface ScannedFurinInstance {
|
|
8
9
|
pagesDir: string;
|
|
@@ -27,7 +28,7 @@ export function scanFurinInstances(serverEntryPath: string): ScannedFurinInstanc
|
|
|
27
28
|
return [];
|
|
28
29
|
}
|
|
29
30
|
|
|
30
|
-
const { program, diagnostics } =
|
|
31
|
+
const { program, diagnostics } = parseSource(code, lang);
|
|
31
32
|
const firstError = diagnostics.find((d) => d.severity === "error");
|
|
32
33
|
if (firstError) {
|
|
33
34
|
console.error("[furin] scan-server: parse error:", firstError.message, "in", serverEntryPath);
|
package/src/build/ssg-cache.ts
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
|
+
// biome-ignore-all lint/performance/noAwaitInLoops: SSG cache generation runs routes sequentially for deterministic cache output
|
|
1
2
|
import type { SsgCacheEntry } from "../server/cache/index.ts";
|
|
2
|
-
import { prerenderSSG } from "../server/render/index.ts";
|
|
3
|
-
import { createSearchRouteMetadata, type ResolvedRoute, type RootLayout } from "../server/router/index.ts";
|
|
4
3
|
import { resolvePath } from "../server/render/assemble.ts";
|
|
4
|
+
import { prerenderSSG } from "../server/render/index.ts";
|
|
5
|
+
import {
|
|
6
|
+
createSearchRouteMetadata,
|
|
7
|
+
type ResolvedRoute,
|
|
8
|
+
type RootLayout,
|
|
9
|
+
} from "../server/router/index.ts";
|
|
5
10
|
|
|
6
11
|
export type SSGCacheSnapshot = Record<string, SsgCacheEntry>;
|
|
7
12
|
|
package/src/build/types.ts
CHANGED
package/src/cli/index.ts
CHANGED
|
@@ -8,7 +8,7 @@ import { normalizePrefix } from "../server/instance.ts";
|
|
|
8
8
|
import { loadCliConfig } from "./config.ts";
|
|
9
9
|
|
|
10
10
|
const argv = process.argv.slice(2);
|
|
11
|
-
const command = argv
|
|
11
|
+
const [command] = argv;
|
|
12
12
|
|
|
13
13
|
function log(msg: string): void {
|
|
14
14
|
console.log(`\x1b[32m◆\x1b[0m ${msg}`);
|
|
@@ -35,17 +35,59 @@ function resolveCompileMode(
|
|
|
35
35
|
return configCompile;
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
+
function extractCompileFlag(args: string[]): {
|
|
39
|
+
compileFlag: string | boolean | undefined;
|
|
40
|
+
parseableArgs: string[];
|
|
41
|
+
} {
|
|
42
|
+
const parseableArgs: string[] = [];
|
|
43
|
+
let compileFlag: string | boolean | undefined;
|
|
44
|
+
|
|
45
|
+
for (let index = 0; index < args.length; index += 1) {
|
|
46
|
+
const arg = args[index];
|
|
47
|
+
if (arg === "--") {
|
|
48
|
+
parseableArgs.push(...args.slice(index));
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
51
|
+
if (arg === "--compile") {
|
|
52
|
+
const next = args[index + 1];
|
|
53
|
+
if (next && !next.startsWith("-")) {
|
|
54
|
+
compileFlag = next;
|
|
55
|
+
index += 1;
|
|
56
|
+
} else {
|
|
57
|
+
compileFlag = true;
|
|
58
|
+
}
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
if (arg?.startsWith("--compile=")) {
|
|
62
|
+
compileFlag = arg.slice("--compile=".length);
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
if (arg) {
|
|
66
|
+
parseableArgs.push(arg);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return { compileFlag, parseableArgs };
|
|
71
|
+
}
|
|
72
|
+
|
|
38
73
|
if (command === "build") {
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
74
|
+
const buildArgv = argv.slice(1);
|
|
75
|
+
const { compileFlag, parseableArgs } = extractCompileFlag(buildArgv);
|
|
76
|
+
let rawValues: ReturnType<typeof parseArgs>["values"];
|
|
77
|
+
try {
|
|
78
|
+
rawValues = parseArgs({
|
|
79
|
+
args: parseableArgs,
|
|
80
|
+
options: {
|
|
81
|
+
target: { type: "string" },
|
|
82
|
+
pagesDir: { type: "string" },
|
|
83
|
+
prefix: { type: "string" },
|
|
84
|
+
config: { type: "string" },
|
|
85
|
+
},
|
|
86
|
+
strict: true,
|
|
87
|
+
}).values;
|
|
88
|
+
} catch (error) {
|
|
89
|
+
bail(error instanceof Error ? error.message : String(error));
|
|
90
|
+
}
|
|
49
91
|
|
|
50
92
|
const values = rawValues as {
|
|
51
93
|
target?: string;
|
|
@@ -54,17 +96,6 @@ if (command === "build") {
|
|
|
54
96
|
config?: string;
|
|
55
97
|
};
|
|
56
98
|
|
|
57
|
-
// --compile has an optional value: absent → undefined, present alone → true, present with "embed" → "embed"
|
|
58
|
-
const buildArgv = argv.slice(1);
|
|
59
|
-
const compileIdx = buildArgv.indexOf("--compile");
|
|
60
|
-
let compileFlag: string | boolean | undefined;
|
|
61
|
-
if (compileIdx < 0) {
|
|
62
|
-
compileFlag = undefined;
|
|
63
|
-
} else {
|
|
64
|
-
const next = buildArgv[compileIdx + 1];
|
|
65
|
-
compileFlag = next && !next.startsWith("-") ? next : true;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
99
|
const target = values.target ?? "bun";
|
|
69
100
|
|
|
70
101
|
if (target !== "all" && !(BUILD_TARGETS as readonly string[]).includes(target)) {
|
|
@@ -17,6 +17,28 @@ const SERVER_RESET_NOOP = () => {
|
|
|
17
17
|
/* reset is a client-only action; on the server the response is already committed */
|
|
18
18
|
};
|
|
19
19
|
|
|
20
|
+
function getServerDigest(error: unknown): string | undefined {
|
|
21
|
+
if (isFurinServerError(error)) {
|
|
22
|
+
return error.digest;
|
|
23
|
+
}
|
|
24
|
+
if ((typeof error !== "object" && typeof error !== "function") || error === null) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
const digest = (error as Error & { __furinDigest?: unknown }).__furinDigest;
|
|
28
|
+
return typeof digest === "string" ? digest : undefined;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function normalizeCaughtError(error: unknown): Error {
|
|
32
|
+
if (error instanceof Error) {
|
|
33
|
+
return error;
|
|
34
|
+
}
|
|
35
|
+
const normalized = new Error(String(error));
|
|
36
|
+
if ((typeof error === "object" && error !== null) || typeof error === "function") {
|
|
37
|
+
Object.defineProperties(normalized, Object.getOwnPropertyDescriptors(error));
|
|
38
|
+
}
|
|
39
|
+
return normalized;
|
|
40
|
+
}
|
|
41
|
+
|
|
20
42
|
interface ErrorBoundaryProps {
|
|
21
43
|
children: ReactNode;
|
|
22
44
|
/**
|
|
@@ -46,9 +68,9 @@ interface ErrorBoundaryProps {
|
|
|
46
68
|
|
|
47
69
|
interface ErrorBoundaryState {
|
|
48
70
|
/**
|
|
49
|
-
* Digest
|
|
50
|
-
* each distinct caught error gets its own ID,
|
|
51
|
-
* inheriting the server-provided `digest` prop.
|
|
71
|
+
* Digest preserved from a server error or computed when the error was
|
|
72
|
+
* latched. Stored in state so each distinct caught error gets its own ID,
|
|
73
|
+
* instead of all of them inheriting the server-provided `digest` prop.
|
|
52
74
|
*/
|
|
53
75
|
digest: string | null;
|
|
54
76
|
/** Unmount/remount counter — bumped on reset to force React to discard
|
|
@@ -73,11 +95,14 @@ export class FurinErrorBoundary extends Component<ErrorBoundaryProps, ErrorBound
|
|
|
73
95
|
error: null,
|
|
74
96
|
};
|
|
75
97
|
|
|
76
|
-
static getDerivedStateFromError(error:
|
|
77
|
-
//
|
|
78
|
-
//
|
|
79
|
-
//
|
|
80
|
-
return {
|
|
98
|
+
static getDerivedStateFromError(error: unknown): Partial<ErrorBoundaryState> {
|
|
99
|
+
// Preserve server digests carried by SPA error sentinels or deferred
|
|
100
|
+
// rejections. Otherwise compute one right at catch-time so the value is
|
|
101
|
+
// anchored to this specific error instance across re-renders.
|
|
102
|
+
return {
|
|
103
|
+
digest: getServerDigest(error) ?? computeErrorDigest(error),
|
|
104
|
+
error: normalizeCaughtError(error),
|
|
105
|
+
};
|
|
81
106
|
}
|
|
82
107
|
|
|
83
108
|
override componentDidUpdate(prevProps: ErrorBoundaryProps) {
|
|
@@ -109,18 +134,17 @@ export class FurinErrorBoundary extends Component<ErrorBoundaryProps, ErrorBound
|
|
|
109
134
|
}
|
|
110
135
|
const Fallback = this.props.fallback ?? DefaultErrorFallback;
|
|
111
136
|
// Digest precedence:
|
|
112
|
-
// 1.
|
|
113
|
-
//
|
|
114
|
-
//
|
|
115
|
-
//
|
|
116
|
-
//
|
|
117
|
-
// ACTUAL caught error.
|
|
137
|
+
// 1. A server digest — carried by an SPA error sentinel or serialized
|
|
138
|
+
// deferred rejection so logs correlate without recomputing a
|
|
139
|
+
// different hash from a sanitized error and synthetic stack.
|
|
140
|
+
// 2. state.digest — preserved or computed at catch time for the
|
|
141
|
+
// actual caught error.
|
|
118
142
|
// 3. props.digest — the server-rendered digest, only meaningful for
|
|
119
143
|
// the very first error post-hydration; we still honour it as a
|
|
120
144
|
// last-resort fallback in case state.digest is somehow missing
|
|
121
145
|
// (e.g. tests that inject state by hand).
|
|
122
146
|
// 4. recompute on the spot — defensive, should never be reached.
|
|
123
|
-
const serverDigest =
|
|
147
|
+
const serverDigest = getServerDigest(error);
|
|
124
148
|
const finalDigest = serverDigest ?? digest ?? this.props.digest ?? computeErrorDigest(error);
|
|
125
149
|
const message = this.props.fallback ? error.message : getPublicErrorMessage(error);
|
|
126
150
|
// Status precedence: FurinServerError carries the original Response.status
|
|
@@ -129,7 +153,7 @@ export class FurinErrorBoundary extends Component<ErrorBoundaryProps, ErrorBound
|
|
|
129
153
|
const status = isFurinServerError(error) ? error.status : DEFAULT_ERROR_STATUS;
|
|
130
154
|
return (
|
|
131
155
|
<Fallback
|
|
132
|
-
error={{
|
|
156
|
+
error={{ digest: finalDigest, message, status }}
|
|
133
157
|
reset={typeof window === "undefined" ? SERVER_RESET_NOOP : this.reset}
|
|
134
158
|
/>
|
|
135
159
|
);
|
|
@@ -168,7 +192,7 @@ export class FurinNotFoundBoundary extends Component<NotFoundBoundaryProps, NotF
|
|
|
168
192
|
|
|
169
193
|
override componentDidUpdate(prevProps: NotFoundBoundaryProps) {
|
|
170
194
|
if (prevProps.resetKey !== this.props.resetKey && this.state.error) {
|
|
171
|
-
this.setState((s) => ({
|
|
195
|
+
this.setState((s) => ({ epoch: s.epoch + 1, error: null }));
|
|
172
196
|
}
|
|
173
197
|
}
|
|
174
198
|
|
|
@@ -179,7 +203,7 @@ export class FurinNotFoundBoundary extends Component<NotFoundBoundaryProps, NotF
|
|
|
179
203
|
throw error;
|
|
180
204
|
}
|
|
181
205
|
const Fallback = this.props.fallback ?? DefaultNotFoundFallback;
|
|
182
|
-
return <Fallback error={{
|
|
206
|
+
return <Fallback error={{ data: error.data, message: error.message }} />;
|
|
183
207
|
}
|
|
184
208
|
return <Fragment key={epoch}>{this.props.children}</Fragment>;
|
|
185
209
|
}
|
|
@@ -147,22 +147,22 @@ const ACTIONS_STYLE: CSSProperties = {
|
|
|
147
147
|
};
|
|
148
148
|
|
|
149
149
|
const BUTTON_BASE: CSSProperties = {
|
|
150
|
+
alignItems: "center",
|
|
151
|
+
appearance: "none",
|
|
150
152
|
border: 0,
|
|
153
|
+
boxSizing: "border-box",
|
|
151
154
|
cursor: "pointer",
|
|
152
155
|
display: "inline-flex",
|
|
153
156
|
fontFamily: FONT_SANS,
|
|
154
157
|
fontSize: "14px",
|
|
155
158
|
fontWeight: 500,
|
|
159
|
+
justifyContent: "center",
|
|
156
160
|
lineHeight: 1,
|
|
157
161
|
minWidth: "120px",
|
|
158
162
|
padding: "10px 16px",
|
|
159
163
|
textAlign: "center",
|
|
160
164
|
textDecoration: "none",
|
|
161
165
|
transition: "background-color 120ms ease, color 120ms ease, opacity 120ms ease",
|
|
162
|
-
appearance: "none",
|
|
163
|
-
alignItems: "center",
|
|
164
|
-
justifyContent: "center",
|
|
165
|
-
boxSizing: "border-box",
|
|
166
166
|
};
|
|
167
167
|
|
|
168
168
|
// Outlined buttons: thin neutral border, no fill — discreet enough to blend
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type React from "react";
|
|
2
|
+
import type { HeadOptions, RenderingMode, RequestLoaderContext } from "../../client.ts";
|
|
3
|
+
|
|
4
|
+
export type RuntimeData = Record<string, unknown>;
|
|
5
|
+
|
|
6
|
+
type Awaitable<T> = Promise<T> | T;
|
|
7
|
+
|
|
8
|
+
export interface RuntimeRoute {
|
|
9
|
+
__type: "FURIN_ROUTE";
|
|
10
|
+
layout?: React.FC<RuntimeData & { children: React.ReactNode }>;
|
|
11
|
+
loader?: (ctx: RuntimeData) => Awaitable<RuntimeData>;
|
|
12
|
+
mode?: RenderingMode;
|
|
13
|
+
params?: unknown;
|
|
14
|
+
parent?: RuntimeRoute;
|
|
15
|
+
query?: unknown;
|
|
16
|
+
requestLoader?: (ctx: RequestLoaderContext) => Awaitable<object>;
|
|
17
|
+
revalidate?: number;
|
|
18
|
+
tags?: string[];
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface RuntimePage {
|
|
22
|
+
__type: "FURIN_PAGE";
|
|
23
|
+
_route: RuntimeRoute;
|
|
24
|
+
component: React.FC<RuntimeData>;
|
|
25
|
+
head?: (ctx: RuntimeData) => HeadOptions;
|
|
26
|
+
loader?: (ctx: RuntimeData) => Awaitable<RuntimeData>;
|
|
27
|
+
mode?: RenderingMode;
|
|
28
|
+
revalidate?: number;
|
|
29
|
+
staticParams?: () => Awaitable<Record<string, string>[]>;
|
|
30
|
+
tags?: string[];
|
|
31
|
+
}
|