@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.
@@ -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,55 +1,84 @@
1
1
  {
2
2
  "name": "@teyik0/furin",
3
- "version": "0.1.0-alpha.12",
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": {
@@ -62,7 +91,7 @@
62
91
  "dependencies": {
63
92
  "@elysiajs/static": "^1.4.10",
64
93
  "magic-string": "^0.30.21",
65
- "oxc-parser": "^0.128.0"
94
+ "yuku-parser": "^0.4.6"
66
95
  },
67
96
  "devDependencies": {
68
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;
@@ -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
 
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 { parseSync } from "oxc-parser";
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, errors } = parseSync("dce.js", code);
284
- if (errors.length > 0) {
285
- console.error("[furin] DCE: failed to parse transformed output:", errors[0]?.message);
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 — oxc-parser: parse plain JS to ESTree AST with span offsets.
351
- const { program, errors } = parseSync(filename, plainJs);
352
- if (errors.length > 0) {
353
- throw new Error(`Failed to parse ${filename}: ${errors[0]?.message}`);
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.
@@ -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 */
@@ -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
- if (href === "/") {
436
- return "/";
436
+ const url = new URL(href, "http://localhost");
437
+ let pathname = url.pathname;
438
+ if (pathname !== "/") {
439
+ pathname = pathname.replace(/\/+$/g, "");
437
440
  }
438
- // Strip trailing slashes before query string or hash, and at end of string
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 };