@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/hydrate.ts
CHANGED
|
@@ -45,6 +45,7 @@ export function generateHydrateEntry(
|
|
|
45
45
|
};
|
|
46
46
|
|
|
47
47
|
const routeEntries: string[] = [];
|
|
48
|
+
const activeHotComponentKeys = new Set<string>();
|
|
48
49
|
|
|
49
50
|
const clientRoutes = [...routes].sort((a, b) =>
|
|
50
51
|
compareRouteSpecificity(b.pattern, a.pattern),
|
|
@@ -57,6 +58,15 @@ export function generateHydrateEntry(
|
|
|
57
58
|
mergeRouteSchemas(route.routeChain ?? [], "query")
|
|
58
59
|
);
|
|
59
60
|
const boundaryIdents = new Map<string, string>();
|
|
61
|
+
const layoutPaths = (route.routeChain ?? [])
|
|
62
|
+
.slice(1)
|
|
63
|
+
.filter((entry) => entry.layout && entry.sourcePath)
|
|
64
|
+
.map((entry) => entry.sourcePath as string);
|
|
65
|
+
activeHotComponentKeys.add(`page:${resolvedPage}`);
|
|
66
|
+
for (const layoutPath of layoutPaths) {
|
|
67
|
+
activeHotComponentKeys.add(`layout:${layoutPath.replace(/\\/g, "/")}`);
|
|
68
|
+
}
|
|
69
|
+
const layoutIdents = layoutPaths.map((_, index) => `__furin_layout_${index}`);
|
|
60
70
|
|
|
61
71
|
// Emit one boundary literal per segment that actually carries a convention
|
|
62
72
|
// file — segments that only declare one of the two are emitted with the
|
|
@@ -80,16 +90,23 @@ export function generateHydrateEntry(
|
|
|
80
90
|
|
|
81
91
|
const lazyImports = [
|
|
82
92
|
`import("${resolvedPage}")`,
|
|
93
|
+
...layoutPaths.map((filePath) => `import("${filePath.replace(/\\/g, "/")}")`),
|
|
83
94
|
...[...boundaryIdents.keys()].map((filePath) => `import("${filePath.replace(/\\/g, "/")}")`),
|
|
84
95
|
];
|
|
85
|
-
const
|
|
96
|
+
const importIdents = ["__furin_page", ...layoutIdents, ...boundaryIdents.values()];
|
|
97
|
+
const layoutAssignments = layoutPaths
|
|
98
|
+
.map((filePath, index) => {
|
|
99
|
+
const ident = layoutIdents[index];
|
|
100
|
+
const componentKey = JSON.stringify(`layout:${filePath.replace(/\\/g, "/")}`);
|
|
101
|
+
return `const __furin_layout_route_${index} = ${ident}.route; __furin_parent = { __type: "FURIN_ROUTE", layout: hotComponent(${componentKey}, __furin_layout_route_${index}.component), parent: __furin_parent };`;
|
|
102
|
+
})
|
|
103
|
+
.join(" ");
|
|
104
|
+
const boundaryResult =
|
|
86
105
|
boundaryLiterals.length > 0
|
|
87
|
-
?
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
)}]) => ({ default: __furin_page.default, segmentBoundaries: [${boundaryLiterals.join(", ")}] }))`
|
|
92
|
-
: `import("${resolvedPage}")`;
|
|
106
|
+
? `, segmentBoundaries: [${boundaryLiterals.join(", ")}]`
|
|
107
|
+
: "";
|
|
108
|
+
const pageComponentKey = JSON.stringify(`page:${resolvedPage}`);
|
|
109
|
+
const loadBody = `Promise.all([${lazyImports.join(", ")}]).then(([${importIdents.join(", ")}]) => { const __furin_page_route = __furin_page.route; let __furin_parent = root; ${layoutAssignments} return { default: { __type: "FURIN_PAGE", _route: { __type: "FURIN_ROUTE", parent: __furin_parent }, component: hotComponent(${pageComponentKey}, __furin_page_route.component) }${boundaryResult} }; })`;
|
|
93
110
|
|
|
94
111
|
const searchDefaultsEntry = searchDefaults
|
|
95
112
|
? `, searchDefaults: ${JSON.stringify(searchDefaults)}`
|
|
@@ -127,17 +144,53 @@ export function generateHydrateEntry(
|
|
|
127
144
|
: "const log = { error() {}, info() {} };";
|
|
128
145
|
|
|
129
146
|
// RouterProvider receives basePath so navigate() / Link push physical paths.
|
|
130
|
-
const routerProviderDefaults = `\n autoRefresh: true,\n basePath: ${basePathLiteral},\n defaultPreload: "intent",\n defaultPreloadDelay: 50,\n defaultPreloadStaleTime: 30000,\n prefetchCacheSize: 50,\n
|
|
147
|
+
const routerProviderDefaults = `\n autoRefresh: true,\n basePath: ${basePathLiteral},\n defaultPreload: "intent",\n defaultPreloadDelay: 50,\n defaultPreloadStaleTime: 30000,\n prefetchCacheSize: 50,\n syncPath,`;
|
|
148
|
+
|
|
149
|
+
const resolvedRootLayout = rootLayout.replace(/\\/g, "/");
|
|
150
|
+
const rootComponentKey = JSON.stringify(`root:${resolvedRootLayout}`);
|
|
151
|
+
activeHotComponentKeys.add(`root:${resolvedRootLayout}`);
|
|
152
|
+
const activeHotComponentKeysLiteral = JSON.stringify([...activeHotComponentKeys]);
|
|
131
153
|
|
|
132
|
-
return `import { hydrateRoot
|
|
133
|
-
import { createElement } from "react";
|
|
134
|
-
${loggingImports}import {
|
|
154
|
+
return `import { hydrateRoot } from "react-dom/client";
|
|
155
|
+
import { createElement, type ReactNode } from "react";
|
|
156
|
+
${loggingImports}import { DocumentProvider, type DocumentState, type HotComponentRegistry, reconcileHotComponentRegistry, updateHotComponent } from "@teyik0/furin/client";
|
|
157
|
+
import { RouterProvider } from "@teyik0/furin/link";
|
|
135
158
|
import { fromCrossJSON, parseDeferredNdjson } from "@teyik0/furin/link";
|
|
136
159
|
import type { SerovalNode } from "seroval";
|
|
137
|
-
import { route as
|
|
160
|
+
import { route as __furin_root_route } from "${resolvedRootLayout}";
|
|
138
161
|
|
|
139
162
|
${loggerSetup}
|
|
140
163
|
|
|
164
|
+
if (import.meta.hot) {
|
|
165
|
+
const connectionState = ((window as unknown as {
|
|
166
|
+
__FURIN_HMR_CONNECTION__?: { disconnected: boolean; installed: boolean };
|
|
167
|
+
}).__FURIN_HMR_CONNECTION__ ??= { disconnected: false, installed: false });
|
|
168
|
+
if (!connectionState.installed) {
|
|
169
|
+
import.meta.hot.on("bun:ws:disconnect", () => {
|
|
170
|
+
connectionState.disconnected = true;
|
|
171
|
+
});
|
|
172
|
+
import.meta.hot.on("bun:ws:connect", () => {
|
|
173
|
+
if (connectionState.disconnected) {
|
|
174
|
+
window.location.reload();
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
connectionState.installed = true;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
const hotComponentRegistry = ((window as unknown as {
|
|
182
|
+
__FURIN_HOT_COMPONENTS__?: HotComponentRegistry;
|
|
183
|
+
}).__FURIN_HOT_COMPONENTS__ ??= new Map());
|
|
184
|
+
reconcileHotComponentRegistry(hotComponentRegistry, new Set(${activeHotComponentKeysLiteral}));
|
|
185
|
+
const hotComponent = <Props,>(key: string, component: (props: Props) => ReactNode) =>
|
|
186
|
+
import.meta.hot ? updateHotComponent(hotComponentRegistry, key, component) : component;
|
|
187
|
+
const __furin_root_component = hotComponent(${rootComponentKey}, __furin_root_route.component);
|
|
188
|
+
const root = {
|
|
189
|
+
...__furin_root_route,
|
|
190
|
+
component: __furin_root_component,
|
|
191
|
+
layout: __furin_root_component,
|
|
192
|
+
};
|
|
193
|
+
|
|
141
194
|
const routes = [
|
|
142
195
|
${routeEntries.join(",\n")}
|
|
143
196
|
];
|
|
@@ -156,7 +209,30 @@ const dataEl = document.getElementById("__FURIN_DATA__");
|
|
|
156
209
|
let loaderData = dataEl ? JSON.parse(dataEl.textContent || "{}") : {};
|
|
157
210
|
const syncEl = document.getElementById("__FURIN_SYNC__");
|
|
158
211
|
const syncConfig = syncEl ? JSON.parse(syncEl.textContent || "{}") : {};
|
|
159
|
-
const
|
|
212
|
+
const syncPath = typeof syncConfig.path === "string" ? syncConfig.path : undefined;
|
|
213
|
+
const headEl = document.getElementById("__FURIN_HEAD__");
|
|
214
|
+
const head = headEl ? JSON.parse(headEl.textContent || "{}") : {};
|
|
215
|
+
const entryEl = document.querySelector("script[data-furin-entry][src]") as HTMLScriptElement | null;
|
|
216
|
+
const frameworkModules = Array.from(
|
|
217
|
+
document.querySelectorAll("script[data-furin-framework-module][src]")
|
|
218
|
+
).map((script) => script.getAttribute("src") ?? "").filter(Boolean);
|
|
219
|
+
const buildId = document.querySelector('meta[name="furin-build-id"]')?.getAttribute("content") ?? undefined;
|
|
220
|
+
const faviconHref = document.querySelector('link[rel="icon"]')?.getAttribute("href") ?? undefined;
|
|
221
|
+
const documentState: DocumentState = {
|
|
222
|
+
assets: {
|
|
223
|
+
buildId,
|
|
224
|
+
entryModule: entryEl?.getAttribute("src") ?? undefined,
|
|
225
|
+
faviconHref,
|
|
226
|
+
frameworkModules,
|
|
227
|
+
staticMode: document.querySelector('meta[name="furin-mode"][content="static"]') !== null,
|
|
228
|
+
stylesheets: Array.from(document.querySelectorAll('link[rel="stylesheet"]'))
|
|
229
|
+
.map((link) => link.getAttribute("href") ?? "")
|
|
230
|
+
.filter(Boolean),
|
|
231
|
+
},
|
|
232
|
+
dataJson: dataEl?.textContent ?? undefined,
|
|
233
|
+
head,
|
|
234
|
+
syncJson: syncEl?.textContent ?? undefined,
|
|
235
|
+
};
|
|
160
236
|
|
|
161
237
|
// ── Deferred data hydration ─────────────────────────────────────────────────
|
|
162
238
|
// window.__FURIN_DEFERRED__ is injected by the server when a loader returns
|
|
@@ -224,8 +300,6 @@ if (__deferred && __deferred._chunks) {
|
|
|
224
300
|
}
|
|
225
301
|
}
|
|
226
302
|
}
|
|
227
|
-
const rootEl = document.getElementById("root") as HTMLElement;
|
|
228
|
-
|
|
229
303
|
// Eagerly load only the current page module for initial hydration.
|
|
230
304
|
// All other pages are loaded on demand when the user navigates to them.
|
|
231
305
|
// Wrapped in an async IIFE to avoid top-level await, which causes Bun's HTML
|
|
@@ -260,6 +334,7 @@ const rootEl = document.getElementById("root") as HTMLElement;
|
|
|
260
334
|
initialMatch: match,
|
|
261
335
|
initialData: { ...loaderData, ...deferredData },
|
|
262
336
|
initialDigest: loaderData.__furinError?.digest,
|
|
337
|
+
initialError: loaderData.__furinError,
|
|
263
338
|
initialNotFound: isNotFound ? (loaderData.__furinNotFound ?? loaderData) : undefined,${routerProviderDefaults}
|
|
264
339
|
} as any);
|
|
265
340
|
} else if (loaderData.__furinStatus === 404) {
|
|
@@ -277,6 +352,7 @@ const rootEl = document.getElementById("root") as HTMLElement;
|
|
|
277
352
|
initialMatch: null,
|
|
278
353
|
initialData: cleanData,
|
|
279
354
|
initialDigest: loaderData.__furinError?.digest,
|
|
355
|
+
initialError: loaderData.__furinError,
|
|
280
356
|
initialNotFound: loaderData.__furinNotFound ?? {},${routerProviderDefaults}
|
|
281
357
|
} as any);
|
|
282
358
|
} else {
|
|
@@ -286,44 +362,73 @@ const rootEl = document.getElementById("root") as HTMLElement;
|
|
|
286
362
|
log.error({ action: "hydrate_no_match", pathname });
|
|
287
363
|
return;
|
|
288
364
|
}
|
|
365
|
+
app = createElement(DocumentProvider, { value: documentState }, app);
|
|
289
366
|
|
|
290
367
|
if (import.meta.hot) {
|
|
291
368
|
// Dev mode — preserve root across HMR using a window global.
|
|
292
369
|
// window is the only object that survives Bun's module re-evaluation.
|
|
293
370
|
// biome-ignore lint/suspicious/noExplicitAny: dev-only HMR global
|
|
294
371
|
const existingRoot = (window as any).__FURIN_ROOT__;
|
|
372
|
+
const hmrWindow = window as unknown as {
|
|
373
|
+
__FURIN_HMR_UPDATE__?: (
|
|
374
|
+
sourcePath: string,
|
|
375
|
+
component: (props: never) => ReactNode,
|
|
376
|
+
dataChanged: boolean
|
|
377
|
+
) => Promise<void>;
|
|
378
|
+
};
|
|
379
|
+
hmrWindow.__FURIN_HMR_UPDATE__ = async (sourcePath, component, dataChanged) => {
|
|
380
|
+
const commitComponent = () => {
|
|
381
|
+
const componentKeySuffix = ":" + sourcePath;
|
|
382
|
+
for (const key of hotComponentRegistry.keys()) {
|
|
383
|
+
if (key.endsWith(componentKeySuffix)) {
|
|
384
|
+
updateHotComponent(hotComponentRegistry, key, component);
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
};
|
|
388
|
+
const refresh = (window as unknown as {
|
|
389
|
+
__FURIN_HMR_REFRESH__?: (
|
|
390
|
+
beforeCommit: (() => void) | undefined,
|
|
391
|
+
dataChanged: boolean
|
|
392
|
+
) => Promise<void>;
|
|
393
|
+
}).__FURIN_HMR_REFRESH__;
|
|
394
|
+
if (refresh) {
|
|
395
|
+
await refresh(commitComponent, dataChanged);
|
|
396
|
+
return;
|
|
397
|
+
}
|
|
398
|
+
window.location.reload();
|
|
399
|
+
};
|
|
295
400
|
if (existingRoot) {
|
|
296
|
-
// Already mounted — reconciliation, NOT hydration. React Fast Refresh
|
|
297
|
-
// patched the component in-place, now re-render with the new module.
|
|
298
|
-
existingRoot.render(app);
|
|
299
401
|
// The initialData embedded in the DOM is stale (from the original SSR).
|
|
300
|
-
//
|
|
301
|
-
//
|
|
302
|
-
|
|
402
|
+
// Prepare fresh loader data, then publish it with the new module in the
|
|
403
|
+
// same React commit. If the router effect is not installed yet, reconcile
|
|
404
|
+
// the module directly; this branch only occurs during initial boot.
|
|
405
|
+
const hmrRefresh = (window as unknown as {
|
|
406
|
+
__FURIN_HMR_REFRESH__?: (
|
|
407
|
+
beforeCommit: (() => void) | undefined,
|
|
408
|
+
dataChanged: boolean
|
|
409
|
+
) => Promise<void>;
|
|
410
|
+
}).__FURIN_HMR_REFRESH__;
|
|
303
411
|
if (hmrRefresh) {
|
|
304
|
-
|
|
412
|
+
await hmrRefresh(() => existingRoot.render(app), true);
|
|
413
|
+
} else {
|
|
414
|
+
existingRoot.render(app);
|
|
305
415
|
}
|
|
306
|
-
} else if (rootEl.innerHTML.trim()) {
|
|
307
|
-
// First load with SSR content — hydrateRoot renders on construction
|
|
308
|
-
const root = hydrateRoot(rootEl, app);
|
|
309
|
-
// biome-ignore lint/suspicious/noExplicitAny: dev-only HMR global
|
|
310
|
-
(window as any).__FURIN_ROOT__ = root;
|
|
311
416
|
} else {
|
|
312
|
-
// First load
|
|
313
|
-
const root =
|
|
314
|
-
root.render(app);
|
|
417
|
+
// First load — the root layout owns the server-rendered document.
|
|
418
|
+
const root = hydrateRoot(document, app);
|
|
315
419
|
// biome-ignore lint/suspicious/noExplicitAny: dev-only HMR global
|
|
316
420
|
(window as any).__FURIN_ROOT__ = root;
|
|
317
421
|
}
|
|
318
|
-
} else if (rootEl.innerHTML.trim()) {
|
|
319
|
-
hydrateRoot(rootEl, app);
|
|
320
422
|
} else {
|
|
321
|
-
|
|
423
|
+
hydrateRoot(document, app);
|
|
322
424
|
}
|
|
323
425
|
|
|
324
426
|
log.info({ action: "hydrate_complete", pathname });
|
|
325
427
|
})().catch((err: unknown) => {
|
|
326
428
|
log.error({ action: "hydrate_failed", pathname, error: String(err) });
|
|
429
|
+
window.dispatchEvent(
|
|
430
|
+
new CustomEvent("furin:client-error", { detail: { error: err, phase: "hydrate" } })
|
|
431
|
+
);
|
|
327
432
|
});
|
|
328
433
|
`;
|
|
329
434
|
}
|
|
@@ -346,8 +451,10 @@ export function writeDevFiles(
|
|
|
346
451
|
const hydrateCode = generateHydrateEntry(routes, rootLayout, basePath, clientLogging);
|
|
347
452
|
const hydratePath = join(outDir, "_hydrate.tsx");
|
|
348
453
|
const existingHydrate = existsSync(hydratePath) ? readFileSync(hydratePath, "utf8") : "";
|
|
454
|
+
let changed = false;
|
|
349
455
|
if (hydrateCode !== existingHydrate) {
|
|
350
456
|
writeFileSync(hydratePath, hydrateCode);
|
|
457
|
+
changed = true;
|
|
351
458
|
}
|
|
352
459
|
|
|
353
460
|
const indexHtml = generateIndexHtml();
|
|
@@ -355,13 +462,16 @@ export function writeDevFiles(
|
|
|
355
462
|
const existingIndex = existsSync(indexPath) ? readFileSync(indexPath, "utf8") : "";
|
|
356
463
|
if (indexHtml !== existingIndex) {
|
|
357
464
|
writeFileSync(indexPath, indexHtml);
|
|
465
|
+
changed = true;
|
|
358
466
|
}
|
|
359
467
|
|
|
360
468
|
if (!skipRouteTypes) {
|
|
361
|
-
writeRouteTypes(routes, projectRoot);
|
|
469
|
+
changed = writeRouteTypes(routes, projectRoot) || changed;
|
|
362
470
|
}
|
|
363
471
|
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
472
|
+
if (changed) {
|
|
473
|
+
console.log(
|
|
474
|
+
"[furin] Dev files written (.furin/_hydrate.tsx + .furin/index.html + furin-env.d.ts)"
|
|
475
|
+
);
|
|
476
|
+
}
|
|
367
477
|
}
|
package/src/build/index.ts
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
// biome-ignore-all lint/performance/noAwaitInLoops: build phases run in sequence because later phases consume prior artifacts
|
|
2
2
|
import { existsSync, writeFileSync } from "node:fs";
|
|
3
3
|
import { join, relative, resolve } from "node:path";
|
|
4
|
-
import { buildBunTarget
|
|
4
|
+
import { buildBunTarget } from "../adapter/bun";
|
|
5
5
|
import { buildPackageTarget } from "../adapter/package";
|
|
6
|
+
import type { RuntimeTargetApp } from "../adapter/runtime-build";
|
|
6
7
|
import { buildStaticTarget } from "../adapter/static";
|
|
8
|
+
import { buildVercelTarget } from "../adapter/vercel";
|
|
7
9
|
import { BUILD_TARGETS, type BuildTarget, type FurinPlugin } from "../config";
|
|
8
10
|
import { isomorphicTransformPlugin } from "../plugin/transform-isomorphic.ts";
|
|
9
11
|
import { normalizePrefix } from "../server/instance.ts";
|
|
10
|
-
import { scanPages } from "../server/router/
|
|
12
|
+
import { scanPages } from "../server/router/discovery.ts";
|
|
11
13
|
import { assertNoPrefixSlugCollisions } from "../shared/prefix.ts";
|
|
12
14
|
import { scanFurinInstances } from "./scan-server";
|
|
13
15
|
import { ensureDir, toBuildRouteManifestEntry, toPosixPath } from "./shared";
|
|
@@ -16,7 +18,7 @@ import type { BuildAppOptions, BuildAppResult, BuildManifest } from "./types";
|
|
|
16
18
|
// biome-ignore lint/performance/noBarrelFile: intentional — build/index.ts is the public build API entry
|
|
17
19
|
export { buildClient } from "./client";
|
|
18
20
|
export { writeDevFiles } from "./hydrate";
|
|
19
|
-
export {
|
|
21
|
+
export { writeRouteTypes } from "./route-types";
|
|
20
22
|
export { buildSSGCacheSnapshot, type SSGCacheSnapshot } from "./ssg-cache";
|
|
21
23
|
export type {
|
|
22
24
|
BuildAppOptions,
|
|
@@ -25,11 +27,12 @@ export type {
|
|
|
25
27
|
BuildManifest,
|
|
26
28
|
BuildRouteManifestEntry,
|
|
27
29
|
TargetBuildManifest,
|
|
30
|
+
VercelTargetBuildManifest,
|
|
28
31
|
} from "./types";
|
|
29
32
|
|
|
30
33
|
// "package" is intentionally excluded from `--target all` — it is an
|
|
31
34
|
// alternative packaging of ONE app, not an additional deploy target.
|
|
32
|
-
const IMPLEMENTED_TARGETS = ["bun", "static"] as const satisfies BuildTarget[];
|
|
35
|
+
const IMPLEMENTED_TARGETS = ["bun", "vercel", "static"] as const satisfies BuildTarget[];
|
|
33
36
|
export const BUILD_OUTPUT_DIR = ".furin/build";
|
|
34
37
|
let isomorphicRuntimePluginRegistered = false;
|
|
35
38
|
|
|
@@ -147,13 +150,13 @@ export async function buildApp(options: BuildAppOptions): Promise<BuildAppResult
|
|
|
147
150
|
});
|
|
148
151
|
|
|
149
152
|
// scanPages throws if root.tsx is missing, so root is always defined per app.
|
|
150
|
-
const apps:
|
|
153
|
+
const apps: RuntimeTargetApp[] = [];
|
|
151
154
|
for (const spec of appSpecs) {
|
|
152
155
|
const { root, routes } = await scanPages(spec.pagesDir);
|
|
153
156
|
apps.push({ pagesDir: spec.pagesDir, prefix: spec.prefix, root, routes });
|
|
154
157
|
}
|
|
155
158
|
// The root-mounted app drives single-app manifest fields and the static target.
|
|
156
|
-
const primaryApp = (apps.find((app) => app.prefix === "") ?? apps[0]) as
|
|
159
|
+
const primaryApp = (apps.find((app) => app.prefix === "") ?? apps[0]) as RuntimeTargetApp;
|
|
157
160
|
|
|
158
161
|
ensureDir(buildRoot);
|
|
159
162
|
|
|
@@ -215,8 +218,19 @@ export async function buildApp(options: BuildAppOptions): Promise<BuildAppResult
|
|
|
215
218
|
options
|
|
216
219
|
);
|
|
217
220
|
break;
|
|
218
|
-
case "node":
|
|
219
221
|
case "vercel":
|
|
222
|
+
if (!serverEntry) {
|
|
223
|
+
throw new Error("[furin] `--target vercel` requires a server entry point.");
|
|
224
|
+
}
|
|
225
|
+
manifest.targets.vercel = await buildVercelTarget(
|
|
226
|
+
apps,
|
|
227
|
+
rootDir,
|
|
228
|
+
buildRoot,
|
|
229
|
+
serverEntry,
|
|
230
|
+
options
|
|
231
|
+
);
|
|
232
|
+
break;
|
|
233
|
+
case "node":
|
|
220
234
|
case "cloudflare":
|
|
221
235
|
throw new Error(
|
|
222
236
|
`[furin] \`--target ${target}\` is planned but not implemented yet in this branch.`
|
|
@@ -1,14 +1,66 @@
|
|
|
1
|
-
import { resolve } from "node:path";
|
|
1
|
+
import { dirname, relative, resolve } from "node:path";
|
|
2
2
|
|
|
3
3
|
const INSTRUMENTATION_IMPORT = /(?:^|[/\\])devtools[/\\]instrumentation(?:\.ts|\.js)?$/;
|
|
4
|
+
const DEV_PAGE_PLUGIN_IMPORT = /(?:^|[/\\])server[/\\]dev-page-plugin(?:\.ts|\.js)?$/;
|
|
5
|
+
const DEV_RUNTIME_IMPORT =
|
|
6
|
+
/(?:^|[/\\])server[/\\]dev[/\\](?:browser-events|diagnostics|plugin)(?:\.ts|\.js)?$/;
|
|
7
|
+
const DEV_BUILD_IMPORT =
|
|
8
|
+
/(?:^|[/\\])(?:build[/\\]hydrate|plugin[/\\]route-config-autofix)(?:\.ts|\.js)?$/;
|
|
9
|
+
const HMR_IMPORT = /(?:^|[/\\])server[/\\]router[/\\]hmr(?:\.ts|\.js)?$/;
|
|
10
|
+
const PRODUCTION_BOUNDARY_IMPORT =
|
|
11
|
+
/(?:browser-events|instrumentation|dev-page-plugin|diagnostics|plugin|hmr|hydrate|route-config-autofix)(?:\.ts|\.js)?$/;
|
|
12
|
+
const PRODUCTION_STUB_NAMESPACE = "furin-production-runtime-stub";
|
|
13
|
+
const FURIN_RUNTIME_ROOT = resolve(import.meta.dir, "..");
|
|
14
|
+
|
|
15
|
+
function isFurinRuntimePath(path: string): boolean {
|
|
16
|
+
const fromRuntimeRoot = relative(FURIN_RUNTIME_ROOT, path);
|
|
17
|
+
return (
|
|
18
|
+
fromRuntimeRoot !== ".." &&
|
|
19
|
+
!fromRuntimeRoot.startsWith("../") &&
|
|
20
|
+
!fromRuntimeRoot.startsWith("..\\")
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function devBuildExport(path: string): "fixRouteConfigLayout" | "writeDevFiles" {
|
|
25
|
+
return path.includes("route-config-autofix") ? "fixRouteConfigLayout" : "writeDevFiles";
|
|
26
|
+
}
|
|
4
27
|
|
|
5
28
|
export function productionInstrumentationPlugin(): Bun.BunPlugin {
|
|
6
29
|
return {
|
|
7
30
|
name: "furin-production-instrumentation",
|
|
8
31
|
setup(build) {
|
|
9
|
-
build.onResolve({ filter:
|
|
10
|
-
|
|
11
|
-
|
|
32
|
+
build.onResolve({ filter: PRODUCTION_BOUNDARY_IMPORT }, (args) => {
|
|
33
|
+
const importPath = resolve(dirname(args.importer), args.path);
|
|
34
|
+
if (!isFurinRuntimePath(importPath)) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
if (INSTRUMENTATION_IMPORT.test(importPath)) {
|
|
38
|
+
return {
|
|
39
|
+
path: resolve(import.meta.dir, "../server/devtools/instrumentation.production.ts"),
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
if (DEV_PAGE_PLUGIN_IMPORT.test(importPath)) {
|
|
43
|
+
return { path: resolve(import.meta.dir, "../server/dev-page-plugin.production.ts") };
|
|
44
|
+
}
|
|
45
|
+
if (DEV_RUNTIME_IMPORT.test(importPath)) {
|
|
46
|
+
return { path: resolve(import.meta.dir, "../server/dev/runtime.production.ts") };
|
|
47
|
+
}
|
|
48
|
+
if (HMR_IMPORT.test(importPath)) {
|
|
49
|
+
return { path: resolve(import.meta.dir, "../server/router/hmr.production.ts") };
|
|
50
|
+
}
|
|
51
|
+
if (DEV_BUILD_IMPORT.test(importPath)) {
|
|
52
|
+
return { namespace: PRODUCTION_STUB_NAMESPACE, path: importPath };
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
build.onLoad(
|
|
56
|
+
{ filter: /.*/, namespace: PRODUCTION_STUB_NAMESPACE },
|
|
57
|
+
({ path }) => ({
|
|
58
|
+
contents: `export function ${devBuildExport(path)}() {
|
|
59
|
+
throw new Error("[furin] Development-only module reached a production bundle.");
|
|
60
|
+
}`,
|
|
61
|
+
loader: "js",
|
|
62
|
+
})
|
|
63
|
+
);
|
|
12
64
|
},
|
|
13
65
|
};
|
|
14
66
|
}
|
package/src/build/route-types.ts
CHANGED
|
@@ -1,121 +1,26 @@
|
|
|
1
|
-
import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
|
2
|
-
import { join } from "node:path";
|
|
3
|
-
import { mergeRouteSchemas } from "../server/router/schema-merge.ts";
|
|
1
|
+
import { existsSync, readFileSync, renameSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { extname, join, relative } from "node:path";
|
|
4
3
|
import type { ResolvedRoute } from "../server/router/types.ts";
|
|
5
|
-
|
|
6
|
-
/** @internal Exported for unit testing only. */
|
|
7
|
-
export function patternToTypeString(pattern: string): string {
|
|
8
|
-
// biome-ignore lint/suspicious/noTemplateCurlyInString: intentional — generates TS template literal syntax
|
|
9
|
-
const t = pattern.replace(/:[^/]+/g, "${string}").replace(/\*/g, "${string}");
|
|
10
|
-
return t.includes("${") ? `\`${t}\`` : `"${t}"`;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Converts a runtime TypeBox/JSON Schema object to a TypeScript type string.
|
|
15
|
-
* Handles the common cases found in Elysia query schemas (string, number, boolean,
|
|
16
|
-
* optional fields, nullable via anyOf).
|
|
17
|
-
*
|
|
18
|
-
* @internal Exported for unit testing only.
|
|
19
|
-
*/
|
|
20
|
-
export function schemaToTypeString(schema: unknown): string {
|
|
21
|
-
return schemaToTypeStringWithDefaults(schema, true);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
function schemaToTypeStringWithDefaults(schema: unknown, defaultsAreRequired: boolean): string {
|
|
25
|
-
if (!schema || typeof schema !== "object") {
|
|
26
|
-
return "unknown";
|
|
27
|
-
}
|
|
28
|
-
const s = schema as Record<string, unknown>;
|
|
29
|
-
if (s.anyOf && Array.isArray(s.anyOf)) {
|
|
30
|
-
const parts: string[] = [];
|
|
31
|
-
for (const item of s.anyOf as unknown[]) {
|
|
32
|
-
const t = schemaToTypeStringWithDefaults(item, defaultsAreRequired);
|
|
33
|
-
if (t !== "null") {
|
|
34
|
-
parts.push(t);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
return parts.join(" | ") || "unknown";
|
|
38
|
-
}
|
|
39
|
-
switch (s.type) {
|
|
40
|
-
case "string":
|
|
41
|
-
return "string";
|
|
42
|
-
case "number":
|
|
43
|
-
case "integer":
|
|
44
|
-
return "number";
|
|
45
|
-
case "boolean":
|
|
46
|
-
return "boolean";
|
|
47
|
-
case "null":
|
|
48
|
-
return "null";
|
|
49
|
-
case "array": {
|
|
50
|
-
const inner = schemaToTypeStringWithDefaults(s.items, defaultsAreRequired);
|
|
51
|
-
return inner.includes("|") || inner.includes("&") ? `(${inner})[]` : `${inner}[]`;
|
|
52
|
-
}
|
|
53
|
-
case "object": {
|
|
54
|
-
if (!s.properties || typeof s.properties !== "object") {
|
|
55
|
-
return "Record<string, unknown>";
|
|
56
|
-
}
|
|
57
|
-
const required = new Set<string>(Array.isArray(s.required) ? (s.required as string[]) : []);
|
|
58
|
-
const props = Object.entries(s.properties as Record<string, unknown>)
|
|
59
|
-
.map(([k, v]) => {
|
|
60
|
-
const isPresent = required.has(k) || (defaultsAreRequired && hasNonNullSchemaDefault(v));
|
|
61
|
-
return `${k}${isPresent ? "" : "?"}: ${schemaToTypeStringWithDefaults(v, defaultsAreRequired)}`;
|
|
62
|
-
})
|
|
63
|
-
.join("; ");
|
|
64
|
-
return `{ ${props} }`;
|
|
65
|
-
}
|
|
66
|
-
default:
|
|
67
|
-
return "unknown";
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
/** @internal Exported for unit testing only. */
|
|
72
|
-
export function schemaToInputTypeString(schema: unknown): string {
|
|
73
|
-
return schemaToTypeStringWithDefaults(schema, false);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
function hasNonNullSchemaDefault(schema: unknown): boolean {
|
|
77
|
-
if (!schema || typeof schema !== "object") {
|
|
78
|
-
return false;
|
|
79
|
-
}
|
|
80
|
-
const s = schema as Record<string, unknown>;
|
|
81
|
-
return "default" in s && s.default !== null;
|
|
82
|
-
}
|
|
4
|
+
import { routeMapDeclaration, type RouteMapEntry } from "../shared/route-map.ts";
|
|
83
5
|
|
|
84
6
|
function tagKeyToPropertyName(tag: string): string {
|
|
85
7
|
return /^[$A-Z_a-z][$\w]*$/.test(tag) ? tag : JSON.stringify(tag);
|
|
86
8
|
}
|
|
87
9
|
|
|
88
10
|
function tagToStringLiteral(tag: string): string {
|
|
89
|
-
// Use JSON.stringify for robust escaping of control chars, unicode
|
|
90
|
-
// separators, backslashes and quotes, then convert double quotes to single.
|
|
91
11
|
const json = JSON.stringify(tag);
|
|
92
|
-
// json is double-quoted; convert to single-quoted literal by escaping
|
|
93
|
-
// any contained single quotes and swapping the outer quotes.
|
|
94
12
|
return `'${json.slice(1, -1).replaceAll("'", "\\'")}'`;
|
|
95
13
|
}
|
|
96
14
|
|
|
97
|
-
/**
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
/** @internal Exported for unit testing only. */
|
|
106
|
-
export function writeRouteTypes(routes: ResolvedRoute[], projectRoot: string): void {
|
|
107
|
-
const sortedRoutes = [...routes].sort((a, b) => a.pattern.localeCompare(b.pattern));
|
|
108
|
-
const entries = sortedRoutes.map((r) => {
|
|
109
|
-
const typeKey = patternToTypeString(r.pattern);
|
|
110
|
-
const isDynamic = typeKey.startsWith("`");
|
|
111
|
-
const querySchema = mergeRouteSchemas(r.routeChain ?? [], "query");
|
|
112
|
-
const searchType = querySchema ? schemaToTypeString(querySchema) : "never";
|
|
113
|
-
const searchInputType = querySchema ? schemaToInputTypeString(querySchema) : "never";
|
|
114
|
-
return isDynamic
|
|
115
|
-
? ` [key: ${typeKey}]: { search?: ${searchType}; searchInput?: ${searchInputType} }`
|
|
116
|
-
: ` ${typeKey}: { search?: ${searchType}; searchInput?: ${searchInputType} }`;
|
|
15
|
+
/** @internal Exported for framework build and focused contract tests. */
|
|
16
|
+
export function writeRouteTypes(routes: ResolvedRoute[], projectRoot: string): boolean {
|
|
17
|
+
const entries: RouteMapEntry[] = routes.map((route) => {
|
|
18
|
+
const extension = extname(route.path);
|
|
19
|
+
const sourcePath = extension ? route.path.slice(0, -extension.length) : route.path;
|
|
20
|
+
const relativePath = relative(projectRoot, sourcePath).replaceAll("\\", "/");
|
|
21
|
+
const specifier = relativePath.startsWith(".") ? relativePath : `./${relativePath}`;
|
|
22
|
+
return { importSpecifier: specifier, pattern: route.pattern };
|
|
117
23
|
});
|
|
118
|
-
const routeManifestEntries = entries.join(";\n");
|
|
119
24
|
|
|
120
25
|
const sortedTags = [...new Set(routes.flatMap((route) => route.tags ?? []))].sort();
|
|
121
26
|
const tagBlock =
|
|
@@ -127,18 +32,18 @@ export function writeRouteTypes(routes: ResolvedRoute[], projectRoot: string): v
|
|
|
127
32
|
|
|
128
33
|
const content = `// Auto-generated by Furin. Do not edit manually.
|
|
129
34
|
/// <reference types="@teyik0/furin/env" />
|
|
130
|
-
import "@teyik0/furin/
|
|
35
|
+
import "@teyik0/furin/routes";
|
|
131
36
|
|
|
132
|
-
|
|
133
|
-
interface RouteManifest {
|
|
134
|
-
${routeManifestEntries};
|
|
135
|
-
}
|
|
136
|
-
}${tagBlock}
|
|
37
|
+
${routeMapDeclaration(entries)}${tagBlock}
|
|
137
38
|
`;
|
|
138
39
|
|
|
139
40
|
const typesPath = join(projectRoot, "furin-env.d.ts");
|
|
140
41
|
const existing = existsSync(typesPath) ? readFileSync(typesPath, "utf8") : "";
|
|
141
|
-
if (content
|
|
142
|
-
|
|
42
|
+
if (content === existing) {
|
|
43
|
+
return false;
|
|
143
44
|
}
|
|
45
|
+
const temporaryPath = `${typesPath}.${process.pid}.${Bun.nanoseconds()}.tmp`;
|
|
46
|
+
writeFileSync(temporaryPath, content);
|
|
47
|
+
renameSync(temporaryPath, typesPath);
|
|
48
|
+
return true;
|
|
144
49
|
}
|
package/src/build/shared.ts
CHANGED
|
@@ -2,7 +2,8 @@ import { cpSync, existsSync, mkdirSync, readdirSync, rmSync } from "node:fs";
|
|
|
2
2
|
import { join, relative } from "node:path";
|
|
3
3
|
import { fileURLToPath } from "node:url";
|
|
4
4
|
import type { BuildTarget } from "../config";
|
|
5
|
-
import
|
|
5
|
+
import { resolveRouteRevalidate } from "../server/router/patterns.ts";
|
|
6
|
+
import type { ResolvedRoute } from "../server/router/types.ts";
|
|
6
7
|
import type { BuildRouteManifestEntry, TargetBuildManifest } from "./types";
|
|
7
8
|
|
|
8
9
|
// import.meta.dir/path/url are inlined at bundle time to the OUTPUT file's
|
|
@@ -56,7 +57,7 @@ export function toBuildRouteManifestEntry(
|
|
|
56
57
|
pagePath: toPosixPath(relative(rootDir, route.path)),
|
|
57
58
|
hasLayout: route.routeChain.some((entry) => !!entry.layout),
|
|
58
59
|
hasStaticParams: !!route.page?.staticParams,
|
|
59
|
-
revalidate: route.page
|
|
60
|
+
revalidate: resolveRouteRevalidate(route.page) ?? null,
|
|
60
61
|
};
|
|
61
62
|
}
|
|
62
63
|
|