@teyik0/furin 0.1.0-alpha.11 → 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 +453 -282
- package/dist/build/server-routes-entry.ts +55 -0
- package/dist/cli/index.js +457 -286
- package/dist/env.d.ts +50 -0
- package/dist/furin.js +402 -263
- package/dist/internal.js +17 -0
- package/dist/link.d.ts +5 -438
- package/dist/link.js +228 -137
- package/dist/plugin/index.js +9 -7
- package/dist/render/cache.d.ts +18 -5
- package/dist/render/dev-cache.d.ts +29 -0
- package/dist/render/index.ts +870 -0
- package/dist/render/route-cache.d.ts +26 -0
- package/dist/render/shell.ts +187 -0
- package/dist/router-provider.d.ts +467 -0
- package/dist/router.js +515 -368
- package/dist/router.ts +1034 -0
- package/dist/runtime-env.js +10 -0
- package/package.json +47 -17
- package/src/adapter/bun.ts +4 -1
- package/src/build/entry-template.ts +13 -6
- package/src/build/hydrate.ts +7 -5
- package/src/build/scan-server.ts +32 -3
- package/src/dev-page-plugin.ts +6 -0
- package/src/link.tsx +43 -1297
- package/src/plugin/transform-client.ts +10 -8
- package/src/render/cache.ts +77 -67
- package/src/render/dev-cache.ts +106 -15
- package/src/render/index.ts +4 -3
- package/src/render/route-cache.ts +124 -0
- package/src/router-provider.tsx +1428 -0
package/package.json
CHANGED
|
@@ -1,67 +1,97 @@
|
|
|
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": {
|
|
56
|
-
"
|
|
57
|
-
"test
|
|
58
|
-
"
|
|
59
|
-
"
|
|
85
|
+
"fix": "ultracite fix",
|
|
86
|
+
"test": "bun test --parallel --isolate --bail --preload ../../tests/setup.ts",
|
|
87
|
+
"test:dev": "bun test --changed --parallel --isolate --bail --preload ../../tests/setup.ts",
|
|
88
|
+
"tscheck": "tsc --noEmit",
|
|
89
|
+
"build": "bun run build.ts"
|
|
60
90
|
},
|
|
61
91
|
"dependencies": {
|
|
62
92
|
"@elysiajs/static": "^1.4.10",
|
|
63
93
|
"magic-string": "^0.30.21",
|
|
64
|
-
"
|
|
94
|
+
"yuku-parser": "^0.4.6"
|
|
65
95
|
},
|
|
66
96
|
"devDependencies": {
|
|
67
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/hydrate.ts
CHANGED
|
@@ -86,9 +86,11 @@ export function generateHydrateEntry(
|
|
|
86
86
|
// Strip basePath only when it matches on a path boundary (prevents "/furin" from
|
|
87
87
|
// matching "/furinity/foo"). The boundary holds when the pathname ends exactly
|
|
88
88
|
// at the prefix length OR the next character is "/".
|
|
89
|
+
// Trailing slashes are also stripped so "/docs/routing/" matches the route
|
|
90
|
+
// pattern "/docs/routing" — GitHub Pages and many static hosts append them.
|
|
89
91
|
const pathnameExpr = basePath
|
|
90
|
-
? `(() => { const p = window.location.pathname; const b = ${basePathLiteral};
|
|
91
|
-
:
|
|
92
|
+
? `(() => { const p = window.location.pathname; const b = ${basePathLiteral}; const stripped = (p.startsWith(b) && (p.length === b.length || p[b.length] === "/")) ? p.slice(b.length) || "/" : p; return stripped === "/" ? "/" : stripped.replace(/\\/+$/, ""); })()`
|
|
93
|
+
: `window.location.pathname.replace(/\\/+$/, "") || "/"`;
|
|
92
94
|
|
|
93
95
|
// Log drain endpoint: prepend basePath so the request goes to the correct origin path.
|
|
94
96
|
const logEndpoint = basePath
|
|
@@ -96,7 +98,7 @@ export function generateHydrateEntry(
|
|
|
96
98
|
: `"/_furin/ingest"`;
|
|
97
99
|
|
|
98
100
|
// RouterProvider receives basePath so navigate() / Link push physical paths.
|
|
99
|
-
const
|
|
101
|
+
const routerProviderDefaults = `\n autoRefresh: true,\n basePath: ${basePathLiteral},\n defaultPreload: "intent",\n defaultPreloadDelay: 50,\n defaultPreloadStaleTime: 30000,\n prefetchCacheSize: 50,`;
|
|
100
102
|
|
|
101
103
|
const conventionImportsBlock = conventionImportLines ? `\n${conventionImportLines}` : "";
|
|
102
104
|
|
|
@@ -145,7 +147,7 @@ const rootEl = document.getElementById("root") as HTMLElement;
|
|
|
145
147
|
initialMatch: match,
|
|
146
148
|
initialData: loaderData,
|
|
147
149
|
initialDigest: loaderData.__furinError?.digest,
|
|
148
|
-
initialNotFound: isNotFound ? (loaderData.__furinNotFound ?? loaderData) : undefined,${
|
|
150
|
+
initialNotFound: isNotFound ? (loaderData.__furinNotFound ?? loaderData) : undefined,${routerProviderDefaults}
|
|
149
151
|
} as any);
|
|
150
152
|
} else if (loaderData.__furinStatus === 404) {
|
|
151
153
|
// Direct load to an unknown URL. The server sent the root not-found UI
|
|
@@ -162,7 +164,7 @@ const rootEl = document.getElementById("root") as HTMLElement;
|
|
|
162
164
|
initialMatch: null,
|
|
163
165
|
initialData: cleanData,
|
|
164
166
|
initialDigest: loaderData.__furinError?.digest,
|
|
165
|
-
initialNotFound: loaderData.__furinNotFound ?? {},${
|
|
167
|
+
initialNotFound: loaderData.__furinNotFound ?? {},${routerProviderDefaults}
|
|
166
168
|
} as any);
|
|
167
169
|
} else {
|
|
168
170
|
// No match and no 404 signal — either the client bundle is out of sync
|
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/dev-page-plugin.ts
CHANGED
|
@@ -64,6 +64,8 @@ const T_PARAM_RE = /&t=(\d+)/;
|
|
|
64
64
|
const STRIP_FURIN_SERVER_RE = /\?furin-server.*$/;
|
|
65
65
|
const STRIP_T_PARAM_RE = /\?t=\d+$/;
|
|
66
66
|
|
|
67
|
+
let _pluginRegistered = false;
|
|
68
|
+
|
|
67
69
|
type SourceLoader = "js" | "jsx" | "ts" | "tsx";
|
|
68
70
|
|
|
69
71
|
// ── Singleton package resolution ───────────────────────────────────────────────
|
|
@@ -332,6 +334,10 @@ function transformDevSource(
|
|
|
332
334
|
}
|
|
333
335
|
|
|
334
336
|
export function registerDevPagePlugin(): void {
|
|
337
|
+
if (_pluginRegistered) {
|
|
338
|
+
return;
|
|
339
|
+
}
|
|
340
|
+
_pluginRegistered = true;
|
|
335
341
|
Bun.plugin({
|
|
336
342
|
name: "furin-dev-page-loader",
|
|
337
343
|
setup(build) {
|