@teyik0/furin 0.2.0-alpha.2 → 0.2.0-alpha.3
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/LICENSE +21 -21
- package/README.md +33 -33
- package/dist/adapter/bun.d.ts +3 -0
- package/dist/adapter/static.d.ts +3 -0
- package/dist/build/client.d.ts +25 -0
- package/dist/build/compile-entry.d.ts +9 -0
- package/dist/build/compile-entry.ts +109 -0
- package/dist/build/entry-template.d.ts +38 -0
- package/dist/build/entry-template.ts +156 -0
- package/dist/build/hydrate.d.ts +24 -0
- package/dist/build/index.d.ts +8 -0
- package/dist/build/index.js +8106 -0
- package/dist/build/route-types.d.ts +23 -0
- package/dist/build/scan-server.d.ts +8 -0
- package/dist/build/server-routes-entry.d.ts +13 -0
- package/dist/build/server-routes-entry.ts +36 -0
- package/dist/build/shared.d.ts +12 -0
- package/dist/build/ssg-cache.d.ts +4 -0
- package/dist/build/types.d.ts +80 -0
- package/dist/cli/config.d.ts +9 -0
- package/dist/cli/index.d.ts +2 -0
- package/dist/cli/index.js +8097 -0
- package/dist/client/boundaries.d.ts +117 -0
- package/dist/client/default-screens.d.ts +17 -0
- package/dist/client/link.d.ts +22 -0
- package/dist/client/link.js +4244 -0
- package/dist/client/router/boundary-tree.d.ts +26 -0
- package/dist/client/router/context.d.ts +8 -0
- package/dist/client/router/history.d.ts +9 -0
- package/dist/client/router/index.d.ts +11 -0
- package/dist/client/router/link-utils.d.ts +53 -0
- package/dist/client/router/navigation.d.ts +10 -0
- package/dist/client/router/provider.d.ts +4 -0
- package/dist/client/router/search/index.d.ts +18 -0
- package/dist/client/router/search-store.d.ts +21 -0
- package/dist/client/router/spa-response.d.ts +58 -0
- package/dist/client/router/types.d.ts +292 -0
- package/dist/client/server-error.d.ts +12 -0
- package/dist/client/sync.d.ts +25 -0
- package/dist/client.d.ts +243 -0
- package/dist/client.js +140 -0
- package/dist/config.d.ts +57 -0
- package/dist/config.js +29 -0
- package/dist/env.d.ts +50 -0
- package/dist/furin.d.ts +77 -0
- package/dist/furin.js +8693 -0
- package/dist/plugin/index.d.ts +20 -0
- package/dist/plugin/index.js +1500 -0
- package/dist/plugin/transform-client.d.ts +10 -0
- package/dist/server/auto-invalidate/index.d.ts +4 -0
- package/dist/server/auto-invalidate/plugin.d.ts +38 -0
- package/dist/server/auto-invalidate/registry.d.ts +9 -0
- package/dist/server/auto-invalidate/runtime.d.ts +9 -0
- package/dist/server/auto-invalidate/types.d.ts +12 -0
- package/dist/server/cache/dev-loader.d.ts +28 -0
- package/dist/server/cache/index.d.ts +10 -0
- package/dist/server/cache/invalidation.d.ts +12 -0
- package/dist/server/cache/isr-ssg.d.ts +26 -0
- package/dist/server/cache/isr.d.ts +6 -0
- package/dist/server/cache/registry.d.ts +5 -0
- package/dist/server/cache/route-cache.d.ts +26 -0
- package/dist/server/cache/ssg.d.ts +5 -0
- package/dist/server/context-logger.d.ts +28 -0
- package/dist/server/dev-inspector.d.ts +89 -0
- package/dist/server/dev-page-plugin.d.ts +112 -0
- package/dist/server/internal.d.ts +35 -0
- package/dist/server/internal.js +17 -0
- package/dist/server/lang-detect.d.ts +5 -0
- package/dist/server/render/assemble.d.ts +49 -0
- package/dist/server/render/element.d.ts +24 -0
- package/dist/server/render/index.d.ts +7 -0
- package/dist/server/render/index.ts +22 -0
- package/dist/server/render/isr.d.ts +4 -0
- package/dist/server/render/loaders.d.ts +64 -0
- package/dist/server/render/not-found.d.ts +6 -0
- package/dist/server/render/shell.d.ts +39 -0
- package/dist/server/render/shell.ts +202 -0
- package/dist/server/render/ssg.d.ts +9 -0
- package/dist/server/render/ssr.d.ts +108 -0
- package/dist/server/render/template.d.ts +6 -0
- package/dist/server/router/discovery.d.ts +16 -0
- package/dist/server/router/hmr.d.ts +65 -0
- package/dist/server/router/index.d.ts +6 -0
- package/dist/server/router/index.js +27 -0
- package/dist/server/router/index.ts +28 -0
- package/dist/server/router/patterns.d.ts +40 -0
- package/dist/server/router/plugin.d.ts +21 -0
- package/dist/server/router/schemas.d.ts +59 -0
- package/dist/server/router/types.d.ts +60 -0
- package/dist/server/runtime-env.d.ts +3 -0
- package/dist/server/runtime-env.js +10 -0
- package/dist/server/sync/config.d.ts +6 -0
- package/dist/server/sync/index.d.ts +4 -0
- package/dist/server/sync/plugin.d.ts +369 -0
- package/dist/server/sync/stream.d.ts +47 -0
- package/dist/shared/await.d.ts +67 -0
- package/dist/shared/deferred-ndjson.d.ts +32 -0
- package/dist/shared/digest.d.ts +16 -0
- package/dist/shared/error.d.ts +37 -0
- package/dist/shared/not-found.d.ts +19 -0
- package/dist/shared/search-params.d.ts +17 -0
- package/dist/shared/utils/ast-walk.d.ts +18 -0
- package/dist/shared/utils/index.d.ts +13 -0
- package/package.json +5 -5
- package/src/adapter/README.md +13 -13
- package/src/build/client.ts +152 -152
- package/src/build/compile-entry.ts +109 -109
- package/src/build/entry-template.ts +156 -156
- package/src/build/hydrate.ts +340 -337
- package/src/build/index.ts +152 -152
- package/src/build/route-types.ts +145 -145
- package/src/build/scan-server.ts +95 -95
- package/src/build/server-routes-entry.ts +36 -36
- package/src/build/shared.ts +80 -79
- package/src/build/ssg-cache.ts +32 -32
- package/src/build/types.ts +89 -89
- package/src/client/router/link-utils.ts +184 -177
- package/src/client/router/provider.tsx +804 -759
- package/src/client/router/types.ts +276 -271
- package/src/client/sync.ts +98 -0
- package/src/client.ts +369 -355
- package/src/furin.ts +465 -444
- package/src/server/auto-invalidate/runtime.ts +134 -133
- package/src/server/dev-page-plugin.ts +454 -449
- package/src/server/render/assemble.ts +160 -133
- package/src/server/render/isr.ts +323 -317
- package/src/server/render/ssr.ts +585 -583
- package/src/server/router/plugin.ts +384 -384
- package/src/server/sync/config.ts +29 -0
- package/src/server/sync/index.ts +14 -0
- package/src/server/sync/plugin.ts +108 -0
- package/src/server/sync/stream.ts +144 -0
package/src/build/scan-server.ts
CHANGED
|
@@ -1,95 +1,95 @@
|
|
|
1
|
-
import { readFileSync } from "node:fs";
|
|
2
|
-
import { parse, type CallExpression, type ObjectExpression, type ObjectProperty } from "yuku-parser";
|
|
3
|
-
import { detectLangFromPath, unwrapTSExpression } from "../server/lang-detect.ts";
|
|
4
|
-
import { walkAST } from "../shared/utils/ast-walk.ts";
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Statically scans a server entry file and returns all `pagesDir` string
|
|
8
|
-
* literal values found inside `furin({ pagesDir: "..." })` call expressions.
|
|
9
|
-
*
|
|
10
|
-
* Dynamic paths (template literals, variables) are silently ignored.
|
|
11
|
-
* Returns an empty array when nothing is detected.
|
|
12
|
-
*/
|
|
13
|
-
export function scanFurinInstances(serverEntryPath: string): string[] {
|
|
14
|
-
const code = readFileSync(serverEntryPath, "utf8");
|
|
15
|
-
const lang = detectLangFromPath(serverEntryPath);
|
|
16
|
-
|
|
17
|
-
// Declaration files contain no runtime code — skip parsing.
|
|
18
|
-
if (lang === "dts") {
|
|
19
|
-
return [];
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const { program, diagnostics } = parse(code, { sourceType: "module", lang });
|
|
23
|
-
const firstError = diagnostics.find((d) => d.severity === "error");
|
|
24
|
-
if (firstError) {
|
|
25
|
-
console.error("[furin] scan-server: parse error:", firstError.message, "in", serverEntryPath);
|
|
26
|
-
return [];
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const results: string[] = [];
|
|
30
|
-
walkAST(program, (node) => {
|
|
31
|
-
if (node.type === "CallExpression") {
|
|
32
|
-
checkFurinCall(node as unknown as CallExpression, results);
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
return results;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/** Checks whether `node` is a `furin({ pagesDir: "..." })` call and, if so, pushes the value. */
|
|
39
|
-
function checkFurinCall(node: CallExpression, out: string[]): void {
|
|
40
|
-
const isFurinCall = node.callee.type === "Identifier" && node.callee.name === "furin";
|
|
41
|
-
|
|
42
|
-
if (!isFurinCall || node.arguments.length === 0) {
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// Unwrap TS expression wrappers like `furin({...} as Config)` or
|
|
47
|
-
// `furin({...} satisfies Options)` so we still see the ObjectExpression.
|
|
48
|
-
const firstArgNode = node.arguments[0];
|
|
49
|
-
if (!firstArgNode) {
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
52
|
-
const firstArg = unwrapTSExpression(firstArgNode);
|
|
53
|
-
if (!isObjectExpressionNode(firstArg)) {
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
const pagesDir = extractStringProperty(firstArg, "pagesDir");
|
|
58
|
-
if (pagesDir !== null) {
|
|
59
|
-
out.push(pagesDir);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
function isObjectExpressionNode(node: { type: string }): node is ObjectExpression {
|
|
64
|
-
return node.type === "ObjectExpression";
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
function extractStringProperty(obj: ObjectExpression, propName: string): string | null {
|
|
68
|
-
for (const prop of obj.properties) {
|
|
69
|
-
if (prop.type !== "Property") {
|
|
70
|
-
continue;
|
|
71
|
-
}
|
|
72
|
-
const value = getStringPropertyValue(prop, propName);
|
|
73
|
-
|
|
74
|
-
if (value !== undefined) {
|
|
75
|
-
return value;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
return null;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
function getStringPropertyValue(prop: ObjectProperty, propName: string): string | null | undefined {
|
|
82
|
-
const keyMatches =
|
|
83
|
-
(prop.key.type === "Identifier" && prop.key.name === propName) ||
|
|
84
|
-
(prop.key.type === "Literal" && prop.key.value === propName);
|
|
85
|
-
|
|
86
|
-
if (!keyMatches) {
|
|
87
|
-
return undefined;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
// Only accept string literals — ignore template literals, identifiers, etc.
|
|
91
|
-
if (prop.value.type === "Literal" && typeof prop.value.value === "string") {
|
|
92
|
-
return prop.value.value;
|
|
93
|
-
}
|
|
94
|
-
return null; // dynamic path — silently skip
|
|
95
|
-
}
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { parse, type CallExpression, type ObjectExpression, type ObjectProperty } from "yuku-parser";
|
|
3
|
+
import { detectLangFromPath, unwrapTSExpression } from "../server/lang-detect.ts";
|
|
4
|
+
import { walkAST } from "../shared/utils/ast-walk.ts";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Statically scans a server entry file and returns all `pagesDir` string
|
|
8
|
+
* literal values found inside `furin({ pagesDir: "..." })` call expressions.
|
|
9
|
+
*
|
|
10
|
+
* Dynamic paths (template literals, variables) are silently ignored.
|
|
11
|
+
* Returns an empty array when nothing is detected.
|
|
12
|
+
*/
|
|
13
|
+
export function scanFurinInstances(serverEntryPath: string): string[] {
|
|
14
|
+
const code = readFileSync(serverEntryPath, "utf8");
|
|
15
|
+
const lang = detectLangFromPath(serverEntryPath);
|
|
16
|
+
|
|
17
|
+
// Declaration files contain no runtime code — skip parsing.
|
|
18
|
+
if (lang === "dts") {
|
|
19
|
+
return [];
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const { program, diagnostics } = parse(code, { sourceType: "module", lang });
|
|
23
|
+
const firstError = diagnostics.find((d) => d.severity === "error");
|
|
24
|
+
if (firstError) {
|
|
25
|
+
console.error("[furin] scan-server: parse error:", firstError.message, "in", serverEntryPath);
|
|
26
|
+
return [];
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const results: string[] = [];
|
|
30
|
+
walkAST(program, (node) => {
|
|
31
|
+
if (node.type === "CallExpression") {
|
|
32
|
+
checkFurinCall(node as unknown as CallExpression, results);
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
return results;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** Checks whether `node` is a `furin({ pagesDir: "..." })` call and, if so, pushes the value. */
|
|
39
|
+
function checkFurinCall(node: CallExpression, out: string[]): void {
|
|
40
|
+
const isFurinCall = node.callee.type === "Identifier" && node.callee.name === "furin";
|
|
41
|
+
|
|
42
|
+
if (!isFurinCall || node.arguments.length === 0) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Unwrap TS expression wrappers like `furin({...} as Config)` or
|
|
47
|
+
// `furin({...} satisfies Options)` so we still see the ObjectExpression.
|
|
48
|
+
const firstArgNode = node.arguments[0];
|
|
49
|
+
if (!firstArgNode) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
const firstArg = unwrapTSExpression(firstArgNode);
|
|
53
|
+
if (!isObjectExpressionNode(firstArg)) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const pagesDir = extractStringProperty(firstArg, "pagesDir");
|
|
58
|
+
if (pagesDir !== null) {
|
|
59
|
+
out.push(pagesDir);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function isObjectExpressionNode(node: { type: string }): node is ObjectExpression {
|
|
64
|
+
return node.type === "ObjectExpression";
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function extractStringProperty(obj: ObjectExpression, propName: string): string | null {
|
|
68
|
+
for (const prop of obj.properties) {
|
|
69
|
+
if (prop.type !== "Property") {
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
const value = getStringPropertyValue(prop, propName);
|
|
73
|
+
|
|
74
|
+
if (value !== undefined) {
|
|
75
|
+
return value;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function getStringPropertyValue(prop: ObjectProperty, propName: string): string | null | undefined {
|
|
82
|
+
const keyMatches =
|
|
83
|
+
(prop.key.type === "Identifier" && prop.key.name === propName) ||
|
|
84
|
+
(prop.key.type === "Literal" && prop.key.value === propName);
|
|
85
|
+
|
|
86
|
+
if (!keyMatches) {
|
|
87
|
+
return undefined;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// Only accept string literals — ignore template literals, identifiers, etc.
|
|
91
|
+
if (prop.value.type === "Literal" && typeof prop.value.value === "string") {
|
|
92
|
+
return prop.value.value;
|
|
93
|
+
}
|
|
94
|
+
return null; // dynamic path — silently skip
|
|
95
|
+
}
|
|
@@ -1,36 +1,36 @@
|
|
|
1
|
-
import { writeFileSync } from "node:fs";
|
|
2
|
-
import { join } from "node:path";
|
|
3
|
-
import { buildEntrySource, type BuildEntryOptions } from "./entry-template";
|
|
4
|
-
import { ensureDir } from "./shared";
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Generates `server.ts` — an intermediate entry used to produce `server.js`.
|
|
8
|
-
*
|
|
9
|
-
* Equivalent to `_compile-entry.ts` but for disk (non-binary) production builds:
|
|
10
|
-
* 1. Statically imports every page module so Bun bundles them into server.js
|
|
11
|
-
* 2. Sets production mode and registers everything in a single CompileContext
|
|
12
|
-
* 3. Imports server.ts to boot the app
|
|
13
|
-
*
|
|
14
|
-
* This file is intermediate: `adapter/bun.ts` runs `Bun.build()` on it to produce
|
|
15
|
-
* the self-contained `server.js` bundle, then deletes this file.
|
|
16
|
-
*/
|
|
17
|
-
export function generateServerRoutesEntry(options: BuildEntryOptions): string {
|
|
18
|
-
const { buildId, outDir, rootPath, routes, serverEntry, rootConventions, routeMetadata, ssgCache } =
|
|
19
|
-
options;
|
|
20
|
-
ensureDir(outDir);
|
|
21
|
-
const source = buildEntrySource({
|
|
22
|
-
buildId,
|
|
23
|
-
headerComment: "// Auto-generated by furin build — do not edit",
|
|
24
|
-
rootPath,
|
|
25
|
-
routes,
|
|
26
|
-
serverEntry,
|
|
27
|
-
rootConventions,
|
|
28
|
-
routeMetadata,
|
|
29
|
-
ssgCache,
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
// Named "server.ts" so Bun.build() outputs "server.js"
|
|
33
|
-
const entryPath = join(outDir, "server.ts");
|
|
34
|
-
writeFileSync(entryPath, source);
|
|
35
|
-
return entryPath;
|
|
36
|
-
}
|
|
1
|
+
import { writeFileSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { buildEntrySource, type BuildEntryOptions } from "./entry-template";
|
|
4
|
+
import { ensureDir } from "./shared";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Generates `server.ts` — an intermediate entry used to produce `server.js`.
|
|
8
|
+
*
|
|
9
|
+
* Equivalent to `_compile-entry.ts` but for disk (non-binary) production builds:
|
|
10
|
+
* 1. Statically imports every page module so Bun bundles them into server.js
|
|
11
|
+
* 2. Sets production mode and registers everything in a single CompileContext
|
|
12
|
+
* 3. Imports server.ts to boot the app
|
|
13
|
+
*
|
|
14
|
+
* This file is intermediate: `adapter/bun.ts` runs `Bun.build()` on it to produce
|
|
15
|
+
* the self-contained `server.js` bundle, then deletes this file.
|
|
16
|
+
*/
|
|
17
|
+
export function generateServerRoutesEntry(options: BuildEntryOptions): string {
|
|
18
|
+
const { buildId, outDir, rootPath, routes, serverEntry, rootConventions, routeMetadata, ssgCache } =
|
|
19
|
+
options;
|
|
20
|
+
ensureDir(outDir);
|
|
21
|
+
const source = buildEntrySource({
|
|
22
|
+
buildId,
|
|
23
|
+
headerComment: "// Auto-generated by furin build — do not edit",
|
|
24
|
+
rootPath,
|
|
25
|
+
routes,
|
|
26
|
+
serverEntry,
|
|
27
|
+
rootConventions,
|
|
28
|
+
routeMetadata,
|
|
29
|
+
ssgCache,
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
// Named "server.ts" so Bun.build() outputs "server.js"
|
|
33
|
+
const entryPath = join(outDir, "server.ts");
|
|
34
|
+
writeFileSync(entryPath, source);
|
|
35
|
+
return entryPath;
|
|
36
|
+
}
|
package/src/build/shared.ts
CHANGED
|
@@ -1,79 +1,80 @@
|
|
|
1
|
-
import { cpSync, existsSync, mkdirSync, readdirSync, rmSync } from "node:fs";
|
|
2
|
-
import { join, relative } from "node:path";
|
|
3
|
-
import
|
|
4
|
-
import type {
|
|
5
|
-
import type {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
//
|
|
9
|
-
//
|
|
10
|
-
//
|
|
11
|
-
|
|
12
|
-
export const
|
|
13
|
-
export const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
}
|
|
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
|
+
}
|
package/src/build/ssg-cache.ts
CHANGED
|
@@ -1,32 +1,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
|
-
): 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
|
+
): 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
|
+
}
|