@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.
@@ -0,0 +1,10 @@
1
+ // @bun
2
+ // src/runtime-env.ts
3
+ var IS_DEV = true;
4
+ function __setDevMode(val) {
5
+ IS_DEV = val;
6
+ }
7
+ export {
8
+ __setDevMode,
9
+ IS_DEV
10
+ };
package/package.json CHANGED
@@ -1,67 +1,97 @@
1
1
  {
2
2
  "name": "@teyik0/furin",
3
- "version": "0.1.0-alpha.11",
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": "./src/furin.ts",
39
+ "types": "./dist/furin.d.ts",
12
40
  "bin": {
13
- "furin": "./src/cli/index.ts"
41
+ "furin": "./dist/cli/index.js"
14
42
  },
15
43
  "exports": {
16
44
  ".": {
17
- "types": "./src/furin.ts",
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": "./src/client.ts",
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": "./src/build/index.ts",
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": "./src/config.ts",
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": "./src/router.ts",
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": "./src/plugin/index.ts",
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": "./src/link.tsx",
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": "./src/env.d.ts"
80
+ "types": "./dist/env.d.ts",
81
+ "bun": "./src/env.d.ts"
53
82
  }
54
83
  },
55
84
  "scripts": {
56
- "test": "bun test",
57
- "test:types": "tsc --noEmit",
58
- "build": "bun run build.ts",
59
- "fix": "ultracite fix"
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
- "oxc-parser": "^0.128.0"
94
+ "yuku-parser": "^0.4.6"
65
95
  },
66
96
  "devDependencies": {
67
97
  "@types/react": "^19.2.14",
@@ -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 _pkgSrcDir = dirname(fileURLToPath(import.meta.resolve("@teyik0/furin")));
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 { dirname } from "node:path";
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. The "bun" condition
5
- // on "." resolves to src/furin.ts, so dirname gives us the src/ dir.
6
- const _pkgSrcDir = dirname(new URL(import.meta.resolve("@teyik0/furin")).pathname);
7
- const INTERNAL_MODULE_PATH = `${_pkgSrcDir}/internal.ts`;
8
- const RUNTIME_ENV_MODULE_PATH = `${_pkgSrcDir}/runtime-env.ts`;
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;
@@ -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}; return (p.startsWith(b) && (p.length === b.length || p[b.length] === "/")) ? p.slice(b.length) || "/" : p; })()`
91
- : "window.location.pathname";
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 basePathProp = basePath ? `\n basePath: ${basePathLiteral},` : "";
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,${basePathProp}
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 ?? {},${basePathProp}
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
@@ -1,5 +1,5 @@
1
1
  import { readFileSync } from "node:fs";
2
- import { parseSync } from "oxc-parser";
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
- const { program, errors } = parseSync(serverEntryPath, code);
20
- if (errors.length > 0) {
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
 
@@ -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) {