@teyik0/furin 0.2.0-alpha.3 → 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.
Files changed (98) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +37 -33
  3. package/dist/adapter/bun.d.ts +17 -1
  4. package/dist/adapter/package.d.ts +26 -0
  5. package/dist/build/client.d.ts +1 -1
  6. package/dist/build/compile-entry.d.ts +3 -3
  7. package/dist/build/compile-entry.ts +114 -109
  8. package/dist/build/entry-template.d.ts +35 -9
  9. package/dist/build/entry-template.ts +206 -156
  10. package/dist/build/hydrate.d.ts +1 -1
  11. package/dist/build/index.js +643 -247
  12. package/dist/build/scan-server.d.ts +10 -4
  13. package/dist/build/server-routes-entry.d.ts +3 -3
  14. package/dist/build/server-routes-entry.ts +30 -36
  15. package/dist/build/ssg-cache.d.ts +1 -1
  16. package/dist/build/types.d.ts +36 -1
  17. package/dist/cli/config.d.ts +6 -1
  18. package/dist/cli/index.js +662 -260
  19. package/dist/client/link.js +163 -16
  20. package/dist/client/router/abort.d.ts +1 -0
  21. package/dist/client/router/sync-catch-up.d.ts +29 -0
  22. package/dist/config.d.ts +11 -2
  23. package/dist/config.js +5 -1
  24. package/dist/furin.d.ts +37 -19
  25. package/dist/furin.js +982 -378
  26. package/dist/server/auto-invalidate/registry.d.ts +8 -1
  27. package/dist/server/cache/dev-loader.d.ts +3 -2
  28. package/dist/server/cache/invalidation.d.ts +19 -0
  29. package/dist/server/cache/isr.d.ts +6 -2
  30. package/dist/server/cache/registry.d.ts +3 -3
  31. package/dist/server/cache/ssg.d.ts +6 -2
  32. package/dist/server/cache/store-view.d.ts +11 -0
  33. package/dist/server/instance.d.ts +86 -0
  34. package/dist/server/internal.d.ts +16 -1
  35. package/dist/server/internal.js +72 -5
  36. package/dist/server/render/template.d.ts +3 -2
  37. package/dist/server/sync/adapter.d.ts +62 -0
  38. package/dist/server/sync/config.d.ts +11 -0
  39. package/dist/server/sync/fingerprint.d.ts +6 -0
  40. package/dist/server/sync/index.d.ts +2 -2
  41. package/dist/server/sync/memory-adapter.d.ts +17 -0
  42. package/dist/server/sync/plugin.d.ts +12 -195
  43. package/dist/server/sync/response.d.ts +4 -0
  44. package/dist/server/sync/stream.d.ts +24 -5
  45. package/dist/shared/prefix.d.ts +15 -0
  46. package/package.json +6 -1
  47. package/src/adapter/README.md +13 -13
  48. package/src/adapter/bun.ts +113 -50
  49. package/src/adapter/package.ts +206 -0
  50. package/src/build/client.ts +158 -152
  51. package/src/build/compile-entry.ts +114 -109
  52. package/src/build/entry-template.ts +206 -156
  53. package/src/build/hydrate.ts +342 -340
  54. package/src/build/index.ts +223 -152
  55. package/src/build/route-types.ts +145 -145
  56. package/src/build/scan-server.ts +111 -95
  57. package/src/build/server-routes-entry.ts +30 -36
  58. package/src/build/shared.ts +80 -80
  59. package/src/build/ssg-cache.ts +36 -32
  60. package/src/build/types.ts +125 -89
  61. package/src/cli/config.ts +9 -3
  62. package/src/cli/index.ts +21 -3
  63. package/src/client/router/abort.ts +5 -0
  64. package/src/client/router/link-utils.ts +184 -184
  65. package/src/client/router/provider.tsx +883 -804
  66. package/src/client/router/sync-catch-up.ts +113 -0
  67. package/src/client/router/types.ts +276 -276
  68. package/src/client/sync.ts +98 -98
  69. package/src/client.ts +369 -369
  70. package/src/config.ts +14 -1
  71. package/src/furin.ts +619 -465
  72. package/src/server/auto-invalidate/registry.ts +23 -1
  73. package/src/server/auto-invalidate/runtime.ts +159 -134
  74. package/src/server/cache/dev-loader.ts +77 -38
  75. package/src/server/cache/invalidation.ts +71 -30
  76. package/src/server/cache/isr.ts +20 -5
  77. package/src/server/cache/registry.ts +17 -20
  78. package/src/server/cache/ssg.ts +19 -4
  79. package/src/server/cache/store-view.ts +30 -0
  80. package/src/server/dev-page-plugin.ts +454 -454
  81. package/src/server/instance.ts +252 -0
  82. package/src/server/internal.ts +100 -5
  83. package/src/server/render/assemble.ts +160 -160
  84. package/src/server/render/isr.ts +323 -323
  85. package/src/server/render/not-found.ts +9 -3
  86. package/src/server/render/ssr.ts +603 -585
  87. package/src/server/render/template.ts +57 -24
  88. package/src/server/router/plugin.ts +384 -384
  89. package/src/server/sync/adapter.ts +65 -0
  90. package/src/server/sync/config.ts +60 -29
  91. package/src/server/sync/fingerprint.ts +44 -0
  92. package/src/server/sync/index.ts +15 -14
  93. package/src/server/sync/memory-adapter.ts +196 -0
  94. package/src/server/sync/plugin.ts +199 -108
  95. package/src/server/sync/response.ts +77 -0
  96. package/src/server/sync/stream.ts +162 -144
  97. package/src/shared/deferred-ndjson.ts +7 -0
  98. package/src/shared/prefix.ts +38 -0
@@ -1,80 +1,80 @@
1
- import { cpSync, existsSync, mkdirSync, readdirSync, rmSync } from "node:fs";
2
- import { join, relative } from "node:path";
3
- import { fileURLToPath } from "node:url";
4
- import type { BuildTarget } from "../config";
5
- import type { ResolvedRoute } from "../server/router/index.ts";
6
- import type { BuildRouteManifestEntry, TargetBuildManifest } from "./types";
7
-
8
- // import.meta.dir/path/url are inlined at bundle time to the OUTPUT file's
9
- // location — so relative paths break when bundled. import.meta.resolve() is a
10
- // function call (not inlined), runs at runtime, and resolves through package
11
- // exports. This is the Web-standard approach (Bun, Node 20.6+, browsers).
12
- export const CLIENT_MODULE_PATH = fileURLToPath(import.meta.resolve("@teyik0/furin/client"));
13
- export const LINK_MODULE_PATH = fileURLToPath(import.meta.resolve("@teyik0/furin/link"));
14
- export const SEARCH_MODULE_PATH = fileURLToPath(import.meta.resolve("@teyik0/furin/search"));
15
-
16
- export function ensureDir(path: string): void {
17
- if (!existsSync(path)) {
18
- mkdirSync(path, { recursive: true });
19
- }
20
- }
21
-
22
- export function toPosixPath(path: string): string {
23
- return path.replace(/\\/g, "/");
24
- }
25
-
26
- export function collectFilesRecursive(dir: string): string[] {
27
- const files: string[] = [];
28
- const entries = readdirSync(dir, { withFileTypes: true });
29
-
30
- for (const entry of entries) {
31
- const absolutePath = join(dir, entry.name);
32
- if (entry.isDirectory()) {
33
- files.push(...collectFilesRecursive(absolutePath));
34
- continue;
35
- }
36
- if (entry.isFile()) {
37
- files.push(absolutePath);
38
- }
39
- }
40
-
41
- return files.sort();
42
- }
43
-
44
- export function copyDirRecursive(sourceDir: string, targetDir: string): void {
45
- rmSync(targetDir, { force: true, recursive: true });
46
- cpSync(sourceDir, targetDir, { recursive: true });
47
- }
48
-
49
- export function toBuildRouteManifestEntry(
50
- route: ResolvedRoute,
51
- rootDir: string
52
- ): BuildRouteManifestEntry {
53
- return {
54
- pattern: route.pattern,
55
- mode: route.mode,
56
- pagePath: toPosixPath(relative(rootDir, route.path)),
57
- hasLayout: route.routeChain.some((entry) => !!entry.layout),
58
- hasStaticParams: !!route.page?.staticParams,
59
- revalidate: route.page?._route.revalidate ?? null,
60
- };
61
- }
62
-
63
- export function buildTargetManifest(
64
- rootDir: string,
65
- buildRoot: string,
66
- target: BuildTarget,
67
- serverEntry: string | null
68
- ): TargetBuildManifest {
69
- const targetDir = join(buildRoot, target);
70
-
71
- return {
72
- buildId: "", // populated by adapter after buildClient() completes
73
- generatedAt: new Date().toISOString(),
74
- targetDir: toPosixPath(relative(rootDir, targetDir)),
75
- clientDir: toPosixPath(relative(rootDir, join(targetDir, "client"))),
76
- templatePath: toPosixPath(relative(rootDir, join(targetDir, "client", "index.html"))),
77
- serverPath: null,
78
- serverEntry: serverEntry ? toPosixPath(relative(rootDir, serverEntry)) : null,
79
- };
80
- }
1
+ import { cpSync, existsSync, mkdirSync, readdirSync, rmSync } from "node:fs";
2
+ import { join, relative } from "node:path";
3
+ import { fileURLToPath } from "node:url";
4
+ import type { BuildTarget } from "../config";
5
+ import type { ResolvedRoute } from "../server/router/index.ts";
6
+ import type { BuildRouteManifestEntry, TargetBuildManifest } from "./types";
7
+
8
+ // import.meta.dir/path/url are inlined at bundle time to the OUTPUT file's
9
+ // location — so relative paths break when bundled. import.meta.resolve() is a
10
+ // function call (not inlined), runs at runtime, and resolves through package
11
+ // exports. This is the Web-standard approach (Bun, Node 20.6+, browsers).
12
+ export const CLIENT_MODULE_PATH = fileURLToPath(import.meta.resolve("@teyik0/furin/client"));
13
+ export const LINK_MODULE_PATH = fileURLToPath(import.meta.resolve("@teyik0/furin/link"));
14
+ export const SEARCH_MODULE_PATH = fileURLToPath(import.meta.resolve("@teyik0/furin/search"));
15
+
16
+ export function ensureDir(path: string): void {
17
+ if (!existsSync(path)) {
18
+ mkdirSync(path, { recursive: true });
19
+ }
20
+ }
21
+
22
+ export function toPosixPath(path: string): string {
23
+ return path.replace(/\\/g, "/");
24
+ }
25
+
26
+ export function collectFilesRecursive(dir: string): string[] {
27
+ const files: string[] = [];
28
+ const entries = readdirSync(dir, { withFileTypes: true });
29
+
30
+ for (const entry of entries) {
31
+ const absolutePath = join(dir, entry.name);
32
+ if (entry.isDirectory()) {
33
+ files.push(...collectFilesRecursive(absolutePath));
34
+ continue;
35
+ }
36
+ if (entry.isFile()) {
37
+ files.push(absolutePath);
38
+ }
39
+ }
40
+
41
+ return files.sort();
42
+ }
43
+
44
+ export function copyDirRecursive(sourceDir: string, targetDir: string): void {
45
+ rmSync(targetDir, { force: true, recursive: true });
46
+ cpSync(sourceDir, targetDir, { recursive: true });
47
+ }
48
+
49
+ export function toBuildRouteManifestEntry(
50
+ route: ResolvedRoute,
51
+ rootDir: string
52
+ ): BuildRouteManifestEntry {
53
+ return {
54
+ pattern: route.pattern,
55
+ mode: route.mode,
56
+ pagePath: toPosixPath(relative(rootDir, route.path)),
57
+ hasLayout: route.routeChain.some((entry) => !!entry.layout),
58
+ hasStaticParams: !!route.page?.staticParams,
59
+ revalidate: route.page?._route.revalidate ?? null,
60
+ };
61
+ }
62
+
63
+ export function buildTargetManifest(
64
+ rootDir: string,
65
+ buildRoot: string,
66
+ target: BuildTarget,
67
+ serverEntry: string | null
68
+ ): TargetBuildManifest {
69
+ const targetDir = join(buildRoot, target);
70
+
71
+ return {
72
+ buildId: "", // populated by adapter after buildClient() completes
73
+ generatedAt: new Date().toISOString(),
74
+ targetDir: toPosixPath(relative(rootDir, targetDir)),
75
+ clientDir: toPosixPath(relative(rootDir, join(targetDir, "client"))),
76
+ templatePath: toPosixPath(relative(rootDir, join(targetDir, "client", "index.html"))),
77
+ serverPath: null,
78
+ serverEntry: serverEntry ? toPosixPath(relative(rootDir, serverEntry)) : null,
79
+ };
80
+ }
@@ -1,32 +1,36 @@
1
- import type { SsgCacheEntry } from "../server/cache/index.ts";
2
- import { prerenderSSG } from "../server/render/index.ts";
3
- import { createSearchRouteMetadata, type ResolvedRoute, type RootLayout } from "../server/router/index.ts";
4
- import { resolvePath } from "../server/render/assemble.ts";
5
-
6
- export type SSGCacheSnapshot = Record<string, SsgCacheEntry>;
7
-
8
- export async function buildSSGCacheSnapshot(
9
- routes: ResolvedRoute[],
10
- root: RootLayout,
11
- origin: string
12
- ): Promise<SSGCacheSnapshot> {
13
- const snapshot: SSGCacheSnapshot = {};
14
- const searchRoutes = createSearchRouteMetadata(routes);
15
-
16
- for (const route of routes) {
17
- if (route.mode !== "ssg" || !route.page.staticParams) {
18
- continue;
19
- }
20
-
21
- const paramSets = await route.page.staticParams();
22
- for (const params of paramSets) {
23
- const entry = await prerenderSSG(route, params, root, origin, undefined, searchRoutes);
24
- if (entry instanceof Response) {
25
- continue;
26
- }
27
- snapshot[resolvePath(route.pattern, params)] = entry;
28
- }
29
- }
30
-
31
- return snapshot;
32
- }
1
+ import type { SsgCacheEntry } from "../server/cache/index.ts";
2
+ import { prerenderSSG } from "../server/render/index.ts";
3
+ import { createSearchRouteMetadata, type ResolvedRoute, type RootLayout } from "../server/router/index.ts";
4
+ import { resolvePath } from "../server/render/assemble.ts";
5
+
6
+ export type SSGCacheSnapshot = Record<string, SsgCacheEntry>;
7
+
8
+ export async function buildSSGCacheSnapshot(
9
+ routes: ResolvedRoute[],
10
+ root: RootLayout,
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
16
+ ): Promise<SSGCacheSnapshot> {
17
+ const snapshot: SSGCacheSnapshot = {};
18
+ const searchRoutes = createSearchRouteMetadata(routes);
19
+
20
+ for (const route of routes) {
21
+ if (route.mode !== "ssg" || !route.page.staticParams) {
22
+ continue;
23
+ }
24
+
25
+ const paramSets = await route.page.staticParams();
26
+ for (const params of paramSets) {
27
+ const entry = await prerenderSSG(route, params, root, origin, basePath, searchRoutes);
28
+ if (entry instanceof Response) {
29
+ continue;
30
+ }
31
+ snapshot[resolvePath(route.pattern, params)] = entry;
32
+ }
33
+ }
34
+
35
+ return snapshot;
36
+ }
@@ -1,89 +1,125 @@
1
- import type { BuildTarget, StaticExportConfig } from "../config";
2
- import type { ResolvedRoute } from "../server/router/index.ts";
3
-
4
- export interface BuildClientOptions {
5
- /**
6
- * Sub-path prefix for the deployment (e.g. "/furin" for GitHub Pages).
7
- * Passed through to the generated hydrate entry so SPA navigation uses
8
- * correct physical URLs. Pass "" for root deployments.
9
- */
10
- basePath: string;
11
- /** Inject the evlog client logger into the hydrate entry. Off by default. */
12
- clientLogging: boolean;
13
- outDir: string;
14
- pagesDir?: string;
15
- plugins?: Bun.BunPlugin[];
16
- /**
17
- * Public path prefix for all emitted JS/CSS chunks.
18
- * Pass "/_client/" for root deployments; override for basePath deployments,
19
- * e.g. "/furin/_client/".
20
- */
21
- publicPath: string;
22
- rootLayout: string;
23
- }
24
-
25
- export interface BuildRouteManifestEntry {
26
- hasLayout: boolean;
27
- hasStaticParams: boolean;
28
- mode: ResolvedRoute["mode"];
29
- pagePath: string;
30
- pattern: string;
31
- revalidate: number | null;
32
- }
33
-
34
- export interface TargetBuildManifest {
35
- buildId: string;
36
- clientDir: string | null;
37
- generatedAt: string;
38
- serverEntry: string | null;
39
- serverPath: string | null;
40
- targetDir: string;
41
- templatePath: string | null;
42
- }
43
-
44
- export type AnyTargetManifest = TargetBuildManifest | StaticTargetBuildManifest;
45
-
46
- export interface BuildManifest {
47
- generatedAt: string;
48
- pagesDir: string;
49
- rootDir: string;
50
- rootPath: string;
51
- routes: BuildRouteManifestEntry[];
52
- serverEntry: string | null;
53
- targets: Partial<Record<BuildTarget, AnyTargetManifest>>;
54
- version: 1;
55
- }
56
-
57
- export interface BuildAppOptions {
58
- /** Inject the evlog client logger into the hydrate entry. Defaults to false. */
59
- clientLogging?: boolean;
60
- compile?: "server" | "embed";
61
- pagesDir?: string;
62
- plugins?: Bun.BunPlugin[];
63
- rootDir?: string;
64
- serverEntry?: string;
65
- /** Configuration for the `static` build target. */
66
- staticConfig?: StaticExportConfig;
67
- target: BuildTarget | "all";
68
- }
69
-
70
- /** Build manifest entry produced by the `static` adapter. */
71
- export interface StaticTargetBuildManifest {
72
- basePath: string;
73
- generatedAt: string;
74
- outDir: string;
75
- renderedRoutes: string[];
76
- skippedRoutes: string[];
77
- }
78
-
79
- export interface BuildAppResult {
80
- manifest: BuildManifest;
81
- targets: Partial<Record<BuildTarget, AnyTargetManifest>>;
82
- }
83
-
84
- export type BunBuildAliasConfig = Bun.BuildConfig & {
85
- alias?: Record<string, string>;
86
- outfile?: string;
87
- packages?: "bundle" | "external";
88
- write?: boolean;
89
- };
1
+ import type { BuildTarget, StaticExportConfig } from "../config";
2
+ import type { ResolvedRoute } from "../server/router/index.ts";
3
+
4
+ export interface BuildClientOptions {
5
+ /**
6
+ * Sub-path prefix for the deployment (e.g. "/furin" for GitHub Pages).
7
+ * Passed through to the generated hydrate entry so SPA navigation uses
8
+ * correct physical URLs. Pass "" for root deployments.
9
+ */
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;
16
+ /** Inject the evlog client logger into the hydrate entry. Off by default. */
17
+ clientLogging: boolean;
18
+ outDir: string;
19
+ pagesDir?: string;
20
+ plugins?: Bun.BunPlugin[];
21
+ /**
22
+ * Public path prefix for all emitted JS/CSS chunks.
23
+ * Pass "/_client/" for root deployments; override for basePath deployments,
24
+ * e.g. "/furin/_client/".
25
+ */
26
+ publicPath: string;
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;
34
+ }
35
+
36
+ export interface BuildRouteManifestEntry {
37
+ hasLayout: boolean;
38
+ hasStaticParams: boolean;
39
+ mode: ResolvedRoute["mode"];
40
+ pagePath: string;
41
+ pattern: string;
42
+ revalidate: number | null;
43
+ }
44
+
45
+ export interface TargetBuildManifest {
46
+ buildId: string;
47
+ clientDir: string | null;
48
+ generatedAt: string;
49
+ serverEntry: string | null;
50
+ serverPath: string | null;
51
+ targetDir: string;
52
+ templatePath: string | null;
53
+ }
54
+
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
+ }
74
+
75
+ export interface BuildManifest {
76
+ /** Every mounted app built into this artifact (multi-instance). */
77
+ apps?: Array<{ pagesDir: string; prefix: string; routes: BuildRouteManifestEntry[] }>;
78
+ generatedAt: string;
79
+ pagesDir: string;
80
+ rootDir: string;
81
+ rootPath: string;
82
+ routes: BuildRouteManifestEntry[];
83
+ serverEntry: string | null;
84
+ targets: Partial<Record<BuildTarget, AnyTargetManifest>>;
85
+ version: 1;
86
+ }
87
+
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[];
94
+ /** Inject the evlog client logger into the hydrate entry. Defaults to false. */
95
+ clientLogging?: boolean;
96
+ compile?: "server" | "embed";
97
+ pagesDir?: string;
98
+ plugins?: Bun.BunPlugin[];
99
+ rootDir?: string;
100
+ serverEntry?: string;
101
+ /** Configuration for the `static` build target. */
102
+ staticConfig?: StaticExportConfig;
103
+ target: BuildTarget | "all";
104
+ }
105
+
106
+ /** Build manifest entry produced by the `static` adapter. */
107
+ export interface StaticTargetBuildManifest {
108
+ basePath: string;
109
+ generatedAt: string;
110
+ outDir: string;
111
+ renderedRoutes: string[];
112
+ skippedRoutes: string[];
113
+ }
114
+
115
+ export interface BuildAppResult {
116
+ manifest: BuildManifest;
117
+ targets: Partial<Record<BuildTarget, AnyTargetManifest>>;
118
+ }
119
+
120
+ export type BunBuildAliasConfig = Bun.BuildConfig & {
121
+ alias?: Record<string, string>;
122
+ outfile?: string;
123
+ packages?: "bundle" | "external";
124
+ write?: boolean;
125
+ };
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
- pagesDir: string;
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: resolve(resolvedRootDir, configToValidate.pagesDir ?? "src/pages"),
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 isStaticTarget = target === "static";
76
+ const isServerlessTarget = target === "static" || target === "package";
74
77
 
75
- const resolvedServerEntry = isStaticTarget
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
- pagesDir: values.pagesDir ?? config.pagesDir,
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
  `
@@ -0,0 +1,5 @@
1
+ export function isAbortError(error: unknown): boolean {
2
+ return (
3
+ error !== null && typeof error === "object" && "name" in error && error.name === "AbortError"
4
+ );
5
+ }