@teyik0/furin 0.4.0-alpha.1 → 0.5.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/adapter/bun.d.ts +2 -18
- package/dist/adapter/package.d.ts +2 -2
- package/dist/adapter/runtime-build.d.ts +33 -0
- package/dist/adapter/vercel.d.ts +3 -0
- package/dist/build/client.d.ts +1 -1
- package/dist/build/compile-entry.d.ts +6 -4
- package/dist/build/compile-entry.ts +36 -77
- package/dist/build/elysia-aot.d.ts +9 -0
- package/dist/build/entry-template.d.ts +9 -3
- package/dist/build/entry-template.ts +55 -13
- package/dist/build/index.d.ts +1 -1
- package/dist/build/index.js +8912 -6391
- package/dist/build/server-app-entry.d.ts +12 -0
- package/dist/build/ssg-cache.d.ts +13 -0
- package/dist/build/types.d.ts +25 -2
- package/dist/build/virtual-entry.d.ts +8 -0
- package/dist/cache.d.ts +6 -0
- package/dist/cache.js +282 -0
- package/dist/cli/index.js +8936 -6308
- package/dist/cli/preview.d.ts +7 -0
- package/dist/client/boundaries.d.ts +1 -0
- package/dist/client/browser-events-runtime.d.ts +2 -0
- package/dist/client/browser-events.d.ts +2 -0
- package/dist/client/define-route.d.ts +9 -8
- package/dist/client/dev-error-overlay.d.ts +1 -0
- package/dist/client/dev-error-overlay.ts +201 -0
- package/dist/client/document.d.ts +1 -0
- package/dist/client/hmr.d.ts +4 -2
- package/dist/client/internal/runtime-types.d.ts +8 -1
- package/dist/client/link.js +465 -86
- package/dist/client/router/provider.d.ts +1 -1
- package/dist/client/router/sync-catch-up.d.ts +1 -1
- package/dist/client/router/types.d.ts +8 -10
- package/dist/client/sync.d.ts +1 -0
- package/dist/client.js +37 -23
- package/dist/config.d.ts +35 -17
- package/dist/config.js +10 -2
- package/dist/define-route.d.ts +282 -1015
- package/dist/devtools/protocol.d.ts +2 -2
- package/dist/furin.d.ts +21 -6
- package/dist/furin.js +12823 -8484
- package/dist/plugin/index.js +476 -7
- package/dist/plugin/routes.d.ts +10 -3
- package/dist/rsc/build/index.d.ts +5 -1
- package/dist/server/assets/production.d.ts +3 -0
- package/dist/server/auto-invalidate/plugin.d.ts +8 -24
- package/dist/server/auto-invalidate/runtime.d.ts +2 -2
- package/dist/server/browser-events/plugin.d.ts +11 -0
- package/dist/server/browser-events/types.d.ts +9 -0
- package/dist/server/cache/invalidation.d.ts +2 -3
- package/dist/server/cache/isr.d.ts +1 -0
- package/dist/server/cache/page-cache-state.d.ts +5 -0
- package/dist/server/cache/page-cache.d.ts +53 -0
- package/dist/server/cache/purger.d.ts +7 -0
- package/dist/server/cache/redis/index.d.ts +39 -0
- package/dist/server/cache/redis/index.js +396 -0
- package/dist/server/cache/redis/scripts.d.ts +6 -0
- package/dist/server/cache/runtime-cache.d.ts +21 -0
- package/dist/server/context-logger.d.ts +2 -2
- package/dist/server/dev/browser-events.d.ts +4 -0
- package/dist/server/dev/diagnostics.d.ts +39 -0
- package/dist/server/dev/error.d.ts +17 -0
- package/dist/server/dev/graph.d.ts +86 -0
- package/dist/server/dev/plugin.d.ts +9 -0
- package/dist/server/dev/request-security.d.ts +1 -0
- package/dist/server/dev/rewrite-module-specifiers.d.ts +7 -0
- package/dist/server/dev/runtime.production.d.ts +6 -0
- package/dist/server/dev/symbolicate.d.ts +11 -0
- package/dist/server/dev/transform-failure.d.ts +4 -0
- package/dist/server/dev-page-plugin.d.ts +7 -0
- package/dist/server/dev-page-plugin.production.d.ts +1 -0
- package/dist/server/devtools/hub.d.ts +3 -2
- package/dist/server/devtools/instrumentation.d.ts +1 -1
- package/dist/server/devtools/instrumentation.production.d.ts +1 -1
- package/dist/server/devtools/plugin.d.ts +1 -1
- package/dist/server/evlog.d.ts +14 -0
- package/dist/server/external-prerender.d.ts +2 -0
- package/dist/server/instance.d.ts +2 -2
- package/dist/server/internal.d.ts +20 -2
- package/dist/server/internal.js +2973 -1
- package/dist/server/render/element.d.ts +1 -0
- package/dist/server/render/index.d.ts +1 -1
- package/dist/server/render/index.ts +1 -1
- package/dist/server/render/not-found.d.ts +1 -1
- package/dist/server/render/ppr-document.d.ts +21 -0
- package/dist/server/render/ppr-request.d.ts +26 -0
- package/dist/server/render/ppr-route.d.ts +3 -1
- package/dist/server/render/shell.ts +0 -12
- package/dist/server/render/ssg.d.ts +7 -0
- package/dist/server/render/ssr.d.ts +17 -6
- package/dist/server/render/static-params.d.ts +4 -0
- package/dist/server/router/defined-route.d.ts +1 -1
- package/dist/server/router/hmr.production.d.ts +2 -0
- package/dist/server/router/patterns.d.ts +1 -0
- package/dist/server/router/plugin.d.ts +3 -1
- package/dist/server/router/schemas.d.ts +1 -0
- package/dist/server/sync/adapter.d.ts +13 -0
- package/dist/server/sync/config.d.ts +5 -5
- package/dist/server/sync/index.d.ts +6 -6
- package/dist/server/sync/index.js +1252 -599
- package/dist/server/sync/notifier.d.ts +1 -0
- package/dist/server/sync/plugin.d.ts +31 -158
- package/dist/server/sync/postgres/index.d.ts +12 -1
- package/dist/server/sync/postgres/index.js +101 -6
- package/dist/server/sync/stream.d.ts +37 -61
- package/dist/shared/await.d.ts +3 -3
- package/dist/shared/browser-events.d.ts +22 -0
- package/dist/shared/compact-json.d.ts +8 -0
- package/dist/shared/deferred-ndjson.d.ts +6 -5
- package/dist/shared/dev-diagnostics.d.ts +36 -0
- package/dist/shared/elysia-contract.d.ts +8 -14
- package/dist/shared/prefix.d.ts +2 -0
- package/package.json +26 -11
- package/src/adapter/README.md +53 -1
- package/src/adapter/bun.ts +106 -283
- package/src/adapter/package.ts +21 -11
- package/src/adapter/runtime-build.ts +382 -0
- package/src/adapter/static.ts +87 -8
- package/src/adapter/vercel.ts +876 -0
- package/src/build/client.ts +55 -13
- package/src/build/compile-entry.ts +36 -77
- package/src/build/elysia-aot.ts +102 -0
- package/src/build/entry-template.ts +55 -13
- package/src/build/hydrate.ts +60 -20
- package/src/build/index.ts +17 -8
- package/src/build/production-instrumentation.ts +56 -4
- package/src/build/server-app-entry.ts +60 -0
- package/src/build/shared.ts +5 -2
- package/src/build/ssg-cache.ts +93 -12
- package/src/build/types.ts +31 -2
- package/src/build/virtual-entry.ts +28 -0
- package/src/cache.ts +26 -0
- package/src/cli/config.ts +3 -3
- package/src/cli/index.ts +58 -3
- package/src/cli/preview.ts +90 -0
- package/src/client/boundaries.tsx +10 -1
- package/src/client/browser-events-runtime.ts +204 -0
- package/src/client/browser-events.ts +22 -0
- package/src/client/define-route.ts +7 -17
- package/src/client/dev-error-overlay.ts +201 -0
- package/src/client/document.tsx +4 -7
- package/src/client/hmr.ts +26 -3
- package/src/client/internal/runtime-types.ts +10 -1
- package/src/client/router/boundary-tree.tsx +4 -4
- package/src/client/router/provider.tsx +165 -63
- package/src/client/router/sync-catch-up.ts +3 -4
- package/src/client/router/types.ts +6 -6
- package/src/client/sync.ts +1 -0
- package/src/config.ts +28 -2
- package/src/define-route.ts +285 -134
- package/src/devtools/devtools-element.js +56 -77
- package/src/devtools/protocol.ts +2 -2
- package/src/furin.ts +272 -203
- package/src/plugin/route-config-autofix.ts +11 -2
- package/src/plugin/routes.ts +291 -65
- package/src/plugin/transform-client.ts +685 -3
- package/src/react-dom-edge.d.ts +6 -0
- package/src/rsc/build/index.ts +15 -3
- package/src/server/assets/production.ts +99 -0
- package/src/server/auto-invalidate/plugin.ts +4 -4
- package/src/server/auto-invalidate/runtime.ts +76 -41
- package/src/server/browser-events/plugin.ts +173 -0
- package/src/server/browser-events/types.ts +11 -0
- package/src/server/cache/dev-loader.ts +30 -29
- package/src/server/cache/invalidation.ts +67 -35
- package/src/server/cache/isr.ts +9 -0
- package/src/server/cache/page-cache-state.ts +22 -0
- package/src/server/cache/page-cache.ts +300 -0
- package/src/server/cache/purger.ts +41 -0
- package/src/server/cache/redis/index.ts +350 -0
- package/src/server/cache/redis/scripts.ts +160 -0
- package/src/server/cache/runtime-cache.ts +137 -0
- package/src/server/context-logger.ts +5 -5
- package/src/server/dev/browser-events.ts +54 -0
- package/src/server/dev/diagnostics.ts +297 -0
- package/src/server/dev/error.ts +148 -0
- package/src/server/dev/graph.ts +438 -0
- package/src/server/dev/plugin.ts +130 -0
- package/src/server/dev/request-security.ts +38 -0
- package/src/server/dev/rewrite-module-specifiers.ts +81 -0
- package/src/server/dev/runtime.production.ts +28 -0
- package/src/server/dev/symbolicate.ts +135 -0
- package/src/server/dev/transform-failure.ts +8 -0
- package/src/server/dev-page-plugin.production.ts +3 -0
- package/src/server/dev-page-plugin.ts +136 -53
- package/src/server/devtools/hub.ts +6 -5
- package/src/server/devtools/instrumentation.production.ts +1 -1
- package/src/server/devtools/instrumentation.ts +12 -6
- package/src/server/devtools/plugin.ts +7 -150
- package/src/server/evlog.ts +99 -0
- package/src/server/external-prerender.ts +10 -0
- package/src/server/instance.ts +3 -3
- package/src/server/internal.ts +46 -2
- package/src/server/render/assemble.ts +4 -4
- package/src/server/render/document.tsx +13 -4
- package/src/server/render/element.tsx +18 -14
- package/src/server/render/index.ts +1 -1
- package/src/server/render/isr.ts +509 -136
- package/src/server/render/loaders.ts +31 -15
- package/src/server/render/not-found.ts +32 -8
- package/src/server/render/ppr-document.ts +239 -0
- package/src/server/render/ppr-request.ts +104 -0
- package/src/server/render/ppr-route.ts +335 -28
- package/src/server/render/shell.ts +0 -12
- package/src/server/render/ssg.ts +186 -24
- package/src/server/render/ssr.ts +215 -89
- package/src/server/render/static-params.ts +174 -0
- package/src/server/render/template.ts +47 -11
- package/src/server/router/defined-route.ts +9 -40
- package/src/server/router/hmr.production.ts +7 -0
- package/src/server/router/hmr.ts +108 -67
- package/src/server/router/patterns.ts +5 -1
- package/src/server/router/plugin.ts +164 -66
- package/src/server/router/schema-merge.ts +1 -1
- package/src/server/router/schemas.ts +174 -61
- package/src/server/router/source-version.ts +3 -10
- package/src/server/sync/adapter.ts +13 -0
- package/src/server/sync/config.ts +12 -12
- package/src/server/sync/index.ts +8 -8
- package/src/server/sync/notifier.ts +1 -0
- package/src/server/sync/plugin.ts +18 -11
- package/src/server/sync/postgres/index.ts +111 -5
- package/src/server/sync/response.ts +3 -3
- package/src/server/sync/runtime.ts +12 -0
- package/src/server/sync/stream.ts +78 -113
- package/src/shared/await.tsx +3 -3
- package/src/shared/browser-events.ts +28 -0
- package/src/shared/compact-json.ts +77 -0
- package/src/shared/deferred-ndjson.ts +20 -6
- package/src/shared/dev-diagnostics.ts +44 -0
- package/src/shared/elysia-contract.ts +23 -25
- package/src/shared/prefix.ts +8 -0
- package/src/shared/route-map.ts +10 -1
|
@@ -448,6 +448,7 @@ interface FixContext {
|
|
|
448
448
|
expectedResolvedPath: string;
|
|
449
449
|
filePath: string;
|
|
450
450
|
hasLoader: boolean;
|
|
451
|
+
hasStaticParams: boolean;
|
|
451
452
|
imports: LayoutImport[];
|
|
452
453
|
isRootLayout: boolean;
|
|
453
454
|
lastImportEnd: number;
|
|
@@ -659,6 +660,9 @@ function validateConfigProperties(
|
|
|
659
660
|
ctx: FixContext
|
|
660
661
|
): { inferredMode: InferredRenderingMode | null; layoutValue: AstNode | null } {
|
|
661
662
|
const layoutValue = properties.layout ? asAstNode(properties.layout.value) : null;
|
|
663
|
+
if (properties.staticParams) {
|
|
664
|
+
throw routeConfigError(ctx.filePath, "staticParams must be chained after config");
|
|
665
|
+
}
|
|
662
666
|
if (!ctx.isRootLayout && properties.layout && layoutValue?.type !== "Identifier") {
|
|
663
667
|
throw routeConfigError(ctx.filePath, "use a static layout route reference");
|
|
664
668
|
}
|
|
@@ -670,7 +674,7 @@ function validateConfigProperties(
|
|
|
670
674
|
) {
|
|
671
675
|
throw routeConfigError(ctx.filePath, "revalidate requires mode isr");
|
|
672
676
|
}
|
|
673
|
-
if (
|
|
677
|
+
if (ctx.hasStaticParams && modeValue?.type === "Literal" && modeValue.value === "ssr") {
|
|
674
678
|
throw routeConfigError(ctx.filePath, "staticParams requires mode ssg or isr");
|
|
675
679
|
}
|
|
676
680
|
if (!properties.revalidate && modeValue?.type === "Literal" && modeValue.value === "isr") {
|
|
@@ -685,7 +689,7 @@ function validateConfigProperties(
|
|
|
685
689
|
hasRevalidate: Boolean(properties.revalidate),
|
|
686
690
|
isRootLayout: ctx.isRootLayout,
|
|
687
691
|
});
|
|
688
|
-
if (
|
|
692
|
+
if (ctx.hasStaticParams && inferredMode === "ssr") {
|
|
689
693
|
throw routeConfigError(ctx.filePath, "staticParams requires mode ssg or isr");
|
|
690
694
|
}
|
|
691
695
|
return { inferredMode, layoutValue };
|
|
@@ -970,6 +974,9 @@ function insertCompleteConfig(routeHead: ChainHead, ctx: FixContext): void {
|
|
|
970
974
|
hasRevalidate: false,
|
|
971
975
|
isRootLayout: ctx.isRootLayout,
|
|
972
976
|
});
|
|
977
|
+
if (ctx.hasStaticParams && mode === "ssr") {
|
|
978
|
+
throw routeConfigError(ctx.filePath, "staticParams requires mode ssg or isr");
|
|
979
|
+
}
|
|
973
980
|
entries.push(`mode: "${mode}"`);
|
|
974
981
|
if (ctx.dynamicParams.length > 0) {
|
|
975
982
|
const typeBoxBinding = ensureTImport(ctx);
|
|
@@ -1097,6 +1104,7 @@ export function fixRouteConfigLayout(
|
|
|
1097
1104
|
);
|
|
1098
1105
|
const bindings = collectBuilderBindings(parsed.program);
|
|
1099
1106
|
const hasLoader = builderChainHasMethod(parsed.program, bindings, "loader");
|
|
1107
|
+
const hasStaticParams = builderChainHasMethod(parsed.program, bindings, "staticParams");
|
|
1100
1108
|
const heads = collectChainHeads(parsed.program, bindings).filter(
|
|
1101
1109
|
(candidate) => candidate.end !== 0
|
|
1102
1110
|
);
|
|
@@ -1116,6 +1124,7 @@ export function fixRouteConfigLayout(
|
|
|
1116
1124
|
expectedResolvedPath,
|
|
1117
1125
|
filePath,
|
|
1118
1126
|
hasLoader,
|
|
1127
|
+
hasStaticParams,
|
|
1119
1128
|
imports,
|
|
1120
1129
|
isRootLayout: convention.isRootLayout,
|
|
1121
1130
|
lastImportEnd,
|
package/src/plugin/routes.ts
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
existsSync,
|
|
3
|
+
type FSWatcher,
|
|
4
|
+
readdirSync,
|
|
5
|
+
readFileSync,
|
|
6
|
+
realpathSync,
|
|
7
|
+
statSync,
|
|
8
|
+
watch,
|
|
9
|
+
} from "node:fs";
|
|
10
|
+
import { dirname, extname, isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
3
11
|
import { pathToFileURL } from "node:url";
|
|
4
12
|
import { type AnyElysia, Elysia } from "elysia";
|
|
5
13
|
import { type FurinNativeRouteContext, getFurinRenderer } from "../define-route.ts";
|
|
@@ -8,10 +16,12 @@ import { parseDynamicRouteSegment, routeSegmentToPattern } from "../server/route
|
|
|
8
16
|
|
|
9
17
|
const ROUTES_NAMESPACE_PREFIX = "furin-routes";
|
|
10
18
|
const ROUTES_REGISTRY_SPECIFIER = "furin/routes?registry";
|
|
11
|
-
const
|
|
19
|
+
const COMPOSABLE_ROUTES_REGISTRY_SPECIFIER = "furin/routes?registry=composable";
|
|
20
|
+
const ROUTES_REGISTRY_FILTER = /^furin\/routes\?registry(?:=composable)?$/;
|
|
12
21
|
const ROUTE_FILE_FILTER = /^furin-route-file:.+$/;
|
|
13
22
|
const ROUTE_FILES_NAMESPACE = "furin-route-files";
|
|
14
|
-
const ROUTES_REGISTRY_FILE_FILTER =
|
|
23
|
+
const ROUTES_REGISTRY_FILE_FILTER =
|
|
24
|
+
/[\\/]\.furin-routes-registry(?:-composable)?\.ts\?furin-virtual$/;
|
|
15
25
|
const CLIENT_ROUTES_NAMESPACE = "furin-routes-client";
|
|
16
26
|
const CLIENT_ROUTES_FILTER = /^(?:@teyik0\/furin|furin)\/routes$/;
|
|
17
27
|
const SERVER_ROUTES_FILTER = /^(?:@teyik0\/furin|furin)\/routes\?instance=.+$/;
|
|
@@ -21,6 +31,8 @@ const ROUTE_CONVENTIONS = new Set(["error", "not-found", "root"]);
|
|
|
21
31
|
const DEV_ROUTES_APPS_SYMBOL = Symbol.for("@teyik0/furin/dev-routes-apps");
|
|
22
32
|
const DEV_ROUTE_WATCHERS_SYMBOL = Symbol.for("@teyik0/furin/dev-route-watchers");
|
|
23
33
|
const DEV_ROUTES_FILE_FILTER = /[\\/]routes\.ts\?instance=[^&]+$/;
|
|
34
|
+
const DEV_ROUTE_RECONCILE_DELAY_MS = 25;
|
|
35
|
+
const DEV_ROUTE_RETRY_DELAY_MS = 100;
|
|
24
36
|
|
|
25
37
|
const devInstancesBySpecifier = new Map<string, RouteInstanceSpec>();
|
|
26
38
|
let devRoutesPluginRegistered = false;
|
|
@@ -42,21 +54,26 @@ export interface CreateRoutesPluginOptions {
|
|
|
42
54
|
|
|
43
55
|
export interface DevRouteTopologyWatcher {
|
|
44
56
|
close: () => void;
|
|
57
|
+
refresh: () => Promise<void>;
|
|
45
58
|
}
|
|
46
59
|
|
|
47
60
|
export interface DevRouteTopologyWatcherOptions {
|
|
48
61
|
instance: RouteInstanceSpec;
|
|
49
|
-
onRouteFilesTouched?: () => Promise<void> | void;
|
|
50
|
-
|
|
51
|
-
|
|
62
|
+
onRouteFilesTouched?: (sourcePaths: readonly string[]) => Promise<void> | void;
|
|
63
|
+
onSourceError?: (error: unknown, sourcePath: string) => void;
|
|
64
|
+
onTopologyChange: (sourcePaths: readonly string[]) => Promise<void> | void;
|
|
52
65
|
}
|
|
53
66
|
|
|
54
67
|
interface DevRouteTopologyWatcherState extends DevRouteTopologyWatcherOptions {
|
|
68
|
+
changedSources: Set<string>;
|
|
69
|
+
closed: boolean;
|
|
70
|
+
dirty: boolean;
|
|
55
71
|
pending: boolean;
|
|
56
|
-
|
|
72
|
+
reconcileTimer: ReturnType<typeof setTimeout> | undefined;
|
|
73
|
+
refreshPromise: Promise<void> | undefined;
|
|
57
74
|
routeFilesSignature: string;
|
|
58
75
|
source: string;
|
|
59
|
-
|
|
76
|
+
watchers: FSWatcher[];
|
|
60
77
|
}
|
|
61
78
|
|
|
62
79
|
function instanceKey(instance: RouteInstanceSpec): string {
|
|
@@ -67,6 +84,10 @@ export function routeModuleSpecifier(instance: RouteInstanceSpec): string {
|
|
|
67
84
|
return `@teyik0/furin/routes?instance=${Bun.hash(instanceKey(instance)).toString(16)}`;
|
|
68
85
|
}
|
|
69
86
|
|
|
87
|
+
export function composableRouteModuleSpecifier(instance: RouteInstanceSpec): string {
|
|
88
|
+
return `${routeModuleSpecifier(instance)}&composable`;
|
|
89
|
+
}
|
|
90
|
+
|
|
70
91
|
function instanceNamespace(instance: RouteInstanceSpec): string {
|
|
71
92
|
return `${ROUTES_NAMESPACE_PREFIX}-${Bun.hash(instanceKey(instance)).toString(16)}`;
|
|
72
93
|
}
|
|
@@ -258,7 +279,7 @@ function routeTopologySource(instance: RouteInstanceSpec): string {
|
|
|
258
279
|
return `${JSON.stringify(paths)}\n`;
|
|
259
280
|
}
|
|
260
281
|
|
|
261
|
-
function
|
|
282
|
+
function routeDependencyPaths(instance: RouteInstanceSpec): string[] {
|
|
262
283
|
const dependencyPaths = new Set<string>();
|
|
263
284
|
for (const sourcePath of routeSnapshotSourcePaths(instance)) {
|
|
264
285
|
const cached = routeModuleCache().get(sourcePath);
|
|
@@ -267,18 +288,40 @@ function routeFilesSignature(instance: RouteInstanceSpec): string {
|
|
|
267
288
|
dependencyPaths.add(dependency.path);
|
|
268
289
|
}
|
|
269
290
|
}
|
|
270
|
-
return [...dependencyPaths]
|
|
271
|
-
|
|
291
|
+
return [...dependencyPaths].toSorted((left, right) => left.localeCompare(right));
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
function routeFilesSignature(instance: RouteInstanceSpec): string {
|
|
295
|
+
return routeDependencyPaths(instance)
|
|
272
296
|
.map((path) => {
|
|
273
297
|
try {
|
|
274
|
-
|
|
298
|
+
const stats = statSync(path, { bigint: true });
|
|
299
|
+
return `${path}\0${stats.mtimeNs}:${stats.size}`;
|
|
275
300
|
} catch {
|
|
276
|
-
return `${path}
|
|
301
|
+
return `${path}\0missing`;
|
|
277
302
|
}
|
|
278
303
|
})
|
|
279
304
|
.join("\n");
|
|
280
305
|
}
|
|
281
306
|
|
|
307
|
+
function changedSignaturePaths(previous: string, next: string): string[] {
|
|
308
|
+
const entries = (signature: string): Map<string, string> =>
|
|
309
|
+
new Map(
|
|
310
|
+
signature
|
|
311
|
+
.split("\n")
|
|
312
|
+
.filter(Boolean)
|
|
313
|
+
.map((line) => {
|
|
314
|
+
const separator = line.indexOf("\0");
|
|
315
|
+
return [line.slice(0, separator), line.slice(separator + 1)];
|
|
316
|
+
})
|
|
317
|
+
);
|
|
318
|
+
const previousEntries = entries(previous);
|
|
319
|
+
const nextEntries = entries(next);
|
|
320
|
+
return [...new Set([...previousEntries.keys(), ...nextEntries.keys()])].filter(
|
|
321
|
+
(path) => previousEntries.get(path) !== nextEntries.get(path)
|
|
322
|
+
);
|
|
323
|
+
}
|
|
324
|
+
|
|
282
325
|
function devRouteTopologyWatchers(): Map<string, DevRouteTopologyWatcherState> {
|
|
283
326
|
const existing = Reflect.get(globalThis, DEV_ROUTE_WATCHERS_SYMBOL);
|
|
284
327
|
if (existing instanceof Map) {
|
|
@@ -289,36 +332,155 @@ function devRouteTopologyWatchers(): Map<string, DevRouteTopologyWatcherState> {
|
|
|
289
332
|
return watchers;
|
|
290
333
|
}
|
|
291
334
|
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
return
|
|
335
|
+
function watcherChangedSources(state: DevRouteTopologyWatcherState): Set<string> {
|
|
336
|
+
const existing = Reflect.get(state, "changedSources");
|
|
337
|
+
if (existing instanceof Set) {
|
|
338
|
+
return existing as Set<string>;
|
|
296
339
|
}
|
|
297
|
-
|
|
340
|
+
const changedSources = new Set<string>();
|
|
341
|
+
state.changedSources = changedSources;
|
|
342
|
+
return changedSources;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
async function refreshRouteTopologyOnce(state: DevRouteTopologyWatcherState): Promise<void> {
|
|
346
|
+
const pendingChangedSources = watcherChangedSources(state);
|
|
347
|
+
let changedSources = [...pendingChangedSources];
|
|
348
|
+
pendingChangedSources.clear();
|
|
298
349
|
try {
|
|
299
|
-
state.
|
|
350
|
+
state.dirty = false;
|
|
300
351
|
const source = routeTopologySource(state.instance);
|
|
301
352
|
if (source === state.source) {
|
|
302
353
|
const signature = routeFilesSignature(state.instance);
|
|
303
354
|
if (signature !== state.routeFilesSignature) {
|
|
304
|
-
|
|
355
|
+
changedSources = [
|
|
356
|
+
...new Set([
|
|
357
|
+
...changedSources,
|
|
358
|
+
...changedSignaturePaths(state.routeFilesSignature, signature),
|
|
359
|
+
]),
|
|
360
|
+
];
|
|
361
|
+
await state.onRouteFilesTouched?.(changedSources);
|
|
305
362
|
state.routeFilesSignature = routeFilesSignature(state.instance);
|
|
363
|
+
if (!state.closed) {
|
|
364
|
+
replaceSourceWatchers(state);
|
|
365
|
+
}
|
|
306
366
|
}
|
|
307
367
|
} else {
|
|
308
|
-
await state.onTopologyChange();
|
|
368
|
+
await state.onTopologyChange(changedSources);
|
|
309
369
|
state.source = routeTopologySource(state.instance);
|
|
310
370
|
state.routeFilesSignature = routeFilesSignature(state.instance);
|
|
371
|
+
if (!state.closed) {
|
|
372
|
+
replaceSourceWatchers(state);
|
|
373
|
+
}
|
|
311
374
|
}
|
|
312
375
|
} catch (error) {
|
|
313
376
|
console.error("[furin] Failed to refresh route topology", error);
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
await refreshRouteTopology(state);
|
|
377
|
+
state.dirty = true;
|
|
378
|
+
for (const sourcePath of changedSources) {
|
|
379
|
+
pendingChangedSources.add(sourcePath);
|
|
318
380
|
}
|
|
381
|
+
scheduleRouteTopologyRefresh(state, DEV_ROUTE_RETRY_DELAY_MS);
|
|
319
382
|
}
|
|
320
383
|
}
|
|
321
384
|
|
|
385
|
+
function scheduleRouteTopologyRefresh(state: DevRouteTopologyWatcherState, delay: number): void {
|
|
386
|
+
if (state.closed || state.reconcileTimer !== undefined) {
|
|
387
|
+
return;
|
|
388
|
+
}
|
|
389
|
+
state.reconcileTimer = setTimeout(() => {
|
|
390
|
+
state.reconcileTimer = undefined;
|
|
391
|
+
refreshRouteTopology(state).catch((error) => {
|
|
392
|
+
console.error("[furin] Failed to reconcile route topology", error);
|
|
393
|
+
});
|
|
394
|
+
}, delay);
|
|
395
|
+
state.reconcileTimer.unref();
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
function reportChangedSourceError(
|
|
399
|
+
state: DevRouteTopologyWatcherState,
|
|
400
|
+
directory: string,
|
|
401
|
+
filename: string | Buffer | null
|
|
402
|
+
): void {
|
|
403
|
+
if (filename === null) {
|
|
404
|
+
return;
|
|
405
|
+
}
|
|
406
|
+
const sourcePath = resolve(directory, String(filename));
|
|
407
|
+
if (!(ROUTE_EXTENSION.test(sourcePath) && existsSync(sourcePath))) {
|
|
408
|
+
return;
|
|
409
|
+
}
|
|
410
|
+
try {
|
|
411
|
+
const source = readFileSync(sourcePath, "utf8");
|
|
412
|
+
const loader = detectLoaderFromPath(sourcePath);
|
|
413
|
+
new Bun.Transpiler({ loader }).transformSync(source, loader);
|
|
414
|
+
} catch (error) {
|
|
415
|
+
state.onSourceError?.(error, sourcePath);
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
function replaceSourceWatchers(state: DevRouteTopologyWatcherState): void {
|
|
420
|
+
const previousWatchers = state.watchers;
|
|
421
|
+
const nextWatchers: FSWatcher[] = [];
|
|
422
|
+
const pagesDir = resolve(state.instance.pagesDir);
|
|
423
|
+
const directories = new Set<string>();
|
|
424
|
+
for (const path of routeDependencyPaths(state.instance)) {
|
|
425
|
+
if (!(path === pagesDir || path.startsWith(`${pagesDir}${sep}`))) {
|
|
426
|
+
directories.add(dirname(path));
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
const watchDirectory = (directory: string, recursive: boolean): void => {
|
|
430
|
+
const watcher = watch(directory, { recursive }, (_, filename) => {
|
|
431
|
+
if (!state.watchers.includes(watcher)) {
|
|
432
|
+
return;
|
|
433
|
+
}
|
|
434
|
+
state.dirty = true;
|
|
435
|
+
if (filename !== null) {
|
|
436
|
+
watcherChangedSources(state).add(resolve(directory, String(filename)));
|
|
437
|
+
}
|
|
438
|
+
reportChangedSourceError(state, directory, filename);
|
|
439
|
+
scheduleRouteTopologyRefresh(state, DEV_ROUTE_RECONCILE_DELAY_MS);
|
|
440
|
+
});
|
|
441
|
+
watcher.unref();
|
|
442
|
+
nextWatchers.push(watcher);
|
|
443
|
+
};
|
|
444
|
+
try {
|
|
445
|
+
watchDirectory(pagesDir, true);
|
|
446
|
+
for (const directory of directories) {
|
|
447
|
+
watchDirectory(directory, false);
|
|
448
|
+
}
|
|
449
|
+
} catch (error) {
|
|
450
|
+
for (const watcher of nextWatchers) {
|
|
451
|
+
watcher.close();
|
|
452
|
+
}
|
|
453
|
+
throw error;
|
|
454
|
+
}
|
|
455
|
+
state.watchers = nextWatchers;
|
|
456
|
+
for (const watcher of previousWatchers) {
|
|
457
|
+
watcher.close();
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
function refreshRouteTopology(state: DevRouteTopologyWatcherState): Promise<void> {
|
|
462
|
+
if (state.closed) {
|
|
463
|
+
return Promise.resolve();
|
|
464
|
+
}
|
|
465
|
+
state.pending = true;
|
|
466
|
+
if (state.refreshPromise) {
|
|
467
|
+
return state.refreshPromise;
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
state.refreshPromise = (async () => {
|
|
471
|
+
try {
|
|
472
|
+
while (state.pending && !state.closed) {
|
|
473
|
+
state.pending = false;
|
|
474
|
+
// biome-ignore lint/performance/noAwaitInLoops: refreshes must be serialized so requests observe the latest route snapshot
|
|
475
|
+
await refreshRouteTopologyOnce(state);
|
|
476
|
+
}
|
|
477
|
+
} finally {
|
|
478
|
+
state.refreshPromise = undefined;
|
|
479
|
+
}
|
|
480
|
+
})();
|
|
481
|
+
return state.refreshPromise;
|
|
482
|
+
}
|
|
483
|
+
|
|
322
484
|
export function registerDevRouteTopologyWatcher(
|
|
323
485
|
options: DevRouteTopologyWatcherOptions
|
|
324
486
|
): DevRouteTopologyWatcher {
|
|
@@ -328,43 +490,61 @@ export function registerDevRouteTopologyWatcher(
|
|
|
328
490
|
if (existing) {
|
|
329
491
|
existing.instance = options.instance;
|
|
330
492
|
existing.onRouteFilesTouched = options.onRouteFilesTouched;
|
|
493
|
+
existing.onSourceError = options.onSourceError;
|
|
331
494
|
existing.onTopologyChange = options.onTopologyChange;
|
|
332
495
|
return {
|
|
333
496
|
close: () => {
|
|
334
|
-
|
|
497
|
+
existing.closed = true;
|
|
498
|
+
if (existing.reconcileTimer !== undefined) {
|
|
499
|
+
clearTimeout(existing.reconcileTimer);
|
|
500
|
+
}
|
|
501
|
+
for (const watcher of existing.watchers) {
|
|
502
|
+
watcher.close();
|
|
503
|
+
}
|
|
335
504
|
watchers.delete(watcherKey);
|
|
336
505
|
},
|
|
506
|
+
refresh: () => refreshRouteTopology(existing),
|
|
337
507
|
};
|
|
338
508
|
}
|
|
339
509
|
|
|
340
510
|
const source = routeTopologySource(options.instance);
|
|
341
511
|
const routeFilesSignatureValue = routeFilesSignature(options.instance);
|
|
342
|
-
|
|
343
|
-
const timer = setInterval(() => {
|
|
344
|
-
refreshRouteTopology(state).catch((error) => {
|
|
345
|
-
console.error("[furin] Failed to poll route topology", error);
|
|
346
|
-
});
|
|
347
|
-
}, options.pollIntervalMs);
|
|
348
|
-
timer.unref();
|
|
349
|
-
state = {
|
|
512
|
+
const state: DevRouteTopologyWatcherState = {
|
|
350
513
|
...options,
|
|
514
|
+
changedSources: new Set(),
|
|
515
|
+
closed: false,
|
|
516
|
+
dirty: false,
|
|
351
517
|
pending: false,
|
|
352
|
-
|
|
518
|
+
reconcileTimer: undefined,
|
|
519
|
+
refreshPromise: undefined,
|
|
353
520
|
routeFilesSignature: routeFilesSignatureValue,
|
|
354
521
|
source,
|
|
355
|
-
|
|
522
|
+
watchers: [],
|
|
356
523
|
};
|
|
524
|
+
replaceSourceWatchers(state);
|
|
525
|
+
scheduleRouteTopologyRefresh(state, DEV_ROUTE_RECONCILE_DELAY_MS);
|
|
357
526
|
watchers.set(watcherKey, state);
|
|
358
527
|
|
|
359
528
|
return {
|
|
360
529
|
close: () => {
|
|
361
|
-
|
|
530
|
+
state.closed = true;
|
|
531
|
+
if (state.reconcileTimer !== undefined) {
|
|
532
|
+
clearTimeout(state.reconcileTimer);
|
|
533
|
+
}
|
|
534
|
+
for (const watcher of state.watchers) {
|
|
535
|
+
watcher.close();
|
|
536
|
+
}
|
|
362
537
|
watchers.delete(watcherKey);
|
|
363
538
|
},
|
|
539
|
+
refresh: () => refreshRouteTopology(state),
|
|
364
540
|
};
|
|
365
541
|
}
|
|
366
542
|
|
|
367
|
-
function emitRouteNode(
|
|
543
|
+
function emitRouteNode(
|
|
544
|
+
node: RouteTreeNode,
|
|
545
|
+
indentation: string,
|
|
546
|
+
includeRootCatchAll: boolean
|
|
547
|
+
): string {
|
|
368
548
|
const childIndentation = `${indentation} `;
|
|
369
549
|
const prefix = node.name ? `/${segmentPath(node.name)}` : "";
|
|
370
550
|
const head = `new Elysia({ prefix: ${JSON.stringify(prefix)} })`;
|
|
@@ -374,7 +554,7 @@ function emitRouteNode(node: RouteTreeNode, indentation: string): string {
|
|
|
374
554
|
`${childIndentation}.use(new Elysia({ prefix: "" }).use(${node.indexRoute.id}.elysia))`
|
|
375
555
|
);
|
|
376
556
|
}
|
|
377
|
-
for (const route of node.fileRoutes) {
|
|
557
|
+
for (const route of node.fileRoutes.filter((file) => includeRootCatchAll || file.path !== "/*")) {
|
|
378
558
|
const segment = route.path.slice(route.path.lastIndexOf("/") + 1);
|
|
379
559
|
content.push(
|
|
380
560
|
`${childIndentation}.use(new Elysia({ prefix: ${JSON.stringify(`/${segment}`)} }).use(${route.id}.elysia))`
|
|
@@ -382,7 +562,7 @@ function emitRouteNode(node: RouteTreeNode, indentation: string): string {
|
|
|
382
562
|
}
|
|
383
563
|
for (const child of node.children) {
|
|
384
564
|
content.push(`${childIndentation}.use(`);
|
|
385
|
-
content.push(emitRouteNode(child, `${childIndentation}
|
|
565
|
+
content.push(emitRouteNode(child, `${childIndentation} `, includeRootCatchAll));
|
|
386
566
|
content.push(`${childIndentation})`);
|
|
387
567
|
}
|
|
388
568
|
if (node.layout) {
|
|
@@ -434,7 +614,9 @@ async function retainComposableRoutes(node: RouteTreeNode): Promise<void> {
|
|
|
434
614
|
|
|
435
615
|
async function generateServerInstance(
|
|
436
616
|
instance: RouteInstanceSpec,
|
|
437
|
-
routeFilesBySpecifier: Map<string, RouteModuleInfo
|
|
617
|
+
routeFilesBySpecifier: Map<string, RouteModuleInfo>,
|
|
618
|
+
materialized: boolean,
|
|
619
|
+
includeRootCatchAll: boolean
|
|
438
620
|
): Promise<GeneratedServerInstance> {
|
|
439
621
|
const instanceId = Bun.hash(instanceKey(instance)).toString(16);
|
|
440
622
|
const tree = buildRouteTree(instance.pagesDir, instanceId);
|
|
@@ -442,7 +624,9 @@ async function generateServerInstance(
|
|
|
442
624
|
const imports = collectRouteFiles(tree)
|
|
443
625
|
.sort((left, right) => left.sourcePath.localeCompare(right.sourcePath))
|
|
444
626
|
.map((route) => {
|
|
445
|
-
const specifier =
|
|
627
|
+
const specifier = materialized
|
|
628
|
+
? resolve(route.sourcePath).replaceAll("\\", "/")
|
|
629
|
+
: routeFileSpecifier(route);
|
|
446
630
|
routeFilesBySpecifier.set(specifier, {
|
|
447
631
|
routePath: route.path,
|
|
448
632
|
sourcePath: resolve(route.sourcePath),
|
|
@@ -451,7 +635,7 @@ async function generateServerInstance(
|
|
|
451
635
|
})
|
|
452
636
|
.join("\n");
|
|
453
637
|
return {
|
|
454
|
-
appExpression: emitRouteNode(tree, ""),
|
|
638
|
+
appExpression: emitRouteNode(tree, "", includeRootCatchAll),
|
|
455
639
|
exportName: `furinApp_${instanceId}`,
|
|
456
640
|
imports,
|
|
457
641
|
};
|
|
@@ -459,11 +643,15 @@ async function generateServerInstance(
|
|
|
459
643
|
|
|
460
644
|
async function serverRegistrySource(
|
|
461
645
|
instances: RouteInstanceSpec[],
|
|
462
|
-
routeFilesBySpecifier: Map<string, RouteModuleInfo
|
|
646
|
+
routeFilesBySpecifier: Map<string, RouteModuleInfo>,
|
|
647
|
+
materialized: boolean,
|
|
648
|
+
includeRootCatchAll: boolean
|
|
463
649
|
): Promise<string> {
|
|
464
650
|
routeFilesBySpecifier.clear();
|
|
465
651
|
const generated = await Promise.all(
|
|
466
|
-
instances.map((instance) =>
|
|
652
|
+
instances.map((instance) =>
|
|
653
|
+
generateServerInstance(instance, routeFilesBySpecifier, materialized, includeRootCatchAll)
|
|
654
|
+
)
|
|
467
655
|
);
|
|
468
656
|
return `import { Elysia } from "elysia";
|
|
469
657
|
${generated.map(({ imports }) => imports).join("\n")}
|
|
@@ -474,6 +662,18 @@ ${generated
|
|
|
474
662
|
`;
|
|
475
663
|
}
|
|
476
664
|
|
|
665
|
+
/**
|
|
666
|
+
* Emits a real server route module for build-time consumers such as Elysia's
|
|
667
|
+
* AOT plugin, which imports the application outside Bun's virtual module graph.
|
|
668
|
+
*/
|
|
669
|
+
export async function materializedRouteModuleSource(instance: RouteInstanceSpec): Promise<string> {
|
|
670
|
+
const routeFilesBySpecifier = new Map<string, RouteModuleInfo>();
|
|
671
|
+
const source = await serverRegistrySource([instance], routeFilesBySpecifier, true, false);
|
|
672
|
+
await validateRouteModules(routeFilesBySpecifier.values());
|
|
673
|
+
const exportName = `furinApp_${Bun.hash(instanceKey(instance)).toString(16)}`;
|
|
674
|
+
return `${source}\nexport { ${exportName} as furinApp };\n`;
|
|
675
|
+
}
|
|
676
|
+
|
|
477
677
|
export function validateRouteParams(
|
|
478
678
|
path: string,
|
|
479
679
|
schemas: { params?: { properties?: object } } | undefined
|
|
@@ -697,10 +897,11 @@ async function composableRouteApps(route: RouteFile): Promise<DevRoutesApps | un
|
|
|
697
897
|
|
|
698
898
|
async function composeRuntimeNode(node: RouteTreeNode): Promise<DevRoutesApps> {
|
|
699
899
|
const prefix = node.name ? `/${segmentPath(node.name)}` : "";
|
|
900
|
+
const { fileRoutes } = node;
|
|
700
901
|
const [layoutApps, indexRouteApps, fileRouteApps, childApps] = await Promise.all([
|
|
701
902
|
node.layout ? composableRouteApps(node.layout) : undefined,
|
|
702
903
|
node.indexRoute ? composableRouteApps(node.indexRoute) : undefined,
|
|
703
|
-
Promise.all(
|
|
904
|
+
Promise.all(fileRoutes.map((route) => composableRouteApps(route))),
|
|
704
905
|
Promise.all(node.children.map((child) => composeRuntimeNode(child))),
|
|
705
906
|
]);
|
|
706
907
|
const appScope = layoutApps?.app ?? new Elysia();
|
|
@@ -710,12 +911,14 @@ async function composeRuntimeNode(node: RouteTreeNode): Promise<DevRoutesApps> {
|
|
|
710
911
|
appScope.use(new Elysia({ prefix: "" }).use(indexRouteApps.app));
|
|
711
912
|
shellScope.use(new Elysia({ prefix: "" }).use(indexRouteApps.shell));
|
|
712
913
|
}
|
|
713
|
-
for (const [index, route] of
|
|
914
|
+
for (const [index, route] of fileRoutes.entries()) {
|
|
714
915
|
const routeApps = fileRouteApps[index];
|
|
715
916
|
if (routeApps) {
|
|
716
917
|
const segment = route.path.slice(route.path.lastIndexOf("/") + 1);
|
|
717
918
|
appScope.use(new Elysia({ prefix: `/${segment}` }).use(routeApps.app));
|
|
718
|
-
|
|
919
|
+
if (route.path !== "/*") {
|
|
920
|
+
shellScope.use(new Elysia({ prefix: `/${segment}` }).use(routeApps.shell));
|
|
921
|
+
}
|
|
719
922
|
}
|
|
720
923
|
}
|
|
721
924
|
for (const child of childApps) {
|
|
@@ -804,9 +1007,12 @@ function primaryInstance(instances: RouteInstanceSpec[]): RouteInstanceSpec {
|
|
|
804
1007
|
return instance;
|
|
805
1008
|
}
|
|
806
1009
|
|
|
807
|
-
function serverProxySource(instance: RouteInstanceSpec): string {
|
|
1010
|
+
function serverProxySource(instance: RouteInstanceSpec, includeRootCatchAll: boolean): string {
|
|
808
1011
|
const exportName = `furinApp_${Bun.hash(instanceKey(instance)).toString(16)}`;
|
|
809
|
-
|
|
1012
|
+
const registry = includeRootCatchAll
|
|
1013
|
+
? ROUTES_REGISTRY_SPECIFIER
|
|
1014
|
+
: COMPOSABLE_ROUTES_REGISTRY_SPECIFIER;
|
|
1015
|
+
return `export { ${exportName} as furinApp } from ${JSON.stringify(registry)};\n`;
|
|
810
1016
|
}
|
|
811
1017
|
|
|
812
1018
|
export function createRoutesPlugin(options: CreateRoutesPluginOptions): Bun.BunPlugin {
|
|
@@ -816,14 +1022,28 @@ export function createRoutesPlugin(options: CreateRoutesPluginOptions): Bun.BunP
|
|
|
816
1022
|
resolve(primaryInstance(options.instances).pagesDir),
|
|
817
1023
|
".furin-routes-registry.ts?furin-virtual"
|
|
818
1024
|
);
|
|
819
|
-
const
|
|
820
|
-
options.instances.
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
1025
|
+
const composableRegistryVirtualPath = join(
|
|
1026
|
+
resolve(primaryInstance(options.instances).pagesDir),
|
|
1027
|
+
".furin-routes-registry-composable.ts?furin-virtual"
|
|
1028
|
+
);
|
|
1029
|
+
const instancesBySpecifier = new Map<
|
|
1030
|
+
string,
|
|
1031
|
+
{ instance: RouteInstanceSpec; namespace: string; includeRootCatchAll: boolean }
|
|
1032
|
+
>(
|
|
1033
|
+
options.instances.flatMap((instance) => [
|
|
1034
|
+
[
|
|
1035
|
+
routeModuleSpecifier(instance),
|
|
1036
|
+
{ includeRootCatchAll: true, instance, namespace: instanceNamespace(instance) },
|
|
1037
|
+
] as const,
|
|
1038
|
+
[
|
|
1039
|
+
composableRouteModuleSpecifier(instance),
|
|
1040
|
+
{
|
|
1041
|
+
includeRootCatchAll: false,
|
|
1042
|
+
instance,
|
|
1043
|
+
namespace: `${instanceNamespace(instance)}-composable`,
|
|
1044
|
+
},
|
|
1045
|
+
] as const,
|
|
1046
|
+
])
|
|
827
1047
|
);
|
|
828
1048
|
|
|
829
1049
|
return {
|
|
@@ -848,12 +1068,18 @@ export function createRoutesPlugin(options: CreateRoutesPluginOptions): Bun.BunP
|
|
|
848
1068
|
}
|
|
849
1069
|
return { namespace: registered.namespace, path };
|
|
850
1070
|
});
|
|
851
|
-
build.onResolve({ filter: ROUTES_REGISTRY_FILTER }, () => ({
|
|
1071
|
+
build.onResolve({ filter: ROUTES_REGISTRY_FILTER }, ({ path }) => ({
|
|
852
1072
|
namespace: "file",
|
|
853
|
-
path:
|
|
1073
|
+
path:
|
|
1074
|
+
path === ROUTES_REGISTRY_SPECIFIER ? registryVirtualPath : composableRegistryVirtualPath,
|
|
854
1075
|
}));
|
|
855
|
-
build.onLoad({ filter: ROUTES_REGISTRY_FILE_FILTER, namespace: "file" }, async () => {
|
|
856
|
-
const contents = await serverRegistrySource(
|
|
1076
|
+
build.onLoad({ filter: ROUTES_REGISTRY_FILE_FILTER, namespace: "file" }, async ({ path }) => {
|
|
1077
|
+
const contents = await serverRegistrySource(
|
|
1078
|
+
options.instances,
|
|
1079
|
+
routeFilesBySpecifier,
|
|
1080
|
+
false,
|
|
1081
|
+
path === registryVirtualPath
|
|
1082
|
+
);
|
|
857
1083
|
await validateRouteModules(routeFilesBySpecifier.values());
|
|
858
1084
|
return { contents, loader: "ts" };
|
|
859
1085
|
});
|
|
@@ -880,9 +1106,9 @@ export function createRoutesPlugin(options: CreateRoutesPluginOptions): Bun.BunP
|
|
|
880
1106
|
};
|
|
881
1107
|
}
|
|
882
1108
|
);
|
|
883
|
-
for (const { instance, namespace } of instancesBySpecifier.values()) {
|
|
1109
|
+
for (const { instance, namespace, includeRootCatchAll } of instancesBySpecifier.values()) {
|
|
884
1110
|
build.onLoad({ filter: VIRTUAL_ROUTES_FILTER, namespace }, () => ({
|
|
885
|
-
contents: serverProxySource(instance),
|
|
1111
|
+
contents: serverProxySource(instance, includeRootCatchAll),
|
|
886
1112
|
loader: "ts",
|
|
887
1113
|
}));
|
|
888
1114
|
}
|