@teyik0/furin 0.1.0-alpha.7 → 0.1.0-alpha.8
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/dist/adapter/static.d.ts +3 -0
- package/dist/build/client.d.ts +3 -3
- package/dist/build/compile-entry.d.ts +4 -4
- package/dist/build/entry-template.d.ts +2 -2
- package/dist/build/hydrate.d.ts +6 -2
- package/dist/build/index.d.ts +1 -1
- package/dist/build/index.js +644 -75
- package/dist/build/types.d.ts +26 -3
- package/dist/cli/index.js +678 -88
- package/dist/client.d.ts +15 -11
- package/dist/config.d.ts +33 -2
- package/dist/config.js +6 -1
- package/dist/dev-page-plugin.d.ts +77 -0
- package/dist/furin.js +395 -63
- package/dist/link.d.ts +31 -3
- package/dist/link.js +138 -50
- package/dist/render/index.d.ts +1 -1
- package/dist/render/loaders.d.ts +1 -1
- package/dist/router.js +84 -24
- package/package.json +6 -5
- package/src/adapter/bun.ts +20 -0
- package/src/adapter/static.ts +337 -0
- package/src/build/client.ts +21 -11
- package/src/build/compile-entry.ts +5 -3
- package/src/build/entry-template.ts +2 -2
- package/src/build/hydrate.ts +37 -9
- package/src/build/index.ts +56 -21
- package/src/build/scan-server.ts +43 -21
- package/src/build/types.ts +28 -3
- package/src/cli/index.ts +13 -5
- package/src/client.ts +16 -25
- package/src/config.ts +35 -1
- package/src/dev-page-plugin.ts +339 -4
- package/src/furin.ts +6 -2
- package/src/link.tsx +268 -62
- package/src/plugin/index.ts +2 -2
- package/src/render/index.ts +64 -24
- package/src/render/loaders.ts +77 -36
- package/src/render/shell.ts +2 -2
- package/src/router.ts +11 -1
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.
|
|
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.
|
|
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
|
-
|
|
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
|
|
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.
|
|
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.
|
|
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.
|
|
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
|
|
930
|
-
|
|
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.
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
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) {
|
|
@@ -1285,21 +1410,48 @@ function buildElement(route, data, rootLayout) {
|
|
|
1285
1410
|
var init_element = () => {};
|
|
1286
1411
|
|
|
1287
1412
|
// src/render/loaders.ts
|
|
1288
|
-
|
|
1413
|
+
function createLoaderCtx(ctx, accumulatedParentPromise) {
|
|
1414
|
+
const cache = new Map;
|
|
1415
|
+
return new Proxy(ctx, {
|
|
1416
|
+
get(target, prop) {
|
|
1417
|
+
if (typeof prop !== "string") {
|
|
1418
|
+
return Reflect.get(target, prop);
|
|
1419
|
+
}
|
|
1420
|
+
if (prop === "then" || prop === "catch" || prop === "finally" || prop === "toJSON") {
|
|
1421
|
+
return Reflect.get(target, prop);
|
|
1422
|
+
}
|
|
1423
|
+
if (Object.hasOwn(target, prop)) {
|
|
1424
|
+
return target[prop];
|
|
1425
|
+
}
|
|
1426
|
+
let entry = cache.get(prop);
|
|
1427
|
+
if (!entry) {
|
|
1428
|
+
entry = accumulatedParentPromise.then((data) => data[prop]);
|
|
1429
|
+
cache.set(prop, entry);
|
|
1430
|
+
}
|
|
1431
|
+
return entry;
|
|
1432
|
+
}
|
|
1433
|
+
});
|
|
1434
|
+
}
|
|
1435
|
+
async function runLoaders(route, ctx, _rootLayout) {
|
|
1289
1436
|
try {
|
|
1437
|
+
const ctxRecord = ctx;
|
|
1290
1438
|
const loaderMap = new Map;
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1439
|
+
let accumulatedParentPromise = Promise.resolve({});
|
|
1440
|
+
for (const r of route.routeChain) {
|
|
1441
|
+
const parentAccum = accumulatedParentPromise;
|
|
1442
|
+
if (r.loader) {
|
|
1443
|
+
const loaderCtx = createLoaderCtx(ctxRecord, parentAccum);
|
|
1444
|
+
const loaderPromise = Promise.resolve(r.loader(loaderCtx)).then((res) => res ?? {});
|
|
1445
|
+
loaderMap.set(r, loaderPromise);
|
|
1446
|
+
accumulatedParentPromise = Promise.all([parentAccum, loaderPromise]).then(([acc, own]) => ({
|
|
1447
|
+
...acc,
|
|
1448
|
+
...own
|
|
1449
|
+
}));
|
|
1450
|
+
accumulatedParentPromise.catch(() => {});
|
|
1300
1451
|
}
|
|
1301
1452
|
}
|
|
1302
|
-
const
|
|
1453
|
+
const pageCtx = createLoaderCtx(ctxRecord, accumulatedParentPromise);
|
|
1454
|
+
const pagePromise = route.page?.loader ? Promise.resolve(route.page.loader(pageCtx)).then((r) => r ?? {}) : Promise.resolve({});
|
|
1303
1455
|
const results = await Promise.all([...loaderMap.values(), pagePromise]);
|
|
1304
1456
|
const data = Object.assign({}, ...results);
|
|
1305
1457
|
const headers = {};
|
|
@@ -1356,8 +1508,9 @@ var init_template = () => {};
|
|
|
1356
1508
|
var IS_DEV = true;
|
|
1357
1509
|
|
|
1358
1510
|
// src/render/index.ts
|
|
1511
|
+
import { createElement as createElement2 } from "react";
|
|
1359
1512
|
import { renderToReadableStream } from "react-dom/server";
|
|
1360
|
-
async function prepareRender(route, ctx, root) {
|
|
1513
|
+
async function prepareRender(route, ctx, root, basePath) {
|
|
1361
1514
|
const loaderStart = Date.now();
|
|
1362
1515
|
const loaderResult = await runLoaders(route, ctx, root.route);
|
|
1363
1516
|
const loader_ms = Date.now() - loaderStart;
|
|
@@ -1372,13 +1525,29 @@ async function prepareRender(route, ctx, root) {
|
|
|
1372
1525
|
path: ctx.path
|
|
1373
1526
|
};
|
|
1374
1527
|
const headData = buildHeadInjection(route.page?.head?.(componentProps));
|
|
1375
|
-
const
|
|
1376
|
-
const
|
|
1528
|
+
const prodTemplate = getProductionTemplate();
|
|
1529
|
+
const template = prodTemplate ?? (IS_DEV ? await getDevTemplate(new URL(ctx.request.url).origin) : generateIndexHtml());
|
|
1530
|
+
let element = buildElement(route, componentProps, root.route);
|
|
1531
|
+
if (basePath !== undefined) {
|
|
1532
|
+
const ssrContext = {
|
|
1533
|
+
basePath,
|
|
1534
|
+
currentHref: ctx.path,
|
|
1535
|
+
navigate: () => Promise.resolve(),
|
|
1536
|
+
prefetch: () => {},
|
|
1537
|
+
invalidatePrefetch: () => {},
|
|
1538
|
+
refresh: () => Promise.resolve(),
|
|
1539
|
+
isNavigating: false,
|
|
1540
|
+
defaultPreload: "intent",
|
|
1541
|
+
defaultPreloadDelay: 50,
|
|
1542
|
+
defaultPreloadStaleTime: 30000
|
|
1543
|
+
};
|
|
1544
|
+
element = createElement2(RouterContext.Provider, { value: ssrContext }, element);
|
|
1545
|
+
}
|
|
1377
1546
|
return { componentProps, element, headData, headers, loader_ms, template };
|
|
1378
1547
|
}
|
|
1379
|
-
async function renderForPath(route, params, root, origin) {
|
|
1548
|
+
async function renderForPath(route, params, root, origin, basePath) {
|
|
1380
1549
|
const resolvedPath = resolvePath(route.pattern, params);
|
|
1381
|
-
|
|
1550
|
+
const ctx = {
|
|
1382
1551
|
params,
|
|
1383
1552
|
query: {},
|
|
1384
1553
|
request: new Request(`${origin}${resolvedPath}`),
|
|
@@ -1387,10 +1556,8 @@ async function renderForPath(route, params, root, origin) {
|
|
|
1387
1556
|
redirect: (url, status = 302) => new Response(null, { status, headers: { Location: url } }),
|
|
1388
1557
|
set: { headers: {} },
|
|
1389
1558
|
path: resolvedPath
|
|
1390
|
-
}
|
|
1391
|
-
|
|
1392
|
-
async function renderToHTML(route, ctx, root) {
|
|
1393
|
-
const prepared = await prepareRender(route, ctx, root);
|
|
1559
|
+
};
|
|
1560
|
+
const prepared = await prepareRender(route, ctx, root, basePath);
|
|
1394
1561
|
if (prepared instanceof Response) {
|
|
1395
1562
|
throw prepared;
|
|
1396
1563
|
}
|
|
@@ -1403,7 +1570,7 @@ async function renderToHTML(route, ctx, root) {
|
|
|
1403
1570
|
headers
|
|
1404
1571
|
};
|
|
1405
1572
|
}
|
|
1406
|
-
async function prerenderSSG(route, params, root, origin = "http://localhost:3000") {
|
|
1573
|
+
async function prerenderSSG(route, params, root, origin = "http://localhost:3000", basePath) {
|
|
1407
1574
|
const resolvedPath = resolvePath(route.pattern, params);
|
|
1408
1575
|
const cached = getSSGCache(resolvedPath);
|
|
1409
1576
|
if (cached && !IS_DEV) {
|
|
@@ -1411,7 +1578,7 @@ async function prerenderSSG(route, params, root, origin = "http://localhost:3000
|
|
|
1411
1578
|
}
|
|
1412
1579
|
let result;
|
|
1413
1580
|
try {
|
|
1414
|
-
result = await renderForPath(route, params, root, origin);
|
|
1581
|
+
result = await renderForPath(route, params, root, origin, basePath);
|
|
1415
1582
|
} catch (err) {
|
|
1416
1583
|
if (err instanceof Response) {
|
|
1417
1584
|
return err;
|
|
@@ -1574,6 +1741,7 @@ function revalidateInBackground(route, params, cacheKey, revalidate, root, origi
|
|
|
1574
1741
|
}
|
|
1575
1742
|
var SSG_WARM_CONCURRENCY = 4, pendingRevalidations;
|
|
1576
1743
|
var init_render = __esm(() => {
|
|
1744
|
+
init_link();
|
|
1577
1745
|
init_assemble();
|
|
1578
1746
|
init_cache();
|
|
1579
1747
|
init_element();
|
|
@@ -1768,11 +1936,17 @@ function queryDefaultRedirectHook({ request, query, status, set }) {
|
|
|
1768
1936
|
}
|
|
1769
1937
|
async function handleDevRequest(route, ctx, root) {
|
|
1770
1938
|
try {
|
|
1939
|
+
let currentRoot = root;
|
|
1940
|
+
const rootMod = await import(`${root.path}?furin-server&t=${Date.now()}`);
|
|
1941
|
+
const rootExport = rootMod.route ?? rootMod.default;
|
|
1942
|
+
if (rootExport && isFurinRoute(rootExport) && rootExport.layout) {
|
|
1943
|
+
currentRoot = { path: root.path, route: rootExport };
|
|
1944
|
+
}
|
|
1771
1945
|
const pageMod = await import(`${route.path}?furin-server&t=${Date.now()}`);
|
|
1772
1946
|
const page = pageMod.default;
|
|
1773
1947
|
if (page && isFurinPage(page)) {
|
|
1774
1948
|
const chain = collectRouteChainFromRoute(page._route);
|
|
1775
|
-
return renderSSR({ ...route, page, routeChain: chain }, ctx,
|
|
1949
|
+
return renderSSR({ ...route, page, routeChain: chain }, ctx, currentRoot);
|
|
1776
1950
|
}
|
|
1777
1951
|
} catch (err) {
|
|
1778
1952
|
console.error(`[furin] Dev page load error for ${route.path}:`, err);
|
|
@@ -1889,10 +2063,62 @@ var init_router = __esm(() => {
|
|
|
1889
2063
|
// src/dev-page-plugin.ts
|
|
1890
2064
|
var exports_dev_page_plugin = {};
|
|
1891
2065
|
__export(exports_dev_page_plugin, {
|
|
2066
|
+
rewriteSingletonImports: () => rewriteSingletonImports,
|
|
1892
2067
|
rewriteRelativeImports: () => rewriteRelativeImports,
|
|
1893
|
-
|
|
2068
|
+
rewriteBareImports: () => rewriteBareImports,
|
|
2069
|
+
registerDevPagePlugin: () => registerDevPagePlugin,
|
|
2070
|
+
injectJsxHelperImports: () => injectJsxHelperImports
|
|
1894
2071
|
});
|
|
1895
2072
|
import { dirname, resolve } from "path";
|
|
2073
|
+
import { fileURLToPath } from "url";
|
|
2074
|
+
function escapeRegExp(s) {
|
|
2075
|
+
return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
2076
|
+
}
|
|
2077
|
+
function rewriteSingletonImports(source) {
|
|
2078
|
+
let result = source;
|
|
2079
|
+
for (const [pkg, absPath] of SINGLETON_PATHS) {
|
|
2080
|
+
const re = new RegExp(`((?:from|import(?:\\s+type)?)\\s+)["']${escapeRegExp(pkg)}["']`, "g");
|
|
2081
|
+
result = result.replace(re, (_, g1) => `${g1}"${absPath}"`);
|
|
2082
|
+
}
|
|
2083
|
+
return result;
|
|
2084
|
+
}
|
|
2085
|
+
function injectJsxHelperImports(transpiled) {
|
|
2086
|
+
const JSX_HELPER_RE = /\b(jsxDEV|jsxs|jsx|Fragment)_([0-9a-z]{8})\b/g;
|
|
2087
|
+
const devRuntime = new Map;
|
|
2088
|
+
const prodRuntime = new Map;
|
|
2089
|
+
for (const [, base, hash] of transpiled.matchAll(JSX_HELPER_RE)) {
|
|
2090
|
+
if (!(base && hash)) {
|
|
2091
|
+
continue;
|
|
2092
|
+
}
|
|
2093
|
+
const varName = `${base}_${hash}`;
|
|
2094
|
+
if (base === "jsxDEV" || base === "Fragment") {
|
|
2095
|
+
devRuntime.set(varName, base);
|
|
2096
|
+
} else {
|
|
2097
|
+
prodRuntime.set(varName, base);
|
|
2098
|
+
}
|
|
2099
|
+
}
|
|
2100
|
+
const lines = [];
|
|
2101
|
+
if (devRuntime.size > 0) {
|
|
2102
|
+
const absPath = SINGLETON_PATHS.get("react/jsx-dev-runtime");
|
|
2103
|
+
if (absPath) {
|
|
2104
|
+
const specifiers = [...devRuntime.entries()].map(([varName, exportName]) => `${exportName} as ${varName}`).join(", ");
|
|
2105
|
+
lines.push(`import { ${specifiers} } from "${absPath}";`);
|
|
2106
|
+
}
|
|
2107
|
+
}
|
|
2108
|
+
if (prodRuntime.size > 0) {
|
|
2109
|
+
const absPath = SINGLETON_PATHS.get("react/jsx-runtime");
|
|
2110
|
+
if (absPath) {
|
|
2111
|
+
const specifiers = [...prodRuntime.entries()].map(([varName, exportName]) => `${exportName} as ${varName}`).join(", ");
|
|
2112
|
+
lines.push(`import { ${specifiers} } from "${absPath}";`);
|
|
2113
|
+
}
|
|
2114
|
+
}
|
|
2115
|
+
if (lines.length === 0) {
|
|
2116
|
+
return transpiled;
|
|
2117
|
+
}
|
|
2118
|
+
return `${lines.join(`
|
|
2119
|
+
`)}
|
|
2120
|
+
${transpiled}`;
|
|
2121
|
+
}
|
|
1896
2122
|
function rewriteRelativeImports(source, dir) {
|
|
1897
2123
|
return source.replace(RELATIVE_SPECIFIER_RE, (match, relPath, offset) => {
|
|
1898
2124
|
const lineStart = source.lastIndexOf(`
|
|
@@ -1906,6 +2132,72 @@ function rewriteRelativeImports(source, dir) {
|
|
|
1906
2132
|
return `${keyword} "${absPath}"`;
|
|
1907
2133
|
});
|
|
1908
2134
|
}
|
|
2135
|
+
function rewriteBareImports(source, transpiled, dir) {
|
|
2136
|
+
const scanner = new Bun.Transpiler({ loader: "tsx" });
|
|
2137
|
+
let { imports } = scanner.scan(source);
|
|
2138
|
+
const seen = new Set;
|
|
2139
|
+
imports = imports.filter((imp) => {
|
|
2140
|
+
if (seen.has(imp.path)) {
|
|
2141
|
+
return false;
|
|
2142
|
+
}
|
|
2143
|
+
seen.add(imp.path);
|
|
2144
|
+
return true;
|
|
2145
|
+
});
|
|
2146
|
+
let result = transpiled;
|
|
2147
|
+
for (const imp of imports) {
|
|
2148
|
+
const spec = imp.path;
|
|
2149
|
+
if (spec.startsWith(".") || spec.startsWith("/") || spec.startsWith("file:")) {
|
|
2150
|
+
continue;
|
|
2151
|
+
}
|
|
2152
|
+
if (SINGLETON_PATHS.has(spec)) {
|
|
2153
|
+
continue;
|
|
2154
|
+
}
|
|
2155
|
+
let resolved;
|
|
2156
|
+
try {
|
|
2157
|
+
resolved = Bun.resolveSync(spec, dir);
|
|
2158
|
+
} catch {
|
|
2159
|
+
continue;
|
|
2160
|
+
}
|
|
2161
|
+
const re = new RegExp(`((?:from|import(?:\\s+type)?)\\s+)["']${escapeRegExp(spec)}["']`, "g");
|
|
2162
|
+
result = result.replace(re, (_, g1) => `${g1}"${resolved}"`);
|
|
2163
|
+
}
|
|
2164
|
+
return result;
|
|
2165
|
+
}
|
|
2166
|
+
function getSourceLoader(filePath) {
|
|
2167
|
+
if (filePath.endsWith(".tsx")) {
|
|
2168
|
+
return "tsx";
|
|
2169
|
+
}
|
|
2170
|
+
if (filePath.endsWith(".ts")) {
|
|
2171
|
+
return "ts";
|
|
2172
|
+
}
|
|
2173
|
+
if (filePath.endsWith(".jsx")) {
|
|
2174
|
+
return "jsx";
|
|
2175
|
+
}
|
|
2176
|
+
if (filePath.endsWith(".js")) {
|
|
2177
|
+
return "js";
|
|
2178
|
+
}
|
|
2179
|
+
return null;
|
|
2180
|
+
}
|
|
2181
|
+
function shouldSkipWorkspaceTransform(filePath) {
|
|
2182
|
+
const normalized = filePath.replace(/\\/g, "/");
|
|
2183
|
+
return normalized.includes("/.furin/");
|
|
2184
|
+
}
|
|
2185
|
+
function transformDevSource(raw, filePath, options) {
|
|
2186
|
+
const loader = getSourceLoader(filePath);
|
|
2187
|
+
if (!loader) {
|
|
2188
|
+
throw new Error(`[furin] Unsupported source loader for ${filePath}`);
|
|
2189
|
+
}
|
|
2190
|
+
const dir = dirname(filePath);
|
|
2191
|
+
const sourceForTranspile = options.rewriteRelativeImports ? rewriteRelativeImports(raw, dir) : raw;
|
|
2192
|
+
const transpiler = new Bun.Transpiler({ loader });
|
|
2193
|
+
const transpiled = transpiler.transformSync(sourceForTranspile, loader);
|
|
2194
|
+
let result = transpiled;
|
|
2195
|
+
if (options.rewriteBareImports) {
|
|
2196
|
+
result = rewriteBareImports(raw, result, dir);
|
|
2197
|
+
}
|
|
2198
|
+
result = rewriteSingletonImports(result);
|
|
2199
|
+
return injectJsxHelperImports(result);
|
|
2200
|
+
}
|
|
1909
2201
|
function registerDevPagePlugin() {
|
|
1910
2202
|
Bun.plugin({
|
|
1911
2203
|
name: "furin-dev-page-loader",
|
|
@@ -1916,25 +2208,64 @@ function registerDevPagePlugin() {
|
|
|
1916
2208
|
const resolvedPath = tMatch ? `${filePath}?t=${tMatch[1]}` : filePath;
|
|
1917
2209
|
return { path: resolvedPath, namespace: "furin-dev-page" };
|
|
1918
2210
|
});
|
|
2211
|
+
build.onLoad({ filter: WORKSPACE_SOURCE_FILTER }, async (args) => {
|
|
2212
|
+
const raw = await Bun.file(args.path).text();
|
|
2213
|
+
const loader = getSourceLoader(args.path);
|
|
2214
|
+
if (!loader) {
|
|
2215
|
+
throw new Error(`[furin] Unsupported source loader for ${args.path}`);
|
|
2216
|
+
}
|
|
2217
|
+
if (shouldSkipWorkspaceTransform(args.path)) {
|
|
2218
|
+
return {
|
|
2219
|
+
contents: raw,
|
|
2220
|
+
loader
|
|
2221
|
+
};
|
|
2222
|
+
}
|
|
2223
|
+
const contents = transformDevSource(raw, args.path, {
|
|
2224
|
+
rewriteBareImports: false,
|
|
2225
|
+
rewriteRelativeImports: false
|
|
2226
|
+
});
|
|
2227
|
+
return {
|
|
2228
|
+
contents,
|
|
2229
|
+
loader: "js"
|
|
2230
|
+
};
|
|
2231
|
+
});
|
|
1919
2232
|
build.onLoad({ namespace: "furin-dev-page", filter: ANY_FILTER }, async (args) => {
|
|
1920
2233
|
const filePath = args.path.replace(STRIP_T_PARAM_RE, "");
|
|
1921
2234
|
const raw = await Bun.file(filePath).text();
|
|
1922
|
-
const contents =
|
|
2235
|
+
const contents = transformDevSource(raw, filePath, {
|
|
2236
|
+
rewriteBareImports: true,
|
|
2237
|
+
rewriteRelativeImports: true
|
|
2238
|
+
});
|
|
1923
2239
|
return {
|
|
1924
2240
|
contents,
|
|
1925
|
-
loader:
|
|
2241
|
+
loader: "js"
|
|
1926
2242
|
};
|
|
1927
2243
|
});
|
|
1928
2244
|
}
|
|
1929
2245
|
});
|
|
1930
2246
|
}
|
|
1931
|
-
var FURIN_SERVER_FILTER, ANY_FILTER, T_PARAM_RE, STRIP_FURIN_SERVER_RE, STRIP_T_PARAM_RE, RELATIVE_SPECIFIER_RE;
|
|
2247
|
+
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
2248
|
var init_dev_page_plugin = __esm(() => {
|
|
1933
2249
|
FURIN_SERVER_FILTER = /\?furin-server(?:&t=\d+)?$/;
|
|
1934
2250
|
ANY_FILTER = /.*/;
|
|
2251
|
+
WORKSPACE_SOURCE_FILTER = /^(?!.*(?:\/node_modules\/|\/\.bun\/))(?!.*\.(?:test|spec)\.[jt]sx?$).*\.[jt]sx?$/;
|
|
1935
2252
|
T_PARAM_RE = /&t=(\d+)/;
|
|
1936
2253
|
STRIP_FURIN_SERVER_RE = /\?furin-server.*$/;
|
|
1937
2254
|
STRIP_T_PARAM_RE = /\?t=\d+$/;
|
|
2255
|
+
SINGLETON_PKGS = [
|
|
2256
|
+
"react",
|
|
2257
|
+
"react/jsx-runtime",
|
|
2258
|
+
"react/jsx-dev-runtime",
|
|
2259
|
+
"react-dom",
|
|
2260
|
+
"react-dom/server",
|
|
2261
|
+
"react-dom/client"
|
|
2262
|
+
];
|
|
2263
|
+
SINGLETON_PATHS = new Map;
|
|
2264
|
+
for (const pkg of SINGLETON_PKGS) {
|
|
2265
|
+
try {
|
|
2266
|
+
SINGLETON_PATHS.set(pkg, fileURLToPath(import.meta.resolve(pkg)));
|
|
2267
|
+
} catch {}
|
|
2268
|
+
}
|
|
1938
2269
|
RELATIVE_SPECIFIER_RE = /(?:from|import)\s+["'](\.\.?\/[^"']+)["']/g;
|
|
1939
2270
|
});
|
|
1940
2271
|
|
|
@@ -2011,28 +2342,33 @@ __export(exports_hydrate, {
|
|
|
2011
2342
|
});
|
|
2012
2343
|
import { existsSync as existsSync3, mkdirSync, readFileSync as readFileSync3, writeFileSync as writeFileSync2 } from "fs";
|
|
2013
2344
|
import { join as join3 } from "path";
|
|
2014
|
-
function generateHydrateEntry(routes, rootLayout) {
|
|
2345
|
+
function generateHydrateEntry(routes, rootLayout, basePath) {
|
|
2015
2346
|
const routeEntries = [];
|
|
2016
2347
|
for (const route of routes) {
|
|
2017
2348
|
const resolvedPage = route.path.replace(/\\/g, "/");
|
|
2018
2349
|
const regexPattern = route.pattern.replace(/:[^/]+/g, "([^/]+)").replace(/\*/g, "(.*)");
|
|
2019
2350
|
routeEntries.push(` { pattern: "${route.pattern}", regex: new RegExp("^${regexPattern}$"), load: () => import("${resolvedPage}") }`);
|
|
2020
2351
|
}
|
|
2352
|
+
const basePathLiteral = JSON.stringify(basePath);
|
|
2353
|
+
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";
|
|
2354
|
+
const logEndpoint = basePath ? `${JSON.stringify(basePath)} + "/_furin/ingest"` : `"/_furin/ingest"`;
|
|
2355
|
+
const basePathProp = basePath ? `
|
|
2356
|
+
basePath: ${basePathLiteral},` : "";
|
|
2021
2357
|
return `import { hydrateRoot, createRoot } from "react-dom/client";
|
|
2022
2358
|
import { createElement } from "react";
|
|
2023
2359
|
import { initLogger, log } from "evlog";
|
|
2024
|
-
import {
|
|
2360
|
+
import { createHttpLogDrain } from "evlog/http";
|
|
2025
2361
|
import { RouterProvider } from "@teyik0/furin/link";
|
|
2026
2362
|
import { route as root } from "${rootLayout.replace(/\\/g, "/")}";
|
|
2027
2363
|
|
|
2028
|
-
initLogger({ drain:
|
|
2364
|
+
initLogger({ drain: createHttpLogDrain({ drain: { endpoint: ${logEndpoint} } }) });
|
|
2029
2365
|
|
|
2030
2366
|
const routes = [
|
|
2031
2367
|
${routeEntries.join(`,
|
|
2032
2368
|
`)}
|
|
2033
2369
|
];
|
|
2034
2370
|
|
|
2035
|
-
const pathname =
|
|
2371
|
+
const pathname = ${pathnameExpr};
|
|
2036
2372
|
const _match = routes.find((r) => r.regex.test(pathname));
|
|
2037
2373
|
|
|
2038
2374
|
// Eagerly load only the current page module for initial hydration.
|
|
@@ -2052,7 +2388,7 @@ const _match = routes.find((r) => r.regex.test(pathname));
|
|
|
2052
2388
|
routes,
|
|
2053
2389
|
root,
|
|
2054
2390
|
initialMatch: match,
|
|
2055
|
-
initialData: loaderData
|
|
2391
|
+
initialData: loaderData,${basePathProp}
|
|
2056
2392
|
} as any);
|
|
2057
2393
|
|
|
2058
2394
|
if (import.meta.hot) {
|
|
@@ -2082,11 +2418,11 @@ const _match = routes.find((r) => r.regex.test(pathname));
|
|
|
2082
2418
|
});
|
|
2083
2419
|
`;
|
|
2084
2420
|
}
|
|
2085
|
-
function writeDevFiles(routes, { outDir, rootLayout }, projectRoot) {
|
|
2421
|
+
function writeDevFiles(routes, { outDir, rootLayout, basePath }, projectRoot) {
|
|
2086
2422
|
if (!existsSync3(outDir)) {
|
|
2087
2423
|
mkdirSync(outDir, { recursive: true });
|
|
2088
2424
|
}
|
|
2089
|
-
const hydrateCode = generateHydrateEntry(routes, rootLayout);
|
|
2425
|
+
const hydrateCode = generateHydrateEntry(routes, rootLayout, basePath);
|
|
2090
2426
|
const hydratePath = join3(outDir, "_hydrate.tsx");
|
|
2091
2427
|
const existingHydrate = existsSync3(hydratePath) ? readFileSync3(hydratePath, "utf8") : "";
|
|
2092
2428
|
if (hydrateCode !== existingHydrate) {
|
|
@@ -2107,22 +2443,18 @@ var init_hydrate = __esm(() => {
|
|
|
2107
2443
|
});
|
|
2108
2444
|
|
|
2109
2445
|
// src/furin.ts
|
|
2110
|
-
|
|
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
|
|
2446
|
+
init_dist();
|
|
2120
2447
|
init_elysia();
|
|
2121
2448
|
init_cache();
|
|
2122
2449
|
init_render();
|
|
2123
2450
|
init_template();
|
|
2124
2451
|
init_router();
|
|
2125
2452
|
init_cache();
|
|
2453
|
+
import { existsSync as existsSync4 } from "fs";
|
|
2454
|
+
import { basename, dirname as dirname2, join as join4, resolve as resolve2 } from "path";
|
|
2455
|
+
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
2456
|
+
import { staticPlugin } from "@elysiajs/static";
|
|
2457
|
+
import { Elysia as Elysia3, file } from "elysia";
|
|
2126
2458
|
function resolveClientDirFromArgv() {
|
|
2127
2459
|
return resolveClientDirFromEnv() ?? resolveClientDirFromModuleUrl() ?? resolveClientDirFromProcessArgs() ?? resolveFallbackClientDir();
|
|
2128
2460
|
}
|
|
@@ -2139,7 +2471,7 @@ function resolveClientDirFromModuleUrl() {
|
|
|
2139
2471
|
if (moduleUrl.protocol !== "file:") {
|
|
2140
2472
|
return null;
|
|
2141
2473
|
}
|
|
2142
|
-
const modulePath =
|
|
2474
|
+
const modulePath = fileURLToPath2(moduleUrl);
|
|
2143
2475
|
if (modulePath.includes("/$bunfs/")) {
|
|
2144
2476
|
return null;
|
|
2145
2477
|
}
|
|
@@ -2270,7 +2602,7 @@ async function furin({
|
|
|
2270
2602
|
const { scanPages: scanPages2 } = await Promise.resolve().then(() => (init_router(), exports_router));
|
|
2271
2603
|
const { root: root2, routes: routes2 } = await scanPages2(resolvedPagesDir);
|
|
2272
2604
|
const { writeDevFiles: writeDevFiles2 } = await Promise.resolve().then(() => (init_hydrate(), exports_hydrate));
|
|
2273
|
-
writeDevFiles2(routes2, { outDir: furinDir, rootLayout: root2.path }, cwd);
|
|
2605
|
+
writeDevFiles2(routes2, { outDir: furinDir, rootLayout: root2.path, basePath: "", publicPath: "/_client/" }, cwd);
|
|
2274
2606
|
const publicDir = resolve2(cwd, "public");
|
|
2275
2607
|
const publicExists = existsSync4(publicDir);
|
|
2276
2608
|
const devApp = new Elysia3({ name: instanceName, seed: resolvedPagesDir }).use(loggerPlugin).onAfterHandle({ as: "global" }, ({ set }) => {
|
|
@@ -2278,7 +2610,7 @@ async function furin({
|
|
|
2278
2610
|
if (pending.length > 0) {
|
|
2279
2611
|
set.headers["x-furin-revalidate"] = pending.join(",");
|
|
2280
2612
|
}
|
|
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) => {
|
|
2613
|
+
}).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
2614
|
for (const route of routes2) {
|
|
2283
2615
|
app.use(createRoutePlugin(route, root2));
|
|
2284
2616
|
}
|