@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
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { CacheTag } from "../../furin.ts";
|
|
2
|
+
import type { SyncQueryIdentity } from "../../shared/sync-query.ts";
|
|
2
3
|
import type { RevalidateType } from "../cache/route-cache.ts";
|
|
3
4
|
|
|
4
5
|
export type InvalidationRule =
|
|
@@ -14,3 +15,8 @@ export type InvalidationRule =
|
|
|
14
15
|
};
|
|
15
16
|
|
|
16
17
|
export type InvalidationInput = InvalidationRule | readonly InvalidationRule[];
|
|
18
|
+
|
|
19
|
+
export type SyncInvalidationInput =
|
|
20
|
+
| InvalidationRule
|
|
21
|
+
| SyncQueryIdentity
|
|
22
|
+
| readonly (InvalidationRule | SyncQueryIdentity)[];
|
package/src/server/cache/isr.ts
CHANGED
|
@@ -1,38 +1,23 @@
|
|
|
1
1
|
import { allStateBuckets, type FurinInstance, instanceSlot } from "../instance.ts";
|
|
2
2
|
import { createHtmlRouteCache, type ISRCacheEntry } from "./isr-ssg";
|
|
3
3
|
import { registerCacheInvalidator } from "./registry";
|
|
4
|
-
import type { Cache } from "./route-cache";
|
|
4
|
+
import type { Cache, CacheGeneration } from "./route-cache";
|
|
5
5
|
import { createStoreView, type StoreView } from "./store-view";
|
|
6
6
|
|
|
7
7
|
interface ISRCacheState {
|
|
8
8
|
cache: Cache<ISRCacheEntry>;
|
|
9
|
-
generations: Map<string, Set<ISRCacheGeneration>>;
|
|
10
9
|
pendingRevalidations: Map<string, Promise<void>>;
|
|
11
10
|
}
|
|
12
11
|
|
|
13
|
-
export
|
|
14
|
-
valid: boolean;
|
|
15
|
-
}
|
|
12
|
+
export type ISRCacheGeneration = CacheGeneration;
|
|
16
13
|
|
|
17
14
|
// Per-instance ISR HTML cache — registered against the owning instance's
|
|
18
15
|
// invalidator map on first access.
|
|
19
16
|
const instanceIsrCache = instanceSlot<ISRCacheState>((instance) => {
|
|
20
|
-
const generations = new Map<string, Set<ISRCacheGeneration>>();
|
|
21
17
|
const pendingRevalidations = new Map<string, Promise<void>>();
|
|
22
|
-
const cache = createHtmlRouteCache<ISRCacheEntry>("isr"
|
|
23
|
-
onDelete: (key) => {
|
|
24
|
-
const pending = generations.get(key);
|
|
25
|
-
if (pending === undefined) {
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
for (const generation of pending) {
|
|
29
|
-
generation.valid = false;
|
|
30
|
-
}
|
|
31
|
-
generations.delete(key);
|
|
32
|
-
},
|
|
33
|
-
});
|
|
18
|
+
const cache = createHtmlRouteCache<ISRCacheEntry>("isr");
|
|
34
19
|
registerCacheInvalidator(cache, instance);
|
|
35
|
-
return { cache,
|
|
20
|
+
return { cache, pendingRevalidations };
|
|
36
21
|
});
|
|
37
22
|
|
|
38
23
|
export function isrRouteCache(instance?: FurinInstance): Cache<ISRCacheEntry> {
|
|
@@ -57,24 +42,11 @@ export function setISRCache(key: string, entry: ISRCacheEntry): void {
|
|
|
57
42
|
}
|
|
58
43
|
|
|
59
44
|
export function captureISRCacheGeneration(key: string): ISRCacheGeneration {
|
|
60
|
-
|
|
61
|
-
const generation = { valid: true };
|
|
62
|
-
const pending = state.generations.get(key);
|
|
63
|
-
if (pending === undefined) {
|
|
64
|
-
state.generations.set(key, new Set([generation]));
|
|
65
|
-
} else {
|
|
66
|
-
pending.add(generation);
|
|
67
|
-
}
|
|
68
|
-
return generation;
|
|
45
|
+
return instanceIsrCache().cache.captureGeneration(key);
|
|
69
46
|
}
|
|
70
47
|
|
|
71
48
|
export function releaseISRCacheGeneration(key: string, generation: ISRCacheGeneration): void {
|
|
72
|
-
|
|
73
|
-
const pending = generations.get(key);
|
|
74
|
-
pending?.delete(generation);
|
|
75
|
-
if (pending?.size === 0) {
|
|
76
|
-
generations.delete(key);
|
|
77
|
-
}
|
|
49
|
+
instanceIsrCache().cache.releaseGeneration(key, generation);
|
|
78
50
|
}
|
|
79
51
|
|
|
80
52
|
export function setISRCacheIfGenerationUnchanged(
|
|
@@ -5,7 +5,12 @@ export interface CacheInvalidationResult {
|
|
|
5
5
|
purgedPaths: string[];
|
|
6
6
|
}
|
|
7
7
|
|
|
8
|
+
export interface CacheGeneration {
|
|
9
|
+
valid: boolean;
|
|
10
|
+
}
|
|
11
|
+
|
|
8
12
|
export interface Cache<Entry> {
|
|
13
|
+
captureGeneration: (key: string) => CacheGeneration;
|
|
9
14
|
clear: () => void;
|
|
10
15
|
delete: (key: string) => boolean;
|
|
11
16
|
entries: () => IterableIterator<[string, Entry]>;
|
|
@@ -14,6 +19,7 @@ export interface Cache<Entry> {
|
|
|
14
19
|
invalidatePath: (path: string, type: RevalidateType) => CacheInvalidationResult;
|
|
15
20
|
keys: () => IterableIterator<string>;
|
|
16
21
|
readonly name: string;
|
|
22
|
+
releaseGeneration: (key: string, generation: CacheGeneration) => void;
|
|
17
23
|
set: (key: string, entry: Entry) => void;
|
|
18
24
|
get size(): number;
|
|
19
25
|
readonly store: Map<string, Entry>;
|
|
@@ -54,8 +60,16 @@ function matchesPath(urlPath: string, path: string, type: RevalidateType): boole
|
|
|
54
60
|
|
|
55
61
|
export function createRouteCache<Entry>(options: RouteCacheOptions<Entry>): Cache<Entry> {
|
|
56
62
|
const store = new Map<string, Entry>();
|
|
63
|
+
const generations = new Map<string, Set<CacheGeneration>>();
|
|
57
64
|
const pathFromKey = options.pathFromKey ?? defaultPathFromKey;
|
|
58
65
|
|
|
66
|
+
const invalidateGenerations = (key: string): void => {
|
|
67
|
+
for (const generation of generations.get(key) ?? []) {
|
|
68
|
+
generation.valid = false;
|
|
69
|
+
}
|
|
70
|
+
generations.delete(key);
|
|
71
|
+
};
|
|
72
|
+
|
|
59
73
|
const evictOldest = (): void => {
|
|
60
74
|
if (options.maxSize === undefined || store.size <= options.maxSize) {
|
|
61
75
|
return;
|
|
@@ -67,6 +81,7 @@ export function createRouteCache<Entry>(options: RouteCacheOptions<Entry>): Cach
|
|
|
67
81
|
};
|
|
68
82
|
|
|
69
83
|
const deleteEntry = (key: string): boolean => {
|
|
84
|
+
invalidateGenerations(key);
|
|
70
85
|
const entry = store.get(key);
|
|
71
86
|
if (entry === undefined) {
|
|
72
87
|
return false;
|
|
@@ -77,7 +92,20 @@ export function createRouteCache<Entry>(options: RouteCacheOptions<Entry>): Cach
|
|
|
77
92
|
};
|
|
78
93
|
|
|
79
94
|
return {
|
|
95
|
+
captureGeneration(key) {
|
|
96
|
+
const generation = { valid: true };
|
|
97
|
+
let pending = generations.get(key);
|
|
98
|
+
if (pending === undefined) {
|
|
99
|
+
pending = new Set();
|
|
100
|
+
generations.set(key, pending);
|
|
101
|
+
}
|
|
102
|
+
pending.add(generation);
|
|
103
|
+
return generation;
|
|
104
|
+
},
|
|
80
105
|
clear() {
|
|
106
|
+
for (const key of generations.keys()) {
|
|
107
|
+
invalidateGenerations(key);
|
|
108
|
+
}
|
|
81
109
|
for (const key of [...store.keys()]) {
|
|
82
110
|
deleteEntry(key);
|
|
83
111
|
}
|
|
@@ -104,14 +132,15 @@ export function createRouteCache<Entry>(options: RouteCacheOptions<Entry>): Cach
|
|
|
104
132
|
let deleted = false;
|
|
105
133
|
const purgedPaths: string[] = [];
|
|
106
134
|
|
|
107
|
-
for (const key of [...store.keys()]) {
|
|
135
|
+
for (const key of new Set([...store.keys(), ...generations.keys()])) {
|
|
108
136
|
const urlPath = pathFromKey(key);
|
|
109
137
|
if (urlPath === null || !matchesPath(urlPath, path, type)) {
|
|
110
138
|
continue;
|
|
111
139
|
}
|
|
112
|
-
deleteEntry(key)
|
|
113
|
-
|
|
114
|
-
|
|
140
|
+
if (deleteEntry(key)) {
|
|
141
|
+
deleted = true;
|
|
142
|
+
purgedPaths.push(urlPath);
|
|
143
|
+
}
|
|
115
144
|
}
|
|
116
145
|
|
|
117
146
|
return { deleted, purgedPaths: [...new Set(purgedPaths)] };
|
|
@@ -120,6 +149,13 @@ export function createRouteCache<Entry>(options: RouteCacheOptions<Entry>): Cach
|
|
|
120
149
|
return store.keys();
|
|
121
150
|
},
|
|
122
151
|
name: options.name,
|
|
152
|
+
releaseGeneration(key, generation) {
|
|
153
|
+
const pending = generations.get(key);
|
|
154
|
+
pending?.delete(generation);
|
|
155
|
+
if (pending?.size === 0) {
|
|
156
|
+
generations.delete(key);
|
|
157
|
+
}
|
|
158
|
+
},
|
|
123
159
|
set(key, entry) {
|
|
124
160
|
const previous = store.get(key);
|
|
125
161
|
if (previous !== undefined) {
|
package/src/server/dev/graph.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { randomUUID } from "node:crypto";
|
|
2
2
|
import { readFileSync, statSync } from "node:fs";
|
|
3
|
-
import { dirname, extname, resolve } from "node:path";
|
|
3
|
+
import { dirname, extname, isAbsolute, resolve } from "node:path";
|
|
4
4
|
import type { FurinRouteDispatcher } from "../../define-route.ts";
|
|
5
5
|
import { currentInstance, type FurinInstance } from "../instance.ts";
|
|
6
6
|
import type { ResolvedRoute, RootLayout } from "../router/types.ts";
|
|
@@ -84,7 +84,7 @@ export function resolveDevSourceImports(
|
|
|
84
84
|
? resolve(dirname(path), imported.path)
|
|
85
85
|
: Bun.resolveSync(imported.path, dirname(path));
|
|
86
86
|
const resolved = normalizeModulePath(absolute);
|
|
87
|
-
if (!resolved.includes("/node_modules/")) {
|
|
87
|
+
if (isAbsolute(resolved) && !resolved.includes("/node_modules/")) {
|
|
88
88
|
imports.push(resolved);
|
|
89
89
|
}
|
|
90
90
|
} catch {
|
|
@@ -268,6 +268,20 @@ export class DevGraph<Snapshot> {
|
|
|
268
268
|
return this.importChain(from, normalizedTo).includes(normalizedTo);
|
|
269
269
|
}
|
|
270
270
|
|
|
271
|
+
sourceDependencies(from: string): string[] {
|
|
272
|
+
const pending = [normalizeModulePath(from)];
|
|
273
|
+
const visited = new Set<string>();
|
|
274
|
+
while (pending.length > 0) {
|
|
275
|
+
const path = pending.pop();
|
|
276
|
+
if (path === undefined || visited.has(path)) {
|
|
277
|
+
continue;
|
|
278
|
+
}
|
|
279
|
+
visited.add(path);
|
|
280
|
+
pending.push(...(this.#dependencies.get(path) ?? []));
|
|
281
|
+
}
|
|
282
|
+
return [...visited];
|
|
283
|
+
}
|
|
284
|
+
|
|
271
285
|
clearSourceErrors(path: string): void {
|
|
272
286
|
const modulePath = normalizeModulePath(path);
|
|
273
287
|
for (const [message, positions] of this.#sourceErrors) {
|
|
@@ -47,17 +47,19 @@
|
|
|
47
47
|
* guaranteeing a single shared React instance regardless of CWD or
|
|
48
48
|
* hot-reload state.
|
|
49
49
|
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
* that modules which both import and re-export from the same package are fully
|
|
53
|
-
* rewritten while string literals in non-import positions are left untouched.
|
|
50
|
+
* Static imports, re-exports, and literal dynamic imports are rewritten from
|
|
51
|
+
* the parsed module, leaving ordinary strings and comments untouched.
|
|
54
52
|
*/
|
|
55
53
|
|
|
56
54
|
import { statSync } from "node:fs";
|
|
57
55
|
import { dirname, isAbsolute, resolve } from "node:path";
|
|
58
56
|
import { fileURLToPath } from "node:url";
|
|
57
|
+
import MagicString from "magic-string";
|
|
59
58
|
import { splitDevPage } from "../plugin/transform-dev-page.ts";
|
|
60
59
|
import { transformIsomorphicFunctions } from "../plugin/transform-isomorphic.ts";
|
|
60
|
+
import { parseSource } from "../shared/parser.ts";
|
|
61
|
+
import type { AstNode } from "../shared/utils/ast-walk.ts";
|
|
62
|
+
import { walkAST } from "../shared/utils/ast-walk.ts";
|
|
61
63
|
import { invalidateDevLoaderCacheBySource } from "./cache/dev-loader.ts";
|
|
62
64
|
import { publishDevError } from "./dev/error.ts";
|
|
63
65
|
import { developmentGraphs, resolveDevSourceImports } from "./dev/graph.ts";
|
|
@@ -74,6 +76,7 @@ export const WORKSPACE_SOURCE_FILTER =
|
|
|
74
76
|
const T_PARAM_RE = /&t=(\d+)/;
|
|
75
77
|
const STRIP_FURIN_SERVER_RE = /\?furin-server.*$/;
|
|
76
78
|
const STRIP_T_PARAM_RE = /\?t=\d+$/;
|
|
79
|
+
const IMPORT_ATTRIBUTES_RE = /\b(?:with|assert)\s*\{/;
|
|
77
80
|
const DELETED_DEV_PAGE_CONTENTS = "export const route = undefined;";
|
|
78
81
|
|
|
79
82
|
let _pluginRegistered = false;
|
|
@@ -240,69 +243,45 @@ function rewriteRelativeImportsWithVersion(
|
|
|
240
243
|
}
|
|
241
244
|
|
|
242
245
|
/**
|
|
243
|
-
*
|
|
244
|
-
*
|
|
245
|
-
*
|
|
246
|
-
* Uses `Bun.Transpiler.scan()` on the original source to get the authoritative
|
|
247
|
-
* list of *actual* import specifiers (parsing correctly handles template
|
|
248
|
-
* literals, comments, etc.). For each bare specifier that is not already
|
|
249
|
-
* handled by `rewriteSingletonImports`, it calls `Bun.resolveSync` and
|
|
250
|
-
* replaces **every** import/re-export occurrence of the quoted specifier using
|
|
251
|
-
* a context-aware regex with the `g` flag — mirroring the approach used by
|
|
252
|
-
* `rewriteSingletonImports`. This correctly handles modules that both import
|
|
253
|
-
* and re-export from the same package without leaving any bare specifier
|
|
254
|
-
* behind. String literals that happen to contain the same text (inside
|
|
255
|
-
* template literals, JSX props, etc.) are not touched because the regex
|
|
256
|
-
* requires a preceding `from` or `import` keyword.
|
|
246
|
+
* Resolves static imports, re-exports, and literal dynamic imports from the
|
|
247
|
+
* page file's directory, including tsconfig aliases in virtual modules.
|
|
257
248
|
*
|
|
258
249
|
* @internal exported for testing
|
|
259
250
|
*/
|
|
260
|
-
export function rewriteBareImports(
|
|
261
|
-
const
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
seen.add(imp.path);
|
|
271
|
-
return true;
|
|
272
|
-
});
|
|
273
|
-
|
|
274
|
-
let result = transpiled;
|
|
275
|
-
for (const imp of imports) {
|
|
276
|
-
const spec = imp.path;
|
|
277
|
-
// Skip relative paths (already rewritten by rewriteRelativeImports before transpilation)
|
|
278
|
-
// and already-absolute paths.
|
|
279
|
-
if (spec.startsWith(".") || spec.startsWith("/") || spec.startsWith("file:")) {
|
|
280
|
-
continue;
|
|
251
|
+
export function rewriteBareImports(transpiled: string, dir: string): string {
|
|
252
|
+
const output = new MagicString(transpiled);
|
|
253
|
+
walkAST(parseSource(transpiled, "js").program, (node) => {
|
|
254
|
+
if (
|
|
255
|
+
node.type !== "ImportDeclaration" &&
|
|
256
|
+
node.type !== "ExportNamedDeclaration" &&
|
|
257
|
+
node.type !== "ExportAllDeclaration" &&
|
|
258
|
+
node.type !== "ImportExpression"
|
|
259
|
+
) {
|
|
260
|
+
return;
|
|
281
261
|
}
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
262
|
+
const literal = node.source as AstNode | undefined;
|
|
263
|
+
const specifier = literal?.value;
|
|
264
|
+
if (
|
|
265
|
+
literal?.type !== "Literal" ||
|
|
266
|
+
typeof specifier !== "string" ||
|
|
267
|
+
specifier.startsWith(".") ||
|
|
268
|
+
isAbsolute(specifier) ||
|
|
269
|
+
specifier.startsWith("file:") ||
|
|
270
|
+
SINGLETON_PATHS.has(specifier)
|
|
271
|
+
) {
|
|
272
|
+
return;
|
|
285
273
|
}
|
|
286
274
|
|
|
287
275
|
let resolved: string;
|
|
288
276
|
try {
|
|
289
|
-
resolved = toImportSpecifier(Bun.resolveSync(
|
|
277
|
+
resolved = toImportSpecifier(Bun.resolveSync(specifier, dir));
|
|
290
278
|
} catch {
|
|
291
|
-
//
|
|
292
|
-
|
|
293
|
-
continue;
|
|
279
|
+
// Leave unresolved imports to Bun's native resolution and diagnostics.
|
|
280
|
+
return;
|
|
294
281
|
}
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
// that both import and re-export from the same package. The regex only
|
|
299
|
-
// matches when the specifier is preceded by `from` or `import` so string
|
|
300
|
-
// literals in non-import positions are left untouched.
|
|
301
|
-
// react-doctor-disable-next-line react-doctor/js-hoist-regexp
|
|
302
|
-
const re = new RegExp(`((?:from|import(?:\\s+type)?)\\s+)["']${escapeRegExp(spec)}["']`, "g");
|
|
303
|
-
result = result.replace(re, (_, g1: string) => `${g1}${JSON.stringify(resolved)}`);
|
|
304
|
-
}
|
|
305
|
-
return result;
|
|
282
|
+
output.update(literal.start, literal.end, JSON.stringify(resolved));
|
|
283
|
+
});
|
|
284
|
+
return output.toString();
|
|
306
285
|
}
|
|
307
286
|
|
|
308
287
|
function getSourceLoader(filePath: string): SourceLoader | null {
|
|
@@ -321,6 +300,57 @@ function getSourceLoader(filePath: string): SourceLoader | null {
|
|
|
321
300
|
return null;
|
|
322
301
|
}
|
|
323
302
|
|
|
303
|
+
// Bun.Transpiler drops static import attributes, turning text imports into file paths.
|
|
304
|
+
function restoreImportAttributes(source: string, transpiled: string, loader: SourceLoader): string {
|
|
305
|
+
if (!IMPORT_ATTRIBUTES_RE.test(source)) {
|
|
306
|
+
return transpiled;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
const declarations = parseSource(source, loader).program.body as AstNode[];
|
|
310
|
+
const output = new MagicString(transpiled);
|
|
311
|
+
const emitted = parseSource(transpiled, "js").program.body as AstNode[];
|
|
312
|
+
const matched = new Set<AstNode>();
|
|
313
|
+
for (const declaration of declarations) {
|
|
314
|
+
if (declaration.importKind === "type" || declaration.exportKind === "type") {
|
|
315
|
+
continue;
|
|
316
|
+
}
|
|
317
|
+
const specifiers = declaration.specifiers as AstNode[] | undefined;
|
|
318
|
+
if (
|
|
319
|
+
specifiers?.length &&
|
|
320
|
+
specifiers.every(
|
|
321
|
+
(specifier) => specifier.importKind === "type" || specifier.exportKind === "type"
|
|
322
|
+
)
|
|
323
|
+
) {
|
|
324
|
+
continue;
|
|
325
|
+
}
|
|
326
|
+
const sourcePath = (declaration.source as { value?: unknown } | undefined)?.value;
|
|
327
|
+
if (typeof sourcePath !== "string") {
|
|
328
|
+
continue;
|
|
329
|
+
}
|
|
330
|
+
const target = emitted.find(
|
|
331
|
+
(node) =>
|
|
332
|
+
!matched.has(node) &&
|
|
333
|
+
node.type === declaration.type &&
|
|
334
|
+
(node.source as { value?: unknown } | undefined)?.value === sourcePath
|
|
335
|
+
);
|
|
336
|
+
if (!target) {
|
|
337
|
+
continue;
|
|
338
|
+
}
|
|
339
|
+
matched.add(target);
|
|
340
|
+
const attributes = declaration.attributes as AstNode[] | undefined;
|
|
341
|
+
if (!attributes?.length || (target.attributes as AstNode[] | undefined)?.length) {
|
|
342
|
+
continue;
|
|
343
|
+
}
|
|
344
|
+
const [first] = attributes;
|
|
345
|
+
const last = attributes.at(-1);
|
|
346
|
+
const imported = target.source as AstNode | undefined;
|
|
347
|
+
if (first && last && imported) {
|
|
348
|
+
output.appendLeft(imported.end, ` with { ${source.slice(first.start, last.end)} }`);
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
return output.toString();
|
|
352
|
+
}
|
|
353
|
+
|
|
324
354
|
function shouldSkipWorkspaceTransform(filePath: string): boolean {
|
|
325
355
|
const normalized = filePath.replace(/\\/g, "/");
|
|
326
356
|
return normalized.includes("/.furin/");
|
|
@@ -422,11 +452,15 @@ export function transformDevSource(
|
|
|
422
452
|
? rewriteRelativeImportsWithVersion(serverSource, filePath, true)
|
|
423
453
|
: serverSource;
|
|
424
454
|
const transpiler = new Bun.Transpiler({ loader });
|
|
425
|
-
const transpiled =
|
|
455
|
+
const transpiled = restoreImportAttributes(
|
|
456
|
+
sourceForTranspile,
|
|
457
|
+
transpiler.transformSync(sourceForTranspile, loader),
|
|
458
|
+
loader
|
|
459
|
+
);
|
|
426
460
|
|
|
427
461
|
let result = transpiled;
|
|
428
462
|
if (options.rewriteBareImports) {
|
|
429
|
-
result = rewriteBareImports(
|
|
463
|
+
result = rewriteBareImports(result, dirname(filePath));
|
|
430
464
|
}
|
|
431
465
|
|
|
432
466
|
result = rewriteSingletonImports(result);
|
package/src/server/internal.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { AnyElysia } from "elysia";
|
|
2
|
+
import type { ClientPreloadManifest } from "../build/preload-manifest.ts";
|
|
2
3
|
import type { SsgCacheEntry } from "./cache/index.ts";
|
|
3
4
|
import {
|
|
4
5
|
hasPendingISRRevalidations as hasPendingISR,
|
|
@@ -44,6 +45,8 @@ export interface CompileContext {
|
|
|
44
45
|
nativeRoutes?: AnyElysia;
|
|
45
46
|
/** Mount prefix this app was built for (`""` = root). */
|
|
46
47
|
prefix?: string;
|
|
48
|
+
/** Chunk URLs to modulepreload, produced by the client build. */
|
|
49
|
+
preloadManifest?: ClientPreloadManifest;
|
|
47
50
|
/** Root-level conventions discovered at compile time. */
|
|
48
51
|
rootConventions?: { errorPath?: string; notFoundPath?: string };
|
|
49
52
|
rootPath: string;
|
|
@@ -4,8 +4,11 @@ import {
|
|
|
4
4
|
DocumentProvider,
|
|
5
5
|
type DocumentState,
|
|
6
6
|
} from "../../client/document.tsx";
|
|
7
|
+
import { QueryStoreContext } from "../../client/query.tsx";
|
|
8
|
+
import { QueryStore } from "../../client/query-store.ts";
|
|
7
9
|
import type { HeadOptions } from "../../client.ts";
|
|
8
10
|
import { containsRscSource, serializeRouteFrames } from "../../shared/route-frame.ts";
|
|
11
|
+
import type { QuerySeed } from "../../shared/sync-query.ts";
|
|
9
12
|
import { currentInstance } from "../instance.ts";
|
|
10
13
|
import { getSyncPath } from "../sync/config.ts";
|
|
11
14
|
import { safeJson } from "./shell.ts";
|
|
@@ -38,5 +41,11 @@ export function withDocumentState(
|
|
|
38
41
|
routeFrames,
|
|
39
42
|
syncJson: syncPath === undefined ? undefined : safeJson({ path: syncPath }),
|
|
40
43
|
};
|
|
41
|
-
|
|
44
|
+
const queries = new QueryStore(undefined);
|
|
45
|
+
queries.hydrate((data as { __furinQueries?: QuerySeed[] } | undefined)?.__furinQueries ?? []);
|
|
46
|
+
return createElement(
|
|
47
|
+
DocumentProvider,
|
|
48
|
+
{ value: state },
|
|
49
|
+
createElement(QueryStoreContext.Provider, { value: queries }, element)
|
|
50
|
+
);
|
|
42
51
|
}
|
|
@@ -2,8 +2,10 @@ import { createElement, type ElementType, type ReactNode } from "react";
|
|
|
2
2
|
import { wrapSegmentBoundaries } from "../../client/boundaries.tsx";
|
|
3
3
|
import { DefaultErrorFallback, DefaultNotFoundFallback } from "../../client/default-screens.tsx";
|
|
4
4
|
import type { RuntimeRoute } from "../../client/internal/runtime-types.ts";
|
|
5
|
+
import { withRouteSnapshot } from "../../client/route-api.tsx";
|
|
5
6
|
import type { ErrorComponent } from "../../shared/error.ts";
|
|
6
7
|
import type { FurinNotFoundError, NotFoundComponent } from "../../shared/not-found.ts";
|
|
8
|
+
import { pageKey } from "../../shared/page-key.ts";
|
|
7
9
|
import type { ResolvedRoute, SegmentBoundary } from "../router/types.ts";
|
|
8
10
|
import { IS_DEV } from "../runtime-env.ts";
|
|
9
11
|
|
|
@@ -13,24 +15,30 @@ export function buildElement(
|
|
|
13
15
|
rootLayout: RuntimeRoute
|
|
14
16
|
): ReactNode {
|
|
15
17
|
const Component = route.page.component;
|
|
16
|
-
let element: ReactNode = createElement(Component,
|
|
18
|
+
let element: ReactNode = createElement(Component, {
|
|
19
|
+
...data,
|
|
20
|
+
key: pageKey(route.pattern, data, route.page._route.remountDeps),
|
|
21
|
+
});
|
|
17
22
|
|
|
18
|
-
//
|
|
19
|
-
//
|
|
20
|
-
|
|
21
|
-
const byDepth = new Map<number, SegmentBoundary>();
|
|
23
|
+
// Directories without layouts share their enclosing layout's chain index.
|
|
24
|
+
// Keep their boundaries in inside-out order instead of overwriting them.
|
|
25
|
+
const byDepth = new Map<number, SegmentBoundary[]>();
|
|
22
26
|
const legacyRoute = route as ResolvedRoute & {
|
|
23
27
|
segmentBoundaries?: SegmentBoundary[];
|
|
24
28
|
};
|
|
25
29
|
for (const segment of legacyRoute.segmentBoundaries ?? []) {
|
|
26
|
-
byDepth.
|
|
30
|
+
const boundaries = byDepth.get(segment.depth) ?? [];
|
|
31
|
+
boundaries.unshift(segment);
|
|
32
|
+
byDepth.set(segment.depth, boundaries);
|
|
27
33
|
}
|
|
28
34
|
|
|
29
35
|
// Build inside-out. At each level we first wrap the accumulated subtree
|
|
30
36
|
// with the boundary declared at this depth (so the boundary sits INSIDE
|
|
31
37
|
// the layout at the same depth), THEN wrap with the layout itself.
|
|
32
38
|
for (let i = route.routeChain.length - 1; i >= 1; i -= 1) {
|
|
33
|
-
|
|
39
|
+
for (const segment of byDepth.get(i) ?? []) {
|
|
40
|
+
element = wrapSegmentBoundaries(element, segment, undefined);
|
|
41
|
+
}
|
|
34
42
|
const routeEntry = route.routeChain[i];
|
|
35
43
|
if (routeEntry?.layout) {
|
|
36
44
|
const Layout = routeEntry.layout;
|
|
@@ -38,16 +46,18 @@ export function buildElement(
|
|
|
38
46
|
}
|
|
39
47
|
}
|
|
40
48
|
|
|
41
|
-
//
|
|
42
|
-
//
|
|
43
|
-
|
|
49
|
+
// Index-0 boundaries wrap everything below the root layout, including
|
|
50
|
+
// pathless directories without their own layouts.
|
|
51
|
+
for (const segment of byDepth.get(0) ?? []) {
|
|
52
|
+
element = wrapSegmentBoundaries(element, segment, undefined);
|
|
53
|
+
}
|
|
44
54
|
|
|
45
55
|
if (rootLayout.layout) {
|
|
46
56
|
const RootLayoutComponent = rootLayout.layout;
|
|
47
57
|
element = createElement(RootLayoutComponent as ElementType, data, element);
|
|
48
58
|
}
|
|
49
59
|
|
|
50
|
-
return element;
|
|
60
|
+
return withRouteSnapshot(element, route.pattern, data);
|
|
51
61
|
}
|
|
52
62
|
|
|
53
63
|
export function wrapRootLayout(
|