@teyik0/furin 0.1.0-alpha.7 → 0.1.0-alpha.9

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.
Files changed (46) hide show
  1. package/dist/adapter/static.d.ts +3 -0
  2. package/dist/build/client.d.ts +3 -3
  3. package/dist/build/compile-entry.d.ts +4 -4
  4. package/dist/build/entry-template.d.ts +2 -2
  5. package/dist/build/hydrate.d.ts +6 -2
  6. package/dist/build/index.d.ts +1 -1
  7. package/dist/build/index.js +1491 -78
  8. package/dist/build/types.d.ts +26 -3
  9. package/dist/cli/index.js +1525 -91
  10. package/dist/client.d.ts +18 -11
  11. package/dist/config.d.ts +33 -2
  12. package/dist/config.js +6 -1
  13. package/dist/context-logger.d.ts +26 -0
  14. package/dist/dev-page-plugin.d.ts +77 -0
  15. package/dist/furin.js +459 -69
  16. package/dist/link.d.ts +31 -3
  17. package/dist/link.js +198 -51
  18. package/dist/render/assemble.d.ts +4 -2
  19. package/dist/render/index.d.ts +1 -1
  20. package/dist/render/loaders.d.ts +1 -1
  21. package/dist/render/shell.d.ts +4 -1
  22. package/dist/router.d.ts +11 -0
  23. package/dist/router.js +942 -41
  24. package/package.json +6 -5
  25. package/src/adapter/bun.ts +20 -0
  26. package/src/adapter/static.ts +341 -0
  27. package/src/build/client.ts +21 -11
  28. package/src/build/compile-entry.ts +5 -3
  29. package/src/build/entry-template.ts +2 -2
  30. package/src/build/hydrate.ts +37 -9
  31. package/src/build/index.ts +56 -21
  32. package/src/build/scan-server.ts +43 -21
  33. package/src/build/types.ts +28 -3
  34. package/src/cli/index.ts +13 -5
  35. package/src/client.ts +19 -25
  36. package/src/config.ts +35 -1
  37. package/src/context-logger.ts +71 -0
  38. package/src/dev-page-plugin.ts +339 -4
  39. package/src/furin.ts +6 -2
  40. package/src/link.tsx +355 -64
  41. package/src/plugin/index.ts +2 -2
  42. package/src/render/assemble.ts +4 -2
  43. package/src/render/index.ts +67 -23
  44. package/src/render/loaders.ts +81 -36
  45. package/src/render/shell.ts +11 -4
  46. package/src/router.ts +55 -6
package/dist/furin.js CHANGED
@@ -15,7 +15,7 @@ var __export = (target, all) => {
15
15
  };
16
16
  var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
17
17
 
18
- // ../../node_modules/.bun/evlog@2.12.0+f7c24eab1d196b1d/node_modules/evlog/dist/utils.mjs
18
+ // ../../node_modules/.bun/evlog@2.13.0+449e6d239244fccb/node_modules/evlog/dist/utils.mjs
19
19
  function formatDuration(ms) {
20
20
  if (ms < 1000)
21
21
  return `${Math.round(ms)}ms`;
@@ -126,7 +126,7 @@ var init_utils = __esm(() => {
126
126
  patternCache = /* @__PURE__ */ new Map;
127
127
  });
128
128
 
129
- // ../../node_modules/.bun/evlog@2.12.0+f7c24eab1d196b1d/node_modules/evlog/dist/logger-DY0X5oQd.mjs
129
+ // ../../node_modules/.bun/evlog@2.13.0+449e6d239244fccb/node_modules/evlog/dist/logger-DnobymUQ.mjs
130
130
  function resolveRedactConfig(input) {
131
131
  if (input === undefined || input === false)
132
132
  return;
@@ -236,6 +236,9 @@ function isoNow() {
236
236
  _tsDate.setTime(Date.now());
237
237
  return _tsDate.toISOString();
238
238
  }
239
+ function warnPostEmit(method, detail) {
240
+ console.warn(`[evlog] ${method} called after the wide event was emitted \u2014 ${detail} This data will not appear in observability. ${POST_EMIT_FORK_HINT}`);
241
+ }
239
242
  function mergeInto(target, source) {
240
243
  for (const key in source) {
241
244
  const sourceVal = source[key];
@@ -244,6 +247,8 @@ function mergeInto(target, source) {
244
247
  const targetVal = target[key];
245
248
  if (isPlainObject(sourceVal) && isPlainObject(targetVal))
246
249
  mergeInto(targetVal, sourceVal);
250
+ else if (Array.isArray(targetVal) && Array.isArray(sourceVal))
251
+ target[key] = [...targetVal, ...sourceVal];
247
252
  else
248
253
  target[key] = sourceVal;
249
254
  }
@@ -635,6 +640,7 @@ function createLogger(initialContext = {}, internalOptions) {
635
640
  const context = { ...initialContext };
636
641
  let hasError = false;
637
642
  let hasWarn = false;
643
+ let emitted = false;
638
644
  function addLog(level, message) {
639
645
  if (!Array.isArray(context.requestLogs))
640
646
  context.requestLogs = [];
@@ -646,9 +652,18 @@ function createLogger(initialContext = {}, internalOptions) {
646
652
  }
647
653
  return {
648
654
  set(data) {
655
+ if (emitted) {
656
+ const keys = Object.keys(data);
657
+ warnPostEmit("log.set()", `Keys dropped: ${keys.length ? keys.join(", ") : "(empty)"}.`);
658
+ return;
659
+ }
649
660
  mergeInto(context, data);
650
661
  },
651
662
  error(error, errorContext) {
663
+ if (emitted) {
664
+ warnPostEmit("log.error()", `Keys dropped: ${(errorContext ? [...Object.keys(errorContext), "error"] : ["error"]).join(", ")}.`);
665
+ return;
666
+ }
652
667
  hasError = true;
653
668
  const err = typeof error === "string" ? new Error(error) : error;
654
669
  if (errorContext)
@@ -676,6 +691,10 @@ function createLogger(initialContext = {}, internalOptions) {
676
691
  context.error = errorObj;
677
692
  },
678
693
  info(message, infoContext) {
694
+ if (emitted) {
695
+ warnPostEmit("log.info()", `Keys dropped: ${(infoContext ? ["message", ...Object.keys(infoContext).filter((k) => k !== "requestLogs")] : ["message"]).join(", ")}.`);
696
+ return;
697
+ }
679
698
  addLog("info", message);
680
699
  if (infoContext) {
681
700
  const { requestLogs: _, ...rest } = infoContext;
@@ -683,6 +702,10 @@ function createLogger(initialContext = {}, internalOptions) {
683
702
  }
684
703
  },
685
704
  warn(message, warnContext) {
705
+ if (emitted) {
706
+ warnPostEmit("log.warn()", `Keys dropped: ${(warnContext ? ["message", ...Object.keys(warnContext).filter((k) => k !== "requestLogs")] : ["message"]).join(", ")}.`);
707
+ return;
708
+ }
686
709
  hasWarn = true;
687
710
  addLog("warn", message);
688
711
  if (warnContext) {
@@ -691,6 +714,10 @@ function createLogger(initialContext = {}, internalOptions) {
691
714
  }
692
715
  },
693
716
  emit(overrides) {
717
+ if (emitted) {
718
+ warnPostEmit("log.emit()", "Ignoring duplicate emit.");
719
+ return null;
720
+ }
694
721
  const durationMs = Date.now() - startTime;
695
722
  const level = hasError ? "error" : hasWarn ? "warn" : "info";
696
723
  let forceKeep = false;
@@ -704,8 +731,10 @@ function createLogger(initialContext = {}, internalOptions) {
704
731
  method: context.method,
705
732
  context
706
733
  });
707
- if (!forceKeep && !shouldSample(level))
734
+ if (!forceKeep && !shouldSample(level)) {
735
+ emitted = true;
708
736
  return null;
737
+ }
709
738
  if (overrides) {
710
739
  const obj = overrides;
711
740
  for (const key in obj)
@@ -713,7 +742,9 @@ function createLogger(initialContext = {}, internalOptions) {
713
742
  context[key] = obj[key];
714
743
  }
715
744
  context.duration = formatDuration(durationMs);
716
- return emitWideEvent(level, context, deferDrain, true);
745
+ const wide = emitWideEvent(level, context, deferDrain, true);
746
+ emitted = true;
747
+ return wide;
717
748
  },
718
749
  getContext() {
719
750
  return { ...context };
@@ -730,8 +761,8 @@ function createRequestLogger(options = {}, internalOptions) {
730
761
  initial.requestId = options.requestId;
731
762
  return createLogger(initial, internalOptions);
732
763
  }
733
- var DEFAULT_REPLACEMENT = "[REDACTED]", builtinPatterns, _tsDate, globalEnv, globalPretty, globalSampling, globalStringify = true, globalDrain, globalRedact, globalEnabled = true, globalSilent = false, globalMinLevel = "debug", _log, noopLogger;
734
- var init_logger_DY0X5oQd = __esm(() => {
764
+ var DEFAULT_REPLACEMENT = "[REDACTED]", builtinPatterns, _tsDate, POST_EMIT_FORK_HINT = "For intentional background work tied to this request, use log.fork('label', fn) when your integration supports it (see https://evlog.dev).", globalEnv, globalPretty, globalSampling, globalStringify = true, globalDrain, globalRedact, globalEnabled = true, globalSilent = false, globalMinLevel = "debug", _log, noopLogger;
765
+ var init_logger_DnobymUQ = __esm(() => {
735
766
  init_utils();
736
767
  builtinPatterns = {
737
768
  creditCard: {
@@ -809,7 +840,12 @@ var init_logger_DY0X5oQd = __esm(() => {
809
840
  initLogger(__EVLOG_CONFIG__);
810
841
  });
811
842
 
812
- // ../../node_modules/.bun/evlog@2.12.0+f7c24eab1d196b1d/node_modules/evlog/dist/errors-BJRXUfMg.mjs
843
+ // ../../node_modules/.bun/evlog@2.13.0+449e6d239244fccb/node_modules/evlog/dist/index.mjs
844
+ var init_dist = __esm(() => {
845
+ init_logger_DnobymUQ();
846
+ });
847
+
848
+ // ../../node_modules/.bun/evlog@2.13.0+449e6d239244fccb/node_modules/evlog/dist/errors-BJRXUfMg.mjs
813
849
  function extractErrorStatus(error) {
814
850
  if (error === null || typeof error !== "object")
815
851
  return 500;
@@ -819,7 +855,7 @@ function extractErrorStatus(error) {
819
855
  }
820
856
  var init_errors_BJRXUfMg = () => {};
821
857
 
822
- // ../../node_modules/.bun/evlog@2.12.0+f7c24eab1d196b1d/node_modules/evlog/dist/routes-CGPmbzCZ.mjs
858
+ // ../../node_modules/.bun/evlog@2.13.0+449e6d239244fccb/node_modules/evlog/dist/routes-CGPmbzCZ.mjs
823
859
  function shouldLog(path, include, exclude) {
824
860
  if (exclude && exclude.length > 0) {
825
861
  if (exclude.some((pattern) => matchesPattern(path, pattern)))
@@ -840,7 +876,7 @@ var init_routes_CGPmbzCZ = __esm(() => {
840
876
  init_utils();
841
877
  });
842
878
 
843
- // ../../node_modules/.bun/evlog@2.12.0+f7c24eab1d196b1d/node_modules/evlog/dist/headers-ht4yS2mx.mjs
879
+ // ../../node_modules/.bun/evlog@2.13.0+449e6d239244fccb/node_modules/evlog/dist/middleware-BtBuosFV.mjs
844
880
  async function runEnrichAndDrain(emittedEvent, options, requestInfo, responseStatus) {
845
881
  const resolvedRedact = resolveRedactConfig(options.redact);
846
882
  if (resolvedRedact)
@@ -926,8 +962,8 @@ function createMiddlewareLogger(options) {
926
962
  };
927
963
  }
928
964
  var noopResult;
929
- var init_headers_ht4yS2mx = __esm(() => {
930
- init_logger_DY0X5oQd();
965
+ var init_middleware_BtBuosFV = __esm(() => {
966
+ init_logger_DnobymUQ();
931
967
  init_errors_BJRXUfMg();
932
968
  init_routes_CGPmbzCZ();
933
969
  noopResult = {
@@ -948,7 +984,70 @@ var init_headers_ht4yS2mx = __esm(() => {
948
984
  };
949
985
  });
950
986
 
951
- // ../../node_modules/.bun/evlog@2.12.0+f7c24eab1d196b1d/node_modules/evlog/dist/elysia/index.mjs
987
+ // ../../node_modules/.bun/evlog@2.13.0+449e6d239244fccb/node_modules/evlog/dist/fork-Y4z8iHti.mjs
988
+ function attachForkToLogger(storage, parent, middlewareOptions, lifecycle) {
989
+ const log = parent;
990
+ log.fork = (label, fn) => {
991
+ forkBackgroundLogger({
992
+ storage,
993
+ parent,
994
+ middlewareOptions,
995
+ label,
996
+ fn,
997
+ lifecycle
998
+ });
999
+ };
1000
+ }
1001
+ function forkBackgroundLogger(options) {
1002
+ const { storage, parent, middlewareOptions, label, fn, lifecycle } = options;
1003
+ const parentCtx = parent.getContext();
1004
+ const parentRequestId = parentCtx.requestId;
1005
+ if (typeof parentRequestId !== "string" || parentRequestId.length === 0)
1006
+ throw new Error("[evlog] log.fork() requires the parent logger to have a requestId. Ensure the request was created by evlog middleware.");
1007
+ const method = String(parentCtx.method ?? middlewareOptions.method);
1008
+ const path = String(parentCtx.path ?? middlewareOptions.path);
1009
+ const child = createRequestLogger({
1010
+ method,
1011
+ path,
1012
+ requestId: crypto.randomUUID()
1013
+ }, { _deferDrain: true });
1014
+ child.set({
1015
+ operation: label,
1016
+ _parentRequestId: parentRequestId
1017
+ });
1018
+ const childRequestInfo = {
1019
+ method,
1020
+ path,
1021
+ requestId: child.getContext().requestId
1022
+ };
1023
+ storage.run(child, () => {
1024
+ lifecycle?.onChildEnter?.(child);
1025
+ Promise.resolve().then(() => fn()).then(async () => {
1026
+ const emittedEvent = child.emit();
1027
+ const ctxStatus = child.getContext().status;
1028
+ const status = emittedEvent?.status ?? (typeof ctxStatus === "number" ? ctxStatus : undefined);
1029
+ if (emittedEvent && (middlewareOptions.enrich || middlewareOptions.drain || getGlobalDrain()))
1030
+ await runEnrichAndDrain(emittedEvent, middlewareOptions, childRequestInfo, status);
1031
+ }).catch(async (err) => {
1032
+ const error = err instanceof Error ? err : new Error(String(err));
1033
+ child.error(error);
1034
+ child.set({ status: extractErrorStatus(error) });
1035
+ const emittedEvent = child.emit();
1036
+ const status = extractErrorStatus(error);
1037
+ if (emittedEvent && (middlewareOptions.enrich || middlewareOptions.drain || getGlobalDrain()))
1038
+ await runEnrichAndDrain(emittedEvent, middlewareOptions, childRequestInfo, status);
1039
+ }).finally(() => {
1040
+ lifecycle?.onChildExit?.(child);
1041
+ });
1042
+ });
1043
+ }
1044
+ var init_fork_Y4z8iHti = __esm(() => {
1045
+ init_logger_DnobymUQ();
1046
+ init_errors_BJRXUfMg();
1047
+ init_middleware_BtBuosFV();
1048
+ });
1049
+
1050
+ // ../../node_modules/.bun/evlog@2.13.0+449e6d239244fccb/node_modules/evlog/dist/elysia/index.mjs
952
1051
  import { AsyncLocalStorage } from "async_hooks";
953
1052
  import { Elysia } from "elysia";
954
1053
  function useLogger2() {
@@ -961,15 +1060,25 @@ function evlog(options = {}) {
961
1060
  const emitted = /* @__PURE__ */ new WeakSet;
962
1061
  const requestState = /* @__PURE__ */ new WeakMap;
963
1062
  return new Elysia({ name: "evlog" }).derive({ as: "global" }, ({ request, path, headers }) => {
964
- const { logger, finish, skipped } = createMiddlewareLogger({
1063
+ const middlewareOpts = {
965
1064
  method: request.method,
966
1065
  path,
967
1066
  requestId: headers["x-request-id"] || crypto.randomUUID(),
968
1067
  headers: filterSafeHeaders(headers),
969
1068
  ...options
970
- });
971
- if (!skipped)
1069
+ };
1070
+ const { logger, finish, skipped } = createMiddlewareLogger(middlewareOpts);
1071
+ if (!skipped) {
1072
+ attachForkToLogger(storage, logger, middlewareOpts, {
1073
+ onChildEnter: (child) => {
1074
+ activeLoggers.add(child);
1075
+ },
1076
+ onChildExit: (child) => {
1077
+ activeLoggers.delete(child);
1078
+ }
1079
+ });
972
1080
  activeLoggers.add(logger);
1081
+ }
973
1082
  storage.enterWith(logger);
974
1083
  requestState.set(request, {
975
1084
  finish,
@@ -1000,7 +1109,8 @@ function evlog(options = {}) {
1000
1109
  var storage, activeLoggers;
1001
1110
  var init_elysia = __esm(() => {
1002
1111
  init_utils();
1003
- init_headers_ht4yS2mx();
1112
+ init_middleware_BtBuosFV();
1113
+ init_fork_Y4z8iHti();
1004
1114
  storage = new AsyncLocalStorage;
1005
1115
  activeLoggers = /* @__PURE__ */ new WeakSet;
1006
1116
  });
@@ -1117,6 +1227,21 @@ var init_cache = __esm(() => {
1117
1227
  _globalPendingInvalidations = new Set;
1118
1228
  });
1119
1229
 
1230
+ // src/link.tsx
1231
+ import {
1232
+ createContext,
1233
+ createElement,
1234
+ useCallback,
1235
+ useContext,
1236
+ useEffect,
1237
+ useRef,
1238
+ useState
1239
+ } from "react";
1240
+ var RouterContext;
1241
+ var init_link = __esm(() => {
1242
+ RouterContext = createContext(null);
1243
+ });
1244
+
1120
1245
  // src/render/shell.ts
1121
1246
  function extractTitle(meta) {
1122
1247
  if (!meta) {
@@ -1284,22 +1409,86 @@ function buildElement(route, data, rootLayout) {
1284
1409
  }
1285
1410
  var init_element = () => {};
1286
1411
 
1412
+ // src/context-logger.ts
1413
+ import { AsyncLocalStorage as AsyncLocalStorage3 } from "async_hooks";
1414
+ function useLogger3() {
1415
+ try {
1416
+ return useLogger2();
1417
+ } catch {
1418
+ return syntheticRenderStorage.getStore() ?? noopLogger2;
1419
+ }
1420
+ }
1421
+ async function runInSyntheticRenderScope(fn, initialContext) {
1422
+ const logger = createLogger(initialContext);
1423
+ try {
1424
+ const result = await syntheticRenderStorage.run(logger, () => Promise.resolve(fn()));
1425
+ logger.emit();
1426
+ return result;
1427
+ } catch (err) {
1428
+ logger.error(err instanceof Error ? err : new Error(String(err)));
1429
+ logger.emit();
1430
+ throw err;
1431
+ }
1432
+ }
1433
+ var noopLogger2, syntheticRenderStorage;
1434
+ var init_context_logger = __esm(() => {
1435
+ init_dist();
1436
+ init_elysia();
1437
+ noopLogger2 = {
1438
+ set: () => {},
1439
+ error: () => {},
1440
+ info: () => {},
1441
+ warn: () => {},
1442
+ emit: () => null,
1443
+ getContext: () => ({}),
1444
+ fork: (_label, fn) => fn()
1445
+ };
1446
+ syntheticRenderStorage = new AsyncLocalStorage3;
1447
+ });
1448
+
1287
1449
  // src/render/loaders.ts
1288
- async function runLoaders(route, ctx, rootLayout) {
1450
+ function createLoaderCtx(ctx, accumulatedParentPromise) {
1451
+ const cache = new Map;
1452
+ return new Proxy(ctx, {
1453
+ get(target, prop) {
1454
+ if (typeof prop !== "string") {
1455
+ return Reflect.get(target, prop);
1456
+ }
1457
+ if (prop === "then" || prop === "catch" || prop === "finally" || prop === "toJSON") {
1458
+ return Reflect.get(target, prop);
1459
+ }
1460
+ if (Object.hasOwn(target, prop)) {
1461
+ return target[prop];
1462
+ }
1463
+ let entry = cache.get(prop);
1464
+ if (!entry) {
1465
+ entry = accumulatedParentPromise.then((data) => data[prop]);
1466
+ cache.set(prop, entry);
1467
+ }
1468
+ return entry;
1469
+ }
1470
+ });
1471
+ }
1472
+ async function runLoaders(route, ctx, _rootLayout) {
1289
1473
  try {
1474
+ const ctxRecord = { ...ctx, log: useLogger3() };
1290
1475
  const loaderMap = new Map;
1291
- const deps = (routeRef) => loaderMap.get(routeRef) ?? Promise.resolve({});
1292
- const rootPromise = rootLayout.loader ? Promise.resolve(rootLayout.loader({ ...ctx }, deps)).then((r) => r ?? {}) : Promise.resolve({});
1293
- loaderMap.set(rootLayout, rootPromise);
1294
- const rootData = await rootPromise;
1295
- const ctxWithRoot = { ...ctx, ...rootData };
1296
- for (let i = 1;i < route.routeChain.length; i++) {
1297
- const ancestor = route.routeChain[i];
1298
- if (ancestor?.loader) {
1299
- loaderMap.set(ancestor, Promise.resolve(ancestor.loader(ctxWithRoot, deps)).then((r) => r ?? {}));
1476
+ let accumulatedParentPromise = Promise.resolve({});
1477
+ for (const r of route.routeChain) {
1478
+ const parentAccum = accumulatedParentPromise;
1479
+ if (r.loader) {
1480
+ const loaderCtx = createLoaderCtx(ctxRecord, parentAccum);
1481
+ const loaderPromise = Promise.resolve(r.loader(loaderCtx)).then((res) => res ?? {});
1482
+ loaderMap.set(r, loaderPromise);
1483
+ accumulatedParentPromise = Promise.all([parentAccum, loaderPromise]).then(([acc, own]) => ({
1484
+ ...acc,
1485
+ ...own
1486
+ }));
1487
+ accumulatedParentPromise.catch(() => {});
1300
1488
  }
1301
1489
  }
1302
- const pagePromise = route.page?.loader ? Promise.resolve(route.page.loader(ctxWithRoot, deps)).then((r) => r ?? {}) : Promise.resolve({});
1490
+ const pageCtx = createLoaderCtx(ctxRecord, accumulatedParentPromise);
1491
+ const pagePromise = route.page?.loader ? Promise.resolve(route.page.loader(pageCtx)).then((r) => r ?? {}) : Promise.resolve({});
1303
1492
  const results = await Promise.all([...loaderMap.values(), pagePromise]);
1304
1493
  const data = Object.assign({}, ...results);
1305
1494
  const headers = {};
@@ -1312,6 +1501,9 @@ async function runLoaders(route, ctx, rootLayout) {
1312
1501
  throw err;
1313
1502
  }
1314
1503
  }
1504
+ var init_loaders = __esm(() => {
1505
+ init_context_logger();
1506
+ });
1315
1507
 
1316
1508
  // src/render/template.ts
1317
1509
  import { readFileSync } from "fs";
@@ -1356,8 +1548,9 @@ var init_template = () => {};
1356
1548
  var IS_DEV = true;
1357
1549
 
1358
1550
  // src/render/index.ts
1551
+ import { createElement as createElement2 } from "react";
1359
1552
  import { renderToReadableStream } from "react-dom/server";
1360
- async function prepareRender(route, ctx, root) {
1553
+ async function prepareRender(route, ctx, root, basePath) {
1361
1554
  const loaderStart = Date.now();
1362
1555
  const loaderResult = await runLoaders(route, ctx, root.route);
1363
1556
  const loader_ms = Date.now() - loaderStart;
@@ -1372,13 +1565,29 @@ async function prepareRender(route, ctx, root) {
1372
1565
  path: ctx.path
1373
1566
  };
1374
1567
  const headData = buildHeadInjection(route.page?.head?.(componentProps));
1375
- const template = IS_DEV ? await getDevTemplate(new URL(ctx.request.url).origin) : getProductionTemplate() ?? generateIndexHtml();
1376
- const element = buildElement(route, componentProps, root.route);
1568
+ const prodTemplate = getProductionTemplate();
1569
+ const template = prodTemplate ?? (IS_DEV ? await getDevTemplate(new URL(ctx.request.url).origin) : generateIndexHtml());
1570
+ let element = buildElement(route, componentProps, root.route);
1571
+ if (basePath !== undefined) {
1572
+ const ssrContext = {
1573
+ basePath,
1574
+ currentHref: ctx.path,
1575
+ navigate: () => Promise.resolve(),
1576
+ prefetch: () => {},
1577
+ invalidatePrefetch: () => {},
1578
+ refresh: () => Promise.resolve(),
1579
+ isNavigating: false,
1580
+ defaultPreload: "intent",
1581
+ defaultPreloadDelay: 50,
1582
+ defaultPreloadStaleTime: 30000
1583
+ };
1584
+ element = createElement2(RouterContext.Provider, { value: ssrContext }, element);
1585
+ }
1377
1586
  return { componentProps, element, headData, headers, loader_ms, template };
1378
1587
  }
1379
- async function renderForPath(route, params, root, origin) {
1588
+ async function renderForPath(route, params, root, origin, basePath) {
1380
1589
  const resolvedPath = resolvePath(route.pattern, params);
1381
- return await renderToHTML(route, {
1590
+ const ctx = {
1382
1591
  params,
1383
1592
  query: {},
1384
1593
  request: new Request(`${origin}${resolvedPath}`),
@@ -1387,10 +1596,8 @@ async function renderForPath(route, params, root, origin) {
1387
1596
  redirect: (url, status = 302) => new Response(null, { status, headers: { Location: url } }),
1388
1597
  set: { headers: {} },
1389
1598
  path: resolvedPath
1390
- }, root);
1391
- }
1392
- async function renderToHTML(route, ctx, root) {
1393
- const prepared = await prepareRender(route, ctx, root);
1599
+ };
1600
+ const prepared = await runInSyntheticRenderScope(() => prepareRender(route, ctx, root, basePath), { route: route.pattern });
1394
1601
  if (prepared instanceof Response) {
1395
1602
  throw prepared;
1396
1603
  }
@@ -1403,7 +1610,7 @@ async function renderToHTML(route, ctx, root) {
1403
1610
  headers
1404
1611
  };
1405
1612
  }
1406
- async function prerenderSSG(route, params, root, origin = "http://localhost:3000") {
1613
+ async function prerenderSSG(route, params, root, origin = "http://localhost:3000", basePath) {
1407
1614
  const resolvedPath = resolvePath(route.pattern, params);
1408
1615
  const cached = getSSGCache(resolvedPath);
1409
1616
  if (cached && !IS_DEV) {
@@ -1411,7 +1618,7 @@ async function prerenderSSG(route, params, root, origin = "http://localhost:3000
1411
1618
  }
1412
1619
  let result;
1413
1620
  try {
1414
- result = await renderForPath(route, params, root, origin);
1621
+ result = await renderForPath(route, params, root, origin, basePath);
1415
1622
  } catch (err) {
1416
1623
  if (err instanceof Response) {
1417
1624
  return err;
@@ -1574,14 +1781,18 @@ function revalidateInBackground(route, params, cacheKey, revalidate, root, origi
1574
1781
  }
1575
1782
  var SSG_WARM_CONCURRENCY = 4, pendingRevalidations;
1576
1783
  var init_render = __esm(() => {
1784
+ init_link();
1577
1785
  init_assemble();
1578
1786
  init_cache();
1579
1787
  init_element();
1788
+ init_loaders();
1580
1789
  init_shell();
1581
1790
  init_template();
1582
1791
  init_assemble();
1583
1792
  init_element();
1793
+ init_loaders();
1584
1794
  init_elysia();
1795
+ init_context_logger();
1585
1796
  init_shell();
1586
1797
  pendingRevalidations = new Set;
1587
1798
  });
@@ -1634,6 +1845,7 @@ __export(exports_router, {
1634
1845
  scanPages: () => scanPages,
1635
1846
  resolveMode: () => resolveMode,
1636
1847
  queryDefaultRedirectHook: () => queryDefaultRedirectHook,
1848
+ mergeRouteSchemas: () => mergeRouteSchemas,
1637
1849
  loadProdRoutes: () => loadProdRoutes,
1638
1850
  filePathToPattern: () => filePathToPattern,
1639
1851
  createRoutePlugin: () => createRoutePlugin
@@ -1641,7 +1853,7 @@ __export(exports_router, {
1641
1853
  import { existsSync } from "fs";
1642
1854
  import { readdir } from "fs/promises";
1643
1855
  import { join, parse } from "path";
1644
- import { Elysia as Elysia2 } from "elysia";
1856
+ import { Elysia as Elysia2, t } from "elysia";
1645
1857
  function loadProdRoutes(ctx) {
1646
1858
  const rootMod = ctx.modules[ctx.rootPath];
1647
1859
  const rootExport = rootMod.route ?? rootMod.default;
@@ -1768,11 +1980,17 @@ function queryDefaultRedirectHook({ request, query, status, set }) {
1768
1980
  }
1769
1981
  async function handleDevRequest(route, ctx, root) {
1770
1982
  try {
1983
+ let currentRoot = root;
1984
+ const rootMod = await import(`${root.path}?furin-server&t=${Date.now()}`);
1985
+ const rootExport = rootMod.route ?? rootMod.default;
1986
+ if (rootExport && isFurinRoute(rootExport) && rootExport.layout) {
1987
+ currentRoot = { path: root.path, route: rootExport };
1988
+ }
1771
1989
  const pageMod = await import(`${route.path}?furin-server&t=${Date.now()}`);
1772
1990
  const page = pageMod.default;
1773
1991
  if (page && isFurinPage(page)) {
1774
1992
  const chain = collectRouteChainFromRoute(page._route);
1775
- return renderSSR({ ...route, page, routeChain: chain }, ctx, root);
1993
+ return renderSSR({ ...route, page, routeChain: chain }, ctx, currentRoot);
1776
1994
  }
1777
1995
  } catch (err) {
1778
1996
  console.error(`[furin] Dev page load error for ${route.path}:`, err);
@@ -1799,10 +2017,22 @@ async function handleSSGRequest(route, ctx, root, buildId) {
1799
2017
  ctx.set.headers["cache-tag"] = resolvedPath;
1800
2018
  return entry.html;
1801
2019
  }
2020
+ function mergeRouteSchemas(routeChain, key) {
2021
+ const schemas = routeChain.map((r) => r[key]).filter(Boolean);
2022
+ if (schemas.length === 0) {
2023
+ return;
2024
+ }
2025
+ if (schemas.length === 1) {
2026
+ return schemas[0];
2027
+ }
2028
+ const mergedProperties = Object.assign({}, ...schemas.map((s) => s.properties ?? {}));
2029
+ const mergedOptions = Object.assign({}, ...schemas.map((s) => Object.fromEntries(Object.entries(s).filter(([k]) => !TOBJECT_STRUCTURAL_KEYS.has(k)))));
2030
+ return t.Object(mergedProperties, mergedOptions);
2031
+ }
1802
2032
  function createRoutePlugin(route, root, buildId = "") {
1803
2033
  const { pattern, routeChain } = route;
1804
- const allParams = routeChain.findLast((r) => r.params)?.params;
1805
- const allQuery = routeChain.findLast((r) => r.query)?.query;
2034
+ const allParams = mergeRouteSchemas(routeChain, "params");
2035
+ const allQuery = mergeRouteSchemas(routeChain, "query");
1806
2036
  const hasQuerySchema = !!allQuery;
1807
2037
  const plugin = new Elysia2;
1808
2038
  if (allParams || allQuery) {
@@ -1881,18 +2111,72 @@ function filePathToPattern(path) {
1881
2111
  }
1882
2112
  return `/${segments.join("/")}`;
1883
2113
  }
2114
+ var TOBJECT_STRUCTURAL_KEYS;
1884
2115
  var init_router = __esm(() => {
1885
2116
  init_assemble();
1886
2117
  init_render();
2118
+ TOBJECT_STRUCTURAL_KEYS = new Set(["type", "properties", "required"]);
1887
2119
  });
1888
2120
 
1889
2121
  // src/dev-page-plugin.ts
1890
2122
  var exports_dev_page_plugin = {};
1891
2123
  __export(exports_dev_page_plugin, {
2124
+ rewriteSingletonImports: () => rewriteSingletonImports,
1892
2125
  rewriteRelativeImports: () => rewriteRelativeImports,
1893
- registerDevPagePlugin: () => registerDevPagePlugin
2126
+ rewriteBareImports: () => rewriteBareImports,
2127
+ registerDevPagePlugin: () => registerDevPagePlugin,
2128
+ injectJsxHelperImports: () => injectJsxHelperImports
1894
2129
  });
1895
2130
  import { dirname, resolve } from "path";
2131
+ import { fileURLToPath } from "url";
2132
+ function escapeRegExp(s) {
2133
+ return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
2134
+ }
2135
+ function rewriteSingletonImports(source) {
2136
+ let result = source;
2137
+ for (const [pkg, absPath] of SINGLETON_PATHS) {
2138
+ const re = new RegExp(`((?:from|import(?:\\s+type)?)\\s+)["']${escapeRegExp(pkg)}["']`, "g");
2139
+ result = result.replace(re, (_, g1) => `${g1}"${absPath}"`);
2140
+ }
2141
+ return result;
2142
+ }
2143
+ function injectJsxHelperImports(transpiled) {
2144
+ const JSX_HELPER_RE = /\b(jsxDEV|jsxs|jsx|Fragment)_([0-9a-z]{8})\b/g;
2145
+ const devRuntime = new Map;
2146
+ const prodRuntime = new Map;
2147
+ for (const [, base, hash] of transpiled.matchAll(JSX_HELPER_RE)) {
2148
+ if (!(base && hash)) {
2149
+ continue;
2150
+ }
2151
+ const varName = `${base}_${hash}`;
2152
+ if (base === "jsxDEV" || base === "Fragment") {
2153
+ devRuntime.set(varName, base);
2154
+ } else {
2155
+ prodRuntime.set(varName, base);
2156
+ }
2157
+ }
2158
+ const lines = [];
2159
+ if (devRuntime.size > 0) {
2160
+ const absPath = SINGLETON_PATHS.get("react/jsx-dev-runtime");
2161
+ if (absPath) {
2162
+ const specifiers = [...devRuntime.entries()].map(([varName, exportName]) => `${exportName} as ${varName}`).join(", ");
2163
+ lines.push(`import { ${specifiers} } from "${absPath}";`);
2164
+ }
2165
+ }
2166
+ if (prodRuntime.size > 0) {
2167
+ const absPath = SINGLETON_PATHS.get("react/jsx-runtime");
2168
+ if (absPath) {
2169
+ const specifiers = [...prodRuntime.entries()].map(([varName, exportName]) => `${exportName} as ${varName}`).join(", ");
2170
+ lines.push(`import { ${specifiers} } from "${absPath}";`);
2171
+ }
2172
+ }
2173
+ if (lines.length === 0) {
2174
+ return transpiled;
2175
+ }
2176
+ return `${lines.join(`
2177
+ `)}
2178
+ ${transpiled}`;
2179
+ }
1896
2180
  function rewriteRelativeImports(source, dir) {
1897
2181
  return source.replace(RELATIVE_SPECIFIER_RE, (match, relPath, offset) => {
1898
2182
  const lineStart = source.lastIndexOf(`
@@ -1906,6 +2190,72 @@ function rewriteRelativeImports(source, dir) {
1906
2190
  return `${keyword} "${absPath}"`;
1907
2191
  });
1908
2192
  }
2193
+ function rewriteBareImports(source, transpiled, dir) {
2194
+ const scanner = new Bun.Transpiler({ loader: "tsx" });
2195
+ let { imports } = scanner.scan(source);
2196
+ const seen = new Set;
2197
+ imports = imports.filter((imp) => {
2198
+ if (seen.has(imp.path)) {
2199
+ return false;
2200
+ }
2201
+ seen.add(imp.path);
2202
+ return true;
2203
+ });
2204
+ let result = transpiled;
2205
+ for (const imp of imports) {
2206
+ const spec = imp.path;
2207
+ if (spec.startsWith(".") || spec.startsWith("/") || spec.startsWith("file:")) {
2208
+ continue;
2209
+ }
2210
+ if (SINGLETON_PATHS.has(spec)) {
2211
+ continue;
2212
+ }
2213
+ let resolved;
2214
+ try {
2215
+ resolved = Bun.resolveSync(spec, dir);
2216
+ } catch {
2217
+ continue;
2218
+ }
2219
+ const re = new RegExp(`((?:from|import(?:\\s+type)?)\\s+)["']${escapeRegExp(spec)}["']`, "g");
2220
+ result = result.replace(re, (_, g1) => `${g1}"${resolved}"`);
2221
+ }
2222
+ return result;
2223
+ }
2224
+ function getSourceLoader(filePath) {
2225
+ if (filePath.endsWith(".tsx")) {
2226
+ return "tsx";
2227
+ }
2228
+ if (filePath.endsWith(".ts")) {
2229
+ return "ts";
2230
+ }
2231
+ if (filePath.endsWith(".jsx")) {
2232
+ return "jsx";
2233
+ }
2234
+ if (filePath.endsWith(".js")) {
2235
+ return "js";
2236
+ }
2237
+ return null;
2238
+ }
2239
+ function shouldSkipWorkspaceTransform(filePath) {
2240
+ const normalized = filePath.replace(/\\/g, "/");
2241
+ return normalized.includes("/.furin/");
2242
+ }
2243
+ function transformDevSource(raw, filePath, options) {
2244
+ const loader = getSourceLoader(filePath);
2245
+ if (!loader) {
2246
+ throw new Error(`[furin] Unsupported source loader for ${filePath}`);
2247
+ }
2248
+ const dir = dirname(filePath);
2249
+ const sourceForTranspile = options.rewriteRelativeImports ? rewriteRelativeImports(raw, dir) : raw;
2250
+ const transpiler = new Bun.Transpiler({ loader });
2251
+ const transpiled = transpiler.transformSync(sourceForTranspile, loader);
2252
+ let result = transpiled;
2253
+ if (options.rewriteBareImports) {
2254
+ result = rewriteBareImports(raw, result, dir);
2255
+ }
2256
+ result = rewriteSingletonImports(result);
2257
+ return injectJsxHelperImports(result);
2258
+ }
1909
2259
  function registerDevPagePlugin() {
1910
2260
  Bun.plugin({
1911
2261
  name: "furin-dev-page-loader",
@@ -1916,25 +2266,64 @@ function registerDevPagePlugin() {
1916
2266
  const resolvedPath = tMatch ? `${filePath}?t=${tMatch[1]}` : filePath;
1917
2267
  return { path: resolvedPath, namespace: "furin-dev-page" };
1918
2268
  });
2269
+ build.onLoad({ filter: WORKSPACE_SOURCE_FILTER }, async (args) => {
2270
+ const raw = await Bun.file(args.path).text();
2271
+ const loader = getSourceLoader(args.path);
2272
+ if (!loader) {
2273
+ throw new Error(`[furin] Unsupported source loader for ${args.path}`);
2274
+ }
2275
+ if (shouldSkipWorkspaceTransform(args.path)) {
2276
+ return {
2277
+ contents: raw,
2278
+ loader
2279
+ };
2280
+ }
2281
+ const contents = transformDevSource(raw, args.path, {
2282
+ rewriteBareImports: false,
2283
+ rewriteRelativeImports: false
2284
+ });
2285
+ return {
2286
+ contents,
2287
+ loader: "js"
2288
+ };
2289
+ });
1919
2290
  build.onLoad({ namespace: "furin-dev-page", filter: ANY_FILTER }, async (args) => {
1920
2291
  const filePath = args.path.replace(STRIP_T_PARAM_RE, "");
1921
2292
  const raw = await Bun.file(filePath).text();
1922
- const contents = rewriteRelativeImports(raw, dirname(filePath));
2293
+ const contents = transformDevSource(raw, filePath, {
2294
+ rewriteBareImports: true,
2295
+ rewriteRelativeImports: true
2296
+ });
1923
2297
  return {
1924
2298
  contents,
1925
- loader: filePath.endsWith(".tsx") ? "tsx" : "ts"
2299
+ loader: "js"
1926
2300
  };
1927
2301
  });
1928
2302
  }
1929
2303
  });
1930
2304
  }
1931
- var FURIN_SERVER_FILTER, ANY_FILTER, T_PARAM_RE, STRIP_FURIN_SERVER_RE, STRIP_T_PARAM_RE, RELATIVE_SPECIFIER_RE;
2305
+ var FURIN_SERVER_FILTER, ANY_FILTER, WORKSPACE_SOURCE_FILTER, T_PARAM_RE, STRIP_FURIN_SERVER_RE, STRIP_T_PARAM_RE, SINGLETON_PKGS, SINGLETON_PATHS, RELATIVE_SPECIFIER_RE;
1932
2306
  var init_dev_page_plugin = __esm(() => {
1933
2307
  FURIN_SERVER_FILTER = /\?furin-server(?:&t=\d+)?$/;
1934
2308
  ANY_FILTER = /.*/;
2309
+ WORKSPACE_SOURCE_FILTER = /^(?!.*(?:\/node_modules\/|\/\.bun\/))(?!.*\.(?:test|spec)\.[jt]sx?$).*\.[jt]sx?$/;
1935
2310
  T_PARAM_RE = /&t=(\d+)/;
1936
2311
  STRIP_FURIN_SERVER_RE = /\?furin-server.*$/;
1937
2312
  STRIP_T_PARAM_RE = /\?t=\d+$/;
2313
+ SINGLETON_PKGS = [
2314
+ "react",
2315
+ "react/jsx-runtime",
2316
+ "react/jsx-dev-runtime",
2317
+ "react-dom",
2318
+ "react-dom/server",
2319
+ "react-dom/client"
2320
+ ];
2321
+ SINGLETON_PATHS = new Map;
2322
+ for (const pkg of SINGLETON_PKGS) {
2323
+ try {
2324
+ SINGLETON_PATHS.set(pkg, fileURLToPath(import.meta.resolve(pkg)));
2325
+ } catch {}
2326
+ }
1938
2327
  RELATIVE_SPECIFIER_RE = /(?:from|import)\s+["'](\.\.?\/[^"']+)["']/g;
1939
2328
  });
1940
2329
 
@@ -1942,8 +2331,8 @@ var init_dev_page_plugin = __esm(() => {
1942
2331
  import { existsSync as existsSync2, readFileSync as readFileSync2, writeFileSync } from "fs";
1943
2332
  import { join as join2 } from "path";
1944
2333
  function patternToTypeString(pattern) {
1945
- const t = pattern.replace(/:[^/]+/g, "${string}").replace(/\*/g, "${string}");
1946
- return t.includes("${") ? `\`${t}\`` : `"${t}"`;
2334
+ const t2 = pattern.replace(/:[^/]+/g, "${string}").replace(/\*/g, "${string}");
2335
+ return t2.includes("${") ? `\`${t2}\`` : `"${t2}"`;
1947
2336
  }
1948
2337
  function schemaToTypeString(schema) {
1949
2338
  if (!schema || typeof schema !== "object") {
@@ -1951,7 +2340,7 @@ function schemaToTypeString(schema) {
1951
2340
  }
1952
2341
  const s = schema;
1953
2342
  if (s.anyOf && Array.isArray(s.anyOf)) {
1954
- const parts = s.anyOf.map(schemaToTypeString).filter((t) => t !== "null");
2343
+ const parts = s.anyOf.map(schemaToTypeString).filter((t2) => t2 !== "null");
1955
2344
  return parts.join(" | ") || "unknown";
1956
2345
  }
1957
2346
  switch (s.type) {
@@ -2011,28 +2400,33 @@ __export(exports_hydrate, {
2011
2400
  });
2012
2401
  import { existsSync as existsSync3, mkdirSync, readFileSync as readFileSync3, writeFileSync as writeFileSync2 } from "fs";
2013
2402
  import { join as join3 } from "path";
2014
- function generateHydrateEntry(routes, rootLayout) {
2403
+ function generateHydrateEntry(routes, rootLayout, basePath) {
2015
2404
  const routeEntries = [];
2016
2405
  for (const route of routes) {
2017
2406
  const resolvedPage = route.path.replace(/\\/g, "/");
2018
2407
  const regexPattern = route.pattern.replace(/:[^/]+/g, "([^/]+)").replace(/\*/g, "(.*)");
2019
2408
  routeEntries.push(` { pattern: "${route.pattern}", regex: new RegExp("^${regexPattern}$"), load: () => import("${resolvedPage}") }`);
2020
2409
  }
2410
+ const basePathLiteral = JSON.stringify(basePath);
2411
+ const pathnameExpr = basePath ? `(() => { const p = window.location.pathname; const b = ${basePathLiteral}; return (p.startsWith(b) && (p.length === b.length || p[b.length] === "/")) ? p.slice(b.length) || "/" : p; })()` : "window.location.pathname";
2412
+ const logEndpoint = basePath ? `${JSON.stringify(basePath)} + "/_furin/ingest"` : `"/_furin/ingest"`;
2413
+ const basePathProp = basePath ? `
2414
+ basePath: ${basePathLiteral},` : "";
2021
2415
  return `import { hydrateRoot, createRoot } from "react-dom/client";
2022
2416
  import { createElement } from "react";
2023
2417
  import { initLogger, log } from "evlog";
2024
- import { createBrowserLogDrain } from "evlog/browser";
2418
+ import { createHttpLogDrain } from "evlog/http";
2025
2419
  import { RouterProvider } from "@teyik0/furin/link";
2026
2420
  import { route as root } from "${rootLayout.replace(/\\/g, "/")}";
2027
2421
 
2028
- initLogger({ drain: createBrowserLogDrain({ drain: { endpoint: "/_furin/ingest" } }) });
2422
+ initLogger({ drain: createHttpLogDrain({ drain: { endpoint: ${logEndpoint} } }) });
2029
2423
 
2030
2424
  const routes = [
2031
2425
  ${routeEntries.join(`,
2032
2426
  `)}
2033
2427
  ];
2034
2428
 
2035
- const pathname = window.location.pathname;
2429
+ const pathname = ${pathnameExpr};
2036
2430
  const _match = routes.find((r) => r.regex.test(pathname));
2037
2431
 
2038
2432
  // Eagerly load only the current page module for initial hydration.
@@ -2052,7 +2446,7 @@ const _match = routes.find((r) => r.regex.test(pathname));
2052
2446
  routes,
2053
2447
  root,
2054
2448
  initialMatch: match,
2055
- initialData: loaderData,
2449
+ initialData: loaderData,${basePathProp}
2056
2450
  } as any);
2057
2451
 
2058
2452
  if (import.meta.hot) {
@@ -2082,11 +2476,11 @@ const _match = routes.find((r) => r.regex.test(pathname));
2082
2476
  });
2083
2477
  `;
2084
2478
  }
2085
- function writeDevFiles(routes, { outDir, rootLayout }, projectRoot) {
2479
+ function writeDevFiles(routes, { outDir, rootLayout, basePath }, projectRoot) {
2086
2480
  if (!existsSync3(outDir)) {
2087
2481
  mkdirSync(outDir, { recursive: true });
2088
2482
  }
2089
- const hydrateCode = generateHydrateEntry(routes, rootLayout);
2483
+ const hydrateCode = generateHydrateEntry(routes, rootLayout, basePath);
2090
2484
  const hydratePath = join3(outDir, "_hydrate.tsx");
2091
2485
  const existingHydrate = existsSync3(hydratePath) ? readFileSync3(hydratePath, "utf8") : "";
2092
2486
  if (hydrateCode !== existingHydrate) {
@@ -2107,22 +2501,18 @@ var init_hydrate = __esm(() => {
2107
2501
  });
2108
2502
 
2109
2503
  // src/furin.ts
2110
- import { existsSync as existsSync4 } from "fs";
2111
- import { basename, dirname as dirname2, join as join4, resolve as resolve2 } from "path";
2112
- import { fileURLToPath } from "url";
2113
- import { staticPlugin } from "@elysiajs/static";
2114
- import { Elysia as Elysia3, file } from "elysia";
2115
-
2116
- // ../../node_modules/.bun/evlog@2.12.0+f7c24eab1d196b1d/node_modules/evlog/dist/index.mjs
2117
- init_logger_DY0X5oQd();
2118
-
2119
- // src/furin.ts
2504
+ init_dist();
2120
2505
  init_elysia();
2121
2506
  init_cache();
2122
2507
  init_render();
2123
2508
  init_template();
2124
2509
  init_router();
2125
2510
  init_cache();
2511
+ import { existsSync as existsSync4 } from "fs";
2512
+ import { basename, dirname as dirname2, join as join4, resolve as resolve2 } from "path";
2513
+ import { fileURLToPath as fileURLToPath2 } from "url";
2514
+ import { staticPlugin } from "@elysiajs/static";
2515
+ import { Elysia as Elysia3, file } from "elysia";
2126
2516
  function resolveClientDirFromArgv() {
2127
2517
  return resolveClientDirFromEnv() ?? resolveClientDirFromModuleUrl() ?? resolveClientDirFromProcessArgs() ?? resolveFallbackClientDir();
2128
2518
  }
@@ -2139,7 +2529,7 @@ function resolveClientDirFromModuleUrl() {
2139
2529
  if (moduleUrl.protocol !== "file:") {
2140
2530
  return null;
2141
2531
  }
2142
- const modulePath = fileURLToPath(moduleUrl);
2532
+ const modulePath = fileURLToPath2(moduleUrl);
2143
2533
  if (modulePath.includes("/$bunfs/")) {
2144
2534
  return null;
2145
2535
  }
@@ -2270,7 +2660,7 @@ async function furin({
2270
2660
  const { scanPages: scanPages2 } = await Promise.resolve().then(() => (init_router(), exports_router));
2271
2661
  const { root: root2, routes: routes2 } = await scanPages2(resolvedPagesDir);
2272
2662
  const { writeDevFiles: writeDevFiles2 } = await Promise.resolve().then(() => (init_hydrate(), exports_hydrate));
2273
- writeDevFiles2(routes2, { outDir: furinDir, rootLayout: root2.path }, cwd);
2663
+ writeDevFiles2(routes2, { outDir: furinDir, rootLayout: root2.path, basePath: "", publicPath: "/_client/" }, cwd);
2274
2664
  const publicDir = resolve2(cwd, "public");
2275
2665
  const publicExists = existsSync4(publicDir);
2276
2666
  const devApp = new Elysia3({ name: instanceName, seed: resolvedPagesDir }).use(loggerPlugin).onAfterHandle({ as: "global" }, ({ set }) => {
@@ -2278,7 +2668,7 @@ async function furin({
2278
2668
  if (pending.length > 0) {
2279
2669
  set.headers["x-furin-revalidate"] = pending.join(",");
2280
2670
  }
2281
- }).use(await staticPlugin({ assets: furinDir, prefix: "/_bun_hmr_entry" })).use(publicExists ? await staticPlugin({ assets: publicDir, prefix: "/public" }) : new Elysia3).get("/favicon.ico", publicExists ? file(join4(publicDir, "favicon.ico")) : () => new Response(null, { status: 404 })).use((app) => {
2671
+ }).use(await staticPlugin({ assets: furinDir, prefix: "/_bun_hmr_entry", bunFullstack: true })).use(publicExists ? await staticPlugin({ assets: publicDir, prefix: "/public" }) : new Elysia3).get("/favicon.ico", publicExists ? file(join4(publicDir, "favicon.ico")) : () => new Response(null, { status: 404 })).use((app) => {
2282
2672
  for (const route of routes2) {
2283
2673
  app.use(createRoutePlugin(route, root2));
2284
2674
  }