@teyik0/furin 0.1.0-alpha.10
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 +3 -0
- package/dist/adapter/static.d.ts +3 -0
- package/dist/build/client.d.ts +25 -0
- package/dist/build/compile-entry.d.ts +35 -0
- package/dist/build/entry-template.d.ts +26 -0
- package/dist/build/hydrate.d.ts +24 -0
- package/dist/build/index.d.ts +7 -0
- package/dist/build/index.js +4716 -0
- package/dist/build/route-types.d.ts +21 -0
- package/dist/build/scan-server.d.ts +8 -0
- package/dist/build/server-routes-entry.d.ts +35 -0
- package/dist/build/shared.d.ts +11 -0
- package/dist/build/types.d.ts +76 -0
- package/dist/cli/config.d.ts +9 -0
- package/dist/cli/index.d.ts +2 -0
- package/dist/cli/index.js +4751 -0
- package/dist/client.d.ts +195 -0
- package/dist/client.js +20 -0
- package/dist/config.d.ts +50 -0
- package/dist/config.js +28 -0
- package/dist/context-logger.d.ts +28 -0
- package/dist/dev-page-plugin.d.ts +109 -0
- package/dist/error.d.ts +23 -0
- package/dist/furin.d.ts +52 -0
- package/dist/furin.js +3948 -0
- package/dist/internal.d.ts +33 -0
- package/dist/link.d.ts +454 -0
- package/dist/link.js +1790 -0
- package/dist/not-found.d.ts +19 -0
- package/dist/plugin/index.d.ts +20 -0
- package/dist/plugin/index.js +1408 -0
- package/dist/plugin/transform-client.d.ts +9 -0
- package/dist/render/assemble.d.ts +15 -0
- package/dist/render/boundaries.d.ts +79 -0
- package/dist/render/cache.d.ts +96 -0
- package/dist/render/default-screens.d.ts +11 -0
- package/dist/render/digest.d.ts +16 -0
- package/dist/render/element.d.ts +8 -0
- package/dist/render/index.d.ts +53 -0
- package/dist/render/loaders.d.ts +21 -0
- package/dist/render/shell.d.ts +29 -0
- package/dist/render/template.d.ts +6 -0
- package/dist/router.d.ts +96 -0
- package/dist/router.js +2693 -0
- package/dist/runtime-env.d.ts +3 -0
- package/dist/utils.d.ts +6 -0
- package/package.json +77 -0
- package/src/adapter/README.md +13 -0
- package/src/adapter/bun.ts +239 -0
- package/src/adapter/static.ts +341 -0
- package/src/build/client.ts +153 -0
- package/src/build/compile-entry.ts +129 -0
- package/src/build/entry-template.ts +126 -0
- package/src/build/hydrate.ts +250 -0
- package/src/build/index.ts +151 -0
- package/src/build/route-types.ts +89 -0
- package/src/build/scan-server.ts +110 -0
- package/src/build/server-routes-entry.ts +55 -0
- package/src/build/shared.ts +78 -0
- package/src/build/types.ts +85 -0
- package/src/cli/config.ts +68 -0
- package/src/cli/index.ts +115 -0
- package/src/client.ts +278 -0
- package/src/config.ts +66 -0
- package/src/context-logger.ts +74 -0
- package/src/dev-page-plugin.ts +434 -0
- package/src/env.d.ts +49 -0
- package/src/error.ts +32 -0
- package/src/furin.ts +383 -0
- package/src/internal.ts +51 -0
- package/src/link.tsx +1578 -0
- package/src/not-found.ts +40 -0
- package/src/plugin/index.ts +80 -0
- package/src/plugin/transform-client.ts +372 -0
- package/src/render/assemble.ts +66 -0
- package/src/render/boundaries.tsx +176 -0
- package/src/render/cache.ts +251 -0
- package/src/render/default-screens.tsx +299 -0
- package/src/render/digest.ts +71 -0
- package/src/render/element.tsx +119 -0
- package/src/render/index.ts +867 -0
- package/src/render/loaders.ts +127 -0
- package/src/render/shell.ts +187 -0
- package/src/render/template.ts +55 -0
- package/src/router.ts +779 -0
- package/src/runtime-env.ts +6 -0
- package/src/utils.ts +68 -0
package/src/furin.ts
ADDED
|
@@ -0,0 +1,383 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import { basename, dirname, join, resolve } from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
import { staticPlugin } from "@elysiajs/static";
|
|
5
|
+
import { type AnyElysia, Elysia, file } from "elysia";
|
|
6
|
+
import { type DrainContext, initLogger } from "evlog";
|
|
7
|
+
import { type EvlogElysiaOptions, evlog } from "evlog/elysia";
|
|
8
|
+
import type { EmbeddedAppData } from "./internal.ts";
|
|
9
|
+
import { getCompileContext } from "./internal.ts";
|
|
10
|
+
import {
|
|
11
|
+
_runWithRequestInvalidationScope,
|
|
12
|
+
consumePendingInvalidations,
|
|
13
|
+
getBuildId,
|
|
14
|
+
setBuildId,
|
|
15
|
+
} from "./render/cache.ts";
|
|
16
|
+
import { renderRootNotFound, warmSSGCache } from "./render/index.ts";
|
|
17
|
+
import { setProductionTemplateContent, setProductionTemplatePath } from "./render/template.ts";
|
|
18
|
+
import { createRoutePlugin, loadProdRoutes } from "./router.ts";
|
|
19
|
+
import { IS_DEV } from "./runtime-env.ts";
|
|
20
|
+
|
|
21
|
+
function resolveClientDirFromArgv(): string {
|
|
22
|
+
return (
|
|
23
|
+
resolveClientDirFromEnv() ??
|
|
24
|
+
resolveClientDirFromModuleUrl() ??
|
|
25
|
+
resolveClientDirFromProcessArgs() ??
|
|
26
|
+
resolveFallbackClientDir()
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function resolveClientDirFromEnv(): string | null {
|
|
31
|
+
const envClientDir = process.env.FURIN_CLIENT_DIR;
|
|
32
|
+
if (!envClientDir) {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
return envClientDir.startsWith("/") ? envClientDir : resolve(process.cwd(), envClientDir);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function resolveClientDirFromModuleUrl(): string | null {
|
|
39
|
+
try {
|
|
40
|
+
const moduleUrl = new URL(import.meta.url);
|
|
41
|
+
if (moduleUrl.protocol !== "file:") {
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
const modulePath = fileURLToPath(moduleUrl);
|
|
45
|
+
if (modulePath.includes("/$bunfs/")) {
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
const moduleClientDir = join(dirname(modulePath), "client");
|
|
49
|
+
if (existsSync(join(moduleClientDir, "index.html"))) {
|
|
50
|
+
return moduleClientDir;
|
|
51
|
+
}
|
|
52
|
+
} catch {
|
|
53
|
+
// ignore, fallback to argv-based resolution
|
|
54
|
+
}
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function resolveClientDirFromProcessArgs(): string | null {
|
|
59
|
+
const candidates = [
|
|
60
|
+
process.argv[1],
|
|
61
|
+
process.argv[0],
|
|
62
|
+
(process as { argv0?: string }).argv0,
|
|
63
|
+
process.execPath,
|
|
64
|
+
].filter((value): value is string => typeof value === "string" && value.length > 0);
|
|
65
|
+
|
|
66
|
+
for (const candidate of candidates) {
|
|
67
|
+
const resolved = resolveClientDirFromCandidate(candidate);
|
|
68
|
+
if (resolved) {
|
|
69
|
+
return resolved;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function resolveClientDirFromCandidate(candidate: string): string | null {
|
|
77
|
+
const name = basename(candidate);
|
|
78
|
+
if (name === "bun" || name === "node") {
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
if (candidate.includes("/$bunfs/") || candidate.startsWith("bunfs:")) {
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const absolute = candidate.startsWith("/") ? candidate : resolve(process.cwd(), candidate);
|
|
86
|
+
if (existsSync(absolute)) {
|
|
87
|
+
return join(dirname(absolute), "client");
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if (!candidate.includes("/")) {
|
|
91
|
+
return resolveClientDirFromPath(candidate);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function resolveClientDirFromPath(candidate: string): string | null {
|
|
98
|
+
const pathEntries = process.env.PATH?.split(":") ?? [];
|
|
99
|
+
for (const dir of pathEntries) {
|
|
100
|
+
const fullPath = join(dir, candidate);
|
|
101
|
+
if (existsSync(fullPath)) {
|
|
102
|
+
return join(dirname(fullPath), "client");
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return null;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function resolveFallbackClientDir(): string {
|
|
109
|
+
const defaultClientDir = resolve(process.cwd(), ".furin/build/bun/client");
|
|
110
|
+
if (existsSync(join(defaultClientDir, "index.html"))) {
|
|
111
|
+
return defaultClientDir;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return join(process.cwd(), "client");
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
async function setupProdTemplate(
|
|
118
|
+
embedded: EmbeddedAppData | undefined,
|
|
119
|
+
clientDir: string
|
|
120
|
+
): Promise<void> {
|
|
121
|
+
if (embedded) {
|
|
122
|
+
if (!embedded.template) {
|
|
123
|
+
throw new Error("[furin] Embedded app is missing its HTML template (index.html).");
|
|
124
|
+
}
|
|
125
|
+
const html = await Bun.file(embedded.template).text();
|
|
126
|
+
setProductionTemplateContent(html);
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
const templatePath = join(clientDir, "index.html");
|
|
131
|
+
if (!existsSync(templatePath)) {
|
|
132
|
+
throw new Error("[furin] No pre-built assets found. Run `bun run build` first.");
|
|
133
|
+
}
|
|
134
|
+
setProductionTemplatePath(templatePath);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Registers a HigherOrderFunction on the Elysia instance so that every request
|
|
139
|
+
* runs inside a fresh `AsyncLocalStorage` scope. This isolates
|
|
140
|
+
* `pendingInvalidations` per request, preventing concurrent requests from
|
|
141
|
+
* stealing each other's `revalidatePath()` calls.
|
|
142
|
+
*
|
|
143
|
+
* Uses `app.wrap()` (Elysia HigherOrderFunction) instead of mutating
|
|
144
|
+
* `app.handle`, because handle mutations are lost when the Furin plugin is
|
|
145
|
+
* `.use()`-d by a parent Elysia instance. HigherOrderFunctions survive the
|
|
146
|
+
* plugin merge and wrap the entire composed `map` handler.
|
|
147
|
+
*/
|
|
148
|
+
function wrapWithRequestScope(app: AnyElysia): Elysia {
|
|
149
|
+
return app.wrap(
|
|
150
|
+
(handler, _request) => (ctx: unknown) => _runWithRequestInvalidationScope(() => handler(ctx))
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Main Furin plugin.
|
|
156
|
+
*
|
|
157
|
+
* Returns a standalone Elysia instance (async function) so that routes are
|
|
158
|
+
* properly registered in Elysia's router for SPA navigation to work.
|
|
159
|
+
*
|
|
160
|
+
* ## Usage
|
|
161
|
+
*
|
|
162
|
+
* ```ts
|
|
163
|
+
* new Elysia()
|
|
164
|
+
* .use(await furin({ ... }))
|
|
165
|
+
* .listen(3000)
|
|
166
|
+
* ```
|
|
167
|
+
*/
|
|
168
|
+
export async function furin({
|
|
169
|
+
pagesDir,
|
|
170
|
+
logger,
|
|
171
|
+
}: {
|
|
172
|
+
pagesDir?: string;
|
|
173
|
+
logger?: EvlogElysiaOptions;
|
|
174
|
+
}) {
|
|
175
|
+
const { exclude: userExclude, ...evlogOptions } = logger ?? {};
|
|
176
|
+
initLogger({ env: { service: "furin" } });
|
|
177
|
+
|
|
178
|
+
const loggerPlugin = new Elysia()
|
|
179
|
+
.use(
|
|
180
|
+
evlog({
|
|
181
|
+
...evlogOptions,
|
|
182
|
+
exclude: [
|
|
183
|
+
"/_client/**",
|
|
184
|
+
"/public/**",
|
|
185
|
+
"/favicon.ico",
|
|
186
|
+
"/_furin/!(ingest)",
|
|
187
|
+
"/_bun_hmr_entry/**",
|
|
188
|
+
...(userExclude ?? []),
|
|
189
|
+
],
|
|
190
|
+
})
|
|
191
|
+
)
|
|
192
|
+
.post(
|
|
193
|
+
"/_furin/ingest",
|
|
194
|
+
({ body, log, status }) => {
|
|
195
|
+
if (!Array.isArray(body)) {
|
|
196
|
+
return status("Bad Request");
|
|
197
|
+
}
|
|
198
|
+
// Cap batch size to prevent abuse
|
|
199
|
+
const batch = (body as DrainContext[]).slice(0, 100);
|
|
200
|
+
for (const entry of batch) {
|
|
201
|
+
if (!entry || typeof entry !== "object" || !("event" in entry)) {
|
|
202
|
+
log.set({ msg: "[furin] ingest: skipping malformed entry" });
|
|
203
|
+
continue;
|
|
204
|
+
}
|
|
205
|
+
// Pick only safe, known fields from the event to prevent prototype pollution
|
|
206
|
+
const event = entry.event as Record<string, unknown> | undefined;
|
|
207
|
+
if (!event || typeof event !== "object") {
|
|
208
|
+
continue;
|
|
209
|
+
}
|
|
210
|
+
const {
|
|
211
|
+
__proto__,
|
|
212
|
+
constructor: _ctor,
|
|
213
|
+
prototype,
|
|
214
|
+
environment: _browserEnv,
|
|
215
|
+
...safeEvent
|
|
216
|
+
} = event as Record<string, unknown>;
|
|
217
|
+
log.set({ ...safeEvent, service: "furin:browser" });
|
|
218
|
+
}
|
|
219
|
+
return status("No Content");
|
|
220
|
+
},
|
|
221
|
+
{ parse: "json" }
|
|
222
|
+
);
|
|
223
|
+
|
|
224
|
+
const cwd = process.cwd();
|
|
225
|
+
const ctx = getCompileContext();
|
|
226
|
+
const resolvedPagesDir = ctx?.rootPath
|
|
227
|
+
? dirname(ctx.rootPath)
|
|
228
|
+
: resolve(cwd, pagesDir ?? "src/pages");
|
|
229
|
+
|
|
230
|
+
// Unique name per pagesDir to avoid Elysia's name-based plugin dedup.
|
|
231
|
+
const instanceName = `furin-${resolvedPagesDir.replaceAll("\\", "/")}`;
|
|
232
|
+
|
|
233
|
+
// ── Dev: Bun native HMR ────────────────────────────────────────────────
|
|
234
|
+
if (IS_DEV) {
|
|
235
|
+
const furinDir = resolve(cwd, ".furin");
|
|
236
|
+
// Lazy import — build pipeline has native deps not available in compiled binaries
|
|
237
|
+
const { registerDevPagePlugin } = await import("./dev-page-plugin.ts");
|
|
238
|
+
registerDevPagePlugin();
|
|
239
|
+
|
|
240
|
+
const { scanPages } = await import("./router.ts");
|
|
241
|
+
const { root, routes } = await scanPages(resolvedPagesDir);
|
|
242
|
+
|
|
243
|
+
const { writeDevFiles } = await import("./build/hydrate.ts");
|
|
244
|
+
writeDevFiles(
|
|
245
|
+
routes,
|
|
246
|
+
{ outDir: furinDir, rootLayout: root.path, basePath: "", publicPath: "/_client/" },
|
|
247
|
+
cwd
|
|
248
|
+
);
|
|
249
|
+
|
|
250
|
+
const publicDir = resolve(cwd, "public");
|
|
251
|
+
const publicExists = existsSync(publicDir);
|
|
252
|
+
|
|
253
|
+
const devApp = new Elysia({ name: instanceName, seed: resolvedPagesDir })
|
|
254
|
+
.use(loggerPlugin)
|
|
255
|
+
.onError({ as: "global" }, async ({ code, request }) => {
|
|
256
|
+
if (code === "NOT_FOUND") {
|
|
257
|
+
return await renderRootNotFound(root, request);
|
|
258
|
+
}
|
|
259
|
+
})
|
|
260
|
+
.onAfterHandle({ as: "global" }, ({ set }) => {
|
|
261
|
+
// Forward pending revalidation paths so the client can bust its prefetch cache
|
|
262
|
+
const pending = consumePendingInvalidations();
|
|
263
|
+
if (pending.length > 0) {
|
|
264
|
+
set.headers["x-furin-revalidate"] = pending.join(",");
|
|
265
|
+
}
|
|
266
|
+
})
|
|
267
|
+
.use(await staticPlugin({ assets: furinDir, prefix: "/_bun_hmr_entry", bunFullstack: true }))
|
|
268
|
+
.use(
|
|
269
|
+
publicExists ? await staticPlugin({ assets: publicDir, prefix: "/public" }) : new Elysia()
|
|
270
|
+
)
|
|
271
|
+
.get(
|
|
272
|
+
"/favicon.ico",
|
|
273
|
+
publicExists
|
|
274
|
+
? file(join(publicDir, "favicon.ico"))
|
|
275
|
+
: () => new Response(null, { status: 404 })
|
|
276
|
+
)
|
|
277
|
+
.use((app) => {
|
|
278
|
+
for (const route of routes) {
|
|
279
|
+
app.use(createRoutePlugin(route, root));
|
|
280
|
+
}
|
|
281
|
+
return app;
|
|
282
|
+
});
|
|
283
|
+
return wrapWithRequestScope(devApp);
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
// ── Production ──────────────────────────────────────────────────────────
|
|
287
|
+
if (!ctx) {
|
|
288
|
+
throw new Error("[furin] No pre-built assets found. Run `bunx furin build` first.");
|
|
289
|
+
}
|
|
290
|
+
const { root, routes } = loadProdRoutes(ctx);
|
|
291
|
+
const prodBuildId = ctx.buildId ?? "";
|
|
292
|
+
setBuildId(prodBuildId);
|
|
293
|
+
|
|
294
|
+
const embedded = ctx?.embedded;
|
|
295
|
+
const clientDir = embedded ? "" : resolveClientDirFromArgv();
|
|
296
|
+
await setupProdTemplate(embedded, clientDir);
|
|
297
|
+
|
|
298
|
+
const prodApp = new Elysia({ name: instanceName, seed: resolvedPagesDir })
|
|
299
|
+
.use(loggerPlugin)
|
|
300
|
+
.onError({ as: "global" }, async ({ code, request }) => {
|
|
301
|
+
if (code === "NOT_FOUND") {
|
|
302
|
+
return await renderRootNotFound(root, request);
|
|
303
|
+
}
|
|
304
|
+
})
|
|
305
|
+
.onAfterHandle({ as: "global" }, ({ path, set }) => {
|
|
306
|
+
// Content-hashed client assets are permanently cacheable — browsers never need to
|
|
307
|
+
// revalidate them because any change produces a new filename.
|
|
308
|
+
if (path.startsWith("/_client/")) {
|
|
309
|
+
set.headers["cache-control"] = "public, max-age=31536000, immutable";
|
|
310
|
+
}
|
|
311
|
+
// Forward pending revalidation paths so the client can bust its prefetch cache
|
|
312
|
+
const pending = consumePendingInvalidations();
|
|
313
|
+
if (pending.length > 0) {
|
|
314
|
+
set.headers["x-furin-revalidate"] = pending.join(",");
|
|
315
|
+
}
|
|
316
|
+
// Tell the client the current build ID so it can detect stale deploys
|
|
317
|
+
const buildId = getBuildId();
|
|
318
|
+
if (buildId) {
|
|
319
|
+
set.headers["x-furin-build-id"] = buildId;
|
|
320
|
+
}
|
|
321
|
+
})
|
|
322
|
+
.onStart(async ({ server }) => {
|
|
323
|
+
const origin = server?.url?.origin ?? "http://localhost:3000";
|
|
324
|
+
await warmSSGCache(routes, root, origin);
|
|
325
|
+
})
|
|
326
|
+
.use(
|
|
327
|
+
await (async () => {
|
|
328
|
+
if (embedded) {
|
|
329
|
+
return new Elysia()
|
|
330
|
+
.get("/favicon.ico", ({ status }) => {
|
|
331
|
+
const asset = embedded.assets["/public/favicon.ico"];
|
|
332
|
+
if (!asset) {
|
|
333
|
+
return status("Not Found");
|
|
334
|
+
}
|
|
335
|
+
return Bun.file(asset);
|
|
336
|
+
})
|
|
337
|
+
.get("/_client/*", ({ params, status }) => {
|
|
338
|
+
const asset = embedded.assets[`/_client/${params["*"]}`];
|
|
339
|
+
if (!asset) {
|
|
340
|
+
return status("Not Found");
|
|
341
|
+
}
|
|
342
|
+
return Bun.file(asset);
|
|
343
|
+
})
|
|
344
|
+
.get("/public/*", ({ params, status }) => {
|
|
345
|
+
const asset = embedded.assets[`/public/${params["*"]}`];
|
|
346
|
+
if (!asset) {
|
|
347
|
+
return status("Not Found");
|
|
348
|
+
}
|
|
349
|
+
return Bun.file(asset);
|
|
350
|
+
});
|
|
351
|
+
}
|
|
352
|
+
const publicDir = join(dirname(clientDir), "public");
|
|
353
|
+
const app = new Elysia();
|
|
354
|
+
if (existsSync(publicDir)) {
|
|
355
|
+
app
|
|
356
|
+
.get("/favicon.ico", file(join(publicDir, "favicon.ico")))
|
|
357
|
+
.use(await staticPlugin({ assets: publicDir, prefix: "/public" }));
|
|
358
|
+
}
|
|
359
|
+
app.use(await staticPlugin({ assets: clientDir, prefix: "/_client" }));
|
|
360
|
+
return app;
|
|
361
|
+
})()
|
|
362
|
+
)
|
|
363
|
+
.use((app) => {
|
|
364
|
+
for (const route of routes) {
|
|
365
|
+
app.use(createRoutePlugin(route, root, prodBuildId));
|
|
366
|
+
}
|
|
367
|
+
return app;
|
|
368
|
+
});
|
|
369
|
+
return wrapWithRequestScope(prodApp);
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
// ── Public API re-export ──────────────────────────────────────────────────────
|
|
373
|
+
// biome-ignore-start lint/performance/noBarrelFile: intentional — furin.ts is the public package entry
|
|
374
|
+
export type { ErrorComponent, ErrorProps } from "./error.ts";
|
|
375
|
+
export type {
|
|
376
|
+
NotFoundComponent,
|
|
377
|
+
NotFoundOptions,
|
|
378
|
+
NotFoundProps,
|
|
379
|
+
} from "./not-found.ts";
|
|
380
|
+
export { isNotFoundError, notFound } from "./not-found.ts";
|
|
381
|
+
export { revalidatePath, setCachePurger } from "./render/cache.ts";
|
|
382
|
+
export { renderRootNotFound } from "./render/index.ts";
|
|
383
|
+
// biome-ignore-end lint/performance/noBarrelFile: intentional — furin.ts is the public package entry
|
package/src/internal.ts
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// ── Compile-time context for compiled binaries ──────────────────────────────
|
|
2
|
+
// The generated compile entry calls `__setCompileContext()` before importing
|
|
3
|
+
// server.ts. At runtime, `router.ts` and `furin.ts` use `getCompileContext()`
|
|
4
|
+
// to resolve modules and assets from the binary instead of the filesystem.
|
|
5
|
+
|
|
6
|
+
export interface EmbeddedAppData {
|
|
7
|
+
assets: Record<string, string>;
|
|
8
|
+
template: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface CompileContextRoute {
|
|
12
|
+
mode: "ssr" | "ssg" | "isr";
|
|
13
|
+
path: string;
|
|
14
|
+
pattern: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface CompileContext {
|
|
18
|
+
buildId?: string;
|
|
19
|
+
embedded?: EmbeddedAppData;
|
|
20
|
+
modules: Record<string, unknown>;
|
|
21
|
+
/** Root-level conventions discovered at compile time. */
|
|
22
|
+
rootConventions?: { errorPath?: string; notFoundPath?: string };
|
|
23
|
+
rootPath: string;
|
|
24
|
+
/** Per-route metadata including pre-computed segment boundaries. */
|
|
25
|
+
routeMetadata?: Record<
|
|
26
|
+
string,
|
|
27
|
+
{
|
|
28
|
+
segmentBoundaries: Array<{
|
|
29
|
+
depth: number;
|
|
30
|
+
path: string;
|
|
31
|
+
errorPath?: string;
|
|
32
|
+
notFoundPath?: string;
|
|
33
|
+
}>;
|
|
34
|
+
}
|
|
35
|
+
>;
|
|
36
|
+
routes: CompileContextRoute[];
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
let _compileCtx: CompileContext | null = null;
|
|
40
|
+
|
|
41
|
+
export function __setCompileContext(ctx: CompileContext): void {
|
|
42
|
+
_compileCtx = ctx;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function getCompileContext(): CompileContext | null {
|
|
46
|
+
return _compileCtx;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function __resetCompileContext(): void {
|
|
50
|
+
_compileCtx = null;
|
|
51
|
+
}
|