@teyik0/furin 0.1.0-alpha.12 → 0.1.0-alpha.13
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 -0
- package/README.md +251 -0
- package/dist/build/compile-entry.ts +129 -0
- package/dist/build/entry-template.ts +133 -0
- package/dist/build/index.js +110 -116
- package/dist/build/server-routes-entry.ts +55 -0
- package/dist/cli/index.js +114 -120
- package/dist/env.d.ts +50 -0
- package/dist/furin.js +11 -7
- package/dist/internal.js +17 -0
- package/dist/link.js +9 -7
- package/dist/plugin/index.js +9 -7
- package/dist/render/index.ts +870 -0
- package/dist/render/shell.ts +187 -0
- package/dist/router-provider.d.ts +2 -1
- package/dist/router.js +10 -2
- package/dist/router.ts +1034 -0
- package/dist/runtime-env.js +10 -0
- package/package.json +42 -13
- package/src/adapter/bun.ts +4 -1
- package/src/build/entry-template.ts +13 -6
- package/src/build/scan-server.ts +32 -3
- package/src/link.tsx +2 -1
- package/src/plugin/transform-client.ts +10 -8
- package/src/render/index.ts +4 -3
- package/src/router-provider.tsx +10 -8
package/package.json
CHANGED
|
@@ -1,55 +1,84 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@teyik0/furin",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.13",
|
|
4
|
+
"description": "React meta-framework powered by Elysia and Bun with file-based routing, SSR, SSG, and ISR.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "teyik0",
|
|
7
|
+
"sideEffects": false,
|
|
4
8
|
"type": "module",
|
|
9
|
+
"engines": {
|
|
10
|
+
"bun": ">=1.3.0"
|
|
11
|
+
},
|
|
12
|
+
"keywords": [
|
|
13
|
+
"react",
|
|
14
|
+
"furin",
|
|
15
|
+
"framework",
|
|
16
|
+
"elysia",
|
|
17
|
+
"bun",
|
|
18
|
+
"ssr",
|
|
19
|
+
"ssg",
|
|
20
|
+
"routing",
|
|
21
|
+
"file-based-routing"
|
|
22
|
+
],
|
|
23
|
+
"repository": {
|
|
24
|
+
"type": "git",
|
|
25
|
+
"url": "git+https://github.com/teyik0/furin.git"
|
|
26
|
+
},
|
|
27
|
+
"bugs": {
|
|
28
|
+
"url": "https://github.com/teyik0/furin/issues"
|
|
29
|
+
},
|
|
30
|
+
"homepage": "https://github.com/teyik0/furin#readme",
|
|
5
31
|
"files": [
|
|
6
32
|
"dist",
|
|
7
|
-
"src"
|
|
33
|
+
"src",
|
|
34
|
+
"LICENSE",
|
|
35
|
+
"README.md"
|
|
8
36
|
],
|
|
9
37
|
"main": "./dist/furin.js",
|
|
10
38
|
"module": "./dist/furin.js",
|
|
11
|
-
"types": "./
|
|
39
|
+
"types": "./dist/furin.d.ts",
|
|
12
40
|
"bin": {
|
|
13
|
-
"furin": "./
|
|
41
|
+
"furin": "./dist/cli/index.js"
|
|
14
42
|
},
|
|
15
43
|
"exports": {
|
|
16
44
|
".": {
|
|
17
|
-
"types": "./
|
|
45
|
+
"types": "./dist/furin.d.ts",
|
|
18
46
|
"bun": "./src/furin.ts",
|
|
19
47
|
"import": "./dist/furin.js"
|
|
20
48
|
},
|
|
21
49
|
"./client": {
|
|
22
|
-
"types": "./
|
|
50
|
+
"types": "./dist/client.d.ts",
|
|
23
51
|
"bun": "./src/client.ts",
|
|
24
52
|
"import": "./dist/client.js"
|
|
25
53
|
},
|
|
26
54
|
"./build": {
|
|
27
|
-
"types": "./
|
|
55
|
+
"types": "./dist/build/index.d.ts",
|
|
28
56
|
"bun": "./src/build/index.ts",
|
|
29
57
|
"import": "./dist/build/index.js"
|
|
30
58
|
},
|
|
31
59
|
"./config": {
|
|
32
|
-
"types": "./
|
|
60
|
+
"types": "./dist/config.d.ts",
|
|
33
61
|
"bun": "./src/config.ts",
|
|
34
62
|
"import": "./dist/config.js"
|
|
35
63
|
},
|
|
36
64
|
"./router": {
|
|
37
|
-
"types": "./
|
|
65
|
+
"types": "./dist/router.d.ts",
|
|
38
66
|
"bun": "./src/router.ts",
|
|
39
67
|
"import": "./dist/router.js"
|
|
40
68
|
},
|
|
41
69
|
"./strip-plugin": {
|
|
42
|
-
"types": "./
|
|
70
|
+
"types": "./dist/plugin/index.d.ts",
|
|
43
71
|
"bun": "./src/plugin/index.ts",
|
|
44
72
|
"import": "./dist/plugin/index.js"
|
|
45
73
|
},
|
|
46
74
|
"./link": {
|
|
47
|
-
"types": "./
|
|
75
|
+
"types": "./dist/link.d.ts",
|
|
48
76
|
"bun": "./src/link.tsx",
|
|
49
77
|
"import": "./dist/link.js"
|
|
50
78
|
},
|
|
51
79
|
"./env": {
|
|
52
|
-
"types": "./
|
|
80
|
+
"types": "./dist/env.d.ts",
|
|
81
|
+
"bun": "./src/env.d.ts"
|
|
53
82
|
}
|
|
54
83
|
},
|
|
55
84
|
"scripts": {
|
|
@@ -62,7 +91,7 @@
|
|
|
62
91
|
"dependencies": {
|
|
63
92
|
"@elysiajs/static": "^1.4.10",
|
|
64
93
|
"magic-string": "^0.30.21",
|
|
65
|
-
"
|
|
94
|
+
"yuku-parser": "^0.4.6"
|
|
66
95
|
},
|
|
67
96
|
"devDependencies": {
|
|
68
97
|
"@types/react": "^19.2.14",
|
package/src/adapter/bun.ts
CHANGED
|
@@ -12,7 +12,10 @@ import type { ResolvedRoute, RootLayout } from "../router.ts";
|
|
|
12
12
|
|
|
13
13
|
// import.meta.resolve() runs at runtime (not inlined at bundle time), resolves
|
|
14
14
|
// through package exports, and is the Web-standard API.
|
|
15
|
-
const
|
|
15
|
+
const _pkgRoot = dirname(dirname(fileURLToPath(import.meta.resolve("@teyik0/furin"))));
|
|
16
|
+
const _pkgSrcDir = existsSync(join(_pkgRoot, "src", "furin.ts"))
|
|
17
|
+
? join(_pkgRoot, "src")
|
|
18
|
+
: join(_pkgRoot, "dist");
|
|
16
19
|
const BUILD_ID_INPUT_PATHS = [
|
|
17
20
|
`${_pkgSrcDir}/build/compile-entry.ts`,
|
|
18
21
|
`${_pkgSrcDir}/build/entry-template.ts`,
|
|
@@ -1,11 +1,18 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import { dirname, join } from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
2
4
|
|
|
3
5
|
// import.meta.resolve() runs at runtime (not inlined at bundle time), resolves
|
|
4
|
-
// through package exports, and is the Web-standard API.
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
// through package exports, and is the Web-standard API.
|
|
7
|
+
const _pkgRoot = dirname(dirname(fileURLToPath(import.meta.resolve("@teyik0/furin"))));
|
|
8
|
+
const _pkgSrcDirRaw = existsSync(join(_pkgRoot, "src", "furin.ts"))
|
|
9
|
+
? join(_pkgRoot, "src")
|
|
10
|
+
: join(_pkgRoot, "dist");
|
|
11
|
+
// Normalize to forward slashes so endsWith checks and template paths work on Windows.
|
|
12
|
+
const _pkgSrcDir = _pkgSrcDirRaw.replace(/\\/g, "/");
|
|
13
|
+
const _ext = _pkgSrcDir.endsWith("/src") ? ".ts" : ".js";
|
|
14
|
+
const INTERNAL_MODULE_PATH = `${_pkgSrcDir}/internal${_ext}`;
|
|
15
|
+
const RUNTIME_ENV_MODULE_PATH = `${_pkgSrcDir}/runtime-env${_ext}`;
|
|
9
16
|
|
|
10
17
|
export interface EntryTemplateOptions {
|
|
11
18
|
buildId?: string;
|
package/src/build/scan-server.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { readFileSync } from "node:fs";
|
|
2
|
-
import {
|
|
2
|
+
import { parse } from "yuku-parser";
|
|
3
3
|
|
|
4
4
|
// Minimal AST node shapes — just what we need
|
|
5
5
|
interface AstNode {
|
|
@@ -7,6 +7,19 @@ interface AstNode {
|
|
|
7
7
|
[key: string]: unknown;
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
+
function detectLangFromPath(filePath: string): "js" | "ts" | "jsx" | "tsx" | "dts" {
|
|
11
|
+
if (filePath.endsWith(".d.ts")) {
|
|
12
|
+
return "dts";
|
|
13
|
+
}
|
|
14
|
+
const ext = filePath.split(".").pop()?.toLowerCase();
|
|
15
|
+
switch (ext) {
|
|
16
|
+
case "ts": return "ts";
|
|
17
|
+
case "tsx": return "tsx";
|
|
18
|
+
case "jsx": return "jsx";
|
|
19
|
+
default: return "js";
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
10
23
|
/**
|
|
11
24
|
* Statically scans a server entry file and returns all `pagesDir` string
|
|
12
25
|
* literal values found inside `furin({ pagesDir: "..." })` call expressions.
|
|
@@ -16,8 +29,24 @@ interface AstNode {
|
|
|
16
29
|
*/
|
|
17
30
|
export function scanFurinInstances(serverEntryPath: string): string[] {
|
|
18
31
|
const code = readFileSync(serverEntryPath, "utf8");
|
|
19
|
-
|
|
20
|
-
|
|
32
|
+
let lang = detectLangFromPath(serverEntryPath);
|
|
33
|
+
|
|
34
|
+
// Declaration files contain no runtime code — skip parsing.
|
|
35
|
+
if (lang === "dts") {
|
|
36
|
+
return [];
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
let parseInput = code;
|
|
40
|
+
if (lang === "ts" || lang === "tsx") {
|
|
41
|
+
const transpiler = new Bun.Transpiler({ loader: lang });
|
|
42
|
+
parseInput = transpiler.transformSync(code);
|
|
43
|
+
lang = "js";
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const { program, diagnostics } = parse(parseInput, { sourceType: "module", lang });
|
|
47
|
+
const firstError = diagnostics.find((d) => d.severity === "error");
|
|
48
|
+
if (firstError) {
|
|
49
|
+
console.error("[furin] scan-server: parse error:", firstError.message, "in", serverEntryPath);
|
|
21
50
|
return [];
|
|
22
51
|
}
|
|
23
52
|
|
package/src/link.tsx
CHANGED
|
@@ -3,6 +3,7 @@ import { createElement, useCallback, useEffect, useRef } from "react";
|
|
|
3
3
|
import {
|
|
4
4
|
buildHref,
|
|
5
5
|
type LinkProps,
|
|
6
|
+
normalizeHref,
|
|
6
7
|
RouterContext,
|
|
7
8
|
type RouterContextValue,
|
|
8
9
|
type RouteTo,
|
|
@@ -52,7 +53,7 @@ function computeLinkView<To extends RouteTo>(
|
|
|
52
53
|
logicalHref.startsWith("https://") ||
|
|
53
54
|
logicalHref.startsWith("//");
|
|
54
55
|
const href = isAbsolute ? logicalHref : router.basePath + logicalHref;
|
|
55
|
-
const isActive = router.currentHref === logicalHrefWithoutHash;
|
|
56
|
+
const isActive = !isAbsolute && router.currentHref === normalizeHref(logicalHrefWithoutHash);
|
|
56
57
|
const resolvedChildren = typeof children === "function" ? children({ isActive }) : children;
|
|
57
58
|
const extraProps: React.AnchorHTMLAttributes<HTMLAnchorElement> = {
|
|
58
59
|
...(inactiveProps && !isActive ? inactiveProps() : {}),
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import MagicString from "magic-string";
|
|
2
|
-
import {
|
|
2
|
+
import { parse } from "yuku-parser";
|
|
3
3
|
|
|
4
4
|
// ---------------------------------------------------------------------------
|
|
5
5
|
// Bun.Transpiler singleton — strips TypeScript + JSX before AST work.
|
|
@@ -280,9 +280,10 @@ function removeUnusedSpecifiers(
|
|
|
280
280
|
// ---------------------------------------------------------------------------
|
|
281
281
|
export function deadCodeElimination(s: MagicString): MagicString {
|
|
282
282
|
const code = s.toString();
|
|
283
|
-
const { program,
|
|
284
|
-
|
|
285
|
-
|
|
283
|
+
const { program, diagnostics } = parse(code, { sourceType: "module" });
|
|
284
|
+
const firstError = diagnostics.find((d) => d.severity === "error");
|
|
285
|
+
if (firstError) {
|
|
286
|
+
console.error("[furin] DCE: failed to parse transformed output:", firstError.message);
|
|
286
287
|
return s;
|
|
287
288
|
}
|
|
288
289
|
|
|
@@ -347,10 +348,11 @@ export function transformForClient(code: string, filename: string): TransformRes
|
|
|
347
348
|
// Pass 1 — Bun.Transpiler: strip TypeScript + JSX → plain JS.
|
|
348
349
|
const plainJs = bunTranspiler.transformSync(code);
|
|
349
350
|
|
|
350
|
-
// Pass 2 —
|
|
351
|
-
const { program,
|
|
352
|
-
|
|
353
|
-
|
|
351
|
+
// Pass 2 — yuku-parser: parse plain JS to ESTree AST with span offsets.
|
|
352
|
+
const { program, diagnostics } = parse(plainJs, { sourceType: "module" });
|
|
353
|
+
const firstError = diagnostics.find((d) => d.severity === "error");
|
|
354
|
+
if (firstError) {
|
|
355
|
+
throw new Error(`Failed to parse ${filename}: ${firstError.message}`);
|
|
354
356
|
}
|
|
355
357
|
|
|
356
358
|
// Pass 3 — MagicString: surgically remove server-only properties.
|
package/src/render/index.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
// biome-ignore-all lint/correctness/useHookAtTopLevel: useLogger is not a hook attached to a react component
|
|
1
2
|
import { createElement, type ReactNode } from "react";
|
|
2
3
|
import { renderToReadableStream } from "react-dom/server";
|
|
3
4
|
import { FurinNotFoundError } from "../not-found.ts";
|
|
4
5
|
import type { RootLayout } from "../router.ts";
|
|
5
|
-
import { RouterContext, type RouterContextValue } from "../router-provider.tsx";
|
|
6
|
+
import { normalizeHref, RouterContext, type RouterContextValue } from "../router-provider.tsx";
|
|
6
7
|
import { assembleHTML, resolvePath, splitTemplate, streamToString } from "./assemble.ts";
|
|
7
8
|
import {
|
|
8
9
|
getISRCache,
|
|
@@ -146,7 +147,7 @@ async function prepareRender(
|
|
|
146
147
|
// while the client hydrates with the real pathname.
|
|
147
148
|
const ssrContext: RouterContextValue = {
|
|
148
149
|
basePath: basePath ?? "",
|
|
149
|
-
currentHref: ctx.path,
|
|
150
|
+
currentHref: normalizeHref(ctx.path),
|
|
150
151
|
navigate: () => Promise.resolve(),
|
|
151
152
|
prefetch: () => {
|
|
152
153
|
/* noop */
|
|
@@ -473,7 +474,7 @@ export async function renderRootNotFound(
|
|
|
473
474
|
|
|
474
475
|
const notFoundContext: RouterContextValue = {
|
|
475
476
|
basePath: "",
|
|
476
|
-
currentHref: request ? new URL(request.url).pathname : "/",
|
|
477
|
+
currentHref: request ? normalizeHref(new URL(request.url).pathname) : "/",
|
|
477
478
|
navigate: () => Promise.resolve(),
|
|
478
479
|
prefetch: () => {
|
|
479
480
|
/* noop */
|
package/src/router-provider.tsx
CHANGED
|
@@ -430,13 +430,15 @@ function stripHashFromHref(href: string): string {
|
|
|
430
430
|
return href.replace(HASH_FRAGMENT_RE, "");
|
|
431
431
|
}
|
|
432
432
|
|
|
433
|
-
/** Strips trailing slashes from a pathname or href. Root `/` is preserved.
|
|
433
|
+
/** Strips trailing slashes from a pathname or href. Root `/` is preserved.
|
|
434
|
+
* Query strings and hashes are preserved and re-attached after normalization. */
|
|
434
435
|
export function normalizeHref(href: string): string {
|
|
435
|
-
|
|
436
|
-
|
|
436
|
+
const url = new URL(href, "http://localhost");
|
|
437
|
+
let pathname = url.pathname;
|
|
438
|
+
if (pathname !== "/") {
|
|
439
|
+
pathname = pathname.replace(/\/+$/g, "");
|
|
437
440
|
}
|
|
438
|
-
|
|
439
|
-
return href.replace(/\/+(\?|#|$)/g, "$1");
|
|
441
|
+
return pathname + url.search + url.hash;
|
|
440
442
|
}
|
|
441
443
|
|
|
442
444
|
/** Strips a single trailing slash from a pathname. Root `/` and empty string are preserved. */
|
|
@@ -893,7 +895,7 @@ export function RouterProvider({
|
|
|
893
895
|
if (typeof window === "undefined") {
|
|
894
896
|
return "/";
|
|
895
897
|
}
|
|
896
|
-
return toLogical(window.location.pathname, _basePath) + window.location.search;
|
|
898
|
+
return normalizeHref(toLogical(window.location.pathname, _basePath)) + window.location.search;
|
|
897
899
|
});
|
|
898
900
|
const prefetchCache = useRef(new Map<string, CacheEntry>());
|
|
899
901
|
/** Monotonic counter to discard stale navigations (race condition guard). */
|
|
@@ -1134,7 +1136,7 @@ export function RouterProvider({
|
|
|
1134
1136
|
}
|
|
1135
1137
|
// Store the LOGICAL path in currentHref so Link active-state works.
|
|
1136
1138
|
const effectiveUrl = new URL(physicalEffective, window.location.origin);
|
|
1137
|
-
const logicalPath = toLogical(effectiveUrl.pathname, _basePath);
|
|
1139
|
+
const logicalPath = normalizeHref(toLogical(effectiveUrl.pathname, _basePath));
|
|
1138
1140
|
setCurrentHref(logicalPath + effectiveUrl.search);
|
|
1139
1141
|
if (opts?.resetScroll ?? true) {
|
|
1140
1142
|
pendingScrollRef.current = { type: "reset", href: physicalEffective };
|
|
@@ -1224,7 +1226,7 @@ export function RouterProvider({
|
|
|
1224
1226
|
window.history.replaceState(history.state, "", _basePath + effectiveLogical);
|
|
1225
1227
|
}
|
|
1226
1228
|
// effectiveLogical already contains the search params — no URL round-trip needed.
|
|
1227
|
-
setCurrentHref(effectiveLogical);
|
|
1229
|
+
setCurrentHref(normalizeHref(effectiveLogical));
|
|
1228
1230
|
// Queue scroll restoration for the layout effect tied to currentHref.
|
|
1229
1231
|
if (destKey) {
|
|
1230
1232
|
pendingScrollRef.current = { type: "restore", key: destKey };
|