@teyik0/furin 0.2.0-alpha.4 → 0.2.0-alpha.5
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 +17 -1
- package/dist/adapter/package.d.ts +26 -0
- package/dist/build/client.d.ts +1 -1
- package/dist/build/compile-entry.d.ts +3 -3
- package/dist/build/compile-entry.ts +88 -83
- package/dist/build/entry-template.d.ts +35 -9
- package/dist/build/entry-template.ts +106 -56
- package/dist/build/hydrate.d.ts +1 -1
- package/dist/build/index.js +643 -247
- package/dist/build/scan-server.d.ts +10 -4
- package/dist/build/server-routes-entry.d.ts +3 -3
- package/dist/build/server-routes-entry.ts +5 -11
- package/dist/build/ssg-cache.d.ts +1 -1
- package/dist/build/types.d.ts +36 -1
- package/dist/cli/config.d.ts +6 -1
- package/dist/cli/index.js +662 -260
- package/dist/config.d.ts +11 -2
- package/dist/config.js +5 -1
- package/dist/furin.d.ts +36 -18
- package/dist/furin.js +630 -310
- package/dist/server/auto-invalidate/registry.d.ts +8 -1
- package/dist/server/cache/dev-loader.d.ts +3 -2
- package/dist/server/cache/invalidation.d.ts +19 -0
- package/dist/server/cache/isr.d.ts +6 -2
- package/dist/server/cache/registry.d.ts +3 -3
- package/dist/server/cache/ssg.d.ts +6 -2
- package/dist/server/cache/store-view.d.ts +11 -0
- package/dist/server/instance.d.ts +86 -0
- package/dist/server/internal.d.ts +16 -1
- package/dist/server/internal.js +72 -5
- package/dist/server/render/template.d.ts +3 -2
- package/dist/server/sync/config.d.ts +11 -0
- package/dist/server/sync/stream.d.ts +8 -1
- package/dist/shared/prefix.d.ts +15 -0
- package/package.json +6 -1
- package/src/adapter/bun.ts +113 -50
- package/src/adapter/package.ts +206 -0
- package/src/build/client.ts +9 -3
- package/src/build/compile-entry.ts +88 -83
- package/src/build/entry-template.ts +106 -56
- package/src/build/hydrate.ts +4 -2
- package/src/build/index.ts +99 -28
- package/src/build/scan-server.ts +23 -7
- package/src/build/server-routes-entry.ts +5 -11
- package/src/build/ssg-cache.ts +6 -2
- package/src/build/types.ts +37 -1
- package/src/cli/config.ts +9 -3
- package/src/cli/index.ts +21 -3
- package/src/config.ts +14 -1
- package/src/furin.ts +297 -143
- package/src/server/auto-invalidate/registry.ts +23 -1
- package/src/server/auto-invalidate/runtime.ts +29 -4
- package/src/server/cache/dev-loader.ts +77 -38
- package/src/server/cache/invalidation.ts +71 -30
- package/src/server/cache/isr.ts +20 -5
- package/src/server/cache/registry.ts +17 -20
- package/src/server/cache/ssg.ts +19 -4
- package/src/server/cache/store-view.ts +30 -0
- package/src/server/instance.ts +252 -0
- package/src/server/internal.ts +100 -5
- package/src/server/render/not-found.ts +9 -3
- package/src/server/render/ssr.ts +16 -4
- package/src/server/render/template.ts +57 -24
- package/src/server/sync/config.ts +32 -1
- package/src/server/sync/plugin.ts +4 -5
- package/src/server/sync/stream.ts +19 -9
- package/src/shared/prefix.ts +38 -0
package/src/build/scan-server.ts
CHANGED
|
@@ -1,16 +1,24 @@
|
|
|
1
1
|
import { readFileSync } from "node:fs";
|
|
2
2
|
import { parse, type CallExpression, type ObjectExpression, type ObjectProperty } from "yuku-parser";
|
|
3
|
+
import { normalizePrefix } from "../server/instance.ts";
|
|
3
4
|
import { detectLangFromPath, unwrapTSExpression } from "../server/lang-detect.ts";
|
|
4
5
|
import { walkAST } from "../shared/utils/ast-walk.ts";
|
|
5
6
|
|
|
7
|
+
export interface ScannedFurinInstance {
|
|
8
|
+
pagesDir: string;
|
|
9
|
+
/** Normalized mount prefix (`""` when absent). */
|
|
10
|
+
prefix: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
6
13
|
/**
|
|
7
|
-
* Statically scans a server entry file and returns
|
|
8
|
-
*
|
|
14
|
+
* Statically scans a server entry file and returns the `pagesDir` (and
|
|
15
|
+
* optional `prefix`) string literals found inside `furin({ pagesDir: "..." })`
|
|
16
|
+
* call expressions.
|
|
9
17
|
*
|
|
10
|
-
* Dynamic
|
|
18
|
+
* Dynamic values (template literals, variables) are silently ignored.
|
|
11
19
|
* Returns an empty array when nothing is detected.
|
|
12
20
|
*/
|
|
13
|
-
export function scanFurinInstances(serverEntryPath: string):
|
|
21
|
+
export function scanFurinInstances(serverEntryPath: string): ScannedFurinInstance[] {
|
|
14
22
|
const code = readFileSync(serverEntryPath, "utf8");
|
|
15
23
|
const lang = detectLangFromPath(serverEntryPath);
|
|
16
24
|
|
|
@@ -26,7 +34,7 @@ export function scanFurinInstances(serverEntryPath: string): string[] {
|
|
|
26
34
|
return [];
|
|
27
35
|
}
|
|
28
36
|
|
|
29
|
-
const results:
|
|
37
|
+
const results: ScannedFurinInstance[] = [];
|
|
30
38
|
walkAST(program, (node) => {
|
|
31
39
|
if (node.type === "CallExpression") {
|
|
32
40
|
checkFurinCall(node as unknown as CallExpression, results);
|
|
@@ -36,7 +44,7 @@ export function scanFurinInstances(serverEntryPath: string): string[] {
|
|
|
36
44
|
}
|
|
37
45
|
|
|
38
46
|
/** Checks whether `node` is a `furin({ pagesDir: "..." })` call and, if so, pushes the value. */
|
|
39
|
-
function checkFurinCall(node: CallExpression, out:
|
|
47
|
+
function checkFurinCall(node: CallExpression, out: ScannedFurinInstance[]): void {
|
|
40
48
|
const isFurinCall = node.callee.type === "Identifier" && node.callee.name === "furin";
|
|
41
49
|
|
|
42
50
|
if (!isFurinCall || node.arguments.length === 0) {
|
|
@@ -56,10 +64,18 @@ function checkFurinCall(node: CallExpression, out: string[]): void {
|
|
|
56
64
|
|
|
57
65
|
const pagesDir = extractStringProperty(firstArg, "pagesDir");
|
|
58
66
|
if (pagesDir !== null) {
|
|
59
|
-
|
|
67
|
+
const prefix = extractStringProperty(firstArg, "prefix");
|
|
68
|
+
out.push({ pagesDir, prefix: normalizeScannedPrefix(prefix) });
|
|
60
69
|
}
|
|
61
70
|
}
|
|
62
71
|
|
|
72
|
+
// Delegates to the runtime's normalizePrefix so a literal that would make
|
|
73
|
+
// `furin()` throw at startup fails at build time too, with the same message —
|
|
74
|
+
// silently "fixing" it here would build assets the runtime never serves.
|
|
75
|
+
function normalizeScannedPrefix(prefix: string | null): string {
|
|
76
|
+
return normalizePrefix(prefix ?? undefined);
|
|
77
|
+
}
|
|
78
|
+
|
|
63
79
|
function isObjectExpressionNode(node: { type: string }): node is ObjectExpression {
|
|
64
80
|
return node.type === "ObjectExpression";
|
|
65
81
|
}
|
|
@@ -7,26 +7,20 @@ import { ensureDir } from "./shared";
|
|
|
7
7
|
* Generates `server.ts` — an intermediate entry used to produce `server.js`.
|
|
8
8
|
*
|
|
9
9
|
* Equivalent to `_compile-entry.ts` but for disk (non-binary) production builds:
|
|
10
|
-
* 1. Statically imports every page module so Bun bundles them
|
|
11
|
-
* 2. Sets production mode and registers
|
|
12
|
-
* 3. Imports server.ts to boot the app
|
|
10
|
+
* 1. Statically imports every page module of every app so Bun bundles them
|
|
11
|
+
* 2. Sets production mode and registers one CompileContext PER APP
|
|
12
|
+
* 3. Imports server.ts to boot the composed app
|
|
13
13
|
*
|
|
14
14
|
* This file is intermediate: `adapter/bun.ts` runs `Bun.build()` on it to produce
|
|
15
15
|
* the self-contained `server.js` bundle, then deletes this file.
|
|
16
16
|
*/
|
|
17
17
|
export function generateServerRoutesEntry(options: BuildEntryOptions): string {
|
|
18
|
-
const {
|
|
19
|
-
options;
|
|
18
|
+
const { apps, outDir, serverEntry } = options;
|
|
20
19
|
ensureDir(outDir);
|
|
21
20
|
const source = buildEntrySource({
|
|
22
|
-
|
|
21
|
+
apps: apps.map(({ embed: _embed, ...context }) => context),
|
|
23
22
|
headerComment: "// Auto-generated by furin build — do not edit",
|
|
24
|
-
rootPath,
|
|
25
|
-
routes,
|
|
26
23
|
serverEntry,
|
|
27
|
-
rootConventions,
|
|
28
|
-
routeMetadata,
|
|
29
|
-
ssgCache,
|
|
30
24
|
});
|
|
31
25
|
|
|
32
26
|
// Named "server.ts" so Bun.build() outputs "server.js"
|
package/src/build/ssg-cache.ts
CHANGED
|
@@ -8,7 +8,11 @@ export type SSGCacheSnapshot = Record<string, SsgCacheEntry>;
|
|
|
8
8
|
export async function buildSSGCacheSnapshot(
|
|
9
9
|
routes: ResolvedRoute[],
|
|
10
10
|
root: RootLayout,
|
|
11
|
-
origin: string
|
|
11
|
+
origin: string,
|
|
12
|
+
// Build-time renders run OUTSIDE any instance scope (default bucket), so a
|
|
13
|
+
// prefixed app's mount prefix must be passed explicitly — otherwise the
|
|
14
|
+
// snapshot HTML bakes in basePath "" and prerendered <Link> hrefs lose it.
|
|
15
|
+
basePath?: string
|
|
12
16
|
): Promise<SSGCacheSnapshot> {
|
|
13
17
|
const snapshot: SSGCacheSnapshot = {};
|
|
14
18
|
const searchRoutes = createSearchRouteMetadata(routes);
|
|
@@ -20,7 +24,7 @@ export async function buildSSGCacheSnapshot(
|
|
|
20
24
|
|
|
21
25
|
const paramSets = await route.page.staticParams();
|
|
22
26
|
for (const params of paramSets) {
|
|
23
|
-
const entry = await prerenderSSG(route, params, root, origin,
|
|
27
|
+
const entry = await prerenderSSG(route, params, root, origin, basePath, searchRoutes);
|
|
24
28
|
if (entry instanceof Response) {
|
|
25
29
|
continue;
|
|
26
30
|
}
|
package/src/build/types.ts
CHANGED
|
@@ -8,6 +8,11 @@ export interface BuildClientOptions {
|
|
|
8
8
|
* correct physical URLs. Pass "" for root deployments.
|
|
9
9
|
*/
|
|
10
10
|
basePath: string;
|
|
11
|
+
/**
|
|
12
|
+
* On-disk client dir name under outDir (default "client"). Multi-instance
|
|
13
|
+
* builds pass "client-<slug>" per mounted app.
|
|
14
|
+
*/
|
|
15
|
+
clientDirName?: string;
|
|
11
16
|
/** Inject the evlog client logger into the hydrate entry. Off by default. */
|
|
12
17
|
clientLogging: boolean;
|
|
13
18
|
outDir: string;
|
|
@@ -20,6 +25,12 @@ export interface BuildClientOptions {
|
|
|
20
25
|
*/
|
|
21
26
|
publicPath: string;
|
|
22
27
|
rootLayout: string;
|
|
28
|
+
/**
|
|
29
|
+
* Skip furin-env.d.ts generation. Set for non-root instances in
|
|
30
|
+
* multi-instance dev — the file lives at the project root and only the root
|
|
31
|
+
* app owns it.
|
|
32
|
+
*/
|
|
33
|
+
skipRouteTypes?: boolean;
|
|
23
34
|
}
|
|
24
35
|
|
|
25
36
|
export interface BuildRouteManifestEntry {
|
|
@@ -41,9 +52,29 @@ export interface TargetBuildManifest {
|
|
|
41
52
|
templatePath: string | null;
|
|
42
53
|
}
|
|
43
54
|
|
|
44
|
-
|
|
55
|
+
/** Build manifest entry produced by the `package` adapter. */
|
|
56
|
+
export interface PackageTargetBuildManifest {
|
|
57
|
+
buildId: string;
|
|
58
|
+
generatedAt: string;
|
|
59
|
+
prefix: string;
|
|
60
|
+
targetDir: string;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export type AnyTargetManifest =
|
|
64
|
+
| TargetBuildManifest
|
|
65
|
+
| StaticTargetBuildManifest
|
|
66
|
+
| PackageTargetBuildManifest;
|
|
67
|
+
|
|
68
|
+
/** One mounted app in a multi-instance build. */
|
|
69
|
+
export interface BuildAppSpec {
|
|
70
|
+
pagesDir: string;
|
|
71
|
+
/** Mount prefix (`""` or absent = root). */
|
|
72
|
+
prefix?: string;
|
|
73
|
+
}
|
|
45
74
|
|
|
46
75
|
export interface BuildManifest {
|
|
76
|
+
/** Every mounted app built into this artifact (multi-instance). */
|
|
77
|
+
apps?: Array<{ pagesDir: string; prefix: string; routes: BuildRouteManifestEntry[] }>;
|
|
47
78
|
generatedAt: string;
|
|
48
79
|
pagesDir: string;
|
|
49
80
|
rootDir: string;
|
|
@@ -55,6 +86,11 @@ export interface BuildManifest {
|
|
|
55
86
|
}
|
|
56
87
|
|
|
57
88
|
export interface BuildAppOptions {
|
|
89
|
+
/**
|
|
90
|
+
* Explicit multi-app build (furin.config.ts `apps`). Overrides `pagesDir`
|
|
91
|
+
* and server-entry auto-detection.
|
|
92
|
+
*/
|
|
93
|
+
apps?: BuildAppSpec[];
|
|
58
94
|
/** Inject the evlog client logger into the hydrate entry. Defaults to false. */
|
|
59
95
|
clientLogging?: boolean;
|
|
60
96
|
compile?: "server" | "embed";
|
package/src/cli/config.ts
CHANGED
|
@@ -14,7 +14,12 @@ const DEFAULT_CONFIG_FILENAMES = [
|
|
|
14
14
|
|
|
15
15
|
interface ResolvedCliConfig extends FurinConfig {
|
|
16
16
|
configPath: string | null;
|
|
17
|
-
|
|
17
|
+
/**
|
|
18
|
+
* Only set when the config file declares one — leaving it undefined lets
|
|
19
|
+
* buildApp fall back to scanning server.ts for `furin({ pagesDir, prefix })`
|
|
20
|
+
* calls (multi-instance detection).
|
|
21
|
+
*/
|
|
22
|
+
pagesDir?: string;
|
|
18
23
|
plugins?: Bun.BunPlugin[];
|
|
19
24
|
rootDir: string;
|
|
20
25
|
}
|
|
@@ -34,7 +39,6 @@ export async function loadCliConfig(
|
|
|
34
39
|
return {
|
|
35
40
|
configPath: null,
|
|
36
41
|
rootDir,
|
|
37
|
-
pagesDir: resolve(rootDir, "src/pages"),
|
|
38
42
|
};
|
|
39
43
|
}
|
|
40
44
|
|
|
@@ -63,6 +67,8 @@ export async function loadCliConfig(
|
|
|
63
67
|
plugins,
|
|
64
68
|
configPath,
|
|
65
69
|
rootDir: resolvedRootDir,
|
|
66
|
-
pagesDir:
|
|
70
|
+
pagesDir: configToValidate.pagesDir
|
|
71
|
+
? resolve(resolvedRootDir, configToValidate.pagesDir)
|
|
72
|
+
: undefined,
|
|
67
73
|
};
|
|
68
74
|
}
|
package/src/cli/index.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { resolve } from "node:path";
|
|
|
4
4
|
import { parseArgs } from "node:util";
|
|
5
5
|
import { buildApp } from "../build/index.ts";
|
|
6
6
|
import { BUILD_TARGETS, type BuildTarget } from "../config.ts";
|
|
7
|
+
import { normalizePrefix } from "../server/instance.ts";
|
|
7
8
|
import { loadCliConfig } from "./config.ts";
|
|
8
9
|
|
|
9
10
|
const argv = process.argv.slice(2);
|
|
@@ -40,6 +41,7 @@ if (command === "build") {
|
|
|
40
41
|
options: {
|
|
41
42
|
target: { type: "string" },
|
|
42
43
|
pagesDir: { type: "string" },
|
|
44
|
+
prefix: { type: "string" },
|
|
43
45
|
config: { type: "string" },
|
|
44
46
|
},
|
|
45
47
|
strict: false,
|
|
@@ -48,6 +50,7 @@ if (command === "build") {
|
|
|
48
50
|
const values = rawValues as {
|
|
49
51
|
target?: string;
|
|
50
52
|
pagesDir?: string;
|
|
53
|
+
prefix?: string;
|
|
51
54
|
config?: string;
|
|
52
55
|
};
|
|
53
56
|
|
|
@@ -70,9 +73,9 @@ if (command === "build") {
|
|
|
70
73
|
|
|
71
74
|
const config = await loadCliConfig(process.cwd(), values.config);
|
|
72
75
|
|
|
73
|
-
const
|
|
76
|
+
const isServerlessTarget = target === "static" || target === "package";
|
|
74
77
|
|
|
75
|
-
const resolvedServerEntry =
|
|
78
|
+
const resolvedServerEntry = isServerlessTarget
|
|
76
79
|
? undefined
|
|
77
80
|
: (() => {
|
|
78
81
|
const entry = resolve(config.rootDir, config.serverEntry ?? "src/server.ts");
|
|
@@ -89,7 +92,20 @@ if (command === "build") {
|
|
|
89
92
|
target: target as BuildTarget | "all",
|
|
90
93
|
compile: resolveCompileMode(compileFlag, config.bun?.compile),
|
|
91
94
|
rootDir: config.rootDir,
|
|
92
|
-
|
|
95
|
+
// --pagesDir/--prefix build a single explicit app; otherwise fall back to
|
|
96
|
+
// the config's `apps` list (then to server.ts scanning inside buildApp).
|
|
97
|
+
// normalizePrefix here so a bad --prefix fails before buildApp starts
|
|
98
|
+
// (resolveAppSpecs normalizes config-provided prefixes the same way).
|
|
99
|
+
apps:
|
|
100
|
+
(values.pagesDir ?? config.pagesDir)
|
|
101
|
+
? [
|
|
102
|
+
{
|
|
103
|
+
pagesDir: values.pagesDir ?? (config.pagesDir as string),
|
|
104
|
+
prefix: normalizePrefix(values.prefix),
|
|
105
|
+
},
|
|
106
|
+
]
|
|
107
|
+
: config.apps,
|
|
108
|
+
pagesDir: undefined,
|
|
93
109
|
serverEntry: resolvedServerEntry,
|
|
94
110
|
plugins: config.plugins,
|
|
95
111
|
staticConfig: config.static,
|
|
@@ -106,7 +122,9 @@ USAGE furin build [options]
|
|
|
106
122
|
|
|
107
123
|
OPTIONS
|
|
108
124
|
--target ${BUILD_TARGETS.join(" | ")} | all (default: bun)
|
|
125
|
+
"package" builds a publishable Elysia-plugin artifact (register.js + factory + client assets)
|
|
109
126
|
--pagesDir Pages directory
|
|
127
|
+
--prefix Mount prefix for the built app (e.g. /admin) — pairs with --pagesDir
|
|
110
128
|
--config Config file path
|
|
111
129
|
--compile server | embed Compile to binary: "server" keeps client on disk, "embed" is self-contained
|
|
112
130
|
`
|
package/src/config.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { BunPlugin } from "bun";
|
|
2
2
|
import { t } from "elysia";
|
|
3
3
|
|
|
4
|
-
export const BUILD_TARGETS = ["bun", "node", "vercel", "cloudflare", "static"] as const;
|
|
4
|
+
export const BUILD_TARGETS = ["bun", "node", "vercel", "cloudflare", "static", "package"] as const;
|
|
5
5
|
|
|
6
6
|
export type BuildTarget = (typeof BUILD_TARGETS)[number];
|
|
7
7
|
|
|
@@ -37,6 +37,19 @@ const compileTargetSchema = t.Union([t.Literal("server"), t.Literal("embed")]);
|
|
|
37
37
|
export const configSchema = t.Object({
|
|
38
38
|
rootDir: t.Optional(t.String()),
|
|
39
39
|
pagesDir: t.Optional(t.String()),
|
|
40
|
+
/**
|
|
41
|
+
* Multi-instance builds: one entry per mounted furin app. Overrides
|
|
42
|
+
* `pagesDir` and server-entry auto-detection. `prefix` must match the
|
|
43
|
+
* `furin({ prefix })` the app is mounted with (`""`/absent = root).
|
|
44
|
+
*/
|
|
45
|
+
apps: t.Optional(
|
|
46
|
+
t.Array(
|
|
47
|
+
t.Object({
|
|
48
|
+
pagesDir: t.String(),
|
|
49
|
+
prefix: t.Optional(t.String()),
|
|
50
|
+
})
|
|
51
|
+
)
|
|
52
|
+
),
|
|
40
53
|
serverEntry: t.Optional(t.String()),
|
|
41
54
|
/**
|
|
42
55
|
* Initialize the browser HTTP log drain in the hydration entry. Off by
|