@teyik0/furin 0.1.0-alpha.8 → 0.2.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +33 -0
- package/dist/adapter/bun.d.ts +2 -2
- package/dist/adapter/static.d.ts +1 -1
- package/dist/build/client.d.ts +2 -2
- package/dist/build/compile-entry.d.ts +2 -16
- package/dist/build/compile-entry.ts +109 -0
- package/dist/build/entry-template.d.ts +24 -0
- package/dist/build/entry-template.ts +156 -0
- package/dist/build/hydrate.d.ts +3 -3
- package/dist/build/index.d.ts +1 -0
- package/dist/build/index.js +4734 -548
- package/dist/build/route-types.d.ts +1 -1
- package/dist/build/server-routes-entry.d.ts +2 -12
- package/dist/build/server-routes-entry.ts +36 -0
- package/dist/build/shared.d.ts +1 -1
- package/dist/build/ssg-cache.d.ts +4 -0
- package/dist/build/types.d.ts +5 -1
- package/dist/cli/index.js +4713 -549
- package/dist/client/boundaries.d.ts +117 -0
- package/dist/client/default-screens.d.ts +17 -0
- package/dist/client/link.d.ts +22 -0
- package/dist/client/link.js +3450 -0
- package/dist/client/router/boundary-tree.d.ts +26 -0
- package/dist/client/router/context.d.ts +8 -0
- package/dist/client/router/history.d.ts +9 -0
- package/dist/client/router/index.d.ts +7 -0
- package/dist/client/router/link-utils.d.ts +51 -0
- package/dist/client/router/provider.d.ts +4 -0
- package/dist/client/router/spa-response.d.ts +58 -0
- package/dist/{link.d.ts → client/router/types.d.ts} +114 -80
- package/dist/client/server-error.d.ts +12 -0
- package/dist/client.d.ts +54 -4
- package/dist/client.js +77 -1
- package/dist/config.d.ts +12 -2
- package/dist/config.js +1 -0
- package/dist/env.d.ts +50 -0
- package/dist/furin.d.ts +37 -2
- package/dist/furin.js +5288 -601
- package/dist/plugin/index.js +140 -48
- package/dist/plugin/transform-client.d.ts +2 -1
- package/dist/server/auto-invalidate/index.d.ts +4 -0
- package/dist/server/auto-invalidate/plugin.d.ts +38 -0
- package/dist/server/auto-invalidate/registry.d.ts +9 -0
- package/dist/server/auto-invalidate/runtime.d.ts +9 -0
- package/dist/server/auto-invalidate/types.d.ts +12 -0
- package/dist/server/cache/dev-loader.d.ts +28 -0
- package/dist/server/cache/index.d.ts +10 -0
- package/dist/server/cache/invalidation.d.ts +12 -0
- package/dist/server/cache/isr-ssg.d.ts +26 -0
- package/dist/server/cache/isr.d.ts +6 -0
- package/dist/server/cache/registry.d.ts +5 -0
- package/dist/server/cache/route-cache.d.ts +26 -0
- package/dist/server/cache/ssg.d.ts +5 -0
- package/dist/server/context-logger.d.ts +28 -0
- package/dist/server/dev-inspector.d.ts +89 -0
- package/dist/{internal.d.ts → server/internal.d.ts} +16 -0
- package/dist/server/internal.js +17 -0
- package/dist/server/lang-detect.d.ts +5 -0
- package/dist/server/render/assemble.d.ts +47 -0
- package/dist/server/render/element.d.ts +24 -0
- package/dist/server/render/index.d.ts +7 -0
- package/dist/server/render/index.ts +22 -0
- package/dist/server/render/isr.d.ts +3 -0
- package/dist/server/render/loaders.d.ts +64 -0
- package/dist/server/render/not-found.d.ts +6 -0
- package/dist/{render → server/render}/shell.d.ts +17 -4
- package/{src → dist/server}/render/shell.ts +31 -9
- package/dist/server/render/ssg.d.ts +8 -0
- package/dist/server/render/ssr.d.ts +107 -0
- package/dist/server/router/discovery.d.ts +16 -0
- package/dist/server/router/hmr.d.ts +64 -0
- package/dist/server/router/index.d.ts +6 -0
- package/dist/server/router/index.js +28 -0
- package/dist/server/router/index.ts +29 -0
- package/dist/server/router/patterns.d.ts +40 -0
- package/dist/server/router/plugin.d.ts +20 -0
- package/dist/server/router/schemas.d.ts +51 -0
- package/dist/server/router/types.d.ts +60 -0
- package/dist/server/runtime-env.js +10 -0
- package/dist/shared/await.d.ts +67 -0
- package/dist/shared/deferred-ndjson.d.ts +32 -0
- package/dist/shared/digest.d.ts +16 -0
- package/dist/shared/error.d.ts +37 -0
- package/dist/shared/not-found.d.ts +19 -0
- package/dist/shared/utils/ast-walk.d.ts +18 -0
- package/dist/shared/utils/index.d.ts +13 -0
- package/package.json +56 -25
- package/src/adapter/bun.ts +90 -41
- package/src/adapter/static.ts +83 -36
- package/src/build/client.ts +8 -12
- package/src/build/compile-entry.ts +20 -14
- package/src/build/entry-template.ts +90 -8
- package/src/build/hydrate.ts +213 -36
- package/src/build/index.ts +10 -9
- package/src/build/route-types.ts +30 -4
- package/src/build/scan-server.ts +52 -67
- package/src/build/server-routes-entry.ts +7 -11
- package/src/build/shared.ts +1 -1
- package/src/build/ssg-cache.ts +31 -0
- package/src/build/types.ts +5 -1
- package/src/cli/index.ts +1 -0
- package/src/client/boundaries.tsx +259 -0
- package/src/client/default-screens.tsx +304 -0
- package/src/client/link.tsx +338 -0
- package/src/client/router/boundary-tree.tsx +116 -0
- package/src/client/router/context.ts +38 -0
- package/src/client/router/history.ts +41 -0
- package/src/client/router/index.ts +47 -0
- package/src/client/router/link-utils.ts +180 -0
- package/src/client/router/provider.tsx +723 -0
- package/src/client/router/spa-response.ts +143 -0
- package/src/client/router/types.ts +263 -0
- package/src/client/server-error.ts +47 -0
- package/src/client.ts +83 -3
- package/src/config.ts +11 -3
- package/src/env.d.ts +1 -0
- package/src/furin.ts +104 -26
- package/src/plugin/index.ts +7 -8
- package/src/plugin/transform-client.ts +146 -120
- package/src/server/auto-invalidate/index.ts +10 -0
- package/src/server/auto-invalidate/plugin.ts +25 -0
- package/src/server/auto-invalidate/registry.ts +60 -0
- package/src/server/auto-invalidate/runtime.ts +133 -0
- package/src/server/auto-invalidate/types.ts +16 -0
- package/src/server/cache/dev-loader.ts +211 -0
- package/src/server/cache/index.ts +34 -0
- package/src/server/cache/invalidation.ts +111 -0
- package/src/server/cache/isr-ssg.ts +41 -0
- package/src/server/cache/isr.ts +17 -0
- package/src/server/cache/registry.ts +35 -0
- package/src/server/cache/route-cache.ts +124 -0
- package/src/server/cache/ssg.ts +15 -0
- package/src/server/context-logger.ts +76 -0
- package/src/server/dev-inspector.ts +60 -0
- package/src/{dev-page-plugin.ts → server/dev-page-plugin.ts} +15 -0
- package/src/{internal.ts → server/internal.ts} +17 -0
- package/src/server/lang-detect.ts +46 -0
- package/src/server/render/assemble.ts +133 -0
- package/src/server/render/element.tsx +113 -0
- package/src/server/render/index.ts +22 -0
- package/src/server/render/isr.ts +295 -0
- package/src/server/render/loaders.ts +328 -0
- package/src/server/render/not-found.ts +96 -0
- package/src/server/render/shell.ts +202 -0
- package/src/server/render/ssg.ts +137 -0
- package/src/server/render/ssr.ts +545 -0
- package/src/server/router/discovery.ts +474 -0
- package/src/server/router/hmr.ts +372 -0
- package/src/server/router/index.ts +29 -0
- package/src/server/router/patterns.ts +214 -0
- package/src/server/router/plugin.ts +401 -0
- package/src/server/router/schemas.ts +163 -0
- package/src/server/router/types.ts +59 -0
- package/src/shared/await.tsx +192 -0
- package/src/shared/deferred-ndjson.ts +244 -0
- package/src/shared/digest.ts +71 -0
- package/src/shared/error.ts +49 -0
- package/src/shared/not-found.ts +40 -0
- package/src/shared/utils/ast-walk.ts +51 -0
- package/src/{utils.ts → shared/utils/index.ts} +32 -1
- package/dist/link.js +0 -1173
- package/dist/render/assemble.d.ts +0 -13
- package/dist/render/cache.d.ts +0 -95
- package/dist/render/element.d.ts +0 -4
- package/dist/render/index.d.ts +0 -27
- package/dist/render/loaders.d.ts +0 -12
- package/dist/router.d.ts +0 -34
- package/dist/router.js +0 -830
- package/dist/utils.d.ts +0 -6
- package/src/link.tsx +0 -1035
- package/src/render/assemble.ts +0 -64
- package/src/render/cache.ts +0 -241
- package/src/render/element.tsx +0 -28
- package/src/render/index.ts +0 -479
- package/src/render/loaders.ts +0 -113
- package/src/router.ts +0 -400
- /package/dist/{dev-page-plugin.d.ts → server/dev-page-plugin.d.ts} +0 -0
- /package/dist/{render → server/render}/template.d.ts +0 -0
- /package/dist/{runtime-env.d.ts → server/runtime-env.d.ts} +0 -0
- /package/src/{render → server/render}/template.ts +0 -0
- /package/src/{runtime-env.ts → server/runtime-env.ts} +0 -0
package/dist/plugin/index.js
CHANGED
|
@@ -1137,39 +1137,77 @@ class MagicString {
|
|
|
1137
1137
|
}
|
|
1138
1138
|
|
|
1139
1139
|
// src/plugin/transform-client.ts
|
|
1140
|
-
import {
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1140
|
+
import {
|
|
1141
|
+
parse
|
|
1142
|
+
} from "yuku-parser";
|
|
1143
|
+
|
|
1144
|
+
// src/server/lang-detect.ts
|
|
1145
|
+
function detectLangFromPath(filePath) {
|
|
1146
|
+
if (filePath.endsWith(".d.ts")) {
|
|
1147
|
+
return "dts";
|
|
1148
|
+
}
|
|
1149
|
+
const ext = filePath.split(".").pop()?.toLowerCase();
|
|
1150
|
+
switch (ext) {
|
|
1151
|
+
case "ts":
|
|
1152
|
+
return "ts";
|
|
1153
|
+
case "tsx":
|
|
1154
|
+
return "tsx";
|
|
1155
|
+
case "jsx":
|
|
1156
|
+
return "jsx";
|
|
1157
|
+
default:
|
|
1158
|
+
return "js";
|
|
1149
1159
|
}
|
|
1150
|
-
}
|
|
1151
|
-
var
|
|
1152
|
-
|
|
1160
|
+
}
|
|
1161
|
+
var TS_WRAPPER_TYPES = new Set([
|
|
1162
|
+
"TSAsExpression",
|
|
1163
|
+
"TSSatisfiesExpression",
|
|
1164
|
+
"TSTypeAssertion",
|
|
1165
|
+
"TSNonNullExpression",
|
|
1166
|
+
"TSInstantiationExpression",
|
|
1167
|
+
"ParenthesizedExpression"
|
|
1168
|
+
]);
|
|
1169
|
+
function unwrapTSExpression(node) {
|
|
1170
|
+
let current = node;
|
|
1171
|
+
while (current && typeof current === "object" && TS_WRAPPER_TYPES.has(current.type) && current.expression && typeof current.expression === "object") {
|
|
1172
|
+
current = current.expression;
|
|
1173
|
+
}
|
|
1174
|
+
return current;
|
|
1175
|
+
}
|
|
1176
|
+
|
|
1177
|
+
// src/shared/utils/ast-walk.ts
|
|
1178
|
+
var SKIP_KEYS = new Set(["type", "start", "end", "comments"]);
|
|
1179
|
+
function isAstNode(value) {
|
|
1180
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
1181
|
+
return false;
|
|
1182
|
+
}
|
|
1183
|
+
const candidate = value;
|
|
1184
|
+
return typeof candidate.type === "string";
|
|
1185
|
+
}
|
|
1186
|
+
function walkAST(node, visitor) {
|
|
1153
1187
|
if (!node || typeof node !== "object") {
|
|
1154
1188
|
return;
|
|
1155
1189
|
}
|
|
1156
1190
|
if (Array.isArray(node)) {
|
|
1157
1191
|
for (const child of node) {
|
|
1158
|
-
|
|
1192
|
+
walkAST(child, visitor);
|
|
1159
1193
|
}
|
|
1160
1194
|
return;
|
|
1161
1195
|
}
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
visitor(n2);
|
|
1196
|
+
if (!isAstNode(node)) {
|
|
1197
|
+
return;
|
|
1165
1198
|
}
|
|
1199
|
+
const n2 = node;
|
|
1200
|
+
visitor(n2);
|
|
1166
1201
|
for (const key of Object.keys(n2)) {
|
|
1167
|
-
if (key
|
|
1202
|
+
if (SKIP_KEYS.has(key)) {
|
|
1168
1203
|
continue;
|
|
1169
1204
|
}
|
|
1170
|
-
|
|
1205
|
+
walkAST(n2[key], visitor);
|
|
1171
1206
|
}
|
|
1172
1207
|
}
|
|
1208
|
+
|
|
1209
|
+
// src/plugin/transform-client.ts
|
|
1210
|
+
var SERVER_ONLY_PROPERTIES = new Set(["loader", "query", "params", "staticParams"]);
|
|
1173
1211
|
function isCreateRouteCall(node) {
|
|
1174
1212
|
return node.callee.type === "Identifier" && node.callee.name === "createRoute";
|
|
1175
1213
|
}
|
|
@@ -1178,7 +1216,7 @@ function isRoutePageCall(node) {
|
|
|
1178
1216
|
if (callee.type === "Identifier" && callee.name === "page") {
|
|
1179
1217
|
return true;
|
|
1180
1218
|
}
|
|
1181
|
-
if (callee.type === "MemberExpression" && callee.property
|
|
1219
|
+
if (callee.type === "MemberExpression" && callee.property.type === "Identifier" && callee.property.name === "page") {
|
|
1182
1220
|
return true;
|
|
1183
1221
|
}
|
|
1184
1222
|
return false;
|
|
@@ -1186,6 +1224,9 @@ function isRoutePageCall(node) {
|
|
|
1186
1224
|
function isTargetCall(node) {
|
|
1187
1225
|
return isCreateRouteCall(node) || isRoutePageCall(node);
|
|
1188
1226
|
}
|
|
1227
|
+
function isObjectExpressionNode(node) {
|
|
1228
|
+
return node.type === "ObjectExpression";
|
|
1229
|
+
}
|
|
1189
1230
|
function removeServerProperties(s, source, obj) {
|
|
1190
1231
|
const toRemove = obj.properties.filter((p) => {
|
|
1191
1232
|
if (p.type !== "Property") {
|
|
@@ -1231,31 +1272,77 @@ function removeServerProperties(s, source, obj) {
|
|
|
1231
1272
|
}
|
|
1232
1273
|
return true;
|
|
1233
1274
|
}
|
|
1275
|
+
var TYPE_SCOPE_NODES = new Set([
|
|
1276
|
+
"TSTypeAnnotation",
|
|
1277
|
+
"TSTypeParameterDeclaration",
|
|
1278
|
+
"TSTypeParameterInstantiation",
|
|
1279
|
+
"TSInterfaceDeclaration",
|
|
1280
|
+
"TSTypeAliasDeclaration",
|
|
1281
|
+
"TSTypePredicate",
|
|
1282
|
+
"TSClassImplements"
|
|
1283
|
+
]);
|
|
1284
|
+
function markTypeDescendants(node, excluded) {
|
|
1285
|
+
if (!node || typeof node !== "object") {
|
|
1286
|
+
return;
|
|
1287
|
+
}
|
|
1288
|
+
if (Array.isArray(node)) {
|
|
1289
|
+
for (const item of node) {
|
|
1290
|
+
markTypeDescendants(item, excluded);
|
|
1291
|
+
}
|
|
1292
|
+
return;
|
|
1293
|
+
}
|
|
1294
|
+
const n2 = node;
|
|
1295
|
+
if (n2.type === "Identifier" || n2.type === "JSXIdentifier") {
|
|
1296
|
+
excluded.add(n2);
|
|
1297
|
+
}
|
|
1298
|
+
for (const key of Object.keys(n2)) {
|
|
1299
|
+
if (key === "type" || key === "start" || key === "end") {
|
|
1300
|
+
continue;
|
|
1301
|
+
}
|
|
1302
|
+
markTypeDescendants(n2[key], excluded);
|
|
1303
|
+
}
|
|
1304
|
+
}
|
|
1305
|
+
function excludeTypePositionIdentifiers(node, excluded) {
|
|
1306
|
+
if (TYPE_SCOPE_NODES.has(node.type)) {
|
|
1307
|
+
markTypeDescendants(node, excluded);
|
|
1308
|
+
return;
|
|
1309
|
+
}
|
|
1310
|
+
if (node.type === "TSAsExpression" || node.type === "TSSatisfiesExpression" || node.type === "TSTypeAssertion") {
|
|
1311
|
+
markTypeDescendants(node.typeAnnotation, excluded);
|
|
1312
|
+
}
|
|
1313
|
+
}
|
|
1234
1314
|
function collectReferencedNames(program) {
|
|
1235
1315
|
const refs = new Set;
|
|
1236
1316
|
const excluded = new Set;
|
|
1237
|
-
for (const stmt of program.body
|
|
1317
|
+
for (const stmt of program.body) {
|
|
1238
1318
|
if (stmt.type === "ImportDeclaration") {
|
|
1239
1319
|
continue;
|
|
1240
1320
|
}
|
|
1241
|
-
|
|
1321
|
+
walkAST(stmt, (node) => {
|
|
1242
1322
|
if (node.type === "Property" && !node.computed) {
|
|
1243
1323
|
excluded.add(node.key);
|
|
1244
1324
|
}
|
|
1245
1325
|
if (node.type === "MemberExpression" && !node.computed) {
|
|
1246
1326
|
excluded.add(node.property);
|
|
1247
1327
|
}
|
|
1328
|
+
if (node.type === "JSXAttribute") {
|
|
1329
|
+
excluded.add(node.name);
|
|
1330
|
+
}
|
|
1331
|
+
if (node.type === "JSXMemberExpression") {
|
|
1332
|
+
excluded.add(node.property);
|
|
1333
|
+
}
|
|
1334
|
+
excludeTypePositionIdentifiers(node, excluded);
|
|
1248
1335
|
});
|
|
1249
1336
|
}
|
|
1250
|
-
for (const stmt of program.body
|
|
1337
|
+
for (const stmt of program.body) {
|
|
1251
1338
|
if (stmt.type === "ImportDeclaration") {
|
|
1252
1339
|
continue;
|
|
1253
1340
|
}
|
|
1254
|
-
|
|
1341
|
+
walkAST(stmt, (node) => {
|
|
1255
1342
|
if (excluded.has(node)) {
|
|
1256
1343
|
return;
|
|
1257
1344
|
}
|
|
1258
|
-
if (node.type === "Identifier" && typeof node.name === "string") {
|
|
1345
|
+
if ((node.type === "Identifier" || node.type === "JSXIdentifier") && typeof node.name === "string") {
|
|
1259
1346
|
refs.add(node.name);
|
|
1260
1347
|
}
|
|
1261
1348
|
});
|
|
@@ -1286,17 +1373,17 @@ function removeUnusedSpecifiers(s, code, decl, refs) {
|
|
|
1286
1373
|
s.remove(removeStart, removeEnd);
|
|
1287
1374
|
}
|
|
1288
1375
|
}
|
|
1289
|
-
function deadCodeElimination(s) {
|
|
1376
|
+
function deadCodeElimination(s, lang) {
|
|
1290
1377
|
const code = s.toString();
|
|
1291
|
-
const { program,
|
|
1292
|
-
|
|
1293
|
-
|
|
1378
|
+
const { program, diagnostics } = parse(code, { sourceType: "module", lang });
|
|
1379
|
+
const firstError = diagnostics.find((d) => d.severity === "error");
|
|
1380
|
+
if (firstError) {
|
|
1381
|
+
console.error("[furin] DCE: failed to parse transformed output:", firstError.message);
|
|
1294
1382
|
return s;
|
|
1295
1383
|
}
|
|
1296
1384
|
const fresh = new MagicString(code);
|
|
1297
|
-
const
|
|
1298
|
-
const
|
|
1299
|
-
const body = programNode.body ?? [];
|
|
1385
|
+
const refs = collectReferencedNames(program);
|
|
1386
|
+
const body = program.body;
|
|
1300
1387
|
for (let i = body.length - 1;i >= 0; i--) {
|
|
1301
1388
|
const stmt = body[i];
|
|
1302
1389
|
if (!stmt) {
|
|
@@ -1320,7 +1407,7 @@ function deadCodeElimination(s) {
|
|
|
1320
1407
|
}
|
|
1321
1408
|
function removeServerExports(s, source, program) {
|
|
1322
1409
|
let removedServerCode = false;
|
|
1323
|
-
|
|
1410
|
+
walkAST(program, (node) => {
|
|
1324
1411
|
if (node.type !== "CallExpression") {
|
|
1325
1412
|
return;
|
|
1326
1413
|
}
|
|
@@ -1328,8 +1415,12 @@ function removeServerExports(s, source, program) {
|
|
|
1328
1415
|
if (!isTargetCall(call)) {
|
|
1329
1416
|
return;
|
|
1330
1417
|
}
|
|
1331
|
-
const
|
|
1332
|
-
if (!
|
|
1418
|
+
const firstArg = call.arguments[0];
|
|
1419
|
+
if (!firstArg) {
|
|
1420
|
+
return;
|
|
1421
|
+
}
|
|
1422
|
+
const arg = unwrapTSExpression(firstArg);
|
|
1423
|
+
if (!isObjectExpressionNode(arg)) {
|
|
1333
1424
|
return;
|
|
1334
1425
|
}
|
|
1335
1426
|
if (removeServerProperties(s, source, arg)) {
|
|
@@ -1339,15 +1430,19 @@ function removeServerExports(s, source, program) {
|
|
|
1339
1430
|
return removedServerCode;
|
|
1340
1431
|
}
|
|
1341
1432
|
function transformForClient(code, filename) {
|
|
1342
|
-
const
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
throw new Error(`Failed to parse ${filename}: ${errors[0]?.message}`);
|
|
1433
|
+
const lang = detectLangFromPath(filename);
|
|
1434
|
+
if (lang === "dts") {
|
|
1435
|
+
return { code, map: null, removedServerCode: false };
|
|
1346
1436
|
}
|
|
1347
|
-
|
|
1348
|
-
const
|
|
1437
|
+
const { program, diagnostics } = parse(code, { sourceType: "module", lang });
|
|
1438
|
+
const firstError = diagnostics.find((d) => d.severity === "error");
|
|
1439
|
+
if (firstError) {
|
|
1440
|
+
throw new Error(`Failed to parse ${filename}: ${firstError.message}`);
|
|
1441
|
+
}
|
|
1442
|
+
let s = new MagicString(code);
|
|
1443
|
+
const removedServerCode = removeServerExports(s, code, program);
|
|
1349
1444
|
if (removedServerCode) {
|
|
1350
|
-
s = deadCodeElimination(s);
|
|
1445
|
+
s = deadCodeElimination(s, lang);
|
|
1351
1446
|
}
|
|
1352
1447
|
return {
|
|
1353
1448
|
code: s.toString(),
|
|
@@ -1361,7 +1456,6 @@ var ELYSIA_FILTER = /^elysia$/;
|
|
|
1361
1456
|
var BUN_BUILTIN_FILTER = /^bun:/;
|
|
1362
1457
|
var ANY_FILTER = /.*/;
|
|
1363
1458
|
var TS_FILE_FILTER = /\.(tsx|ts)$/;
|
|
1364
|
-
var REACT_IMPORT_FILTER = /import\s+React\b/;
|
|
1365
1459
|
var ELYSIA_STUB = `export const t = new Proxy({}, { get: () => (...args) => args[0] ?? {} });
|
|
1366
1460
|
export class NotFoundError extends Error { constructor(m) { super(m); this.name = "NotFoundError"; } }
|
|
1367
1461
|
export class ValidationError extends Error { constructor(m) { super(m); this.name = "ValidationError"; } }
|
|
@@ -1389,12 +1483,10 @@ var plugin = {
|
|
|
1389
1483
|
const source = await Bun.file(args.path).text();
|
|
1390
1484
|
try {
|
|
1391
1485
|
const result = transformForClient(source, args.path);
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
}
|
|
1397
|
-
return { contents: code, loader: "js" };
|
|
1486
|
+
return {
|
|
1487
|
+
contents: result.code,
|
|
1488
|
+
loader: args.path.endsWith(".tsx") ? "tsx" : "ts"
|
|
1489
|
+
};
|
|
1398
1490
|
} catch (err) {
|
|
1399
1491
|
console.error(`[furin] strip-plugin transform error for ${args.path}:`, err);
|
|
1400
1492
|
return;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import MagicString from "magic-string";
|
|
2
|
+
import { type SourceLang } from "yuku-parser";
|
|
2
3
|
interface TransformResult {
|
|
3
4
|
code: string;
|
|
4
5
|
map: ReturnType<MagicString["generateMap"]> | null;
|
|
5
6
|
removedServerCode: boolean;
|
|
6
7
|
}
|
|
7
|
-
export declare function deadCodeElimination(s: MagicString): MagicString;
|
|
8
|
+
export declare function deadCodeElimination(s: MagicString, lang: SourceLang): MagicString;
|
|
8
9
|
export declare function transformForClient(code: string, filename: string): TransformResult;
|
|
9
10
|
export {};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { furinInvalidate } from "./plugin.ts";
|
|
2
|
+
export { AutoInvalidateRegistry, autoInvalidateRegistry } from "./registry.ts";
|
|
3
|
+
export { appendPendingInvalidationHeader, isSuccessfulMutationResponse, revalidateTag, runInvalidationRules, } from "./runtime.ts";
|
|
4
|
+
export type { InvalidationInput, InvalidationRule } from "./types.ts";
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { type AfterHandler, Elysia } from "elysia";
|
|
2
|
+
import type { InvalidationInput } from "./types.ts";
|
|
3
|
+
type AnyAfterHandleContext = Parameters<AfterHandler>[0];
|
|
4
|
+
export declare function furinInvalidate(): Elysia<"", {
|
|
5
|
+
decorator: {};
|
|
6
|
+
store: {};
|
|
7
|
+
derive: {};
|
|
8
|
+
resolve: {};
|
|
9
|
+
}, {
|
|
10
|
+
typebox: {};
|
|
11
|
+
error: {};
|
|
12
|
+
}, {
|
|
13
|
+
schema: {};
|
|
14
|
+
standaloneSchema: {};
|
|
15
|
+
macro: Partial<{
|
|
16
|
+
readonly invalidate: InvalidationInput;
|
|
17
|
+
}>;
|
|
18
|
+
macroFn: {
|
|
19
|
+
readonly invalidate: (rules: InvalidationInput) => {
|
|
20
|
+
readonly afterHandle: (ctx: AnyAfterHandleContext) => void;
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
parser: {};
|
|
24
|
+
response: {};
|
|
25
|
+
}, {}, {
|
|
26
|
+
derive: {};
|
|
27
|
+
resolve: {};
|
|
28
|
+
schema: {};
|
|
29
|
+
standaloneSchema: {};
|
|
30
|
+
response: {};
|
|
31
|
+
}, {
|
|
32
|
+
derive: {};
|
|
33
|
+
resolve: {};
|
|
34
|
+
schema: {};
|
|
35
|
+
standaloneSchema: {};
|
|
36
|
+
response: {};
|
|
37
|
+
}>;
|
|
38
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare class AutoInvalidateRegistry {
|
|
2
|
+
private readonly pathToTags;
|
|
3
|
+
private readonly tagToPaths;
|
|
4
|
+
registerLoaderTags(urlPath: string, tags: readonly string[] | undefined): void;
|
|
5
|
+
pathsForTags(tags: readonly string[]): string[];
|
|
6
|
+
unregisterPath(urlPath: string): void;
|
|
7
|
+
reset(): void;
|
|
8
|
+
}
|
|
9
|
+
export declare const autoInvalidateRegistry: AutoInvalidateRegistry;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Context } from "elysia";
|
|
2
|
+
import type { InvalidationInput } from "./types.ts";
|
|
3
|
+
export declare function isSuccessfulMutationResponse(ctx: Pick<Context, "set"> & {
|
|
4
|
+
responseValue?: unknown;
|
|
5
|
+
response?: unknown;
|
|
6
|
+
}): boolean;
|
|
7
|
+
export declare function appendPendingInvalidationHeader(set: Context["set"]): void;
|
|
8
|
+
export declare function revalidateTag(tags: string | readonly string[]): boolean;
|
|
9
|
+
export declare function runInvalidationRules(input: InvalidationInput): boolean;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { CacheTag } from "../../furin.ts";
|
|
2
|
+
import type { RevalidateType } from "../cache/route-cache.ts";
|
|
3
|
+
export type InvalidationRule = {
|
|
4
|
+
path: string;
|
|
5
|
+
tags?: readonly CacheTag[];
|
|
6
|
+
type: RevalidateType;
|
|
7
|
+
} | {
|
|
8
|
+
path?: never;
|
|
9
|
+
tags: readonly CacheTag[];
|
|
10
|
+
type?: never;
|
|
11
|
+
};
|
|
12
|
+
export type InvalidationInput = InvalidationRule | readonly InvalidationRule[];
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { type RevalidateType } from "./route-cache";
|
|
2
|
+
export interface DevLoaderCacheEntry {
|
|
3
|
+
dependencies: string[];
|
|
4
|
+
generatedAt: number;
|
|
5
|
+
headers: Record<string, string>;
|
|
6
|
+
loaderData: Record<string, unknown>;
|
|
7
|
+
mode: "isr" | "ssg";
|
|
8
|
+
revalidate: number;
|
|
9
|
+
}
|
|
10
|
+
export interface InvalidateOutcome {
|
|
11
|
+
cleared: string[];
|
|
12
|
+
isr: number;
|
|
13
|
+
ssg: number;
|
|
14
|
+
}
|
|
15
|
+
export declare const devISRLoaderCache: import("./route-cache").Cache<DevLoaderCacheEntry>;
|
|
16
|
+
export declare const devSSGLoaderCache: import("./route-cache").Cache<DevLoaderCacheEntry>;
|
|
17
|
+
export declare function getDevISRLoaderCache(key: string): DevLoaderCacheEntry | undefined;
|
|
18
|
+
export declare function setDevISRLoaderCache(key: string, entry: DevLoaderCacheEntry): void;
|
|
19
|
+
export declare function getDevSSGLoaderCache(key: string): DevLoaderCacheEntry | undefined;
|
|
20
|
+
export declare function setDevSSGLoaderCache(key: string, entry: DevLoaderCacheEntry): void;
|
|
21
|
+
export declare function urlPathFromCacheKey(key: string): string | null;
|
|
22
|
+
export declare function invalidateDevLoaderCacheByPath(path: string, type: RevalidateType): InvalidateOutcome;
|
|
23
|
+
export declare function invalidateDevLoaderCacheBySource(filePath: string): InvalidateOutcome;
|
|
24
|
+
export declare function isDevLoaderCacheFresh(entry: DevLoaderCacheEntry): boolean;
|
|
25
|
+
export declare function isDevLoaderCacheValid(entry: DevLoaderCacheEntry): boolean;
|
|
26
|
+
export declare function getAllDevISRLoaderEntries(): [string, DevLoaderCacheEntry][];
|
|
27
|
+
export declare function getAllDevSSGLoaderEntries(): [string, DevLoaderCacheEntry][];
|
|
28
|
+
export declare function __resetDevLoaderCacheState(): void;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type { DevLoaderCacheEntry, InvalidateOutcome } from "./dev-loader";
|
|
2
|
+
export { __resetDevLoaderCacheState, getAllDevISRLoaderEntries, getAllDevSSGLoaderEntries, getDevISRLoaderCache, getDevSSGLoaderCache, invalidateDevLoaderCacheByPath, invalidateDevLoaderCacheBySource, isDevLoaderCacheFresh, isDevLoaderCacheValid, setDevISRLoaderCache, setDevSSGLoaderCache, urlPathFromCacheKey, } from "./dev-loader";
|
|
3
|
+
export { __resetCacheState, _runWithRequestInvalidationScope, callCachePurger, consumePendingInvalidations, getBuildId, revalidatePath, setBuildId, setCachePurger, } from "./invalidation";
|
|
4
|
+
export { deleteISRCache, getISRCache, isrCache, setISRCache } from "./isr";
|
|
5
|
+
export type { ISRCacheEntry, SsgCacheEntry } from "./isr-ssg";
|
|
6
|
+
export type { CacheInvalidator } from "./registry";
|
|
7
|
+
export { registerCacheInvalidator } from "./registry";
|
|
8
|
+
export type { Cache, CacheInvalidationResult, RevalidateType } from "./route-cache";
|
|
9
|
+
export { createRouteCache } from "./route-cache";
|
|
10
|
+
export { getSSGCache, setSSGCache, ssgCache } from "./ssg";
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { RevalidateType } from "./route-cache";
|
|
2
|
+
export declare function setBuildId(id: string): void;
|
|
3
|
+
export declare function getBuildId(): string;
|
|
4
|
+
export declare function _runWithRequestInvalidationScope<T>(fn: () => T): T;
|
|
5
|
+
export declare function consumePendingInvalidations(): string[];
|
|
6
|
+
type CachePurger = (paths: string[]) => Promise<void>;
|
|
7
|
+
export declare function setCachePurger(fn: CachePurger): void;
|
|
8
|
+
export declare function callCachePurger(paths: string[]): void;
|
|
9
|
+
export declare function revalidatePath(path: string, type: RevalidateType): boolean;
|
|
10
|
+
/** @internal — resets all module state between tests */
|
|
11
|
+
export declare function __resetCacheState(): void;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { type Cache } from "./route-cache";
|
|
2
|
+
export interface ISRCacheEntry {
|
|
3
|
+
generatedAt: number;
|
|
4
|
+
html: string;
|
|
5
|
+
revalidate: number;
|
|
6
|
+
}
|
|
7
|
+
export interface SsgCacheEntry {
|
|
8
|
+
cachedAt: number;
|
|
9
|
+
html: string;
|
|
10
|
+
/**
|
|
11
|
+
* NDJSON payload identical in shape to what the live `/_furin/data` endpoint
|
|
12
|
+
* emits. Persisted alongside the HTML by the static adapter so SPA navigation
|
|
13
|
+
* on a static-hosted deployment can fetch loader data without going through
|
|
14
|
+
* a runtime endpoint that does not exist on a file server.
|
|
15
|
+
*/
|
|
16
|
+
ndjson: string;
|
|
17
|
+
status: number;
|
|
18
|
+
tags?: string[];
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Builds the LRU cache backing one render mode's pre-rendered HTML. ISR and SSG
|
|
22
|
+
* share the same eviction bound and the same `onDelete` hook — which keeps the
|
|
23
|
+
* auto-invalidate path registry in sync — and differ only in entry shape and
|
|
24
|
+
* the diagnostic `name`.
|
|
25
|
+
*/
|
|
26
|
+
export declare function createHtmlRouteCache<Entry>(mode: "isr" | "ssg"): Cache<Entry>;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type ISRCacheEntry } from "./isr-ssg";
|
|
2
|
+
export declare const isrRouteCache: import("./route-cache").Cache<ISRCacheEntry>;
|
|
3
|
+
export declare const isrCache: Map<string, ISRCacheEntry>;
|
|
4
|
+
export declare function getISRCache(key: string): ISRCacheEntry | undefined;
|
|
5
|
+
export declare function deleteISRCache(key: string): boolean;
|
|
6
|
+
export declare function setISRCache(key: string, entry: ISRCacheEntry): void;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Cache } from "./route-cache";
|
|
2
|
+
export type CacheInvalidator = Pick<Cache<unknown>, "invalidatePath" | "name">;
|
|
3
|
+
export declare function registerCacheInvalidator(invalidator: CacheInvalidator): () => void;
|
|
4
|
+
export declare function getCacheInvalidators(): IterableIterator<CacheInvalidator>;
|
|
5
|
+
export declare function clearCacheInvalidators(): void;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export type RevalidateType = "page" | "layout";
|
|
2
|
+
export interface CacheInvalidationResult {
|
|
3
|
+
deleted: boolean;
|
|
4
|
+
purgedPaths: string[];
|
|
5
|
+
}
|
|
6
|
+
export interface Cache<Entry> {
|
|
7
|
+
clear(): void;
|
|
8
|
+
delete(key: string): boolean;
|
|
9
|
+
entries(): IterableIterator<[string, Entry]>;
|
|
10
|
+
get(key: string): Entry | undefined;
|
|
11
|
+
has(key: string): boolean;
|
|
12
|
+
invalidatePath(path: string, type: RevalidateType): CacheInvalidationResult;
|
|
13
|
+
keys(): IterableIterator<string>;
|
|
14
|
+
readonly name: string;
|
|
15
|
+
set(key: string, entry: Entry): void;
|
|
16
|
+
get size(): number;
|
|
17
|
+
readonly store: Map<string, Entry>;
|
|
18
|
+
}
|
|
19
|
+
export interface RouteCacheOptions<Entry> {
|
|
20
|
+
maxSize?: number;
|
|
21
|
+
name: string;
|
|
22
|
+
onDelete?: (key: string, entry: Entry) => void;
|
|
23
|
+
onSet?: (key: string, entry: Entry, previous: Entry | undefined) => void;
|
|
24
|
+
pathFromKey?: (key: string) => string | null;
|
|
25
|
+
}
|
|
26
|
+
export declare function createRouteCache<Entry>(options: RouteCacheOptions<Entry>): Cache<Entry>;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type SsgCacheEntry } from "./isr-ssg";
|
|
2
|
+
export declare const ssgRouteCache: import("./route-cache").Cache<SsgCacheEntry>;
|
|
3
|
+
export declare const ssgCache: Map<string, SsgCacheEntry>;
|
|
4
|
+
export declare function getSSGCache(key: string): SsgCacheEntry | undefined;
|
|
5
|
+
export declare function setSSGCache(key: string, entry: SsgCacheEntry): void;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { RequestLogger } from "evlog";
|
|
2
|
+
import { createLogger } from "evlog";
|
|
3
|
+
export { createLogger };
|
|
4
|
+
/**
|
|
5
|
+
* Returns the current request-scoped logger.
|
|
6
|
+
*
|
|
7
|
+
* Priority:
|
|
8
|
+
* 1. Live Elysia request handled by the evlog() plugin → full request-scoped wide event
|
|
9
|
+
* 2. Synthetic render scope (ISR revalidation, SSG pre-render) → detached createLogger()
|
|
10
|
+
* that still drains to the configured adapter (Datadog, Axiom, etc.)
|
|
11
|
+
* 3. Completely outside any context → no-op
|
|
12
|
+
*
|
|
13
|
+
* Import from `@teyik0/furin` instead of `evlog/elysia` so this fallback chain
|
|
14
|
+
* applies in all rendering contexts.
|
|
15
|
+
*/
|
|
16
|
+
export declare function useLogger(): RequestLogger;
|
|
17
|
+
/**
|
|
18
|
+
* Runs `fn` inside a synthetic render scope.
|
|
19
|
+
*
|
|
20
|
+
* Creates a detached `createLogger()` instance for the duration of `fn`.
|
|
21
|
+
* `useLogger()` calls inside `fn` (including user loaders) return this logger
|
|
22
|
+
* instead of throwing. On completion, the accumulated wide event is emitted to
|
|
23
|
+
* the global drain with the provided initial context (e.g. route pattern).
|
|
24
|
+
*
|
|
25
|
+
* Used by renderForPath() which drives both ISR background revalidation and
|
|
26
|
+
* SSG pre-renders — neither has a live Elysia request context.
|
|
27
|
+
*/
|
|
28
|
+
export declare function runInSyntheticRenderScope<T>(fn: () => Promise<T> | T, initialContext: Record<string, unknown>): Promise<T>;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { Elysia } from "elysia";
|
|
2
|
+
/**
|
|
3
|
+
* Dev "Live ISR" inspector.
|
|
4
|
+
*
|
|
5
|
+
* Mounts read-only JSON endpoints that surface the active entries of the
|
|
6
|
+
* dev-mode loader caches. Designed to back a future browser DevTools panel:
|
|
7
|
+
* the JSON shape is stable and carries enough information for a UI to render
|
|
8
|
+
* a freshness-aware entry list with dependencies and a data preview.
|
|
9
|
+
*
|
|
10
|
+
* The plugin always registers the routes — caller is responsible for gating
|
|
11
|
+
* on `IS_DEV` to keep them out of production builds.
|
|
12
|
+
*/
|
|
13
|
+
/** Public response shape — keep stable for downstream UI consumers. */
|
|
14
|
+
export interface InspectorEntry {
|
|
15
|
+
/** Per-entry preview of the cached loader output. */
|
|
16
|
+
dataPreview: Record<string, unknown>;
|
|
17
|
+
/** Source files whose change drops this entry. */
|
|
18
|
+
dependencies: string[];
|
|
19
|
+
/** ms timestamp at which the entry was written. */
|
|
20
|
+
generatedAt: number;
|
|
21
|
+
/** True iff the entry is still within its `revalidate` window. */
|
|
22
|
+
isFresh: boolean;
|
|
23
|
+
/** Resolved cache key (the same path used by `revalidatePath`). */
|
|
24
|
+
key: string;
|
|
25
|
+
/** Cache origin — surfaced verbatim so a UI can group by mode. */
|
|
26
|
+
mode: "isr" | "ssg";
|
|
27
|
+
/** Revalidate window in seconds. SSG entries report `-1` for "indefinite". */
|
|
28
|
+
revalidate: number;
|
|
29
|
+
}
|
|
30
|
+
export declare function createDevInspectorPlugin(): Elysia<"", {
|
|
31
|
+
decorator: {};
|
|
32
|
+
store: {};
|
|
33
|
+
derive: {};
|
|
34
|
+
resolve: {};
|
|
35
|
+
}, {
|
|
36
|
+
typebox: {};
|
|
37
|
+
error: {};
|
|
38
|
+
}, {
|
|
39
|
+
schema: {};
|
|
40
|
+
standaloneSchema: {};
|
|
41
|
+
macro: {};
|
|
42
|
+
macroFn: {};
|
|
43
|
+
parser: {};
|
|
44
|
+
response: {};
|
|
45
|
+
}, {
|
|
46
|
+
__furin: {
|
|
47
|
+
_inspect: {
|
|
48
|
+
isr: {
|
|
49
|
+
get: {
|
|
50
|
+
body: unknown;
|
|
51
|
+
params: {};
|
|
52
|
+
query: unknown;
|
|
53
|
+
headers: unknown;
|
|
54
|
+
response: {
|
|
55
|
+
200: InspectorEntry[];
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
} & {
|
|
62
|
+
__furin: {
|
|
63
|
+
_inspect: {
|
|
64
|
+
ssg: {
|
|
65
|
+
get: {
|
|
66
|
+
body: unknown;
|
|
67
|
+
params: {};
|
|
68
|
+
query: unknown;
|
|
69
|
+
headers: unknown;
|
|
70
|
+
response: {
|
|
71
|
+
200: InspectorEntry[];
|
|
72
|
+
};
|
|
73
|
+
};
|
|
74
|
+
};
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
}, {
|
|
78
|
+
derive: {};
|
|
79
|
+
resolve: {};
|
|
80
|
+
schema: {};
|
|
81
|
+
standaloneSchema: {};
|
|
82
|
+
response: {};
|
|
83
|
+
}, {
|
|
84
|
+
derive: {};
|
|
85
|
+
resolve: {};
|
|
86
|
+
schema: {};
|
|
87
|
+
standaloneSchema: {};
|
|
88
|
+
response: {};
|
|
89
|
+
}>;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { SsgCacheEntry } from "./cache/index.ts";
|
|
1
2
|
export interface EmbeddedAppData {
|
|
2
3
|
assets: Record<string, string>;
|
|
3
4
|
template: string;
|
|
@@ -11,8 +12,23 @@ export interface CompileContext {
|
|
|
11
12
|
buildId?: string;
|
|
12
13
|
embedded?: EmbeddedAppData;
|
|
13
14
|
modules: Record<string, unknown>;
|
|
15
|
+
/** Root-level conventions discovered at compile time. */
|
|
16
|
+
rootConventions?: {
|
|
17
|
+
errorPath?: string;
|
|
18
|
+
notFoundPath?: string;
|
|
19
|
+
};
|
|
14
20
|
rootPath: string;
|
|
21
|
+
/** Per-route metadata including pre-computed segment boundaries. */
|
|
22
|
+
routeMetadata?: Record<string, {
|
|
23
|
+
segmentBoundaries: Array<{
|
|
24
|
+
depth: number;
|
|
25
|
+
path: string;
|
|
26
|
+
errorPath?: string;
|
|
27
|
+
notFoundPath?: string;
|
|
28
|
+
}>;
|
|
29
|
+
}>;
|
|
15
30
|
routes: CompileContextRoute[];
|
|
31
|
+
ssgCache?: Record<string, SsgCacheEntry>;
|
|
16
32
|
}
|
|
17
33
|
export declare function __setCompileContext(ctx: CompileContext): void;
|
|
18
34
|
export declare function getCompileContext(): CompileContext | null;
|