@teyik0/furin 0.6.0-alpha.1 → 0.7.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/runtime-build.d.ts +1 -1
- package/dist/build/client.d.ts +4 -1
- package/dist/build/elysia-aot-worker.d.ts +22 -0
- package/dist/build/elysia-aot.d.ts +1 -1
- package/dist/build/entry-template.d.ts +3 -0
- package/dist/build/entry-template.ts +7 -0
- package/dist/build/hydrate.d.ts +1 -1
- package/dist/build/index.js +1880 -401
- package/dist/build/preload-manifest.d.ts +17 -0
- package/dist/build/types.d.ts +6 -0
- package/dist/cli/index.js +1878 -408
- package/dist/client/client-module.d.ts +26 -0
- package/dist/client/define-route.d.ts +9 -0
- package/dist/client/document.d.ts +2 -0
- package/dist/client/internal/runtime-types.d.ts +2 -0
- package/dist/client/link.js +942 -122
- package/dist/client/mutation.d.ts +38 -0
- package/dist/client/query-store.d.ts +85 -0
- package/dist/client/query.d.ts +14 -0
- package/dist/client/route-api.d.ts +11 -0
- package/dist/client/router/context.d.ts +3 -2
- package/dist/client/router/index.d.ts +1 -1
- package/dist/client/router/link-utils.d.ts +8 -1
- package/dist/client/router/navigation.d.ts +2 -9
- package/dist/client/router/optimistic.d.ts +41 -0
- package/dist/client/router/search/index.d.ts +3 -3
- package/dist/client/router/search-store.d.ts +1 -0
- package/dist/client/router/sync-catch-up.d.ts +3 -0
- package/dist/client/router/types.d.ts +51 -7
- package/dist/client/sync.d.ts +39 -22
- package/dist/client.d.ts +11 -33
- package/dist/client.js +1219 -59
- package/dist/config.d.ts +7 -0
- package/dist/config.js +1 -0
- package/dist/define-route.d.ts +78 -32
- package/dist/env.d.ts +2 -2
- package/dist/furin.d.ts +1 -2
- package/dist/furin.js +2484 -708
- package/dist/plugin/hmr-dependencies.d.ts +2 -0
- package/dist/plugin/index.js +349 -18
- package/dist/plugin/transform-client-module.d.ts +16 -0
- package/dist/plugin/transform-client.d.ts +2 -0
- package/dist/plugin/transform-isomorphic.d.ts +1 -1
- package/dist/routes.d.ts +6 -0
- package/dist/rsc-client.js +87 -16
- package/dist/rsc.js +87 -16
- package/dist/server/auto-invalidate/registry.d.ts +1 -0
- package/dist/server/auto-invalidate/types.d.ts +2 -0
- package/dist/server/cache/isr.d.ts +2 -4
- package/dist/server/cache/route-cache.d.ts +5 -0
- package/dist/server/dev/graph.d.ts +1 -0
- package/dist/server/dev-page-plugin.d.ts +5 -19
- package/dist/server/internal.d.ts +3 -0
- package/dist/server/internal.js +55 -35
- package/dist/server/production-server.js +54 -34
- package/dist/server/render/loaders.d.ts +4 -2
- package/dist/server/render/react-stream.d.ts +3 -0
- package/dist/server/render/ssr.d.ts +2 -1
- package/dist/server/render/template.d.ts +4 -0
- package/dist/server/router/defined-route.d.ts +2 -0
- package/dist/server/router/hmr.d.ts +1 -1
- package/dist/server/router/patterns.d.ts +2 -0
- package/dist/server/router/types.d.ts +1 -1
- package/dist/server/sync/adapter.d.ts +25 -4
- package/dist/server/sync/atomic.d.ts +25 -0
- package/dist/server/sync/drizzle/index.d.ts +45 -0
- package/dist/server/sync/drizzle/index.js +540 -0
- package/dist/server/sync/execution-error.d.ts +2 -0
- package/dist/server/sync/index.d.ts +2 -1
- package/dist/server/sync/index.js +533 -105
- package/dist/server/sync/mutation-handler.d.ts +4 -0
- package/dist/server/sync/plugin.d.ts +34 -11
- package/dist/server/sync/postgres/execute.d.ts +3 -0
- package/dist/server/sync/postgres/index.d.ts +12 -1
- package/dist/server/sync/postgres/index.js +34 -13
- package/dist/server/sync/postgres/sql.d.ts +8 -0
- package/dist/server/sync/prisma/index.d.ts +24 -0
- package/dist/server/sync/prisma/index.js +340 -0
- package/dist/server/sync/queries.d.ts +21 -0
- package/dist/server/sync/query-context.d.ts +5 -0
- package/dist/server/sync/redis/index.js +3 -3
- package/dist/server/sync/redis/scripts.d.ts +1 -1
- package/dist/server/sync/response.d.ts +1 -0
- package/dist/server/sync/sqlite/index.d.ts +3 -0
- package/dist/server/sync/sqlite/index.js +10 -4
- package/dist/server/sync/stream.d.ts +2 -5
- package/dist/server/sync/validation.d.ts +4 -0
- package/dist/shared/defer.d.ts +31 -0
- package/dist/shared/error.d.ts +2 -2
- package/dist/shared/page-key.d.ts +7 -0
- package/dist/shared/query-bindings.d.ts +12 -0
- package/dist/shared/route-frame.d.ts +1 -0
- package/dist/shared/sync-query.d.ts +40 -0
- package/package.json +29 -6
- package/src/adapter/package.ts +12 -2
- package/src/adapter/runtime-build.ts +63 -12
- package/src/adapter/static.ts +7 -2
- package/src/adapter/vercel.ts +15 -13
- package/src/build/client.ts +23 -5
- package/src/build/elysia-aot-worker.ts +51 -0
- package/src/build/elysia-aot.ts +83 -19
- package/src/build/entry-template.ts +7 -0
- package/src/build/hydrate.ts +21 -3
- package/src/build/preload-manifest.ts +100 -0
- package/src/build/production-instrumentation.ts +6 -3
- package/src/build/types.ts +4 -0
- package/src/cli/index.ts +1 -0
- package/src/client/browser-events-runtime.ts +4 -0
- package/src/client/client-module.ts +57 -0
- package/src/client/define-route.ts +11 -1
- package/src/client/document.tsx +28 -18
- package/src/client/hmr.ts +2 -1
- package/src/client/internal/runtime-types.ts +2 -0
- package/src/client/link.tsx +8 -8
- package/src/client/mutation.ts +136 -0
- package/src/client/query-store.ts +418 -0
- package/src/client/query.tsx +67 -0
- package/src/client/route-api.tsx +75 -0
- package/src/client/router/boundary-tree.tsx +19 -12
- package/src/client/router/context.ts +57 -4
- package/src/client/router/index.ts +3 -0
- package/src/client/router/link-utils.ts +29 -1
- package/src/client/router/navigation.ts +3 -50
- package/src/client/router/optimistic.ts +233 -0
- package/src/client/router/provider.tsx +306 -46
- package/src/client/router/search/index.ts +37 -17
- package/src/client/router/search-store.ts +4 -0
- package/src/client/router/sync-catch-up.ts +7 -0
- package/src/client/router/types.ts +73 -9
- package/src/client/sync.ts +438 -65
- package/src/client.ts +20 -60
- package/src/config.ts +5 -0
- package/src/define-route.ts +113 -55
- package/src/env.d.ts +2 -2
- package/src/furin.ts +75 -13
- package/src/plugin/hmr-dependencies.ts +58 -0
- package/src/plugin/index.ts +38 -2
- package/src/plugin/routes.ts +28 -16
- package/src/plugin/transform-client-module.ts +123 -0
- package/src/plugin/transform-client.ts +293 -13
- package/src/plugin/transform-isomorphic.ts +11 -5
- package/src/routes.ts +8 -0
- package/src/rsc/shared.tsx +104 -18
- package/src/server/auto-invalidate/registry.ts +4 -0
- package/src/server/auto-invalidate/runtime.ts +17 -0
- package/src/server/auto-invalidate/types.ts +6 -0
- package/src/server/cache/isr.ts +6 -34
- package/src/server/cache/route-cache.ts +40 -4
- package/src/server/dev/graph.ts +16 -2
- package/src/server/dev-page-plugin.ts +93 -59
- package/src/server/internal.ts +3 -0
- package/src/server/render/document.tsx +10 -1
- package/src/server/render/element.tsx +21 -11
- package/src/server/render/isr.ts +61 -29
- package/src/server/render/loaders.ts +118 -47
- package/src/server/render/mixed-cache.ts +33 -4
- package/src/server/render/not-found.ts +4 -7
- package/src/server/render/ppr-document.ts +2 -1
- package/src/server/render/ppr-route.ts +30 -10
- package/src/server/render/react-stream.ts +17 -0
- package/src/server/render/route-frame-transport.ts +3 -0
- package/src/server/render/ssg.ts +51 -18
- package/src/server/render/ssr.ts +53 -8
- package/src/server/render/template.ts +23 -0
- package/src/server/router/defined-route.ts +3 -0
- package/src/server/router/discovery.ts +25 -9
- package/src/server/router/hmr.ts +3 -2
- package/src/server/router/patterns.ts +16 -0
- package/src/server/router/plugin.ts +27 -12
- package/src/server/router/types.ts +1 -1
- package/src/server/sync/adapter.ts +41 -4
- package/src/server/sync/atomic.ts +303 -0
- package/src/server/sync/drizzle/index.ts +145 -0
- package/src/server/sync/execution-error.ts +1 -0
- package/src/server/sync/fingerprint.ts +2 -6
- package/src/server/sync/index.ts +6 -0
- package/src/server/sync/mutation-handler.ts +69 -0
- package/src/server/sync/plugin.ts +177 -60
- package/src/server/sync/postgres/execute.ts +20 -0
- package/src/server/sync/postgres/index.ts +52 -16
- package/src/server/sync/postgres/sql.ts +20 -0
- package/src/server/sync/prisma/index.ts +70 -0
- package/src/server/sync/queries.ts +75 -0
- package/src/server/sync/query-context.ts +85 -0
- package/src/server/sync/redis/index.ts +7 -3
- package/src/server/sync/redis/scripts.ts +1 -1
- package/src/server/sync/response.ts +21 -0
- package/src/server/sync/sqlite/index.ts +19 -8
- package/src/server/sync/stream.ts +14 -22
- package/src/server/sync/validation.ts +34 -0
- package/src/shared/defer.ts +48 -0
- package/src/shared/error.ts +2 -2
- package/src/shared/page-key.ts +36 -0
- package/src/shared/query-bindings.ts +138 -0
- package/src/shared/route-frame.ts +13 -1
- package/src/shared/route-map.ts +12 -2
- package/src/shared/sync-query.ts +138 -0
package/dist/build/index.js
CHANGED
|
@@ -71,6 +71,12 @@ function routeSegmentToPattern(segment) {
|
|
|
71
71
|
}
|
|
72
72
|
return dynamic.catchAll ? "*" : `:${dynamic.name}`;
|
|
73
73
|
}
|
|
74
|
+
function isRouteGroup(segment) {
|
|
75
|
+
return ROUTE_GROUP_RE.test(segment);
|
|
76
|
+
}
|
|
77
|
+
function routePatternKey(pattern) {
|
|
78
|
+
return pattern.replace(DYNAMIC_ROUTE_SEGMENT_RE, "$1:param");
|
|
79
|
+
}
|
|
74
80
|
function filePathToPattern(path) {
|
|
75
81
|
const parts = path.replaceAll("\\", "/").split("/");
|
|
76
82
|
const segments = [];
|
|
@@ -82,6 +88,9 @@ function filePathToPattern(path) {
|
|
|
82
88
|
}
|
|
83
89
|
const isFile = idx === lastIndex;
|
|
84
90
|
const name = isFile ? parse(part).name : part;
|
|
91
|
+
if (!isFile && isRouteGroup(name)) {
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
85
94
|
if (isFile && name === "index") {
|
|
86
95
|
continue;
|
|
87
96
|
}
|
|
@@ -176,9 +185,11 @@ function buildRouteMatcher(routes) {
|
|
|
176
185
|
return null;
|
|
177
186
|
};
|
|
178
187
|
}
|
|
179
|
-
var DYNAMIC_PARAMETER_NAME_RE, REGEX_META_CHARS_RE;
|
|
188
|
+
var DYNAMIC_PARAMETER_NAME_RE, ROUTE_GROUP_RE, DYNAMIC_ROUTE_SEGMENT_RE, REGEX_META_CHARS_RE;
|
|
180
189
|
var init_patterns = __esm(() => {
|
|
181
190
|
DYNAMIC_PARAMETER_NAME_RE = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
191
|
+
ROUTE_GROUP_RE = /^\([^()]+\)$/;
|
|
192
|
+
DYNAMIC_ROUTE_SEGMENT_RE = /(^|\/):[^/]+/g;
|
|
182
193
|
REGEX_META_CHARS_RE = /[.*+?^${}()|[\]\\]/;
|
|
183
194
|
});
|
|
184
195
|
|
|
@@ -289,7 +300,7 @@ var init_instance = __esm(() => {
|
|
|
289
300
|
// src/server/dev/graph.ts
|
|
290
301
|
import { randomUUID } from "crypto";
|
|
291
302
|
import { readFileSync, statSync } from "fs";
|
|
292
|
-
import { dirname as dirname5, extname, resolve as resolve3 } from "path";
|
|
303
|
+
import { dirname as dirname5, extname, isAbsolute as isAbsolute2, resolve as resolve3 } from "path";
|
|
293
304
|
function normalizeModulePath(path) {
|
|
294
305
|
return path.replaceAll("\\", "/");
|
|
295
306
|
}
|
|
@@ -302,7 +313,7 @@ function resolveDevSourceImports(source, path, loader) {
|
|
|
302
313
|
const isSourceExtension = [".js", ".jsx", ".ts", ".tsx"].includes(extension);
|
|
303
314
|
const absolute = imported.path.startsWith(".") && extension && !isSourceExtension ? resolve3(dirname5(path), imported.path) : Bun.resolveSync(imported.path, dirname5(path));
|
|
304
315
|
const resolved = normalizeModulePath(absolute);
|
|
305
|
-
if (!resolved.includes("/node_modules/")) {
|
|
316
|
+
if (isAbsolute2(resolved) && !resolved.includes("/node_modules/")) {
|
|
306
317
|
imports.push(resolved);
|
|
307
318
|
}
|
|
308
319
|
} catch {}
|
|
@@ -448,6 +459,19 @@ class DevGraph {
|
|
|
448
459
|
const normalizedTo = normalizeModulePath(to);
|
|
449
460
|
return this.importChain(from, normalizedTo).includes(normalizedTo);
|
|
450
461
|
}
|
|
462
|
+
sourceDependencies(from) {
|
|
463
|
+
const pending = [normalizeModulePath(from)];
|
|
464
|
+
const visited = new Set;
|
|
465
|
+
while (pending.length > 0) {
|
|
466
|
+
const path = pending.pop();
|
|
467
|
+
if (path === undefined || visited.has(path)) {
|
|
468
|
+
continue;
|
|
469
|
+
}
|
|
470
|
+
visited.add(path);
|
|
471
|
+
pending.push(...this.#dependencies.get(path) ?? []);
|
|
472
|
+
}
|
|
473
|
+
return [...visited];
|
|
474
|
+
}
|
|
451
475
|
clearSourceErrors(path) {
|
|
452
476
|
const modulePath = normalizeModulePath(path);
|
|
453
477
|
for (const [message, positions] of this.#sourceErrors) {
|
|
@@ -3224,6 +3248,87 @@ var init_dead_code_elimination = __esm(() => {
|
|
|
3224
3248
|
]);
|
|
3225
3249
|
});
|
|
3226
3250
|
|
|
3251
|
+
// src/plugin/transform-client-module.ts
|
|
3252
|
+
import { realpathSync as realpathSync2 } from "fs";
|
|
3253
|
+
import { dirname as dirname7 } from "path";
|
|
3254
|
+
function clientModuleKey(modulePath) {
|
|
3255
|
+
const realPath = realpathSync2(modulePath).replaceAll("\\", "/");
|
|
3256
|
+
return `__FURIN_CLIENT_MODULE_${Bun.hash(realPath).toString(36)}__`;
|
|
3257
|
+
}
|
|
3258
|
+
function collectClientModuleBindings(program) {
|
|
3259
|
+
const bindings = new Set;
|
|
3260
|
+
for (const statement of program.body) {
|
|
3261
|
+
if (statement.type !== "ImportDeclaration") {
|
|
3262
|
+
continue;
|
|
3263
|
+
}
|
|
3264
|
+
const declaration = statement;
|
|
3265
|
+
if (declaration.importKind === "type" || !FURIN_CLIENT_MODULES.has(String(declaration.source.value))) {
|
|
3266
|
+
continue;
|
|
3267
|
+
}
|
|
3268
|
+
for (const specifier of declaration.specifiers) {
|
|
3269
|
+
const imported = specifier.imported;
|
|
3270
|
+
const local = specifier.local;
|
|
3271
|
+
if (specifier.type === "ImportSpecifier" && specifier.importKind !== "type" && imported?.name === "clientModule" && typeof local?.name === "string") {
|
|
3272
|
+
bindings.add(local.name);
|
|
3273
|
+
}
|
|
3274
|
+
}
|
|
3275
|
+
}
|
|
3276
|
+
return bindings;
|
|
3277
|
+
}
|
|
3278
|
+
function dynamicImportSpecifier(loader) {
|
|
3279
|
+
if (loader.type !== "ArrowFunctionExpression" || loader.params.length > 0) {
|
|
3280
|
+
return null;
|
|
3281
|
+
}
|
|
3282
|
+
const body = loader.body;
|
|
3283
|
+
const source = body.type === "ImportExpression" ? body.source : null;
|
|
3284
|
+
return source?.type === "Literal" && typeof source.value === "string" ? source.value : null;
|
|
3285
|
+
}
|
|
3286
|
+
function transformClientModules(source, filename, environment) {
|
|
3287
|
+
if (!source.includes("clientModule")) {
|
|
3288
|
+
return source;
|
|
3289
|
+
}
|
|
3290
|
+
const { program } = parseSource(source, detectLangFromPath(filename));
|
|
3291
|
+
const bindings = collectClientModuleBindings(program);
|
|
3292
|
+
if (bindings.size === 0) {
|
|
3293
|
+
return source;
|
|
3294
|
+
}
|
|
3295
|
+
const transformed = new MagicString(source);
|
|
3296
|
+
walk(program, {
|
|
3297
|
+
CallExpression(node, context) {
|
|
3298
|
+
const call = node;
|
|
3299
|
+
const [loader, ...rest] = call.arguments;
|
|
3300
|
+
if (call.callee.type !== "Identifier" || !bindings.has(call.callee.name) || hasShadowingDeclaration(call.callee.name, context.ancestors()) || !loader || rest.length > 0) {
|
|
3301
|
+
return;
|
|
3302
|
+
}
|
|
3303
|
+
const unwrapped = unwrapTSExpression(loader);
|
|
3304
|
+
const specifier = dynamicImportSpecifier(unwrapped);
|
|
3305
|
+
if (specifier === null) {
|
|
3306
|
+
return;
|
|
3307
|
+
}
|
|
3308
|
+
let key;
|
|
3309
|
+
try {
|
|
3310
|
+
key = JSON.stringify(clientModuleKey(Bun.resolveSync(specifier, dirname7(filename))));
|
|
3311
|
+
} catch (error) {
|
|
3312
|
+
throw new Error(`[furin] Cannot resolve clientModule import ${JSON.stringify(specifier)} in ${filename}`, { cause: error });
|
|
3313
|
+
}
|
|
3314
|
+
if (environment === "client") {
|
|
3315
|
+
transformed.appendLeft(loader.end, `, ${key}`);
|
|
3316
|
+
} else {
|
|
3317
|
+
transformed.overwrite(loader.start, loader.end, `${SERVER_LOAD}, ${key}`);
|
|
3318
|
+
}
|
|
3319
|
+
}
|
|
3320
|
+
});
|
|
3321
|
+
return transformed.toString();
|
|
3322
|
+
}
|
|
3323
|
+
var FURIN_CLIENT_MODULES, SERVER_LOAD = '() => Promise.reject(new Error("[furin] clientModule() can only be loaded in the browser."))';
|
|
3324
|
+
var init_transform_client_module = __esm(() => {
|
|
3325
|
+
init_dist();
|
|
3326
|
+
init_dist2();
|
|
3327
|
+
init_lang_detect();
|
|
3328
|
+
init_parser();
|
|
3329
|
+
FURIN_CLIENT_MODULES = new Set(["@teyik0/furin/client", "furin/client"]);
|
|
3330
|
+
});
|
|
3331
|
+
|
|
3227
3332
|
// src/plugin/transform-isomorphic.ts
|
|
3228
3333
|
function importedName(specifier) {
|
|
3229
3334
|
const { imported } = specifier;
|
|
@@ -3444,11 +3549,13 @@ function assertStaticEnvironmentMethods(source, filename, program, bindings, bui
|
|
|
3444
3549
|
}
|
|
3445
3550
|
});
|
|
3446
3551
|
}
|
|
3447
|
-
function transformIsomorphicFunctions(
|
|
3552
|
+
function transformIsomorphicFunctions(input, filename, environment) {
|
|
3448
3553
|
const lang = detectLangFromPath(filename);
|
|
3449
3554
|
if (lang === "dts") {
|
|
3450
|
-
return { code:
|
|
3555
|
+
return { code: input, map: null, transformed: false };
|
|
3451
3556
|
}
|
|
3557
|
+
const source = transformClientModules(input, filename, environment);
|
|
3558
|
+
const clientModulesTransformed = source !== input;
|
|
3452
3559
|
const { program, diagnostics } = parseSource(source, lang);
|
|
3453
3560
|
const firstError = diagnostics.find((diagnostic) => diagnostic.severity === "error");
|
|
3454
3561
|
if (firstError) {
|
|
@@ -3460,7 +3567,7 @@ function transformIsomorphicFunctions(source, filename, environment) {
|
|
|
3460
3567
|
assertNoSplitChains(source, filename, program, builders);
|
|
3461
3568
|
const candidates = collectCandidates(source, filename, program, bindings);
|
|
3462
3569
|
if (candidates.length === 0) {
|
|
3463
|
-
return { code: source, map: null, transformed:
|
|
3570
|
+
return { code: source, map: null, transformed: clientModulesTransformed };
|
|
3464
3571
|
}
|
|
3465
3572
|
const transformed = new MagicString(source);
|
|
3466
3573
|
for (const candidate of candidates) {
|
|
@@ -3478,7 +3585,8 @@ function isomorphicTransformPlugin(environment) {
|
|
|
3478
3585
|
return {
|
|
3479
3586
|
name: `furin-isomorphic-${environment}`,
|
|
3480
3587
|
setup(build) {
|
|
3481
|
-
build.onLoad({ filter: SCRIPT_FILE_FILTER }, async (
|
|
3588
|
+
build.onLoad({ filter: SCRIPT_FILE_FILTER }, async (args) => {
|
|
3589
|
+
const path = args.path.split("?")[0];
|
|
3482
3590
|
const source = await Bun.file(path).text();
|
|
3483
3591
|
const loader = detectLoaderFromPath(path);
|
|
3484
3592
|
const result = transformIsomorphicFunctions(source, path, environment);
|
|
@@ -3497,8 +3605,9 @@ var init_transform_isomorphic = __esm(() => {
|
|
|
3497
3605
|
init_lang_detect();
|
|
3498
3606
|
init_parser();
|
|
3499
3607
|
init_dead_code_elimination();
|
|
3608
|
+
init_transform_client_module();
|
|
3500
3609
|
FURIN_MODULES = new Set(["@teyik0/furin", "furin"]);
|
|
3501
|
-
SCRIPT_FILE_FILTER = /^(?!.*(?:node_modules|[\\/]\.furin[\\/]build[\\/])).*\.(tsx?|jsx?)
|
|
3610
|
+
SCRIPT_FILE_FILTER = /^(?!.*(?:node_modules|[\\/]\.furin[\\/]build[\\/])).*\.(tsx?|jsx?)(?:\?.*)?$/;
|
|
3502
3611
|
});
|
|
3503
3612
|
|
|
3504
3613
|
// src/server/sync/config.ts
|
|
@@ -3578,6 +3687,9 @@ class AutoInvalidateRegistry {
|
|
|
3578
3687
|
}
|
|
3579
3688
|
return [...paths];
|
|
3580
3689
|
}
|
|
3690
|
+
tagsForPath(path) {
|
|
3691
|
+
return [...this.pathToTags.get(path) ?? []];
|
|
3692
|
+
}
|
|
3581
3693
|
unregisterPath(urlPath, owner) {
|
|
3582
3694
|
if (owner === undefined) {
|
|
3583
3695
|
this.pathOwners.delete(urlPath);
|
|
@@ -3631,7 +3743,14 @@ function matchesPath(urlPath, path, type) {
|
|
|
3631
3743
|
}
|
|
3632
3744
|
function createRouteCache(options) {
|
|
3633
3745
|
const store = new Map;
|
|
3746
|
+
const generations = new Map;
|
|
3634
3747
|
const pathFromKey = options.pathFromKey ?? defaultPathFromKey;
|
|
3748
|
+
const invalidateGenerations = (key) => {
|
|
3749
|
+
for (const generation of generations.get(key) ?? []) {
|
|
3750
|
+
generation.valid = false;
|
|
3751
|
+
}
|
|
3752
|
+
generations.delete(key);
|
|
3753
|
+
};
|
|
3635
3754
|
const evictOldest = () => {
|
|
3636
3755
|
if (options.maxSize === undefined || store.size <= options.maxSize) {
|
|
3637
3756
|
return;
|
|
@@ -3642,6 +3761,7 @@ function createRouteCache(options) {
|
|
|
3642
3761
|
}
|
|
3643
3762
|
};
|
|
3644
3763
|
const deleteEntry = (key) => {
|
|
3764
|
+
invalidateGenerations(key);
|
|
3645
3765
|
const entry = store.get(key);
|
|
3646
3766
|
if (entry === undefined) {
|
|
3647
3767
|
return false;
|
|
@@ -3651,7 +3771,20 @@ function createRouteCache(options) {
|
|
|
3651
3771
|
return true;
|
|
3652
3772
|
};
|
|
3653
3773
|
return {
|
|
3774
|
+
captureGeneration(key) {
|
|
3775
|
+
const generation = { valid: true };
|
|
3776
|
+
let pending = generations.get(key);
|
|
3777
|
+
if (pending === undefined) {
|
|
3778
|
+
pending = new Set;
|
|
3779
|
+
generations.set(key, pending);
|
|
3780
|
+
}
|
|
3781
|
+
pending.add(generation);
|
|
3782
|
+
return generation;
|
|
3783
|
+
},
|
|
3654
3784
|
clear() {
|
|
3785
|
+
for (const key of generations.keys()) {
|
|
3786
|
+
invalidateGenerations(key);
|
|
3787
|
+
}
|
|
3655
3788
|
for (const key of [...store.keys()]) {
|
|
3656
3789
|
deleteEntry(key);
|
|
3657
3790
|
}
|
|
@@ -3677,14 +3810,15 @@ function createRouteCache(options) {
|
|
|
3677
3810
|
invalidatePath(path, type) {
|
|
3678
3811
|
let deleted = false;
|
|
3679
3812
|
const purgedPaths = [];
|
|
3680
|
-
for (const key of [...store.keys()]) {
|
|
3813
|
+
for (const key of new Set([...store.keys(), ...generations.keys()])) {
|
|
3681
3814
|
const urlPath = pathFromKey(key);
|
|
3682
3815
|
if (urlPath === null || !matchesPath(urlPath, path, type)) {
|
|
3683
3816
|
continue;
|
|
3684
3817
|
}
|
|
3685
|
-
deleteEntry(key)
|
|
3686
|
-
|
|
3687
|
-
|
|
3818
|
+
if (deleteEntry(key)) {
|
|
3819
|
+
deleted = true;
|
|
3820
|
+
purgedPaths.push(urlPath);
|
|
3821
|
+
}
|
|
3688
3822
|
}
|
|
3689
3823
|
return { deleted, purgedPaths: [...new Set(purgedPaths)] };
|
|
3690
3824
|
},
|
|
@@ -3692,6 +3826,13 @@ function createRouteCache(options) {
|
|
|
3692
3826
|
return store.keys();
|
|
3693
3827
|
},
|
|
3694
3828
|
name: options.name,
|
|
3829
|
+
releaseGeneration(key, generation) {
|
|
3830
|
+
const pending = generations.get(key);
|
|
3831
|
+
pending?.delete(generation);
|
|
3832
|
+
if (pending?.size === 0) {
|
|
3833
|
+
generations.delete(key);
|
|
3834
|
+
}
|
|
3835
|
+
},
|
|
3695
3836
|
set(key, entry) {
|
|
3696
3837
|
const previous = store.get(key);
|
|
3697
3838
|
if (previous !== undefined) {
|
|
@@ -3728,7 +3869,7 @@ var init_registry2 = __esm(() => {
|
|
|
3728
3869
|
instanceInvalidators = instanceSlot(() => new Map);
|
|
3729
3870
|
});
|
|
3730
3871
|
|
|
3731
|
-
// ../../node_modules/.bun/evlog@2.29.0+
|
|
3872
|
+
// ../../node_modules/.bun/evlog@2.29.0+e419d84a67dec76a/node_modules/evlog/dist/utils.mjs
|
|
3732
3873
|
function elapsedMs(startTime) {
|
|
3733
3874
|
return Math.max(0, Date.now() - startTime);
|
|
3734
3875
|
}
|
|
@@ -3869,7 +4010,7 @@ var init_utils = __esm(() => {
|
|
|
3869
4010
|
_isoDate = /* @__PURE__ */ new Date;
|
|
3870
4011
|
});
|
|
3871
4012
|
|
|
3872
|
-
// ../../node_modules/.bun/evlog@2.29.0+
|
|
4013
|
+
// ../../node_modules/.bun/evlog@2.29.0+e419d84a67dec76a/node_modules/evlog/dist/redact-C7FmdhwI.mjs
|
|
3873
4014
|
function normalizeRedactPathPattern(pattern) {
|
|
3874
4015
|
if (!pattern.includes("*") && !pattern.includes("."))
|
|
3875
4016
|
return `**.${pattern}`;
|
|
@@ -4178,7 +4319,7 @@ var init_redact_C7FmdhwI = __esm(() => {
|
|
|
4178
4319
|
globallyRedacted = Symbol.for("evlog.globallyRedacted");
|
|
4179
4320
|
});
|
|
4180
4321
|
|
|
4181
|
-
// ../../node_modules/.bun/evlog@2.29.0+
|
|
4322
|
+
// ../../node_modules/.bun/evlog@2.29.0+e419d84a67dec76a/node_modules/evlog/dist/globalRegistry-Bh3bIGwA.mjs
|
|
4182
4323
|
function logPluginError(name, hook, err) {
|
|
4183
4324
|
console.error(`[evlog/${name}] ${hook} failed:`, err);
|
|
4184
4325
|
}
|
|
@@ -4348,7 +4489,7 @@ var init_globalRegistry_Bh3bIGwA = __esm(() => {
|
|
|
4348
4489
|
globalConfig = getRegistry().config;
|
|
4349
4490
|
});
|
|
4350
4491
|
|
|
4351
|
-
// ../../node_modules/.bun/evlog@2.29.0+
|
|
4492
|
+
// ../../node_modules/.bun/evlog@2.29.0+e419d84a67dec76a/node_modules/evlog/dist/pretty-error-D8rlWNL1.mjs
|
|
4352
4493
|
function pushTreeSpacer(children) {
|
|
4353
4494
|
children.push(PRETTY_ERROR_TREE_SPACER);
|
|
4354
4495
|
}
|
|
@@ -4649,7 +4790,7 @@ var init_pretty_error_D8rlWNL1 = __esm(() => {
|
|
|
4649
4790
|
SKIP_FRAME_FN_RE = /^(?:createError|EvlogError|new EvlogError)$/;
|
|
4650
4791
|
});
|
|
4651
4792
|
|
|
4652
|
-
// ../../node_modules/.bun/evlog@2.29.0+
|
|
4793
|
+
// ../../node_modules/.bun/evlog@2.29.0+e419d84a67dec76a/node_modules/evlog/dist/dev-terminal-Brarc6vc.mjs
|
|
4653
4794
|
function finalizePrettyError(partial, frameworkOverlay, pretty, inDev) {
|
|
4654
4795
|
const compact = partial.compact ?? (inDev && pretty);
|
|
4655
4796
|
const detail = partial.detail ?? (frameworkOverlay ? "guidance" : "full");
|
|
@@ -4702,7 +4843,7 @@ var init_dev_terminal_Brarc6vc = __esm(() => {
|
|
|
4702
4843
|
};
|
|
4703
4844
|
});
|
|
4704
4845
|
|
|
4705
|
-
// ../../node_modules/.bun/evlog@2.29.0+
|
|
4846
|
+
// ../../node_modules/.bun/evlog@2.29.0+e419d84a67dec76a/node_modules/evlog/dist/wideEventChannel-BUDW48oP.mjs
|
|
4706
4847
|
function hasWideEventPublisher() {
|
|
4707
4848
|
return publisher !== null;
|
|
4708
4849
|
}
|
|
@@ -4718,7 +4859,7 @@ function publishWideEvent(event) {
|
|
|
4718
4859
|
var publisher = null;
|
|
4719
4860
|
var init_wideEventChannel_BUDW48oP = () => {};
|
|
4720
4861
|
|
|
4721
|
-
// ../../node_modules/.bun/evlog@2.29.0+
|
|
4862
|
+
// ../../node_modules/.bun/evlog@2.29.0+e419d84a67dec76a/node_modules/evlog/dist/error-brand-D0-DCPvr.mjs
|
|
4722
4863
|
function isEvlogError(error) {
|
|
4723
4864
|
return typeof error === "object" && error !== null && error[evlogErrorBrand] === true;
|
|
4724
4865
|
}
|
|
@@ -4727,7 +4868,7 @@ var init_error_brand_D0_DCPvr = __esm(() => {
|
|
|
4727
4868
|
evlogErrorBrand = Symbol.for("evlog.error.brand");
|
|
4728
4869
|
});
|
|
4729
4870
|
|
|
4730
|
-
// ../../node_modules/.bun/evlog@2.29.0+
|
|
4871
|
+
// ../../node_modules/.bun/evlog@2.29.0+e419d84a67dec76a/node_modules/evlog/dist/error.mjs
|
|
4731
4872
|
var evlogErrorInternalKey, evlogErrorDataKey, EvlogError;
|
|
4732
4873
|
var init_error = __esm(() => {
|
|
4733
4874
|
init_utils();
|
|
@@ -4836,7 +4977,7 @@ var init_error = __esm(() => {
|
|
|
4836
4977
|
});
|
|
4837
4978
|
});
|
|
4838
4979
|
|
|
4839
|
-
// ../../node_modules/.bun/evlog@2.29.0+
|
|
4980
|
+
// ../../node_modules/.bun/evlog@2.29.0+e419d84a67dec76a/node_modules/evlog/dist/headers-Bx1ieR-m.mjs
|
|
4840
4981
|
function extractSafeHeaders(headers) {
|
|
4841
4982
|
const raw = {};
|
|
4842
4983
|
headers.forEach((value, key) => {
|
|
@@ -4857,7 +4998,7 @@ var init_headers_Bx1ieR_m = __esm(() => {
|
|
|
4857
4998
|
init_utils();
|
|
4858
4999
|
});
|
|
4859
5000
|
|
|
4860
|
-
// ../../node_modules/.bun/evlog@2.29.0+
|
|
5001
|
+
// ../../node_modules/.bun/evlog@2.29.0+e419d84a67dec76a/node_modules/evlog/dist/audit-C8euLMvu.mjs
|
|
4861
5002
|
function writePrettyStdout(text) {
|
|
4862
5003
|
(globalThis.__evlogNativeStdoutWrite ?? nativeStdoutWrite)?.(text);
|
|
4863
5004
|
}
|
|
@@ -5779,12 +5920,12 @@ var init_audit_C8euLMvu = __esm(() => {
|
|
|
5779
5920
|
initLogger(__EVLOG_CONFIG__);
|
|
5780
5921
|
});
|
|
5781
5922
|
|
|
5782
|
-
// ../../node_modules/.bun/evlog@2.29.0+
|
|
5923
|
+
// ../../node_modules/.bun/evlog@2.29.0+e419d84a67dec76a/node_modules/evlog/dist/index.mjs
|
|
5783
5924
|
var init_dist3 = __esm(() => {
|
|
5784
5925
|
init_audit_C8euLMvu();
|
|
5785
5926
|
});
|
|
5786
5927
|
|
|
5787
|
-
// ../../node_modules/.bun/evlog@2.29.0+
|
|
5928
|
+
// ../../node_modules/.bun/evlog@2.29.0+e419d84a67dec76a/node_modules/evlog/dist/streamResponse-OlirMA5P.mjs
|
|
5788
5929
|
function shouldDeferEmitForResponse(response) {
|
|
5789
5930
|
if (!response.body)
|
|
5790
5931
|
return false;
|
|
@@ -5864,7 +6005,7 @@ function bindStreamingResponseLifecycle(response, onComplete) {
|
|
|
5864
6005
|
}
|
|
5865
6006
|
var init_streamResponse_OlirMA5P = () => {};
|
|
5866
6007
|
|
|
5867
|
-
// ../../node_modules/.bun/evlog@2.29.0+
|
|
6008
|
+
// ../../node_modules/.bun/evlog@2.29.0+e419d84a67dec76a/node_modules/evlog/dist/errors-CL8dDgIi.mjs
|
|
5868
6009
|
function extractErrorStatus(error) {
|
|
5869
6010
|
if (error === null || typeof error !== "object")
|
|
5870
6011
|
return 500;
|
|
@@ -5874,7 +6015,7 @@ function extractErrorStatus(error) {
|
|
|
5874
6015
|
}
|
|
5875
6016
|
var init_errors_CL8dDgIi = () => {};
|
|
5876
6017
|
|
|
5877
|
-
// ../../node_modules/.bun/evlog@2.29.0+
|
|
6018
|
+
// ../../node_modules/.bun/evlog@2.29.0+e419d84a67dec76a/node_modules/evlog/dist/deferred-drain-CfRYimo5.mjs
|
|
5878
6019
|
function shouldLog(path, include, exclude) {
|
|
5879
6020
|
if (exclude && exclude.length > 0) {
|
|
5880
6021
|
if (exclude.some((pattern) => matchesPattern(path, pattern)))
|
|
@@ -5902,7 +6043,7 @@ var init_deferred_drain_CfRYimo5 = __esm(() => {
|
|
|
5902
6043
|
init_utils();
|
|
5903
6044
|
});
|
|
5904
6045
|
|
|
5905
|
-
// ../../node_modules/.bun/evlog@2.29.0+
|
|
6046
|
+
// ../../node_modules/.bun/evlog@2.29.0+e419d84a67dec76a/node_modules/evlog/dist/middleware-fam3VyaL.mjs
|
|
5906
6047
|
function resolveMiddlewarePluginRunner(options) {
|
|
5907
6048
|
const global2 = getGlobalPluginRunner();
|
|
5908
6049
|
const local = options.plugins;
|
|
@@ -6097,7 +6238,7 @@ var init_middleware_fam3VyaL = __esm(() => {
|
|
|
6097
6238
|
runnerCache = /* @__PURE__ */ new WeakMap;
|
|
6098
6239
|
});
|
|
6099
6240
|
|
|
6100
|
-
// ../../node_modules/.bun/evlog@2.29.0+
|
|
6241
|
+
// ../../node_modules/.bun/evlog@2.29.0+e419d84a67dec76a/node_modules/evlog/dist/integration-CGD18W8r.mjs
|
|
6101
6242
|
function attachForkToLogger(storage, parent, middlewareOptions, lifecycle) {
|
|
6102
6243
|
const log = parent;
|
|
6103
6244
|
log.fork = (label, fn) => {
|
|
@@ -6200,7 +6341,7 @@ var init_integration_CGD18W8r = __esm(() => {
|
|
|
6200
6341
|
init_middleware_fam3VyaL();
|
|
6201
6342
|
});
|
|
6202
6343
|
|
|
6203
|
-
// ../../node_modules/.bun/evlog@2.29.0+
|
|
6344
|
+
// ../../node_modules/.bun/evlog@2.29.0+e419d84a67dec76a/node_modules/evlog/dist/toolkit/storage.mjs
|
|
6204
6345
|
import { AsyncLocalStorage as AsyncLocalStorage3 } from "async_hooks";
|
|
6205
6346
|
function createLoggerStorage(contextHint, id = contextHint) {
|
|
6206
6347
|
const storage = getSharedStorage(id, () => new AsyncLocalStorage3);
|
|
@@ -6219,7 +6360,7 @@ var init_storage = __esm(() => {
|
|
|
6219
6360
|
init_globalRegistry_Bh3bIGwA();
|
|
6220
6361
|
});
|
|
6221
6362
|
|
|
6222
|
-
// ../../node_modules/.bun/evlog@2.29.0+
|
|
6363
|
+
// ../../node_modules/.bun/evlog@2.29.0+e419d84a67dec76a/node_modules/evlog/dist/toolkit.mjs
|
|
6223
6364
|
var init_toolkit = __esm(() => {
|
|
6224
6365
|
init_integration_CGD18W8r();
|
|
6225
6366
|
init_storage();
|
|
@@ -6588,12 +6729,12 @@ var extensionErrorFilterScript = `window.addEventListener("unhandledrejection",
|
|
|
6588
6729
|
var init_plugin2 = () => {};
|
|
6589
6730
|
|
|
6590
6731
|
// src/build/index.ts
|
|
6591
|
-
import { existsSync as
|
|
6592
|
-
import { join as
|
|
6732
|
+
import { existsSync as existsSync16, writeFileSync as writeFileSync12 } from "fs";
|
|
6733
|
+
import { join as join18, relative as relative11, resolve as resolve12 } from "path";
|
|
6593
6734
|
|
|
6594
6735
|
// src/adapter/bun.ts
|
|
6595
|
-
import { existsSync as
|
|
6596
|
-
import { join as
|
|
6736
|
+
import { existsSync as existsSync11, readFileSync as readFileSync8, rmSync as rmSync2, writeFileSync as writeFileSync8 } from "fs";
|
|
6737
|
+
import { join as join13, resolve as resolve9 } from "path";
|
|
6597
6738
|
|
|
6598
6739
|
// src/build/bun-build.ts
|
|
6599
6740
|
function runBunBuild(config) {
|
|
@@ -6663,6 +6804,7 @@ function buildAppContextBlock(app, varPrefix) {
|
|
|
6663
6804
|
const deploymentTargetLine = app.deploymentTarget === undefined ? "" : ` deploymentTarget: ${JSON.stringify(app.deploymentTarget)},`;
|
|
6664
6805
|
const serveAssetsLine = app.serveAssets === undefined ? "" : ` serveAssets: ${JSON.stringify(app.serveAssets)},`;
|
|
6665
6806
|
const ssgCacheLine = app.ssgCache ? ` ssgCache: ${JSON.stringify(app.ssgCache)},` : "";
|
|
6807
|
+
const preloadManifestLine = app.preloadManifest ? ` preloadManifest: ${JSON.stringify(app.preloadManifest)},` : "";
|
|
6666
6808
|
const templateHtmlLine = app.templateHtml === undefined ? "" : ` templateHtml: ${JSON.stringify(app.templateHtml)},`;
|
|
6667
6809
|
const contextLines = [
|
|
6668
6810
|
"__setCompileContext({",
|
|
@@ -6682,6 +6824,7 @@ function buildAppContextBlock(app, varPrefix) {
|
|
|
6682
6824
|
routeMetadataLine,
|
|
6683
6825
|
serveAssetsLine,
|
|
6684
6826
|
ssgCacheLine,
|
|
6827
|
+
preloadManifestLine,
|
|
6685
6828
|
templateHtmlLine,
|
|
6686
6829
|
...app.extraContext ?? [],
|
|
6687
6830
|
"});"
|
|
@@ -6840,11 +6983,16 @@ function prepareCompileEntryApps(options) {
|
|
|
6840
6983
|
}
|
|
6841
6984
|
|
|
6842
6985
|
// src/build/elysia-aot.ts
|
|
6843
|
-
import { dirname as dirname2, resolve } from "path";
|
|
6844
|
-
import {
|
|
6986
|
+
import { dirname as dirname2, join as join4, resolve } from "path";
|
|
6987
|
+
import { fileURLToPath as fileURLToPath3 } from "url";
|
|
6988
|
+
import { Worker } from "worker_threads";
|
|
6845
6989
|
var AOT_NAMESPACE = "furin-elysia-aot";
|
|
6846
6990
|
var ELYSIA_RESOLVE_DIR = dirname2(Bun.resolveSync("elysia", import.meta.dir));
|
|
6991
|
+
var AOT_WORKER_PATH = join4(dirname2(dirname2(fileURLToPath3(import.meta.resolve("@teyik0/furin")))), "src/build/elysia-aot-worker.ts");
|
|
6847
6992
|
var SOURCE_FILTER = /\.[cm]?[jt]sx?$/;
|
|
6993
|
+
var ELYSIA_IMPORT_FILTER = /^elysia(?:\/(?!compiled$|type$).*)?$/;
|
|
6994
|
+
var ELYSIA_VIRTUAL_IMPORT_FILTER = /^elysia\/(?:compiled|type)$/;
|
|
6995
|
+
var ANY_MODULE_FILTER = /.*/;
|
|
6848
6996
|
var WEBSOCKET_STUB_MARKER = "[elysia-aot] WebSocket route builder was stripped (strip mode) but a WS route was used.";
|
|
6849
6997
|
function loaderFor(path) {
|
|
6850
6998
|
const extension = path.slice(path.lastIndexOf("."));
|
|
@@ -6872,44 +7020,88 @@ export function handleWSResponse(){return e()}
|
|
|
6872
7020
|
}
|
|
6873
7021
|
function elysiaAot(entry) {
|
|
6874
7022
|
const entryPath = resolve(entry);
|
|
6875
|
-
const hooks = aotFactory({ entry, strip: false, target: "bun" });
|
|
6876
7023
|
return {
|
|
6877
7024
|
name: "elysia-aot",
|
|
6878
7025
|
async setup(build) {
|
|
7026
|
+
const worker = new Worker(AOT_WORKER_PATH, { workerData: { entry: entryPath } });
|
|
7027
|
+
const pending = new Map;
|
|
7028
|
+
let nextId = 0;
|
|
7029
|
+
let workerFailure;
|
|
7030
|
+
const fail = (error) => {
|
|
7031
|
+
workerFailure = error;
|
|
7032
|
+
for (const request of pending.values()) {
|
|
7033
|
+
request.reject(error);
|
|
7034
|
+
}
|
|
7035
|
+
pending.clear();
|
|
7036
|
+
};
|
|
7037
|
+
worker.on("message", (response) => {
|
|
7038
|
+
const request = pending.get(response.id);
|
|
7039
|
+
pending.delete(response.id);
|
|
7040
|
+
if (response.ok) {
|
|
7041
|
+
request?.resolve(response);
|
|
7042
|
+
} else {
|
|
7043
|
+
request?.reject(response.error);
|
|
7044
|
+
}
|
|
7045
|
+
});
|
|
7046
|
+
worker.on("error", fail);
|
|
7047
|
+
worker.on("exit", (code) => fail(new Error(`[furin] Elysia AOT worker exited (${code}).`)));
|
|
7048
|
+
const request = (payload) => new Promise((resolveResponse, reject) => {
|
|
7049
|
+
if (workerFailure) {
|
|
7050
|
+
reject(workerFailure);
|
|
7051
|
+
return;
|
|
7052
|
+
}
|
|
7053
|
+
const id = nextId;
|
|
7054
|
+
nextId += 1;
|
|
7055
|
+
pending.set(id, { reject, resolve: resolveResponse });
|
|
7056
|
+
worker.postMessage({ ...payload, id });
|
|
7057
|
+
});
|
|
7058
|
+
let compiled;
|
|
7059
|
+
let virtualType;
|
|
6879
7060
|
try {
|
|
6880
|
-
await
|
|
7061
|
+
({ code: compiled, virtualType } = await request({ method: "start" }));
|
|
6881
7062
|
} catch (error) {
|
|
7063
|
+
await worker.terminate();
|
|
6882
7064
|
if (error instanceof Error && error.message.startsWith("[elysia-aot]") && error.message.includes("mounts a sub-app")) {
|
|
6883
7065
|
console.warn("[furin] Elysia AOT skipped because the app uses .mount().");
|
|
6884
7066
|
return;
|
|
6885
7067
|
}
|
|
6886
7068
|
throw error;
|
|
6887
7069
|
}
|
|
7070
|
+
build.onEnd(async () => {
|
|
7071
|
+
try {
|
|
7072
|
+
await request({ method: "end" });
|
|
7073
|
+
} finally {
|
|
7074
|
+
await worker.terminate();
|
|
7075
|
+
}
|
|
7076
|
+
});
|
|
6888
7077
|
const entrySource = await Bun.file(entryPath).text();
|
|
6889
|
-
const transformedEntry = await
|
|
7078
|
+
const { code: transformedEntry } = await request({
|
|
7079
|
+
code: entrySource,
|
|
7080
|
+
method: "transform",
|
|
7081
|
+
path: entryPath
|
|
7082
|
+
});
|
|
6890
7083
|
if (transformedEntry !== undefined) {
|
|
6891
7084
|
await Bun.write(entryPath, transformedEntry);
|
|
6892
7085
|
}
|
|
6893
|
-
build.onResolve({ filter:
|
|
7086
|
+
build.onResolve({ filter: ELYSIA_IMPORT_FILTER }, ({ path }) => ({
|
|
6894
7087
|
path: Bun.resolveSync(path, ELYSIA_RESOLVE_DIR)
|
|
6895
7088
|
}));
|
|
6896
|
-
build.onResolve({ filter:
|
|
6897
|
-
|
|
6898
|
-
|
|
7089
|
+
build.onResolve({ filter: ELYSIA_VIRTUAL_IMPORT_FILTER }, ({ path }) => {
|
|
7090
|
+
if (path === "elysia/type" && virtualType === undefined) {
|
|
7091
|
+
return;
|
|
7092
|
+
}
|
|
7093
|
+
return { namespace: AOT_NAMESPACE, path };
|
|
6899
7094
|
});
|
|
6900
|
-
build.onLoad({ filter:
|
|
6901
|
-
const contents =
|
|
7095
|
+
build.onLoad({ filter: ANY_MODULE_FILTER, namespace: AOT_NAMESPACE }, ({ path }) => {
|
|
7096
|
+
const contents = path === "elysia/compiled" ? compiled : virtualType;
|
|
6902
7097
|
return contents === undefined ? undefined : { contents, loader: "js", resolveDir: ELYSIA_RESOLVE_DIR };
|
|
6903
7098
|
});
|
|
6904
7099
|
build.onLoad({ filter: SOURCE_FILTER }, async ({ path }) => {
|
|
6905
7100
|
if (resolve(path) === entryPath) {
|
|
6906
7101
|
return;
|
|
6907
7102
|
}
|
|
6908
|
-
if (hooks.transformInclude?.(path) === false) {
|
|
6909
|
-
return;
|
|
6910
|
-
}
|
|
6911
7103
|
const original = await Bun.file(path).text();
|
|
6912
|
-
const transformed = await
|
|
7104
|
+
const { code: transformed } = await request({ code: original, method: "transform", path });
|
|
6913
7105
|
if (transformed === undefined) {
|
|
6914
7106
|
return;
|
|
6915
7107
|
}
|
|
@@ -6918,23 +7110,20 @@ function elysiaAot(entry) {
|
|
|
6918
7110
|
loader: loaderFor(path)
|
|
6919
7111
|
};
|
|
6920
7112
|
});
|
|
6921
|
-
build.onEnd(() => {
|
|
6922
|
-
hooks.buildEnd?.();
|
|
6923
|
-
});
|
|
6924
7113
|
}
|
|
6925
7114
|
};
|
|
6926
7115
|
}
|
|
6927
7116
|
|
|
6928
7117
|
// src/build/private-server-sourcemaps.ts
|
|
6929
7118
|
import { existsSync as existsSync4, renameSync } from "fs";
|
|
6930
|
-
import { dirname as dirname3, isAbsolute, join as
|
|
7119
|
+
import { dirname as dirname3, isAbsolute, join as join5, relative as relative2 } from "path";
|
|
6931
7120
|
function movePrivateServerSourceMaps(outputDir, privateDir, filenames) {
|
|
6932
7121
|
for (const filename of filenames) {
|
|
6933
|
-
const source = isAbsolute(filename) ? filename :
|
|
7122
|
+
const source = isAbsolute(filename) ? filename : join5(outputDir, filename);
|
|
6934
7123
|
if (!existsSync4(source)) {
|
|
6935
7124
|
continue;
|
|
6936
7125
|
}
|
|
6937
|
-
const destination =
|
|
7126
|
+
const destination = join5(privateDir, relative2(outputDir, source));
|
|
6938
7127
|
ensureDir(dirname3(destination));
|
|
6939
7128
|
renameSync(source, destination);
|
|
6940
7129
|
}
|
|
@@ -6945,9 +7134,9 @@ import { dirname as dirname4, relative as relative3, resolve as resolve2 } from
|
|
|
6945
7134
|
var INSTRUMENTATION_IMPORT = /(?:^|[/\\])devtools[/\\]instrumentation(?:\.ts|\.js)?$/;
|
|
6946
7135
|
var DEV_PAGE_PLUGIN_IMPORT = /(?:^|[/\\])server[/\\]dev-page-plugin(?:\.ts|\.js)?$/;
|
|
6947
7136
|
var DEV_RUNTIME_IMPORT = /(?:^|[/\\])server[/\\]dev[/\\](?:browser-events|diagnostics|graph|plugin)(?:\.ts|\.js)?$/;
|
|
6948
|
-
var DEV_BUILD_IMPORT = /(?:^|[/\\])(?:build[/\\]hydrate|plugin[/\\]route-config-autofix)(?:\.ts|\.js)?$/;
|
|
7137
|
+
var DEV_BUILD_IMPORT = /(?:^|[/\\])(?:build[/\\]hydrate|plugin[/\\](?:route-config-autofix|transform-client))(?:\.ts|\.js)?$/;
|
|
6949
7138
|
var HMR_IMPORT = /(?:^|[/\\])server[/\\]router[/\\]hmr(?:\.ts|\.js)?$/;
|
|
6950
|
-
var PRODUCTION_BOUNDARY_IMPORT = /(?:browser-events|instrumentation|dev-page-plugin|diagnostics|graph|plugin|hmr|hydrate|route-config-autofix)(?:\.ts|\.js)?$/;
|
|
7139
|
+
var PRODUCTION_BOUNDARY_IMPORT = /(?:browser-events|instrumentation|dev-page-plugin|diagnostics|graph|plugin|hmr|hydrate|route-config-autofix|transform-client)(?:\.ts|\.js)?$/;
|
|
6951
7140
|
var PRODUCTION_STUB_NAMESPACE = "furin-production-runtime-stub";
|
|
6952
7141
|
var FURIN_RUNTIME_ROOT = resolve2(import.meta.dir, "..");
|
|
6953
7142
|
function isFurinRuntimePath(path) {
|
|
@@ -6955,6 +7144,9 @@ function isFurinRuntimePath(path) {
|
|
|
6955
7144
|
return fromRuntimeRoot !== ".." && !fromRuntimeRoot.startsWith("../") && !fromRuntimeRoot.startsWith("..\\");
|
|
6956
7145
|
}
|
|
6957
7146
|
function devBuildExport(path) {
|
|
7147
|
+
if (path.includes("transform-client")) {
|
|
7148
|
+
return "getHmrDataSignature";
|
|
7149
|
+
}
|
|
6958
7150
|
return path.includes("route-config-autofix") ? "fixRouteConfigLayout" : "writeDevFiles";
|
|
6959
7151
|
}
|
|
6960
7152
|
function productionInstrumentationPlugin() {
|
|
@@ -6996,7 +7188,7 @@ function productionInstrumentationPlugin() {
|
|
|
6996
7188
|
|
|
6997
7189
|
// src/build/server-app-entry.ts
|
|
6998
7190
|
import { writeFileSync } from "fs";
|
|
6999
|
-
import { join as
|
|
7191
|
+
import { join as join7 } from "path";
|
|
7000
7192
|
|
|
7001
7193
|
// src/plugin/routes.ts
|
|
7002
7194
|
import {
|
|
@@ -7007,13 +7199,24 @@ import {
|
|
|
7007
7199
|
statSync as statSync2,
|
|
7008
7200
|
watch
|
|
7009
7201
|
} from "fs";
|
|
7010
|
-
import { dirname as dirname6, extname as extname2, isAbsolute as
|
|
7202
|
+
import { dirname as dirname6, extname as extname2, isAbsolute as isAbsolute3, join as join6, relative as relative4, resolve as resolve4, sep } from "path";
|
|
7011
7203
|
import { pathToFileURL } from "url";
|
|
7012
7204
|
import { Elysia } from "elysia";
|
|
7013
7205
|
|
|
7014
7206
|
// src/shared/elysia-contract.ts
|
|
7015
7207
|
import { Validator } from "elysia";
|
|
7016
7208
|
var TYPEBOX_KIND = Symbol.for("TypeBox.Kind");
|
|
7209
|
+
function getSchemaValidator(schema) {
|
|
7210
|
+
const validator = Validator.create(schema);
|
|
7211
|
+
if (validator === undefined) {
|
|
7212
|
+
return;
|
|
7213
|
+
}
|
|
7214
|
+
return {
|
|
7215
|
+
Check: (value) => validator.Check(value),
|
|
7216
|
+
Errors: (value) => validator.Errors(value),
|
|
7217
|
+
parse: async (value, type) => validator.From ? await validator.From(value, type) : value
|
|
7218
|
+
};
|
|
7219
|
+
}
|
|
7017
7220
|
function isTypeBoxObjectSchema(schema) {
|
|
7018
7221
|
if (schema === null || typeof schema !== "object") {
|
|
7019
7222
|
return false;
|
|
@@ -7187,6 +7390,214 @@ function mergeRouteSchemas(routeChain, key) {
|
|
|
7187
7390
|
}
|
|
7188
7391
|
|
|
7189
7392
|
// src/server/router/schemas.ts
|
|
7393
|
+
function decodeQueryPart(value) {
|
|
7394
|
+
return new URLSearchParams(`value=${value}`).get("value") ?? "";
|
|
7395
|
+
}
|
|
7396
|
+
function parseArrayQueryValue(raw, decoded, repeated) {
|
|
7397
|
+
const rawBracketed = raw.startsWith("[") && raw.endsWith("]");
|
|
7398
|
+
const decodedBracketed = decoded.startsWith("[") && decoded.endsWith("]");
|
|
7399
|
+
if (repeated && !rawBracketed && !decodedBracketed) {
|
|
7400
|
+
return [decoded];
|
|
7401
|
+
}
|
|
7402
|
+
if (decoded === "[]") {
|
|
7403
|
+
return [];
|
|
7404
|
+
}
|
|
7405
|
+
if (rawBracketed) {
|
|
7406
|
+
return raw.slice(1, -1).split(",").map(decodeQueryPart);
|
|
7407
|
+
}
|
|
7408
|
+
if (decodedBracketed) {
|
|
7409
|
+
return decoded.slice(1, -1).split(",");
|
|
7410
|
+
}
|
|
7411
|
+
return raw.includes(",") ? raw.split(",").map(decodeQueryPart) : [decoded];
|
|
7412
|
+
}
|
|
7413
|
+
function parseQueryFromURL(search, arrayKeys) {
|
|
7414
|
+
const query = Object.create(null);
|
|
7415
|
+
if (!arrayKeys) {
|
|
7416
|
+
for (const [key, value] of new URLSearchParams(search)) {
|
|
7417
|
+
query[key] = value;
|
|
7418
|
+
}
|
|
7419
|
+
return query;
|
|
7420
|
+
}
|
|
7421
|
+
for (const pair of search.slice(1).split("&")) {
|
|
7422
|
+
const entry = new URLSearchParams(pair).entries().next().value;
|
|
7423
|
+
if (!entry) {
|
|
7424
|
+
continue;
|
|
7425
|
+
}
|
|
7426
|
+
const [key, value] = entry;
|
|
7427
|
+
if (!arrayKeys[key]) {
|
|
7428
|
+
query[key] = value;
|
|
7429
|
+
continue;
|
|
7430
|
+
}
|
|
7431
|
+
const equalIndex = pair.indexOf("=");
|
|
7432
|
+
const rawValue = equalIndex === -1 ? "" : pair.slice(equalIndex + 1);
|
|
7433
|
+
const previous = query[key];
|
|
7434
|
+
const values = parseArrayQueryValue(rawValue, value, Array.isArray(previous));
|
|
7435
|
+
if (Array.isArray(previous)) {
|
|
7436
|
+
previous.push(...values);
|
|
7437
|
+
} else {
|
|
7438
|
+
query[key] = values;
|
|
7439
|
+
}
|
|
7440
|
+
}
|
|
7441
|
+
return query;
|
|
7442
|
+
}
|
|
7443
|
+
function isObjectSchema(schema) {
|
|
7444
|
+
return !!schema && typeof schema === "object";
|
|
7445
|
+
}
|
|
7446
|
+
function isStandardSchema(schema) {
|
|
7447
|
+
return isObjectSchema(schema) && "~standard" in schema;
|
|
7448
|
+
}
|
|
7449
|
+
function collectQueryArrayKeys(schema) {
|
|
7450
|
+
return collectQueryKeys(schema, "array");
|
|
7451
|
+
}
|
|
7452
|
+
function collectQueryObjectKeys(schema) {
|
|
7453
|
+
return collectQueryKeys(schema, "object");
|
|
7454
|
+
}
|
|
7455
|
+
function collectQueryKeys(schema, type) {
|
|
7456
|
+
if (!isObjectSchema(schema)) {
|
|
7457
|
+
return;
|
|
7458
|
+
}
|
|
7459
|
+
const keys = {};
|
|
7460
|
+
if (isObjectSchema(schema.properties)) {
|
|
7461
|
+
for (const [key, value] of Object.entries(schema.properties)) {
|
|
7462
|
+
if (hasSchemaType(value, type)) {
|
|
7463
|
+
keys[key] = 1;
|
|
7464
|
+
}
|
|
7465
|
+
}
|
|
7466
|
+
}
|
|
7467
|
+
for (const keyword of ["allOf", "anyOf"]) {
|
|
7468
|
+
const members = schema[keyword];
|
|
7469
|
+
if (!Array.isArray(members)) {
|
|
7470
|
+
continue;
|
|
7471
|
+
}
|
|
7472
|
+
for (const member of members) {
|
|
7473
|
+
Object.assign(keys, collectQueryKeys(member, type));
|
|
7474
|
+
}
|
|
7475
|
+
}
|
|
7476
|
+
return Object.keys(keys).length > 0 ? keys : undefined;
|
|
7477
|
+
}
|
|
7478
|
+
function hasSchemaType(schema, type) {
|
|
7479
|
+
if (!isObjectSchema(schema)) {
|
|
7480
|
+
return false;
|
|
7481
|
+
}
|
|
7482
|
+
if (schema.type === type) {
|
|
7483
|
+
return true;
|
|
7484
|
+
}
|
|
7485
|
+
for (const keyword of ["allOf", "anyOf"]) {
|
|
7486
|
+
const members = schema[keyword];
|
|
7487
|
+
if (Array.isArray(members) && members.some((member) => hasSchemaType(member, type))) {
|
|
7488
|
+
return true;
|
|
7489
|
+
}
|
|
7490
|
+
}
|
|
7491
|
+
return false;
|
|
7492
|
+
}
|
|
7493
|
+
function parseJsonQueryObjects(query, objectKeys) {
|
|
7494
|
+
if (!objectKeys) {
|
|
7495
|
+
return query;
|
|
7496
|
+
}
|
|
7497
|
+
const parsed = { ...query };
|
|
7498
|
+
for (const key of Object.keys(objectKeys)) {
|
|
7499
|
+
const value = parsed[key];
|
|
7500
|
+
if (typeof value !== "string") {
|
|
7501
|
+
continue;
|
|
7502
|
+
}
|
|
7503
|
+
try {
|
|
7504
|
+
parsed[key] = JSON.parse(value);
|
|
7505
|
+
} catch {
|
|
7506
|
+
parsed[key] = value;
|
|
7507
|
+
}
|
|
7508
|
+
}
|
|
7509
|
+
return parsed;
|
|
7510
|
+
}
|
|
7511
|
+
function coerceUnionValue(members, value) {
|
|
7512
|
+
for (const member of members) {
|
|
7513
|
+
const candidate = coerceSchemaValue(member, value);
|
|
7514
|
+
const validator = getSchemaValidator(member);
|
|
7515
|
+
if (validator?.Check(candidate)) {
|
|
7516
|
+
return candidate;
|
|
7517
|
+
}
|
|
7518
|
+
}
|
|
7519
|
+
return value;
|
|
7520
|
+
}
|
|
7521
|
+
function coerceObjectValue(properties, value) {
|
|
7522
|
+
const coerced = { ...value };
|
|
7523
|
+
for (const [key, propertySchema] of Object.entries(properties)) {
|
|
7524
|
+
if (key in coerced) {
|
|
7525
|
+
coerced[key] = coerceSchemaValue(propertySchema, coerced[key]);
|
|
7526
|
+
}
|
|
7527
|
+
}
|
|
7528
|
+
return coerced;
|
|
7529
|
+
}
|
|
7530
|
+
function coerceStringValue(schema, value) {
|
|
7531
|
+
if (value.length === 0) {
|
|
7532
|
+
return value;
|
|
7533
|
+
}
|
|
7534
|
+
if (schema.type === "boolean") {
|
|
7535
|
+
if (value === "true") {
|
|
7536
|
+
return true;
|
|
7537
|
+
}
|
|
7538
|
+
if (value === "false") {
|
|
7539
|
+
return false;
|
|
7540
|
+
}
|
|
7541
|
+
return value;
|
|
7542
|
+
}
|
|
7543
|
+
if (schema.type === "number" || schema.type === "integer") {
|
|
7544
|
+
const number = Number(value);
|
|
7545
|
+
if (Number.isFinite(number) && (schema.type !== "integer" || Number.isInteger(number))) {
|
|
7546
|
+
return number;
|
|
7547
|
+
}
|
|
7548
|
+
}
|
|
7549
|
+
return value;
|
|
7550
|
+
}
|
|
7551
|
+
function coerceSchemaValue(schema, value) {
|
|
7552
|
+
if (!isObjectSchema(schema)) {
|
|
7553
|
+
return value;
|
|
7554
|
+
}
|
|
7555
|
+
if (Array.isArray(schema.anyOf)) {
|
|
7556
|
+
return coerceUnionValue(schema.anyOf, value);
|
|
7557
|
+
}
|
|
7558
|
+
if (Array.isArray(schema.allOf)) {
|
|
7559
|
+
return schema.allOf.reduce((candidate, member) => coerceSchemaValue(member, candidate), value);
|
|
7560
|
+
}
|
|
7561
|
+
if (schema.type === "object" && isObjectSchema(schema.properties) && isObjectSchema(value)) {
|
|
7562
|
+
return coerceObjectValue(schema.properties, value);
|
|
7563
|
+
}
|
|
7564
|
+
if (schema.type === "array" && Array.isArray(value)) {
|
|
7565
|
+
return value.map((entry) => coerceSchemaValue(schema.items, entry));
|
|
7566
|
+
}
|
|
7567
|
+
return typeof value === "string" ? coerceStringValue(schema, value) : value;
|
|
7568
|
+
}
|
|
7569
|
+
function coerceRouteInput(schema, value) {
|
|
7570
|
+
return coerceSchemaValue(schema, value);
|
|
7571
|
+
}
|
|
7572
|
+
async function validateRouteInput(input, schema, type) {
|
|
7573
|
+
const inputWithDefaults = isStandardSchema(schema) ? input : applySchemaDefaults(schema, input);
|
|
7574
|
+
const valueToValidate = isStandardSchema(schema) ? inputWithDefaults : coerceRouteInput(schema, inputWithDefaults);
|
|
7575
|
+
const validator = getSchemaValidator(schema);
|
|
7576
|
+
try {
|
|
7577
|
+
const parsed = await validator?.parse(valueToValidate, type);
|
|
7578
|
+
return {
|
|
7579
|
+
ok: true,
|
|
7580
|
+
value: parsed ?? valueToValidate
|
|
7581
|
+
};
|
|
7582
|
+
} catch {
|
|
7583
|
+
return { errors: [...validator?.Errors(valueToValidate) ?? []], ok: false };
|
|
7584
|
+
}
|
|
7585
|
+
}
|
|
7586
|
+
async function parseRouteQuery(url, schema) {
|
|
7587
|
+
if (!schema) {
|
|
7588
|
+
return { ok: true, query: parseQueryFromURL(url.search) };
|
|
7589
|
+
}
|
|
7590
|
+
const rawQuery = isStandardSchema(schema) ? parseQueryFromURL(url.search) : parseJsonQueryObjects(parseQueryFromURL(url.search, collectQueryArrayKeys(schema)), collectQueryObjectKeys(schema));
|
|
7591
|
+
const result = await validateRouteInput(rawQuery, schema, "query");
|
|
7592
|
+
return result.ok ? { ok: true, query: result.value } : result;
|
|
7593
|
+
}
|
|
7594
|
+
async function parseRouteParams(params, schema) {
|
|
7595
|
+
if (!schema) {
|
|
7596
|
+
return { ok: true, params };
|
|
7597
|
+
}
|
|
7598
|
+
const result = await validateRouteInput(params, schema, "params");
|
|
7599
|
+
return result.ok ? { ok: true, params: result.value } : result;
|
|
7600
|
+
}
|
|
7190
7601
|
function createSearchRouteMetadata(routes) {
|
|
7191
7602
|
const metadata = [];
|
|
7192
7603
|
for (const route of routes) {
|
|
@@ -7202,6 +7613,23 @@ function createSearchRouteMetadata(routes) {
|
|
|
7202
7613
|
}
|
|
7203
7614
|
return metadata;
|
|
7204
7615
|
}
|
|
7616
|
+
function applySchemaDefaults(schema, values) {
|
|
7617
|
+
if (!schema || typeof schema !== "object") {
|
|
7618
|
+
return values;
|
|
7619
|
+
}
|
|
7620
|
+
const s = schema;
|
|
7621
|
+
if (s.type !== "object" || !s.properties || typeof s.properties !== "object") {
|
|
7622
|
+
return values;
|
|
7623
|
+
}
|
|
7624
|
+
const result = { ...values };
|
|
7625
|
+
const properties = s.properties;
|
|
7626
|
+
for (const [key, propSchema] of Object.entries(properties)) {
|
|
7627
|
+
if (!(key in result) && propSchema && typeof propSchema === "object" && "default" in propSchema) {
|
|
7628
|
+
result[key] = propSchema.default;
|
|
7629
|
+
}
|
|
7630
|
+
}
|
|
7631
|
+
return result;
|
|
7632
|
+
}
|
|
7205
7633
|
|
|
7206
7634
|
// src/plugin/routes.ts
|
|
7207
7635
|
init_lang_detect();
|
|
@@ -7235,12 +7663,13 @@ function instanceNamespace(instance) {
|
|
|
7235
7663
|
return `${ROUTES_NAMESPACE_PREFIX}-${Bun.hash(instanceKey(instance)).toString(16)}`;
|
|
7236
7664
|
}
|
|
7237
7665
|
function scanRouteFiles(directory, directorySegments, files) {
|
|
7238
|
-
|
|
7666
|
+
const entries = readdirSync2(directory, { withFileTypes: true }).sort((left, right) => left.name.localeCompare(right.name));
|
|
7667
|
+
for (const entry of entries) {
|
|
7239
7668
|
if (entry.isDirectory()) {
|
|
7240
7669
|
if (entry.name.startsWith("_")) {
|
|
7241
7670
|
continue;
|
|
7242
7671
|
}
|
|
7243
|
-
scanRouteFiles(
|
|
7672
|
+
scanRouteFiles(join6(directory, entry.name), [...directorySegments, entry.name], files);
|
|
7244
7673
|
continue;
|
|
7245
7674
|
}
|
|
7246
7675
|
const extension = extname2(entry.name);
|
|
@@ -7248,7 +7677,7 @@ function scanRouteFiles(directory, directorySegments, files) {
|
|
|
7248
7677
|
continue;
|
|
7249
7678
|
}
|
|
7250
7679
|
const base = entry.name.slice(0, -extension.length);
|
|
7251
|
-
const sourcePath =
|
|
7680
|
+
const sourcePath = join6(directory, entry.name);
|
|
7252
7681
|
for (const segment of [...directorySegments, base]) {
|
|
7253
7682
|
parseDynamicRouteSegment(segment, sourcePath);
|
|
7254
7683
|
}
|
|
@@ -7268,9 +7697,6 @@ function scanRouteFiles(directory, directorySegments, files) {
|
|
|
7268
7697
|
function segmentPath(segment) {
|
|
7269
7698
|
return routeSegmentToPattern(segment);
|
|
7270
7699
|
}
|
|
7271
|
-
function routePath(segments) {
|
|
7272
|
-
return segments.length === 0 ? "/" : `/${segments.map(segmentPath).join("/")}`;
|
|
7273
|
-
}
|
|
7274
7700
|
function routeId(instanceId, path) {
|
|
7275
7701
|
const encodedPath = Array.from(new TextEncoder().encode(path), (byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
7276
7702
|
return `_route_${instanceId}_${encodedPath}`;
|
|
@@ -7299,14 +7725,22 @@ function buildRouteTree(pagesDir, instanceId) {
|
|
|
7299
7725
|
return node;
|
|
7300
7726
|
};
|
|
7301
7727
|
const root = ensureNode([]);
|
|
7728
|
+
const seenPatterns = new Map;
|
|
7302
7729
|
for (const file of scannedFiles) {
|
|
7303
7730
|
const node = ensureNode(file.directorySegments);
|
|
7304
7731
|
if (file.base === "_route") {
|
|
7305
|
-
const path =
|
|
7732
|
+
const path = `/${file.directorySegments.map(segmentPath).join("/")}#layout`;
|
|
7306
7733
|
node.layout = { id: routeId(instanceId, path), path: "", sourcePath: file.sourcePath };
|
|
7307
7734
|
continue;
|
|
7308
7735
|
}
|
|
7309
|
-
const path =
|
|
7736
|
+
const path = filePathToPattern(relative4(pagesDir, file.sourcePath));
|
|
7737
|
+
const patternKey = routePatternKey(path);
|
|
7738
|
+
const relativePath = relative4(pagesDir, file.sourcePath).replaceAll("\\", "/");
|
|
7739
|
+
const previousPath = seenPatterns.get(patternKey);
|
|
7740
|
+
if (previousPath !== undefined) {
|
|
7741
|
+
throw new Error(`[furin] Duplicate route pattern "${patternKey}" from "${previousPath}" and "${relativePath}".`);
|
|
7742
|
+
}
|
|
7743
|
+
seenPatterns.set(patternKey, relativePath);
|
|
7310
7744
|
const route = { id: routeId(instanceId, path), path, sourcePath: file.sourcePath };
|
|
7311
7745
|
if (file.base === "index") {
|
|
7312
7746
|
node.indexRoute = route;
|
|
@@ -7341,7 +7775,7 @@ function routeSourcePaths(instance) {
|
|
|
7341
7775
|
}
|
|
7342
7776
|
function emitRouteNode(node, indentation, includeRootCatchAll) {
|
|
7343
7777
|
const childIndentation = `${indentation} `;
|
|
7344
|
-
const prefix = node.name ? `/${segmentPath(node.name)}` : "";
|
|
7778
|
+
const prefix = node.name && !isRouteGroup(node.name) ? `/${segmentPath(node.name)}` : "";
|
|
7345
7779
|
const head = `new Elysia({ prefix: ${JSON.stringify(prefix)} })`;
|
|
7346
7780
|
const content = [];
|
|
7347
7781
|
if (node.indexRoute) {
|
|
@@ -7450,16 +7884,16 @@ function findPackageRoot(sourcePath) {
|
|
|
7450
7884
|
const fallback = dirname6(sourcePath);
|
|
7451
7885
|
let directory = fallback;
|
|
7452
7886
|
while (dirname6(directory) !== directory) {
|
|
7453
|
-
if (existsSync5(
|
|
7887
|
+
if (existsSync5(join6(directory, "package.json"))) {
|
|
7454
7888
|
return directory;
|
|
7455
7889
|
}
|
|
7456
7890
|
directory = dirname6(directory);
|
|
7457
7891
|
}
|
|
7458
|
-
return existsSync5(
|
|
7892
|
+
return existsSync5(join6(directory, "package.json")) ? directory : fallback;
|
|
7459
7893
|
}
|
|
7460
7894
|
function isWithinDirectory(path, directory) {
|
|
7461
7895
|
const relativePath = relative4(directory, path);
|
|
7462
|
-
return relativePath === "" || !(relativePath.startsWith("..") ||
|
|
7896
|
+
return relativePath === "" || !(relativePath.startsWith("..") || isAbsolute3(relativePath));
|
|
7463
7897
|
}
|
|
7464
7898
|
function isFurinPackageImport(specifier) {
|
|
7465
7899
|
return specifier === "furin" || specifier.startsWith("furin/") || specifier === "@teyik0/furin" || specifier.startsWith("@teyik0/furin/");
|
|
@@ -7477,7 +7911,7 @@ function resolveRouteModuleImports(dependencyPath, packageRoot) {
|
|
|
7477
7911
|
}
|
|
7478
7912
|
try {
|
|
7479
7913
|
const resolvedImport = realpathSync.native(Bun.resolveSync(imported.path, dirname6(dependencyPath)));
|
|
7480
|
-
if (
|
|
7914
|
+
if (isAbsolute3(resolvedImport) && isWithinDirectory(resolvedImport, packageRoot) && !relative4(packageRoot, resolvedImport).split(sep).includes("node_modules")) {
|
|
7481
7915
|
resolvedImports.push(resolvedImport);
|
|
7482
7916
|
}
|
|
7483
7917
|
} catch {}
|
|
@@ -7551,7 +7985,7 @@ async function clientRoutesSource(instance) {
|
|
|
7551
7985
|
const module = await loadRouteModule(routeFile.sourcePath);
|
|
7552
7986
|
validateRouteParams(routeFile.path, module.route?.schemas);
|
|
7553
7987
|
return {
|
|
7554
|
-
hasLoader: module.route?.loader !== undefined
|
|
7988
|
+
hasLoader: module.route?.loader !== undefined,
|
|
7555
7989
|
mode: module.route?.mode ?? "ssr",
|
|
7556
7990
|
pattern: routeFile.path
|
|
7557
7991
|
};
|
|
@@ -7575,8 +8009,8 @@ function serverProxySource(instance, includeRootCatchAll) {
|
|
|
7575
8009
|
function createRoutesPlugin(options) {
|
|
7576
8010
|
const routeFilesBySpecifier = new Map;
|
|
7577
8011
|
const routeFilesByResolvedPath = new Map;
|
|
7578
|
-
const registryVirtualPath =
|
|
7579
|
-
const composableRegistryVirtualPath =
|
|
8012
|
+
const registryVirtualPath = join6(resolve4(primaryInstance(options.instances).pagesDir), ".furin-routes-registry.ts?furin-virtual");
|
|
8013
|
+
const composableRegistryVirtualPath = join6(resolve4(primaryInstance(options.instances).pagesDir), ".furin-routes-registry-composable.ts?furin-virtual");
|
|
7580
8014
|
const instancesBySpecifier = new Map(options.instances.flatMap((instance) => [
|
|
7581
8015
|
[
|
|
7582
8016
|
routeModuleSpecifier(instance),
|
|
@@ -7657,11 +8091,11 @@ async function materializeServerAppEntry(options) {
|
|
|
7657
8091
|
if (!instance) {
|
|
7658
8092
|
throw new Error(`[furin] Missing route instance for server app ${index}.`);
|
|
7659
8093
|
}
|
|
7660
|
-
const routePath =
|
|
8094
|
+
const routePath = join7(options.outDir, `_furin-routes-${index}.ts`);
|
|
7661
8095
|
writeFileSync(routePath, await materializedRouteModuleSource(instance));
|
|
7662
8096
|
return { ...app, nativeRoutes: toPosixPath(routePath) };
|
|
7663
8097
|
}));
|
|
7664
|
-
const entryPath =
|
|
8098
|
+
const entryPath = join7(options.outDir, "_furin-app.ts");
|
|
7665
8099
|
writeFileSync(entryPath, buildEntrySource({
|
|
7666
8100
|
apps,
|
|
7667
8101
|
headerComment: options.headerComment,
|
|
@@ -7691,7 +8125,7 @@ if (typeof startServer === "function") {
|
|
|
7691
8125
|
init_transform_isomorphic();
|
|
7692
8126
|
|
|
7693
8127
|
// src/rsc/build/environment.ts
|
|
7694
|
-
import { fileURLToPath as
|
|
8128
|
+
import { fileURLToPath as fileURLToPath4 } from "url";
|
|
7695
8129
|
var SERVER_ONLY_RE = /^(?:@teyik0\/)?furin\/server-only$/;
|
|
7696
8130
|
var CLIENT_ONLY_RE = /^(?:@teyik0\/)?furin\/client-only$/;
|
|
7697
8131
|
function environmentGuardPlugin(graph) {
|
|
@@ -7702,13 +8136,13 @@ function environmentGuardPlugin(graph) {
|
|
|
7702
8136
|
if (graph === "client") {
|
|
7703
8137
|
throw new Error(`[furin] ${args.importer} imports furin/server-only from the client graph.`);
|
|
7704
8138
|
}
|
|
7705
|
-
return { path:
|
|
8139
|
+
return { path: fileURLToPath4(import.meta.resolve("../../server-only.ts")) };
|
|
7706
8140
|
});
|
|
7707
8141
|
build.onResolve({ filter: CLIENT_ONLY_RE }, (args) => {
|
|
7708
8142
|
if (graph !== "client") {
|
|
7709
8143
|
throw new Error(`[furin] ${args.importer} imports furin/client-only from the ${graph} graph.`);
|
|
7710
8144
|
}
|
|
7711
|
-
return { path:
|
|
8145
|
+
return { path: fileURLToPath4(import.meta.resolve("../../client-only.ts")) };
|
|
7712
8146
|
});
|
|
7713
8147
|
}
|
|
7714
8148
|
};
|
|
@@ -7740,13 +8174,13 @@ function assertNoPrefixSlugCollisions(prefixes) {
|
|
|
7740
8174
|
}
|
|
7741
8175
|
|
|
7742
8176
|
// src/adapter/runtime-build.ts
|
|
7743
|
-
import { existsSync as
|
|
7744
|
-
import { basename as
|
|
7745
|
-
import { fileURLToPath as
|
|
8177
|
+
import { existsSync as existsSync10, realpathSync as realpathSync4, writeFileSync as writeFileSync7 } from "fs";
|
|
8178
|
+
import { basename as basename5, dirname as dirname11, isAbsolute as isAbsolute5, join as join12, relative as relative7, resolve as resolve8 } from "path";
|
|
8179
|
+
import { fileURLToPath as fileURLToPath6 } from "url";
|
|
7746
8180
|
|
|
7747
8181
|
// src/build/client.ts
|
|
7748
|
-
import { existsSync as
|
|
7749
|
-
import { basename as
|
|
8182
|
+
import { existsSync as existsSync9, mkdirSync as mkdirSync3, writeFileSync as writeFileSync5 } from "fs";
|
|
8183
|
+
import { basename as basename3, dirname as dirname9, join as join10, resolve as resolve7 } from "path";
|
|
7750
8184
|
|
|
7751
8185
|
// src/plugin/transform-client.ts
|
|
7752
8186
|
init_dist();
|
|
@@ -7754,13 +8188,60 @@ init_dist2();
|
|
|
7754
8188
|
init_lang_detect();
|
|
7755
8189
|
init_parser();
|
|
7756
8190
|
init_dead_code_elimination();
|
|
8191
|
+
|
|
8192
|
+
// src/plugin/hmr-dependencies.ts
|
|
8193
|
+
init_lang_detect();
|
|
8194
|
+
import { readFileSync as readFileSync3 } from "fs";
|
|
8195
|
+
import { dirname as dirname8, isAbsolute as isAbsolute4, resolve as resolve5 } from "path";
|
|
8196
|
+
var SCRIPT_FILE = /\.[cm]?[jt]sx?$/;
|
|
8197
|
+
function hmrDependencySignature(imports, filename) {
|
|
8198
|
+
const routePath = resolve5(filename);
|
|
8199
|
+
const visited = new Set;
|
|
8200
|
+
const hash = new Bun.CryptoHasher("sha256");
|
|
8201
|
+
const visit = (specifier, importer) => {
|
|
8202
|
+
if (specifier === "furin" || specifier.startsWith("furin/") || specifier === "@teyik0/furin" || specifier.startsWith("@teyik0/furin/")) {
|
|
8203
|
+
return true;
|
|
8204
|
+
}
|
|
8205
|
+
const path = Bun.resolveSync(specifier, dirname8(importer));
|
|
8206
|
+
if (path === routePath) {
|
|
8207
|
+
return false;
|
|
8208
|
+
}
|
|
8209
|
+
hash.update(JSON.stringify([specifier, path]));
|
|
8210
|
+
if (!isAbsolute4(path) || path.replaceAll("\\", "/").includes("/node_modules/") || visited.has(path)) {
|
|
8211
|
+
return true;
|
|
8212
|
+
}
|
|
8213
|
+
visited.add(path);
|
|
8214
|
+
const source = readFileSync3(path, "utf8");
|
|
8215
|
+
hash.update(source);
|
|
8216
|
+
if (SCRIPT_FILE.test(path)) {
|
|
8217
|
+
const transpiler = new Bun.Transpiler({ loader: detectLoaderFromPath(path) });
|
|
8218
|
+
for (const dependency of transpiler.scanImports(source)) {
|
|
8219
|
+
if (!visit(dependency.path, path)) {
|
|
8220
|
+
return false;
|
|
8221
|
+
}
|
|
8222
|
+
}
|
|
8223
|
+
}
|
|
8224
|
+
return true;
|
|
8225
|
+
};
|
|
8226
|
+
try {
|
|
8227
|
+
for (const specifier of imports) {
|
|
8228
|
+
if (!visit(specifier, routePath)) {
|
|
8229
|
+
return;
|
|
8230
|
+
}
|
|
8231
|
+
}
|
|
8232
|
+
return hash.digest("hex");
|
|
8233
|
+
} catch {}
|
|
8234
|
+
}
|
|
8235
|
+
|
|
8236
|
+
// src/plugin/transform-client.ts
|
|
7757
8237
|
init_transform_isomorphic();
|
|
7758
|
-
var
|
|
8238
|
+
var FURIN_CLIENT_MODULES2 = new Set(["@teyik0/furin/client", "furin/client"]);
|
|
7759
8239
|
var FURIN_SERVER_MODULES = new Set(["@teyik0/furin", "furin"]);
|
|
7760
8240
|
var REACT_COMPONENT_WRAPPERS = new Set(["forwardRef", "memo"]);
|
|
7761
8241
|
var SERVER_ONLY_METHODS = new Set(["config", "head", "loader", "requestLoader", "staticParams"]);
|
|
7762
8242
|
var REACT_HOOK_NAME_RE = /^use[A-Z0-9]/;
|
|
7763
8243
|
var HMR_DATA_SIGNATURE = "furin.hmr.data-signature";
|
|
8244
|
+
var HMR_SOURCE_SIGNATURE = "furin.hmr.source-signature";
|
|
7764
8245
|
var TYPESCRIPT_RUNTIME_WRAPPERS = new Map([
|
|
7765
8246
|
["TSAsExpression", ["expression"]],
|
|
7766
8247
|
["TSInstantiationExpression", ["expression"]],
|
|
@@ -7770,7 +8251,7 @@ var TYPESCRIPT_RUNTIME_WRAPPERS = new Map([
|
|
|
7770
8251
|
["TSTypeAssertion", ["expression"]]
|
|
7771
8252
|
]);
|
|
7772
8253
|
function isFurinRouteModule(source) {
|
|
7773
|
-
return typeof source === "string" && (FURIN_SERVER_MODULES.has(source) ||
|
|
8254
|
+
return typeof source === "string" && (FURIN_SERVER_MODULES.has(source) || FURIN_CLIENT_MODULES2.has(source));
|
|
7774
8255
|
}
|
|
7775
8256
|
function importedName2(specifier) {
|
|
7776
8257
|
const { imported } = specifier;
|
|
@@ -7870,8 +8351,51 @@ function chainRootIsDefineRoute(node, bindings, ancestors) {
|
|
|
7870
8351
|
}
|
|
7871
8352
|
return false;
|
|
7872
8353
|
}
|
|
7873
|
-
function
|
|
8354
|
+
function assertCompleteRouteChains(program, bindings, filename) {
|
|
8355
|
+
const namespaces = new Set;
|
|
8356
|
+
for (const statement of program.body) {
|
|
8357
|
+
if (statement.type !== "ImportDeclaration") {
|
|
8358
|
+
continue;
|
|
8359
|
+
}
|
|
8360
|
+
const declaration = statement;
|
|
8361
|
+
if (!isFurinRouteModule(declaration.source.value) || declaration.importKind === "type") {
|
|
8362
|
+
continue;
|
|
8363
|
+
}
|
|
8364
|
+
for (const specifier of declaration.specifiers) {
|
|
8365
|
+
const name = localName2(specifier);
|
|
8366
|
+
if (name && specifier.type === "ImportNamespaceSpecifier") {
|
|
8367
|
+
namespaces.add(name);
|
|
8368
|
+
}
|
|
8369
|
+
}
|
|
8370
|
+
}
|
|
8371
|
+
walk(program, {
|
|
8372
|
+
MemberExpression(node, context) {
|
|
8373
|
+
const object = asAstNode(node.object);
|
|
8374
|
+
const property = asAstNode(node.property);
|
|
8375
|
+
const method = property?.type === "Identifier" ? property.name : property?.value;
|
|
8376
|
+
if (object?.type === "Identifier" && typeof object.name === "string" && namespaces.has(object.name) && (method === "defineRoute" || method === "defineRootRoute") && !hasShadowingDeclaration(object.name, context.ancestors())) {
|
|
8377
|
+
throw new Error(`[furin] ${filename}: route builders require a named import.`);
|
|
8378
|
+
}
|
|
8379
|
+
if (node.computed && context.parent?.type === "CallExpression" && chainRootIsDefineRoute(node.object, bindings, context.ancestors())) {
|
|
8380
|
+
throw new Error(`[furin] ${filename}: route builders require static builder methods.`);
|
|
8381
|
+
}
|
|
8382
|
+
},
|
|
8383
|
+
VariableDeclarator(node, context) {
|
|
8384
|
+
const initializer = asAstNode(node.init);
|
|
8385
|
+
if (!(initializer && chainRootIsDefineRoute(initializer, bindings, context.ancestors()))) {
|
|
8386
|
+
return;
|
|
8387
|
+
}
|
|
8388
|
+
const callee = initializer.type === "CallExpression" ? asAstNode(initializer.callee) : null;
|
|
8389
|
+
const method = callee?.type === "MemberExpression" ? asAstNode(callee.property) : null;
|
|
8390
|
+
if (method?.type !== "Identifier" || method.name !== "page" && method.name !== "layout") {
|
|
8391
|
+
throw new Error(`[furin] ${filename}: route builders must use one fluent chain ending in .page() or .layout().`);
|
|
8392
|
+
}
|
|
8393
|
+
}
|
|
8394
|
+
});
|
|
8395
|
+
}
|
|
8396
|
+
function removeChainedServerCalls(source, program, bindings, configBindings, filename) {
|
|
7874
8397
|
let transformed = rewriteClientImports(source, program, bindings);
|
|
8398
|
+
const { declarations } = collectModuleBindings(program);
|
|
7875
8399
|
walk(program, {
|
|
7876
8400
|
CallExpression(call, context) {
|
|
7877
8401
|
const callee = asAstNode(call.callee);
|
|
@@ -7886,26 +8410,107 @@ function removeChainedServerCalls(source, program, bindings) {
|
|
|
7886
8410
|
if (!object) {
|
|
7887
8411
|
return;
|
|
7888
8412
|
}
|
|
8413
|
+
if (property.name === "config" && Array.isArray(call.arguments)) {
|
|
8414
|
+
const config = asAstNode(call.arguments[0]);
|
|
8415
|
+
if (config?.type === "ObjectExpression" && Array.isArray(config.properties)) {
|
|
8416
|
+
collectConfigBindings(config, declarations, configBindings);
|
|
8417
|
+
const remount = resolveRemountProperty(config, declarations, configBindings, new Set, filename);
|
|
8418
|
+
if (remount) {
|
|
8419
|
+
source.update(object.end, call.end, `.config({ ${source.original.slice(remount.start, remount.end)} })`);
|
|
8420
|
+
transformed = true;
|
|
8421
|
+
return;
|
|
8422
|
+
}
|
|
8423
|
+
}
|
|
8424
|
+
}
|
|
7889
8425
|
source.remove(object.end, call.end);
|
|
7890
8426
|
transformed = true;
|
|
7891
8427
|
}
|
|
7892
8428
|
});
|
|
7893
8429
|
return transformed;
|
|
7894
8430
|
}
|
|
7895
|
-
function
|
|
7896
|
-
|
|
7897
|
-
|
|
7898
|
-
|
|
8431
|
+
function collectConfigBindings(config, declarations, names) {
|
|
8432
|
+
if (config?.type === "Identifier" && typeof config.name === "string" && !names.has(config.name)) {
|
|
8433
|
+
names.add(config.name);
|
|
8434
|
+
const declaration = declarations.get(config.name);
|
|
8435
|
+
collectConfigBindings(asAstNode(declaration?.init), declarations, names);
|
|
8436
|
+
} else if (config?.type === "ObjectExpression" && Array.isArray(config.properties)) {
|
|
8437
|
+
for (const property of config.properties) {
|
|
8438
|
+
const entry = asAstNode(property);
|
|
8439
|
+
if (entry?.type === "SpreadElement") {
|
|
8440
|
+
collectConfigBindings(asAstNode(entry.argument), declarations, names);
|
|
8441
|
+
}
|
|
8442
|
+
}
|
|
7899
8443
|
}
|
|
7900
|
-
|
|
7901
|
-
|
|
7902
|
-
|
|
8444
|
+
}
|
|
8445
|
+
function resolveRemountProperty(config, declarations, configBindings, visiting, filename) {
|
|
8446
|
+
if (config?.type === "Identifier" && typeof config.name === "string" && !visiting.has(config.name)) {
|
|
8447
|
+
visiting.add(config.name);
|
|
8448
|
+
configBindings.add(config.name);
|
|
8449
|
+
const declaration = declarations.get(config.name);
|
|
8450
|
+
const result = resolveRemountProperty(asAstNode(declaration?.init), declarations, configBindings, visiting, filename);
|
|
8451
|
+
visiting.delete(config.name);
|
|
8452
|
+
return result;
|
|
7903
8453
|
}
|
|
7904
|
-
if (
|
|
7905
|
-
|
|
7906
|
-
return;
|
|
8454
|
+
if (config?.type !== "ObjectExpression" || !Array.isArray(config.properties)) {
|
|
8455
|
+
throw new Error(`[furin] ${filename}: route config spreads must resolve to local object literals; declare remountDeps after dynamic spreads.`);
|
|
7907
8456
|
}
|
|
7908
|
-
|
|
8457
|
+
for (let index = config.properties.length - 1;index >= 0; index -= 1) {
|
|
8458
|
+
const entry = asAstNode(config.properties[index]);
|
|
8459
|
+
if (entry?.type === "SpreadElement") {
|
|
8460
|
+
const remount = resolveRemountProperty(asAstNode(entry.argument), declarations, configBindings, visiting, filename);
|
|
8461
|
+
if (remount) {
|
|
8462
|
+
return remount;
|
|
8463
|
+
}
|
|
8464
|
+
} else if (entry?.type === "Property") {
|
|
8465
|
+
const key = asAstNode(entry.key);
|
|
8466
|
+
if (key?.type === "Identifier" && entry.computed !== true && key.name === "remountDeps" || key?.type === "Literal" && key.value === "remountDeps") {
|
|
8467
|
+
return entry;
|
|
8468
|
+
}
|
|
8469
|
+
}
|
|
8470
|
+
}
|
|
8471
|
+
return null;
|
|
8472
|
+
}
|
|
8473
|
+
function pruneUnusedConfigBindings(source, filename, names) {
|
|
8474
|
+
let result = source;
|
|
8475
|
+
let pruned = true;
|
|
8476
|
+
while (pruned) {
|
|
8477
|
+
pruned = false;
|
|
8478
|
+
const code = result.toString();
|
|
8479
|
+
const { program } = parseSource(code, detectLangFromPath(filename));
|
|
8480
|
+
const references = new Set;
|
|
8481
|
+
walkWithAncestors(program, [], (node, ancestors) => {
|
|
8482
|
+
if (node.type === "Identifier" && typeof node.name === "string" && isReferenceIdentifier(node, ancestors)) {
|
|
8483
|
+
references.add(node.name);
|
|
8484
|
+
}
|
|
8485
|
+
});
|
|
8486
|
+
result = new MagicString(code);
|
|
8487
|
+
for (const statement of program.body) {
|
|
8488
|
+
if (statement.type !== "VariableDeclaration") {
|
|
8489
|
+
continue;
|
|
8490
|
+
}
|
|
8491
|
+
const retained = statement.declarations.filter((declaration) => declaration.id.type !== "Identifier" || !names.has(declaration.id.name) || references.has(declaration.id.name));
|
|
8492
|
+
if (retained.length !== statement.declarations.length) {
|
|
8493
|
+
result.update(statement.start, statement.end, retained.length ? `${statement.kind} ${retained.map((node) => code.slice(node.start, node.end)).join(", ")};` : "");
|
|
8494
|
+
pruned = true;
|
|
8495
|
+
}
|
|
8496
|
+
}
|
|
8497
|
+
}
|
|
8498
|
+
return result;
|
|
8499
|
+
}
|
|
8500
|
+
function collectBindingNames(pattern, names) {
|
|
8501
|
+
const node = asAstNode(pattern);
|
|
8502
|
+
if (!node) {
|
|
8503
|
+
return;
|
|
8504
|
+
}
|
|
8505
|
+
if (node.type === "Identifier" && typeof node.name === "string") {
|
|
8506
|
+
names.push(node.name);
|
|
8507
|
+
return;
|
|
8508
|
+
}
|
|
8509
|
+
if (node.type === "AssignmentPattern") {
|
|
8510
|
+
collectBindingNames(node.left, names);
|
|
8511
|
+
return;
|
|
8512
|
+
}
|
|
8513
|
+
if (node.type === "RestElement") {
|
|
7909
8514
|
collectBindingNames(node.argument, names);
|
|
7910
8515
|
return;
|
|
7911
8516
|
}
|
|
@@ -7943,13 +8548,13 @@ function collectDeclarationBindings(declaration, declarations) {
|
|
|
7943
8548
|
}
|
|
7944
8549
|
function collectModuleBindings(program) {
|
|
7945
8550
|
const declarations = new Map;
|
|
7946
|
-
const imports = new
|
|
8551
|
+
const imports = new Map;
|
|
7947
8552
|
for (const statement of program.body) {
|
|
7948
8553
|
if (statement.type === "ImportDeclaration" && Array.isArray(statement.specifiers)) {
|
|
7949
8554
|
for (const specifier of statement.specifiers) {
|
|
7950
8555
|
const local = localName2(specifier);
|
|
7951
8556
|
if (local) {
|
|
7952
|
-
imports.
|
|
8557
|
+
imports.set(local, statement);
|
|
7953
8558
|
}
|
|
7954
8559
|
}
|
|
7955
8560
|
continue;
|
|
@@ -8037,13 +8642,16 @@ function walkWithAncestors(value, ancestors, visitor) {
|
|
|
8037
8642
|
}
|
|
8038
8643
|
}
|
|
8039
8644
|
function collectDependencyIdentifier(child, ancestors, trackImports, state) {
|
|
8040
|
-
|
|
8645
|
+
const parent = ancestors.at(-1);
|
|
8646
|
+
const jsxReference = child.type === "JSXIdentifier" && (parent?.type === "JSXOpeningElement" && parent.name === child && typeof child.name === "string" && child.name[0] === child.name[0]?.toUpperCase() || parent?.type === "JSXMemberExpression" && parent.object === child);
|
|
8647
|
+
if (!(child.type === "Identifier" || jsxReference) || typeof child.name !== "string" || !isReferenceIdentifier(child, ancestors) || hasShadowingDeclaration(child.name, ancestors)) {
|
|
8041
8648
|
return;
|
|
8042
8649
|
}
|
|
8043
8650
|
const declaration = state.moduleBindings.declarations.get(child.name);
|
|
8044
8651
|
if (!declaration) {
|
|
8045
|
-
|
|
8046
|
-
|
|
8652
|
+
const imported = state.moduleBindings.imports.get(child.name);
|
|
8653
|
+
if (trackImports && imported) {
|
|
8654
|
+
state.imports.add(imported);
|
|
8047
8655
|
}
|
|
8048
8656
|
return;
|
|
8049
8657
|
}
|
|
@@ -8064,13 +8672,20 @@ function collectDependencyIdentifier(child, ancestors, trackImports, state) {
|
|
|
8064
8672
|
function collectDependencies(node, trackImports, state) {
|
|
8065
8673
|
walkWithAncestors(node, [], (child, ancestors) => {
|
|
8066
8674
|
collectDependencyIdentifier(child, ancestors, trackImports, state);
|
|
8675
|
+
if (trackImports && child.type === "ImportExpression") {
|
|
8676
|
+
const specifier = asAstNode(child.source)?.value;
|
|
8677
|
+
if (typeof specifier === "string") {
|
|
8678
|
+
state.dynamicImports.add(specifier);
|
|
8679
|
+
}
|
|
8680
|
+
}
|
|
8067
8681
|
});
|
|
8068
8682
|
}
|
|
8069
|
-
function createHmrDataSignature(code, program, bindings) {
|
|
8683
|
+
function createHmrDataSignature(code, program, bindings, filename) {
|
|
8070
8684
|
const serverStages = [];
|
|
8071
8685
|
const dependencyState = {
|
|
8072
8686
|
dependencies: new Map,
|
|
8073
|
-
|
|
8687
|
+
dynamicImports: new Set,
|
|
8688
|
+
imports: new Set,
|
|
8074
8689
|
importTrackedDependencies: new Set,
|
|
8075
8690
|
moduleBindings: collectModuleBindings(program)
|
|
8076
8691
|
};
|
|
@@ -8104,6 +8719,10 @@ function createHmrDataSignature(code, program, bindings) {
|
|
|
8104
8719
|
});
|
|
8105
8720
|
const dataSource = [
|
|
8106
8721
|
...serverStages,
|
|
8722
|
+
...[...dependencyState.imports].map((imported) => ({
|
|
8723
|
+
source: code.slice(imported.start, imported.end),
|
|
8724
|
+
start: imported.start
|
|
8725
|
+
})),
|
|
8107
8726
|
...[...dependencyState.dependencies.values()].map((dependency) => ({
|
|
8108
8727
|
source: code.slice(dependency.start, dependency.end),
|
|
8109
8728
|
start: dependency.start
|
|
@@ -8111,7 +8730,14 @@ function createHmrDataSignature(code, program, bindings) {
|
|
|
8111
8730
|
].sort((left, right) => left.start - right.start).map((entry) => entry.source).join(`
|
|
8112
8731
|
`);
|
|
8113
8732
|
const hash = new Bun.CryptoHasher("sha256").update(dataSource).digest("hex");
|
|
8114
|
-
|
|
8733
|
+
if (dependencyState.imports.size === 0 && dependencyState.dynamicImports.size === 0) {
|
|
8734
|
+
return hash;
|
|
8735
|
+
}
|
|
8736
|
+
const dependencies = hmrDependencySignature(new Set([
|
|
8737
|
+
...[...dependencyState.imports].map((imported) => imported.source.value),
|
|
8738
|
+
...dependencyState.dynamicImports
|
|
8739
|
+
]), filename);
|
|
8740
|
+
return dependencies === undefined ? `external:${hash}` : `imports:${hash}:${dependencies}`;
|
|
8115
8741
|
}
|
|
8116
8742
|
function calledHookName(call) {
|
|
8117
8743
|
const callee = asAstNode(call.callee);
|
|
@@ -8329,9 +8955,14 @@ function transformForClient(code, filename) {
|
|
|
8329
8955
|
}
|
|
8330
8956
|
let source = new MagicString(clientSource);
|
|
8331
8957
|
const routeBindings = collectDefineRouteBindings(program);
|
|
8332
|
-
|
|
8958
|
+
assertCompleteRouteChains(program, routeBindings, filename);
|
|
8959
|
+
const configBindings = new Set;
|
|
8960
|
+
const removedRouteCode = removeChainedServerCalls(source, program, routeBindings, configBindings, filename);
|
|
8333
8961
|
const removedServerCode = isomorphicResult.transformed || removedRouteCode;
|
|
8334
8962
|
if (removedServerCode) {
|
|
8963
|
+
if (configBindings.size > 0) {
|
|
8964
|
+
source = pruneUnusedConfigBindings(source, filename, configBindings);
|
|
8965
|
+
}
|
|
8335
8966
|
source = deadCodeElimination(source, code, lang);
|
|
8336
8967
|
}
|
|
8337
8968
|
const transformedCode = source.toString();
|
|
@@ -8350,11 +8981,16 @@ function transformForClient(code, filename) {
|
|
|
8350
8981
|
if (originalError) {
|
|
8351
8982
|
throw new Error(`Failed to parse ${filename}: ${originalError.message}`);
|
|
8352
8983
|
}
|
|
8353
|
-
const hmrDataSignature = createHmrDataSignature(code, originalParse.program, collectDefineRouteBindings(originalParse.program));
|
|
8984
|
+
const hmrDataSignature = createHmrDataSignature(code, originalParse.program, collectDefineRouteBindings(originalParse.program), filename);
|
|
8354
8985
|
const signatureValue = Array.isArray(hookSignature) ? JSON.stringify(hookSignature) : 'route.component[Symbol.for("furin.hmr.hook-signature")] ?? [String(route.component)]';
|
|
8355
8986
|
source.append(`
|
|
8356
8987
|
if (import.meta.hot && route?.component) {
|
|
8357
8988
|
const previousDataSignature = ${JSON.stringify(hmrDataSignature)};
|
|
8989
|
+
const previousSourceSignature = ${JSON.stringify(Bun.hash(code).toString(16))};
|
|
8990
|
+
Object.defineProperty(route, Symbol.for(${JSON.stringify(HMR_SOURCE_SIGNATURE)}), {
|
|
8991
|
+
configurable: true,
|
|
8992
|
+
value: previousSourceSignature,
|
|
8993
|
+
});
|
|
8358
8994
|
Object.defineProperty(route, Symbol.for(${JSON.stringify(HMR_DATA_SIGNATURE)}), {
|
|
8359
8995
|
configurable: true,
|
|
8360
8996
|
value: previousDataSignature,
|
|
@@ -8370,10 +9006,14 @@ if (import.meta.hot && route?.component) {
|
|
|
8370
9006
|
updatedRoute,
|
|
8371
9007
|
Symbol.for(${JSON.stringify(HMR_DATA_SIGNATURE)})
|
|
8372
9008
|
);
|
|
9009
|
+
// An unchanged source can be re-evaluated by Bun after an import edit
|
|
9010
|
+
// without rerunning this transform. Its embedded dependency hash is stale.
|
|
8373
9011
|
const dataChanged =
|
|
8374
9012
|
previousDataSignature.startsWith("external:") ||
|
|
8375
9013
|
typeof updatedDataSignature !== "string" ||
|
|
8376
9014
|
updatedDataSignature.startsWith("external:") ||
|
|
9015
|
+
(updatedDataSignature.startsWith("imports:") &&
|
|
9016
|
+
Reflect.get(updatedRoute, Symbol.for(${JSON.stringify(HMR_SOURCE_SIGNATURE)})) === previousSourceSignature) ||
|
|
8377
9017
|
updatedDataSignature !== previousDataSignature;
|
|
8378
9018
|
window.__FURIN_HMR_UPDATE__?.(${JSON.stringify(filename)}, updatedRoute.component, dataChanged);
|
|
8379
9019
|
}
|
|
@@ -8392,8 +9032,8 @@ if (import.meta.hot && route?.component) {
|
|
|
8392
9032
|
init_lang_detect();
|
|
8393
9033
|
|
|
8394
9034
|
// src/build/hydrate.ts
|
|
8395
|
-
import { existsSync as existsSync7, mkdirSync as mkdirSync2, readFileSync as
|
|
8396
|
-
import { join as
|
|
9035
|
+
import { existsSync as existsSync7, mkdirSync as mkdirSync2, readFileSync as readFileSync5, writeFileSync as writeFileSync3 } from "fs";
|
|
9036
|
+
import { join as join9 } from "path";
|
|
8397
9037
|
|
|
8398
9038
|
// src/server/render/shell.ts
|
|
8399
9039
|
function escapeHtml(str) {
|
|
@@ -8447,8 +9087,8 @@ ${buildIdMeta}${modeMeta}${faviconLink}${cssLinks ? `${cssLinks}
|
|
|
8447
9087
|
init_patterns();
|
|
8448
9088
|
|
|
8449
9089
|
// src/build/route-types.ts
|
|
8450
|
-
import { existsSync as existsSync6, readFileSync as
|
|
8451
|
-
import { extname as extname3, join as
|
|
9090
|
+
import { existsSync as existsSync6, readFileSync as readFileSync4, renameSync as renameSync2, writeFileSync as writeFileSync2 } from "fs";
|
|
9091
|
+
import { extname as extname3, join as join8, relative as relative5 } from "path";
|
|
8452
9092
|
|
|
8453
9093
|
// src/shared/route-map.ts
|
|
8454
9094
|
function routeTypeProperty(pattern) {
|
|
@@ -8474,12 +9114,19 @@ function compareRouteProperties(left, right) {
|
|
|
8474
9114
|
return leftProperty < rightProperty ? -1 : 1;
|
|
8475
9115
|
}
|
|
8476
9116
|
function routeMapDeclaration(entries) {
|
|
8477
|
-
const
|
|
9117
|
+
const sorted = entries.toSorted(compareRouteProperties);
|
|
9118
|
+
const body = sorted.map((entry) => ` ${routeTypeProperty(entry.pattern)}: typeof import(${JSON.stringify(entry.importSpecifier)}).route;`).join(`
|
|
9119
|
+
`);
|
|
9120
|
+
const patterns = sorted.map((entry) => ` ${JSON.stringify(entry.pattern)}: typeof import(${JSON.stringify(entry.importSpecifier)}).route;`).join(`
|
|
8478
9121
|
`);
|
|
8479
9122
|
return `declare module "@teyik0/furin/routes" {
|
|
8480
9123
|
interface RouteMap {
|
|
8481
9124
|
${body}
|
|
8482
9125
|
}
|
|
9126
|
+
|
|
9127
|
+
interface RoutePatternMap {
|
|
9128
|
+
${patterns}
|
|
9129
|
+
}
|
|
8483
9130
|
}`;
|
|
8484
9131
|
}
|
|
8485
9132
|
|
|
@@ -8514,8 +9161,8 @@ import "@teyik0/furin/routes";
|
|
|
8514
9161
|
|
|
8515
9162
|
${routeMapDeclaration(entries)}${tagBlock}
|
|
8516
9163
|
`;
|
|
8517
|
-
const typesPath =
|
|
8518
|
-
const existing = existsSync6(typesPath) ?
|
|
9164
|
+
const typesPath = join8(projectRoot, "furin-env.d.ts");
|
|
9165
|
+
const existing = existsSync6(typesPath) ? readFileSync4(typesPath, "utf8") : "";
|
|
8519
9166
|
if (content === existing) {
|
|
8520
9167
|
return false;
|
|
8521
9168
|
}
|
|
@@ -8527,6 +9174,7 @@ ${routeMapDeclaration(entries)}${tagBlock}
|
|
|
8527
9174
|
|
|
8528
9175
|
// src/build/hydrate.ts
|
|
8529
9176
|
function generateHydrateEntry(routes, rootLayout, basePath, clientLogging) {
|
|
9177
|
+
const rootDirectory = rootLayout.replaceAll("\\", "/").split("/").slice(0, -1).join("/");
|
|
8530
9178
|
const getBoundaryIdent = (idents, filePath) => {
|
|
8531
9179
|
if (!filePath) {
|
|
8532
9180
|
return;
|
|
@@ -8567,6 +9215,9 @@ function generateHydrateEntry(routes, rootLayout, basePath, clientLogging) {
|
|
|
8567
9215
|
if (notFoundIdent) {
|
|
8568
9216
|
parts.push(`notFound: ${notFoundIdent}.default`);
|
|
8569
9217
|
}
|
|
9218
|
+
if (seg.depth === 0 && seg.path.replaceAll("\\", "/") !== rootDirectory) {
|
|
9219
|
+
parts.push("isRoot: false");
|
|
9220
|
+
}
|
|
8570
9221
|
boundaryLiterals.push(`{ ${parts.join(", ")} }`);
|
|
8571
9222
|
}
|
|
8572
9223
|
const lazyImports = [
|
|
@@ -8582,7 +9233,7 @@ function generateHydrateEntry(routes, rootLayout, basePath, clientLogging) {
|
|
|
8582
9233
|
}).join(" ");
|
|
8583
9234
|
const boundaryResult = boundaryLiterals.length > 0 ? `, segmentBoundaries: [${boundaryLiterals.join(", ")}]` : "";
|
|
8584
9235
|
const pageComponentKey = JSON.stringify(`page:${resolvedPage}`);
|
|
8585
|
-
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} }; })`;
|
|
9236
|
+
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, remountDeps: __furin_page_route.remountDeps }, component: hotComponent(${pageComponentKey}, __furin_page_route.component) }${boundaryResult} }; })`;
|
|
8586
9237
|
const searchDefaultsEntry = searchDefaults ? `, searchDefaults: ${JSON.stringify(searchDefaults)}` : "";
|
|
8587
9238
|
routeEntries.push(` { pattern: "${route.pattern}", regex: new RegExp(${JSON.stringify(regexPattern)}), load: () => ${loadBody}${searchDefaultsEntry} }`);
|
|
8588
9239
|
}
|
|
@@ -8816,6 +9467,12 @@ if (__deferred && __deferred._chunks) {
|
|
|
8816
9467
|
initialNotFound: loaderData.__furinNotFound ?? {},${routerProviderDefaults}
|
|
8817
9468
|
} as any);
|
|
8818
9469
|
} else {
|
|
9470
|
+
// A removed active route has no match in the new development manifest.
|
|
9471
|
+
// Reload its document so the server can render the current 404 response.
|
|
9472
|
+
if (import.meta.hot && (window as unknown as { __FURIN_ROOT__?: unknown }).__FURIN_ROOT__) {
|
|
9473
|
+
window.location.reload();
|
|
9474
|
+
return;
|
|
9475
|
+
}
|
|
8819
9476
|
// No match and no 404 signal \u2014 either the client bundle is out of sync
|
|
8820
9477
|
// with the server (stale deploy) or the server returned something we
|
|
8821
9478
|
// don't know how to hydrate. Bail loudly; the page stays static.
|
|
@@ -8892,21 +9549,24 @@ if (__deferred && __deferred._chunks) {
|
|
|
8892
9549
|
});
|
|
8893
9550
|
`;
|
|
8894
9551
|
}
|
|
8895
|
-
function writeDevFiles(routes, { outDir, rootLayout, basePath, clientLogging, skipRouteTypes }, projectRoot) {
|
|
9552
|
+
function writeDevFiles(routes, { outDir, rootLayout, basePath, clientLogging, skipRouteTypes }, projectRoot, serverSourceVersion) {
|
|
8896
9553
|
if (!existsSync7(outDir)) {
|
|
8897
9554
|
mkdirSync2(outDir, { recursive: true });
|
|
8898
9555
|
}
|
|
8899
|
-
const
|
|
8900
|
-
|
|
8901
|
-
|
|
9556
|
+
const serverVersion = serverSourceVersion === undefined ? "" : `
|
|
9557
|
+
if (import.meta.hot) import.meta.hot.data.furinServerSourceVersion = ${JSON.stringify(serverSourceVersion)};
|
|
9558
|
+
`;
|
|
9559
|
+
const hydrateCode = generateHydrateEntry(routes, rootLayout, basePath, clientLogging) + serverVersion;
|
|
9560
|
+
const hydratePath = join9(outDir, "_hydrate.tsx");
|
|
9561
|
+
const existingHydrate = existsSync7(hydratePath) ? readFileSync5(hydratePath, "utf8") : "";
|
|
8902
9562
|
let changed = false;
|
|
8903
9563
|
if (hydrateCode !== existingHydrate) {
|
|
8904
9564
|
writeFileSync3(hydratePath, hydrateCode);
|
|
8905
9565
|
changed = true;
|
|
8906
9566
|
}
|
|
8907
9567
|
const indexHtml = generateIndexHtml();
|
|
8908
|
-
const indexPath =
|
|
8909
|
-
const existingIndex = existsSync7(indexPath) ?
|
|
9568
|
+
const indexPath = join9(outDir, "index.html");
|
|
9569
|
+
const existingIndex = existsSync7(indexPath) ? readFileSync5(indexPath, "utf8") : "";
|
|
8910
9570
|
if (indexHtml !== existingIndex) {
|
|
8911
9571
|
writeFileSync3(indexPath, indexHtml);
|
|
8912
9572
|
changed = true;
|
|
@@ -8919,9 +9579,65 @@ function writeDevFiles(routes, { outDir, rootLayout, basePath, clientLogging, sk
|
|
|
8919
9579
|
}
|
|
8920
9580
|
}
|
|
8921
9581
|
|
|
9582
|
+
// src/build/preload-manifest.ts
|
|
9583
|
+
init_transform_client_module();
|
|
9584
|
+
import { existsSync as existsSync8, readFileSync as readFileSync6, realpathSync as realpathSync3, writeFileSync as writeFileSync4 } from "fs";
|
|
9585
|
+
import { basename as basename2, resolve as resolve6 } from "path";
|
|
9586
|
+
var CLIENT_MODULE_KEY_RE = /(["'`])(__FURIN_CLIENT_MODULE_[a-z0-9]+__)\1/g;
|
|
9587
|
+
function routeModulePaths(route) {
|
|
9588
|
+
const layouts = (route.routeChain ?? []).slice(1).filter((entry) => entry.layout && entry.sourcePath).map((entry) => entry.sourcePath);
|
|
9589
|
+
const boundaries = (route.segmentBoundaries ?? []).flatMap((segment) => [segment.errorPath, segment.notFoundPath].filter((path) => path !== undefined));
|
|
9590
|
+
return [route.path, ...layouts, ...boundaries];
|
|
9591
|
+
}
|
|
9592
|
+
function realPath(path) {
|
|
9593
|
+
return existsSync8(path) ? realpathSync3(path) : null;
|
|
9594
|
+
}
|
|
9595
|
+
function writeClientPreloadManifest(metafile, outputPaths, entryChunkPath, routes, publicPrefix) {
|
|
9596
|
+
const outputs = new Map(Object.entries(metafile.outputs).map(([path, output]) => [basename2(path), output]));
|
|
9597
|
+
const closure = (file, seen) => {
|
|
9598
|
+
if (!seen.has(file)) {
|
|
9599
|
+
seen.add(file);
|
|
9600
|
+
for (const imported of outputs.get(file)?.imports ?? []) {
|
|
9601
|
+
if (imported.kind === "import-statement") {
|
|
9602
|
+
closure(basename2(imported.path), seen);
|
|
9603
|
+
}
|
|
9604
|
+
}
|
|
9605
|
+
}
|
|
9606
|
+
return seen;
|
|
9607
|
+
};
|
|
9608
|
+
const entryFiles = closure(basename2(entryChunkPath), new Set);
|
|
9609
|
+
const hrefsOf = (file) => [...closure(file, new Set)].filter((chunk) => !entryFiles.has(chunk)).map((chunk) => `${publicPrefix}${chunk}`);
|
|
9610
|
+
const chunkByModule = new Map;
|
|
9611
|
+
for (const [file, output] of outputs) {
|
|
9612
|
+
const modulePath = output.entryPoint ? realPath(resolve6(output.entryPoint)) : null;
|
|
9613
|
+
if (modulePath !== null) {
|
|
9614
|
+
chunkByModule.set(modulePath, file);
|
|
9615
|
+
}
|
|
9616
|
+
}
|
|
9617
|
+
const routeManifest = {};
|
|
9618
|
+
for (const route of routes) {
|
|
9619
|
+
const files = routeModulePaths(route).map((path) => chunkByModule.get(realPath(path) ?? path)).filter((file) => file !== undefined);
|
|
9620
|
+
routeManifest[route.pattern] = [...new Set(files.flatMap(hrefsOf))];
|
|
9621
|
+
}
|
|
9622
|
+
const moduleHrefs = new Map([...chunkByModule].map(([modulePath, file]) => [clientModuleKey(modulePath), file]));
|
|
9623
|
+
const modules = {};
|
|
9624
|
+
for (const path of outputPaths.filter((output) => output.endsWith(".js"))) {
|
|
9625
|
+
const code = readFileSync6(path, "utf8");
|
|
9626
|
+
const rewritten = code.replace(CLIENT_MODULE_KEY_RE, (_match, _quote, key) => {
|
|
9627
|
+
const file = moduleHrefs.get(key);
|
|
9628
|
+
modules[key] = file === undefined ? [] : hrefsOf(file);
|
|
9629
|
+
return JSON.stringify(modules[key]);
|
|
9630
|
+
});
|
|
9631
|
+
if (rewritten !== code) {
|
|
9632
|
+
writeFileSync4(path, rewritten);
|
|
9633
|
+
}
|
|
9634
|
+
}
|
|
9635
|
+
return { modules, routes: routeManifest };
|
|
9636
|
+
}
|
|
9637
|
+
|
|
8922
9638
|
// src/build/client.ts
|
|
8923
9639
|
var SCRIPT_FILE_FILTER2 = /\.(tsx?|jsx?)$/;
|
|
8924
|
-
var ROUTER_PROVIDER_PATH =
|
|
9640
|
+
var ROUTER_PROVIDER_PATH = resolve7(import.meta.dir, "../client/router/provider.tsx");
|
|
8925
9641
|
function resolveClientModuleSpecifiers(code) {
|
|
8926
9642
|
return code.replaceAll(`"@teyik0/furin/client"`, JSON.stringify(CLIENT_MODULE_PATH)).replaceAll(`'furin/client'`, JSON.stringify(CLIENT_MODULE_PATH)).replaceAll(`"@teyik0/furin/link"`, JSON.stringify(LINK_MODULE_PATH)).replaceAll(`'furin/link'`, JSON.stringify(LINK_MODULE_PATH)).replaceAll(`"@teyik0/furin/search"`, JSON.stringify(SEARCH_MODULE_PATH)).replaceAll(`'furin/search'`, JSON.stringify(SEARCH_MODULE_PATH));
|
|
8927
9643
|
}
|
|
@@ -8929,6 +9645,7 @@ async function buildClient(routes, {
|
|
|
8929
9645
|
outDir,
|
|
8930
9646
|
rootLayout,
|
|
8931
9647
|
plugins,
|
|
9648
|
+
preloadRouteChunks,
|
|
8932
9649
|
publicPath,
|
|
8933
9650
|
basePath,
|
|
8934
9651
|
clientLogging,
|
|
@@ -8939,15 +9656,15 @@ async function buildClient(routes, {
|
|
|
8939
9656
|
pagesDir
|
|
8940
9657
|
}) {
|
|
8941
9658
|
const dirName = clientDirName ?? "client";
|
|
8942
|
-
const clientDir =
|
|
8943
|
-
if (!
|
|
9659
|
+
const clientDir = join10(outDir, dirName);
|
|
9660
|
+
if (!existsSync9(outDir)) {
|
|
8944
9661
|
mkdirSync3(outDir, { recursive: true });
|
|
8945
9662
|
}
|
|
8946
|
-
if (!
|
|
9663
|
+
if (!existsSync9(clientDir)) {
|
|
8947
9664
|
mkdirSync3(clientDir, { recursive: true });
|
|
8948
9665
|
}
|
|
8949
9666
|
const hydrateCode = resolveClientModuleSpecifiers(generateHydrateEntry(routes, rootLayout, basePath, clientLogging));
|
|
8950
|
-
const hydratePath =
|
|
9667
|
+
const hydratePath = join10(outDir, dirName === "client" ? "_hydrate.tsx" : `_hydrate-${dirName}.tsx`);
|
|
8951
9668
|
const hydrateEntry = createVirtualBuildEntry(hydratePath, hydrateCode, "tsx");
|
|
8952
9669
|
console.log("[furin] Building production client bundle\u2026");
|
|
8953
9670
|
const transformPlugin = {
|
|
@@ -8987,6 +9704,7 @@ async function buildClient(routes, {
|
|
|
8987
9704
|
files: hydrateEntry.files,
|
|
8988
9705
|
outdir: clientDir,
|
|
8989
9706
|
target: "browser",
|
|
9707
|
+
env: "FURIN_PUBLIC_*",
|
|
8990
9708
|
format: "esm",
|
|
8991
9709
|
splitting: true,
|
|
8992
9710
|
optimizeImports,
|
|
@@ -8994,7 +9712,7 @@ async function buildClient(routes, {
|
|
|
8994
9712
|
reactCompilerOutputMode: "client",
|
|
8995
9713
|
minify: true,
|
|
8996
9714
|
sourcemap: "none",
|
|
8997
|
-
metafile:
|
|
9715
|
+
metafile: true,
|
|
8998
9716
|
naming: {
|
|
8999
9717
|
entry: "[name]-[hash].[ext]",
|
|
9000
9718
|
chunk: "[name]-[hash].[ext]"
|
|
@@ -9014,16 +9732,17 @@ async function buildClient(routes, {
|
|
|
9014
9732
|
"@teyik0/furin/search": SEARCH_MODULE_PATH
|
|
9015
9733
|
},
|
|
9016
9734
|
define: {
|
|
9735
|
+
...Object.fromEntries(Object.entries(process.env).filter(([name, value]) => name.startsWith("FURIN_PUBLIC_") && value !== undefined).map(([name, value]) => [`process.env.${name}`, JSON.stringify(value)])),
|
|
9017
9736
|
"process.env.NODE_ENV": JSON.stringify("production")
|
|
9018
9737
|
}
|
|
9019
9738
|
};
|
|
9020
9739
|
const result = await runBunBuild(clientBuildConfig);
|
|
9740
|
+
if (result.metafile === undefined) {
|
|
9741
|
+
throw new Error("[furin] client build did not produce the requested metafile");
|
|
9742
|
+
}
|
|
9021
9743
|
if (metafilePath !== undefined) {
|
|
9022
|
-
|
|
9023
|
-
|
|
9024
|
-
}
|
|
9025
|
-
mkdirSync3(dirname7(metafilePath), { recursive: true });
|
|
9026
|
-
writeFileSync4(metafilePath, `${JSON.stringify(result.metafile, null, 2)}
|
|
9744
|
+
mkdirSync3(dirname9(metafilePath), { recursive: true });
|
|
9745
|
+
writeFileSync5(metafilePath, `${JSON.stringify(result.metafile, null, 2)}
|
|
9027
9746
|
`);
|
|
9028
9747
|
console.log(`[furin] Client metafile: ${metafilePath}`);
|
|
9029
9748
|
}
|
|
@@ -9041,10 +9760,11 @@ async function buildClient(routes, {
|
|
|
9041
9760
|
} else {
|
|
9042
9761
|
publicPrefix = publicPath.endsWith("/") ? publicPath : `${publicPath}/`;
|
|
9043
9762
|
}
|
|
9044
|
-
const entryChunk = `${publicPrefix}${
|
|
9045
|
-
const cssChunks = cssOutputs.map((o) => `${publicPrefix}${
|
|
9763
|
+
const entryChunk = `${publicPrefix}${basename3(entryOutput.path)}`;
|
|
9764
|
+
const cssChunks = cssOutputs.map((o) => `${publicPrefix}${basename3(o.path)}`);
|
|
9765
|
+
const preloadManifest = writeClientPreloadManifest(result.metafile, result.outputs.map((output) => output.path), entryOutput.path, preloadRouteChunks === false ? [] : routes, publicPrefix);
|
|
9046
9766
|
console.log("[furin] Production client build complete");
|
|
9047
|
-
return { entryChunk, cssChunks };
|
|
9767
|
+
return { entryChunk, cssChunks, preloadManifest };
|
|
9048
9768
|
}
|
|
9049
9769
|
|
|
9050
9770
|
// src/server/render/assemble.ts
|
|
@@ -9073,6 +9793,65 @@ async function streamToString(stream) {
|
|
|
9073
9793
|
html += decoder.decode();
|
|
9074
9794
|
return html;
|
|
9075
9795
|
}
|
|
9796
|
+
// src/shared/sync-query.ts
|
|
9797
|
+
function mergeQuerySeeds(target, incoming) {
|
|
9798
|
+
for (const seed of incoming) {
|
|
9799
|
+
const index = target.findIndex((existing) => existing.url === seed.url);
|
|
9800
|
+
const previous = target[index];
|
|
9801
|
+
const bindings = [...seed.bindings ?? []];
|
|
9802
|
+
if (previous?.identity.session === seed.identity.session && queryTag(previous.identity) === queryTag(seed.identity)) {
|
|
9803
|
+
for (const binding of previous.bindings ?? []) {
|
|
9804
|
+
if (!bindings.some((next) => JSON.stringify(next.target) === JSON.stringify(binding.target))) {
|
|
9805
|
+
bindings.push(binding);
|
|
9806
|
+
}
|
|
9807
|
+
}
|
|
9808
|
+
}
|
|
9809
|
+
const merged = { ...seed, bindings };
|
|
9810
|
+
if (index < 0) {
|
|
9811
|
+
target.push(merged);
|
|
9812
|
+
} else {
|
|
9813
|
+
target[index] = merged;
|
|
9814
|
+
}
|
|
9815
|
+
}
|
|
9816
|
+
}
|
|
9817
|
+
function queryTagsFromData(data) {
|
|
9818
|
+
return (data.__furinQueries ?? []).map((seed) => queryTag(seed.identity));
|
|
9819
|
+
}
|
|
9820
|
+
var PREFIX = "__furin.query:";
|
|
9821
|
+
function queryTag(identity) {
|
|
9822
|
+
for (const [key, value] of Object.entries(identity.scope)) {
|
|
9823
|
+
if (value === undefined) {
|
|
9824
|
+
throw new Error(`[furin] Query scope "${key}" is undefined for "${identity.id}".`);
|
|
9825
|
+
}
|
|
9826
|
+
}
|
|
9827
|
+
return PREFIX + JSON.stringify([
|
|
9828
|
+
identity.id,
|
|
9829
|
+
Object.entries(identity.scope).sort(([a], [b]) => {
|
|
9830
|
+
if (a === b) {
|
|
9831
|
+
return 0;
|
|
9832
|
+
}
|
|
9833
|
+
return a < b ? -1 : 1;
|
|
9834
|
+
})
|
|
9835
|
+
]);
|
|
9836
|
+
}
|
|
9837
|
+
function queryFromTag(tag) {
|
|
9838
|
+
if (!tag.startsWith(PREFIX)) {
|
|
9839
|
+
return;
|
|
9840
|
+
}
|
|
9841
|
+
try {
|
|
9842
|
+
const value = JSON.parse(tag.slice(PREFIX.length));
|
|
9843
|
+
if (!Array.isArray(value) || value.length !== 2 || typeof value[0] !== "string" || !Array.isArray(value[1]) || value[1].some((entry) => !Array.isArray(entry) || entry.length !== 2 || typeof entry[0] !== "string" || !(entry[1] === null || typeof entry[1] === "string" || typeof entry[1] === "number" || typeof entry[1] === "boolean"))) {
|
|
9844
|
+
return;
|
|
9845
|
+
}
|
|
9846
|
+
return { id: value[0], scope: Object.fromEntries(value[1]) };
|
|
9847
|
+
} catch {}
|
|
9848
|
+
}
|
|
9849
|
+
function queryUrl(url, origin) {
|
|
9850
|
+
const parsed = new URL(url, origin);
|
|
9851
|
+
parsed.searchParams.sort();
|
|
9852
|
+
return (parsed.origin === origin ? "" : parsed.origin) + parsed.pathname + parsed.search;
|
|
9853
|
+
}
|
|
9854
|
+
|
|
9076
9855
|
// src/shared/utils/index.ts
|
|
9077
9856
|
function collectRouteChainFromRoute(route) {
|
|
9078
9857
|
const chain = [];
|
|
@@ -9195,8 +9974,7 @@ function setSSGCache(key, entry) {
|
|
|
9195
9974
|
}
|
|
9196
9975
|
|
|
9197
9976
|
// src/server/render/ssr.ts
|
|
9198
|
-
import { createElement as
|
|
9199
|
-
import { renderToReadableStream } from "react-dom/server";
|
|
9977
|
+
import { createElement as createElement7 } from "react";
|
|
9200
9978
|
|
|
9201
9979
|
// ../../node_modules/.bun/seroval@1.6.7/node_modules/seroval/dist/dev/index.js
|
|
9202
9980
|
var SYM_ASYNC_ITERATOR = Symbol.asyncIterator;
|
|
@@ -11301,6 +12079,7 @@ function fromCrossJSON(source, options) {
|
|
|
11301
12079
|
|
|
11302
12080
|
// src/client/document.tsx
|
|
11303
12081
|
import { createContext, createElement, useContext } from "react";
|
|
12082
|
+
import { preloadModule } from "react-dom";
|
|
11304
12083
|
import { jsxDEV, Fragment } from "react/jsx-dev-runtime";
|
|
11305
12084
|
var DocumentContext = createContext(null);
|
|
11306
12085
|
function serializeJson(value) {
|
|
@@ -11315,29 +12094,39 @@ function DocumentProvider({
|
|
|
11315
12094
|
children
|
|
11316
12095
|
}, undefined, false, undefined, this);
|
|
11317
12096
|
}
|
|
11318
|
-
function renderMeta(meta,
|
|
12097
|
+
function renderMeta(meta, key) {
|
|
11319
12098
|
if ("title" in meta) {
|
|
11320
12099
|
return /* @__PURE__ */ jsxDEV("title", {
|
|
11321
12100
|
children: meta.title
|
|
11322
|
-
},
|
|
12101
|
+
}, key, false, undefined, this);
|
|
11323
12102
|
}
|
|
11324
12103
|
if ("script:ld+json" in meta) {
|
|
11325
12104
|
return /* @__PURE__ */ jsxDEV("script", {
|
|
11326
12105
|
dangerouslySetInnerHTML: { __html: serializeJson(meta["script:ld+json"]) },
|
|
11327
12106
|
type: "application/ld+json"
|
|
11328
|
-
},
|
|
12107
|
+
}, key, false, undefined, this);
|
|
11329
12108
|
}
|
|
11330
12109
|
if ("tagName" in meta) {
|
|
11331
12110
|
const { tagName, ...attributes } = meta;
|
|
11332
|
-
return createElement(tagName, { ...attributes, key
|
|
12111
|
+
return createElement(tagName, { ...attributes, key });
|
|
11333
12112
|
}
|
|
11334
|
-
return createElement("meta", { ...meta, key
|
|
12113
|
+
return createElement("meta", { ...meta, key });
|
|
11335
12114
|
}
|
|
11336
12115
|
function HeadContent() {
|
|
11337
12116
|
const state = useContext(DocumentContext);
|
|
11338
12117
|
if (state === null) {
|
|
11339
12118
|
throw new Error("[furin] <HeadContent /> must be rendered inside the root layout.");
|
|
11340
12119
|
}
|
|
12120
|
+
for (const href of state.assets.modulePreloads ?? []) {
|
|
12121
|
+
preloadModule(href, { as: "script", nonce: state.nonce });
|
|
12122
|
+
}
|
|
12123
|
+
const occurrences = new Map;
|
|
12124
|
+
const descriptorKey = (descriptor) => {
|
|
12125
|
+
const identity = JSON.stringify(descriptor);
|
|
12126
|
+
const occurrence = occurrences.get(identity) ?? 0;
|
|
12127
|
+
occurrences.set(identity, occurrence + 1);
|
|
12128
|
+
return `${identity}:${occurrence}`;
|
|
12129
|
+
};
|
|
11341
12130
|
return /* @__PURE__ */ jsxDEV(Fragment, {
|
|
11342
12131
|
children: [
|
|
11343
12132
|
state.assets.extensionErrorFilterScript === undefined ? null : /* @__PURE__ */ jsxDEV("script", {
|
|
@@ -11370,20 +12159,20 @@ function HeadContent() {
|
|
|
11370
12159
|
href,
|
|
11371
12160
|
rel: "stylesheet"
|
|
11372
12161
|
}, href, false, undefined, this)),
|
|
11373
|
-
state.head?.meta?.map(renderMeta),
|
|
11374
|
-
state.head?.links?.map((link
|
|
12162
|
+
state.head?.meta?.map((meta) => renderMeta(meta, descriptorKey(meta))),
|
|
12163
|
+
state.head?.links?.map((link) => /* @__PURE__ */ jsxDEV("link", {
|
|
11375
12164
|
...link
|
|
11376
|
-
},
|
|
11377
|
-
state.head?.scripts?.map(({ children, ...attributes }
|
|
12165
|
+
}, descriptorKey(link), false, undefined, this)),
|
|
12166
|
+
state.head?.scripts?.map(({ children, ...attributes }) => /* @__PURE__ */ jsxDEV("script", {
|
|
11378
12167
|
...attributes,
|
|
11379
|
-
|
|
11380
|
-
|
|
11381
|
-
},
|
|
11382
|
-
state.head?.styles?.map(({ children, type }
|
|
12168
|
+
nonce: state.nonce ?? attributes.nonce,
|
|
12169
|
+
children
|
|
12170
|
+
}, descriptorKey({ children, ...attributes }), false, undefined, this)),
|
|
12171
|
+
state.head?.styles?.map(({ children, type }) => /* @__PURE__ */ jsxDEV("style", {
|
|
11383
12172
|
dangerouslySetInnerHTML: { __html: children },
|
|
11384
12173
|
nonce: state.nonce,
|
|
11385
12174
|
type
|
|
11386
|
-
},
|
|
12175
|
+
}, descriptorKey({ children, type }), false, undefined, this))
|
|
11387
12176
|
]
|
|
11388
12177
|
}, undefined, true, undefined, this);
|
|
11389
12178
|
}
|
|
@@ -11452,7 +12241,7 @@ function FurinDocumentFallback({ children }) {
|
|
|
11452
12241
|
}
|
|
11453
12242
|
|
|
11454
12243
|
// src/client/router/context.ts
|
|
11455
|
-
import { createContext as createContext2, useContext as useContext2 } from "react";
|
|
12244
|
+
import { createContext as createContext2, useCallback, useContext as useContext2, useMemo } from "react";
|
|
11456
12245
|
|
|
11457
12246
|
// src/client/router/link-utils.ts
|
|
11458
12247
|
function navigationHrefPolicy(href, currentOrigin) {
|
|
@@ -11542,7 +12331,7 @@ var CLIENT_FALLBACK_ROUTER = {
|
|
|
11542
12331
|
search: {},
|
|
11543
12332
|
searchRoutes: []
|
|
11544
12333
|
};
|
|
11545
|
-
function
|
|
12334
|
+
function useRouterContext() {
|
|
11546
12335
|
const ctx = useContext2(RouterContext);
|
|
11547
12336
|
return ctx ?? CLIENT_FALLBACK_ROUTER;
|
|
11548
12337
|
}
|
|
@@ -11550,7 +12339,7 @@ function useRouter() {
|
|
|
11550
12339
|
// src/client/router/search-store.ts
|
|
11551
12340
|
import { createContext as createContext3 } from "react";
|
|
11552
12341
|
function searchSnapshotChanged(a, b) {
|
|
11553
|
-
return a.currentHref !== b.currentHref || a.navigate !== b.navigate || a.search !== b.search || a.searchRoutes !== b.searchRoutes;
|
|
12342
|
+
return a.currentHref !== b.currentHref || a.currentPattern !== b.currentPattern || a.navigate !== b.navigate || a.search !== b.search || a.searchRoutes !== b.searchRoutes;
|
|
11554
12343
|
}
|
|
11555
12344
|
function createSearchStore(initialSnapshot) {
|
|
11556
12345
|
let snapshot = initialSnapshot;
|
|
@@ -11587,6 +12376,7 @@ function createSearchStore(initialSnapshot) {
|
|
|
11587
12376
|
function searchSnapshotFromRouterContext(context) {
|
|
11588
12377
|
return {
|
|
11589
12378
|
currentHref: context.currentHref,
|
|
12379
|
+
currentPattern: context.currentPattern,
|
|
11590
12380
|
navigate: context.navigate,
|
|
11591
12381
|
search: context.search,
|
|
11592
12382
|
searchRoutes: context.searchRoutes
|
|
@@ -11594,6 +12384,7 @@ function searchSnapshotFromRouterContext(context) {
|
|
|
11594
12384
|
}
|
|
11595
12385
|
var FALLBACK_SEARCH_STORE = createSearchStore({
|
|
11596
12386
|
currentHref: "/",
|
|
12387
|
+
currentPattern: undefined,
|
|
11597
12388
|
navigate: (href, _opts) => {
|
|
11598
12389
|
if (typeof window !== "undefined") {
|
|
11599
12390
|
if (navigationHrefPolicy(href, window.location.origin) === "blocked") {
|
|
@@ -11871,9 +12662,292 @@ function serializeRouteFrames(data, deferredKeys) {
|
|
|
11871
12662
|
// src/server/render/ssr.ts
|
|
11872
12663
|
init_context_logger();
|
|
11873
12664
|
init_instance();
|
|
11874
|
-
|
|
11875
12665
|
// src/server/render/document.tsx
|
|
11876
12666
|
import { createElement as createElement3 } from "react";
|
|
12667
|
+
|
|
12668
|
+
// src/client/query.tsx
|
|
12669
|
+
import {
|
|
12670
|
+
createContext as createContext4,
|
|
12671
|
+
useCallback as useCallback2,
|
|
12672
|
+
useContext as useContext3,
|
|
12673
|
+
useEffect,
|
|
12674
|
+
useSyncExternalStore
|
|
12675
|
+
} from "react";
|
|
12676
|
+
|
|
12677
|
+
// src/client/query-store.ts
|
|
12678
|
+
var QUERY_REFERENCE = Symbol.for("furin.query.reference.v1");
|
|
12679
|
+
var SERVER_ENVIRONMENT = Symbol.for("furin.query.environment.v1");
|
|
12680
|
+
var environmentGlobal = globalThis;
|
|
12681
|
+
function setServerQueryEnvironment(read) {
|
|
12682
|
+
environmentGlobal[SERVER_ENVIRONMENT] = read;
|
|
12683
|
+
}
|
|
12684
|
+
function currentQueryEnvironment() {
|
|
12685
|
+
return environmentGlobal[SERVER_ENVIRONMENT]?.();
|
|
12686
|
+
}
|
|
12687
|
+
class QueryStore {
|
|
12688
|
+
entries = new Map;
|
|
12689
|
+
listeners = new Set;
|
|
12690
|
+
revisionValue = 0;
|
|
12691
|
+
projections = new Set;
|
|
12692
|
+
session;
|
|
12693
|
+
epoch = 0;
|
|
12694
|
+
origin;
|
|
12695
|
+
constructor(origin) {
|
|
12696
|
+
this.origin = origin;
|
|
12697
|
+
}
|
|
12698
|
+
key(url) {
|
|
12699
|
+
const absolute = new URL(url, this.origin).href;
|
|
12700
|
+
return queryUrl(absolute, undefined);
|
|
12701
|
+
}
|
|
12702
|
+
entry(url) {
|
|
12703
|
+
const key = this.key(url);
|
|
12704
|
+
let entry = this.entries.get(key);
|
|
12705
|
+
if (!entry) {
|
|
12706
|
+
entry = {
|
|
12707
|
+
base: undefined,
|
|
12708
|
+
listeners: new Set,
|
|
12709
|
+
snapshot: { data: undefined, error: null, isFetching: false },
|
|
12710
|
+
stale: true,
|
|
12711
|
+
version: 0
|
|
12712
|
+
};
|
|
12713
|
+
this.entries.set(key, entry);
|
|
12714
|
+
}
|
|
12715
|
+
return entry;
|
|
12716
|
+
}
|
|
12717
|
+
publish(entry) {
|
|
12718
|
+
let data = entry.base;
|
|
12719
|
+
for (const projection of this.projections) {
|
|
12720
|
+
const transform = projection.transforms.get(entry);
|
|
12721
|
+
if (transform && data !== undefined) {
|
|
12722
|
+
data = transform(data);
|
|
12723
|
+
}
|
|
12724
|
+
}
|
|
12725
|
+
entry.snapshot = { ...entry.snapshot, data };
|
|
12726
|
+
for (const listener of entry.listeners) {
|
|
12727
|
+
listener();
|
|
12728
|
+
}
|
|
12729
|
+
this.revisionValue += 1;
|
|
12730
|
+
for (const listener of this.listeners) {
|
|
12731
|
+
listener();
|
|
12732
|
+
}
|
|
12733
|
+
}
|
|
12734
|
+
revision = () => this.revisionValue;
|
|
12735
|
+
subscribeAll = (listener) => {
|
|
12736
|
+
this.listeners.add(listener);
|
|
12737
|
+
return () => this.listeners.delete(listener);
|
|
12738
|
+
};
|
|
12739
|
+
observe(url, result, epoch, version) {
|
|
12740
|
+
const existing = this.entries.get(this.key(url));
|
|
12741
|
+
if (epoch !== this.epoch || result.error !== null || existing && (this.pending(existing) || version !== undefined && existing.version !== version)) {
|
|
12742
|
+
return;
|
|
12743
|
+
}
|
|
12744
|
+
const header = result.response?.headers.get("x-furin-query");
|
|
12745
|
+
const identity = result.identity ?? (header ? JSON.parse(header) : undefined);
|
|
12746
|
+
if (identity) {
|
|
12747
|
+
this.setSession(identity.session);
|
|
12748
|
+
}
|
|
12749
|
+
const entry = this.entry(url);
|
|
12750
|
+
entry.base = result.data;
|
|
12751
|
+
entry.version += 1;
|
|
12752
|
+
entry.identity = identity;
|
|
12753
|
+
entry.local = result.local ?? result.response?.url === "";
|
|
12754
|
+
entry.stale = false;
|
|
12755
|
+
entry.snapshot = { data: result.data, error: null, isFetching: false };
|
|
12756
|
+
for (const projection of this.projections) {
|
|
12757
|
+
if (!projection.pending) {
|
|
12758
|
+
projection.transforms.delete(entry);
|
|
12759
|
+
if (projection.transforms.size === 0) {
|
|
12760
|
+
this.projections.delete(projection);
|
|
12761
|
+
projection.onRemove?.();
|
|
12762
|
+
}
|
|
12763
|
+
}
|
|
12764
|
+
}
|
|
12765
|
+
this.publish(entry);
|
|
12766
|
+
if (this.entries.size > 100) {
|
|
12767
|
+
const oldest = [...this.entries].find(([, item]) => item !== entry && item.listeners.size === 0 && !item.promise && !this.pending(item));
|
|
12768
|
+
if (oldest) {
|
|
12769
|
+
this.entries.delete(oldest[0]);
|
|
12770
|
+
}
|
|
12771
|
+
}
|
|
12772
|
+
}
|
|
12773
|
+
setSession(session) {
|
|
12774
|
+
if (this.session !== undefined && this.session !== session) {
|
|
12775
|
+
this.epoch += 1;
|
|
12776
|
+
for (const projection of this.projections) {
|
|
12777
|
+
projection.onRemove?.();
|
|
12778
|
+
}
|
|
12779
|
+
this.projections.clear();
|
|
12780
|
+
for (const entry of this.entries.values()) {
|
|
12781
|
+
entry.base = undefined;
|
|
12782
|
+
entry.identity = undefined;
|
|
12783
|
+
entry.stale = true;
|
|
12784
|
+
entry.version += 1;
|
|
12785
|
+
entry.snapshot = { data: undefined, error: null, isFetching: false };
|
|
12786
|
+
this.publish(entry);
|
|
12787
|
+
}
|
|
12788
|
+
}
|
|
12789
|
+
this.session = session;
|
|
12790
|
+
}
|
|
12791
|
+
generation() {
|
|
12792
|
+
return this.epoch;
|
|
12793
|
+
}
|
|
12794
|
+
version(url) {
|
|
12795
|
+
return this.entry(url).version;
|
|
12796
|
+
}
|
|
12797
|
+
snapshot(url) {
|
|
12798
|
+
return this.entry(url).snapshot;
|
|
12799
|
+
}
|
|
12800
|
+
subscribe(url, listener) {
|
|
12801
|
+
const entry = this.entry(url);
|
|
12802
|
+
entry.listeners.add(listener);
|
|
12803
|
+
return () => entry.listeners.delete(listener);
|
|
12804
|
+
}
|
|
12805
|
+
bind(url, load, client) {
|
|
12806
|
+
const entry = this.entry(url);
|
|
12807
|
+
if (client && entry.client && client !== entry.client) {
|
|
12808
|
+
entry.base = undefined;
|
|
12809
|
+
entry.identity = undefined;
|
|
12810
|
+
entry.stale = true;
|
|
12811
|
+
entry.version += 1;
|
|
12812
|
+
entry.snapshot = { data: undefined, error: null, isFetching: false };
|
|
12813
|
+
for (const projection of this.projections) {
|
|
12814
|
+
projection.transforms.delete(entry);
|
|
12815
|
+
}
|
|
12816
|
+
}
|
|
12817
|
+
entry.client = client ?? entry.client;
|
|
12818
|
+
entry.load = load;
|
|
12819
|
+
}
|
|
12820
|
+
pending(entry) {
|
|
12821
|
+
return [...this.projections].some((projection) => projection.pending && projection.transforms.has(entry));
|
|
12822
|
+
}
|
|
12823
|
+
fetch(url) {
|
|
12824
|
+
const entry = this.entry(url);
|
|
12825
|
+
if (entry.promise) {
|
|
12826
|
+
return entry.promise;
|
|
12827
|
+
}
|
|
12828
|
+
if (!(entry.stale && entry.load) || this.pending(entry)) {
|
|
12829
|
+
return Promise.resolve();
|
|
12830
|
+
}
|
|
12831
|
+
const { version } = entry;
|
|
12832
|
+
const { epoch } = this;
|
|
12833
|
+
entry.snapshot = { ...entry.snapshot, isFetching: true };
|
|
12834
|
+
this.publish(entry);
|
|
12835
|
+
entry.promise = Promise.resolve().then(() => entry.load?.()).then((result) => {
|
|
12836
|
+
if (!result || epoch !== this.epoch || version !== entry.version || this.pending(entry)) {
|
|
12837
|
+
return;
|
|
12838
|
+
}
|
|
12839
|
+
if (result.error === null) {
|
|
12840
|
+
this.observe(url, result, epoch);
|
|
12841
|
+
} else {
|
|
12842
|
+
entry.snapshot = { ...entry.snapshot, error: result.error };
|
|
12843
|
+
}
|
|
12844
|
+
}).catch((error) => {
|
|
12845
|
+
if (epoch === this.epoch && version === entry.version) {
|
|
12846
|
+
entry.snapshot = { ...entry.snapshot, error };
|
|
12847
|
+
}
|
|
12848
|
+
}).finally(() => {
|
|
12849
|
+
entry.promise = undefined;
|
|
12850
|
+
entry.snapshot = { ...entry.snapshot, isFetching: false };
|
|
12851
|
+
this.publish(entry);
|
|
12852
|
+
if (entry.stale && version !== entry.version && entry.listeners.size > 0) {
|
|
12853
|
+
this.fetch(url);
|
|
12854
|
+
}
|
|
12855
|
+
});
|
|
12856
|
+
return entry.promise;
|
|
12857
|
+
}
|
|
12858
|
+
invalidate(identities) {
|
|
12859
|
+
const tags = new Set(identities.map(queryTag));
|
|
12860
|
+
let affected = false;
|
|
12861
|
+
for (const [url, entry] of this.entries) {
|
|
12862
|
+
if (entry.identity && tags.has(queryTag(entry.identity))) {
|
|
12863
|
+
affected = true;
|
|
12864
|
+
this.invalidateEntry(url, entry);
|
|
12865
|
+
}
|
|
12866
|
+
}
|
|
12867
|
+
return affected;
|
|
12868
|
+
}
|
|
12869
|
+
invalidateEntry(url, entry) {
|
|
12870
|
+
entry.stale = true;
|
|
12871
|
+
entry.version += 1;
|
|
12872
|
+
if (entry.listeners.size > 0) {
|
|
12873
|
+
this.fetch(url);
|
|
12874
|
+
}
|
|
12875
|
+
}
|
|
12876
|
+
invalidateAll() {
|
|
12877
|
+
for (const [url, entry] of this.entries) {
|
|
12878
|
+
this.invalidateEntry(url, entry);
|
|
12879
|
+
}
|
|
12880
|
+
}
|
|
12881
|
+
begin() {
|
|
12882
|
+
return { pending: true, transforms: new Map };
|
|
12883
|
+
}
|
|
12884
|
+
update(projection, url, transform) {
|
|
12885
|
+
const entry = this.entries.get(this.key(url));
|
|
12886
|
+
if (!entry || entry.base === undefined) {
|
|
12887
|
+
return;
|
|
12888
|
+
}
|
|
12889
|
+
const previous = projection.transforms.get(entry);
|
|
12890
|
+
projection.transforms.set(entry, previous ? (data) => transform(previous(data)) : transform);
|
|
12891
|
+
entry.version += 1;
|
|
12892
|
+
this.projections.add(projection);
|
|
12893
|
+
this.publish(entry);
|
|
12894
|
+
}
|
|
12895
|
+
finish(projection, outcome) {
|
|
12896
|
+
projection.pending = false;
|
|
12897
|
+
const entries = [...projection.transforms.keys()];
|
|
12898
|
+
if (outcome === "error") {
|
|
12899
|
+
this.projections.delete(projection);
|
|
12900
|
+
projection.onRemove?.();
|
|
12901
|
+
}
|
|
12902
|
+
for (const entry of entries) {
|
|
12903
|
+
this.publish(entry);
|
|
12904
|
+
if (outcome !== "error") {
|
|
12905
|
+
entry.stale = true;
|
|
12906
|
+
}
|
|
12907
|
+
const url = [...this.entries].find(([, candidate]) => candidate === entry)?.[0];
|
|
12908
|
+
if (url && entry.stale) {
|
|
12909
|
+
this.fetch(url);
|
|
12910
|
+
}
|
|
12911
|
+
}
|
|
12912
|
+
}
|
|
12913
|
+
dehydrate() {
|
|
12914
|
+
return [...this.entries].flatMap(([url, entry]) => entry.identity && entry.base !== undefined ? [{ url, data: entry.base, identity: entry.identity, local: entry.local }] : []);
|
|
12915
|
+
}
|
|
12916
|
+
seedUrl(seed, localOrigin) {
|
|
12917
|
+
const original = new URL(seed.url, this.origin);
|
|
12918
|
+
return seed.local && localOrigin ? new URL(original.pathname + original.search, localOrigin).href : original.href;
|
|
12919
|
+
}
|
|
12920
|
+
captureHydration() {
|
|
12921
|
+
const { epoch } = this;
|
|
12922
|
+
const versions = new Map([...this.entries].map(([key, entry]) => [key, entry.version]));
|
|
12923
|
+
return (seeds, localOrigin) => {
|
|
12924
|
+
if (epoch === this.epoch) {
|
|
12925
|
+
this.hydrate(seeds.filter((seed) => {
|
|
12926
|
+
const url = this.seedUrl(seed, localOrigin);
|
|
12927
|
+
return this.version(url) === (versions.get(this.key(url)) ?? 0);
|
|
12928
|
+
}), localOrigin);
|
|
12929
|
+
}
|
|
12930
|
+
};
|
|
12931
|
+
}
|
|
12932
|
+
hydrate(seeds, localOrigin) {
|
|
12933
|
+
for (const seed of seeds) {
|
|
12934
|
+
const url = this.seedUrl(seed, localOrigin);
|
|
12935
|
+
this.observe(url, {
|
|
12936
|
+
data: seed.data,
|
|
12937
|
+
error: null,
|
|
12938
|
+
identity: seed.identity,
|
|
12939
|
+
local: seed.local ?? false
|
|
12940
|
+
}, this.epoch);
|
|
12941
|
+
}
|
|
12942
|
+
}
|
|
12943
|
+
}
|
|
12944
|
+
|
|
12945
|
+
// src/client/query.tsx
|
|
12946
|
+
var QUERY_CONTEXT = Symbol.for("furin.query.context.v1");
|
|
12947
|
+
var contextGlobal = globalThis;
|
|
12948
|
+
var QueryStoreContext = contextGlobal[QUERY_CONTEXT] ??= createContext4(null);
|
|
12949
|
+
|
|
12950
|
+
// src/server/render/document.tsx
|
|
11877
12951
|
init_instance();
|
|
11878
12952
|
init_config();
|
|
11879
12953
|
function withDocumentState(element, assets, head, data, nonce) {
|
|
@@ -11892,11 +12966,13 @@ function withDocumentState(element, assets, head, data, nonce) {
|
|
|
11892
12966
|
routeFrames,
|
|
11893
12967
|
syncJson: syncPath === undefined ? undefined : safeJson({ path: syncPath })
|
|
11894
12968
|
};
|
|
11895
|
-
|
|
12969
|
+
const queries = new QueryStore(undefined);
|
|
12970
|
+
queries.hydrate(data?.__furinQueries ?? []);
|
|
12971
|
+
return createElement3(DocumentProvider, { value: state }, createElement3(QueryStoreContext.Provider, { value: queries }, element));
|
|
11896
12972
|
}
|
|
11897
12973
|
|
|
11898
12974
|
// src/server/render/element.tsx
|
|
11899
|
-
import { createElement as
|
|
12975
|
+
import { createElement as createElement6 } from "react";
|
|
11900
12976
|
|
|
11901
12977
|
// src/client/boundaries.tsx
|
|
11902
12978
|
import { Component, Fragment as Fragment2 } from "react";
|
|
@@ -11926,7 +13002,57 @@ function isNotFoundError(err) {
|
|
|
11926
13002
|
}
|
|
11927
13003
|
|
|
11928
13004
|
// src/client/link.tsx
|
|
11929
|
-
import { createElement as
|
|
13005
|
+
import { createElement as createElement5, useCallback as useCallback3, useEffect as useEffect2, useRef } from "react";
|
|
13006
|
+
|
|
13007
|
+
// src/shared/page-key.ts
|
|
13008
|
+
function identityValue(value) {
|
|
13009
|
+
return Object.is(value, -0) ? "-0" : String(value);
|
|
13010
|
+
}
|
|
13011
|
+
function pageKey(pattern, data, remountDeps) {
|
|
13012
|
+
const { params, query } = data;
|
|
13013
|
+
if (remountDeps) {
|
|
13014
|
+
const deps = remountDeps({ params: params ?? {}, query: query ?? {} });
|
|
13015
|
+
return JSON.stringify([pattern, deps.map((value) => [typeof value, identityValue(value)])]);
|
|
13016
|
+
}
|
|
13017
|
+
const entries = Object.entries(params ?? {}).sort(([left], [right]) => {
|
|
13018
|
+
if (left < right) {
|
|
13019
|
+
return -1;
|
|
13020
|
+
}
|
|
13021
|
+
return left > right ? 1 : 0;
|
|
13022
|
+
});
|
|
13023
|
+
return JSON.stringify([
|
|
13024
|
+
pattern,
|
|
13025
|
+
entries.map(([name, value]) => [
|
|
13026
|
+
name,
|
|
13027
|
+
Array.isArray(value) ? value.map(identityValue) : identityValue(value)
|
|
13028
|
+
])
|
|
13029
|
+
]);
|
|
13030
|
+
}
|
|
13031
|
+
|
|
13032
|
+
// src/client/route-api.tsx
|
|
13033
|
+
import { createContext as createContext5, createElement as createElement4, useContext as useContext4 } from "react";
|
|
13034
|
+
var RESERVED_RENDER_KEYS = new Set([
|
|
13035
|
+
"catch",
|
|
13036
|
+
"children",
|
|
13037
|
+
"finally",
|
|
13038
|
+
"key",
|
|
13039
|
+
"ref",
|
|
13040
|
+
"then",
|
|
13041
|
+
"toJSON"
|
|
13042
|
+
]);
|
|
13043
|
+
var ROUTE_CONTEXT = Symbol.for("furin.route.context.v1");
|
|
13044
|
+
var contextGlobal2 = globalThis;
|
|
13045
|
+
var RouteContext = contextGlobal2[ROUTE_CONTEXT] ??= createContext5(null);
|
|
13046
|
+
function withRouteSnapshot(element, pattern, props) {
|
|
13047
|
+
const {
|
|
13048
|
+
params,
|
|
13049
|
+
path: _path,
|
|
13050
|
+
query: _query,
|
|
13051
|
+
...data
|
|
13052
|
+
} = props;
|
|
13053
|
+
const loaderData = Object.fromEntries(Object.entries(data).filter(([key]) => !(RESERVED_RENDER_KEYS.has(key) || key.startsWith("__furin"))));
|
|
13054
|
+
return createElement4(RouteContext.Provider, { value: { data: loaderData, params: params ?? {}, pattern } }, element);
|
|
13055
|
+
}
|
|
11930
13056
|
|
|
11931
13057
|
// src/client/server-error.ts
|
|
11932
13058
|
var SERVER_ERROR_BRAND = "FURIN_SERVER_ERROR";
|
|
@@ -11944,6 +13070,96 @@ class FurinServerError extends Error {
|
|
|
11944
13070
|
function isFurinServerError(err) {
|
|
11945
13071
|
return err instanceof FurinServerError || typeof err === "object" && err !== null && err.__furinBrand === SERVER_ERROR_BRAND;
|
|
11946
13072
|
}
|
|
13073
|
+
|
|
13074
|
+
// src/shared/query-bindings.ts
|
|
13075
|
+
function isContainer(value) {
|
|
13076
|
+
if (!value || typeof value !== "object") {
|
|
13077
|
+
return false;
|
|
13078
|
+
}
|
|
13079
|
+
const prototype = Object.getPrototypeOf(value);
|
|
13080
|
+
return Array.isArray(value) || prototype === Object.prototype || prototype === null;
|
|
13081
|
+
}
|
|
13082
|
+
function bindQueryData(data, seeds) {
|
|
13083
|
+
return seeds.map((seed) => {
|
|
13084
|
+
const sources = new WeakMap;
|
|
13085
|
+
const index = (value, path) => {
|
|
13086
|
+
if (!isContainer(value) || sources.has(value)) {
|
|
13087
|
+
return;
|
|
13088
|
+
}
|
|
13089
|
+
sources.set(value, path);
|
|
13090
|
+
if (!Array.isArray(value)) {
|
|
13091
|
+
for (const [key, child] of Object.entries(value)) {
|
|
13092
|
+
index(child, [...path, key]);
|
|
13093
|
+
}
|
|
13094
|
+
}
|
|
13095
|
+
};
|
|
13096
|
+
index(seed.data, []);
|
|
13097
|
+
const bindings = [];
|
|
13098
|
+
const visiting = new WeakSet;
|
|
13099
|
+
const visit = (value, target) => {
|
|
13100
|
+
if (!isContainer(value) || visiting.has(value)) {
|
|
13101
|
+
return;
|
|
13102
|
+
}
|
|
13103
|
+
const source = sources.get(value);
|
|
13104
|
+
if (source) {
|
|
13105
|
+
bindings.push({ source, target });
|
|
13106
|
+
return;
|
|
13107
|
+
}
|
|
13108
|
+
visiting.add(value);
|
|
13109
|
+
for (const [key, child] of Object.entries(value)) {
|
|
13110
|
+
visit(child, [...target, key]);
|
|
13111
|
+
}
|
|
13112
|
+
visiting.delete(value);
|
|
13113
|
+
};
|
|
13114
|
+
visit(data, []);
|
|
13115
|
+
return { ...seed, bindings };
|
|
13116
|
+
});
|
|
13117
|
+
}
|
|
13118
|
+
function replace(value, path, next) {
|
|
13119
|
+
const [key, ...rest] = path;
|
|
13120
|
+
if (key === undefined) {
|
|
13121
|
+
return next;
|
|
13122
|
+
}
|
|
13123
|
+
if (!(isContainer(value) && Object.hasOwn(value, key))) {
|
|
13124
|
+
return value;
|
|
13125
|
+
}
|
|
13126
|
+
const child = replace(value[key], rest, next);
|
|
13127
|
+
if (child === value[key]) {
|
|
13128
|
+
return value;
|
|
13129
|
+
}
|
|
13130
|
+
const copy = Array.isArray(value) ? [...value] : { ...value };
|
|
13131
|
+
Object.defineProperty(copy, key, {
|
|
13132
|
+
configurable: true,
|
|
13133
|
+
enumerable: true,
|
|
13134
|
+
value: child,
|
|
13135
|
+
writable: true
|
|
13136
|
+
});
|
|
13137
|
+
return copy;
|
|
13138
|
+
}
|
|
13139
|
+
function isDeferredTarget(data, target) {
|
|
13140
|
+
const [key] = target;
|
|
13141
|
+
return key !== undefined && isContainer(data) && data[key] instanceof Promise;
|
|
13142
|
+
}
|
|
13143
|
+
function projectQueryData(data, seeds, read) {
|
|
13144
|
+
let projected = data;
|
|
13145
|
+
for (const seed of seeds) {
|
|
13146
|
+
const snapshot = read(seed);
|
|
13147
|
+
if (snapshot === undefined) {
|
|
13148
|
+
continue;
|
|
13149
|
+
}
|
|
13150
|
+
for (const binding of seed.bindings ?? []) {
|
|
13151
|
+
if (isDeferredTarget(data, binding.target)) {
|
|
13152
|
+
continue;
|
|
13153
|
+
}
|
|
13154
|
+
let value = snapshot;
|
|
13155
|
+
for (const key of binding.source) {
|
|
13156
|
+
value = isContainer(value) && Object.hasOwn(value, key) ? value[key] : undefined;
|
|
13157
|
+
}
|
|
13158
|
+
projected = replace(projected, binding.target, value);
|
|
13159
|
+
}
|
|
13160
|
+
}
|
|
13161
|
+
return projected;
|
|
13162
|
+
}
|
|
11947
13163
|
// src/client/link.tsx
|
|
11948
13164
|
function computeLinkView({
|
|
11949
13165
|
to,
|
|
@@ -11993,7 +13209,7 @@ function LinkInteractive({
|
|
|
11993
13209
|
href: _href,
|
|
11994
13210
|
...anchorProps
|
|
11995
13211
|
}) {
|
|
11996
|
-
const router2 =
|
|
13212
|
+
const router2 = useRouterContext();
|
|
11997
13213
|
const anchorRef = useRef(null);
|
|
11998
13214
|
const intentTimerRef = useRef(null);
|
|
11999
13215
|
const { logicalHref, href, isActive, resolvedChildren, extraProps } = computeLinkView({ activeProps, children, hash, inactiveProps, params, search, to }, router2);
|
|
@@ -12001,15 +13217,15 @@ function LinkInteractive({
|
|
|
12001
13217
|
const effectiveDelay = preloadDelay ?? router2.defaultPreloadDelay;
|
|
12002
13218
|
const effectiveStaleTime = preloadStaleTime ?? router2.defaultPreloadStaleTime;
|
|
12003
13219
|
const { prefetch } = router2;
|
|
12004
|
-
const triggerPrefetch =
|
|
13220
|
+
const triggerPrefetch = useCallback3(() => {
|
|
12005
13221
|
prefetch(logicalHref, { staleTime: effectiveStaleTime });
|
|
12006
13222
|
}, [prefetch, logicalHref, effectiveStaleTime]);
|
|
12007
|
-
|
|
13223
|
+
useEffect2(() => {
|
|
12008
13224
|
if (effectivePreload === "render") {
|
|
12009
13225
|
triggerPrefetch();
|
|
12010
13226
|
}
|
|
12011
13227
|
}, [effectivePreload, triggerPrefetch]);
|
|
12012
|
-
|
|
13228
|
+
useEffect2(() => {
|
|
12013
13229
|
if (effectivePreload !== "viewport" || !anchorRef.current) {
|
|
12014
13230
|
return;
|
|
12015
13231
|
}
|
|
@@ -12022,7 +13238,7 @@ function LinkInteractive({
|
|
|
12022
13238
|
observer.observe(anchorRef.current);
|
|
12023
13239
|
return () => observer.disconnect();
|
|
12024
13240
|
}, [effectivePreload, triggerPrefetch]);
|
|
12025
|
-
|
|
13241
|
+
useEffect2(() => () => {
|
|
12026
13242
|
if (intentTimerRef.current !== null) {
|
|
12027
13243
|
clearTimeout(intentTimerRef.current);
|
|
12028
13244
|
intentTimerRef.current = null;
|
|
@@ -12076,7 +13292,7 @@ function LinkInteractive({
|
|
|
12076
13292
|
triggerPrefetch();
|
|
12077
13293
|
}
|
|
12078
13294
|
};
|
|
12079
|
-
return
|
|
13295
|
+
return createElement5("a", {
|
|
12080
13296
|
"data-furin-link": true,
|
|
12081
13297
|
href,
|
|
12082
13298
|
onClick: handleClick,
|
|
@@ -12127,7 +13343,7 @@ function renderLinkElement(props, router2) {
|
|
|
12127
13343
|
href: _href,
|
|
12128
13344
|
...anchorProps
|
|
12129
13345
|
} = props;
|
|
12130
|
-
return
|
|
13346
|
+
return createElement5("a", {
|
|
12131
13347
|
"data-furin-link": true,
|
|
12132
13348
|
href,
|
|
12133
13349
|
...isActive ? { "data-status": "active" } : {},
|
|
@@ -12138,11 +13354,11 @@ function renderLinkElement(props, router2) {
|
|
|
12138
13354
|
}
|
|
12139
13355
|
function Link(props) {
|
|
12140
13356
|
if (typeof window === "undefined") {
|
|
12141
|
-
return
|
|
13357
|
+
return createElement5(RouterContext.Consumer, {
|
|
12142
13358
|
children: (routerCtx) => renderLinkElement(props, routerCtx ?? SSR_FALLBACK_ROUTER)
|
|
12143
13359
|
});
|
|
12144
13360
|
}
|
|
12145
|
-
return
|
|
13361
|
+
return createElement5(LinkInteractive, props);
|
|
12146
13362
|
}
|
|
12147
13363
|
|
|
12148
13364
|
// src/client/default-screens.tsx
|
|
@@ -12548,33 +13764,42 @@ function wrapSegmentBoundaries(inner, segment, options) {
|
|
|
12548
13764
|
import { jsxDEV as jsxDEV4 } from "react/jsx-dev-runtime";
|
|
12549
13765
|
function buildElement(route, data, rootLayout) {
|
|
12550
13766
|
const Component = route.page.component;
|
|
12551
|
-
let element =
|
|
13767
|
+
let element = createElement6(Component, {
|
|
13768
|
+
...data,
|
|
13769
|
+
key: pageKey(route.pattern, data, route.page._route.remountDeps)
|
|
13770
|
+
});
|
|
12552
13771
|
const byDepth = new Map;
|
|
12553
13772
|
const legacyRoute = route;
|
|
12554
13773
|
for (const segment of legacyRoute.segmentBoundaries ?? []) {
|
|
12555
|
-
byDepth.
|
|
13774
|
+
const boundaries = byDepth.get(segment.depth) ?? [];
|
|
13775
|
+
boundaries.unshift(segment);
|
|
13776
|
+
byDepth.set(segment.depth, boundaries);
|
|
12556
13777
|
}
|
|
12557
13778
|
for (let i = route.routeChain.length - 1;i >= 1; i -= 1) {
|
|
12558
|
-
|
|
13779
|
+
for (const segment of byDepth.get(i) ?? []) {
|
|
13780
|
+
element = wrapSegmentBoundaries(element, segment, undefined);
|
|
13781
|
+
}
|
|
12559
13782
|
const routeEntry = route.routeChain[i];
|
|
12560
13783
|
if (routeEntry?.layout) {
|
|
12561
13784
|
const Layout = routeEntry.layout;
|
|
12562
|
-
element =
|
|
13785
|
+
element = createElement6(Layout, data, element);
|
|
12563
13786
|
}
|
|
12564
13787
|
}
|
|
12565
|
-
|
|
13788
|
+
for (const segment of byDepth.get(0) ?? []) {
|
|
13789
|
+
element = wrapSegmentBoundaries(element, segment, undefined);
|
|
13790
|
+
}
|
|
12566
13791
|
if (rootLayout.layout) {
|
|
12567
13792
|
const RootLayoutComponent = rootLayout.layout;
|
|
12568
|
-
element =
|
|
13793
|
+
element = createElement6(RootLayoutComponent, data, element);
|
|
12569
13794
|
}
|
|
12570
|
-
return element;
|
|
13795
|
+
return withRouteSnapshot(element, route.pattern, data);
|
|
12571
13796
|
}
|
|
12572
13797
|
function wrapRootLayout(element, data, rootLayout) {
|
|
12573
13798
|
if (!rootLayout.layout) {
|
|
12574
13799
|
return element;
|
|
12575
13800
|
}
|
|
12576
13801
|
const RootLayoutComponent = rootLayout.layout;
|
|
12577
|
-
return
|
|
13802
|
+
return createElement6(RootLayoutComponent, data, element);
|
|
12578
13803
|
}
|
|
12579
13804
|
function buildNotFoundElement(component, error) {
|
|
12580
13805
|
const NotFound = component ?? DefaultNotFoundFallback;
|
|
@@ -12614,12 +13839,6 @@ function buildErrorElement(component, error, digest, messageOverride, status) {
|
|
|
12614
13839
|
}, undefined, false, undefined, this);
|
|
12615
13840
|
}
|
|
12616
13841
|
|
|
12617
|
-
// src/client.ts
|
|
12618
|
-
var DEFERRED_BRAND = Symbol.for("@teyik0/furin/deferred");
|
|
12619
|
-
function isDeferred(value) {
|
|
12620
|
-
return typeof value === "object" && value !== null && DEFERRED_BRAND in value && Object.hasOwn(value, DEFERRED_BRAND) && value[DEFERRED_BRAND] === true;
|
|
12621
|
-
}
|
|
12622
|
-
|
|
12623
13842
|
// src/rsc/render-error.ts
|
|
12624
13843
|
var INTERNAL_STACK_FRAMES = new Set([
|
|
12625
13844
|
"<anonymous>",
|
|
@@ -12683,17 +13902,88 @@ function isFurinRscRenderError(error) {
|
|
|
12683
13902
|
return error instanceof FurinRscRenderError || typeof error === "object" && error !== null && error.code === "FURIN_RSC_RENDER_ERROR";
|
|
12684
13903
|
}
|
|
12685
13904
|
|
|
13905
|
+
// src/shared/defer.ts
|
|
13906
|
+
var DEFERRED_BRAND = Symbol.for("@teyik0/furin/deferred");
|
|
13907
|
+
function isDeferred(value) {
|
|
13908
|
+
return typeof value === "object" && value !== null && DEFERRED_BRAND in value && Object.hasOwn(value, DEFERRED_BRAND) && value[DEFERRED_BRAND] === true;
|
|
13909
|
+
}
|
|
13910
|
+
|
|
12686
13911
|
// src/server/render/loaders.ts
|
|
12687
13912
|
init_context_logger();
|
|
12688
13913
|
init_instrumentation();
|
|
12689
13914
|
init_patterns();
|
|
12690
13915
|
|
|
13916
|
+
// src/server/sync/query-context.ts
|
|
13917
|
+
import { AsyncLocalStorage as AsyncLocalStorage6 } from "async_hooks";
|
|
13918
|
+
init_registry();
|
|
13919
|
+
init_instance();
|
|
13920
|
+
var QUERY_CONTEXT2 = Symbol.for("furin.query.server-context.v1");
|
|
13921
|
+
var contextGlobal3 = globalThis;
|
|
13922
|
+
var contexts = contextGlobal3[QUERY_CONTEXT2] ??= new AsyncLocalStorage6;
|
|
13923
|
+
setServerQueryEnvironment(() => contexts.getStore());
|
|
13924
|
+
var trackedQueryPaths = instanceSlot(() => new Set);
|
|
13925
|
+
var deferredQueries = new WeakMap;
|
|
13926
|
+
function deferredQuerySeeds(promise) {
|
|
13927
|
+
return deferredQueries.get(promise);
|
|
13928
|
+
}
|
|
13929
|
+
function captureQueryReads(ctx, run, owner) {
|
|
13930
|
+
const { origin } = new URL(ctx.request.url);
|
|
13931
|
+
const store = new QueryStore(origin);
|
|
13932
|
+
const registry = getAutoInvalidateRegistry();
|
|
13933
|
+
const trackedPaths = trackedQueryPaths();
|
|
13934
|
+
const requestUrl = new URL(ctx.request.url);
|
|
13935
|
+
const path = toLogical(requestUrl.pathname, currentInstance().prefix) + requestUrl.search;
|
|
13936
|
+
const onRead = () => {
|
|
13937
|
+
const seeds = store.dehydrate();
|
|
13938
|
+
registry.registerLoaderTags(path, seeds.map((seed) => queryTag(seed.identity)), owner ?? "eden-queries");
|
|
13939
|
+
trackedPaths.delete(path);
|
|
13940
|
+
if (seeds.length > 0) {
|
|
13941
|
+
trackedPaths.add(path);
|
|
13942
|
+
}
|
|
13943
|
+
if (trackedPaths.size > 1000) {
|
|
13944
|
+
const oldest = trackedPaths.values().next().value;
|
|
13945
|
+
if (oldest !== undefined) {
|
|
13946
|
+
trackedPaths.delete(oldest);
|
|
13947
|
+
registry.unregisterPath(oldest, "eden-queries");
|
|
13948
|
+
registry.unregisterPath(oldest, "eden-request-queries");
|
|
13949
|
+
}
|
|
13950
|
+
}
|
|
13951
|
+
};
|
|
13952
|
+
return contexts.run({ origin, store, onRead }, async () => {
|
|
13953
|
+
const result = { ...await run() };
|
|
13954
|
+
const seeds = store.dehydrate();
|
|
13955
|
+
if (result.type === "data" && seeds.length > 0) {
|
|
13956
|
+
const captured = [...result.syncData.__furinQueries ?? []];
|
|
13957
|
+
mergeQuerySeeds(captured, bindQueryData(result.syncData, seeds));
|
|
13958
|
+
result.syncData = { ...result.syncData, __furinQueries: captured };
|
|
13959
|
+
}
|
|
13960
|
+
if (result.type === "data" && result.deferredPromises) {
|
|
13961
|
+
for (const [key, promise] of Object.entries(result.deferredPromises)) {
|
|
13962
|
+
promise.then((value) => {
|
|
13963
|
+
const completed = store.dehydrate();
|
|
13964
|
+
if (completed.length > 0) {
|
|
13965
|
+
const captured = deferredQueries.get(promise) ?? [];
|
|
13966
|
+
mergeQuerySeeds(captured, bindQueryData({ [key]: value }, completed));
|
|
13967
|
+
deferredQueries.set(promise, captured);
|
|
13968
|
+
}
|
|
13969
|
+
}).catch(() => {
|
|
13970
|
+
return;
|
|
13971
|
+
});
|
|
13972
|
+
}
|
|
13973
|
+
}
|
|
13974
|
+
return result;
|
|
13975
|
+
});
|
|
13976
|
+
}
|
|
13977
|
+
|
|
12691
13978
|
// src/server/render/mixed-cache.ts
|
|
12692
13979
|
init_registry();
|
|
12693
13980
|
init_registry2();
|
|
12694
13981
|
init_context_logger();
|
|
12695
13982
|
init_instance();
|
|
12696
13983
|
init_source_version();
|
|
13984
|
+
function capturedQueryTags() {
|
|
13985
|
+
return currentQueryEnvironment()?.store.dehydrate().map((seed) => queryTag(seed.identity)) ?? [];
|
|
13986
|
+
}
|
|
12697
13987
|
var mixedCacheKey = Symbol("furin-mixed-loader-cache");
|
|
12698
13988
|
function cachePathWithSearch(key) {
|
|
12699
13989
|
const separator = key.indexOf("|");
|
|
@@ -12746,7 +14036,11 @@ async function readCachedSegment(entry, revalidate, parentData) {
|
|
|
12746
14036
|
return;
|
|
12747
14037
|
}
|
|
12748
14038
|
}
|
|
12749
|
-
|
|
14039
|
+
const environment = currentQueryEnvironment();
|
|
14040
|
+
environment?.store.hydrate(snapshot.queries ?? []);
|
|
14041
|
+
environment?.onRead();
|
|
14042
|
+
const data = fromCrossJSON(snapshot.data, {});
|
|
14043
|
+
return projectQueryData(data, snapshot.queries ?? [], (seed) => seed.data);
|
|
12750
14044
|
} catch {
|
|
12751
14045
|
getLogger().warn("Mixed loader cache entry is invalid; loading fresh data");
|
|
12752
14046
|
}
|
|
@@ -12759,7 +14053,8 @@ async function createSegmentSnapshot(data, parentData, parentFieldsRead) {
|
|
|
12759
14053
|
})));
|
|
12760
14054
|
return JSON.stringify({
|
|
12761
14055
|
data: await toCrossJSONAsync(data),
|
|
12762
|
-
dependencies
|
|
14056
|
+
dependencies,
|
|
14057
|
+
queries: bindQueryData(data, currentQueryEnvironment()?.store.dehydrate() ?? []).filter((seed) => (seed.bindings?.length ?? 0) > 0)
|
|
12763
14058
|
});
|
|
12764
14059
|
}
|
|
12765
14060
|
async function acquireSharedSegment(shared, identity) {
|
|
@@ -12786,6 +14081,10 @@ async function readSharedSegment(shared, identity, revalidate, parentData) {
|
|
|
12786
14081
|
}
|
|
12787
14082
|
}
|
|
12788
14083
|
async function commitSharedSegment(shared, identity, lease, cached, revalidate) {
|
|
14084
|
+
const identityTags = new Set(identity.tags);
|
|
14085
|
+
if (capturedQueryTags().some((tag) => !identityTags.has(tag))) {
|
|
14086
|
+
return;
|
|
14087
|
+
}
|
|
12789
14088
|
try {
|
|
12790
14089
|
await shared.commit({
|
|
12791
14090
|
entry: {
|
|
@@ -12813,6 +14112,7 @@ function storeLocalSegment(state, generation, key, path, tags, cached) {
|
|
|
12813
14112
|
}
|
|
12814
14113
|
async function cacheMixedPublicLoader(route, ctx, segment, index, parentData, parentFieldsRead, run) {
|
|
12815
14114
|
const instance = currentInstance();
|
|
14115
|
+
const declaredTags = route.tags ?? [];
|
|
12816
14116
|
const mode = segment.mode ?? route.mode;
|
|
12817
14117
|
const revalidate = mode === "isr" ? segment.revalidate ?? 60 : Number.POSITIVE_INFINITY;
|
|
12818
14118
|
const requestUrl = new URL(ctx.request.url);
|
|
@@ -12833,7 +14133,12 @@ async function cacheMixedPublicLoader(route, ctx, segment, index, parentData, pa
|
|
|
12833
14133
|
mode: mode === "isr" ? "isr" : "ssg",
|
|
12834
14134
|
path,
|
|
12835
14135
|
scope: instance.prefix,
|
|
12836
|
-
tags:
|
|
14136
|
+
tags: [
|
|
14137
|
+
...new Set([
|
|
14138
|
+
...declaredTags,
|
|
14139
|
+
...getAutoInvalidateRegistry().tagsForPath(`${path}${requestUrl.search}`)
|
|
14140
|
+
])
|
|
14141
|
+
]
|
|
12837
14142
|
};
|
|
12838
14143
|
const stored = shared === undefined ? undefined : await readSharedSegment(shared, identity, revalidate, parentData);
|
|
12839
14144
|
if (stored !== undefined) {
|
|
@@ -12849,7 +14154,7 @@ async function cacheMixedPublicLoader(route, ctx, segment, index, parentData, pa
|
|
|
12849
14154
|
cachedAt: Date.now(),
|
|
12850
14155
|
payload: await createSegmentSnapshot(data, parentData, parentFieldsRead)
|
|
12851
14156
|
};
|
|
12852
|
-
storeLocalSegment(localState, generation, key, `${path}${requestUrl.search}`,
|
|
14157
|
+
storeLocalSegment(localState, generation, key, `${path}${requestUrl.search}`, [...declaredTags, ...capturedQueryTags()], cached);
|
|
12853
14158
|
if (shared !== undefined && lease !== null) {
|
|
12854
14159
|
await commitSharedSegment(shared, identity, lease, cached, revalidate);
|
|
12855
14160
|
}
|
|
@@ -12884,6 +14189,12 @@ function assertPublicLoaderKey(key) {
|
|
|
12884
14189
|
throw new Error(`[furin] Loader data key "${key}" is reserved: it is overwritten by the route context when component props are assembled. Rename this field to avoid conflicts.`);
|
|
12885
14190
|
}
|
|
12886
14191
|
}
|
|
14192
|
+
function assertRequestLoaderKey(key, ctx) {
|
|
14193
|
+
assertPublicLoaderKey(key);
|
|
14194
|
+
if (key === "log" || Object.hasOwn(ctx, key) || key in ctx && !Object.hasOwn(Object.prototype, key)) {
|
|
14195
|
+
throw new Error(`[furin] requestLoader data key "${key}" is reserved: it is overwritten by the SSR loader context. Rename this field to avoid conflicts.`);
|
|
14196
|
+
}
|
|
14197
|
+
}
|
|
12887
14198
|
function isHttpRedirect(res) {
|
|
12888
14199
|
return REDIRECT_STATUSES.has(res.status) && res.headers.has("location");
|
|
12889
14200
|
}
|
|
@@ -12898,7 +14209,7 @@ async function readResponseMessage(res) {
|
|
|
12898
14209
|
return res.statusText;
|
|
12899
14210
|
}
|
|
12900
14211
|
}
|
|
12901
|
-
function createLoaderCtx(ctx, accumulatedParentPromise, onParentFieldAccess) {
|
|
14212
|
+
function createLoaderCtx(ctx, accumulatedParentPromise, inheritedRequestFields, onParentFieldAccess) {
|
|
12902
14213
|
const cache = new Map;
|
|
12903
14214
|
return new Proxy(ctx, {
|
|
12904
14215
|
get(target, prop) {
|
|
@@ -12911,6 +14222,9 @@ function createLoaderCtx(ctx, accumulatedParentPromise, onParentFieldAccess) {
|
|
|
12911
14222
|
if (Object.hasOwn(target, prop) || prop in target && !Object.hasOwn(Object.prototype, prop)) {
|
|
12912
14223
|
return target[prop];
|
|
12913
14224
|
}
|
|
14225
|
+
if (inheritedRequestFields && Object.hasOwn(inheritedRequestFields, prop)) {
|
|
14226
|
+
return inheritedRequestFields[prop];
|
|
14227
|
+
}
|
|
12914
14228
|
onParentFieldAccess?.(prop);
|
|
12915
14229
|
let entry = cache.get(prop);
|
|
12916
14230
|
if (!entry) {
|
|
@@ -13023,6 +14337,8 @@ function runRequestLoaderFields(route, ctx) {
|
|
|
13023
14337
|
if (declarations?.length !== route.routeChain.length) {
|
|
13024
14338
|
throw new Error(`[furin] Missing per-loader request field metadata for ${route.pattern}.`);
|
|
13025
14339
|
}
|
|
14340
|
+
const declaredKeys = declarations.map((keys) => new Set(keys));
|
|
14341
|
+
const requestKeys = new Set(route.requestKeys);
|
|
13026
14342
|
const requestContext = createRequestLoaderContext(ctx);
|
|
13027
14343
|
const results = loaderIndexes.map((index) => {
|
|
13028
14344
|
const loader = route.routeChain[index]?.requestLoader;
|
|
@@ -13033,8 +14349,8 @@ function runRequestLoaderFields(route, ctx) {
|
|
|
13033
14349
|
const result = observeLoader(() => invocation, `request:${index}`, ctx.path).then((value) => {
|
|
13034
14350
|
const data = value;
|
|
13035
14351
|
for (const key of Object.keys(data)) {
|
|
13036
|
-
|
|
13037
|
-
if (!
|
|
14352
|
+
assertRequestLoaderKey(key, ctx);
|
|
14353
|
+
if (!declaredKeys[index]?.has(key)) {
|
|
13038
14354
|
throw new Error(`[furin] requestLoader in ${route.pattern} returned undeclared field "${key}".`);
|
|
13039
14355
|
}
|
|
13040
14356
|
}
|
|
@@ -13043,27 +14359,36 @@ function runRequestLoaderFields(route, ctx) {
|
|
|
13043
14359
|
result.catch(() => {});
|
|
13044
14360
|
return { index, result };
|
|
13045
14361
|
});
|
|
13046
|
-
|
|
14362
|
+
let fields = {};
|
|
14363
|
+
const fieldsByLoader = route.routeChain.map((_, boundaryIndex) => {
|
|
14364
|
+
fields = { ...fields };
|
|
14365
|
+
for (const key of declarations[boundaryIndex] ?? []) {
|
|
14366
|
+
if (!requestKeys.has(key)) {
|
|
14367
|
+
continue;
|
|
14368
|
+
}
|
|
14369
|
+
const candidates = results.filter(({ index }) => index <= boundaryIndex && declaredKeys[index]?.has(key));
|
|
14370
|
+
fields[key] = Promise.all(candidates.map(({ result }) => result)).then((values) => {
|
|
14371
|
+
for (let index = values.length - 1;index >= 0; index -= 1) {
|
|
14372
|
+
const data = values[index];
|
|
14373
|
+
if (data && Object.hasOwn(data, key)) {
|
|
14374
|
+
return data[key];
|
|
14375
|
+
}
|
|
14376
|
+
}
|
|
14377
|
+
});
|
|
14378
|
+
fields[key].catch(() => {});
|
|
14379
|
+
}
|
|
14380
|
+
return fields;
|
|
14381
|
+
});
|
|
13047
14382
|
for (const key of route.requestKeys) {
|
|
13048
|
-
|
|
13049
|
-
if (candidates.length === 0) {
|
|
14383
|
+
if (!Object.hasOwn(fields, key)) {
|
|
13050
14384
|
throw new Error(`[furin] No requestLoader declares field "${key}" in ${route.pattern}.`);
|
|
13051
14385
|
}
|
|
13052
|
-
fields[key] = Promise.all(candidates.map(({ result }) => result)).then((values) => {
|
|
13053
|
-
for (let index = values.length - 1;index >= 0; index -= 1) {
|
|
13054
|
-
const data = values[index];
|
|
13055
|
-
if (data && Object.hasOwn(data, key)) {
|
|
13056
|
-
return data[key];
|
|
13057
|
-
}
|
|
13058
|
-
}
|
|
13059
|
-
});
|
|
13060
|
-
fields[key].catch(() => {});
|
|
13061
14386
|
}
|
|
13062
14387
|
const noFieldCompletion = Promise.all(results.filter(({ index }) => declarations[index]?.length === 0).map(({ result }) => result)).then(() => {
|
|
13063
14388
|
return;
|
|
13064
14389
|
});
|
|
13065
14390
|
noFieldCompletion.catch(() => {});
|
|
13066
|
-
return { fields, noFieldCompletion };
|
|
14391
|
+
return { fields, fieldsByLoader, noFieldCompletion };
|
|
13067
14392
|
}
|
|
13068
14393
|
function requestFieldPromises(route, fields, syncData, publicDeferred) {
|
|
13069
14394
|
for (const key of Object.keys(fields)) {
|
|
@@ -13144,6 +14469,15 @@ async function normalizeLoaderError(err, headers) {
|
|
|
13144
14469
|
const message = body || "Something went wrong";
|
|
13145
14470
|
return { error: err, headers, message, status, type: "error" };
|
|
13146
14471
|
}
|
|
14472
|
+
if (err instanceof Error && "status" in err && typeof err.status === "number" && err.status >= 400 && err.status <= 599 && "value" in err && err.value !== null && typeof err.value === "object" && "status" in err.value && err.value.status === err.status && "type" in err.value && typeof err.value.type === "string") {
|
|
14473
|
+
let message = "Something went wrong";
|
|
14474
|
+
if ("detail" in err.value && typeof err.value.detail === "string") {
|
|
14475
|
+
message = err.value.detail;
|
|
14476
|
+
} else if ("title" in err.value && typeof err.value.title === "string") {
|
|
14477
|
+
message = err.value.title;
|
|
14478
|
+
}
|
|
14479
|
+
return { error: err, headers, message, status: err.status, type: "error" };
|
|
14480
|
+
}
|
|
13147
14481
|
if (isFurinRscRenderError(err)) {
|
|
13148
14482
|
getLogger().error(err);
|
|
13149
14483
|
return {
|
|
@@ -13172,10 +14506,10 @@ function mergeParentData(parent, own, path) {
|
|
|
13172
14506
|
}
|
|
13173
14507
|
return { ...parent, ...own };
|
|
13174
14508
|
}
|
|
13175
|
-
function startSegmentLoader(route, ctx, segment, index, label, parent, publicParent, ctxRecord, publicCtxRecord, mixed) {
|
|
14509
|
+
function startSegmentLoader(route, ctx, segment, index, label, parent, publicParent, inheritedRequestFields, ctxRecord, publicCtxRecord, mixed) {
|
|
13176
14510
|
const publicSegment = mixed && (segment.mode ?? route.mode) !== "ssr";
|
|
13177
14511
|
const parentFieldsRead = new Set;
|
|
13178
|
-
const loaderCtx = createLoaderCtx(publicSegment ? publicCtxRecord : ctxRecord, publicSegment ? publicParent : parent, publicSegment ? (key) => parentFieldsRead.add(key) : undefined);
|
|
14512
|
+
const loaderCtx = createLoaderCtx(publicSegment ? publicCtxRecord : ctxRecord, publicSegment ? publicParent : parent, publicSegment ? undefined : inheritedRequestFields, publicSegment ? (key) => parentFieldsRead.add(key) : undefined);
|
|
13179
14513
|
return observeLoader(() => {
|
|
13180
14514
|
const run = async () => await segment.loader?.(loaderCtx) ?? {};
|
|
13181
14515
|
return publicSegment ? cacheMixedPublicLoader(route, ctx, segment, index, publicParent, parentFieldsRead, run) : run();
|
|
@@ -13190,13 +14524,13 @@ async function runLoadersInternal(route, ctx, includeRequestData, mixed) {
|
|
|
13190
14524
|
let accumulatedParentPromise = Promise.resolve({});
|
|
13191
14525
|
let publicParentPromise = Promise.resolve({});
|
|
13192
14526
|
let loaderIndex = 0;
|
|
13193
|
-
for (const r of route.routeChain) {
|
|
14527
|
+
for (const [routeIndex, r] of route.routeChain.entries()) {
|
|
13194
14528
|
const parentAccum = accumulatedParentPromise;
|
|
13195
14529
|
const publicParent = publicParentPromise;
|
|
13196
14530
|
const privateSegment = mixed && (r.mode ?? route.mode) === "ssr";
|
|
13197
14531
|
if (r.loader) {
|
|
13198
14532
|
const index = loaderIndex;
|
|
13199
|
-
const loaderPromise = startSegmentLoader(route, ctx, r, index, `layout:${loaderIndex}`, parentAccum, publicParent, ctxRecord, publicCtxRecord, mixed);
|
|
14533
|
+
const loaderPromise = startSegmentLoader(route, ctx, r, index, `layout:${loaderIndex}`, parentAccum, publicParent, requestFields?.fieldsByLoader[routeIndex - 1], ctxRecord, publicCtxRecord, mixed);
|
|
13200
14534
|
loaderIndex += 1;
|
|
13201
14535
|
loaderMap.set(r, loaderPromise);
|
|
13202
14536
|
accumulatedParentPromise = Promise.all([parentAccum, loaderPromise]).then(([acc, own]) => mergeParentData(acc, own, ctx.path));
|
|
@@ -13210,7 +14544,7 @@ async function runLoadersInternal(route, ctx, includeRequestData, mixed) {
|
|
|
13210
14544
|
}
|
|
13211
14545
|
}
|
|
13212
14546
|
}
|
|
13213
|
-
const pagePromise = route.page.loader ? startSegmentLoader(route, ctx, route.page, route.routeChain.length, "page", accumulatedParentPromise, publicParentPromise, ctxRecord, publicCtxRecord, mixed) : Promise.resolve({});
|
|
14547
|
+
const pagePromise = route.page.loader ? startSegmentLoader(route, ctx, route.page, route.routeChain.length, "page", accumulatedParentPromise, publicParentPromise, requestFields?.fields, ctxRecord, publicCtxRecord, mixed) : Promise.resolve({});
|
|
13214
14548
|
const results = await Promise.all([...loaderMap.values(), pagePromise]);
|
|
13215
14549
|
await requestFields?.noFieldCompletion;
|
|
13216
14550
|
const headers = {};
|
|
@@ -13253,10 +14587,10 @@ function createPublicLoaderContext(ctx) {
|
|
|
13253
14587
|
return publicContext;
|
|
13254
14588
|
}
|
|
13255
14589
|
function runLoaders(route, ctx) {
|
|
13256
|
-
return runLoadersInternal(route, ctx, true, false);
|
|
14590
|
+
return captureQueryReads(ctx, () => runLoadersInternal(route, ctx, true, false));
|
|
13257
14591
|
}
|
|
13258
14592
|
function runPublicLoaders(route, ctx) {
|
|
13259
|
-
return runLoadersInternal(route, ctx, false, false);
|
|
14593
|
+
return captureQueryReads(ctx, () => runLoadersInternal(route, ctx, false, false));
|
|
13260
14594
|
}
|
|
13261
14595
|
function hasSsrLoaderAncestor(route) {
|
|
13262
14596
|
return route.routeChain.some((entry) => entry.mode === "ssr" && entry.loader !== undefined);
|
|
@@ -13266,26 +14600,53 @@ function hasMixedLoaderModes(route) {
|
|
|
13266
14600
|
return route.routeChain.some((entry) => entry.loader !== undefined && entry.mode !== undefined && (entry.mode !== route.mode || entry.mode === "isr" && (entry.revalidate ?? 60) !== pageRevalidate));
|
|
13267
14601
|
}
|
|
13268
14602
|
function runMixedLoaders(route, ctx) {
|
|
13269
|
-
return runLoadersInternal(route, ctx, true, true);
|
|
14603
|
+
return captureQueryReads(ctx, () => runLoadersInternal(route, ctx, true, true));
|
|
13270
14604
|
}
|
|
13271
14605
|
function runRouteLoaders(route, ctx) {
|
|
13272
14606
|
return hasMixedLoaderModes(route) ? runMixedLoaders(route, ctx) : runLoaders(route, ctx);
|
|
13273
14607
|
}
|
|
13274
14608
|
function runSegmentPublicLoaders(route, ctx) {
|
|
13275
|
-
return runLoadersInternal(route, ctx, false, true);
|
|
14609
|
+
return captureQueryReads(ctx, () => runLoadersInternal(route, ctx, false, true));
|
|
13276
14610
|
}
|
|
13277
14611
|
function hasRequestLoader(route) {
|
|
13278
14612
|
return route.routeChain.some((entry) => entry.requestLoader !== undefined);
|
|
13279
14613
|
}
|
|
13280
14614
|
|
|
14615
|
+
// src/server/render/react-stream.ts
|
|
14616
|
+
import { AsyncLocalStorage as AsyncLocalStorage7 } from "async_hooks";
|
|
14617
|
+
import { renderToReadableStream as renderReactStream } from "react-dom/server";
|
|
14618
|
+
|
|
14619
|
+
// src/client/client-module.ts
|
|
14620
|
+
import { preloadModule as preloadModule2 } from "react-dom";
|
|
14621
|
+
var resolveModuleHrefs = () => [];
|
|
14622
|
+
var resolveNonce = () => {
|
|
14623
|
+
return;
|
|
14624
|
+
};
|
|
14625
|
+
function setClientModuleNonceResolver(resolver) {
|
|
14626
|
+
resolveNonce = resolver;
|
|
14627
|
+
}
|
|
14628
|
+
function setClientModuleHrefResolver(resolver) {
|
|
14629
|
+
resolveModuleHrefs = resolver;
|
|
14630
|
+
}
|
|
14631
|
+
|
|
14632
|
+
// src/server/render/react-stream.ts
|
|
14633
|
+
var renderNonces = new AsyncLocalStorage7;
|
|
14634
|
+
setClientModuleNonceResolver(() => renderNonces.getStore());
|
|
14635
|
+
function renderToReadableStream(element, options) {
|
|
14636
|
+
const nonce = options?.nonce;
|
|
14637
|
+
return renderNonces.run(typeof nonce === "string" ? nonce : nonce?.script, () => renderReactStream(element, options));
|
|
14638
|
+
}
|
|
14639
|
+
|
|
13281
14640
|
// src/server/render/route-frame-transport.ts
|
|
13282
14641
|
async function serializeDeferredRouteFrame(key, promise, idPrefix) {
|
|
13283
14642
|
try {
|
|
13284
14643
|
const { rscFrames, value } = serializeRouteFrameValue(await promise, idPrefix);
|
|
14644
|
+
const queries = deferredQuerySeeds(promise);
|
|
13285
14645
|
return serializeRouteFrame({
|
|
13286
14646
|
key,
|
|
13287
14647
|
type: "defer-resolve",
|
|
13288
|
-
value
|
|
14648
|
+
value,
|
|
14649
|
+
...queries && { queries: toCrossJSON(queries) }
|
|
13289
14650
|
}) + rscFrames;
|
|
13290
14651
|
} catch (error) {
|
|
13291
14652
|
return serializeRouteFrame({
|
|
@@ -13297,16 +14658,17 @@ async function serializeDeferredRouteFrame(key, promise, idPrefix) {
|
|
|
13297
14658
|
}
|
|
13298
14659
|
|
|
13299
14660
|
// src/server/render/template.ts
|
|
14661
|
+
import { readFileSync as readFileSync7 } from "fs";
|
|
13300
14662
|
init_plugin();
|
|
13301
14663
|
init_instrumentation();
|
|
13302
14664
|
init_instance();
|
|
13303
|
-
import { readFileSync as readFileSync5 } from "fs";
|
|
13304
14665
|
var instanceTemplateState = instanceSlot(() => ({
|
|
13305
14666
|
devAssets: null,
|
|
13306
14667
|
devCache: null,
|
|
13307
14668
|
prodAssets: null,
|
|
13308
14669
|
prodContent: null,
|
|
13309
|
-
prodPath: null
|
|
14670
|
+
prodPath: null,
|
|
14671
|
+
prodPreload: null
|
|
13310
14672
|
}));
|
|
13311
14673
|
var DEV_TEMPLATE_TTL_MS = 1000;
|
|
13312
14674
|
var TAG_ATTRIBUTE_PATTERN = /([A-Za-z][\w:-]*)="([^"]*)"/g;
|
|
@@ -13424,7 +14786,7 @@ function readTemplate(state) {
|
|
|
13424
14786
|
return null;
|
|
13425
14787
|
}
|
|
13426
14788
|
try {
|
|
13427
|
-
state.prodContent =
|
|
14789
|
+
state.prodContent = readFileSync7(state.prodPath, "utf8");
|
|
13428
14790
|
return state.prodContent;
|
|
13429
14791
|
} catch {
|
|
13430
14792
|
return null;
|
|
@@ -13441,10 +14803,17 @@ function readDocumentAssets(state) {
|
|
|
13441
14803
|
state.prodAssets = documentAssetsFromTemplate(template);
|
|
13442
14804
|
return state.prodAssets;
|
|
13443
14805
|
}
|
|
14806
|
+
function setProductionPreloadManifest(manifest, instance) {
|
|
14807
|
+
instanceTemplateState(instance).prodPreload = manifest;
|
|
14808
|
+
}
|
|
14809
|
+
function getProductionPreloadManifest() {
|
|
14810
|
+
return instanceTemplateState().prodPreload ?? instanceTemplateState(defaultInstanceBucket()).prodPreload;
|
|
14811
|
+
}
|
|
14812
|
+
setClientModuleHrefResolver((key) => getProductionPreloadManifest()?.modules[key] ?? []);
|
|
13444
14813
|
|
|
13445
14814
|
// src/server/render/ssr.ts
|
|
13446
14815
|
function withSSRRouterContext(element, contextValue) {
|
|
13447
|
-
return
|
|
14816
|
+
return createElement7(SearchStoreContext.Provider, { value: createSearchStore(searchSnapshotFromRouterContext(contextValue)) }, createElement7(RouterContext.Provider, { value: contextValue }, element));
|
|
13448
14817
|
}
|
|
13449
14818
|
function hasDocumentMarkers(html) {
|
|
13450
14819
|
return html.includes('data-furin-head=""') && html.includes('data-furin-scripts=""');
|
|
@@ -13513,7 +14882,8 @@ async function renderElementWithShellFallback(element, errorComponent, ssrContex
|
|
|
13513
14882
|
}
|
|
13514
14883
|
}
|
|
13515
14884
|
function assertDeferredModeAllowed(route, deferredPromises) {
|
|
13516
|
-
const
|
|
14885
|
+
const requestKeys = new Set(route.requestKeys);
|
|
14886
|
+
const deferredKeys = Object.keys(deferredPromises ?? {}).filter((key) => !requestKeys.has(key));
|
|
13517
14887
|
if (deferredKeys.length > 0 && route.mode !== "ssr" && !hasSsrLoaderAncestor(route)) {
|
|
13518
14888
|
throw new Error(`[furin] page "${route.pattern}" returned defer() but the route is rendered in "${route.mode}" mode. ` + "defer() streams data progressively and is only supported in SSR. " + "Return the data directly (await it inside the loader) or switch the route to SSR mode.");
|
|
13519
14889
|
}
|
|
@@ -13548,6 +14918,10 @@ function resolveDocumentAssets(ctx) {
|
|
|
13548
14918
|
}
|
|
13549
14919
|
return documentAssetsFromTemplate(generateIndexHtml());
|
|
13550
14920
|
}
|
|
14921
|
+
function withRouteModulePreloads(assets, pattern) {
|
|
14922
|
+
const modulePreloads = getProductionPreloadManifest()?.routes[pattern];
|
|
14923
|
+
return modulePreloads ? { ...assets, modulePreloads } : assets;
|
|
14924
|
+
}
|
|
13551
14925
|
async function prepareRender(route, ctx, root, basePath, throwOnFailure, precomputedLoaderResult, searchRoutes) {
|
|
13552
14926
|
const loaderStart = Date.now();
|
|
13553
14927
|
const loaderResult = precomputedLoaderResult ?? await runRouteLoaders(route, ctx);
|
|
@@ -13555,7 +14929,7 @@ async function prepareRender(route, ctx, root, basePath, throwOnFailure, precomp
|
|
|
13555
14929
|
if (loaderResult.type === "redirect") {
|
|
13556
14930
|
return loaderResult.response;
|
|
13557
14931
|
}
|
|
13558
|
-
if (throwOnFailure &&
|
|
14932
|
+
if (throwOnFailure && loaderResult.type === "error") {
|
|
13559
14933
|
throw loaderResult.error;
|
|
13560
14934
|
}
|
|
13561
14935
|
const isNotFound = loaderResult.type === "not-found";
|
|
@@ -13566,7 +14940,7 @@ async function prepareRender(route, ctx, root, basePath, throwOnFailure, precomp
|
|
|
13566
14940
|
assertDeferredModeAllowed(route, deferredPromises);
|
|
13567
14941
|
const { headers } = loaderResult;
|
|
13568
14942
|
const componentProps = deferredPromises === undefined ? syncData : { ...syncData, ...deferredPromises };
|
|
13569
|
-
const assets = await resolveDocumentAssets(ctx);
|
|
14943
|
+
const assets = withRouteModulePreloads(await resolveDocumentAssets(ctx), route.pattern);
|
|
13570
14944
|
const errorComponent = route.error ?? root.error;
|
|
13571
14945
|
let element;
|
|
13572
14946
|
let headData;
|
|
@@ -13594,6 +14968,7 @@ async function prepareRender(route, ctx, root, basePath, throwOnFailure, precomp
|
|
|
13594
14968
|
const ssrContext = {
|
|
13595
14969
|
basePath: resolvedBasePath,
|
|
13596
14970
|
currentHref: currentHrefFromContext(ctx, resolvedBasePath),
|
|
14971
|
+
currentPattern: route.pattern,
|
|
13597
14972
|
defaultPreload: "intent",
|
|
13598
14973
|
defaultPreloadDelay: 50,
|
|
13599
14974
|
defaultPreloadStaleTime: 30000,
|
|
@@ -13624,7 +14999,7 @@ async function prepareRender(route, ctx, root, basePath, throwOnFailure, precomp
|
|
|
13624
14999
|
}
|
|
13625
15000
|
async function renderBufferedResult(prepared, route, root) {
|
|
13626
15001
|
const { assets, deferredPromises, element, headData, headers, syncData } = prepared;
|
|
13627
|
-
const { shellError, stream } = await renderElementWithShellFallback(withDocumentState(element, assets, headData, syncData), route.error ?? root.error, prepared.ssrContext, (fallback, digest, message) => withDocumentState(
|
|
15002
|
+
const { shellError, stream } = await renderElementWithShellFallback(withDocumentState(element, assets, headData, syncData), route.error ?? root.error, prepared.ssrContext, (fallback, digest, message) => withDocumentState(createElement7(FurinDocumentFallback, null, fallback), assets, headData, {
|
|
13628
15003
|
__furinError: { digest, message, status: 500 },
|
|
13629
15004
|
__furinStatus: 500
|
|
13630
15005
|
}));
|
|
@@ -13649,9 +15024,30 @@ async function renderBufferedResult(prepared, route, root) {
|
|
|
13649
15024
|
headers,
|
|
13650
15025
|
html,
|
|
13651
15026
|
ndjson: await serializeLoaderDataNdjson(syncData, deferredPromises),
|
|
15027
|
+
queryTags: queryTagsFromData(syncData),
|
|
13652
15028
|
status: prepared.status
|
|
13653
15029
|
};
|
|
13654
15030
|
}
|
|
15031
|
+
async function normalizePrerenderContext(route, ctx) {
|
|
15032
|
+
const parsedParams = await parseRouteParams(ctx.params, mergeRouteSchemas(route.routeChain, "params"));
|
|
15033
|
+
if (!parsedParams.ok) {
|
|
15034
|
+
throw new Error(`[furin] Invalid prerender params for "${route.pattern}".`, {
|
|
15035
|
+
cause: parsedParams.errors
|
|
15036
|
+
});
|
|
15037
|
+
}
|
|
15038
|
+
ctx.params = parsedParams.params;
|
|
15039
|
+
const querySchema = mergeRouteSchemas(route.routeChain, "query");
|
|
15040
|
+
if (querySchema === undefined) {
|
|
15041
|
+
return;
|
|
15042
|
+
}
|
|
15043
|
+
const parsedQuery = await parseRouteQuery(new URL(ctx.request.url), querySchema);
|
|
15044
|
+
if (!parsedQuery.ok) {
|
|
15045
|
+
throw new Error(`[furin] Invalid prerender query for "${route.pattern}".`, {
|
|
15046
|
+
cause: parsedQuery.errors
|
|
15047
|
+
});
|
|
15048
|
+
}
|
|
15049
|
+
ctx.query = parsedQuery.query;
|
|
15050
|
+
}
|
|
13655
15051
|
function renderForPath(route, params, root, origin, mode, basePath, searchRoutes, search, requestContext) {
|
|
13656
15052
|
return runInSyntheticRenderScope(async () => {
|
|
13657
15053
|
const resolvedPath = resolvePath(route.pattern, params);
|
|
@@ -13677,6 +15073,9 @@ function renderForPath(route, params, root, origin, mode, basePath, searchRoutes
|
|
|
13677
15073
|
request: new Request(requestUrl),
|
|
13678
15074
|
set: { headers: {} }
|
|
13679
15075
|
};
|
|
15076
|
+
if (requestContext === undefined) {
|
|
15077
|
+
await normalizePrerenderContext(route, ctx);
|
|
15078
|
+
}
|
|
13680
15079
|
const loaderResult = await (hasMixedLoaderModes(route) ? runSegmentPublicLoaders(route, ctx) : runPublicLoaders(route, ctx));
|
|
13681
15080
|
const prepared = await prepareRender(route, ctx, root, basePath, true, loaderResult, searchRoutes);
|
|
13682
15081
|
if (prepared instanceof Response) {
|
|
@@ -13717,7 +15116,7 @@ async function serializeLoaderDataNdjson(syncData, deferredPromises) {
|
|
|
13717
15116
|
}
|
|
13718
15117
|
|
|
13719
15118
|
// src/server/render/static-params.ts
|
|
13720
|
-
import { dirname as
|
|
15119
|
+
import { dirname as dirname10, relative as relative6 } from "path";
|
|
13721
15120
|
init_patterns();
|
|
13722
15121
|
var STATIC_PARAMS_CONCURRENCY = 4;
|
|
13723
15122
|
function collectStaticParamsStages(route) {
|
|
@@ -13738,8 +15137,8 @@ function ancestorPattern(route, ancestors) {
|
|
|
13738
15137
|
if (rootSourcePath === undefined || ancestorSourcePath === undefined) {
|
|
13739
15138
|
return route.pattern;
|
|
13740
15139
|
}
|
|
13741
|
-
const pagesDir =
|
|
13742
|
-
const ancestorDir =
|
|
15140
|
+
const pagesDir = dirname10(rootSourcePath);
|
|
15141
|
+
const ancestorDir = dirname10(ancestorSourcePath);
|
|
13743
15142
|
if (ancestorDir === pagesDir) {
|
|
13744
15143
|
return "/";
|
|
13745
15144
|
}
|
|
@@ -13839,25 +15238,44 @@ async function prerenderRoute(route, params, root, origin, mode, basePath, searc
|
|
|
13839
15238
|
html: renderResult.html,
|
|
13840
15239
|
ndjson: renderResult.ndjson,
|
|
13841
15240
|
status: renderResult.status,
|
|
13842
|
-
tags: route.tags
|
|
15241
|
+
tags: [...route.tags ?? [], ...renderResult.queryTags ?? []]
|
|
13843
15242
|
};
|
|
13844
15243
|
}
|
|
13845
|
-
async function
|
|
15244
|
+
async function prerenderLocalSSG(route, params, root, origin, basePath, searchRoutes) {
|
|
13846
15245
|
const resolvedPath = resolvePath(route.pattern, params);
|
|
13847
15246
|
const cached = getSSGCache(resolvedPath);
|
|
13848
15247
|
if (cached) {
|
|
13849
15248
|
if (cached.tags === route.tags) {
|
|
13850
|
-
return cached;
|
|
15249
|
+
return { cacheStored: true, entry: cached };
|
|
13851
15250
|
}
|
|
13852
|
-
const taggedEntry = {
|
|
15251
|
+
const taggedEntry = {
|
|
15252
|
+
...cached,
|
|
15253
|
+
tags: [
|
|
15254
|
+
...route.tags ?? [],
|
|
15255
|
+
...(cached.tags ?? []).filter((tag) => queryFromTag(tag) !== undefined)
|
|
15256
|
+
]
|
|
15257
|
+
};
|
|
13853
15258
|
setSSGCache(resolvedPath, taggedEntry);
|
|
13854
|
-
return taggedEntry;
|
|
15259
|
+
return { cacheStored: true, entry: taggedEntry };
|
|
13855
15260
|
}
|
|
13856
|
-
const
|
|
13857
|
-
|
|
13858
|
-
|
|
15261
|
+
const cache = ssgRouteCache();
|
|
15262
|
+
const generation = cache.captureGeneration(resolvedPath);
|
|
15263
|
+
try {
|
|
15264
|
+
const entry = await prerenderRoute(route, params, root, origin, "ssg", basePath, searchRoutes);
|
|
15265
|
+
if (entry instanceof Response || entry.status !== 200 || !generation.valid) {
|
|
15266
|
+
return { cacheStored: false, entry };
|
|
15267
|
+
}
|
|
15268
|
+
setSSGCache(resolvedPath, entry);
|
|
15269
|
+
return { cacheStored: true, entry };
|
|
15270
|
+
} finally {
|
|
15271
|
+
cache.releaseGeneration(resolvedPath, generation);
|
|
15272
|
+
}
|
|
15273
|
+
}
|
|
15274
|
+
async function prerenderSSG(route, params, root, origin, basePath, searchRoutes) {
|
|
15275
|
+
const { entry } = await prerenderLocalSSG(route, params, root, origin, basePath, searchRoutes);
|
|
15276
|
+
if (!(entry instanceof Response) && entry.status >= 500) {
|
|
15277
|
+
throw new Error(`[furin] Failed to prerender SSG route "${route.pattern}" (HTTP ${entry.status}).`);
|
|
13859
15278
|
}
|
|
13860
|
-
setSSGCache(resolvedPath, entry);
|
|
13861
15279
|
return entry;
|
|
13862
15280
|
}
|
|
13863
15281
|
// src/build/ssg-cache.ts
|
|
@@ -13920,9 +15338,9 @@ async function buildSSGCacheSnapshot(routes, root, origin, basePath) {
|
|
|
13920
15338
|
}
|
|
13921
15339
|
|
|
13922
15340
|
// src/rsc/build/index.ts
|
|
13923
|
-
import { mkdirSync as mkdirSync4, writeFileSync as
|
|
13924
|
-
import { basename as
|
|
13925
|
-
import { fileURLToPath as
|
|
15341
|
+
import { mkdirSync as mkdirSync4, writeFileSync as writeFileSync6 } from "fs";
|
|
15342
|
+
import { basename as basename4, join as join11 } from "path";
|
|
15343
|
+
import { fileURLToPath as fileURLToPath5 } from "url";
|
|
13926
15344
|
init_transform_isomorphic();
|
|
13927
15345
|
|
|
13928
15346
|
// src/rsc/version.ts
|
|
@@ -13971,9 +15389,9 @@ function assertInstalledRscVersions() {
|
|
|
13971
15389
|
// src/rsc/build/index.ts
|
|
13972
15390
|
async function buildRscGraph(apps, outDir, buildId, userPlugins) {
|
|
13973
15391
|
await assertInstalledRscVersions();
|
|
13974
|
-
const graphDir =
|
|
15392
|
+
const graphDir = join11(outDir, "rsc");
|
|
13975
15393
|
mkdirSync4(graphDir, { recursive: true });
|
|
13976
|
-
const rscEntry =
|
|
15394
|
+
const rscEntry = fileURLToPath5(import.meta.resolve("../../rsc-server.tsx"));
|
|
13977
15395
|
const entrypoints = [
|
|
13978
15396
|
...new Set(apps.flatMap(({ root, routes }) => [
|
|
13979
15397
|
root.path,
|
|
@@ -14013,7 +15431,7 @@ ${result.logs.map((log) => log.message).join(`
|
|
|
14013
15431
|
`)}`);
|
|
14014
15432
|
}
|
|
14015
15433
|
const codecResult = await runBunBuild({
|
|
14016
|
-
entrypoints: [
|
|
15434
|
+
entrypoints: [fileURLToPath5(import.meta.resolve("../server-codec.ts"))],
|
|
14017
15435
|
outdir: outDir,
|
|
14018
15436
|
target: "bun",
|
|
14019
15437
|
format: "esm",
|
|
@@ -14031,22 +15449,23 @@ ${result.logs.map((log) => log.message).join(`
|
|
|
14031
15449
|
${codecResult.logs.map((log) => log.message).join(`
|
|
14032
15450
|
`)}`);
|
|
14033
15451
|
}
|
|
14034
|
-
const css = result.outputs.filter((output) => output.path.endsWith(".css")).map((output) => ({ href: `/_rsc/${
|
|
15452
|
+
const css = result.outputs.filter((output) => output.path.endsWith(".css")).map((output) => ({ href: `/_rsc/${basename4(output.path)}` }));
|
|
14035
15453
|
const manifest = { buildId, clientReferences: [], css };
|
|
14036
|
-
|
|
15454
|
+
writeFileSync6(join11(graphDir, "manifest.json"), JSON.stringify(manifest, null, 2));
|
|
14037
15455
|
return manifest;
|
|
14038
15456
|
}
|
|
14039
15457
|
|
|
14040
15458
|
// src/adapter/runtime-build.ts
|
|
14041
15459
|
init_patterns();
|
|
14042
|
-
var _pkgRoot2 =
|
|
14043
|
-
var _pkgSrcDir2 =
|
|
15460
|
+
var _pkgRoot2 = dirname11(dirname11(fileURLToPath6(import.meta.resolve("@teyik0/furin"))));
|
|
15461
|
+
var _pkgSrcDir2 = existsSync10(join12(_pkgRoot2, "src", "furin.ts")) ? join12(_pkgRoot2, "src") : join12(_pkgRoot2, "dist");
|
|
14044
15462
|
var _ext2 = ".ts";
|
|
14045
15463
|
var PPR_ROUTE_IMPORT_RE = /ppr-route(?:\.ts)?$/;
|
|
14046
15464
|
var MIXED_CACHE_IMPORT_RE = /mixed-cache(?:\.ts)?$/;
|
|
14047
15465
|
var ANY_MODULE_RE = /.*/;
|
|
14048
15466
|
var REACT_SERVER_IMPORT_RE = /^react-dom\/server(?:\.edge)?$/;
|
|
14049
15467
|
var REACT_STATIC_IMPORT_RE = /^react-dom\/static\.edge$/;
|
|
15468
|
+
var SCRIPT_FILE_RE = /\.[cm]?[jt]sx?$/;
|
|
14050
15469
|
var BUILD_ID_INPUT_PATHS = [
|
|
14051
15470
|
`${_pkgSrcDir2}/build/compile-entry${_ext2}`,
|
|
14052
15471
|
`${_pkgSrcDir2}/build/entry-template${_ext2}`,
|
|
@@ -14102,16 +15521,49 @@ async function createBuildFingerprint(entryChunk, cssChunks, routes, root, serve
|
|
|
14102
15521
|
}
|
|
14103
15522
|
}
|
|
14104
15523
|
}
|
|
15524
|
+
const sources = new Map;
|
|
15525
|
+
const visit = async (inputPath) => {
|
|
15526
|
+
const path = existsSync10(inputPath) ? realpathSync4(inputPath) : inputPath;
|
|
15527
|
+
fingerprintPaths.delete(inputPath);
|
|
15528
|
+
fingerprintPaths.add(path);
|
|
15529
|
+
if (sources.has(path)) {
|
|
15530
|
+
return;
|
|
15531
|
+
}
|
|
15532
|
+
sources.set(path, "");
|
|
15533
|
+
const content = existsSync10(path) ? await Bun.file(path).text() : "";
|
|
15534
|
+
sources.set(path, content);
|
|
15535
|
+
if (!SCRIPT_FILE_RE.test(path)) {
|
|
15536
|
+
return;
|
|
15537
|
+
}
|
|
15538
|
+
const transpiler = new Bun.Transpiler({ loader: path.endsWith("x") ? "tsx" : "ts" });
|
|
15539
|
+
await Promise.all(transpiler.scanImports(content).flatMap(({ path: specifier }) => {
|
|
15540
|
+
if (specifier === "furin" || specifier.startsWith("furin/") || specifier === "@teyik0/furin" || specifier.startsWith("@teyik0/furin/")) {
|
|
15541
|
+
return [];
|
|
15542
|
+
}
|
|
15543
|
+
let dependency;
|
|
15544
|
+
try {
|
|
15545
|
+
dependency = Bun.resolveSync(specifier, dirname11(path));
|
|
15546
|
+
} catch {
|
|
15547
|
+
return [];
|
|
15548
|
+
}
|
|
15549
|
+
if (!isAbsolute5(dependency) || toPosixPath(dependency).includes("/node_modules/")) {
|
|
15550
|
+
return [];
|
|
15551
|
+
}
|
|
15552
|
+
fingerprintPaths.add(dependency);
|
|
15553
|
+
return [visit(dependency)];
|
|
15554
|
+
}));
|
|
15555
|
+
};
|
|
15556
|
+
await Promise.all([...fingerprintPaths].map(visit));
|
|
14105
15557
|
for (const path of BUILD_ID_INPUT_PATHS) {
|
|
14106
|
-
if (!
|
|
15558
|
+
if (!existsSync10(path)) {
|
|
14107
15559
|
console.warn(`[furin] Warning: build fingerprint input "${toPosixPath(path)}" is missing \u2014 ` + "the generated build ID may not reflect all framework changes.");
|
|
14108
15560
|
}
|
|
14109
15561
|
fingerprintPaths.add(path);
|
|
14110
15562
|
}
|
|
14111
|
-
const fileParts = await Promise.all([...fingerprintPaths].
|
|
14112
|
-
const content =
|
|
15563
|
+
const fileParts = (await Promise.all([...fingerprintPaths].map(async (path) => {
|
|
15564
|
+
const content = sources.get(path) ?? (existsSync10(path) ? await Bun.file(path).text() : "");
|
|
14113
15565
|
return `${stableFingerprintPath(path, projectRoot)}:${content}`;
|
|
14114
|
-
}));
|
|
15566
|
+
}))).sort(compareCodeUnits);
|
|
14115
15567
|
const routeParts = routes.map((route) => JSON.stringify({
|
|
14116
15568
|
mode: route.mode,
|
|
14117
15569
|
path: stableFingerprintPath(route.path, projectRoot),
|
|
@@ -14123,15 +15575,16 @@ async function createBuildFingerprint(entryChunk, cssChunks, routes, root, serve
|
|
|
14123
15575
|
`);
|
|
14124
15576
|
}
|
|
14125
15577
|
function stableFingerprintPath(path, projectRoot) {
|
|
14126
|
-
const
|
|
14127
|
-
|
|
15578
|
+
const absolutePath = existsSync10(path) ? realpathSync4(path) : path;
|
|
15579
|
+
const projectPath = relative7(realpathSync4(projectRoot), absolutePath);
|
|
15580
|
+
if (!isAbsolute5(projectPath) && projectPath !== ".." && !projectPath.startsWith("../") && !projectPath.startsWith("..\\")) {
|
|
14128
15581
|
return `app/${toPosixPath(projectPath)}`;
|
|
14129
15582
|
}
|
|
14130
|
-
const frameworkPath = relative7(_pkgRoot2,
|
|
14131
|
-
if (!
|
|
15583
|
+
const frameworkPath = relative7(_pkgRoot2, absolutePath);
|
|
15584
|
+
if (!isAbsolute5(frameworkPath) && frameworkPath !== ".." && !frameworkPath.startsWith("../") && !frameworkPath.startsWith("..\\")) {
|
|
14132
15585
|
return `furin/${toPosixPath(frameworkPath)}`;
|
|
14133
15586
|
}
|
|
14134
|
-
return `external/${
|
|
15587
|
+
return `external/${basename5(path)}`;
|
|
14135
15588
|
}
|
|
14136
15589
|
function buildCompileMetadata(root, routes) {
|
|
14137
15590
|
const rootConventions = root.errorPath || root.notFoundPath ? {
|
|
@@ -14155,9 +15608,9 @@ function buildCompileMetadata(root, routes) {
|
|
|
14155
15608
|
}
|
|
14156
15609
|
function pprRuntimePlugin(apps) {
|
|
14157
15610
|
const enabled = apps.some((app) => app.routes.some((route) => resolveDocumentMode(route) !== "ssr" && (app.root.route.requestLoader !== undefined || hasRequestLoader(route))));
|
|
14158
|
-
const pprPath =
|
|
14159
|
-
const reactServerPath =
|
|
14160
|
-
const reactStaticPath =
|
|
15611
|
+
const pprPath = resolve8(_pkgSrcDir2, "server/render/ppr-route.ts");
|
|
15612
|
+
const reactServerPath = fileURLToPath6(import.meta.resolve(enabled ? "react-dom/server.edge" : "react-dom/server"));
|
|
15613
|
+
const reactStaticPath = fileURLToPath6(import.meta.resolve("react-dom/static.edge"));
|
|
14161
15614
|
return {
|
|
14162
15615
|
name: "furin-ppr-runtime",
|
|
14163
15616
|
setup(build) {
|
|
@@ -14167,7 +15620,7 @@ function pprRuntimePlugin(apps) {
|
|
|
14167
15620
|
return;
|
|
14168
15621
|
}
|
|
14169
15622
|
build.onResolve({ filter: PPR_ROUTE_IMPORT_RE }, ({ path, importer }) => {
|
|
14170
|
-
const absolute =
|
|
15623
|
+
const absolute = resolve8(dirname11(importer.split("?")[0]), path);
|
|
14171
15624
|
if (absolute !== pprPath && `${absolute}.ts` !== pprPath) {
|
|
14172
15625
|
return;
|
|
14173
15626
|
}
|
|
@@ -14185,7 +15638,7 @@ export const runPprPublicLoaders = renderPprRoute;`,
|
|
|
14185
15638
|
}
|
|
14186
15639
|
function mixedRuntimePlugin(apps) {
|
|
14187
15640
|
const enabled = apps.some((app) => app.routes.some(hasMixedLoaderModes));
|
|
14188
|
-
const mixedPath =
|
|
15641
|
+
const mixedPath = resolve8(_pkgSrcDir2, "server/render/mixed-cache.ts");
|
|
14189
15642
|
return {
|
|
14190
15643
|
name: "furin-mixed-runtime",
|
|
14191
15644
|
setup(build) {
|
|
@@ -14193,7 +15646,7 @@ function mixedRuntimePlugin(apps) {
|
|
|
14193
15646
|
return;
|
|
14194
15647
|
}
|
|
14195
15648
|
build.onResolve({ filter: MIXED_CACHE_IMPORT_RE }, ({ path, importer }) => {
|
|
14196
|
-
const absolute =
|
|
15649
|
+
const absolute = resolve8(dirname11(importer.split("?")[0]), path);
|
|
14197
15650
|
if (absolute !== mixedPath && `${absolute}.ts` !== mixedPath) {
|
|
14198
15651
|
return;
|
|
14199
15652
|
}
|
|
@@ -14219,15 +15672,16 @@ async function buildRuntimeApp(app, projectRoot, targetDir, serverEntry, options
|
|
|
14219
15672
|
const modulePaths = routeSourcePaths(app);
|
|
14220
15673
|
const clientDirName = clientDirNameForPrefix(prefix);
|
|
14221
15674
|
const label = prefix === "" ? "root app" : `app "${prefix}"`;
|
|
14222
|
-
const { entryChunk, cssChunks } = await buildClient(routes, {
|
|
15675
|
+
const { entryChunk, cssChunks, preloadManifest } = await buildClient(routes, {
|
|
14223
15676
|
basePath: prefix,
|
|
14224
15677
|
clientDirName,
|
|
14225
15678
|
clientLogging: options.clientLogging ?? false,
|
|
14226
|
-
metafilePath: options.analyze ?
|
|
15679
|
+
metafilePath: options.analyze ? join12(dirname11(targetDir), "analysis", `${targetName}-${clientDirName}.json`) : undefined,
|
|
14227
15680
|
optimizeImports: options.optimizeImports,
|
|
14228
15681
|
outDir: targetDir,
|
|
14229
15682
|
pagesDir: app.pagesDir,
|
|
14230
15683
|
plugins: options.plugins,
|
|
15684
|
+
preloadRouteChunks: options.preload?.routeChunks,
|
|
14231
15685
|
publicPath: `${prefix}/_client/`,
|
|
14232
15686
|
reactCompiler: options.reactCompiler,
|
|
14233
15687
|
rootLayout: root.path
|
|
@@ -14235,10 +15689,11 @@ async function buildRuntimeApp(app, projectRoot, targetDir, serverEntry, options
|
|
|
14235
15689
|
const buildFingerprint = await createBuildFingerprint(`${prefix}
|
|
14236
15690
|
${entryChunk}`, cssChunks, routes, root, serverEntry, modulePaths, projectRoot);
|
|
14237
15691
|
const buildId = Bun.hash(buildFingerprint).toString(16).slice(0, 12);
|
|
14238
|
-
const clientDir =
|
|
15692
|
+
const clientDir = join12(targetDir, clientDirName);
|
|
14239
15693
|
const indexHtml = generateProdIndexHtml(entryChunk, cssChunks, buildId, undefined, false);
|
|
14240
|
-
|
|
15694
|
+
writeFileSync7(join12(clientDir, "index.html"), indexHtml);
|
|
14241
15695
|
setProductionTemplateContent(indexHtml);
|
|
15696
|
+
setProductionPreloadManifest(preloadManifest);
|
|
14242
15697
|
ssgRouteCache().clear();
|
|
14243
15698
|
let ssgCache;
|
|
14244
15699
|
let prerenders = [];
|
|
@@ -14262,6 +15717,7 @@ ${entryChunk}`, cssChunks, routes, root, serverEntry, modulePaths, projectRoot);
|
|
|
14262
15717
|
modulePaths,
|
|
14263
15718
|
nativeRoutes: composableRouteModuleSpecifier(app),
|
|
14264
15719
|
prefix,
|
|
15720
|
+
preloadManifest,
|
|
14265
15721
|
rootConventions,
|
|
14266
15722
|
rootPath: root.path,
|
|
14267
15723
|
routeMetadata,
|
|
@@ -14297,7 +15753,7 @@ async function buildRuntimeAppsSequentially(apps, projectRoot, targetDir, server
|
|
|
14297
15753
|
// src/adapter/bun.ts
|
|
14298
15754
|
function generateBootEntry(appEntry, outDir, filename) {
|
|
14299
15755
|
ensureDir(outDir);
|
|
14300
|
-
const entryPath =
|
|
15756
|
+
const entryPath = join13(outDir, filename);
|
|
14301
15757
|
return createVirtualBuildEntry(entryPath, serverBootSource(appEntry), "ts");
|
|
14302
15758
|
}
|
|
14303
15759
|
function collectEmbeddedAssets(entryApps, publicDir, compile) {
|
|
@@ -14320,7 +15776,7 @@ function relocateServerMaps(build, enabled, targetDir, buildRoot) {
|
|
|
14320
15776
|
if (!enabled) {
|
|
14321
15777
|
return;
|
|
14322
15778
|
}
|
|
14323
|
-
movePrivateServerSourceMaps(targetDir,
|
|
15779
|
+
movePrivateServerSourceMaps(targetDir, join13(buildRoot, "private", "server-sourcemaps", "bun"), build.outputs.filter((output) => output.kind === "sourcemap").map((output) => output.path));
|
|
14324
15780
|
}
|
|
14325
15781
|
function writeServerMetafile(build, analyze, buildRoot) {
|
|
14326
15782
|
if (!analyze) {
|
|
@@ -14329,10 +15785,10 @@ function writeServerMetafile(build, analyze, buildRoot) {
|
|
|
14329
15785
|
if (build.metafile === undefined) {
|
|
14330
15786
|
throw new Error("[furin] Bun server build did not produce the requested metafile.");
|
|
14331
15787
|
}
|
|
14332
|
-
const analysisDir =
|
|
15788
|
+
const analysisDir = join13(buildRoot, "analysis");
|
|
14333
15789
|
ensureDir(analysisDir);
|
|
14334
|
-
const metafilePath =
|
|
14335
|
-
|
|
15790
|
+
const metafilePath = join13(analysisDir, "bun-server.json");
|
|
15791
|
+
writeFileSync8(metafilePath, `${JSON.stringify(build.metafile, null, 2)}
|
|
14336
15792
|
`);
|
|
14337
15793
|
console.log(`[furin] Server metafile: ${toPosixPath(metafilePath)}`);
|
|
14338
15794
|
}
|
|
@@ -14341,7 +15797,7 @@ function finalizeEmbeddedAssets(compile, apps, targetDir, manifest) {
|
|
|
14341
15797
|
return;
|
|
14342
15798
|
}
|
|
14343
15799
|
for (const app of apps) {
|
|
14344
|
-
rmSync2(
|
|
15800
|
+
rmSync2(join13(targetDir, clientDirNameForPrefix(app.prefix)), {
|
|
14345
15801
|
force: true,
|
|
14346
15802
|
recursive: true
|
|
14347
15803
|
});
|
|
@@ -14364,7 +15820,7 @@ async function createBunAppEntry(apps, entryApps, options, publicDir, serverEntr
|
|
|
14364
15820
|
...context.extraContext ?? [],
|
|
14365
15821
|
` clientDir: import.meta.dir + ${JSON.stringify(`/${clientDirNameForPrefix(context.prefix ?? "")}`)},`
|
|
14366
15822
|
],
|
|
14367
|
-
templateHtml:
|
|
15823
|
+
templateHtml: readFileSync8(join13(targetDir, clientDirNameForPrefix(context.prefix ?? ""), "index.html"), "utf8")
|
|
14368
15824
|
}));
|
|
14369
15825
|
return await materializeServerAppEntry({
|
|
14370
15826
|
apps: contexts,
|
|
@@ -14383,27 +15839,27 @@ async function buildBunTarget(apps, rootDir, buildRoot, serverEntry, options) {
|
|
|
14383
15839
|
}
|
|
14384
15840
|
const target = "bun";
|
|
14385
15841
|
const targetManifest = buildTargetManifest(rootDir, buildRoot, target, serverEntry);
|
|
14386
|
-
const targetDir =
|
|
15842
|
+
const targetDir = resolve9(rootDir, targetManifest.targetDir);
|
|
14387
15843
|
rmSync2(targetDir, { force: true, recursive: true });
|
|
14388
|
-
rmSync2(
|
|
15844
|
+
rmSync2(join13(buildRoot, "private", "server-sourcemaps", "bun"), {
|
|
14389
15845
|
force: true,
|
|
14390
15846
|
recursive: true
|
|
14391
15847
|
});
|
|
14392
15848
|
ensureDir(targetDir);
|
|
14393
|
-
const publicDir =
|
|
15849
|
+
const publicDir = existsSync11(join13(rootDir, "public")) ? join13(rootDir, "public") : undefined;
|
|
14394
15850
|
const { entryApps, headlineBuildId } = await buildRuntimeAppsSequentially(apps, rootDir, targetDir, serverEntry, options, "bun");
|
|
14395
15851
|
targetManifest.buildId = headlineBuildId;
|
|
14396
15852
|
if (serverEntry) {
|
|
14397
|
-
targetManifest.rscManifestPath = toPosixPath(
|
|
15853
|
+
targetManifest.rscManifestPath = toPosixPath(join13(targetManifest.targetDir, "rsc", "manifest.json"));
|
|
14398
15854
|
}
|
|
14399
|
-
const targetPublicDir = publicDir ?
|
|
15855
|
+
const targetPublicDir = publicDir ? join13(targetDir, "public") : undefined;
|
|
14400
15856
|
if (publicDir && targetPublicDir && options.compile !== "embed") {
|
|
14401
15857
|
copyDirRecursive(publicDir, targetPublicDir);
|
|
14402
15858
|
}
|
|
14403
15859
|
const appEntry = await createBunAppEntry(apps, entryApps, options, publicDir, serverEntry, targetDir);
|
|
14404
15860
|
if (options.compile && serverEntry && appEntry) {
|
|
14405
15861
|
const serverFilename = compiledServerFilename(process.platform);
|
|
14406
|
-
const outfile =
|
|
15862
|
+
const outfile = join13(targetDir, serverFilename);
|
|
14407
15863
|
const entry = generateBootEntry(appEntry, targetDir, "_compile-entry.ts");
|
|
14408
15864
|
const embeddedAssets = collectEmbeddedAssets(entryApps, publicDir, options.compile);
|
|
14409
15865
|
const serverBuild = await runBunBuild({
|
|
@@ -14433,7 +15889,7 @@ async function buildBunTarget(apps, rootDir, buildRoot, serverEntry, options) {
|
|
|
14433
15889
|
relocateServerMaps(serverBuild, options.serverSourceMaps, targetDir, buildRoot);
|
|
14434
15890
|
writeServerMetafile(serverBuild, options.analyze, buildRoot);
|
|
14435
15891
|
console.log(`[furin] Server binary: ${outfile}`);
|
|
14436
|
-
targetManifest.serverPath = toPosixPath(
|
|
15892
|
+
targetManifest.serverPath = toPosixPath(join13(targetManifest.targetDir, serverFilename));
|
|
14437
15893
|
finalizeEmbeddedAssets(options.compile, apps, targetDir, targetManifest);
|
|
14438
15894
|
} else if (serverEntry && appEntry) {
|
|
14439
15895
|
const entry = generateBootEntry(appEntry, targetDir, "server.ts");
|
|
@@ -14460,29 +15916,31 @@ async function buildBunTarget(apps, rootDir, buildRoot, serverEntry, options) {
|
|
|
14460
15916
|
});
|
|
14461
15917
|
relocateServerMaps(serverBuild, options.serverSourceMaps, targetDir, buildRoot);
|
|
14462
15918
|
writeServerMetafile(serverBuild, options.analyze, buildRoot);
|
|
14463
|
-
console.log(`[furin] Server bundle: ${toPosixPath(
|
|
14464
|
-
targetManifest.serverPath = toPosixPath(
|
|
15919
|
+
console.log(`[furin] Server bundle: ${toPosixPath(join13(targetManifest.targetDir, "server.js"))}`);
|
|
15920
|
+
targetManifest.serverPath = toPosixPath(join13(targetManifest.targetDir, "server.js"));
|
|
14465
15921
|
}
|
|
14466
15922
|
return targetManifest;
|
|
14467
15923
|
}
|
|
14468
15924
|
|
|
14469
15925
|
// src/adapter/package.ts
|
|
14470
|
-
import { existsSync as
|
|
14471
|
-
import { join as
|
|
15926
|
+
import { existsSync as existsSync12, rmSync as rmSync3, writeFileSync as writeFileSync9 } from "fs";
|
|
15927
|
+
import { join as join14, relative as relative8, resolve as resolve10 } from "path";
|
|
15928
|
+
init_transform_isomorphic();
|
|
14472
15929
|
async function buildPackageTarget(app, rootDir, buildRoot, options) {
|
|
14473
15930
|
const { prefix, root, routes, pagesDir } = app;
|
|
14474
15931
|
const modulePaths = routeSourcePaths(app);
|
|
14475
|
-
const targetDir =
|
|
15932
|
+
const targetDir = join14(buildRoot, "package");
|
|
14476
15933
|
rmSync3(targetDir, { force: true, recursive: true });
|
|
14477
15934
|
ensureDir(targetDir);
|
|
14478
|
-
const { entryChunk, cssChunks } = await buildClient(routes, {
|
|
15935
|
+
const { entryChunk, cssChunks, preloadManifest } = await buildClient(routes, {
|
|
14479
15936
|
basePath: prefix,
|
|
14480
15937
|
clientLogging: options.clientLogging ?? false,
|
|
14481
|
-
metafilePath: options.analyze ?
|
|
15938
|
+
metafilePath: options.analyze ? join14(buildRoot, "analysis", "package-client.json") : undefined,
|
|
14482
15939
|
optimizeImports: options.optimizeImports,
|
|
14483
15940
|
outDir: targetDir,
|
|
14484
15941
|
pagesDir,
|
|
14485
15942
|
plugins: options.plugins,
|
|
15943
|
+
preloadRouteChunks: options.preload?.routeChunks,
|
|
14486
15944
|
publicPath: `${prefix}/_client/`,
|
|
14487
15945
|
reactCompiler: options.reactCompiler,
|
|
14488
15946
|
rootLayout: root.path
|
|
@@ -14490,14 +15948,15 @@ async function buildPackageTarget(app, rootDir, buildRoot, options) {
|
|
|
14490
15948
|
const buildFingerprint = await createBuildFingerprint(`${prefix}
|
|
14491
15949
|
${entryChunk}`, cssChunks, routes, root, null, modulePaths, rootDir);
|
|
14492
15950
|
const buildId = Bun.hash(buildFingerprint).toString(16).slice(0, 12);
|
|
14493
|
-
const clientDir =
|
|
14494
|
-
const publicDir =
|
|
14495
|
-
if (
|
|
14496
|
-
copyDirRecursive(publicDir,
|
|
15951
|
+
const clientDir = join14(targetDir, "client");
|
|
15952
|
+
const publicDir = join14(rootDir, "public");
|
|
15953
|
+
if (existsSync12(publicDir)) {
|
|
15954
|
+
copyDirRecursive(publicDir, join14(targetDir, "public"));
|
|
14497
15955
|
}
|
|
14498
15956
|
const indexHtml = generateProdIndexHtml(entryChunk, cssChunks, buildId, undefined, false);
|
|
14499
|
-
|
|
15957
|
+
writeFileSync9(join14(clientDir, "index.html"), indexHtml);
|
|
14500
15958
|
setProductionTemplateContent(indexHtml);
|
|
15959
|
+
setProductionPreloadManifest(preloadManifest);
|
|
14501
15960
|
ssgRouteCache().clear();
|
|
14502
15961
|
const ssgCache = await buildSSGCacheSnapshot(routes, root, "http://localhost", prefix);
|
|
14503
15962
|
const rootConventions = root.errorPath || root.notFoundPath ? {
|
|
@@ -14525,6 +15984,7 @@ ${entryChunk}`, cssChunks, routes, root, null, modulePaths, rootDir);
|
|
|
14525
15984
|
modulePaths,
|
|
14526
15985
|
nativeRoutes: composableRouteModuleSpecifier(app),
|
|
14527
15986
|
prefix,
|
|
15987
|
+
preloadManifest,
|
|
14528
15988
|
rootConventions,
|
|
14529
15989
|
rootPath: root.path,
|
|
14530
15990
|
routeMetadata,
|
|
@@ -14535,7 +15995,7 @@ ${entryChunk}`, cssChunks, routes, root, null, modulePaths, rootDir);
|
|
|
14535
15995
|
headerComment: "// Auto-generated by `furin build --target package` \u2014 do not edit",
|
|
14536
15996
|
mode: "register"
|
|
14537
15997
|
});
|
|
14538
|
-
const registerEntry =
|
|
15998
|
+
const registerEntry = join14(targetDir, "register.ts");
|
|
14539
15999
|
const register = createVirtualBuildEntry(registerEntry, registerSource, "ts");
|
|
14540
16000
|
const result = await runBunBuild({
|
|
14541
16001
|
entrypoints: [register.entrypoint],
|
|
@@ -14547,7 +16007,9 @@ ${entryChunk}`, cssChunks, routes, root, null, modulePaths, rootDir);
|
|
|
14547
16007
|
plugins: [
|
|
14548
16008
|
register.plugin,
|
|
14549
16009
|
...options.plugins ?? [],
|
|
14550
|
-
createRoutesPlugin({ instances: [app], target: "server" })
|
|
16010
|
+
createRoutesPlugin({ instances: [app], target: "server" }),
|
|
16011
|
+
isomorphicTransformPlugin("server"),
|
|
16012
|
+
environmentGuardPlugin("ssr")
|
|
14551
16013
|
],
|
|
14552
16014
|
sourcemap: "none",
|
|
14553
16015
|
target: "bun"
|
|
@@ -14555,7 +16017,7 @@ ${entryChunk}`, cssChunks, routes, root, null, modulePaths, rootDir);
|
|
|
14555
16017
|
if (!result.success) {
|
|
14556
16018
|
throw new AggregateError(result.logs, "[furin] package register build failed");
|
|
14557
16019
|
}
|
|
14558
|
-
const relativePagesDir = toPosixPath(relative8(targetDir,
|
|
16020
|
+
const relativePagesDir = toPosixPath(relative8(targetDir, resolve10(rootDir, pagesDir)));
|
|
14559
16021
|
const factorySource = `// Auto-generated by \`furin build --target package\` \u2014 do not edit
|
|
14560
16022
|
import { fileURLToPath } from "node:url";
|
|
14561
16023
|
import { furin } from "@teyik0/furin";
|
|
@@ -14582,7 +16044,7 @@ export function createFurinApp(options = {}) {
|
|
|
14582
16044
|
|
|
14583
16045
|
export const prefix = ${JSON.stringify(prefix)};
|
|
14584
16046
|
`;
|
|
14585
|
-
|
|
16047
|
+
writeFileSync9(join14(targetDir, "index.js"), factorySource);
|
|
14586
16048
|
const dtsSource = `import type { FurinOptions, furin } from "@teyik0/furin";
|
|
14587
16049
|
|
|
14588
16050
|
/** Extra furin() options \u2014 pagesDir/prefix/clientDir are baked into the package and cannot be overridden. */
|
|
@@ -14590,7 +16052,7 @@ export type CreateFurinAppOptions = Omit<FurinOptions, "pagesDir" | "prefix" | "
|
|
|
14590
16052
|
export declare function createFurinApp(options?: CreateFurinAppOptions): ReturnType<typeof furin>;
|
|
14591
16053
|
export declare const prefix: string;
|
|
14592
16054
|
`;
|
|
14593
|
-
|
|
16055
|
+
writeFileSync9(join14(targetDir, "index.d.ts"), dtsSource);
|
|
14594
16056
|
console.log(`[furin] Package artifact: ${toPosixPath(relative8(rootDir, targetDir))}`);
|
|
14595
16057
|
return {
|
|
14596
16058
|
buildId,
|
|
@@ -14601,19 +16063,19 @@ export declare const prefix: string;
|
|
|
14601
16063
|
}
|
|
14602
16064
|
|
|
14603
16065
|
// src/adapter/static.ts
|
|
14604
|
-
import { cpSync as cpSync2, existsSync as
|
|
14605
|
-
import { dirname as
|
|
16066
|
+
import { cpSync as cpSync2, existsSync as existsSync13, rmSync as rmSync4, writeFileSync as writeFileSync10 } from "fs";
|
|
16067
|
+
import { dirname as dirname12, isAbsolute as isAbsolute6, join as join15, parse as parse3, relative as relative9, resolve as resolve11, sep as sep2, win32 } from "path";
|
|
14606
16068
|
init_patterns();
|
|
14607
16069
|
var STATIC_CONCURRENCY = 4;
|
|
14608
16070
|
var DYNAMIC_SEGMENT_RE2 = /\/:[^/]+|\/\*/;
|
|
14609
16071
|
var TRAILING_SLASHES_RE = /\/+$/;
|
|
14610
16072
|
var STATIC_RENDER_ORIGIN = "http://localhost";
|
|
14611
16073
|
function pathToOutputFile(urlPath, outDir, fileName) {
|
|
14612
|
-
const normalizedOutDir =
|
|
16074
|
+
const normalizedOutDir = resolve11(outDir);
|
|
14613
16075
|
if (urlPath === "/" || urlPath === "") {
|
|
14614
|
-
return
|
|
16076
|
+
return join15(normalizedOutDir, fileName);
|
|
14615
16077
|
}
|
|
14616
|
-
const resolved =
|
|
16078
|
+
const resolved = resolve11(normalizedOutDir, urlPath.slice(1), fileName);
|
|
14617
16079
|
if (!resolved.startsWith(`${normalizedOutDir}${sep2}`)) {
|
|
14618
16080
|
throw new Error(`[furin] static: unsafe output path detected for URL "${urlPath}" \u2014 path traversal via ".." is not allowed.`);
|
|
14619
16081
|
}
|
|
@@ -14686,22 +16148,22 @@ async function prerenderAndWrite(route, params, root, outDir, renderedRoutes, sk
|
|
|
14686
16148
|
throw new Error(`[furin] static: route "${route.pattern}" returned a response that cannot be exported.`);
|
|
14687
16149
|
}
|
|
14688
16150
|
const staticLocation = resolveStaticRedirectLocation(location, basePath, urlPath);
|
|
14689
|
-
ensureDir(
|
|
14690
|
-
|
|
16151
|
+
ensureDir(dirname12(htmlOutputFile));
|
|
16152
|
+
writeFileSync10(htmlOutputFile, createStaticRedirectHtml(staticLocation.html));
|
|
14691
16153
|
if (staticLocation.spa !== null) {
|
|
14692
16154
|
const serializedRedirect = await toCrossJSONAsync({
|
|
14693
16155
|
__furinRedirect: staticLocation.spa
|
|
14694
16156
|
});
|
|
14695
|
-
|
|
16157
|
+
writeFileSync10(dataOutputFile, `${JSON.stringify(serializedRedirect)}
|
|
14696
16158
|
`);
|
|
14697
16159
|
}
|
|
14698
16160
|
renderedRoutes.push(urlPath);
|
|
14699
16161
|
console.log(`[furin] static: ${urlPath} \u2192 ${toPosixPath(htmlOutputFile)} (redirects to ${staticLocation.html})`);
|
|
14700
16162
|
return;
|
|
14701
16163
|
}
|
|
14702
|
-
ensureDir(
|
|
14703
|
-
|
|
14704
|
-
|
|
16164
|
+
ensureDir(dirname12(htmlOutputFile));
|
|
16165
|
+
writeFileSync10(htmlOutputFile, entry.html);
|
|
16166
|
+
writeFileSync10(dataOutputFile, entry.ndjson);
|
|
14705
16167
|
renderedRoutes.push(urlPath);
|
|
14706
16168
|
console.log(`[furin] static: ${urlPath} \u2192 ${toPosixPath(htmlOutputFile)}`);
|
|
14707
16169
|
} catch (err) {
|
|
@@ -14808,15 +16270,15 @@ async function buildStaticTarget(routes, rootDir, buildRoot, root, options) {
|
|
|
14808
16270
|
throw new Error(`[furin] static: basePath must start with "/" (received "${rawBasePath}"). ` + `Use "" for root deployments or "/sub-path" for sub-path deployments.`);
|
|
14809
16271
|
}
|
|
14810
16272
|
const rawOutDir = staticConfig.outDir ?? "dist";
|
|
14811
|
-
const outDir =
|
|
14812
|
-
const normalizedRoot =
|
|
14813
|
-
const normalizedBuildRoot =
|
|
16273
|
+
const outDir = resolve11(rootDir, rawOutDir);
|
|
16274
|
+
const normalizedRoot = resolve11(rootDir);
|
|
16275
|
+
const normalizedBuildRoot = resolve11(buildRoot);
|
|
14814
16276
|
if (outDir === normalizedRoot || outDir === normalizedBuildRoot || outDir === parse3(outDir).root || rawOutDir === win32.parse(rawOutDir).root) {
|
|
14815
16277
|
throw new Error(`[furin] static: outDir resolves to "${outDir}" which is unsafe to delete. ` + `Use a dedicated output directory such as "dist".`);
|
|
14816
16278
|
}
|
|
14817
16279
|
function isOutsideOutDir(target) {
|
|
14818
16280
|
const rel = relative9(outDir, target);
|
|
14819
|
-
return rel.startsWith("..") ||
|
|
16281
|
+
return rel.startsWith("..") || isAbsolute6(rel);
|
|
14820
16282
|
}
|
|
14821
16283
|
if (!(isOutsideOutDir(normalizedRoot) && isOutsideOutDir(normalizedBuildRoot))) {
|
|
14822
16284
|
throw new Error(`[furin] static: outDir resolves to "${outDir}" which is unsafe to delete. ` + `Use a dedicated output directory such as "dist".`);
|
|
@@ -14832,36 +16294,38 @@ async function buildStaticTarget(routes, rootDir, buildRoot, root, options) {
|
|
|
14832
16294
|
const afterQueueCount = skippedRoutes.length;
|
|
14833
16295
|
rmSync4(outDir, { force: true, recursive: true });
|
|
14834
16296
|
ensureDir(outDir);
|
|
14835
|
-
const targetDir =
|
|
16297
|
+
const targetDir = join15(buildRoot, "static");
|
|
14836
16298
|
rmSync4(targetDir, { force: true, recursive: true });
|
|
14837
16299
|
ensureDir(targetDir);
|
|
14838
|
-
const { entryChunk, cssChunks } = await buildClient(ssgRoutes, {
|
|
16300
|
+
const { entryChunk, cssChunks, preloadManifest } = await buildClient(ssgRoutes, {
|
|
14839
16301
|
basePath,
|
|
14840
16302
|
clientLogging: Boolean(options.clientLogging),
|
|
14841
|
-
metafilePath: options.analyze ?
|
|
16303
|
+
metafilePath: options.analyze ? join15(buildRoot, "analysis", "static-client.json") : undefined,
|
|
14842
16304
|
optimizeImports: options.optimizeImports,
|
|
14843
16305
|
outDir: targetDir,
|
|
14844
|
-
pagesDir:
|
|
16306
|
+
pagesDir: dirname12(root.path),
|
|
14845
16307
|
plugins: options.plugins,
|
|
16308
|
+
preloadRouteChunks: options.preload?.routeChunks,
|
|
14846
16309
|
publicPath,
|
|
14847
16310
|
reactCompiler: options.reactCompiler,
|
|
14848
16311
|
rootLayout: root.path
|
|
14849
16312
|
});
|
|
14850
|
-
const publicFavicon =
|
|
14851
|
-
const faviconHref =
|
|
16313
|
+
const publicFavicon = join15(rootDir, "public", "favicon.ico");
|
|
16314
|
+
const faviconHref = existsSync13(publicFavicon) ? `${basePath}/favicon.ico` : undefined;
|
|
14852
16315
|
const shellHtml = generateProdIndexHtml(entryChunk, cssChunks, undefined, faviconHref, true);
|
|
14853
16316
|
setProductionTemplateContent(shellHtml);
|
|
14854
|
-
|
|
14855
|
-
|
|
16317
|
+
setProductionPreloadManifest(preloadManifest);
|
|
16318
|
+
const publicSrcDir = join15(rootDir, "public");
|
|
16319
|
+
if (existsSync13(publicSrcDir)) {
|
|
14856
16320
|
cpSync2(publicSrcDir, outDir, { recursive: true });
|
|
14857
16321
|
}
|
|
14858
|
-
const clientSrcDir =
|
|
14859
|
-
if (
|
|
14860
|
-
cpSync2(clientSrcDir,
|
|
16322
|
+
const clientSrcDir = join15(targetDir, "client");
|
|
16323
|
+
if (existsSync13(clientSrcDir)) {
|
|
16324
|
+
cpSync2(clientSrcDir, join15(outDir, "_client"), { recursive: true });
|
|
14861
16325
|
}
|
|
14862
16326
|
await runWithConcurrency(tasks, STATIC_CONCURRENCY);
|
|
14863
16327
|
assertNoPrerenderSkips(onSSR, skippedRoutes, afterQueueCount);
|
|
14864
|
-
|
|
16328
|
+
writeFileSync10(join15(outDir, "404.html"), shellHtml);
|
|
14865
16329
|
console.log("[furin] static: wrote 404.html (SPA shell fallback)");
|
|
14866
16330
|
rmSync4(targetDir, { force: true, recursive: true });
|
|
14867
16331
|
console.log(`[furin] static: export complete \u2192 ${toPosixPath(outDir)}` + ` (${renderedRoutes.length} rendered, ${skippedRoutes.length} skipped)`);
|
|
@@ -14875,9 +16339,9 @@ async function buildStaticTarget(routes, rootDir, buildRoot, root, options) {
|
|
|
14875
16339
|
}
|
|
14876
16340
|
|
|
14877
16341
|
// src/adapter/vercel.ts
|
|
14878
|
-
import { cpSync as cpSync3, existsSync as
|
|
14879
|
-
import { basename as
|
|
14880
|
-
import { fileURLToPath as
|
|
16342
|
+
import { cpSync as cpSync3, existsSync as existsSync14, readFileSync as readFileSync9, rmSync as rmSync5, symlinkSync, writeFileSync as writeFileSync11 } from "fs";
|
|
16343
|
+
import { basename as basename6, dirname as dirname13, extname as extname4, join as join16, relative as relative10 } from "path";
|
|
16344
|
+
import { fileURLToPath as fileURLToPath7, pathToFileURL as pathToFileURL2 } from "url";
|
|
14881
16345
|
init_transform_isomorphic();
|
|
14882
16346
|
init_patterns();
|
|
14883
16347
|
var ISR_PATH_PARAM = "__furin_path";
|
|
@@ -14886,9 +16350,9 @@ var ELYSIA_STATIC_IMPORT_RE = /^@elysia\/static$/;
|
|
|
14886
16350
|
var MATCH_ALL_RE = /.*/;
|
|
14887
16351
|
var REGEX_META_RE = /[.*+?^${}()|[\]\\]/;
|
|
14888
16352
|
var UNSAFE_FUNCTION_PATH_RE = /[^a-zA-Z0-9_.[\]/-]/g;
|
|
14889
|
-
var VERCEL_FUNCTIONS_PATH =
|
|
16353
|
+
var VERCEL_FUNCTIONS_PATH = fileURLToPath7(import.meta.resolve("@vercel/functions"));
|
|
14890
16354
|
var VERCEL_RUNTIME_STUB_NAMESPACE = "furin-vercel-runtime-stub";
|
|
14891
|
-
var FURIN_RUNTIME_ROOT2 =
|
|
16355
|
+
var FURIN_RUNTIME_ROOT2 = dirname13(import.meta.dir);
|
|
14892
16356
|
function isFurinRuntimeImporter(importer) {
|
|
14893
16357
|
if (importer === "") {
|
|
14894
16358
|
return false;
|
|
@@ -14919,8 +16383,8 @@ function vercelRuntimePlugin() {
|
|
|
14919
16383
|
};
|
|
14920
16384
|
}
|
|
14921
16385
|
function frameworkVersion() {
|
|
14922
|
-
const packageRoot =
|
|
14923
|
-
const packageJson = JSON.parse(
|
|
16386
|
+
const packageRoot = dirname13(dirname13(fileURLToPath7(import.meta.resolve("@teyik0/furin"))));
|
|
16387
|
+
const packageJson = JSON.parse(readFileSync9(join16(packageRoot, "package.json"), "utf8"));
|
|
14924
16388
|
return packageJson.version;
|
|
14925
16389
|
}
|
|
14926
16390
|
function serverEntryLoader(serverEntry) {
|
|
@@ -14938,7 +16402,7 @@ function serverEntryLoader(serverEntry) {
|
|
|
14938
16402
|
}
|
|
14939
16403
|
function assertDefaultServerExport(serverEntry) {
|
|
14940
16404
|
const transpiler = new Bun.Transpiler({ loader: serverEntryLoader(serverEntry) });
|
|
14941
|
-
const { exports, imports } = transpiler.scan(
|
|
16405
|
+
const { exports, imports } = transpiler.scan(readFileSync9(serverEntry, "utf8"));
|
|
14942
16406
|
if (!exports.includes("default")) {
|
|
14943
16407
|
throw new Error(`[furin] Vercel server entry "${toPosixPath(serverEntry)}" must export the Elysia app as default. ` + "Guard app.listen() with `if (import.meta.main)` so the same entry also runs locally.");
|
|
14944
16408
|
}
|
|
@@ -15018,7 +16482,7 @@ function isPprRoute(app, route) {
|
|
|
15018
16482
|
return resolveDocumentMode(route) !== "ssr" && (app.root.route.requestLoader !== undefined || hasRequestLoader(route));
|
|
15019
16483
|
}
|
|
15020
16484
|
async function addPrerenderFallback(spec, physicalRoutePath, prerender, functionsDir) {
|
|
15021
|
-
const fallback = `${
|
|
16485
|
+
const fallback = `${basename6(spec.functionName)}.prerender-fallback.html`;
|
|
15022
16486
|
const { result } = prerender;
|
|
15023
16487
|
if (result === undefined) {
|
|
15024
16488
|
return;
|
|
@@ -15036,9 +16500,9 @@ async function addPrerenderFallback(spec, physicalRoutePath, prerender, function
|
|
|
15036
16500
|
body = result.html;
|
|
15037
16501
|
({ status } = result);
|
|
15038
16502
|
}
|
|
15039
|
-
const fallbackPath =
|
|
15040
|
-
ensureDir(
|
|
15041
|
-
|
|
16503
|
+
const fallbackPath = join16(dirname13(join16(functionsDir, spec.functionName)), fallback);
|
|
16504
|
+
ensureDir(dirname13(fallbackPath));
|
|
16505
|
+
writeFileSync11(fallbackPath, body);
|
|
15042
16506
|
spec.config.fallback = fallback;
|
|
15043
16507
|
spec.config.initialHeaders = {
|
|
15044
16508
|
"content-type": contentType,
|
|
@@ -15049,9 +16513,9 @@ async function addPrerenderFallback(spec, physicalRoutePath, prerender, function
|
|
|
15049
16513
|
spec.config.initialStatus = status;
|
|
15050
16514
|
}
|
|
15051
16515
|
function createFunctionAlias(functionsDir, serverFunctionDir, functionName) {
|
|
15052
|
-
const aliasPath =
|
|
15053
|
-
ensureDir(
|
|
15054
|
-
const target = relative10(
|
|
16516
|
+
const aliasPath = join16(functionsDir, `${functionName}.func`);
|
|
16517
|
+
ensureDir(dirname13(aliasPath));
|
|
16518
|
+
const target = relative10(dirname13(aliasPath), serverFunctionDir);
|
|
15055
16519
|
symlinkSync(target, aliasPath, process.platform === "win32" ? "junction" : "dir");
|
|
15056
16520
|
}
|
|
15057
16521
|
function createExactPrerenderSpec(prerender, routePath) {
|
|
@@ -15274,10 +16738,10 @@ async function buildPprFallbacks(apps, builds, specs, functionsDir, rootDir, tar
|
|
|
15274
16738
|
if (jobs.length === 0) {
|
|
15275
16739
|
return;
|
|
15276
16740
|
}
|
|
15277
|
-
const resultPath =
|
|
16741
|
+
const resultPath = join16(targetDir, "ppr-results.json");
|
|
15278
16742
|
const requests = jobs.map(({ path, spec }) => `http://localhost/${spec.functionName}?${ISR_PATH_PARAM}=${encodeURIComponent(path)}`);
|
|
15279
16743
|
const script = `
|
|
15280
|
-
const handler = (await import(${JSON.stringify(pathToFileURL2(
|
|
16744
|
+
const handler = (await import(${JSON.stringify(pathToFileURL2(join16(functionsDir, "__server.func/index.js")).href)})).default;
|
|
15281
16745
|
const results = [];
|
|
15282
16746
|
for (const url of ${JSON.stringify(requests)}) {
|
|
15283
16747
|
const response = await handler.fetch(new Request(url));
|
|
@@ -15304,7 +16768,7 @@ process.exit(0);
|
|
|
15304
16768
|
${stderr}
|
|
15305
16769
|
${stdout}`);
|
|
15306
16770
|
}
|
|
15307
|
-
const results = JSON.parse(
|
|
16771
|
+
const results = JSON.parse(readFileSync9(resultPath, "utf8"));
|
|
15308
16772
|
for (const [index, job] of jobs.entries()) {
|
|
15309
16773
|
const result = results[index];
|
|
15310
16774
|
await addPrerenderFallback(job.spec, job.path, {
|
|
@@ -15386,13 +16850,13 @@ export default { fetch: handle };
|
|
|
15386
16850
|
}
|
|
15387
16851
|
async function buildVercelTarget(apps, rootDir, buildRoot, serverEntry, options) {
|
|
15388
16852
|
assertDefaultServerExport(serverEntry);
|
|
15389
|
-
const targetDir =
|
|
15390
|
-
const outputDir =
|
|
15391
|
-
const staticDir =
|
|
15392
|
-
const functionsDir =
|
|
15393
|
-
const serverFunctionDir =
|
|
16853
|
+
const targetDir = join16(buildRoot, "vercel");
|
|
16854
|
+
const outputDir = join16(rootDir, ".vercel", "output");
|
|
16855
|
+
const staticDir = join16(outputDir, "static");
|
|
16856
|
+
const functionsDir = join16(outputDir, "functions");
|
|
16857
|
+
const serverFunctionDir = join16(functionsDir, "__server.func");
|
|
15394
16858
|
rmSync5(targetDir, { force: true, recursive: true });
|
|
15395
|
-
rmSync5(
|
|
16859
|
+
rmSync5(join16(buildRoot, "private", "server-sourcemaps", "vercel"), {
|
|
15396
16860
|
force: true,
|
|
15397
16861
|
recursive: true
|
|
15398
16862
|
});
|
|
@@ -15401,41 +16865,43 @@ async function buildVercelTarget(apps, rootDir, buildRoot, serverEntry, options)
|
|
|
15401
16865
|
ensureDir(staticDir);
|
|
15402
16866
|
ensureDir(serverFunctionDir);
|
|
15403
16867
|
const { builds, headlineBuildId } = await buildRuntimeAppsSequentially(apps, rootDir, targetDir, serverEntry, options, "vercel");
|
|
15404
|
-
cpSync3(
|
|
15405
|
-
const publicDir =
|
|
15406
|
-
if (
|
|
16868
|
+
cpSync3(join16(targetDir, "server-codec.js"), join16(serverFunctionDir, "server-codec.js"));
|
|
16869
|
+
const publicDir = join16(rootDir, "public");
|
|
16870
|
+
if (existsSync14(publicDir)) {
|
|
15407
16871
|
cpSync3(publicDir, staticDir, { recursive: true });
|
|
15408
16872
|
for (const app of apps) {
|
|
15409
|
-
const appStaticDir =
|
|
15410
|
-
const appPublicDir =
|
|
16873
|
+
const appStaticDir = join16(staticDir, app.prefix.slice(1));
|
|
16874
|
+
const appPublicDir = join16(appStaticDir, "public");
|
|
15411
16875
|
cpSync3(publicDir, appPublicDir, { recursive: true });
|
|
15412
|
-
const favicon =
|
|
15413
|
-
if (app.prefix !== "" &&
|
|
15414
|
-
cpSync3(favicon,
|
|
16876
|
+
const favicon = join16(publicDir, "favicon.ico");
|
|
16877
|
+
if (app.prefix !== "" && existsSync14(favicon)) {
|
|
16878
|
+
cpSync3(favicon, join16(appStaticDir, "favicon.ico"));
|
|
15415
16879
|
}
|
|
15416
16880
|
}
|
|
15417
16881
|
}
|
|
15418
16882
|
for (let appIndex = 0;appIndex < apps.length; appIndex += 1) {
|
|
15419
16883
|
const app = apps[appIndex];
|
|
15420
16884
|
const build = builds[appIndex];
|
|
15421
|
-
const clientOutputDir =
|
|
16885
|
+
const clientOutputDir = join16(staticDir, app.prefix.slice(1), "_client");
|
|
15422
16886
|
cpSync3(build.clientDir, clientOutputDir, { recursive: true });
|
|
15423
16887
|
}
|
|
15424
16888
|
const pprResumeKey = crypto.randomUUID();
|
|
15425
|
-
const prerenderSpecs = await
|
|
15426
|
-
|
|
15427
|
-
|
|
15428
|
-
|
|
15429
|
-
|
|
15430
|
-
|
|
15431
|
-
|
|
15432
|
-
|
|
15433
|
-
|
|
15434
|
-
|
|
15435
|
-
|
|
15436
|
-
|
|
15437
|
-
|
|
15438
|
-
|
|
16889
|
+
const [prerenderSpecs, appEntry] = await Promise.all([
|
|
16890
|
+
createPrerenderSpecs(apps, builds, functionsDir, pprResumeKey),
|
|
16891
|
+
materializeServerAppEntry({
|
|
16892
|
+
apps: builds.map(({ entryApp, indexHtml }) => ({
|
|
16893
|
+
...entryApp,
|
|
16894
|
+
embed: undefined,
|
|
16895
|
+
serveAssets: false,
|
|
16896
|
+
templateHtml: indexHtml
|
|
16897
|
+
})),
|
|
16898
|
+
headerComment: "// Auto-generated by `furin build --target vercel` \u2014 do not edit",
|
|
16899
|
+
instances: apps,
|
|
16900
|
+
outDir: serverFunctionDir,
|
|
16901
|
+
serverEntry
|
|
16902
|
+
})
|
|
16903
|
+
]);
|
|
16904
|
+
const entryPath = join16(serverFunctionDir, "_vercel-handler.ts");
|
|
15439
16905
|
const entry = createVirtualBuildEntry(entryPath, vercelEntrySource(apps, builds, prerenderSpecs, appEntry, pprResumeKey), "ts");
|
|
15440
16906
|
const serverBuild = await runBunBuild({
|
|
15441
16907
|
define: { "process.env.NODE_ENV": JSON.stringify("production") },
|
|
@@ -15463,22 +16929,22 @@ async function buildVercelTarget(apps, rootDir, buildRoot, serverEntry, options)
|
|
|
15463
16929
|
target: "bun"
|
|
15464
16930
|
});
|
|
15465
16931
|
if (options.serverSourceMaps) {
|
|
15466
|
-
movePrivateServerSourceMaps(serverFunctionDir,
|
|
16932
|
+
movePrivateServerSourceMaps(serverFunctionDir, join16(buildRoot, "private", "server-sourcemaps", "vercel"), serverBuild.outputs.filter((output) => output.kind === "sourcemap").map((output) => output.path));
|
|
15467
16933
|
}
|
|
15468
16934
|
if (options.analyze) {
|
|
15469
16935
|
if (serverBuild.metafile === undefined) {
|
|
15470
16936
|
throw new Error("[furin] Vercel server build did not produce the requested metafile.");
|
|
15471
16937
|
}
|
|
15472
|
-
const metafilePath =
|
|
15473
|
-
ensureDir(
|
|
15474
|
-
|
|
16938
|
+
const metafilePath = join16(buildRoot, "analysis", "vercel-server.json");
|
|
16939
|
+
ensureDir(dirname13(metafilePath));
|
|
16940
|
+
writeFileSync11(metafilePath, `${JSON.stringify(serverBuild.metafile, null, 2)}
|
|
15475
16941
|
`);
|
|
15476
16942
|
console.log(`[furin] Server metafile: ${toPosixPath(metafilePath)}`);
|
|
15477
16943
|
}
|
|
15478
16944
|
const serverBundleBytes = serverBuild.outputs.filter((output) => output.path.endsWith(".js")).reduce((total, output) => total + output.size, 0);
|
|
15479
|
-
|
|
16945
|
+
writeFileSync11(join16(serverFunctionDir, "index.js"), vercelBootstrapSource(serverBundleBytes));
|
|
15480
16946
|
await buildPprFallbacks(apps, builds, prerenderSpecs, functionsDir, rootDir, targetDir);
|
|
15481
|
-
|
|
16947
|
+
writeFileSync11(join16(serverFunctionDir, ".vc-config.json"), `${JSON.stringify({
|
|
15482
16948
|
handler: "index.js",
|
|
15483
16949
|
launcherType: "Nodejs",
|
|
15484
16950
|
...options.vercelConfig?.regions === undefined ? {} : { regions: options.vercelConfig.regions },
|
|
@@ -15489,7 +16955,7 @@ async function buildVercelTarget(apps, rootDir, buildRoot, serverEntry, options)
|
|
|
15489
16955
|
`);
|
|
15490
16956
|
for (const spec of prerenderSpecs) {
|
|
15491
16957
|
createFunctionAlias(functionsDir, serverFunctionDir, spec.functionName);
|
|
15492
|
-
|
|
16958
|
+
writeFileSync11(join16(functionsDir, `${spec.functionName}.prerender-config.json`), `${JSON.stringify(spec.config, null, 2)}
|
|
15493
16959
|
`);
|
|
15494
16960
|
}
|
|
15495
16961
|
const assetRoutes = apps.map((app) => ({
|
|
@@ -15519,7 +16985,7 @@ async function buildVercelTarget(apps, rootDir, buildRoot, serverEntry, options)
|
|
|
15519
16985
|
],
|
|
15520
16986
|
version: 3
|
|
15521
16987
|
};
|
|
15522
|
-
|
|
16988
|
+
writeFileSync11(join16(outputDir, "config.json"), `${JSON.stringify(config, null, 2)}
|
|
15523
16989
|
`);
|
|
15524
16990
|
const ssgRoutes = builds.flatMap((build, index) => build.prerenders.filter((prerender) => resolveDocumentMode(prerender.route) === "ssg").map((prerender) => physicalPath(apps[index].prefix, prerender.path))).toSorted();
|
|
15525
16991
|
const isrRoutes = apps.flatMap((app) => app.routes.filter((route) => resolveDocumentMode(route) === "isr").map((route) => physicalPath(app.prefix, route.pattern))).toSorted();
|
|
@@ -15572,6 +17038,7 @@ var configSchema = t.Object({
|
|
|
15572
17038
|
clientLogging: t.Optional(t.Boolean()),
|
|
15573
17039
|
optimizeImports: t.Optional(t.Array(t.String())),
|
|
15574
17040
|
pagesDir: t.Optional(t.String()),
|
|
17041
|
+
preload: t.Optional(t.Object({ routeChunks: t.Optional(t.Boolean()) })),
|
|
15575
17042
|
reactCompiler: t.Optional(t.Boolean()),
|
|
15576
17043
|
rootDir: t.Optional(t.String()),
|
|
15577
17044
|
serverEntry: t.Optional(t.String()),
|
|
@@ -15595,9 +17062,9 @@ init_transform_isomorphic();
|
|
|
15595
17062
|
init_instance();
|
|
15596
17063
|
|
|
15597
17064
|
// src/server/router/discovery.ts
|
|
15598
|
-
import { existsSync as
|
|
17065
|
+
import { existsSync as existsSync15 } from "fs";
|
|
15599
17066
|
import { readdir } from "fs/promises";
|
|
15600
|
-
import { join as
|
|
17067
|
+
import { join as join17, parse as parse4 } from "path";
|
|
15601
17068
|
|
|
15602
17069
|
// src/server/internal.ts
|
|
15603
17070
|
var _compileContexts = new Map;
|
|
@@ -15696,6 +17163,7 @@ function adaptDefinedPage(route, parent) {
|
|
|
15696
17163
|
params: route.schemas?.params,
|
|
15697
17164
|
parent,
|
|
15698
17165
|
query: route.schemas?.query,
|
|
17166
|
+
remountDeps: route.remountDeps,
|
|
15699
17167
|
requestLoader: route.requestLoader
|
|
15700
17168
|
},
|
|
15701
17169
|
component,
|
|
@@ -15749,7 +17217,7 @@ async function scanPages(pagesDir) {
|
|
|
15749
17217
|
async function scanRootLayout(pagesDir) {
|
|
15750
17218
|
const rootPath = `${pagesDir}/root.tsx`;
|
|
15751
17219
|
const ctx = getCompileContext();
|
|
15752
|
-
if (!(
|
|
17220
|
+
if (!(existsSync15(rootPath) || ctx?.modules[rootPath])) {
|
|
15753
17221
|
throw new Error("[furin] root.tsx: not found.");
|
|
15754
17222
|
}
|
|
15755
17223
|
const mod = ctx?.modules[rootPath] ?? await import(rootPath);
|
|
@@ -15776,10 +17244,6 @@ async function scanRootLayout(pagesDir) {
|
|
|
15776
17244
|
}
|
|
15777
17245
|
var CONVENTION_FILE_NAMES = ["not-found", "error"];
|
|
15778
17246
|
var SOURCE_MODULE_EXTENSIONS = [".tsx", ".ts", ".jsx", ".js"];
|
|
15779
|
-
var DYNAMIC_ROUTE_SEGMENT_RE = /(^|\/):[^/]+/g;
|
|
15780
|
-
function routePatternKey(pattern) {
|
|
15781
|
-
return pattern.replace(DYNAMIC_ROUTE_SEGMENT_RE, "$1:param");
|
|
15782
|
-
}
|
|
15783
17247
|
function isConventionFileName(name) {
|
|
15784
17248
|
return CONVENTION_FILE_NAMES.includes(name);
|
|
15785
17249
|
}
|
|
@@ -15789,8 +17253,8 @@ function getSourceModuleCandidates(dir, name) {
|
|
|
15789
17253
|
async function loadConventionComponent(dir, name) {
|
|
15790
17254
|
const ctx = getCompileContext();
|
|
15791
17255
|
for (const filePath of getSourceModuleCandidates(dir, name)) {
|
|
15792
|
-
if (
|
|
15793
|
-
const moduleSpecifier = IS_DEV &&
|
|
17256
|
+
if (existsSync15(filePath) || ctx?.modules[filePath]) {
|
|
17257
|
+
const moduleSpecifier = IS_DEV && existsSync15(filePath) ? `${filePath}?furin-server&t=${routeModuleSourceVersion(filePath)}` : filePath;
|
|
15794
17258
|
const mod = ctx?.modules[filePath] ?? await import(moduleSpecifier);
|
|
15795
17259
|
if (mod.default) {
|
|
15796
17260
|
return { component: mod.default, path: filePath };
|
|
@@ -15828,7 +17292,7 @@ async function scanPageFiles(pagesDir, root) {
|
|
|
15828
17292
|
const devRoute = await buildDevRoute(absolutePath, relativePath, pattern, root, pagesDir);
|
|
15829
17293
|
devRoute.notFound = notFound;
|
|
15830
17294
|
devRoute.error = errorComponent;
|
|
15831
|
-
devRoute.segmentBoundaries = segmentBoundaries;
|
|
17295
|
+
devRoute.segmentBoundaries = alignSegmentBoundaryDepths(segmentBoundaries, devRoute.routeChain);
|
|
15832
17296
|
routes.push(devRoute);
|
|
15833
17297
|
continue;
|
|
15834
17298
|
}
|
|
@@ -15848,7 +17312,7 @@ async function scanPageFiles(pagesDir, root) {
|
|
|
15848
17312
|
path: absolutePath,
|
|
15849
17313
|
pattern,
|
|
15850
17314
|
routeChain,
|
|
15851
|
-
segmentBoundaries,
|
|
17315
|
+
segmentBoundaries: alignSegmentBoundaryDepths(segmentBoundaries, routeChain),
|
|
15852
17316
|
tags: collectRouteTags(routeChain, page)
|
|
15853
17317
|
});
|
|
15854
17318
|
}
|
|
@@ -15873,7 +17337,7 @@ async function resolveDefinedLayoutParent(pagePath, pagesDir, rootRoute) {
|
|
|
15873
17337
|
for (const segment of segments) {
|
|
15874
17338
|
directory = `${directory}/${segment}`;
|
|
15875
17339
|
for (const candidate of getSourceModuleCandidates(directory, "_route")) {
|
|
15876
|
-
if (!
|
|
17340
|
+
if (!existsSync15(candidate)) {
|
|
15877
17341
|
continue;
|
|
15878
17342
|
}
|
|
15879
17343
|
const layoutModule = await (IS_DEV ? import(`${candidate}?furin-server&t=${routeModuleSourceVersion(candidate)}`) : import(candidate));
|
|
@@ -15886,6 +17350,21 @@ async function resolveDefinedLayoutParent(pagePath, pagesDir, rootRoute) {
|
|
|
15886
17350
|
}
|
|
15887
17351
|
return parent;
|
|
15888
17352
|
}
|
|
17353
|
+
function alignSegmentBoundaryDepths(boundaries, routeChain) {
|
|
17354
|
+
return boundaries.map((boundary) => {
|
|
17355
|
+
let depth = 0;
|
|
17356
|
+
for (const [index, entry] of routeChain.entries()) {
|
|
17357
|
+
if (!entry.sourcePath) {
|
|
17358
|
+
continue;
|
|
17359
|
+
}
|
|
17360
|
+
const directory = entry.sourcePath.slice(0, entry.sourcePath.lastIndexOf("/"));
|
|
17361
|
+
if (boundary.path === directory || boundary.path.startsWith(`${directory}/`)) {
|
|
17362
|
+
depth = index;
|
|
17363
|
+
}
|
|
17364
|
+
}
|
|
17365
|
+
return { ...boundary, depth };
|
|
17366
|
+
});
|
|
17367
|
+
}
|
|
15889
17368
|
async function collectSegmentBoundaries(pageAbsolutePath, pagesDir, notFoundCache, errorCache) {
|
|
15890
17369
|
const pageDir = pageAbsolutePath.slice(0, pageAbsolutePath.lastIndexOf("/"));
|
|
15891
17370
|
const dirs = [pagesDir];
|
|
@@ -15973,7 +17452,7 @@ async function collectPageFilePaths(dir) {
|
|
|
15973
17452
|
const files = [];
|
|
15974
17453
|
const entries = (await readdir(dir, { withFileTypes: true })).sort((a, b) => a.name.localeCompare(b.name));
|
|
15975
17454
|
const resolved = await mapWithConcurrency(entries, DIR_SCAN_CONCURRENCY, async (entry) => {
|
|
15976
|
-
const absolutePath = toPosixPath2(
|
|
17455
|
+
const absolutePath = toPosixPath2(join17(dir, entry.name));
|
|
15977
17456
|
if (entry.isDirectory()) {
|
|
15978
17457
|
return await collectPageFilePaths(absolutePath);
|
|
15979
17458
|
}
|
|
@@ -15993,9 +17472,9 @@ init_instance();
|
|
|
15993
17472
|
init_lang_detect();
|
|
15994
17473
|
init_ast_walk();
|
|
15995
17474
|
init_parser();
|
|
15996
|
-
import { readFileSync as
|
|
17475
|
+
import { readFileSync as readFileSync10 } from "fs";
|
|
15997
17476
|
function scanFurinInstances(serverEntryPath) {
|
|
15998
|
-
const code =
|
|
17477
|
+
const code = readFileSync10(serverEntryPath, "utf8");
|
|
15999
17478
|
const lang = detectLangFromPath(serverEntryPath);
|
|
16000
17479
|
if (lang === "dts") {
|
|
16001
17480
|
return [];
|
|
@@ -16076,42 +17555,42 @@ function registerIsomorphicRuntimePlugin() {
|
|
|
16076
17555
|
function resolveAppSpecs(options, serverEntry, rootDir) {
|
|
16077
17556
|
if (options.apps && options.apps.length > 0) {
|
|
16078
17557
|
return options.apps.map((app) => ({
|
|
16079
|
-
pagesDir:
|
|
17558
|
+
pagesDir: resolve12(rootDir, app.pagesDir),
|
|
16080
17559
|
prefix: normalizePrefix(app.prefix)
|
|
16081
17560
|
}));
|
|
16082
17561
|
}
|
|
16083
17562
|
if (options.pagesDir) {
|
|
16084
|
-
return [{ pagesDir:
|
|
17563
|
+
return [{ pagesDir: resolve12(rootDir, options.pagesDir), prefix: "" }];
|
|
16085
17564
|
}
|
|
16086
17565
|
if (serverEntry) {
|
|
16087
17566
|
const detected = scanFurinInstances(serverEntry);
|
|
16088
17567
|
if (detected.length > 0) {
|
|
16089
17568
|
return detected.map((app) => ({
|
|
16090
|
-
pagesDir:
|
|
17569
|
+
pagesDir: resolve12(rootDir, app.pagesDir),
|
|
16091
17570
|
prefix: app.prefix
|
|
16092
17571
|
}));
|
|
16093
17572
|
}
|
|
16094
17573
|
}
|
|
16095
|
-
return [{ pagesDir:
|
|
17574
|
+
return [{ pagesDir: resolve12(rootDir, "src/pages"), prefix: "" }];
|
|
16096
17575
|
}
|
|
16097
17576
|
async function buildApp(options) {
|
|
16098
17577
|
return withProductionBuild(() => buildAppInternal(options));
|
|
16099
17578
|
}
|
|
16100
17579
|
async function buildAppInternal(options) {
|
|
16101
|
-
const rootDir =
|
|
16102
|
-
const buildRoot =
|
|
17580
|
+
const rootDir = resolve12(options.rootDir ?? process.cwd());
|
|
17581
|
+
const buildRoot = join18(rootDir, BUILD_OUTPUT_DIR);
|
|
16103
17582
|
const serverEntry = (() => {
|
|
16104
17583
|
if (options.target === "static" || options.target === "package") {
|
|
16105
17584
|
return null;
|
|
16106
17585
|
}
|
|
16107
17586
|
if (options.serverEntry) {
|
|
16108
|
-
const resolved =
|
|
16109
|
-
if (
|
|
17587
|
+
const resolved = resolve12(rootDir, options.serverEntry);
|
|
17588
|
+
if (existsSync16(resolved)) {
|
|
16110
17589
|
return resolved;
|
|
16111
17590
|
}
|
|
16112
17591
|
}
|
|
16113
|
-
const entry =
|
|
16114
|
-
if (!
|
|
17592
|
+
const entry = resolve12(rootDir, "src/server.ts");
|
|
17593
|
+
if (!existsSync16(entry)) {
|
|
16115
17594
|
throw new Error("[furin] Entrypoint server.ts not found");
|
|
16116
17595
|
}
|
|
16117
17596
|
return entry;
|
|
@@ -16192,7 +17671,7 @@ async function buildAppInternal(options) {
|
|
|
16192
17671
|
throw new Error(`[furin] Unsupported build target "${target}"`);
|
|
16193
17672
|
}
|
|
16194
17673
|
}
|
|
16195
|
-
|
|
17674
|
+
writeFileSync12(join18(buildRoot, "manifest.json"), `${JSON.stringify(manifest, null, 2)}
|
|
16196
17675
|
`);
|
|
16197
17676
|
return {
|
|
16198
17677
|
manifest,
|