@teyik0/furin 0.1.0-alpha.6 → 0.1.0-alpha.8
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 +668 -90
- package/dist/build/types.d.ts +26 -3
- package/dist/cli/index.d.ts +1 -0
- package/dist/cli/index.js +704 -103
- package/dist/client.d.ts +22 -15
- package/dist/config.d.ts +33 -2
- package/dist/config.js +6 -1
- package/dist/dev-page-plugin.d.ts +77 -0
- package/dist/furin.js +771 -81
- package/dist/link.d.ts +31 -3
- package/dist/link.js +511 -62
- package/dist/render/index.d.ts +1 -1
- package/dist/render/loaders.d.ts +1 -1
- package/dist/router.js +84 -24
- package/package.json +9 -10
- package/src/adapter/bun.ts +31 -7
- package/src/adapter/static.ts +337 -0
- package/src/build/client.ts +28 -11
- package/src/build/compile-entry.ts +5 -3
- package/src/build/entry-template.ts +9 -5
- package/src/build/hydrate.ts +40 -10
- package/src/build/index.ts +56 -21
- package/src/build/scan-server.ts +43 -21
- package/src/build/shared.ts +7 -3
- package/src/build/types.ts +28 -3
- package/src/cli/index.ts +14 -5
- package/src/client.ts +26 -31
- package/src/config.ts +35 -1
- package/src/dev-page-plugin.ts +339 -4
- package/src/furin.ts +6 -2
- package/src/link.tsx +268 -62
- package/src/plugin/index.ts +2 -2
- package/src/render/index.ts +64 -24
- package/src/render/loaders.ts +77 -36
- package/src/render/shell.ts +2 -2
- package/src/router.ts +11 -1
package/dist/client.d.ts
CHANGED
|
@@ -2,9 +2,20 @@ import type { Cookie, StatusMap } from "elysia";
|
|
|
2
2
|
import type { AnySchema, HTTPHeaders, UnwrapSchema } from "elysia/types";
|
|
3
3
|
declare const UNSET: unique symbol;
|
|
4
4
|
type Unset = typeof UNSET;
|
|
5
|
+
type ToRecord<T> = {
|
|
6
|
+
[K in keyof T]: T[K];
|
|
7
|
+
};
|
|
5
8
|
type ResolvedSchema<T> = [T] extends [Unset] ? Unset : T extends AnySchema ? UnwrapSchema<T> : Unset;
|
|
6
9
|
type MergeSchema<TParent, TOwn> = [TParent] extends [Unset] ? TOwn : [TOwn] extends [Unset] ? TParent : TParent & TOwn;
|
|
7
10
|
type NormalizeUnset<T> = [T] extends [Unset] ? {} : T;
|
|
11
|
+
/**
|
|
12
|
+
* Transforms each key of a parent-data record into an individual `Promise<T>`.
|
|
13
|
+
* This is what child loaders see for inherited fields — direct values from
|
|
14
|
+
* `RouteContext` (request, params, set, …) remain unchanged.
|
|
15
|
+
*/
|
|
16
|
+
type PromisifyData<T extends Record<string, unknown>> = {
|
|
17
|
+
[K in keyof T]: Promise<T[K]>;
|
|
18
|
+
};
|
|
8
19
|
export interface RouteContext<TParams = {}, TQuery = {}> {
|
|
9
20
|
cookie: Record<string, Cookie<unknown>>;
|
|
10
21
|
headers: Record<string, string | undefined>;
|
|
@@ -33,7 +44,7 @@ type ResolveParent<T> = T extends RouteRef<infer D, infer P, infer Q> ? {
|
|
|
33
44
|
query: Unset;
|
|
34
45
|
};
|
|
35
46
|
interface Resolved<TParentRef, TLoaderData, TParamsSchema = Unset, TQuerySchema = Unset> {
|
|
36
|
-
data: ResolveParent<TParentRef>["data"] & TLoaderData
|
|
47
|
+
data: ToRecord<ResolveParent<TParentRef>["data"] & TLoaderData>;
|
|
37
48
|
params: MergeSchema<ResolveParent<TParentRef>["params"], ResolvedSchema<TParamsSchema>>;
|
|
38
49
|
query: MergeSchema<ResolveParent<TParentRef>["query"], ResolvedSchema<TQuerySchema>>;
|
|
39
50
|
}
|
|
@@ -86,14 +97,11 @@ export interface HeadOptions {
|
|
|
86
97
|
children: string;
|
|
87
98
|
}>;
|
|
88
99
|
}
|
|
89
|
-
|
|
90
|
-
__type: string;
|
|
91
|
-
}) => Promise<Record<string, unknown>>;
|
|
92
|
-
type ExtractLoaderReturn<TLoader> = TLoader extends (...args: never[]) => unknown ? Awaited<ReturnType<TLoader>> extends Record<string, unknown> ? Awaited<ReturnType<TLoader>> : {} : {};
|
|
100
|
+
type ExtractLoaderReturn<TLoader> = TLoader extends (...args: never[]) => unknown ? Awaited<ReturnType<TLoader>> extends object ? ToRecord<Awaited<ReturnType<TLoader>>> : {} : {};
|
|
93
101
|
export interface PageConfig<TParentData extends Record<string, unknown>, TParams, TQuery, TPageLoaderData extends object = {}> {
|
|
94
102
|
component: React.FC<TParentData & TPageLoaderData & ComponentProps<TParams, TQuery>>;
|
|
95
103
|
head?: (ctx: ComponentProps<TParams, TQuery> & TParentData & TPageLoaderData) => HeadOptions;
|
|
96
|
-
loader?: (ctx: RouteContext<TParams, TQuery> & TParentData
|
|
104
|
+
loader?: (ctx: RouteContext<TParams, TQuery> & PromisifyData<TParentData>) => Promise<TPageLoaderData> | TPageLoaderData;
|
|
97
105
|
staticParams?: () => Promise<NormalizeUnset<TParams>[]> | NormalizeUnset<TParams>[];
|
|
98
106
|
}
|
|
99
107
|
export interface RuntimeRoute {
|
|
@@ -101,7 +109,7 @@ export interface RuntimeRoute {
|
|
|
101
109
|
layout?: React.FC<Record<string, unknown> & {
|
|
102
110
|
children: React.ReactNode;
|
|
103
111
|
}>;
|
|
104
|
-
loader?(ctx: Record<string, unknown
|
|
112
|
+
loader?(ctx: Record<string, unknown>): Promise<Record<string, unknown>> | Record<string, unknown>;
|
|
105
113
|
mode?: "ssr" | "ssg" | "isr";
|
|
106
114
|
params?: unknown;
|
|
107
115
|
parent?: RuntimeRoute;
|
|
@@ -113,7 +121,7 @@ export interface RuntimePage {
|
|
|
113
121
|
_route: RuntimeRoute;
|
|
114
122
|
component: React.FC<Record<string, unknown>>;
|
|
115
123
|
head?(ctx: Record<string, unknown>): HeadOptions;
|
|
116
|
-
loader?(ctx: Record<string, unknown
|
|
124
|
+
loader?(ctx: Record<string, unknown>): Promise<Record<string, unknown>> | Record<string, unknown>;
|
|
117
125
|
staticParams?(): Promise<Record<string, string>[]> | Record<string, string>[];
|
|
118
126
|
}
|
|
119
127
|
export interface RouteRef<TData extends Record<string, unknown> = Record<string, unknown>, TParams = unknown, TQuery = unknown> {
|
|
@@ -124,21 +132,21 @@ export interface RouteRef<TData extends Record<string, unknown> = Record<string,
|
|
|
124
132
|
query: TQuery;
|
|
125
133
|
};
|
|
126
134
|
}
|
|
127
|
-
interface PageResult<TData extends Record<string, unknown>, TParams, TQuery, TPageLoaderData extends
|
|
135
|
+
interface PageResult<TData extends Record<string, unknown>, TParams, TQuery, TPageLoaderData extends object> {
|
|
128
136
|
__type: "FURIN_PAGE";
|
|
129
137
|
_route: Route<TData, TParams, TQuery>;
|
|
130
138
|
component: React.FC<TData & TPageLoaderData & ComponentProps<TParams, TQuery>>;
|
|
131
139
|
head?: (ctx: ComponentProps<TParams, TQuery> & TData & TPageLoaderData) => HeadOptions;
|
|
132
|
-
loader?: (ctx: RouteContext<TParams, TQuery> & TData
|
|
140
|
+
loader?: (ctx: RouteContext<TParams, TQuery> & PromisifyData<TData>) => Promise<TPageLoaderData> | TPageLoaderData;
|
|
133
141
|
}
|
|
134
142
|
export interface Route<TParentData extends Record<string, unknown>, TParams, TQuery> {
|
|
135
143
|
__type: "FURIN_ROUTE";
|
|
136
144
|
layout?: React.FC<TParentData & {
|
|
137
145
|
children: React.ReactNode;
|
|
138
146
|
} & ComponentProps<TParams, TQuery>>;
|
|
139
|
-
loader?(ctx: RouteContext<TParams, TQuery> & TParentData
|
|
147
|
+
loader?(ctx: RouteContext<TParams, TQuery> & PromisifyData<TParentData>): Promise<TParentData> | TParentData;
|
|
140
148
|
mode?: "ssr" | "ssg" | "isr";
|
|
141
|
-
page<TLoader extends (ctx: RouteContext<TParams, TQuery> & TParentData
|
|
149
|
+
page<TLoader extends (ctx: RouteContext<TParams, TQuery> & PromisifyData<TParentData>) => unknown, TPageLoaderData extends object = ExtractLoaderReturn<TLoader>>(config: {
|
|
142
150
|
loader: TLoader;
|
|
143
151
|
mode?: "ssr" | "ssg" | "isr";
|
|
144
152
|
revalidate?: number;
|
|
@@ -160,8 +168,7 @@ export interface Route<TParentData extends Record<string, unknown>, TParams, TQu
|
|
|
160
168
|
ref: RouteRef<TParentData, TParams, TQuery>;
|
|
161
169
|
revalidate?: number;
|
|
162
170
|
}
|
|
163
|
-
|
|
164
|
-
export declare function createRoute<TParentRef extends RouteRef | undefined = undefined, TParamsSchema extends AnySchema | Unset = Unset, TQuerySchema extends AnySchema | Unset = Unset, TLoaderData extends Record<string, unknown> = {}>(config?: {
|
|
171
|
+
export declare function createRoute<TParentRef extends RouteRef | undefined = undefined, TParamsSchema extends AnySchema | Unset = Unset, TQuerySchema extends AnySchema | Unset = Unset, TLoaderData extends object = {}>(config?: {
|
|
165
172
|
parent?: {
|
|
166
173
|
ref: TParentRef;
|
|
167
174
|
} & {
|
|
@@ -171,7 +178,7 @@ export declare function createRoute<TParentRef extends RouteRef | undefined = un
|
|
|
171
178
|
revalidate?: number;
|
|
172
179
|
params?: TParamsSchema;
|
|
173
180
|
query?: TQuerySchema;
|
|
174
|
-
loader?: (ctx: RouteContext<Resolved<TParentRef, TLoaderData, TParamsSchema, TQuerySchema>["params"], Resolved<TParentRef, TLoaderData, TParamsSchema, TQuerySchema>["query"]> & ResolveParent<TParentRef>["data"]
|
|
181
|
+
loader?: (ctx: RouteContext<Resolved<TParentRef, TLoaderData, TParamsSchema, TQuerySchema>["params"], Resolved<TParentRef, TLoaderData, TParamsSchema, TQuerySchema>["query"]> & PromisifyData<ResolveParent<TParentRef>["data"]>) => Promise<TLoaderData> | TLoaderData;
|
|
175
182
|
layout?: React.FC<Resolved<TParentRef, TLoaderData, TParamsSchema, TQuerySchema>["data"] & {
|
|
176
183
|
children: React.ReactNode;
|
|
177
184
|
} & 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) {
|
|
@@ -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;
|