@teyik0/furin 0.4.0-alpha.1 → 0.5.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 +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 +1 -1
- package/dist/build/compile-entry.d.ts +6 -4
- package/dist/build/compile-entry.ts +36 -77
- package/dist/build/elysia-aot.d.ts +9 -0
- package/dist/build/entry-template.d.ts +9 -3
- package/dist/build/entry-template.ts +55 -13
- package/dist/build/index.d.ts +1 -1
- package/dist/build/index.js +8912 -6391
- package/dist/build/server-app-entry.d.ts +12 -0
- package/dist/build/ssg-cache.d.ts +13 -0
- package/dist/build/types.d.ts +25 -2
- package/dist/build/virtual-entry.d.ts +8 -0
- package/dist/cache.d.ts +6 -0
- package/dist/cache.js +282 -0
- package/dist/cli/index.js +8936 -6308
- package/dist/cli/preview.d.ts +7 -0
- package/dist/client/boundaries.d.ts +1 -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 +9 -8
- 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 +1 -0
- package/dist/client/hmr.d.ts +4 -2
- package/dist/client/internal/runtime-types.d.ts +8 -1
- package/dist/client/link.js +465 -86
- package/dist/client/router/provider.d.ts +1 -1
- package/dist/client/router/sync-catch-up.d.ts +1 -1
- package/dist/client/router/types.d.ts +8 -10
- package/dist/client/sync.d.ts +1 -0
- package/dist/client.js +37 -23
- package/dist/config.d.ts +35 -17
- package/dist/config.js +10 -2
- package/dist/define-route.d.ts +282 -1015
- package/dist/devtools/protocol.d.ts +2 -2
- package/dist/furin.d.ts +21 -6
- package/dist/furin.js +12823 -8484
- package/dist/plugin/index.js +476 -7
- package/dist/plugin/routes.d.ts +10 -3
- package/dist/rsc/build/index.d.ts +5 -1
- package/dist/server/assets/production.d.ts +3 -0
- package/dist/server/auto-invalidate/plugin.d.ts +8 -24
- package/dist/server/auto-invalidate/runtime.d.ts +2 -2
- 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 +2 -3
- package/dist/server/cache/isr.d.ts +1 -0
- package/dist/server/cache/page-cache-state.d.ts +5 -0
- package/dist/server/cache/page-cache.d.ts +53 -0
- package/dist/server/cache/purger.d.ts +7 -0
- package/dist/server/cache/redis/index.d.ts +39 -0
- package/dist/server/cache/redis/index.js +396 -0
- package/dist/server/cache/redis/scripts.d.ts +6 -0
- package/dist/server/cache/runtime-cache.d.ts +21 -0
- package/dist/server/context-logger.d.ts +2 -2
- 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 +6 -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 -0
- 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 +1 -1
- package/dist/server/devtools/instrumentation.production.d.ts +1 -1
- package/dist/server/devtools/plugin.d.ts +1 -1
- package/dist/server/evlog.d.ts +14 -0
- package/dist/server/external-prerender.d.ts +2 -0
- package/dist/server/instance.d.ts +2 -2
- package/dist/server/internal.d.ts +20 -2
- package/dist/server/internal.js +2973 -1
- package/dist/server/render/element.d.ts +1 -0
- package/dist/server/render/index.d.ts +1 -1
- package/dist/server/render/index.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 +3 -1
- package/dist/server/render/shell.ts +0 -12
- package/dist/server/render/ssg.d.ts +7 -0
- package/dist/server/render/ssr.d.ts +17 -6
- package/dist/server/render/static-params.d.ts +4 -0
- package/dist/server/router/defined-route.d.ts +1 -1
- package/dist/server/router/hmr.production.d.ts +2 -0
- package/dist/server/router/patterns.d.ts +1 -0
- package/dist/server/router/plugin.d.ts +3 -1
- package/dist/server/router/schemas.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 +1252 -599
- package/dist/server/sync/notifier.d.ts +1 -0
- package/dist/server/sync/plugin.d.ts +31 -158
- package/dist/server/sync/postgres/index.d.ts +12 -1
- package/dist/server/sync/postgres/index.js +101 -6
- package/dist/server/sync/stream.d.ts +37 -61
- package/dist/shared/await.d.ts +3 -3
- 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 +8 -14
- package/dist/shared/prefix.d.ts +2 -0
- package/package.json +26 -11
- package/src/adapter/README.md +53 -1
- package/src/adapter/bun.ts +106 -283
- package/src/adapter/package.ts +21 -11
- package/src/adapter/runtime-build.ts +382 -0
- package/src/adapter/static.ts +87 -8
- package/src/adapter/vercel.ts +876 -0
- package/src/build/client.ts +55 -13
- package/src/build/compile-entry.ts +36 -77
- package/src/build/elysia-aot.ts +102 -0
- package/src/build/entry-template.ts +55 -13
- package/src/build/hydrate.ts +60 -20
- package/src/build/index.ts +17 -8
- package/src/build/production-instrumentation.ts +56 -4
- package/src/build/server-app-entry.ts +60 -0
- package/src/build/shared.ts +5 -2
- package/src/build/ssg-cache.ts +93 -12
- package/src/build/types.ts +31 -2
- package/src/build/virtual-entry.ts +28 -0
- package/src/cache.ts +26 -0
- package/src/cli/config.ts +3 -3
- package/src/cli/index.ts +58 -3
- package/src/cli/preview.ts +90 -0
- package/src/client/boundaries.tsx +10 -1
- package/src/client/browser-events-runtime.ts +204 -0
- package/src/client/browser-events.ts +22 -0
- package/src/client/define-route.ts +7 -17
- package/src/client/dev-error-overlay.ts +201 -0
- package/src/client/document.tsx +4 -7
- package/src/client/hmr.ts +26 -3
- package/src/client/internal/runtime-types.ts +10 -1
- package/src/client/router/boundary-tree.tsx +4 -4
- package/src/client/router/provider.tsx +165 -63
- package/src/client/router/sync-catch-up.ts +3 -4
- package/src/client/router/types.ts +6 -6
- package/src/client/sync.ts +1 -0
- package/src/config.ts +28 -2
- package/src/define-route.ts +285 -134
- package/src/devtools/devtools-element.js +56 -77
- package/src/devtools/protocol.ts +2 -2
- package/src/furin.ts +272 -203
- package/src/plugin/route-config-autofix.ts +11 -2
- package/src/plugin/routes.ts +291 -65
- package/src/plugin/transform-client.ts +685 -3
- package/src/react-dom-edge.d.ts +6 -0
- package/src/rsc/build/index.ts +15 -3
- package/src/server/assets/production.ts +99 -0
- package/src/server/auto-invalidate/plugin.ts +4 -4
- package/src/server/auto-invalidate/runtime.ts +76 -41
- package/src/server/browser-events/plugin.ts +173 -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 +67 -35
- package/src/server/cache/isr.ts +9 -0
- package/src/server/cache/page-cache-state.ts +22 -0
- package/src/server/cache/page-cache.ts +300 -0
- package/src/server/cache/purger.ts +41 -0
- package/src/server/cache/redis/index.ts +350 -0
- package/src/server/cache/redis/scripts.ts +160 -0
- package/src/server/cache/runtime-cache.ts +137 -0
- package/src/server/context-logger.ts +5 -5
- 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 +28 -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 +136 -53
- package/src/server/devtools/hub.ts +6 -5
- package/src/server/devtools/instrumentation.production.ts +1 -1
- package/src/server/devtools/instrumentation.ts +12 -6
- package/src/server/devtools/plugin.ts +7 -150
- package/src/server/evlog.ts +99 -0
- package/src/server/external-prerender.ts +10 -0
- package/src/server/instance.ts +3 -3
- package/src/server/internal.ts +46 -2
- package/src/server/render/assemble.ts +4 -4
- package/src/server/render/document.tsx +13 -4
- package/src/server/render/element.tsx +18 -14
- package/src/server/render/index.ts +1 -1
- package/src/server/render/isr.ts +509 -136
- package/src/server/render/loaders.ts +31 -15
- package/src/server/render/not-found.ts +32 -8
- 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 +335 -28
- package/src/server/render/shell.ts +0 -12
- package/src/server/render/ssg.ts +186 -24
- package/src/server/render/ssr.ts +215 -89
- package/src/server/render/static-params.ts +174 -0
- package/src/server/render/template.ts +47 -11
- package/src/server/router/defined-route.ts +9 -40
- package/src/server/router/hmr.production.ts +7 -0
- package/src/server/router/hmr.ts +108 -67
- package/src/server/router/patterns.ts +5 -1
- package/src/server/router/plugin.ts +164 -66
- package/src/server/router/schema-merge.ts +1 -1
- package/src/server/router/schemas.ts +174 -61
- package/src/server/router/source-version.ts +3 -10
- 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 +18 -11
- package/src/server/sync/postgres/index.ts +111 -5
- package/src/server/sync/response.ts +3 -3
- package/src/server/sync/runtime.ts +12 -0
- package/src/server/sync/stream.ts +78 -113
- package/src/shared/await.tsx +3 -3
- 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 +23 -25
- package/src/shared/prefix.ts +8 -0
- package/src/shared/route-map.ts +10 -1
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
|
@@ -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, pagesDir, }: 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,11 @@
|
|
|
1
|
-
import { type BuildEntryOptions } from "./entry-template";
|
|
1
|
+
import { type BuildEntryOptions, type EntryAppContext } from "./entry-template";
|
|
2
|
+
import { type VirtualBuildEntry } from "./virtual-entry.ts";
|
|
3
|
+
export declare function prepareCompileEntryApps(options: BuildEntryOptions): EntryAppContext[];
|
|
2
4
|
/**
|
|
3
|
-
* Generates a
|
|
5
|
+
* Generates a virtual `_compile-entry.ts` that:
|
|
4
6
|
* 1. Statically imports every page module of every app so Bun bundles them
|
|
5
|
-
* 2.
|
|
7
|
+
* 2. Points embed-mode contexts at Bun's `compile.assets` directories
|
|
6
8
|
* 3. Sets production mode and registers one CompileContext PER APP
|
|
7
9
|
* 4. Dynamically imports server.ts to boot the composed app
|
|
8
10
|
*/
|
|
9
|
-
export declare function generateCompileEntry(options: BuildEntryOptions):
|
|
11
|
+
export declare function generateCompileEntry(options: BuildEntryOptions): VirtualBuildEntry;
|
|
@@ -1,106 +1,66 @@
|
|
|
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
|
-
|
|
76
|
-
|
|
77
|
-
* 1. Statically imports every page module of every app so Bun bundles them
|
|
78
|
-
* 2. Optionally embeds client assets via `with { type: "file" }` (embed mode)
|
|
79
|
-
* 3. Sets production mode and registers one CompileContext PER APP
|
|
80
|
-
* 4. Dynamically imports server.ts to boot the composed app
|
|
81
|
-
*/
|
|
82
|
-
export function generateCompileEntry(options: BuildEntryOptions): string {
|
|
83
|
-
const { apps, outDir, serverEntry, publicDir } = options;
|
|
84
|
-
ensureDir(outDir);
|
|
85
|
-
|
|
86
|
-
const preparedApps: EntryAppContext[] = apps.map((app, appIndex) => {
|
|
36
|
+
export function prepareCompileEntryApps(options: BuildEntryOptions): EntryAppContext[] {
|
|
37
|
+
return options.apps.map((app) => {
|
|
87
38
|
const { embed, ...context } = app;
|
|
88
39
|
if (!embed) {
|
|
89
40
|
return context;
|
|
90
41
|
}
|
|
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
42
|
return {
|
|
99
43
|
...context,
|
|
100
|
-
extraContext: [
|
|
101
|
-
|
|
44
|
+
extraContext: [
|
|
45
|
+
...(context.extraContext ?? []),
|
|
46
|
+
...buildEmbeddedContext(embed.clientDir, options.publicDir),
|
|
47
|
+
],
|
|
102
48
|
};
|
|
103
49
|
});
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Generates a virtual `_compile-entry.ts` that:
|
|
54
|
+
* 1. Statically imports every page module of every app so Bun bundles them
|
|
55
|
+
* 2. Points embed-mode contexts at Bun's `compile.assets` directories
|
|
56
|
+
* 3. Sets production mode and registers one CompileContext PER APP
|
|
57
|
+
* 4. Dynamically imports server.ts to boot the composed app
|
|
58
|
+
*/
|
|
59
|
+
export function generateCompileEntry(options: BuildEntryOptions): VirtualBuildEntry {
|
|
60
|
+
const { outDir, serverEntry } = options;
|
|
61
|
+
ensureDir(outDir);
|
|
62
|
+
|
|
63
|
+
const preparedApps = prepareCompileEntryApps(options);
|
|
104
64
|
|
|
105
65
|
const source = buildEntrySource({
|
|
106
66
|
apps: preparedApps,
|
|
@@ -109,6 +69,5 @@ export function generateCompileEntry(options: BuildEntryOptions): string {
|
|
|
109
69
|
});
|
|
110
70
|
|
|
111
71
|
const entryPath = join(outDir, "_compile-entry.ts");
|
|
112
|
-
|
|
113
|
-
return entryPath;
|
|
72
|
+
return createVirtualBuildEntry(entryPath, source, "ts");
|
|
114
73
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Kiana strips the WebSocket route module when an app has no WS route,
|
|
3
|
+
* but its capability plugin still imports four helpers omitted by that stub.
|
|
4
|
+
* Keep the upstream failure semantics while restoring the complete export
|
|
5
|
+
* surface. Remove this compatibility shim when Elysia ships the full stub.
|
|
6
|
+
*/
|
|
7
|
+
export declare function patchElysiaWebSocketStub(source: string): string;
|
|
8
|
+
/** Elysia AOT plugin with the no-WebSocket stub compatibility fix. */
|
|
9
|
+
export declare function elysiaAot(entry: string): Bun.BunPlugin;
|
|
@@ -4,10 +4,10 @@ export interface EntryAppContext {
|
|
|
4
4
|
buildId?: string;
|
|
5
5
|
/** Whether the emitted hydration client sends browser log batches. */
|
|
6
6
|
clientLogging?: boolean;
|
|
7
|
+
/** Deployment adapter that owns public page caching for this build. */
|
|
8
|
+
deploymentTarget?: "vercel";
|
|
7
9
|
/** Extra lines injected inside this app's `__setCompileContext({...})` call. */
|
|
8
10
|
extraContext?: string[];
|
|
9
|
-
/** Extra import lines this app needs (embedded asset imports). */
|
|
10
|
-
extraImports?: string[];
|
|
11
11
|
/** Additional route modules such as filesystem-derived `_route` layouts. */
|
|
12
12
|
modulePaths?: string[];
|
|
13
13
|
/** Virtual module specifier exporting this app's composed Elysia route tree. */
|
|
@@ -32,7 +32,11 @@ export interface EntryAppContext {
|
|
|
32
32
|
path: string;
|
|
33
33
|
pattern: string;
|
|
34
34
|
}>;
|
|
35
|
+
/** False when the deployment platform serves client/public assets itself. */
|
|
36
|
+
serveAssets?: boolean;
|
|
35
37
|
ssgCache?: Record<string, SsgCacheEntry>;
|
|
38
|
+
/** In-memory production document template for filesystem-free runtimes. */
|
|
39
|
+
templateHtml?: string;
|
|
36
40
|
}
|
|
37
41
|
export interface EntryTemplateOptions {
|
|
38
42
|
apps: EntryAppContext[];
|
|
@@ -40,13 +44,15 @@ export interface EntryTemplateOptions {
|
|
|
40
44
|
/**
|
|
41
45
|
* - "boot" (default): forces production mode and dynamically imports the
|
|
42
46
|
* server entry after registering contexts — the whole app's entrypoint.
|
|
47
|
+
* - "app": registers contexts and exports the user's Elysia app without
|
|
48
|
+
* starting a listener, so build-time tooling can safely import it.
|
|
43
49
|
* - "register": ONLY registers contexts. Emitted by `--target package` as a
|
|
44
50
|
* side-effect module the HOST app imports; it must not touch dev mode or
|
|
45
51
|
* NODE_ENV (the host decides), and it imports furin internals via the
|
|
46
52
|
* package specifier so the host and the register module share ONE copy of
|
|
47
53
|
* the context registry (`packages: "external"` keeps it unbundled).
|
|
48
54
|
*/
|
|
49
|
-
mode?: "boot" | "register";
|
|
55
|
+
mode?: "app" | "boot" | "register";
|
|
50
56
|
/**
|
|
51
57
|
* Server entry to boot after context registration. Omitted in package
|
|
52
58
|
* (register-module) mode where the entry only registers contexts.
|
|
@@ -22,10 +22,10 @@ export interface EntryAppContext {
|
|
|
22
22
|
buildId?: string;
|
|
23
23
|
/** Whether the emitted hydration client sends browser log batches. */
|
|
24
24
|
clientLogging?: boolean;
|
|
25
|
+
/** Deployment adapter that owns public page caching for this build. */
|
|
26
|
+
deploymentTarget?: "vercel";
|
|
25
27
|
/** Extra lines injected inside this app's `__setCompileContext({...})` call. */
|
|
26
28
|
extraContext?: string[];
|
|
27
|
-
/** Extra import lines this app needs (embedded asset imports). */
|
|
28
|
-
extraImports?: string[];
|
|
29
29
|
/** Additional route modules such as filesystem-derived `_route` layouts. */
|
|
30
30
|
modulePaths?: string[];
|
|
31
31
|
/** Virtual module specifier exporting this app's composed Elysia route tree. */
|
|
@@ -46,7 +46,11 @@ export interface EntryAppContext {
|
|
|
46
46
|
}
|
|
47
47
|
>;
|
|
48
48
|
routes: Array<{ mode: "ssr" | "ssg" | "isr"; path: string; pattern: string }>;
|
|
49
|
+
/** False when the deployment platform serves client/public assets itself. */
|
|
50
|
+
serveAssets?: boolean;
|
|
49
51
|
ssgCache?: Record<string, SsgCacheEntry>;
|
|
52
|
+
/** In-memory production document template for filesystem-free runtimes. */
|
|
53
|
+
templateHtml?: string;
|
|
50
54
|
}
|
|
51
55
|
|
|
52
56
|
export interface EntryTemplateOptions {
|
|
@@ -55,13 +59,15 @@ export interface EntryTemplateOptions {
|
|
|
55
59
|
/**
|
|
56
60
|
* - "boot" (default): forces production mode and dynamically imports the
|
|
57
61
|
* server entry after registering contexts — the whole app's entrypoint.
|
|
62
|
+
* - "app": registers contexts and exports the user's Elysia app without
|
|
63
|
+
* starting a listener, so build-time tooling can safely import it.
|
|
58
64
|
* - "register": ONLY registers contexts. Emitted by `--target package` as a
|
|
59
65
|
* side-effect module the HOST app imports; it must not touch dev mode or
|
|
60
66
|
* NODE_ENV (the host decides), and it imports furin internals via the
|
|
61
67
|
* package specifier so the host and the register module share ONE copy of
|
|
62
68
|
* the context registry (`packages: "external"` keeps it unbundled).
|
|
63
69
|
*/
|
|
64
|
-
mode?: "boot" | "register";
|
|
70
|
+
mode?: "app" | "boot" | "register";
|
|
65
71
|
/**
|
|
66
72
|
* Server entry to boot after context registration. Omitted in package
|
|
67
73
|
* (register-module) mode where the entry only registers contexts.
|
|
@@ -150,12 +156,21 @@ function buildAppContextBlock(
|
|
|
150
156
|
const routeMetadataLine = app.routeMetadata
|
|
151
157
|
? ` routeMetadata: ${JSON.stringify(app.routeMetadata)},`
|
|
152
158
|
: "";
|
|
159
|
+
const deploymentTargetLine =
|
|
160
|
+
app.deploymentTarget === undefined
|
|
161
|
+
? ""
|
|
162
|
+
: ` deploymentTarget: ${JSON.stringify(app.deploymentTarget)},`;
|
|
163
|
+
const serveAssetsLine =
|
|
164
|
+
app.serveAssets === undefined ? "" : ` serveAssets: ${JSON.stringify(app.serveAssets)},`;
|
|
153
165
|
const ssgCacheLine = app.ssgCache ? ` ssgCache: ${JSON.stringify(app.ssgCache)},` : "";
|
|
166
|
+
const templateHtmlLine =
|
|
167
|
+
app.templateHtml === undefined ? "" : ` templateHtml: ${JSON.stringify(app.templateHtml)},`;
|
|
154
168
|
|
|
155
169
|
const contextLines = [
|
|
156
170
|
"__setCompileContext({",
|
|
157
171
|
` buildId: ${JSON.stringify(app.buildId ?? "")},`,
|
|
158
172
|
` clientLogging: ${JSON.stringify(app.clientLogging ?? false)},`,
|
|
173
|
+
deploymentTargetLine,
|
|
159
174
|
` prefix: ${JSON.stringify(app.prefix ?? "")},`,
|
|
160
175
|
` rootPath: ${JSON.stringify(app.rootPath.replace(/\\/g, "/"))},`,
|
|
161
176
|
app.nativeRoutes ? ` nativeRoutes: ${nativeRoutesVar},` : "",
|
|
@@ -167,7 +182,9 @@ function buildAppContextBlock(
|
|
|
167
182
|
...routeEntries,
|
|
168
183
|
" ],",
|
|
169
184
|
routeMetadataLine,
|
|
185
|
+
serveAssetsLine,
|
|
170
186
|
ssgCacheLine,
|
|
187
|
+
templateHtmlLine,
|
|
171
188
|
...(app.extraContext ?? []),
|
|
172
189
|
"});",
|
|
173
190
|
];
|
|
@@ -180,31 +197,29 @@ export function buildEntrySource(options: EntryTemplateOptions): string {
|
|
|
180
197
|
const mode = options.mode ?? "boot";
|
|
181
198
|
const internalSpecifier =
|
|
182
199
|
mode === "register" ? "@teyik0/furin/internal" : INTERNAL_MODULE_PATH;
|
|
200
|
+
const productionMode = mode !== "register";
|
|
183
201
|
|
|
184
202
|
const importLines: string[] = [];
|
|
185
203
|
const contextBlocks: string[] = [];
|
|
186
204
|
|
|
187
205
|
for (let appIndex = 0; appIndex < apps.length; appIndex++) {
|
|
188
206
|
const app = apps[appIndex] as EntryAppContext;
|
|
189
|
-
// Per-app variable namespace so several apps' module
|
|
190
|
-
//
|
|
207
|
+
// Per-app variable namespace so several apps' module imports never collide
|
|
208
|
+
// inside the single generated entry.
|
|
191
209
|
const varPrefix = apps.length === 1 ? "_" : `_a${appIndex}_`;
|
|
192
210
|
const block = buildAppContextBlock(app, varPrefix);
|
|
193
211
|
importLines.push(...block.importLines);
|
|
194
|
-
if (app.extraImports && app.extraImports.length > 0) {
|
|
195
|
-
importLines.push("", ...app.extraImports);
|
|
196
|
-
}
|
|
197
212
|
contextBlocks.push("", ...block.contextLines);
|
|
198
213
|
}
|
|
199
214
|
|
|
200
215
|
const lines = [
|
|
201
216
|
headerComment,
|
|
202
217
|
`import { __setCompileContext } from ${JSON.stringify(internalSpecifier)};`,
|
|
203
|
-
...(
|
|
218
|
+
...(productionMode
|
|
204
219
|
? [`import { __setDevMode } from ${JSON.stringify(RUNTIME_ENV_MODULE_PATH)};`]
|
|
205
220
|
: []),
|
|
206
221
|
...importLines,
|
|
207
|
-
...(
|
|
222
|
+
...(productionMode
|
|
208
223
|
? [
|
|
209
224
|
"",
|
|
210
225
|
"// Force production mode — Bun may inline process.env.NODE_ENV at bundle time.",
|
|
@@ -214,9 +229,36 @@ export function buildEntrySource(options: EntryTemplateOptions): string {
|
|
|
214
229
|
: []),
|
|
215
230
|
...contextBlocks,
|
|
216
231
|
"",
|
|
217
|
-
...(serverEntry
|
|
218
|
-
? [
|
|
219
|
-
|
|
232
|
+
...(serverEntry && mode === "boot"
|
|
233
|
+
? [
|
|
234
|
+
`const __serverModule = await import(${JSON.stringify(serverEntry.replace(/\\/g, "/"))});`,
|
|
235
|
+
"if (typeof __serverModule.startServer === \"function\") {",
|
|
236
|
+
" await __serverModule.startServer();",
|
|
237
|
+
"} else {",
|
|
238
|
+
" const __app = __serverModule.default;",
|
|
239
|
+
" if (__app && typeof __app.listen === \"function\" && !__app.server) {",
|
|
240
|
+
" const __port =",
|
|
241
|
+
" process.env.PORT === undefined",
|
|
242
|
+
" ? typeof __serverModule.port === \"number\"",
|
|
243
|
+
" ? __serverModule.port",
|
|
244
|
+
" : 3000",
|
|
245
|
+
" : Number(process.env.PORT);",
|
|
246
|
+
" __app.listen(__port);",
|
|
247
|
+
" console.log(`[furin] Server running at http://localhost:${__app.server?.port}`);",
|
|
248
|
+
" }",
|
|
249
|
+
"}",
|
|
250
|
+
"",
|
|
251
|
+
]
|
|
252
|
+
: serverEntry && mode === "app"
|
|
253
|
+
? [
|
|
254
|
+
`const __serverModule = await import(${JSON.stringify(serverEntry.replace(/\\/g, "/"))});`,
|
|
255
|
+
"export const app = __serverModule.default;",
|
|
256
|
+
"export const port = __serverModule.port;",
|
|
257
|
+
"export const startServer = __serverModule.startServer;",
|
|
258
|
+
"export default __serverModule.default;",
|
|
259
|
+
"",
|
|
260
|
+
]
|
|
261
|
+
: []),
|
|
220
262
|
];
|
|
221
263
|
|
|
222
264
|
return lines.join("\n");
|
package/dist/build/index.d.ts
CHANGED
|
@@ -3,6 +3,6 @@ export { buildClient } from "./client";
|
|
|
3
3
|
export { writeDevFiles } from "./hydrate";
|
|
4
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>;
|