@teyik0/furin 0.3.0-alpha.1 → 0.4.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/adapter/bun.d.ts +1 -1
- package/dist/build/client.d.ts +2 -2
- package/dist/build/entry-template.d.ts +4 -0
- package/dist/build/entry-template.ts +17 -3
- package/dist/build/index.d.ts +1 -1
- package/dist/build/index.js +8288 -6629
- package/dist/build/route-types.d.ts +2 -22
- package/dist/build/shared.d.ts +1 -1
- package/dist/build/ssg-cache.d.ts +1 -1
- package/dist/build/types.d.ts +1 -1
- package/dist/cli/index.js +7862 -6168
- package/dist/client/boundaries.d.ts +2 -0
- package/dist/client/define-route.d.ts +35 -0
- package/dist/client/document.d.ts +26 -0
- package/dist/client/hmr.d.ts +10 -0
- package/dist/client/internal/runtime-types.d.ts +3 -1
- package/dist/client/link.js +1177 -894
- package/dist/client/router/index.d.ts +1 -1
- package/dist/client/router/link-utils.d.ts +9 -0
- package/dist/client/router/search/index.d.ts +3 -7
- package/dist/client/router/types.d.ts +32 -24
- package/dist/client.d.ts +4 -159
- package/dist/client.js +183 -21
- package/dist/config.d.ts +8 -8
- package/dist/config.js +8 -8
- package/dist/define-route.d.ts +1355 -0
- package/dist/furin.d.ts +17 -33
- package/dist/furin.js +13444 -10301
- package/dist/plugin/index.js +953 -244
- package/dist/plugin/route-config-autofix.d.ts +31 -0
- package/dist/plugin/routes.d.ts +27 -0
- package/dist/routes.d.ts +6 -0
- package/dist/routes.js +1 -0
- package/dist/rsc/build/index.d.ts +1 -1
- package/dist/rsc.js +3 -3
- package/dist/server/dev-page-plugin.d.ts +7 -5
- package/dist/server/devtools/instrumentation.d.ts +2 -2
- package/dist/server/devtools/instrumentation.production.d.ts +2 -2
- package/dist/server/devtools/plugin.d.ts +2 -2
- package/dist/server/internal.d.ts +3 -0
- package/dist/server/logger.d.ts +4 -0
- package/dist/server/render/assemble.d.ts +0 -9
- package/dist/server/render/document.d.ts +4 -0
- package/dist/server/render/element.d.ts +2 -1
- package/dist/server/render/index.d.ts +1 -1
- package/dist/server/render/index.ts +0 -1
- package/dist/server/render/isr.d.ts +1 -1
- package/dist/server/render/loaders.d.ts +1 -1
- package/dist/server/render/not-found.d.ts +1 -1
- package/dist/server/render/ppr-route.d.ts +1 -1
- package/dist/server/render/ssg.d.ts +1 -1
- package/dist/server/render/ssr.d.ts +7 -6
- package/dist/server/render/template.d.ts +4 -0
- package/dist/server/router/defined-route.d.ts +24 -0
- package/dist/server/router/hmr.d.ts +16 -8
- package/dist/server/router/patterns.d.ts +6 -0
- package/dist/server/router/plugin.d.ts +4 -3
- package/dist/server/router/schema-merge.d.ts +2 -2
- package/dist/server/router/schemas.d.ts +5 -5
- package/dist/server/router/source-version.d.ts +2 -0
- package/dist/server/router/types.d.ts +1 -0
- package/dist/server/sync/index.js +961 -806
- package/dist/server/sync/postgres/migrate.js +3 -2
- package/dist/shared/await.d.ts +6 -7
- package/dist/shared/elysia-contract.d.ts +41 -0
- package/dist/shared/route-map.d.ts +5 -0
- package/dist/shared/utils/index.d.ts +1 -3
- package/package.json +44 -41
- package/src/adapter/bun.ts +42 -22
- package/src/adapter/package.ts +20 -14
- package/src/adapter/static.ts +4 -3
- package/src/build/client.ts +20 -3
- package/src/build/entry-template.ts +17 -3
- package/src/build/hydrate.ts +98 -28
- package/src/build/index.ts +2 -2
- package/src/build/route-types.ts +19 -114
- package/src/build/shared.ts +1 -1
- package/src/build/ssg-cache.ts +2 -5
- package/src/build/types.ts +1 -1
- package/src/cli/config.ts +3 -3
- package/src/cli/index.ts +7 -7
- package/src/client/boundaries.tsx +9 -1
- package/src/client/define-route.ts +48 -0
- package/src/client/document.tsx +165 -0
- package/src/client/hmr.ts +40 -0
- package/src/client/internal/runtime-types.ts +3 -1
- package/src/client/link.tsx +21 -6
- package/src/client/router/index.ts +1 -0
- package/src/client/router/link-utils.ts +26 -0
- package/src/client/router/provider.tsx +25 -2
- package/src/client/router/search/index.ts +4 -12
- package/src/client/router/types.ts +50 -24
- package/src/client.ts +14 -316
- package/src/config.ts +10 -10
- package/src/define-route.ts +959 -0
- package/src/devtools/devtools-element.js +11 -10
- package/src/furin.ts +303 -53
- package/src/plugin/route-config-autofix.ts +1140 -0
- package/src/plugin/routes.ts +891 -0
- package/src/plugin/transform-client.ts +132 -266
- package/src/plugin/transform-isomorphic.ts +1 -1
- package/src/routes.ts +6 -0
- package/src/rsc/build/index.ts +1 -1
- package/src/server/auto-invalidate/registry.ts +2 -2
- package/src/server/dev-page-plugin.ts +31 -12
- package/src/server/devtools/instrumentation.production.ts +2 -2
- package/src/server/devtools/instrumentation.ts +2 -2
- package/src/server/devtools/plugin.ts +5 -3
- package/src/server/instance.ts +3 -3
- package/src/server/internal.ts +3 -0
- package/src/server/logger.ts +21 -0
- package/src/server/render/assemble.ts +0 -41
- package/src/server/render/document.tsx +25 -0
- package/src/server/render/element.tsx +13 -1
- package/src/server/render/index.ts +0 -1
- package/src/server/render/isr.ts +31 -10
- package/src/server/render/loaders.ts +31 -6
- package/src/server/render/not-found.ts +51 -27
- package/src/server/render/ppr-route.ts +1 -1
- package/src/server/render/ssg.ts +1 -1
- package/src/server/render/ssr.ts +271 -113
- package/src/server/render/template.ts +91 -1
- package/src/server/router/defined-route.ts +110 -0
- package/src/server/router/discovery.ts +129 -29
- package/src/server/router/hmr.ts +111 -40
- package/src/server/router/patterns.ts +40 -12
- package/src/server/router/plugin.ts +63 -46
- package/src/server/router/schema-merge.ts +4 -14
- package/src/server/router/schemas.ts +11 -8
- package/src/server/router/source-version.ts +16 -0
- package/src/server/router/types.ts +2 -0
- package/src/server/sync/postgres/migrate.ts +3 -2
- package/src/server/sync/response.ts +14 -10
- package/src/shared/await.tsx +6 -7
- package/src/shared/elysia-contract.ts +63 -0
- package/src/shared/route-map.ts +37 -0
- package/src/shared/utils/index.ts +2 -20
- package/dist/build/server-routes-entry.d.ts +0 -13
- package/dist/build/server-routes-entry.ts +0 -30
- package/dist/server/router/index.d.ts +0 -7
- package/dist/server/router/index.js +0 -27
- package/dist/server/router/index.ts +0 -28
- package/src/build/server-routes-entry.ts +0 -30
- package/src/server/router/index.ts +0 -28
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// @bun
|
|
3
3
|
|
|
4
4
|
// src/server/sync/postgres/migrate.ts
|
|
5
|
+
import { fileURLToPath } from "url";
|
|
5
6
|
var {SQL } = globalThis.Bun;
|
|
6
7
|
var databaseUrl = process.env.FURIN_SYNC_POSTGRES_URL;
|
|
7
8
|
if (databaseUrl === undefined || databaseUrl.length === 0) {
|
|
@@ -9,8 +10,8 @@ if (databaseUrl === undefined || databaseUrl.length === 0) {
|
|
|
9
10
|
}
|
|
10
11
|
var sql = new SQL(databaseUrl);
|
|
11
12
|
try {
|
|
12
|
-
const
|
|
13
|
-
await sql.
|
|
13
|
+
const migrationUrl = new URL("./migration.sql", import.meta.url);
|
|
14
|
+
await sql.file(fileURLToPath(migrationUrl));
|
|
14
15
|
} finally {
|
|
15
16
|
await sql.close();
|
|
16
17
|
}
|
package/dist/shared/await.d.ts
CHANGED
|
@@ -49,19 +49,18 @@ export interface AwaitProps<T> {
|
|
|
49
49
|
*
|
|
50
50
|
* @example
|
|
51
51
|
* ```tsx
|
|
52
|
-
* export
|
|
53
|
-
* loader
|
|
54
|
-
*
|
|
52
|
+
* export const route = defineRoute()
|
|
53
|
+
* .loader(() => defer({ board: "x", stats: fetchStats() }))
|
|
54
|
+
* .page(({ data }) => (
|
|
55
55
|
* <div>
|
|
56
|
-
* <h1>{board}</h1>
|
|
56
|
+
* <h1>{data.board}</h1>
|
|
57
57
|
* <Suspense fallback={<Spinner />}>
|
|
58
|
-
* <Await resolve={stats}>
|
|
58
|
+
* <Await resolve={data.stats}>
|
|
59
59
|
* {(s) => <StatsBar stats={s} />}
|
|
60
60
|
* </Await>
|
|
61
61
|
* </Suspense>
|
|
62
62
|
* </div>
|
|
63
|
-
* )
|
|
64
|
-
* });
|
|
63
|
+
* ));
|
|
65
64
|
* ```
|
|
66
65
|
*/
|
|
67
66
|
export declare function Await<T>({ resolve, errorElement, children }: AwaitProps<T>): ReactNode;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { parseQueryFromURL as elysiaParseQueryFromURL, parseQueryStandardSchema as elysiaParseQueryStandardSchema } from "elysia/parse-query";
|
|
2
|
+
import { TypeCompiler as ElysiaTypeCompiler } from "elysia/type-system";
|
|
3
|
+
import type { AnySchema, UnwrapSchema } from "elysia/types";
|
|
4
|
+
export declare const parseQueryFromURL: typeof elysiaParseQueryFromURL;
|
|
5
|
+
export declare const parseQueryStandardSchema: typeof elysiaParseQueryStandardSchema;
|
|
6
|
+
export declare const TypeCompiler: typeof ElysiaTypeCompiler;
|
|
7
|
+
interface SchemaObject {
|
|
8
|
+
[key: string]: unknown;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Central compatibility boundary for Elysia types used by Furin's public DX.
|
|
12
|
+
* Contract tests must fail before changes to these projections reach callers.
|
|
13
|
+
*/
|
|
14
|
+
export type FurinSchema = AnySchema;
|
|
15
|
+
interface FurinSchemaValidator {
|
|
16
|
+
Check: (value: unknown) => unknown;
|
|
17
|
+
Errors: (value: unknown) => Iterable<unknown>;
|
|
18
|
+
parse: (value: unknown) => unknown;
|
|
19
|
+
}
|
|
20
|
+
interface FurinSchemaValidatorOptions {
|
|
21
|
+
coerce?: boolean;
|
|
22
|
+
dynamic?: boolean;
|
|
23
|
+
}
|
|
24
|
+
export declare function getSchemaValidator(schema: FurinSchema, options: FurinSchemaValidatorOptions): FurinSchemaValidator | undefined;
|
|
25
|
+
export type FurinUnwrap<Schema extends FurinSchema | undefined> = UnwrapSchema<Schema>;
|
|
26
|
+
export type ElysiaRoutes<App extends {
|
|
27
|
+
"~Routes": unknown;
|
|
28
|
+
}> = App["~Routes"];
|
|
29
|
+
export type ElysiaRouteLeaf<App> = App extends {
|
|
30
|
+
"~Routes": infer Routes;
|
|
31
|
+
} ? Routes extends {
|
|
32
|
+
get: infer Leaf;
|
|
33
|
+
} ? Leaf : never : never;
|
|
34
|
+
export type ElysiaRouteParams<Leaf> = Leaf extends {
|
|
35
|
+
params: infer Params;
|
|
36
|
+
} ? Params : never;
|
|
37
|
+
export type ElysiaRouteQuery<Leaf> = Leaf extends {
|
|
38
|
+
query: infer Query;
|
|
39
|
+
} ? Query : never;
|
|
40
|
+
export declare function isTypeBoxObjectSchema(schema: unknown): schema is SchemaObject;
|
|
41
|
+
export {};
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare function isFurinPage(value: unknown): value is RuntimePage;
|
|
3
|
-
export declare function isFurinRoute(value: unknown): value is RuntimeRoute;
|
|
1
|
+
import type { RuntimeRoute } from "../../client/internal/runtime-types.ts";
|
|
4
2
|
export declare function collectRouteChainFromRoute(route: RuntimeRoute): RuntimeRoute[];
|
|
5
3
|
export declare function hasCycle(route: RuntimeRoute): boolean;
|
|
6
4
|
/**
|
package/package.json
CHANGED
|
@@ -1,14 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@teyik0/furin",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0-alpha.1",
|
|
4
4
|
"description": "React meta-framework powered by Elysia and Bun with file-based routing, SSR, SSG, and ISR.",
|
|
5
|
-
"license": "MIT",
|
|
6
|
-
"author": "teyik0",
|
|
7
|
-
"sideEffects": false,
|
|
8
|
-
"type": "module",
|
|
9
|
-
"engines": {
|
|
10
|
-
"bun": ">=1.4.0"
|
|
11
|
-
},
|
|
12
5
|
"keywords": [
|
|
13
6
|
"react",
|
|
14
7
|
"furin",
|
|
@@ -20,27 +13,18 @@
|
|
|
20
13
|
"routing",
|
|
21
14
|
"file-based-routing"
|
|
22
15
|
],
|
|
23
|
-
"
|
|
24
|
-
"type": "git",
|
|
25
|
-
"url": "git+https://github.com/teyik0/furin.git"
|
|
26
|
-
},
|
|
16
|
+
"homepage": "https://github.com/teyik0/furin#readme",
|
|
27
17
|
"bugs": {
|
|
28
18
|
"url": "https://github.com/teyik0/furin/issues"
|
|
29
19
|
},
|
|
30
|
-
"
|
|
31
|
-
|
|
32
|
-
"
|
|
33
|
-
"src",
|
|
34
|
-
"LICENSE",
|
|
35
|
-
"README.md"
|
|
36
|
-
],
|
|
37
|
-
"main": "./dist/furin.js",
|
|
38
|
-
"module": "./dist/furin.js",
|
|
39
|
-
"types": "./dist/furin.d.ts",
|
|
40
|
-
"bin": {
|
|
41
|
-
"furin": "./src/cli/index.ts",
|
|
42
|
-
"furin-sync-postgres-migrate": "./dist/server/sync/postgres/migrate.js"
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "git+https://github.com/teyik0/furin.git"
|
|
43
23
|
},
|
|
24
|
+
"license": "MIT",
|
|
25
|
+
"author": "teyik0",
|
|
26
|
+
"sideEffects": false,
|
|
27
|
+
"type": "module",
|
|
44
28
|
"exports": {
|
|
45
29
|
".": {
|
|
46
30
|
"types": "./dist/furin.d.ts",
|
|
@@ -52,6 +36,11 @@
|
|
|
52
36
|
"bun": "./src/client.ts",
|
|
53
37
|
"import": "./dist/client.js"
|
|
54
38
|
},
|
|
39
|
+
"./routes": {
|
|
40
|
+
"types": "./dist/routes.d.ts",
|
|
41
|
+
"bun": "./src/routes.ts",
|
|
42
|
+
"import": "./dist/routes.js"
|
|
43
|
+
},
|
|
55
44
|
"./rsc": {
|
|
56
45
|
"types": "./dist/rsc.d.ts",
|
|
57
46
|
"browser": "./src/rsc-client.ts",
|
|
@@ -68,11 +57,6 @@
|
|
|
68
57
|
"bun": "./src/config.ts",
|
|
69
58
|
"import": "./dist/config.js"
|
|
70
59
|
},
|
|
71
|
-
"./router": {
|
|
72
|
-
"types": "./dist/server/router/index.d.ts",
|
|
73
|
-
"bun": "./src/server/router/index.ts",
|
|
74
|
-
"import": "./dist/server/router/index.js"
|
|
75
|
-
},
|
|
76
60
|
"./sync": {
|
|
77
61
|
"types": "./dist/server/sync/index.d.ts",
|
|
78
62
|
"bun": "./src/server/sync/index.ts",
|
|
@@ -130,31 +114,50 @@
|
|
|
130
114
|
"import": "./dist/client-only.js"
|
|
131
115
|
}
|
|
132
116
|
},
|
|
117
|
+
"main": "./dist/furin.js",
|
|
118
|
+
"module": "./dist/furin.js",
|
|
119
|
+
"types": "./dist/furin.d.ts",
|
|
120
|
+
"bin": {
|
|
121
|
+
"furin": "./src/cli/index.ts",
|
|
122
|
+
"furin-sync-postgres-migrate": "./dist/server/sync/postgres/migrate.js"
|
|
123
|
+
},
|
|
124
|
+
"files": [
|
|
125
|
+
"dist",
|
|
126
|
+
"src",
|
|
127
|
+
"LICENSE",
|
|
128
|
+
"README.md"
|
|
129
|
+
],
|
|
133
130
|
"scripts": {
|
|
131
|
+
"benchmark:dbg-growth": "bun --expose-gc tests/bench/dbg-growth.bench.ts",
|
|
132
|
+
"benchmark:rsc": "bun scripts/benchmark-rsc-transport.ts",
|
|
133
|
+
"build": "bun run build.ts",
|
|
134
134
|
"fix": "ultracite fix",
|
|
135
135
|
"test": "bun test --parallel --isolate --bail",
|
|
136
136
|
"test:dev": "bun test --changed --parallel --isolate --bail",
|
|
137
|
-
"tscheck": "tsc --noEmit"
|
|
138
|
-
"build": "bun run build.ts",
|
|
139
|
-
"benchmark:rsc": "bun scripts/benchmark-rsc-transport.ts"
|
|
137
|
+
"tscheck": "tsc --noEmit"
|
|
140
138
|
},
|
|
141
139
|
"dependencies": {
|
|
142
140
|
"@elysiajs/static": "^1.4.10",
|
|
143
|
-
"@
|
|
144
|
-
"
|
|
141
|
+
"@sinclair/typebox": "0.34.52",
|
|
142
|
+
"@yuku-toolchain/types": "0.9.4",
|
|
143
|
+
"magic-string": "^1.2.3",
|
|
145
144
|
"react-server-dom-webpack": "19.2.8",
|
|
146
|
-
"seroval": "^1.5
|
|
147
|
-
"yuku-
|
|
145
|
+
"seroval": "^1.6.5",
|
|
146
|
+
"yuku-ast": "0.9.4",
|
|
147
|
+
"yuku-parser": "0.9.4"
|
|
148
148
|
},
|
|
149
149
|
"devDependencies": {
|
|
150
|
-
"@types/react": "^19.2.
|
|
151
|
-
"@types/react-dom": "^19.2.
|
|
150
|
+
"@types/react": "^19.2.18",
|
|
151
|
+
"@types/react-dom": "^19.2.7",
|
|
152
152
|
"expect-type": "^1.4.0"
|
|
153
153
|
},
|
|
154
154
|
"peerDependencies": {
|
|
155
|
-
"elysia": "^1.4.
|
|
156
|
-
"evlog": "^2.
|
|
155
|
+
"elysia": "^1.4.30",
|
|
156
|
+
"evlog": "^2.28.1",
|
|
157
157
|
"react": "19.2.8",
|
|
158
158
|
"react-dom": "19.2.8"
|
|
159
|
+
},
|
|
160
|
+
"engines": {
|
|
161
|
+
"bun": ">=1.4.0"
|
|
159
162
|
}
|
|
160
163
|
}
|
package/src/adapter/bun.ts
CHANGED
|
@@ -4,20 +4,24 @@ import { fileURLToPath } from "node:url";
|
|
|
4
4
|
import { runBunBuild } from "../build/bun-build.ts";
|
|
5
5
|
import { buildClient } from "../build/client.ts";
|
|
6
6
|
import { generateCompileEntry } from "../build/compile-entry.ts";
|
|
7
|
-
import
|
|
7
|
+
import {
|
|
8
|
+
type BuildEntryOptions,
|
|
9
|
+
buildEntrySource,
|
|
10
|
+
type EntryAppContext,
|
|
11
|
+
} from "../build/entry-template.ts";
|
|
8
12
|
import { productionInstrumentationPlugin } from "../build/production-instrumentation.ts";
|
|
9
|
-
import { generateServerRoutesEntry } from "../build/server-routes-entry.ts";
|
|
10
13
|
import { buildTargetManifest, copyDirRecursive, ensureDir, toPosixPath } from "../build/shared.ts";
|
|
11
14
|
import { buildSSGCacheSnapshot } from "../build/ssg-cache.ts";
|
|
12
15
|
import type { BuildAppOptions, TargetBuildManifest } from "../build/types.ts";
|
|
13
16
|
import type { BuildTarget } from "../config.ts";
|
|
17
|
+
import { createRoutesPlugin, routeModuleSpecifier, routeSourcePaths } from "../plugin/routes.ts";
|
|
14
18
|
import { isomorphicTransformPlugin } from "../plugin/transform-isomorphic.ts";
|
|
15
19
|
import { environmentGuardPlugin } from "../rsc/build/environment.ts";
|
|
16
20
|
import { buildRscGraph } from "../rsc/build/index.ts";
|
|
17
21
|
import { ssgRouteCache } from "../server/cache/ssg.ts";
|
|
18
22
|
import { generateProdIndexHtml } from "../server/render/shell.ts";
|
|
19
23
|
import { setProductionTemplateContent } from "../server/render/template.ts";
|
|
20
|
-
import type { ResolvedRoute, RootLayout } from "../server/router/
|
|
24
|
+
import type { ResolvedRoute, RootLayout } from "../server/router/types.ts";
|
|
21
25
|
import { clientDirNameForPrefix } from "../shared/prefix.ts";
|
|
22
26
|
|
|
23
27
|
// import.meta.resolve() runs at runtime (not inlined at bundle time), resolves
|
|
@@ -37,10 +41,9 @@ const _ext = ".ts";
|
|
|
37
41
|
const BUILD_ID_INPUT_PATHS = [
|
|
38
42
|
`${_pkgSrcDir}/build/compile-entry${_ext}`,
|
|
39
43
|
`${_pkgSrcDir}/build/entry-template${_ext}`,
|
|
40
|
-
`${_pkgSrcDir}/
|
|
44
|
+
`${_pkgSrcDir}/plugin/routes${_ext}`,
|
|
41
45
|
`${_pkgSrcDir}/server/render/index${_ext}`,
|
|
42
46
|
`${_pkgSrcDir}/server/render/shell${_ext}`,
|
|
43
|
-
`${_pkgSrcDir}/server/router/index${_ext}`,
|
|
44
47
|
];
|
|
45
48
|
|
|
46
49
|
function compareCodeUnits(a: string, b: string): number {
|
|
@@ -53,6 +56,18 @@ function compareCodeUnits(a: string, b: string): number {
|
|
|
53
56
|
return 0;
|
|
54
57
|
}
|
|
55
58
|
|
|
59
|
+
function generateDiskEntry(options: BuildEntryOptions): string {
|
|
60
|
+
ensureDir(options.outDir);
|
|
61
|
+
const source = buildEntrySource({
|
|
62
|
+
apps: options.apps.map(({ embed: _embed, ...context }) => context),
|
|
63
|
+
headerComment: "// Auto-generated by furin build - do not edit",
|
|
64
|
+
serverEntry: options.serverEntry,
|
|
65
|
+
});
|
|
66
|
+
const entryPath = join(options.outDir, "server.ts");
|
|
67
|
+
writeFileSync(entryPath, source);
|
|
68
|
+
return entryPath;
|
|
69
|
+
}
|
|
70
|
+
|
|
56
71
|
/**
|
|
57
72
|
* Deterministic build-ID input covering everything that can change rendered
|
|
58
73
|
* output: client chunks, route shape, route/root/error/not-found source
|
|
@@ -130,9 +145,9 @@ function buildCompileMetadata(root: RootLayout, routes: ResolvedRoute[]) {
|
|
|
130
145
|
routeMetadata[toPosixPath(route.path)] = {
|
|
131
146
|
segmentBoundaries: route.segmentBoundaries.map((b) => ({
|
|
132
147
|
depth: b.depth,
|
|
133
|
-
path: toPosixPath(b.path),
|
|
134
148
|
errorPath: b.errorPath ? toPosixPath(b.errorPath) : undefined,
|
|
135
149
|
notFoundPath: b.notFoundPath ? toPosixPath(b.notFoundPath) : undefined,
|
|
150
|
+
path: toPosixPath(b.path),
|
|
136
151
|
})),
|
|
137
152
|
};
|
|
138
153
|
}
|
|
@@ -164,13 +179,14 @@ async function buildOneApp(
|
|
|
164
179
|
const label = prefix === "" ? "root app" : `app "${prefix}"`;
|
|
165
180
|
|
|
166
181
|
const { entryChunk, cssChunks } = await buildClient(routes, {
|
|
182
|
+
basePath: prefix,
|
|
183
|
+
clientDirName,
|
|
184
|
+
clientLogging: options.clientLogging ?? false,
|
|
167
185
|
outDir: targetDir,
|
|
168
|
-
|
|
186
|
+
pagesDir: app.pagesDir,
|
|
169
187
|
plugins: options.plugins,
|
|
170
188
|
publicPath: `${prefix}/_client/`,
|
|
171
|
-
|
|
172
|
-
clientLogging: options.clientLogging ?? false,
|
|
173
|
-
clientDirName,
|
|
189
|
+
rootLayout: root.path,
|
|
174
190
|
});
|
|
175
191
|
|
|
176
192
|
const buildFingerprint = await createBuildFingerprint(
|
|
@@ -209,13 +225,15 @@ async function buildOneApp(
|
|
|
209
225
|
entryApp: {
|
|
210
226
|
buildId,
|
|
211
227
|
clientLogging: options.clientLogging ?? false,
|
|
228
|
+
embed: options.compile === "embed" ? { clientDir } : undefined,
|
|
229
|
+
modulePaths: routeSourcePaths({ pagesDir: app.pagesDir, prefix }),
|
|
230
|
+
nativeRoutes: routeModuleSpecifier(app),
|
|
212
231
|
prefix,
|
|
213
|
-
rootPath: root.path,
|
|
214
|
-
routes: routes.map((r) => ({ pattern: r.pattern, path: r.path, mode: r.mode })),
|
|
215
232
|
rootConventions,
|
|
233
|
+
rootPath: root.path,
|
|
216
234
|
routeMetadata,
|
|
235
|
+
routes: routes.map((r) => ({ mode: r.mode, path: r.path, pattern: r.pattern })),
|
|
217
236
|
ssgCache,
|
|
218
|
-
embed: options.compile === "embed" ? { clientDir } : undefined,
|
|
219
237
|
},
|
|
220
238
|
hydrateIntermediate:
|
|
221
239
|
clientDirName === "client" ? "_hydrate.tsx" : `_hydrate-${clientDirName}.tsx`,
|
|
@@ -298,23 +316,24 @@ export async function buildBunTarget(
|
|
|
298
316
|
|
|
299
317
|
const entryPath = generateCompileEntry({
|
|
300
318
|
apps: entryApps,
|
|
301
|
-
serverEntry,
|
|
302
319
|
outDir: targetDir,
|
|
303
320
|
publicDir,
|
|
321
|
+
serverEntry,
|
|
304
322
|
});
|
|
305
323
|
|
|
306
324
|
await runBunBuild({
|
|
307
|
-
entrypoints: [entryPath],
|
|
308
325
|
compile: { outfile },
|
|
309
|
-
minify: true,
|
|
310
|
-
sourcemap: "none",
|
|
311
326
|
define: { "process.env.NODE_ENV": JSON.stringify("production") },
|
|
327
|
+
entrypoints: [entryPath],
|
|
328
|
+
minify: true,
|
|
312
329
|
plugins: [
|
|
313
330
|
productionInstrumentationPlugin(),
|
|
314
331
|
...(options.plugins ?? []),
|
|
332
|
+
createRoutesPlugin({ instances: apps, target: "server" }),
|
|
315
333
|
isomorphicTransformPlugin("server"),
|
|
316
334
|
environmentGuardPlugin("ssr"),
|
|
317
335
|
],
|
|
336
|
+
sourcemap: "none",
|
|
318
337
|
});
|
|
319
338
|
|
|
320
339
|
console.log(`[furin] Server binary: ${outfile}`);
|
|
@@ -334,24 +353,25 @@ export async function buildBunTarget(
|
|
|
334
353
|
}
|
|
335
354
|
} else if (serverEntry) {
|
|
336
355
|
// Disk mode: generate server.ts then bundle it into self-contained server.js
|
|
337
|
-
const entryPath =
|
|
356
|
+
const entryPath = generateDiskEntry({
|
|
338
357
|
apps: entryApps,
|
|
339
|
-
serverEntry,
|
|
340
358
|
outDir: targetDir,
|
|
359
|
+
serverEntry,
|
|
341
360
|
});
|
|
342
361
|
|
|
343
362
|
await runBunBuild({
|
|
344
363
|
entrypoints: [entryPath],
|
|
345
|
-
outdir: targetDir,
|
|
346
|
-
target: "bun",
|
|
347
364
|
minify: true,
|
|
348
|
-
|
|
365
|
+
outdir: targetDir,
|
|
349
366
|
plugins: [
|
|
350
367
|
productionInstrumentationPlugin(),
|
|
351
368
|
...(options.plugins ?? []),
|
|
369
|
+
createRoutesPlugin({ instances: apps, target: "server" }),
|
|
352
370
|
isomorphicTransformPlugin("server"),
|
|
353
371
|
environmentGuardPlugin("ssr"),
|
|
354
372
|
],
|
|
373
|
+
sourcemap: "none",
|
|
374
|
+
target: "bun",
|
|
355
375
|
});
|
|
356
376
|
console.log(
|
|
357
377
|
`[furin] Server bundle: ${toPosixPath(join(targetManifest.targetDir, "server.js"))}`
|
package/src/adapter/package.ts
CHANGED
|
@@ -7,6 +7,7 @@ import { buildEntrySource } from "../build/entry-template.ts";
|
|
|
7
7
|
import { copyDirRecursive, ensureDir, toPosixPath } from "../build/shared.ts";
|
|
8
8
|
import { buildSSGCacheSnapshot } from "../build/ssg-cache.ts";
|
|
9
9
|
import type { BuildAppOptions, PackageTargetBuildManifest } from "../build/types.ts";
|
|
10
|
+
import { createRoutesPlugin, routeModuleSpecifier, routeSourcePaths } from "../plugin/routes.ts";
|
|
10
11
|
import { ssgRouteCache } from "../server/cache/ssg.ts";
|
|
11
12
|
import { generateProdIndexHtml } from "../server/render/shell.ts";
|
|
12
13
|
import { setProductionTemplateContent } from "../server/render/template.ts";
|
|
@@ -47,12 +48,13 @@ export async function buildPackageTarget(
|
|
|
47
48
|
ensureDir(targetDir);
|
|
48
49
|
|
|
49
50
|
const { entryChunk, cssChunks } = await buildClient(routes, {
|
|
51
|
+
basePath: prefix,
|
|
52
|
+
clientLogging: options.clientLogging ?? false,
|
|
50
53
|
outDir: targetDir,
|
|
51
|
-
|
|
54
|
+
pagesDir,
|
|
52
55
|
plugins: options.plugins,
|
|
53
56
|
publicPath: `${prefix}/_client/`,
|
|
54
|
-
|
|
55
|
-
clientLogging: options.clientLogging ?? false,
|
|
57
|
+
rootLayout: root.path,
|
|
56
58
|
});
|
|
57
59
|
|
|
58
60
|
// Same fingerprint as the Bun target: hashing only the client chunks would
|
|
@@ -109,9 +111,9 @@ export async function buildPackageTarget(
|
|
|
109
111
|
routeMetadata[toPosixPath(route.path)] = {
|
|
110
112
|
segmentBoundaries: route.segmentBoundaries.map((b) => ({
|
|
111
113
|
depth: b.depth,
|
|
112
|
-
path: toPosixPath(b.path),
|
|
113
114
|
errorPath: b.errorPath ? toPosixPath(b.errorPath) : undefined,
|
|
114
115
|
notFoundPath: b.notFoundPath ? toPosixPath(b.notFoundPath) : undefined,
|
|
116
|
+
path: toPosixPath(b.path),
|
|
115
117
|
})),
|
|
116
118
|
};
|
|
117
119
|
}
|
|
@@ -122,11 +124,13 @@ export async function buildPackageTarget(
|
|
|
122
124
|
{
|
|
123
125
|
buildId,
|
|
124
126
|
clientLogging: options.clientLogging ?? false,
|
|
127
|
+
modulePaths: routeSourcePaths({ pagesDir, prefix }),
|
|
128
|
+
nativeRoutes: routeModuleSpecifier(app),
|
|
125
129
|
prefix,
|
|
126
|
-
rootPath: root.path,
|
|
127
|
-
routes: routes.map((r) => ({ pattern: r.pattern, path: r.path, mode: r.mode })),
|
|
128
130
|
rootConventions,
|
|
131
|
+
rootPath: root.path,
|
|
129
132
|
routeMetadata,
|
|
133
|
+
routes: routes.map((r) => ({ mode: r.mode, path: r.path, pattern: r.pattern })),
|
|
130
134
|
ssgCache,
|
|
131
135
|
},
|
|
132
136
|
],
|
|
@@ -138,16 +142,19 @@ export async function buildPackageTarget(
|
|
|
138
142
|
|
|
139
143
|
const result = await runBunBuild({
|
|
140
144
|
entrypoints: [registerEntry],
|
|
145
|
+
minify: false,
|
|
146
|
+
naming: { chunk: "[name]-[hash].[ext]", entry: "[name].[ext]" },
|
|
141
147
|
outdir: targetDir,
|
|
142
|
-
target: "bun",
|
|
143
148
|
// Keep EVERY dependency external (incl. @teyik0/furin): the host must
|
|
144
149
|
// share one copy of the furin runtime with this register module — only
|
|
145
150
|
// the package's own page sources get bundled in.
|
|
146
151
|
packages: "external",
|
|
147
|
-
|
|
152
|
+
plugins: [
|
|
153
|
+
...(options.plugins ?? []),
|
|
154
|
+
createRoutesPlugin({ instances: [app], target: "server" }),
|
|
155
|
+
],
|
|
148
156
|
sourcemap: "none",
|
|
149
|
-
|
|
150
|
-
plugins: options.plugins,
|
|
157
|
+
target: "bun",
|
|
151
158
|
});
|
|
152
159
|
if (!result.success) {
|
|
153
160
|
throw new AggregateError(result.logs, "[furin] package register build failed");
|
|
@@ -172,7 +179,7 @@ const CLIENT_DIR = fileURLToPath(new URL("./client", import.meta.url));
|
|
|
172
179
|
*
|
|
173
180
|
* @param {object} [options] Extra furin() options (logger, sync, ...) —
|
|
174
181
|
* pagesDir/prefix/clientDir are baked into the package and cannot be overridden.
|
|
175
|
-
* @returns {
|
|
182
|
+
* @returns {ReturnType<typeof import("@teyik0/furin").furin>}
|
|
176
183
|
*/
|
|
177
184
|
export function createFurinApp(options = {}) {
|
|
178
185
|
return furin({
|
|
@@ -187,12 +194,11 @@ export const prefix = ${JSON.stringify(prefix)};
|
|
|
187
194
|
`;
|
|
188
195
|
writeFileSync(join(targetDir, "index.js"), factorySource);
|
|
189
196
|
|
|
190
|
-
const dtsSource = `import type {
|
|
191
|
-
import type { FurinOptions } from "@teyik0/furin";
|
|
197
|
+
const dtsSource = `import type { FurinOptions, furin } from "@teyik0/furin";
|
|
192
198
|
|
|
193
199
|
/** Extra furin() options — pagesDir/prefix/clientDir are baked into the package and cannot be overridden. */
|
|
194
200
|
export type CreateFurinAppOptions = Omit<FurinOptions, "pagesDir" | "prefix" | "clientDir">;
|
|
195
|
-
export declare function createFurinApp(options?: CreateFurinAppOptions):
|
|
201
|
+
export declare function createFurinApp(options?: CreateFurinAppOptions): ReturnType<typeof furin>;
|
|
196
202
|
export declare const prefix: string;
|
|
197
203
|
`;
|
|
198
204
|
writeFileSync(join(targetDir, "index.d.ts"), dtsSource);
|
package/src/adapter/static.ts
CHANGED
|
@@ -228,13 +228,13 @@ async function buildTaskQueue(
|
|
|
228
228
|
// would throw out of `for...of` and abort the entire build.
|
|
229
229
|
if (!Array.isArray(result.paramSets)) {
|
|
230
230
|
console.error(
|
|
231
|
-
`[furin] static: staticParams() for "${
|
|
231
|
+
`[furin] static: staticParams() for "${pattern}" returned a non-array value; skipping route.`
|
|
232
232
|
);
|
|
233
|
-
skippedRoutes.push(
|
|
233
|
+
skippedRoutes.push(pattern);
|
|
234
234
|
continue;
|
|
235
235
|
}
|
|
236
236
|
for (const params of result.paramSets) {
|
|
237
|
-
const urlPath = resolvePath(
|
|
237
|
+
const urlPath = resolvePath(pattern, params);
|
|
238
238
|
pathToOutputFile(urlPath, outDir, "index.html");
|
|
239
239
|
tasks.push(() =>
|
|
240
240
|
prerenderAndWrite(
|
|
@@ -389,6 +389,7 @@ export async function buildStaticTarget(
|
|
|
389
389
|
basePath,
|
|
390
390
|
clientLogging: Boolean(options.clientLogging),
|
|
391
391
|
outDir: targetDir,
|
|
392
|
+
pagesDir: dirname(root.path),
|
|
392
393
|
plugins: options.plugins,
|
|
393
394
|
publicPath,
|
|
394
395
|
rootLayout: root.path,
|
package/src/build/client.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { existsSync, mkdirSync, writeFileSync } from "node:fs";
|
|
2
2
|
import { basename, join } from "node:path";
|
|
3
3
|
import { transformForClient } from "../plugin/transform-client";
|
|
4
|
+
import { createRoutesPlugin } from "../plugin/routes.ts";
|
|
4
5
|
import { environmentGuardPlugin } from "../rsc/build/environment.ts";
|
|
5
6
|
import { detectLoaderFromPath } from "../server/lang-detect.ts";
|
|
6
|
-
import type { ResolvedRoute } from "../server/router/
|
|
7
|
+
import type { ResolvedRoute } from "../server/router/types.ts";
|
|
7
8
|
import { runBunBuild } from "./bun-build.ts";
|
|
8
9
|
import { generateHydrateEntry } from "./hydrate";
|
|
9
10
|
import { CLIENT_MODULE_PATH, LINK_MODULE_PATH, SEARCH_MODULE_PATH } from "./shared";
|
|
@@ -36,7 +37,16 @@ export interface BuildClientResult {
|
|
|
36
37
|
*/
|
|
37
38
|
export async function buildClient(
|
|
38
39
|
routes: ResolvedRoute[],
|
|
39
|
-
{
|
|
40
|
+
{
|
|
41
|
+
outDir,
|
|
42
|
+
rootLayout,
|
|
43
|
+
plugins,
|
|
44
|
+
publicPath,
|
|
45
|
+
basePath,
|
|
46
|
+
clientLogging,
|
|
47
|
+
clientDirName,
|
|
48
|
+
pagesDir,
|
|
49
|
+
}: BuildClientOptions
|
|
40
50
|
): Promise<BuildClientResult> {
|
|
41
51
|
// Per-app client dir so several mounted apps build side by side
|
|
42
52
|
// ("client", "client-admin", …) without clobbering each other.
|
|
@@ -112,7 +122,14 @@ export async function buildClient(
|
|
|
112
122
|
// Overridable via the `publicPath` option (e.g. "/furin/_client/" for basePath builds).
|
|
113
123
|
publicPath,
|
|
114
124
|
// User plugins run before the internal transform so they pre-process files first
|
|
115
|
-
plugins: [
|
|
125
|
+
plugins: [
|
|
126
|
+
...(plugins ?? []),
|
|
127
|
+
...(pagesDir
|
|
128
|
+
? [createRoutesPlugin({ instances: [{ pagesDir, prefix: basePath }], target: "client" })]
|
|
129
|
+
: []),
|
|
130
|
+
environmentGuardPlugin("client"),
|
|
131
|
+
transformPlugin,
|
|
132
|
+
],
|
|
116
133
|
alias: {
|
|
117
134
|
"@teyik0/furin/client": CLIENT_MODULE_PATH,
|
|
118
135
|
"@teyik0/furin/link": LINK_MODULE_PATH,
|
|
@@ -26,6 +26,10 @@ export interface EntryAppContext {
|
|
|
26
26
|
extraContext?: string[];
|
|
27
27
|
/** Extra import lines this app needs (embedded asset imports). */
|
|
28
28
|
extraImports?: string[];
|
|
29
|
+
/** Additional route modules such as filesystem-derived `_route` layouts. */
|
|
30
|
+
modulePaths?: string[];
|
|
31
|
+
/** Virtual module specifier exporting this app's composed Elysia route tree. */
|
|
32
|
+
nativeRoutes?: string;
|
|
29
33
|
/** Mount prefix baked into the context for runtime lookup (`""` = root). */
|
|
30
34
|
prefix?: string;
|
|
31
35
|
rootConventions?: { errorPath?: string; notFoundPath?: string };
|
|
@@ -112,9 +116,12 @@ function buildAppContextBlock(
|
|
|
112
116
|
varPrefix: string
|
|
113
117
|
): { contextLines: string[]; importLines: string[] } {
|
|
114
118
|
const allModulePaths = [
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
119
|
+
...new Set([
|
|
120
|
+
app.rootPath,
|
|
121
|
+
...app.routes.map((r) => r.path),
|
|
122
|
+
...(app.modulePaths ?? []),
|
|
123
|
+
...collectConventionPaths(app.rootConventions, app.routeMetadata),
|
|
124
|
+
]),
|
|
118
125
|
];
|
|
119
126
|
const importLines: string[] = [];
|
|
120
127
|
const moduleEntries: string[] = [];
|
|
@@ -125,6 +132,12 @@ function buildAppContextBlock(
|
|
|
125
132
|
importLines.push(`import * as ${varName} from ${JSON.stringify(absPath)};`);
|
|
126
133
|
moduleEntries.push(` ${JSON.stringify(absPath)}: ${varName},`);
|
|
127
134
|
}
|
|
135
|
+
const nativeRoutesVar = `${varPrefix}furinApp`;
|
|
136
|
+
if (app.nativeRoutes) {
|
|
137
|
+
importLines.push(
|
|
138
|
+
`import { furinApp as ${nativeRoutesVar} } from ${JSON.stringify(app.nativeRoutes)};`
|
|
139
|
+
);
|
|
140
|
+
}
|
|
128
141
|
|
|
129
142
|
const routeEntries = app.routes.map(
|
|
130
143
|
(r) =>
|
|
@@ -145,6 +158,7 @@ function buildAppContextBlock(
|
|
|
145
158
|
` clientLogging: ${JSON.stringify(app.clientLogging ?? false)},`,
|
|
146
159
|
` prefix: ${JSON.stringify(app.prefix ?? "")},`,
|
|
147
160
|
` rootPath: ${JSON.stringify(app.rootPath.replace(/\\/g, "/"))},`,
|
|
161
|
+
app.nativeRoutes ? ` nativeRoutes: ${nativeRoutesVar},` : "",
|
|
148
162
|
rootConventionsLine,
|
|
149
163
|
" modules: {",
|
|
150
164
|
...moduleEntries,
|