@teyik0/furin 0.1.0-alpha.7 → 0.1.0-alpha.9
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/static.d.ts +3 -0
- package/dist/build/client.d.ts +3 -3
- package/dist/build/compile-entry.d.ts +4 -4
- package/dist/build/entry-template.d.ts +2 -2
- package/dist/build/hydrate.d.ts +6 -2
- package/dist/build/index.d.ts +1 -1
- package/dist/build/index.js +1491 -78
- package/dist/build/types.d.ts +26 -3
- package/dist/cli/index.js +1525 -91
- package/dist/client.d.ts +18 -11
- package/dist/config.d.ts +33 -2
- package/dist/config.js +6 -1
- package/dist/context-logger.d.ts +26 -0
- package/dist/dev-page-plugin.d.ts +77 -0
- package/dist/furin.js +459 -69
- package/dist/link.d.ts +31 -3
- package/dist/link.js +198 -51
- package/dist/render/assemble.d.ts +4 -2
- package/dist/render/index.d.ts +1 -1
- package/dist/render/loaders.d.ts +1 -1
- package/dist/render/shell.d.ts +4 -1
- package/dist/router.d.ts +11 -0
- package/dist/router.js +942 -41
- package/package.json +6 -5
- package/src/adapter/bun.ts +20 -0
- package/src/adapter/static.ts +341 -0
- package/src/build/client.ts +21 -11
- package/src/build/compile-entry.ts +5 -3
- package/src/build/entry-template.ts +2 -2
- package/src/build/hydrate.ts +37 -9
- package/src/build/index.ts +56 -21
- package/src/build/scan-server.ts +43 -21
- package/src/build/types.ts +28 -3
- package/src/cli/index.ts +13 -5
- package/src/client.ts +19 -25
- package/src/config.ts +35 -1
- package/src/context-logger.ts +71 -0
- package/src/dev-page-plugin.ts +339 -4
- package/src/furin.ts +6 -2
- package/src/link.tsx +355 -64
- package/src/plugin/index.ts +2 -2
- package/src/render/assemble.ts +4 -2
- package/src/render/index.ts +67 -23
- package/src/render/loaders.ts +81 -36
- package/src/render/shell.ts +11 -4
- package/src/router.ts +55 -6
package/dist/client.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Cookie, StatusMap } from "elysia";
|
|
2
2
|
import type { AnySchema, HTTPHeaders, UnwrapSchema } from "elysia/types";
|
|
3
|
+
import type { RequestLogger } from "evlog";
|
|
3
4
|
declare const UNSET: unique symbol;
|
|
4
5
|
type Unset = typeof UNSET;
|
|
5
6
|
type ToRecord<T> = {
|
|
@@ -8,9 +9,19 @@ type ToRecord<T> = {
|
|
|
8
9
|
type ResolvedSchema<T> = [T] extends [Unset] ? Unset : T extends AnySchema ? UnwrapSchema<T> : Unset;
|
|
9
10
|
type MergeSchema<TParent, TOwn> = [TParent] extends [Unset] ? TOwn : [TOwn] extends [Unset] ? TParent : TParent & TOwn;
|
|
10
11
|
type NormalizeUnset<T> = [T] extends [Unset] ? {} : T;
|
|
12
|
+
/**
|
|
13
|
+
* Transforms each key of a parent-data record into an individual `Promise<T>`.
|
|
14
|
+
* This is what child loaders see for inherited fields — direct values from
|
|
15
|
+
* `RouteContext` (request, params, set, …) remain unchanged.
|
|
16
|
+
*/
|
|
17
|
+
type PromisifyData<T extends Record<string, unknown>> = {
|
|
18
|
+
[K in keyof T]: Promise<T[K]>;
|
|
19
|
+
};
|
|
11
20
|
export interface RouteContext<TParams = {}, TQuery = {}> {
|
|
12
21
|
cookie: Record<string, Cookie<unknown>>;
|
|
13
22
|
headers: Record<string, string | undefined>;
|
|
23
|
+
/** Request-scoped logger. Call `log.set({})` to attach fields to the wide event for this render. */
|
|
24
|
+
log: RequestLogger;
|
|
14
25
|
params: NormalizeUnset<TParams>;
|
|
15
26
|
path: string;
|
|
16
27
|
query: NormalizeUnset<TQuery>;
|
|
@@ -89,14 +100,11 @@ export interface HeadOptions {
|
|
|
89
100
|
children: string;
|
|
90
101
|
}>;
|
|
91
102
|
}
|
|
92
|
-
export type LoaderDeps = (route: {
|
|
93
|
-
__type: string;
|
|
94
|
-
}) => Promise<Record<string, unknown>>;
|
|
95
103
|
type ExtractLoaderReturn<TLoader> = TLoader extends (...args: never[]) => unknown ? Awaited<ReturnType<TLoader>> extends object ? ToRecord<Awaited<ReturnType<TLoader>>> : {} : {};
|
|
96
104
|
export interface PageConfig<TParentData extends Record<string, unknown>, TParams, TQuery, TPageLoaderData extends object = {}> {
|
|
97
105
|
component: React.FC<TParentData & TPageLoaderData & ComponentProps<TParams, TQuery>>;
|
|
98
106
|
head?: (ctx: ComponentProps<TParams, TQuery> & TParentData & TPageLoaderData) => HeadOptions;
|
|
99
|
-
loader?: (ctx: RouteContext<TParams, TQuery> & TParentData
|
|
107
|
+
loader?: (ctx: RouteContext<TParams, TQuery> & PromisifyData<TParentData>) => Promise<TPageLoaderData> | TPageLoaderData;
|
|
100
108
|
staticParams?: () => Promise<NormalizeUnset<TParams>[]> | NormalizeUnset<TParams>[];
|
|
101
109
|
}
|
|
102
110
|
export interface RuntimeRoute {
|
|
@@ -104,7 +112,7 @@ export interface RuntimeRoute {
|
|
|
104
112
|
layout?: React.FC<Record<string, unknown> & {
|
|
105
113
|
children: React.ReactNode;
|
|
106
114
|
}>;
|
|
107
|
-
loader?(ctx: Record<string, unknown
|
|
115
|
+
loader?(ctx: Record<string, unknown>): Promise<Record<string, unknown>> | Record<string, unknown>;
|
|
108
116
|
mode?: "ssr" | "ssg" | "isr";
|
|
109
117
|
params?: unknown;
|
|
110
118
|
parent?: RuntimeRoute;
|
|
@@ -116,7 +124,7 @@ export interface RuntimePage {
|
|
|
116
124
|
_route: RuntimeRoute;
|
|
117
125
|
component: React.FC<Record<string, unknown>>;
|
|
118
126
|
head?(ctx: Record<string, unknown>): HeadOptions;
|
|
119
|
-
loader?(ctx: Record<string, unknown
|
|
127
|
+
loader?(ctx: Record<string, unknown>): Promise<Record<string, unknown>> | Record<string, unknown>;
|
|
120
128
|
staticParams?(): Promise<Record<string, string>[]> | Record<string, string>[];
|
|
121
129
|
}
|
|
122
130
|
export interface RouteRef<TData extends Record<string, unknown> = Record<string, unknown>, TParams = unknown, TQuery = unknown> {
|
|
@@ -132,16 +140,16 @@ interface PageResult<TData extends Record<string, unknown>, TParams, TQuery, TPa
|
|
|
132
140
|
_route: Route<TData, TParams, TQuery>;
|
|
133
141
|
component: React.FC<TData & TPageLoaderData & ComponentProps<TParams, TQuery>>;
|
|
134
142
|
head?: (ctx: ComponentProps<TParams, TQuery> & TData & TPageLoaderData) => HeadOptions;
|
|
135
|
-
loader?: (ctx: RouteContext<TParams, TQuery> & TData
|
|
143
|
+
loader?: (ctx: RouteContext<TParams, TQuery> & PromisifyData<TData>) => Promise<TPageLoaderData> | TPageLoaderData;
|
|
136
144
|
}
|
|
137
145
|
export interface Route<TParentData extends Record<string, unknown>, TParams, TQuery> {
|
|
138
146
|
__type: "FURIN_ROUTE";
|
|
139
147
|
layout?: React.FC<TParentData & {
|
|
140
148
|
children: React.ReactNode;
|
|
141
149
|
} & ComponentProps<TParams, TQuery>>;
|
|
142
|
-
loader?(ctx: RouteContext<TParams, TQuery> & TParentData
|
|
150
|
+
loader?(ctx: RouteContext<TParams, TQuery> & PromisifyData<TParentData>): Promise<TParentData> | TParentData;
|
|
143
151
|
mode?: "ssr" | "ssg" | "isr";
|
|
144
|
-
page<TLoader extends (ctx: RouteContext<TParams, TQuery> & TParentData
|
|
152
|
+
page<TLoader extends (ctx: RouteContext<TParams, TQuery> & PromisifyData<TParentData>) => unknown, TPageLoaderData extends object = ExtractLoaderReturn<TLoader>>(config: {
|
|
145
153
|
loader: TLoader;
|
|
146
154
|
mode?: "ssr" | "ssg" | "isr";
|
|
147
155
|
revalidate?: number;
|
|
@@ -163,7 +171,6 @@ export interface Route<TParentData extends Record<string, unknown>, TParams, TQu
|
|
|
163
171
|
ref: RouteRef<TParentData, TParams, TQuery>;
|
|
164
172
|
revalidate?: number;
|
|
165
173
|
}
|
|
166
|
-
type TypedDeps = <TData extends Record<string, unknown>>(route: Route<TData, any, any>) => Promise<TData>;
|
|
167
174
|
export declare function createRoute<TParentRef extends RouteRef | undefined = undefined, TParamsSchema extends AnySchema | Unset = Unset, TQuerySchema extends AnySchema | Unset = Unset, TLoaderData extends object = {}>(config?: {
|
|
168
175
|
parent?: {
|
|
169
176
|
ref: TParentRef;
|
|
@@ -174,7 +181,7 @@ export declare function createRoute<TParentRef extends RouteRef | undefined = un
|
|
|
174
181
|
revalidate?: number;
|
|
175
182
|
params?: TParamsSchema;
|
|
176
183
|
query?: TQuerySchema;
|
|
177
|
-
loader?: (ctx: RouteContext<Resolved<TParentRef, TLoaderData, TParamsSchema, TQuerySchema>["params"], Resolved<TParentRef, TLoaderData, TParamsSchema, TQuerySchema>["query"]> & ResolveParent<TParentRef>["data"]
|
|
184
|
+
loader?: (ctx: RouteContext<Resolved<TParentRef, TLoaderData, TParamsSchema, TQuerySchema>["params"], Resolved<TParentRef, TLoaderData, TParamsSchema, TQuerySchema>["query"]> & PromisifyData<ResolveParent<TParentRef>["data"]>) => Promise<TLoaderData> | TLoaderData;
|
|
178
185
|
layout?: React.FC<Resolved<TParentRef, TLoaderData, TParamsSchema, TQuerySchema>["data"] & {
|
|
179
186
|
children: React.ReactNode;
|
|
180
187
|
} & ComponentProps<Resolved<TParentRef, TLoaderData, TParamsSchema, TQuerySchema>["params"], Resolved<TParentRef, TLoaderData, TParamsSchema, TQuerySchema>["query"]>>;
|
package/dist/config.d.ts
CHANGED
|
@@ -1,16 +1,47 @@
|
|
|
1
1
|
export type { BunPlugin } from "bun";
|
|
2
|
-
export declare const BUILD_TARGETS: readonly ["bun", "node", "vercel", "cloudflare"];
|
|
2
|
+
export declare const BUILD_TARGETS: readonly ["bun", "node", "vercel", "cloudflare", "static"];
|
|
3
3
|
export type BuildTarget = (typeof BUILD_TARGETS)[number];
|
|
4
|
+
/**
|
|
5
|
+
* Configuration for the `static` build target.
|
|
6
|
+
* Produces a fully pre-rendered directory deployable to any static host
|
|
7
|
+
* (GitHub Pages, Netlify, Surge.sh, …).
|
|
8
|
+
*/
|
|
9
|
+
export interface StaticExportConfig {
|
|
10
|
+
/**
|
|
11
|
+
* Sub-path prefix for GitHub Pages sub-path deployments.
|
|
12
|
+
* e.g. "/furin" when the site is served at `https://user.github.io/furin/`.
|
|
13
|
+
* Must start with "/" and have no trailing slash.
|
|
14
|
+
* Default: "" (site served at root).
|
|
15
|
+
*/
|
|
16
|
+
basePath?: string;
|
|
17
|
+
/**
|
|
18
|
+
* Behaviour when SSR or ISR routes are encountered during a static build.
|
|
19
|
+
* - "error" (default): throw at build time with the list of incompatible routes.
|
|
20
|
+
* - "skip": emit a warning and omit those routes from the output.
|
|
21
|
+
*/
|
|
22
|
+
onSSR?: "error" | "skip";
|
|
23
|
+
/**
|
|
24
|
+
* Output directory for the static export.
|
|
25
|
+
* Default: "dist".
|
|
26
|
+
*/
|
|
27
|
+
outDir?: string;
|
|
28
|
+
}
|
|
4
29
|
export declare const configSchema: import("@sinclair/typebox").TObject<{
|
|
5
30
|
rootDir: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
6
31
|
pagesDir: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
7
32
|
serverEntry: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
8
|
-
targets: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TArray<import("@sinclair/typebox").TUnion<import("@sinclair/typebox").TLiteral<"bun" | "node" | "vercel" | "cloudflare">[]>>>;
|
|
33
|
+
targets: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TArray<import("@sinclair/typebox").TUnion<import("@sinclair/typebox").TLiteral<"bun" | "node" | "vercel" | "cloudflare" | "static">[]>>>;
|
|
9
34
|
bun: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TObject<{
|
|
10
35
|
compile: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TLiteral<"server">, import("@sinclair/typebox").TLiteral<"embed">]>>;
|
|
11
36
|
}>>;
|
|
37
|
+
static: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TObject<{
|
|
38
|
+
basePath: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
39
|
+
outDir: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
40
|
+
onSSR: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TLiteral<"error">, import("@sinclair/typebox").TLiteral<"skip">]>>;
|
|
41
|
+
}>>;
|
|
12
42
|
}>;
|
|
13
43
|
export type FurinConfig = (typeof configSchema)["static"] & {
|
|
14
44
|
plugins?: Bun.BunPlugin[];
|
|
45
|
+
static?: StaticExportConfig;
|
|
15
46
|
};
|
|
16
47
|
export declare function defineConfig(config: FurinConfig): FurinConfig;
|
package/dist/config.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// @bun
|
|
2
2
|
// src/config.ts
|
|
3
3
|
import { t } from "elysia";
|
|
4
|
-
var BUILD_TARGETS = ["bun", "node", "vercel", "cloudflare"];
|
|
4
|
+
var BUILD_TARGETS = ["bun", "node", "vercel", "cloudflare", "static"];
|
|
5
5
|
var buildTargetSchema = t.Union(BUILD_TARGETS.map((v) => t.Literal(v)));
|
|
6
6
|
var compileTargetSchema = t.Union([t.Literal("server"), t.Literal("embed")]);
|
|
7
7
|
var configSchema = t.Object({
|
|
@@ -11,6 +11,11 @@ var configSchema = t.Object({
|
|
|
11
11
|
targets: t.Optional(t.Array(buildTargetSchema)),
|
|
12
12
|
bun: t.Optional(t.Object({
|
|
13
13
|
compile: t.Optional(compileTargetSchema)
|
|
14
|
+
})),
|
|
15
|
+
static: t.Optional(t.Object({
|
|
16
|
+
basePath: t.Optional(t.String()),
|
|
17
|
+
outDir: t.Optional(t.String()),
|
|
18
|
+
onSSR: t.Optional(t.Union([t.Literal("error"), t.Literal("skip")]))
|
|
14
19
|
}))
|
|
15
20
|
});
|
|
16
21
|
function defineConfig(config) {
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { RequestLogger } from "evlog";
|
|
2
|
+
/**
|
|
3
|
+
* Returns the current request-scoped logger.
|
|
4
|
+
*
|
|
5
|
+
* Priority:
|
|
6
|
+
* 1. Live Elysia request handled by the evlog() plugin → full request-scoped wide event
|
|
7
|
+
* 2. Synthetic render scope (ISR revalidation, SSG pre-render) → detached createLogger()
|
|
8
|
+
* that still drains to the configured adapter (Datadog, Axiom, etc.)
|
|
9
|
+
* 3. Completely outside any context → no-op
|
|
10
|
+
*
|
|
11
|
+
* Import from `@teyik0/furin` instead of `evlog/elysia` so this fallback chain
|
|
12
|
+
* applies in all rendering contexts.
|
|
13
|
+
*/
|
|
14
|
+
export declare function useLogger(): RequestLogger;
|
|
15
|
+
/**
|
|
16
|
+
* Runs `fn` inside a synthetic render scope.
|
|
17
|
+
*
|
|
18
|
+
* Creates a detached `createLogger()` instance for the duration of `fn`.
|
|
19
|
+
* `useLogger()` calls inside `fn` (including user loaders) return this logger
|
|
20
|
+
* instead of throwing. On completion, the accumulated wide event is emitted to
|
|
21
|
+
* the global drain with the provided initial context (e.g. route pattern).
|
|
22
|
+
*
|
|
23
|
+
* Used by renderForPath() which drives both ISR background revalidation and
|
|
24
|
+
* SSG pre-renders — neither has a live Elysia request context.
|
|
25
|
+
*/
|
|
26
|
+
export declare function runInSyntheticRenderScope<T>(fn: () => Promise<T> | T, initialContext: Record<string, unknown>): Promise<T>;
|
|
@@ -26,7 +26,84 @@
|
|
|
26
26
|
* Modules in a virtual namespace cannot resolve relative specifiers on their
|
|
27
27
|
* own (there is no real directory context). We rewrite every `./` / `../`
|
|
28
28
|
* path to an absolute one before returning the source.
|
|
29
|
+
*
|
|
30
|
+
* ## Bare specifier rewriting
|
|
31
|
+
*
|
|
32
|
+
* When `onLoad` returns `loader: "js"`, Bun resolves bare specifiers
|
|
33
|
+
* (e.g. `@teyik0/furin/link`, `shiki`) from the process CWD — not from the
|
|
34
|
+
* page file's directory. On a cold start the CWD and the file's directory
|
|
35
|
+
* often agree, but after `bun --hot` re-evaluates the server the module
|
|
36
|
+
* cache for project-local packages (like `packages/core/src/link.tsx`) may
|
|
37
|
+
* be cleared and re-loaded with a fresh React instance that diverges from the
|
|
38
|
+
* one already cached by `react-dom/server`. The result is the classic
|
|
39
|
+
* "two React copies" crash: `dispatcher.useState === null`.
|
|
40
|
+
*
|
|
41
|
+
* Fix: after transpilation, resolve every bare specifier from the page
|
|
42
|
+
* file's directory via `Bun.resolveSync` and replace it with the
|
|
43
|
+
* canonical on-disk path. This pins each import to exactly the same
|
|
44
|
+
* file-system location that Bun's native module resolver would choose,
|
|
45
|
+
* guaranteeing a single shared React instance regardless of CWD or
|
|
46
|
+
* hot-reload state.
|
|
47
|
+
*
|
|
48
|
+
* All import/re-export occurrences of each quoted specifier are replaced using
|
|
49
|
+
* a context-aware regex (requires a preceding `from` or `import` keyword) so
|
|
50
|
+
* that modules which both import and re-export from the same package are fully
|
|
51
|
+
* rewritten while string literals in non-import positions are left untouched.
|
|
52
|
+
*/
|
|
53
|
+
/**
|
|
54
|
+
* Rewrites bare React/react-dom singleton imports in source text to their
|
|
55
|
+
* absolute resolved paths. Handles explicit static import / re-export forms:
|
|
56
|
+
*
|
|
57
|
+
* import { useState } from "react" → import { useState } from "/abs/…"
|
|
58
|
+
* import type { FC } from "react"
|
|
59
|
+
* export { x } from "react"
|
|
60
|
+
* import "react/jsx-dev-runtime"
|
|
61
|
+
*
|
|
62
|
+
* Does NOT touch dynamic `import("react")` or `require("react")`.
|
|
63
|
+
*
|
|
64
|
+
* @internal exported for testing
|
|
29
65
|
*/
|
|
66
|
+
export declare function rewriteSingletonImports(source: string): string;
|
|
67
|
+
/**
|
|
68
|
+
* `Bun.Transpiler.transformSync` converts JSX syntax to function calls using
|
|
69
|
+
* mangled helper names (e.g. `jsxDEV_7x81h0kn`, `Fragment_8vg9x3sq`) but does
|
|
70
|
+
* NOT emit the corresponding import statement — it expects Bun's full bundler
|
|
71
|
+
* pipeline to inject it later.
|
|
72
|
+
*
|
|
73
|
+
* When we return pre-transpiled JS from `onLoad`, that pipeline step never
|
|
74
|
+
* runs, leaving the helpers as undefined free variables. This function scans
|
|
75
|
+
* the transpiled source, detects which mangled helper names are used, and
|
|
76
|
+
* prepends the correct import statements using absolute on-disk paths from
|
|
77
|
+
* `SINGLETON_PATHS`.
|
|
78
|
+
*
|
|
79
|
+
* Helper → package mapping:
|
|
80
|
+
* jsxDEV_* → `{ jsxDEV as … }` from react/jsx-dev-runtime
|
|
81
|
+
* Fragment_* → `{ Fragment as … }` from react/jsx-dev-runtime
|
|
82
|
+
* jsx_* → `{ jsx as … }` from react/jsx-runtime (prod only)
|
|
83
|
+
* jsxs_* → `{ jsxs as … }` from react/jsx-runtime (prod only)
|
|
84
|
+
*
|
|
85
|
+
* @internal exported for testing
|
|
86
|
+
*/
|
|
87
|
+
export declare function injectJsxHelperImports(transpiled: string): string;
|
|
30
88
|
/** @internal exported for testing */
|
|
31
89
|
export declare function rewriteRelativeImports(source: string, dir: string): string;
|
|
90
|
+
/**
|
|
91
|
+
* Rewrites all remaining bare specifiers in the transpiled JS to absolute
|
|
92
|
+
* on-disk paths resolved from `dir` (the page file's directory).
|
|
93
|
+
*
|
|
94
|
+
* Uses `Bun.Transpiler.scan()` on the original source to get the authoritative
|
|
95
|
+
* list of *actual* import specifiers (parsing correctly handles template
|
|
96
|
+
* literals, comments, etc.). For each bare specifier that is not already
|
|
97
|
+
* handled by `rewriteSingletonImports`, it calls `Bun.resolveSync` and
|
|
98
|
+
* replaces **every** import/re-export occurrence of the quoted specifier using
|
|
99
|
+
* a context-aware regex with the `g` flag — mirroring the approach used by
|
|
100
|
+
* `rewriteSingletonImports`. This correctly handles modules that both import
|
|
101
|
+
* and re-export from the same package without leaving any bare specifier
|
|
102
|
+
* behind. String literals that happen to contain the same text (inside
|
|
103
|
+
* template literals, JSX props, etc.) are not touched because the regex
|
|
104
|
+
* requires a preceding `from` or `import` keyword.
|
|
105
|
+
*
|
|
106
|
+
* @internal exported for testing
|
|
107
|
+
*/
|
|
108
|
+
export declare function rewriteBareImports(source: string, transpiled: string, dir: string): string;
|
|
32
109
|
export declare function registerDevPagePlugin(): void;
|