@teyik0/furin 0.9.0-alpha.2 → 0.9.0-alpha.4
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/build/index.js +46 -58
- package/dist/cli/index.js +46 -58
- package/dist/client/chunks/{client-d9v49jwz.js → client-p0jqzfvc.js} +65 -2
- package/dist/client/dev-error-overlay.ts +18 -0
- package/dist/client/link.js +1 -1
- package/dist/client/query.d.ts +13 -0
- package/dist/client.d.ts +1 -1
- package/dist/client.js +3 -1
- package/dist/furin.js +9 -16
- package/dist/plugin/client-plugin.d.ts +1 -1
- package/dist/plugin/index.js +5 -4
- package/dist/server/dev/graph.d.ts +0 -1
- package/dist/server/internal.js +4 -7
- package/dist/server/router/hmr.d.ts +0 -1
- package/dist/server/router/source-version.d.ts +0 -1
- package/dist/server/static-export.js +4 -7
- package/dist/server/sync/index.js +1 -1
- package/dist/sync-client.js +1 -1
- package/package.json +2 -2
- package/src/build/hydrate.ts +2 -0
- package/src/client/dev-error-overlay.ts +18 -0
- package/src/client/query-store.ts +2 -1
- package/src/client/query.tsx +87 -0
- package/src/client.ts +1 -1
- package/src/plugin/client-plugin.ts +13 -8
- package/src/plugin/route-registry.ts +4 -21
- package/src/server/dev/graph.ts +2 -7
- package/src/server/dev/runtime.ts +1 -2
- package/src/server/dev-page-plugin.ts +5 -2
- package/src/server/router/hmr.ts +1 -5
- package/src/server/router/source-version.ts +3 -6
|
@@ -9,7 +9,7 @@ interface ClientStripPluginOptions {
|
|
|
9
9
|
/**
|
|
10
10
|
* Furin's browser-graph plugin, shared by the dev server (bunfig
|
|
11
11
|
* `[serve.static] plugins`) and the production client build:
|
|
12
|
-
* 1. Stubs `elysia` for the browser with
|
|
12
|
+
* 1. Stubs `elysia` for the browser with its schema builder only.
|
|
13
13
|
* 2. Stubs `bun:*` builtins with an empty module (safety net — DCE removes
|
|
14
14
|
* loader imports before they reach the browser bundle in practice).
|
|
15
15
|
* 3. Strips server-only code (loader, query, params) from page files before
|
package/dist/plugin/index.js
CHANGED
|
@@ -4302,11 +4302,12 @@ function stripServerCode(path, source) {
|
|
|
4302
4302
|
var ELYSIA_FILTER = /^elysia$/;
|
|
4303
4303
|
var BUN_BUILTIN_FILTER = /^bun:/;
|
|
4304
4304
|
var ANY_FILTER = /.*/;
|
|
4305
|
-
var
|
|
4305
|
+
var elysiaStub = (typeModule) => `export * as t from ${JSON.stringify(typeModule)};
|
|
4306
4306
|
export class NotFoundError extends Error { constructor(m) { super(m); this.name = "NotFoundError"; } }
|
|
4307
4307
|
export class ValidationError extends Error { constructor(m) { super(m); this.name = "ValidationError"; } }
|
|
4308
4308
|
export default {};
|
|
4309
4309
|
`;
|
|
4310
|
+
var ELYSIA_STUB_PREFIX = "elysia-stub:";
|
|
4310
4311
|
function trackHydrationTopology(filePath, source, topologyPaths) {
|
|
4311
4312
|
const normalizedPath = filePath.replaceAll("\\", "/");
|
|
4312
4313
|
if (!(normalizedPath.includes("/.furin/") && normalizedPath.endsWith("/_hydrate.tsx"))) {
|
|
@@ -4344,16 +4345,16 @@ function createClientStripPlugin({ mode }) {
|
|
|
4344
4345
|
environmentGuardPlugin("client").setup(build);
|
|
4345
4346
|
const topologyPaths = new Set;
|
|
4346
4347
|
const loadedSources = new Map;
|
|
4347
|
-
build.onResolve({ filter: ELYSIA_FILTER }, () => ({
|
|
4348
|
+
build.onResolve({ filter: ELYSIA_FILTER }, (args) => ({
|
|
4348
4349
|
namespace: "furin-stubs",
|
|
4349
|
-
path: "elysia
|
|
4350
|
+
path: ELYSIA_STUB_PREFIX + Bun.resolveSync("elysia/type", args.resolveDir)
|
|
4350
4351
|
}));
|
|
4351
4352
|
build.onResolve({ filter: BUN_BUILTIN_FILTER }, () => ({
|
|
4352
4353
|
namespace: "furin-stubs",
|
|
4353
4354
|
path: "bun-builtin-stub"
|
|
4354
4355
|
}));
|
|
4355
4356
|
build.onLoad({ filter: ANY_FILTER, namespace: "furin-stubs" }, (args) => ({
|
|
4356
|
-
contents: args.path
|
|
4357
|
+
contents: args.path.startsWith(ELYSIA_STUB_PREFIX) ? elysiaStub(args.path.slice(ELYSIA_STUB_PREFIX.length)) : "",
|
|
4357
4358
|
loader: "js"
|
|
4358
4359
|
}));
|
|
4359
4360
|
build.onLoad({ filter: SCRIPT_FILE_FILTER }, async (args) => {
|
|
@@ -74,7 +74,6 @@ export declare class DevGraph<Snapshot> {
|
|
|
74
74
|
recordImports(importer: string, imports: string[]): void;
|
|
75
75
|
recordSourceError(message: string, position: DevSourcePosition): void;
|
|
76
76
|
sourceError(message: string, entryPath: string): DevSourcePosition | undefined;
|
|
77
|
-
invalidateModules(): void;
|
|
78
77
|
sourceVersion(path: string): string;
|
|
79
78
|
state<Value>(key: symbol, initialize: () => Value): Value;
|
|
80
79
|
subscribe(after: number, serverId: string | undefined, listener: (event: DevGraphEvent) => void): {
|
package/dist/server/internal.js
CHANGED
|
@@ -3363,7 +3363,6 @@ class DevGraph {
|
|
|
3363
3363
|
#eventSequence = 0;
|
|
3364
3364
|
#revision = 0;
|
|
3365
3365
|
#snapshot;
|
|
3366
|
-
#sourceGeneration = 0;
|
|
3367
3366
|
constructor(initialSnapshot) {
|
|
3368
3367
|
this.#snapshot = initialSnapshot;
|
|
3369
3368
|
}
|
|
@@ -3566,9 +3565,6 @@ class DevGraph {
|
|
|
3566
3565
|
}
|
|
3567
3566
|
}
|
|
3568
3567
|
}
|
|
3569
|
-
invalidateModules() {
|
|
3570
|
-
this.#sourceGeneration += 1;
|
|
3571
|
-
}
|
|
3572
3568
|
sourceVersion(path) {
|
|
3573
3569
|
const modulePath = normalizeModulePath(path);
|
|
3574
3570
|
const fingerprint = this.#sourceFingerprint(modulePath, new Set);
|
|
@@ -3588,9 +3584,9 @@ class DevGraph {
|
|
|
3588
3584
|
let ownFingerprint;
|
|
3589
3585
|
try {
|
|
3590
3586
|
const stats = statSync(path, { bigint: true });
|
|
3591
|
-
ownFingerprint = `${stats.mtimeNs}:${stats.size}
|
|
3587
|
+
ownFingerprint = `${stats.mtimeNs}:${stats.size}`;
|
|
3592
3588
|
} catch {
|
|
3593
|
-
ownFingerprint =
|
|
3589
|
+
ownFingerprint = "missing";
|
|
3594
3590
|
}
|
|
3595
3591
|
const dependencies = [...this.#dependencies.get(path) ?? []].toSorted((left, right) => left.localeCompare(right)).map((dependency) => this.#sourceFingerprint(dependency, visited));
|
|
3596
3592
|
return `${path}:${ownFingerprint}:${dependencies.join(",")}`;
|
|
@@ -4787,10 +4783,10 @@ class QueryStore {
|
|
|
4787
4783
|
}
|
|
4788
4784
|
}
|
|
4789
4785
|
entry.snapshot = { ...entry.snapshot, data };
|
|
4786
|
+
this.revisionValue += 1;
|
|
4790
4787
|
for (const listener of entry.listeners) {
|
|
4791
4788
|
listener();
|
|
4792
4789
|
}
|
|
4793
|
-
this.revisionValue += 1;
|
|
4794
4790
|
for (const listener of this.listeners) {
|
|
4795
4791
|
listener();
|
|
4796
4792
|
}
|
|
@@ -6142,6 +6138,7 @@ import {
|
|
|
6142
6138
|
useCallback,
|
|
6143
6139
|
useContext as useContext2,
|
|
6144
6140
|
useEffect,
|
|
6141
|
+
useState,
|
|
6145
6142
|
useSyncExternalStore
|
|
6146
6143
|
} from "react";
|
|
6147
6144
|
var QUERY_CONTEXT2 = Symbol.for("furin.query.context.v1");
|
|
@@ -11,7 +11,6 @@ type RouteModuleImport = (specifier: string) => Promise<CompiledModule>;
|
|
|
11
11
|
* requests for the same edited version.
|
|
12
12
|
*/
|
|
13
13
|
export declare function importStampedRouteModule(path: string, resolveImport: RouteModuleImport): Promise<CompiledModule>;
|
|
14
|
-
export declare function invalidateStampedRouteModules(): void;
|
|
15
14
|
/**
|
|
16
15
|
* Re-imports the page's layouts (`layoutPaths`, shallow → deep, as the route
|
|
17
16
|
* manifest lists them) with a versioned module identity, then patches the
|
|
@@ -3355,7 +3355,6 @@ class DevGraph {
|
|
|
3355
3355
|
#eventSequence = 0;
|
|
3356
3356
|
#revision = 0;
|
|
3357
3357
|
#snapshot;
|
|
3358
|
-
#sourceGeneration = 0;
|
|
3359
3358
|
constructor(initialSnapshot) {
|
|
3360
3359
|
this.#snapshot = initialSnapshot;
|
|
3361
3360
|
}
|
|
@@ -3558,9 +3557,6 @@ class DevGraph {
|
|
|
3558
3557
|
}
|
|
3559
3558
|
}
|
|
3560
3559
|
}
|
|
3561
|
-
invalidateModules() {
|
|
3562
|
-
this.#sourceGeneration += 1;
|
|
3563
|
-
}
|
|
3564
3560
|
sourceVersion(path) {
|
|
3565
3561
|
const modulePath = normalizeModulePath(path);
|
|
3566
3562
|
const fingerprint = this.#sourceFingerprint(modulePath, new Set);
|
|
@@ -3580,9 +3576,9 @@ class DevGraph {
|
|
|
3580
3576
|
let ownFingerprint;
|
|
3581
3577
|
try {
|
|
3582
3578
|
const stats = statSync(path, { bigint: true });
|
|
3583
|
-
ownFingerprint = `${stats.mtimeNs}:${stats.size}
|
|
3579
|
+
ownFingerprint = `${stats.mtimeNs}:${stats.size}`;
|
|
3584
3580
|
} catch {
|
|
3585
|
-
ownFingerprint =
|
|
3581
|
+
ownFingerprint = "missing";
|
|
3586
3582
|
}
|
|
3587
3583
|
const dependencies = [...this.#dependencies.get(path) ?? []].toSorted((left, right) => left.localeCompare(right)).map((dependency) => this.#sourceFingerprint(dependency, visited));
|
|
3588
3584
|
return `${path}:${ownFingerprint}:${dependencies.join(",")}`;
|
|
@@ -4617,10 +4613,10 @@ class QueryStore {
|
|
|
4617
4613
|
}
|
|
4618
4614
|
}
|
|
4619
4615
|
entry.snapshot = { ...entry.snapshot, data };
|
|
4616
|
+
this.revisionValue += 1;
|
|
4620
4617
|
for (const listener of entry.listeners) {
|
|
4621
4618
|
listener();
|
|
4622
4619
|
}
|
|
4623
|
-
this.revisionValue += 1;
|
|
4624
4620
|
for (const listener of this.listeners) {
|
|
4625
4621
|
listener();
|
|
4626
4622
|
}
|
|
@@ -5948,6 +5944,7 @@ import {
|
|
|
5948
5944
|
useCallback,
|
|
5949
5945
|
useContext as useContext2,
|
|
5950
5946
|
useEffect,
|
|
5947
|
+
useState,
|
|
5951
5948
|
useSyncExternalStore
|
|
5952
5949
|
} from "react";
|
|
5953
5950
|
var QUERY_CONTEXT2 = Symbol.for("furin.query.context.v1");
|
|
@@ -3777,10 +3777,10 @@ class QueryStore {
|
|
|
3777
3777
|
}
|
|
3778
3778
|
}
|
|
3779
3779
|
entry.snapshot = { ...entry.snapshot, data };
|
|
3780
|
+
this.revisionValue += 1;
|
|
3780
3781
|
for (const listener of entry.listeners) {
|
|
3781
3782
|
listener();
|
|
3782
3783
|
}
|
|
3783
|
-
this.revisionValue += 1;
|
|
3784
3784
|
for (const listener of this.listeners) {
|
|
3785
3785
|
listener();
|
|
3786
3786
|
}
|
package/dist/sync-client.js
CHANGED
|
@@ -602,10 +602,10 @@ class QueryStore {
|
|
|
602
602
|
}
|
|
603
603
|
}
|
|
604
604
|
entry.snapshot = { ...entry.snapshot, data };
|
|
605
|
+
this.revisionValue += 1;
|
|
605
606
|
for (const listener of entry.listeners) {
|
|
606
607
|
listener();
|
|
607
608
|
}
|
|
608
|
-
this.revisionValue += 1;
|
|
609
609
|
for (const listener of this.listeners) {
|
|
610
610
|
listener();
|
|
611
611
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@teyik0/furin",
|
|
3
|
-
"version": "0.9.0-alpha.
|
|
3
|
+
"version": "0.9.0-alpha.4",
|
|
4
4
|
"description": "React meta-framework powered by Elysia and Bun with file-based routing, SSR, SSG, and ISR.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -173,7 +173,7 @@
|
|
|
173
173
|
"test:dev": "bun run generate:sync-prisma && bun test --changed --parallel --isolate --max-concurrency 4 --bail --timeout 15000",
|
|
174
174
|
"test:hmr:soak": "FURIN_WEBVIEW_TESTS=1 FURIN_HMR_SOAK_TESTS=1 bun test tests/browser/hmr-conformance.webview.test.ts -t 'tracks memory' --timeout 3600000",
|
|
175
175
|
"test:webview": "FURIN_WEBVIEW_TESTS=1 bun test tests/browser --timeout 60000",
|
|
176
|
-
"tscheck": "bun run generate:sync-prisma &&
|
|
176
|
+
"tscheck": "bun run generate:sync-prisma && bun check"
|
|
177
177
|
},
|
|
178
178
|
"dependencies": {
|
|
179
179
|
"@elysia/eden": "^2.0.0-rc.1",
|
package/src/build/hydrate.ts
CHANGED
|
@@ -419,6 +419,7 @@ if (__deferred && __deferred._chunks) {
|
|
|
419
419
|
// with the server (stale deploy) or the server returned something we
|
|
420
420
|
// don't know how to hydrate. Bail loudly; the page stays static.
|
|
421
421
|
log.error({ action: "hydrate_no_match", pathname });
|
|
422
|
+
if (import.meta.hot) throw new Error(\`[furin] No client route matches \${pathname}; the page stays static.\`);
|
|
422
423
|
return;
|
|
423
424
|
}
|
|
424
425
|
app = createElement(DocumentProvider, { value: documentState }, app);
|
|
@@ -485,6 +486,7 @@ if (__deferred && __deferred._chunks) {
|
|
|
485
486
|
log.info({ action: "hydrate_complete", pathname });
|
|
486
487
|
})().catch((err: unknown) => {
|
|
487
488
|
log.error({ action: "hydrate_failed", pathname, error: String(err) });
|
|
489
|
+
if (import.meta.hot) console.error("[furin] Hydration failed:", err);
|
|
488
490
|
window.dispatchEvent(
|
|
489
491
|
new CustomEvent("furin:client-error", { detail: { error: err, phase: "hydrate" } })
|
|
490
492
|
);
|
|
@@ -186,6 +186,24 @@ window.addEventListener("furin:client-error", (event) => {
|
|
|
186
186
|
reportClientError(detail).catch(() => undefined);
|
|
187
187
|
});
|
|
188
188
|
|
|
189
|
+
// A module evaluation error (a bundle SyntaxError, a top-level throw in an
|
|
190
|
+
// imported module) stops the hydrate entry before its catch exists. The dev
|
|
191
|
+
// bundle holds the entry's static graph, so report errors from that script
|
|
192
|
+
// until the entry mounts its root; afterwards React boundaries and Bun HMR
|
|
193
|
+
// own runtime errors.
|
|
194
|
+
window.addEventListener("error", (event) => {
|
|
195
|
+
if ((window as { __FURIN_ROOT__?: unknown }).__FURIN_ROOT__ !== undefined) {
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
const entry = document.querySelector<HTMLScriptElement>("script[data-furin-entry][src]");
|
|
199
|
+
if (!entry || event.filename !== entry.src) {
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
reportClientError({ error: event.error ?? event.message, phase: "hydrate" }).catch(
|
|
203
|
+
() => undefined
|
|
204
|
+
);
|
|
205
|
+
});
|
|
206
|
+
|
|
189
207
|
// Retry only failures from before this update, including when reporting is still
|
|
190
208
|
// in flight or server readiness has already dismissed the overlay.
|
|
191
209
|
window.addEventListener("furin:hmr-before-update", () => {
|
|
@@ -243,10 +243,11 @@ export class QueryStore {
|
|
|
243
243
|
}
|
|
244
244
|
}
|
|
245
245
|
entry.snapshot = { ...entry.snapshot, data };
|
|
246
|
+
// Before any listener: a listener reading `revision()` must see this publish.
|
|
247
|
+
this.revisionValue += 1;
|
|
246
248
|
for (const listener of entry.listeners) {
|
|
247
249
|
listener();
|
|
248
250
|
}
|
|
249
|
-
this.revisionValue += 1;
|
|
250
251
|
for (const listener of this.listeners) {
|
|
251
252
|
listener();
|
|
252
253
|
}
|
package/src/client/query.tsx
CHANGED
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
useCallback,
|
|
5
5
|
useContext,
|
|
6
6
|
useEffect,
|
|
7
|
+
useState,
|
|
7
8
|
useSyncExternalStore,
|
|
8
9
|
} from "react";
|
|
9
10
|
import { LIVE_QUERY, type LiveQuery, type QueryStore, type ReadResult } from "./query-store.ts";
|
|
@@ -48,3 +49,89 @@ export function useQuery<Result extends ReadResult, Selected = LiveData<Result>>
|
|
|
48
49
|
isFetching: state.isFetching,
|
|
49
50
|
};
|
|
50
51
|
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Pages are ordinary store entries keyed by their URL: invalidation refetches every loaded page.
|
|
55
|
+
* The hook owns only how many pages are shown; a new first page (changed filters) restarts at one.
|
|
56
|
+
*/
|
|
57
|
+
export function useInfiniteQuery<Result extends ReadResult>(
|
|
58
|
+
page: (index: number) => LiveQuery<Result>,
|
|
59
|
+
options: { next: (last: LiveData<Result>) => boolean }
|
|
60
|
+
): {
|
|
61
|
+
error: Result["error"] | null;
|
|
62
|
+
fetchNext: () => void;
|
|
63
|
+
hasNext: boolean;
|
|
64
|
+
isFetching: boolean;
|
|
65
|
+
pages: LiveData<Result>[];
|
|
66
|
+
} {
|
|
67
|
+
const first = page(0)[LIVE_QUERY];
|
|
68
|
+
const context = useContext(QueryStoreContext);
|
|
69
|
+
const store = context ?? first.reference.client;
|
|
70
|
+
const firstUrl = store.readKey(first.reference, first.options);
|
|
71
|
+
const [loaded, setLoaded] = useState({ count: 1, firstUrl });
|
|
72
|
+
if (loaded.firstUrl !== firstUrl) {
|
|
73
|
+
setLoaded({ count: 1, firstUrl });
|
|
74
|
+
}
|
|
75
|
+
const count = loaded.firstUrl === firstUrl ? loaded.count : 1;
|
|
76
|
+
const urls = Array.from({ length: count }, (_, index) => {
|
|
77
|
+
const { options: readOptions, reference } = page(index)[LIVE_QUERY];
|
|
78
|
+
const url = store.readKey(reference, readOptions);
|
|
79
|
+
store.bind(url, () => reference.load(readOptions), reference.client);
|
|
80
|
+
return url;
|
|
81
|
+
});
|
|
82
|
+
// Encoded URLs never contain a newline: one stable string stands for the page list.
|
|
83
|
+
const key = urls.join("\n");
|
|
84
|
+
const subscribe = useCallback(
|
|
85
|
+
(listener: () => void) => {
|
|
86
|
+
const unsubscribes = key.split("\n").map((url) => store.subscribe(url, listener));
|
|
87
|
+
return () => {
|
|
88
|
+
for (const unsubscribe of unsubscribes) {
|
|
89
|
+
unsubscribe();
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
},
|
|
93
|
+
[store, key]
|
|
94
|
+
);
|
|
95
|
+
// The store revision changes on every publish, so it versions all pages at once.
|
|
96
|
+
useSyncExternalStore(subscribe, store.revision, store.revision);
|
|
97
|
+
useEffect(() => {
|
|
98
|
+
for (const url of key.split("\n")) {
|
|
99
|
+
store.fetch(url);
|
|
100
|
+
}
|
|
101
|
+
}, [store, key]);
|
|
102
|
+
const snapshots = urls.map((url) => store.snapshot(url));
|
|
103
|
+
const pages: LiveData<Result>[] = [];
|
|
104
|
+
for (const entry of snapshots) {
|
|
105
|
+
if (entry.data === undefined) {
|
|
106
|
+
break;
|
|
107
|
+
}
|
|
108
|
+
pages.push(entry.data as LiveData<Result>);
|
|
109
|
+
}
|
|
110
|
+
const last = pages.at(-1);
|
|
111
|
+
const hasNext = pages.length === count && last !== undefined && options.next(last);
|
|
112
|
+
const fetchNext = () => {
|
|
113
|
+
// A failed page stays stale in the store: retry it rather than skipping past it.
|
|
114
|
+
const failed = urls.filter((_, index) => snapshots[index]?.error !== null);
|
|
115
|
+
if (failed.length > 0) {
|
|
116
|
+
for (const url of failed) {
|
|
117
|
+
store.fetch(url);
|
|
118
|
+
}
|
|
119
|
+
} else if (hasNext) {
|
|
120
|
+
// Calls in the same render see the same `count`: only the first one adds a page.
|
|
121
|
+
setLoaded((previous) =>
|
|
122
|
+
previous.firstUrl === firstUrl && previous.count === count
|
|
123
|
+
? { count: count + 1, firstUrl }
|
|
124
|
+
: previous
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
return {
|
|
129
|
+
error: (snapshots.find((entry) => entry.error !== null)?.error ?? null) as
|
|
130
|
+
| Result["error"]
|
|
131
|
+
| null,
|
|
132
|
+
fetchNext,
|
|
133
|
+
hasNext,
|
|
134
|
+
isFetching: snapshots.some((entry) => entry.isFetching),
|
|
135
|
+
pages,
|
|
136
|
+
};
|
|
137
|
+
}
|
package/src/client.ts
CHANGED
|
@@ -22,7 +22,7 @@ export {
|
|
|
22
22
|
updateHotComponent,
|
|
23
23
|
} from "./client/hmr.ts";
|
|
24
24
|
export { useMutation } from "./client/mutation.ts";
|
|
25
|
-
export { useQuery } from "./client/query.tsx";
|
|
25
|
+
export { useInfiniteQuery, useQuery } from "./client/query.tsx";
|
|
26
26
|
export type { LiveQuery } from "./client/query-store.ts";
|
|
27
27
|
export { getRouteApi } from "./client/route-api.tsx";
|
|
28
28
|
export { furinSync, type OptimisticCache, type SyncCallOptions } from "./client/sync.ts";
|
|
@@ -8,14 +8,16 @@ const ELYSIA_FILTER = /^elysia$/;
|
|
|
8
8
|
const BUN_BUILTIN_FILTER = /^bun:/;
|
|
9
9
|
const ANY_FILTER = /.*/;
|
|
10
10
|
|
|
11
|
-
//
|
|
12
|
-
//
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
// Browser stub for elysia: the server stays out of the bundle, but `t` is
|
|
12
|
+
// Elysia's browser-safe schema builder, so a schema shared with the client
|
|
13
|
+
// is the same JSON Schema on both sides. `typeModule` is its resolved path.
|
|
14
|
+
const elysiaStub = (typeModule: string) => `\
|
|
15
|
+
export * as t from ${JSON.stringify(typeModule)};
|
|
15
16
|
export class NotFoundError extends Error { constructor(m) { super(m); this.name = "NotFoundError"; } }
|
|
16
17
|
export class ValidationError extends Error { constructor(m) { super(m); this.name = "ValidationError"; } }
|
|
17
18
|
export default {};
|
|
18
19
|
`;
|
|
20
|
+
const ELYSIA_STUB_PREFIX = "elysia-stub:";
|
|
19
21
|
|
|
20
22
|
/** Records the route modules imported by the dev `.furin/_hydrate.tsx` entry. */
|
|
21
23
|
function trackHydrationTopology(filePath: string, source: string, topologyPaths: Set<string>) {
|
|
@@ -72,7 +74,7 @@ interface ClientStripPluginOptions {
|
|
|
72
74
|
/**
|
|
73
75
|
* Furin's browser-graph plugin, shared by the dev server (bunfig
|
|
74
76
|
* `[serve.static] plugins`) and the production client build:
|
|
75
|
-
* 1. Stubs `elysia` for the browser with
|
|
77
|
+
* 1. Stubs `elysia` for the browser with its schema builder only.
|
|
76
78
|
* 2. Stubs `bun:*` builtins with an empty module (safety net — DCE removes
|
|
77
79
|
* loader imports before they reach the browser bundle in practice).
|
|
78
80
|
* 3. Strips server-only code (loader, query, params) from page files before
|
|
@@ -90,9 +92,10 @@ export function createClientStripPlugin({ mode }: ClientStripPluginOptions): Bun
|
|
|
90
92
|
{ contents: string; loader: Bun.Loader; isRouteModule: boolean }
|
|
91
93
|
>();
|
|
92
94
|
// ── browser stubs ───────────────────────────────────────────────────────
|
|
93
|
-
|
|
95
|
+
// Resolved from the importer, so it is the app's own elysia install.
|
|
96
|
+
build.onResolve({ filter: ELYSIA_FILTER }, (args) => ({
|
|
94
97
|
namespace: "furin-stubs",
|
|
95
|
-
path: "elysia
|
|
98
|
+
path: ELYSIA_STUB_PREFIX + Bun.resolveSync("elysia/type", args.resolveDir),
|
|
96
99
|
}));
|
|
97
100
|
|
|
98
101
|
build.onResolve({ filter: BUN_BUILTIN_FILTER }, () => ({
|
|
@@ -101,7 +104,9 @@ export function createClientStripPlugin({ mode }: ClientStripPluginOptions): Bun
|
|
|
101
104
|
}));
|
|
102
105
|
|
|
103
106
|
build.onLoad({ filter: ANY_FILTER, namespace: "furin-stubs" }, (args) => ({
|
|
104
|
-
contents: args.path
|
|
107
|
+
contents: args.path.startsWith(ELYSIA_STUB_PREFIX)
|
|
108
|
+
? elysiaStub(args.path.slice(ELYSIA_STUB_PREFIX.length))
|
|
109
|
+
: "",
|
|
105
110
|
loader: "js",
|
|
106
111
|
}));
|
|
107
112
|
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { detectLoaderFromPath } from "../server/lang-detect.ts";
|
|
1
|
+
import { join, resolve } from "node:path";
|
|
3
2
|
import {
|
|
4
3
|
loadRouteModule,
|
|
5
4
|
type RouteModuleInfo,
|
|
@@ -21,7 +20,6 @@ const ROUTES_REGISTRY_SPECIFIER = "furin/routes?registry";
|
|
|
21
20
|
const COMPOSABLE_ROUTES_REGISTRY_SPECIFIER = "furin/routes?registry=composable";
|
|
22
21
|
const ROUTES_REGISTRY_FILTER = /^furin\/routes\?registry(?:=composable)?$/;
|
|
23
22
|
const ROUTE_FILE_FILTER = /^furin-route-file:.+$/;
|
|
24
|
-
const ROUTE_FILES_NAMESPACE = "furin-route-files";
|
|
25
23
|
const ROUTES_REGISTRY_FILE_FILTER =
|
|
26
24
|
/[\\/]\.furin-routes-registry(?:-composable)?\.ts\?furin-virtual$/;
|
|
27
25
|
const CLIENT_ROUTES_NAMESPACE = "furin-routes-client";
|
|
@@ -246,7 +244,6 @@ function serverProxySource(instance: RouteInstanceSpec, includeRootCatchAll: boo
|
|
|
246
244
|
|
|
247
245
|
export function createRoutesPlugin(options: CreateRoutesPluginOptions): Bun.BunPlugin {
|
|
248
246
|
const routeFilesBySpecifier = new Map<string, RouteModuleInfo>();
|
|
249
|
-
const routeFilesByResolvedPath = new Map<string, RouteModuleInfo>();
|
|
250
247
|
const registryVirtualPath = join(
|
|
251
248
|
resolve(primaryInstance(options.instances).pagesDir),
|
|
252
249
|
".furin-routes-registry.ts?furin-virtual"
|
|
@@ -314,29 +311,15 @@ export function createRoutesPlugin(options: CreateRoutesPluginOptions): Bun.BunP
|
|
|
314
311
|
}
|
|
315
312
|
return { contents, loader: "ts" };
|
|
316
313
|
});
|
|
314
|
+
// Route files resolve to their real path so the file-namespace server
|
|
315
|
+
// transforms apply and the bundle keeps one copy of each route module.
|
|
317
316
|
build.onResolve({ filter: ROUTE_FILE_FILTER }, ({ path }) => {
|
|
318
317
|
const routeFile = routeFilesBySpecifier.get(path);
|
|
319
318
|
if (!routeFile) {
|
|
320
319
|
throw new Error(`[furin] Unknown route module: ${path}`);
|
|
321
320
|
}
|
|
322
|
-
|
|
323
|
-
routeFilesByResolvedPath.set(resolvedPath, routeFile);
|
|
324
|
-
return { namespace: ROUTE_FILES_NAMESPACE, path: resolvedPath };
|
|
321
|
+
return { path: routeFile.sourcePath };
|
|
325
322
|
});
|
|
326
|
-
build.onLoad(
|
|
327
|
-
{ filter: VIRTUAL_ROUTES_FILTER, namespace: ROUTE_FILES_NAMESPACE },
|
|
328
|
-
async ({ path }) => {
|
|
329
|
-
const routeFile = routeFilesByResolvedPath.get(path);
|
|
330
|
-
if (!routeFile) {
|
|
331
|
-
throw new Error(`[furin] Unknown route module: ${path}`);
|
|
332
|
-
}
|
|
333
|
-
return {
|
|
334
|
-
contents: await Bun.file(routeFile.sourcePath).text(),
|
|
335
|
-
loader: detectLoaderFromPath(routeFile.sourcePath),
|
|
336
|
-
resolveDir: dirname(routeFile.sourcePath),
|
|
337
|
-
};
|
|
338
|
-
}
|
|
339
|
-
);
|
|
340
323
|
for (const { instance, namespace, includeRootCatchAll } of instancesBySpecifier.values()) {
|
|
341
324
|
build.onLoad({ filter: VIRTUAL_ROUTES_FILTER, namespace }, () => ({
|
|
342
325
|
contents: serverProxySource(instance, includeRootCatchAll),
|
package/src/server/dev/graph.ts
CHANGED
|
@@ -139,7 +139,6 @@ export class DevGraph<Snapshot> {
|
|
|
139
139
|
#eventSequence = 0;
|
|
140
140
|
#revision = 0;
|
|
141
141
|
#snapshot: Snapshot;
|
|
142
|
-
#sourceGeneration = 0;
|
|
143
142
|
|
|
144
143
|
constructor(initialSnapshot: Snapshot) {
|
|
145
144
|
this.#snapshot = initialSnapshot;
|
|
@@ -373,10 +372,6 @@ export class DevGraph<Snapshot> {
|
|
|
373
372
|
}
|
|
374
373
|
}
|
|
375
374
|
|
|
376
|
-
invalidateModules(): void {
|
|
377
|
-
this.#sourceGeneration += 1;
|
|
378
|
-
}
|
|
379
|
-
|
|
380
375
|
sourceVersion(path: string): string {
|
|
381
376
|
const modulePath = normalizeModulePath(path);
|
|
382
377
|
const fingerprint = this.#sourceFingerprint(modulePath, new Set());
|
|
@@ -397,9 +392,9 @@ export class DevGraph<Snapshot> {
|
|
|
397
392
|
let ownFingerprint: string;
|
|
398
393
|
try {
|
|
399
394
|
const stats = statSync(path, { bigint: true });
|
|
400
|
-
ownFingerprint = `${stats.mtimeNs}:${stats.size}
|
|
395
|
+
ownFingerprint = `${stats.mtimeNs}:${stats.size}`;
|
|
401
396
|
} catch {
|
|
402
|
-
ownFingerprint =
|
|
397
|
+
ownFingerprint = "missing";
|
|
403
398
|
}
|
|
404
399
|
const dependencies = [...(this.#dependencies.get(path) ?? [])]
|
|
405
400
|
.toSorted((left, right) => left.localeCompare(right))
|
|
@@ -9,7 +9,7 @@ import { createInstrumentationPlugin } from "../devtools/instrumentation.ts";
|
|
|
9
9
|
import { type FurinInstance, withInstance } from "../instance.ts";
|
|
10
10
|
import type { ModeOptions, ModeRuntime } from "../mode.ts";
|
|
11
11
|
import { bindRuntimeRoutes, createRouteRenderer } from "../router/dispatch.ts";
|
|
12
|
-
import { developmentPagePorts
|
|
12
|
+
import { developmentPagePorts } from "../router/hmr.ts";
|
|
13
13
|
import { buildRouteMatcher } from "../router/patterns.ts";
|
|
14
14
|
import { createSearchRouteMetadata } from "../router/schemas.ts";
|
|
15
15
|
import type { ResolvedRoute, RootLayout } from "../router/types.ts";
|
|
@@ -269,7 +269,6 @@ export async function createDevRuntime(
|
|
|
269
269
|
const hmrEntry = (await import(join(furinDir, "index.html"))).default;
|
|
270
270
|
const refreshDevelopmentRoutes = (changedSources: readonly string[]): Promise<void> =>
|
|
271
271
|
withInstance(instance, async () => {
|
|
272
|
-
invalidateStampedRouteModules();
|
|
273
272
|
try {
|
|
274
273
|
const previousSnapshot = currentSnapshot();
|
|
275
274
|
const repaired = repairedDevelopmentRoutes(previousSnapshot, changedSources, graph);
|
|
@@ -179,12 +179,15 @@ export function transformDevSource(
|
|
|
179
179
|
for (const graph of developmentGraphs()) {
|
|
180
180
|
graph.clearSourceErrors(filePath);
|
|
181
181
|
}
|
|
182
|
+
// The parsers reject a shebang (e.g. a workspace package's CLI entry). An imported module
|
|
183
|
+
// never needs one: keep it as a same-length comment so every offset and line stays put.
|
|
184
|
+
const source = raw.startsWith("#!") ? `//${raw.slice(2)}` : raw;
|
|
182
185
|
try {
|
|
183
186
|
if (!options.renderFragment) {
|
|
184
|
-
recordDevImports(
|
|
187
|
+
recordDevImports(source, filePath);
|
|
185
188
|
}
|
|
186
189
|
// CSS belongs to Bun's browser graph; importing it here also registers it with --hot.
|
|
187
|
-
const server = parseModule(
|
|
190
|
+
const server = parseModule(source, filePath);
|
|
188
191
|
for (const statement of server.program.body) {
|
|
189
192
|
if (
|
|
190
193
|
statement.type === "ImportDeclaration" &&
|
package/src/server/router/hmr.ts
CHANGED
|
@@ -38,7 +38,7 @@ import {
|
|
|
38
38
|
import type { CurrentRoute, PagePorts } from "./dispatch.ts";
|
|
39
39
|
import { resolveMode, resolveRouteRevalidate } from "./patterns.ts";
|
|
40
40
|
import { createRouteDataErrorResponse, isPprRoute } from "./plugin.ts";
|
|
41
|
-
import {
|
|
41
|
+
import { routeModuleSourceVersion } from "./source-version.ts";
|
|
42
42
|
import type { ResolvedRoute, RootLayout } from "./types.ts";
|
|
43
43
|
|
|
44
44
|
type RouteModuleImport = (specifier: string) => Promise<CompiledModule>;
|
|
@@ -152,10 +152,6 @@ export function importStampedRouteModule(
|
|
|
152
152
|
return devGraph(undefined).importModule(path, stamp, resolveImport);
|
|
153
153
|
}
|
|
154
154
|
|
|
155
|
-
export function invalidateStampedRouteModules(): void {
|
|
156
|
-
invalidateRouteModuleSourceVersions();
|
|
157
|
-
}
|
|
158
|
-
|
|
159
155
|
function isResolvedRouteModuleCandidate(
|
|
160
156
|
layoutPath: string,
|
|
161
157
|
imported: CompiledModule,
|
|
@@ -3,8 +3,9 @@ import { defaultInstanceBucket, scopedInstance } from "../instance.ts";
|
|
|
3
3
|
|
|
4
4
|
export function routeModuleSourceVersion(path: string): string {
|
|
5
5
|
// Bun's runtime plugin loads modules outside any runtime scope. Use the
|
|
6
|
-
// graphs whose routes depend on this source (or that have no snapshot yet)
|
|
7
|
-
//
|
|
6
|
+
// graphs whose routes depend on this source (or that have no snapshot yet).
|
|
7
|
+
// A version only advances when the source or a recorded dependency changes,
|
|
8
|
+
// so an unchanged module keeps one ESM identity for every importer.
|
|
8
9
|
const current = devGraph(scopedInstance() ?? defaultInstanceBucket());
|
|
9
10
|
const relevant = developmentGraphs().filter((graph) => {
|
|
10
11
|
const { snapshot } = graph;
|
|
@@ -22,7 +23,3 @@ export function routeModuleSourceVersion(path: string): string {
|
|
|
22
23
|
)
|
|
23
24
|
);
|
|
24
25
|
}
|
|
25
|
-
|
|
26
|
-
export function invalidateRouteModuleSourceVersions(): void {
|
|
27
|
-
devGraph(undefined).invalidateModules();
|
|
28
|
-
}
|