@teyik0/furin 0.3.0-alpha.1 → 0.4.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/adapter/bun.d.ts +2 -18
- package/dist/adapter/package.d.ts +2 -2
- package/dist/adapter/runtime-build.d.ts +33 -0
- package/dist/adapter/vercel.d.ts +3 -0
- package/dist/build/client.d.ts +2 -2
- package/dist/build/compile-entry.d.ts +4 -3
- package/dist/build/compile-entry.ts +24 -69
- package/dist/build/entry-template.d.ts +8 -2
- package/dist/build/entry-template.ts +48 -11
- package/dist/build/index.d.ts +2 -2
- package/dist/build/index.js +11720 -7840
- package/dist/build/route-types.d.ts +2 -22
- package/dist/build/shared.d.ts +1 -1
- package/dist/build/ssg-cache.d.ts +14 -1
- package/dist/build/types.d.ts +26 -3
- package/dist/build/virtual-entry.d.ts +8 -0
- package/dist/cache.d.ts +5 -0
- package/dist/cache.js +97 -0
- package/dist/cli/index.js +11815 -7793
- package/dist/cli/preview.d.ts +7 -0
- package/dist/client/boundaries.d.ts +3 -0
- package/dist/client/browser-events-runtime.d.ts +2 -0
- package/dist/client/browser-events.d.ts +2 -0
- package/dist/client/define-route.d.ts +36 -0
- package/dist/client/dev-error-overlay.d.ts +1 -0
- package/dist/client/dev-error-overlay.ts +201 -0
- package/dist/client/document.d.ts +27 -0
- package/dist/client/hmr.d.ts +12 -0
- package/dist/client/internal/runtime-types.d.ts +3 -1
- package/dist/client/link.js +1392 -940
- package/dist/client/router/index.d.ts +1 -1
- package/dist/client/router/link-utils.d.ts +9 -0
- package/dist/client/router/provider.d.ts +1 -1
- package/dist/client/router/search/index.d.ts +3 -7
- package/dist/client/router/sync-catch-up.d.ts +1 -1
- package/dist/client/router/types.d.ts +40 -34
- package/dist/client.d.ts +4 -159
- package/dist/client.js +197 -21
- package/dist/config.d.ts +25 -8
- package/dist/config.js +15 -7
- package/dist/define-route.d.ts +1358 -0
- package/dist/devtools/protocol.d.ts +2 -2
- package/dist/furin.d.ts +18 -34
- package/dist/furin.js +16038 -9395
- package/dist/plugin/index.js +1401 -223
- package/dist/plugin/route-config-autofix.d.ts +31 -0
- package/dist/plugin/routes.d.ts +28 -0
- package/dist/routes.d.ts +6 -0
- package/dist/routes.js +1 -0
- package/dist/rsc/build/index.d.ts +6 -2
- package/dist/rsc.js +3 -3
- package/dist/server/browser-events/plugin.d.ts +11 -0
- package/dist/server/browser-events/types.d.ts +9 -0
- package/dist/server/cache/invalidation.d.ts +1 -2
- package/dist/server/cache/isr.d.ts +1 -0
- package/dist/server/cache/purger.d.ts +7 -0
- package/dist/server/cache/runtime-cache.d.ts +21 -0
- package/dist/server/dev/browser-events.d.ts +4 -0
- package/dist/server/dev/diagnostics.d.ts +39 -0
- package/dist/server/dev/error.d.ts +17 -0
- package/dist/server/dev/graph.d.ts +86 -0
- package/dist/server/dev/plugin.d.ts +9 -0
- package/dist/server/dev/request-security.d.ts +1 -0
- package/dist/server/dev/rewrite-module-specifiers.d.ts +7 -0
- package/dist/server/dev/runtime.production.d.ts +5 -0
- package/dist/server/dev/symbolicate.d.ts +11 -0
- package/dist/server/dev/transform-failure.d.ts +4 -0
- package/dist/server/dev-page-plugin.d.ts +7 -5
- package/dist/server/dev-page-plugin.production.d.ts +1 -0
- package/dist/server/devtools/hub.d.ts +3 -2
- 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/external-prerender.d.ts +2 -0
- package/dist/server/instance.d.ts +2 -2
- package/dist/server/internal.d.ts +17 -2
- package/dist/server/internal.js +436 -1
- 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 +3 -1
- package/dist/server/render/index.d.ts +2 -2
- package/dist/server/render/index.ts +1 -2
- 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-document.d.ts +21 -0
- package/dist/server/render/ppr-request.d.ts +26 -0
- package/dist/server/render/ppr-route.d.ts +4 -2
- package/dist/server/render/shell.ts +0 -12
- package/dist/server/render/ssg.d.ts +3 -1
- package/dist/server/render/ssr.d.ts +23 -11
- 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/hmr.production.d.ts +2 -0
- package/dist/server/router/patterns.d.ts +7 -0
- package/dist/server/router/plugin.d.ts +6 -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/adapter.d.ts +13 -0
- package/dist/server/sync/config.d.ts +5 -5
- package/dist/server/sync/index.d.ts +6 -6
- package/dist/server/sync/index.js +1115 -985
- package/dist/server/sync/notifier.d.ts +1 -0
- package/dist/server/sync/postgres/index.d.ts +12 -1
- package/dist/server/sync/postgres/index.js +101 -6
- package/dist/server/sync/postgres/migrate.js +3 -2
- package/dist/server/sync/stream.d.ts +4 -13
- package/dist/shared/await.d.ts +4 -5
- package/dist/shared/browser-events.d.ts +22 -0
- package/dist/shared/compact-json.d.ts +8 -0
- package/dist/shared/deferred-ndjson.d.ts +6 -5
- package/dist/shared/dev-diagnostics.d.ts +36 -0
- package/dist/shared/elysia-contract.d.ts +41 -0
- package/dist/shared/prefix.d.ts +2 -0
- package/dist/shared/route-map.d.ts +5 -0
- package/dist/shared/utils/index.d.ts +1 -3
- package/package.json +55 -43
- package/src/adapter/README.md +45 -0
- package/src/adapter/bun.ts +62 -265
- package/src/adapter/package.ts +34 -22
- package/src/adapter/runtime-build.ts +375 -0
- package/src/adapter/static.ts +83 -5
- package/src/adapter/vercel.ts +857 -0
- package/src/build/client.ts +58 -16
- package/src/build/compile-entry.ts +24 -69
- package/src/build/entry-template.ts +48 -11
- package/src/build/hydrate.ts +147 -37
- package/src/build/index.ts +21 -7
- package/src/build/production-instrumentation.ts +56 -4
- package/src/build/route-types.ts +19 -114
- package/src/build/shared.ts +3 -2
- package/src/build/ssg-cache.ts +99 -16
- package/src/build/types.ts +32 -3
- package/src/build/virtual-entry.ts +27 -0
- package/src/cache.ts +14 -0
- package/src/cli/config.ts +3 -3
- package/src/cli/index.ts +62 -10
- package/src/cli/preview.ts +90 -0
- package/src/client/boundaries.tsx +19 -2
- package/src/client/browser-events-runtime.ts +204 -0
- package/src/client/browser-events.ts +22 -0
- package/src/client/define-route.ts +38 -0
- package/src/client/dev-error-overlay.ts +201 -0
- package/src/client/document.tsx +162 -0
- package/src/client/hmr.ts +63 -0
- package/src/client/internal/runtime-types.ts +3 -1
- package/src/client/link.tsx +21 -6
- package/src/client/router/boundary-tree.tsx +4 -4
- package/src/client/router/index.ts +1 -0
- package/src/client/router/link-utils.ts +26 -0
- package/src/client/router/provider.tsx +190 -65
- package/src/client/router/search/index.ts +4 -12
- package/src/client/router/sync-catch-up.ts +3 -4
- package/src/client/router/types.ts +56 -30
- package/src/client.ts +14 -316
- package/src/config.ts +35 -10
- package/src/define-route.ts +972 -0
- package/src/devtools/devtools-element.js +67 -87
- package/src/devtools/protocol.ts +2 -2
- package/src/furin.ts +431 -101
- package/src/plugin/route-config-autofix.ts +1140 -0
- package/src/plugin/routes.ts +1061 -0
- package/src/plugin/transform-client.ts +776 -228
- package/src/plugin/transform-isomorphic.ts +1 -1
- package/src/react-dom-edge.d.ts +6 -0
- package/src/routes.ts +6 -0
- package/src/rsc/build/index.ts +16 -4
- package/src/server/auto-invalidate/registry.ts +2 -2
- package/src/server/auto-invalidate/runtime.ts +5 -2
- package/src/server/browser-events/plugin.ts +168 -0
- package/src/server/browser-events/types.ts +11 -0
- package/src/server/cache/dev-loader.ts +30 -29
- package/src/server/cache/invalidation.ts +13 -22
- package/src/server/cache/isr.ts +9 -0
- package/src/server/cache/purger.ts +41 -0
- package/src/server/cache/runtime-cache.ts +137 -0
- package/src/server/dev/browser-events.ts +54 -0
- package/src/server/dev/diagnostics.ts +297 -0
- package/src/server/dev/error.ts +148 -0
- package/src/server/dev/graph.ts +438 -0
- package/src/server/dev/plugin.ts +130 -0
- package/src/server/dev/request-security.ts +38 -0
- package/src/server/dev/rewrite-module-specifiers.ts +81 -0
- package/src/server/dev/runtime.production.ts +24 -0
- package/src/server/dev/symbolicate.ts +135 -0
- package/src/server/dev/transform-failure.ts +8 -0
- package/src/server/dev-page-plugin.production.ts +3 -0
- package/src/server/dev-page-plugin.ts +110 -52
- package/src/server/devtools/hub.ts +6 -5
- package/src/server/devtools/instrumentation.production.ts +3 -3
- package/src/server/devtools/instrumentation.ts +14 -8
- package/src/server/devtools/plugin.ts +12 -153
- package/src/server/external-prerender.ts +10 -0
- package/src/server/instance.ts +5 -5
- package/src/server/internal.ts +42 -2
- package/src/server/logger.ts +21 -0
- package/src/server/render/assemble.ts +4 -45
- package/src/server/render/document.tsx +34 -0
- package/src/server/render/element.tsx +31 -15
- package/src/server/render/index.ts +1 -2
- package/src/server/render/isr.ts +70 -24
- package/src/server/render/loaders.ts +43 -8
- package/src/server/render/not-found.ts +77 -29
- package/src/server/render/ppr-document.ts +239 -0
- package/src/server/render/ppr-request.ts +104 -0
- package/src/server/render/ppr-route.ts +153 -32
- package/src/server/render/shell.ts +0 -12
- package/src/server/render/ssg.ts +39 -21
- package/src/server/render/ssr.ts +429 -143
- package/src/server/render/template.ts +128 -2
- package/src/server/router/defined-route.ts +78 -0
- package/src/server/router/discovery.ts +129 -29
- package/src/server/router/hmr.production.ts +7 -0
- package/src/server/router/hmr.ts +177 -67
- package/src/server/router/patterns.ts +45 -13
- package/src/server/router/plugin.ts +184 -78
- package/src/server/router/schema-merge.ts +4 -14
- package/src/server/router/schemas.ts +11 -8
- package/src/server/router/source-version.ts +9 -0
- package/src/server/router/types.ts +2 -0
- package/src/server/sync/adapter.ts +13 -0
- package/src/server/sync/config.ts +12 -12
- package/src/server/sync/index.ts +8 -8
- package/src/server/sync/notifier.ts +1 -0
- package/src/server/sync/plugin.ts +4 -1
- package/src/server/sync/postgres/index.ts +111 -5
- package/src/server/sync/postgres/migrate.ts +3 -2
- package/src/server/sync/response.ts +14 -10
- package/src/server/sync/runtime.ts +12 -0
- package/src/server/sync/stream.ts +78 -113
- package/src/shared/await.tsx +4 -5
- package/src/shared/browser-events.ts +28 -0
- package/src/shared/compact-json.ts +77 -0
- package/src/shared/deferred-ndjson.ts +20 -6
- package/src/shared/dev-diagnostics.ts +44 -0
- package/src/shared/elysia-contract.ts +63 -0
- package/src/shared/prefix.ts +8 -0
- package/src/shared/route-map.ts +46 -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
package/dist/adapter/bun.d.ts
CHANGED
|
@@ -1,19 +1,3 @@
|
|
|
1
1
|
import type { BuildAppOptions, TargetBuildManifest } from "../build/types.ts";
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
* Deterministic build-ID input covering everything that can change rendered
|
|
5
|
-
* output: client chunks, route shape, route/root/error/not-found source
|
|
6
|
-
* contents and the framework's own render pipeline sources. Shared with the
|
|
7
|
-
* package target so packaged apps get the same stale-deploy detection —
|
|
8
|
-
* SSR-only changes (loader/page code that never reaches the client bundle)
|
|
9
|
-
* must still produce a new build ID.
|
|
10
|
-
*/
|
|
11
|
-
export declare function createBuildFingerprint(entryChunk: string, cssChunks: string[], routes: ResolvedRoute[], root: RootLayout, serverEntry: string | null): Promise<string>;
|
|
12
|
-
/** One mounted app's build input (root + routes scanned from its pagesDir). */
|
|
13
|
-
export interface BunTargetApp {
|
|
14
|
-
pagesDir: string;
|
|
15
|
-
prefix: string;
|
|
16
|
-
root: RootLayout;
|
|
17
|
-
routes: ResolvedRoute[];
|
|
18
|
-
}
|
|
19
|
-
export declare function buildBunTarget(apps: BunTargetApp[], rootDir: string, buildRoot: string, serverEntry: string | null, options: BuildAppOptions): Promise<TargetBuildManifest>;
|
|
2
|
+
import { type RuntimeTargetApp } from "./runtime-build.ts";
|
|
3
|
+
export declare function buildBunTarget(apps: RuntimeTargetApp[], rootDir: string, buildRoot: string, serverEntry: string | null, options: BuildAppOptions): Promise<TargetBuildManifest>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type RuntimeTargetApp } from "../adapter/runtime-build.ts";
|
|
2
2
|
import type { BuildAppOptions, PackageTargetBuildManifest } from "../build/types.ts";
|
|
3
3
|
/**
|
|
4
4
|
* `--target package` — builds a furin app as a PUBLISHABLE Elysia plugin
|
|
@@ -23,4 +23,4 @@ import type { BuildAppOptions, PackageTargetBuildManifest } from "../build/types
|
|
|
23
23
|
* so the same factory works under `bun --hot` (dev scans live). A published
|
|
24
24
|
* package without sources is production-only; its context is found by prefix.
|
|
25
25
|
*/
|
|
26
|
-
export declare function buildPackageTarget(app:
|
|
26
|
+
export declare function buildPackageTarget(app: RuntimeTargetApp, rootDir: string, buildRoot: string, options: BuildAppOptions): Promise<PackageTargetBuildManifest>;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { BuildEntryOptions } from "../build/entry-template.ts";
|
|
2
|
+
import { type RoutePrerender } from "../build/ssg-cache.ts";
|
|
3
|
+
import type { BuildAppOptions } from "../build/types.ts";
|
|
4
|
+
import type { ResolvedRoute, RootLayout } from "../server/router/types.ts";
|
|
5
|
+
/**
|
|
6
|
+
* Deterministic build-ID input covering everything that can change rendered
|
|
7
|
+
* output: client chunks, route shape, route/root/error/not-found source
|
|
8
|
+
* contents and the framework's own render pipeline sources.
|
|
9
|
+
*/
|
|
10
|
+
export declare function createBuildFingerprint(entryChunk: string, cssChunks: string[], routes: ResolvedRoute[], root: RootLayout, serverEntry: string | null, routeSources: string[], projectRoot: string): Promise<string>;
|
|
11
|
+
/** One mounted app's build input (root + routes scanned from its pagesDir). */
|
|
12
|
+
export interface RuntimeTargetApp {
|
|
13
|
+
pagesDir: string;
|
|
14
|
+
prefix: string;
|
|
15
|
+
root: RootLayout;
|
|
16
|
+
routes: ResolvedRoute[];
|
|
17
|
+
}
|
|
18
|
+
/** Avoid loading React's resumable renderer in applications without PPR routes. */
|
|
19
|
+
export declare function pprRuntimePlugin(apps: RuntimeTargetApp[]): Bun.BunPlugin;
|
|
20
|
+
export interface RuntimeAppBuild {
|
|
21
|
+
buildId: string;
|
|
22
|
+
clientDir: string;
|
|
23
|
+
entryApp: BuildEntryOptions["apps"][number];
|
|
24
|
+
indexHtml: string;
|
|
25
|
+
prerenders: RoutePrerender[];
|
|
26
|
+
}
|
|
27
|
+
/** Builds one app's client bundle and compile-context payload. */
|
|
28
|
+
export declare function buildRuntimeApp(app: RuntimeTargetApp, projectRoot: string, targetDir: string, serverEntry: string | null, options: BuildAppOptions, targetName: "bun" | "vercel"): Promise<RuntimeAppBuild>;
|
|
29
|
+
export declare function buildRuntimeAppsSequentially(apps: RuntimeTargetApp[], projectRoot: string, targetDir: string, serverEntry: string | null, options: BuildAppOptions, targetName: "bun" | "vercel"): Promise<{
|
|
30
|
+
builds: RuntimeAppBuild[];
|
|
31
|
+
entryApps: BuildEntryOptions["apps"];
|
|
32
|
+
headlineBuildId: string;
|
|
33
|
+
}>;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { BuildAppOptions, VercelTargetBuildManifest } from "../build/types.ts";
|
|
2
|
+
import { type RuntimeTargetApp } from "./runtime-build.ts";
|
|
3
|
+
export declare function buildVercelTarget(apps: RuntimeTargetApp[], rootDir: string, buildRoot: string, serverEntry: string, options: BuildAppOptions): Promise<VercelTargetBuildManifest>;
|
package/dist/build/client.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ResolvedRoute } from "../server/router/
|
|
1
|
+
import type { ResolvedRoute } from "../server/router/types.ts";
|
|
2
2
|
import type { BuildClientOptions } from "./types";
|
|
3
3
|
export interface BuildClientResult {
|
|
4
4
|
/** Public paths of all CSS chunks, e.g. `["/_client/chunk-abc.css"]` */
|
|
@@ -22,4 +22,4 @@ export interface BuildClientResult {
|
|
|
22
22
|
* it as an SSR template, injects the pre-rendered React HTML into
|
|
23
23
|
* <!--ssr-outlet-->, and sends the complete page.
|
|
24
24
|
*/
|
|
25
|
-
export declare function buildClient(routes: ResolvedRoute[], { outDir, rootLayout, plugins, publicPath, basePath, clientLogging, clientDirName }: BuildClientOptions): Promise<BuildClientResult>;
|
|
25
|
+
export declare function buildClient(routes: ResolvedRoute[], { outDir, rootLayout, plugins, publicPath, basePath, clientLogging, clientDirName, metafilePath, optimizeImports, reactCompiler, pagesDir, }: BuildClientOptions): Promise<BuildClientResult>;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { type BuildEntryOptions } from "./entry-template";
|
|
2
|
+
import { type VirtualBuildEntry } from "./virtual-entry.ts";
|
|
2
3
|
/**
|
|
3
|
-
* Generates a
|
|
4
|
+
* Generates a virtual `_compile-entry.ts` that:
|
|
4
5
|
* 1. Statically imports every page module of every app so Bun bundles them
|
|
5
|
-
* 2.
|
|
6
|
+
* 2. Points embed-mode contexts at Bun's `compile.assets` directories
|
|
6
7
|
* 3. Sets production mode and registers one CompileContext PER APP
|
|
7
8
|
* 4. Dynamically imports server.ts to boot the composed app
|
|
8
9
|
*/
|
|
9
|
-
export declare function generateCompileEntry(options: BuildEntryOptions):
|
|
10
|
+
export declare function generateCompileEntry(options: BuildEntryOptions): VirtualBuildEntry;
|
|
@@ -1,104 +1,60 @@
|
|
|
1
|
-
import { existsSync
|
|
2
|
-
import {
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import { basename, join } from "node:path";
|
|
3
3
|
import { buildEntrySource, type BuildEntryOptions, type EntryAppContext } from "./entry-template";
|
|
4
|
-
import {
|
|
4
|
+
import { ensureDir } from "./shared";
|
|
5
|
+
import { createVirtualBuildEntry, type VirtualBuildEntry } from "./virtual-entry.ts";
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
|
-
* Builds one app's embedded
|
|
8
|
-
*
|
|
9
|
-
* strips the mount path before lookup at runtime.
|
|
8
|
+
* Builds one app's embedded directory context. Bun places each directory from
|
|
9
|
+
* `compile.assets` below `import.meta.dir` in the standalone executable.
|
|
10
10
|
*/
|
|
11
|
-
function
|
|
12
|
-
outDir: string,
|
|
11
|
+
function buildEmbeddedContext(
|
|
13
12
|
clientDir: string,
|
|
14
|
-
publicDir: string | undefined
|
|
15
|
-
|
|
16
|
-
): { extraContext: string[]; extraImports: string[] } {
|
|
13
|
+
publicDir: string | undefined
|
|
14
|
+
): string[] {
|
|
17
15
|
if (!existsSync(clientDir)) {
|
|
18
16
|
throw new Error(
|
|
19
17
|
`[furin] Client directory not found: ${clientDir}. Run the client build first.`
|
|
20
18
|
);
|
|
21
19
|
}
|
|
22
|
-
|
|
23
|
-
const assetImports: string[] = [];
|
|
24
|
-
const assetEntries: string[] = [];
|
|
25
|
-
let templateVarName: string | null = null;
|
|
26
|
-
|
|
27
|
-
let assetIndex = 0;
|
|
28
|
-
const importAsset = (file: string): string => {
|
|
29
|
-
const varName = `${varPrefix}asset${assetIndex++}`;
|
|
30
|
-
const relPath = toPosixPath(relative(outDir, file));
|
|
31
|
-
const importPath = relPath.startsWith(".") ? relPath : `./${relPath}`;
|
|
32
|
-
assetImports.push(
|
|
33
|
-
`import ${varName} from ${JSON.stringify(importPath)} with { type: "file" };`
|
|
34
|
-
);
|
|
35
|
-
return varName;
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
for (const file of clientFiles) {
|
|
39
|
-
const varName = importAsset(file);
|
|
40
|
-
const clientRelativePath = toPosixPath(relative(clientDir, file));
|
|
41
|
-
if (clientRelativePath === "index.html") {
|
|
42
|
-
templateVarName = varName;
|
|
43
|
-
} else {
|
|
44
|
-
assetEntries.push(` ${JSON.stringify(`/_client/${clientRelativePath}`)}: ${varName},`);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
if (templateVarName === null) {
|
|
20
|
+
if (!existsSync(join(clientDir, "index.html"))) {
|
|
49
21
|
throw new Error(
|
|
50
22
|
`[furin] Embed mode requires a client index.html at ${join(clientDir, "index.html")}. Run the client build first.`
|
|
51
23
|
);
|
|
52
24
|
}
|
|
53
25
|
|
|
54
|
-
|
|
55
|
-
const publicFiles = collectFilesRecursive(publicDir);
|
|
56
|
-
for (const file of publicFiles) {
|
|
57
|
-
const varName = importAsset(file);
|
|
58
|
-
const publicRelativePath = toPosixPath(relative(publicDir, file));
|
|
59
|
-
assetEntries.push(` ${JSON.stringify(`/public/${publicRelativePath}`)}: ${varName},`);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
const extraContext = [
|
|
26
|
+
return [
|
|
64
27
|
" embedded: {",
|
|
65
|
-
`
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
28
|
+
` clientDir: import.meta.dir + ${JSON.stringify(`/${basename(clientDir)}`)},`,
|
|
29
|
+
...(publicDir && existsSync(publicDir)
|
|
30
|
+
? [` publicDir: import.meta.dir + ${JSON.stringify(`/${basename(publicDir)}`)},`]
|
|
31
|
+
: []),
|
|
69
32
|
" },",
|
|
70
33
|
];
|
|
71
|
-
|
|
72
|
-
return { extraContext, extraImports: assetImports };
|
|
73
34
|
}
|
|
74
35
|
|
|
75
36
|
/**
|
|
76
|
-
* Generates a
|
|
37
|
+
* Generates a virtual `_compile-entry.ts` that:
|
|
77
38
|
* 1. Statically imports every page module of every app so Bun bundles them
|
|
78
|
-
* 2.
|
|
39
|
+
* 2. Points embed-mode contexts at Bun's `compile.assets` directories
|
|
79
40
|
* 3. Sets production mode and registers one CompileContext PER APP
|
|
80
41
|
* 4. Dynamically imports server.ts to boot the composed app
|
|
81
42
|
*/
|
|
82
|
-
export function generateCompileEntry(options: BuildEntryOptions):
|
|
43
|
+
export function generateCompileEntry(options: BuildEntryOptions): VirtualBuildEntry {
|
|
83
44
|
const { apps, outDir, serverEntry, publicDir } = options;
|
|
84
45
|
ensureDir(outDir);
|
|
85
46
|
|
|
86
|
-
const preparedApps: EntryAppContext[] = apps.map((app
|
|
47
|
+
const preparedApps: EntryAppContext[] = apps.map((app) => {
|
|
87
48
|
const { embed, ...context } = app;
|
|
88
49
|
if (!embed) {
|
|
89
50
|
return context;
|
|
90
51
|
}
|
|
91
|
-
const varPrefix = apps.length === 1 ? "_" : `_a${appIndex}_`;
|
|
92
|
-
// Every app gets the project-level public/ dir: each instance serves only
|
|
93
|
-
// from its own `embedded.assets`, so `/public/*` (and `/favicon.ico`) would
|
|
94
|
-
// 404 on non-first apps otherwise. This only duplicates the string keys —
|
|
95
|
-
// each app imports the same file via the same relative path, and Bun
|
|
96
|
-
// dedupes identical `with { type: "file" }` modules into one embedded blob.
|
|
97
|
-
const embedded = buildEmbeddedAssets(outDir, embed.clientDir, publicDir, varPrefix);
|
|
98
52
|
return {
|
|
99
53
|
...context,
|
|
100
|
-
extraContext: [
|
|
101
|
-
|
|
54
|
+
extraContext: [
|
|
55
|
+
...(context.extraContext ?? []),
|
|
56
|
+
...buildEmbeddedContext(embed.clientDir, publicDir),
|
|
57
|
+
],
|
|
102
58
|
};
|
|
103
59
|
});
|
|
104
60
|
|
|
@@ -109,6 +65,5 @@ export function generateCompileEntry(options: BuildEntryOptions): string {
|
|
|
109
65
|
});
|
|
110
66
|
|
|
111
67
|
const entryPath = join(outDir, "_compile-entry.ts");
|
|
112
|
-
|
|
113
|
-
return entryPath;
|
|
68
|
+
return createVirtualBuildEntry(entryPath, source, "ts");
|
|
114
69
|
}
|
|
@@ -6,8 +6,10 @@ export interface EntryAppContext {
|
|
|
6
6
|
clientLogging?: boolean;
|
|
7
7
|
/** Extra lines injected inside this app's `__setCompileContext({...})` call. */
|
|
8
8
|
extraContext?: string[];
|
|
9
|
-
/**
|
|
10
|
-
|
|
9
|
+
/** Additional route modules such as filesystem-derived `_route` layouts. */
|
|
10
|
+
modulePaths?: string[];
|
|
11
|
+
/** Virtual module specifier exporting this app's composed Elysia route tree. */
|
|
12
|
+
nativeRoutes?: string;
|
|
11
13
|
/** Mount prefix baked into the context for runtime lookup (`""` = root). */
|
|
12
14
|
prefix?: string;
|
|
13
15
|
rootConventions?: {
|
|
@@ -28,7 +30,11 @@ export interface EntryAppContext {
|
|
|
28
30
|
path: string;
|
|
29
31
|
pattern: string;
|
|
30
32
|
}>;
|
|
33
|
+
/** False when the deployment platform serves client/public assets itself. */
|
|
34
|
+
serveAssets?: boolean;
|
|
31
35
|
ssgCache?: Record<string, SsgCacheEntry>;
|
|
36
|
+
/** In-memory production document template for filesystem-free runtimes. */
|
|
37
|
+
templateHtml?: string;
|
|
32
38
|
}
|
|
33
39
|
export interface EntryTemplateOptions {
|
|
34
40
|
apps: EntryAppContext[];
|
|
@@ -24,8 +24,10 @@ export interface EntryAppContext {
|
|
|
24
24
|
clientLogging?: boolean;
|
|
25
25
|
/** Extra lines injected inside this app's `__setCompileContext({...})` call. */
|
|
26
26
|
extraContext?: string[];
|
|
27
|
-
/**
|
|
28
|
-
|
|
27
|
+
/** Additional route modules such as filesystem-derived `_route` layouts. */
|
|
28
|
+
modulePaths?: string[];
|
|
29
|
+
/** Virtual module specifier exporting this app's composed Elysia route tree. */
|
|
30
|
+
nativeRoutes?: string;
|
|
29
31
|
/** Mount prefix baked into the context for runtime lookup (`""` = root). */
|
|
30
32
|
prefix?: string;
|
|
31
33
|
rootConventions?: { errorPath?: string; notFoundPath?: string };
|
|
@@ -42,7 +44,11 @@ export interface EntryAppContext {
|
|
|
42
44
|
}
|
|
43
45
|
>;
|
|
44
46
|
routes: Array<{ mode: "ssr" | "ssg" | "isr"; path: string; pattern: string }>;
|
|
47
|
+
/** False when the deployment platform serves client/public assets itself. */
|
|
48
|
+
serveAssets?: boolean;
|
|
45
49
|
ssgCache?: Record<string, SsgCacheEntry>;
|
|
50
|
+
/** In-memory production document template for filesystem-free runtimes. */
|
|
51
|
+
templateHtml?: string;
|
|
46
52
|
}
|
|
47
53
|
|
|
48
54
|
export interface EntryTemplateOptions {
|
|
@@ -112,9 +118,12 @@ function buildAppContextBlock(
|
|
|
112
118
|
varPrefix: string
|
|
113
119
|
): { contextLines: string[]; importLines: string[] } {
|
|
114
120
|
const allModulePaths = [
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
121
|
+
...new Set([
|
|
122
|
+
app.rootPath,
|
|
123
|
+
...app.routes.map((r) => r.path),
|
|
124
|
+
...(app.modulePaths ?? []),
|
|
125
|
+
...collectConventionPaths(app.rootConventions, app.routeMetadata),
|
|
126
|
+
]),
|
|
118
127
|
];
|
|
119
128
|
const importLines: string[] = [];
|
|
120
129
|
const moduleEntries: string[] = [];
|
|
@@ -125,6 +134,12 @@ function buildAppContextBlock(
|
|
|
125
134
|
importLines.push(`import * as ${varName} from ${JSON.stringify(absPath)};`);
|
|
126
135
|
moduleEntries.push(` ${JSON.stringify(absPath)}: ${varName},`);
|
|
127
136
|
}
|
|
137
|
+
const nativeRoutesVar = `${varPrefix}furinApp`;
|
|
138
|
+
if (app.nativeRoutes) {
|
|
139
|
+
importLines.push(
|
|
140
|
+
`import { furinApp as ${nativeRoutesVar} } from ${JSON.stringify(app.nativeRoutes)};`
|
|
141
|
+
);
|
|
142
|
+
}
|
|
128
143
|
|
|
129
144
|
const routeEntries = app.routes.map(
|
|
130
145
|
(r) =>
|
|
@@ -137,7 +152,11 @@ function buildAppContextBlock(
|
|
|
137
152
|
const routeMetadataLine = app.routeMetadata
|
|
138
153
|
? ` routeMetadata: ${JSON.stringify(app.routeMetadata)},`
|
|
139
154
|
: "";
|
|
155
|
+
const serveAssetsLine =
|
|
156
|
+
app.serveAssets === undefined ? "" : ` serveAssets: ${JSON.stringify(app.serveAssets)},`;
|
|
140
157
|
const ssgCacheLine = app.ssgCache ? ` ssgCache: ${JSON.stringify(app.ssgCache)},` : "";
|
|
158
|
+
const templateHtmlLine =
|
|
159
|
+
app.templateHtml === undefined ? "" : ` templateHtml: ${JSON.stringify(app.templateHtml)},`;
|
|
141
160
|
|
|
142
161
|
const contextLines = [
|
|
143
162
|
"__setCompileContext({",
|
|
@@ -145,6 +164,7 @@ function buildAppContextBlock(
|
|
|
145
164
|
` clientLogging: ${JSON.stringify(app.clientLogging ?? false)},`,
|
|
146
165
|
` prefix: ${JSON.stringify(app.prefix ?? "")},`,
|
|
147
166
|
` rootPath: ${JSON.stringify(app.rootPath.replace(/\\/g, "/"))},`,
|
|
167
|
+
app.nativeRoutes ? ` nativeRoutes: ${nativeRoutesVar},` : "",
|
|
148
168
|
rootConventionsLine,
|
|
149
169
|
" modules: {",
|
|
150
170
|
...moduleEntries,
|
|
@@ -153,7 +173,9 @@ function buildAppContextBlock(
|
|
|
153
173
|
...routeEntries,
|
|
154
174
|
" ],",
|
|
155
175
|
routeMetadataLine,
|
|
176
|
+
serveAssetsLine,
|
|
156
177
|
ssgCacheLine,
|
|
178
|
+
templateHtmlLine,
|
|
157
179
|
...(app.extraContext ?? []),
|
|
158
180
|
"});",
|
|
159
181
|
];
|
|
@@ -172,14 +194,11 @@ export function buildEntrySource(options: EntryTemplateOptions): string {
|
|
|
172
194
|
|
|
173
195
|
for (let appIndex = 0; appIndex < apps.length; appIndex++) {
|
|
174
196
|
const app = apps[appIndex] as EntryAppContext;
|
|
175
|
-
// Per-app variable namespace so several apps' module
|
|
176
|
-
//
|
|
197
|
+
// Per-app variable namespace so several apps' module imports never collide
|
|
198
|
+
// inside the single generated entry.
|
|
177
199
|
const varPrefix = apps.length === 1 ? "_" : `_a${appIndex}_`;
|
|
178
200
|
const block = buildAppContextBlock(app, varPrefix);
|
|
179
201
|
importLines.push(...block.importLines);
|
|
180
|
-
if (app.extraImports && app.extraImports.length > 0) {
|
|
181
|
-
importLines.push("", ...app.extraImports);
|
|
182
|
-
}
|
|
183
202
|
contextBlocks.push("", ...block.contextLines);
|
|
184
203
|
}
|
|
185
204
|
|
|
@@ -201,7 +220,25 @@ export function buildEntrySource(options: EntryTemplateOptions): string {
|
|
|
201
220
|
...contextBlocks,
|
|
202
221
|
"",
|
|
203
222
|
...(serverEntry
|
|
204
|
-
? [
|
|
223
|
+
? [
|
|
224
|
+
`const __serverModule = await import(${JSON.stringify(serverEntry.replace(/\\/g, "/"))});`,
|
|
225
|
+
"if (typeof __serverModule.startServer === \"function\") {",
|
|
226
|
+
" await __serverModule.startServer();",
|
|
227
|
+
"} else {",
|
|
228
|
+
" const __app = __serverModule.default;",
|
|
229
|
+
" if (__app && typeof __app.listen === \"function\" && !__app.server) {",
|
|
230
|
+
" const __port =",
|
|
231
|
+
" process.env.PORT === undefined",
|
|
232
|
+
" ? typeof __serverModule.port === \"number\"",
|
|
233
|
+
" ? __serverModule.port",
|
|
234
|
+
" : 3000",
|
|
235
|
+
" : Number(process.env.PORT);",
|
|
236
|
+
" __app.listen(__port);",
|
|
237
|
+
" console.log(`[furin] Server running at http://localhost:${__app.server?.port}`);",
|
|
238
|
+
" }",
|
|
239
|
+
"}",
|
|
240
|
+
"",
|
|
241
|
+
]
|
|
205
242
|
: []),
|
|
206
243
|
];
|
|
207
244
|
|
package/dist/build/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { BuildAppOptions, BuildAppResult } from "./types";
|
|
2
2
|
export { buildClient } from "./client";
|
|
3
3
|
export { writeDevFiles } from "./hydrate";
|
|
4
|
-
export {
|
|
4
|
+
export { writeRouteTypes } from "./route-types";
|
|
5
5
|
export { buildSSGCacheSnapshot, type SSGCacheSnapshot } from "./ssg-cache";
|
|
6
|
-
export type { BuildAppOptions, BuildAppResult, BuildClientOptions, BuildManifest, BuildRouteManifestEntry, TargetBuildManifest, } from "./types";
|
|
6
|
+
export type { BuildAppOptions, BuildAppResult, BuildClientOptions, BuildManifest, BuildRouteManifestEntry, TargetBuildManifest, VercelTargetBuildManifest, } from "./types";
|
|
7
7
|
export declare const BUILD_OUTPUT_DIR = ".furin/build";
|
|
8
8
|
export declare function buildApp(options: BuildAppOptions): Promise<BuildAppResult>;
|