@teyik0/furin 0.1.0-alpha.11 → 0.1.0-alpha.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +251 -0
- package/dist/build/compile-entry.ts +129 -0
- package/dist/build/entry-template.ts +133 -0
- package/dist/build/index.js +453 -282
- package/dist/build/server-routes-entry.ts +55 -0
- package/dist/cli/index.js +457 -286
- package/dist/env.d.ts +50 -0
- package/dist/furin.js +402 -263
- package/dist/internal.js +17 -0
- package/dist/link.d.ts +5 -438
- package/dist/link.js +228 -137
- package/dist/plugin/index.js +9 -7
- package/dist/render/cache.d.ts +18 -5
- package/dist/render/dev-cache.d.ts +29 -0
- package/dist/render/index.ts +870 -0
- package/dist/render/route-cache.d.ts +26 -0
- package/dist/render/shell.ts +187 -0
- package/dist/router-provider.d.ts +467 -0
- package/dist/router.js +515 -368
- package/dist/router.ts +1034 -0
- package/dist/runtime-env.js +10 -0
- package/package.json +47 -17
- package/src/adapter/bun.ts +4 -1
- package/src/build/entry-template.ts +13 -6
- package/src/build/hydrate.ts +7 -5
- package/src/build/scan-server.ts +32 -3
- package/src/dev-page-plugin.ts +6 -0
- package/src/link.tsx +43 -1297
- package/src/plugin/transform-client.ts +10 -8
- package/src/render/cache.ts +77 -67
- package/src/render/dev-cache.ts +106 -15
- package/src/render/index.ts +4 -3
- package/src/render/route-cache.ts +124 -0
- package/src/router-provider.tsx +1428 -0
package/dist/build/index.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
// @bun
|
|
2
2
|
// src/build/index.ts
|
|
3
|
-
import { existsSync as
|
|
4
|
-
import { join as
|
|
3
|
+
import { existsSync as existsSync10, writeFileSync as writeFileSync8 } from "fs";
|
|
4
|
+
import { join as join11, relative as relative4, resolve as resolve3 } from "path";
|
|
5
5
|
|
|
6
6
|
// src/adapter/bun.ts
|
|
7
|
-
import { existsSync as
|
|
8
|
-
import { dirname as dirname2, join as
|
|
9
|
-
import { fileURLToPath } from "url";
|
|
7
|
+
import { existsSync as existsSync7, rmSync as rmSync2, writeFileSync as writeFileSync6 } from "fs";
|
|
8
|
+
import { dirname as dirname2, join as join8, resolve } from "path";
|
|
9
|
+
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
10
10
|
|
|
11
11
|
// src/build/client.ts
|
|
12
12
|
import { existsSync as existsSync4, mkdirSync as mkdirSync3, writeFileSync as writeFileSync3 } from "fs";
|
|
@@ -1150,7 +1150,7 @@ class MagicString {
|
|
|
1150
1150
|
}
|
|
1151
1151
|
|
|
1152
1152
|
// src/plugin/transform-client.ts
|
|
1153
|
-
import {
|
|
1153
|
+
import { parse } from "yuku-parser";
|
|
1154
1154
|
var bunTranspiler = new Bun.Transpiler({
|
|
1155
1155
|
loader: "tsx",
|
|
1156
1156
|
tsconfig: {
|
|
@@ -1301,9 +1301,10 @@ function removeUnusedSpecifiers(s, code, decl, refs) {
|
|
|
1301
1301
|
}
|
|
1302
1302
|
function deadCodeElimination(s) {
|
|
1303
1303
|
const code = s.toString();
|
|
1304
|
-
const { program,
|
|
1305
|
-
|
|
1306
|
-
|
|
1304
|
+
const { program, diagnostics } = parse(code, { sourceType: "module" });
|
|
1305
|
+
const firstError = diagnostics.find((d) => d.severity === "error");
|
|
1306
|
+
if (firstError) {
|
|
1307
|
+
console.error("[furin] DCE: failed to parse transformed output:", firstError.message);
|
|
1307
1308
|
return s;
|
|
1308
1309
|
}
|
|
1309
1310
|
const fresh = new MagicString(code);
|
|
@@ -1353,9 +1354,10 @@ function removeServerExports(s, source, program) {
|
|
|
1353
1354
|
}
|
|
1354
1355
|
function transformForClient(code, filename) {
|
|
1355
1356
|
const plainJs = bunTranspiler.transformSync(code);
|
|
1356
|
-
const { program,
|
|
1357
|
-
|
|
1358
|
-
|
|
1357
|
+
const { program, diagnostics } = parse(plainJs, { sourceType: "module" });
|
|
1358
|
+
const firstError = diagnostics.find((d) => d.severity === "error");
|
|
1359
|
+
if (firstError) {
|
|
1360
|
+
throw new Error(`Failed to parse ${filename}: ${firstError.message}`);
|
|
1359
1361
|
}
|
|
1360
1362
|
let s = new MagicString(plainJs);
|
|
1361
1363
|
const removedServerCode = removeServerExports(s, plainJs, program);
|
|
@@ -1598,10 +1600,15 @@ function generateHydrateEntry(routes, rootLayout, basePath) {
|
|
|
1598
1600
|
const conventionImportLines = [...conventionIdents.entries()].map(([filePath, ident]) => `import ${ident} from "${filePath.replace(/\\/g, "/")}";`).join(`
|
|
1599
1601
|
`);
|
|
1600
1602
|
const basePathLiteral = JSON.stringify(basePath);
|
|
1601
|
-
const pathnameExpr = basePath ? `(() => { const p = window.location.pathname; const b = ${basePathLiteral};
|
|
1603
|
+
const pathnameExpr = basePath ? `(() => { const p = window.location.pathname; const b = ${basePathLiteral}; const stripped = (p.startsWith(b) && (p.length === b.length || p[b.length] === "/")) ? p.slice(b.length) || "/" : p; return stripped === "/" ? "/" : stripped.replace(/\\/+$/, ""); })()` : `window.location.pathname.replace(/\\/+$/, "") || "/"`;
|
|
1602
1604
|
const logEndpoint = basePath ? `${JSON.stringify(basePath)} + "/_furin/ingest"` : `"/_furin/ingest"`;
|
|
1603
|
-
const
|
|
1604
|
-
|
|
1605
|
+
const routerProviderDefaults = `
|
|
1606
|
+
autoRefresh: true,
|
|
1607
|
+
basePath: ${basePathLiteral},
|
|
1608
|
+
defaultPreload: "intent",
|
|
1609
|
+
defaultPreloadDelay: 50,
|
|
1610
|
+
defaultPreloadStaleTime: 30000,
|
|
1611
|
+
prefetchCacheSize: 50,`;
|
|
1605
1612
|
const conventionImportsBlock = conventionImportLines ? `
|
|
1606
1613
|
${conventionImportLines}` : "";
|
|
1607
1614
|
return `import { hydrateRoot, createRoot } from "react-dom/client";
|
|
@@ -1650,7 +1657,7 @@ const rootEl = document.getElementById("root") as HTMLElement;
|
|
|
1650
1657
|
initialMatch: match,
|
|
1651
1658
|
initialData: loaderData,
|
|
1652
1659
|
initialDigest: loaderData.__furinError?.digest,
|
|
1653
|
-
initialNotFound: isNotFound ? (loaderData.__furinNotFound ?? loaderData) : undefined,${
|
|
1660
|
+
initialNotFound: isNotFound ? (loaderData.__furinNotFound ?? loaderData) : undefined,${routerProviderDefaults}
|
|
1654
1661
|
} as any);
|
|
1655
1662
|
} else if (loaderData.__furinStatus === 404) {
|
|
1656
1663
|
// Direct load to an unknown URL. The server sent the root not-found UI
|
|
@@ -1667,7 +1674,7 @@ const rootEl = document.getElementById("root") as HTMLElement;
|
|
|
1667
1674
|
initialMatch: null,
|
|
1668
1675
|
initialData: cleanData,
|
|
1669
1676
|
initialDigest: loaderData.__furinError?.digest,
|
|
1670
|
-
initialNotFound: loaderData.__furinNotFound ?? {},${
|
|
1677
|
+
initialNotFound: loaderData.__furinNotFound ?? {},${routerProviderDefaults}
|
|
1671
1678
|
} as any);
|
|
1672
1679
|
} else {
|
|
1673
1680
|
// No match and no 404 signal \u2014 either the client bundle is out of sync
|
|
@@ -1879,14 +1886,19 @@ ${transformed}`;
|
|
|
1879
1886
|
}
|
|
1880
1887
|
|
|
1881
1888
|
// src/build/compile-entry.ts
|
|
1882
|
-
import { existsSync as
|
|
1883
|
-
import { join as
|
|
1889
|
+
import { existsSync as existsSync6, writeFileSync as writeFileSync4 } from "fs";
|
|
1890
|
+
import { join as join6, relative as relative2 } from "path";
|
|
1884
1891
|
|
|
1885
1892
|
// src/build/entry-template.ts
|
|
1886
|
-
import {
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
var
|
|
1893
|
+
import { existsSync as existsSync5 } from "fs";
|
|
1894
|
+
import { dirname, join as join5 } from "path";
|
|
1895
|
+
import { fileURLToPath } from "url";
|
|
1896
|
+
var _pkgRoot = dirname(dirname(fileURLToPath(import.meta.resolve("@teyik0/furin"))));
|
|
1897
|
+
var _pkgSrcDirRaw = existsSync5(join5(_pkgRoot, "src", "furin.ts")) ? join5(_pkgRoot, "src") : join5(_pkgRoot, "dist");
|
|
1898
|
+
var _pkgSrcDir = _pkgSrcDirRaw.replace(/\\/g, "/");
|
|
1899
|
+
var _ext = _pkgSrcDir.endsWith("/src") ? ".ts" : ".js";
|
|
1900
|
+
var INTERNAL_MODULE_PATH = `${_pkgSrcDir}/internal${_ext}`;
|
|
1901
|
+
var RUNTIME_ENV_MODULE_PATH = `${_pkgSrcDir}/runtime-env${_ext}`;
|
|
1890
1902
|
function collectConventionPaths(rootConventions, routeMetadata) {
|
|
1891
1903
|
const paths = [];
|
|
1892
1904
|
if (rootConventions?.errorPath) {
|
|
@@ -1983,7 +1995,7 @@ function generateCompileEntry(options) {
|
|
|
1983
1995
|
const assetImports = [];
|
|
1984
1996
|
let embeddedBlock = [];
|
|
1985
1997
|
if (embed) {
|
|
1986
|
-
if (!
|
|
1998
|
+
if (!existsSync6(embed.clientDir)) {
|
|
1987
1999
|
throw new Error(`[furin] Client directory not found: ${embed.clientDir}. Run the client build first.`);
|
|
1988
2000
|
}
|
|
1989
2001
|
const clientFiles = collectFilesRecursive(embed.clientDir);
|
|
@@ -2003,9 +2015,9 @@ function generateCompileEntry(options) {
|
|
|
2003
2015
|
}
|
|
2004
2016
|
}
|
|
2005
2017
|
if (templateVarName === null) {
|
|
2006
|
-
throw new Error(`[furin] Embed mode requires a client index.html at ${
|
|
2018
|
+
throw new Error(`[furin] Embed mode requires a client index.html at ${join6(embed.clientDir, "index.html")}. Run the client build first.`);
|
|
2007
2019
|
}
|
|
2008
|
-
if (publicDir &&
|
|
2020
|
+
if (publicDir && existsSync6(publicDir)) {
|
|
2009
2021
|
const publicFiles = collectFilesRecursive(publicDir);
|
|
2010
2022
|
for (const file of publicFiles) {
|
|
2011
2023
|
const varName = `_asset${assetIndex++}`;
|
|
@@ -2036,14 +2048,14 @@ function generateCompileEntry(options) {
|
|
|
2036
2048
|
rootConventions,
|
|
2037
2049
|
routeMetadata
|
|
2038
2050
|
});
|
|
2039
|
-
const entryPath =
|
|
2051
|
+
const entryPath = join6(outDir, "_compile-entry.ts");
|
|
2040
2052
|
writeFileSync4(entryPath, source);
|
|
2041
2053
|
return entryPath;
|
|
2042
2054
|
}
|
|
2043
2055
|
|
|
2044
2056
|
// src/build/server-routes-entry.ts
|
|
2045
2057
|
import { writeFileSync as writeFileSync5 } from "fs";
|
|
2046
|
-
import { join as
|
|
2058
|
+
import { join as join7 } from "path";
|
|
2047
2059
|
function generateServerRoutesEntry(options) {
|
|
2048
2060
|
const { buildId, outDir, rootPath, routes, serverEntry, rootConventions, routeMetadata } = options;
|
|
2049
2061
|
ensureDir(outDir);
|
|
@@ -2056,13 +2068,14 @@ function generateServerRoutesEntry(options) {
|
|
|
2056
2068
|
rootConventions,
|
|
2057
2069
|
routeMetadata
|
|
2058
2070
|
});
|
|
2059
|
-
const entryPath =
|
|
2071
|
+
const entryPath = join7(outDir, "server.ts");
|
|
2060
2072
|
writeFileSync5(entryPath, source);
|
|
2061
2073
|
return entryPath;
|
|
2062
2074
|
}
|
|
2063
2075
|
|
|
2064
2076
|
// src/adapter/bun.ts
|
|
2065
|
-
var
|
|
2077
|
+
var _pkgRoot2 = dirname2(dirname2(fileURLToPath2(import.meta.resolve("@teyik0/furin"))));
|
|
2078
|
+
var _pkgSrcDir2 = existsSync7(join8(_pkgRoot2, "src", "furin.ts")) ? join8(_pkgRoot2, "src") : join8(_pkgRoot2, "dist");
|
|
2066
2079
|
var BUILD_ID_INPUT_PATHS = [
|
|
2067
2080
|
`${_pkgSrcDir2}/build/compile-entry.ts`,
|
|
2068
2081
|
`${_pkgSrcDir2}/build/entry-template.ts`,
|
|
@@ -2093,13 +2106,13 @@ async function createBuildFingerprint(entryChunk, cssChunks, routes, root, serve
|
|
|
2093
2106
|
}
|
|
2094
2107
|
}
|
|
2095
2108
|
for (const path of BUILD_ID_INPUT_PATHS) {
|
|
2096
|
-
if (!
|
|
2109
|
+
if (!existsSync7(path)) {
|
|
2097
2110
|
console.warn(`[furin] Warning: build fingerprint input "${toPosixPath(path)}" is missing \u2014 ` + "the generated build ID may not reflect all framework changes.");
|
|
2098
2111
|
}
|
|
2099
2112
|
fingerprintPaths.add(path);
|
|
2100
2113
|
}
|
|
2101
2114
|
const fileParts = await Promise.all([...fingerprintPaths].sort().map(async (path) => {
|
|
2102
|
-
const content =
|
|
2115
|
+
const content = existsSync7(path) ? await Bun.file(path).text() : "";
|
|
2103
2116
|
return `${toPosixPath(path)}:${content}`;
|
|
2104
2117
|
}));
|
|
2105
2118
|
const routeParts = routes.map((route) => JSON.stringify({ mode: route.mode, path: toPosixPath(route.path), pattern: route.pattern })).sort();
|
|
@@ -2143,18 +2156,18 @@ async function buildBunTarget(routes, rootDir, buildRoot, root, serverEntry, opt
|
|
|
2143
2156
|
const buildFingerprint = await createBuildFingerprint(entryChunk, cssChunks, routes, root, serverEntry);
|
|
2144
2157
|
const buildId = Bun.hash(buildFingerprint).toString(16).slice(0, 12);
|
|
2145
2158
|
targetManifest.buildId = buildId;
|
|
2146
|
-
const clientDir =
|
|
2147
|
-
writeFileSync6(
|
|
2159
|
+
const clientDir = join8(targetDir, "client");
|
|
2160
|
+
writeFileSync6(join8(clientDir, "index.html"), generateProdIndexHtml(entryChunk, cssChunks, buildId));
|
|
2148
2161
|
const routeManifest = routes.map((r) => ({ pattern: r.pattern, path: r.path, mode: r.mode }));
|
|
2149
|
-
const publicDir =
|
|
2150
|
-
const targetPublicDir = publicDir ?
|
|
2162
|
+
const publicDir = existsSync7(join8(rootDir, "public")) ? join8(rootDir, "public") : undefined;
|
|
2163
|
+
const targetPublicDir = publicDir ? join8(targetDir, "public") : undefined;
|
|
2151
2164
|
if (publicDir && targetPublicDir && options.compile !== "embed") {
|
|
2152
2165
|
copyDirRecursive(publicDir, targetPublicDir);
|
|
2153
2166
|
}
|
|
2154
2167
|
const { rootConventions, routeMetadata } = buildCompileMetadata(root, routes);
|
|
2155
2168
|
if (options.compile && serverEntry) {
|
|
2156
|
-
const clientDir2 =
|
|
2157
|
-
const outfile =
|
|
2169
|
+
const clientDir2 = join8(targetDir, "client");
|
|
2170
|
+
const outfile = join8(targetDir, "server");
|
|
2158
2171
|
const entryPath = generateCompileEntry({
|
|
2159
2172
|
buildId,
|
|
2160
2173
|
rootPath: root.path,
|
|
@@ -2175,7 +2188,7 @@ async function buildBunTarget(routes, rootDir, buildRoot, root, serverEntry, opt
|
|
|
2175
2188
|
plugins: options.plugins
|
|
2176
2189
|
});
|
|
2177
2190
|
console.log(`[furin] Server binary: ${outfile}`);
|
|
2178
|
-
targetManifest.serverPath = toPosixPath(
|
|
2191
|
+
targetManifest.serverPath = toPosixPath(join8(targetManifest.targetDir, "server"));
|
|
2179
2192
|
if (options.compile === "embed") {
|
|
2180
2193
|
rmSync2(clientDir2, { force: true, recursive: true });
|
|
2181
2194
|
targetManifest.clientDir = null;
|
|
@@ -2199,8 +2212,8 @@ async function buildBunTarget(routes, rootDir, buildRoot, root, serverEntry, opt
|
|
|
2199
2212
|
sourcemap: "linked",
|
|
2200
2213
|
plugins: options.plugins
|
|
2201
2214
|
});
|
|
2202
|
-
console.log(`[furin] Server bundle: ${toPosixPath(
|
|
2203
|
-
targetManifest.serverPath = toPosixPath(
|
|
2215
|
+
console.log(`[furin] Server bundle: ${toPosixPath(join8(targetManifest.targetDir, "server.js"))}`);
|
|
2216
|
+
targetManifest.serverPath = toPosixPath(join8(targetManifest.targetDir, "server.js"));
|
|
2204
2217
|
}
|
|
2205
2218
|
for (const file of [
|
|
2206
2219
|
"_compile-entry.ts",
|
|
@@ -2208,14 +2221,14 @@ async function buildBunTarget(routes, rootDir, buildRoot, root, serverEntry, opt
|
|
|
2208
2221
|
"server.ts",
|
|
2209
2222
|
"_hydrate.tsx"
|
|
2210
2223
|
]) {
|
|
2211
|
-
rmSync2(
|
|
2224
|
+
rmSync2(join8(targetDir, file), { force: true });
|
|
2212
2225
|
}
|
|
2213
2226
|
return targetManifest;
|
|
2214
2227
|
}
|
|
2215
2228
|
|
|
2216
2229
|
// src/adapter/static.ts
|
|
2217
|
-
import { cpSync as cpSync2, existsSync as
|
|
2218
|
-
import { dirname as dirname3, isAbsolute, join as
|
|
2230
|
+
import { cpSync as cpSync2, existsSync as existsSync8, rmSync as rmSync3, writeFileSync as writeFileSync7 } from "fs";
|
|
2231
|
+
import { dirname as dirname3, isAbsolute, join as join9, relative as relative3, resolve as resolve2, sep } from "path";
|
|
2219
2232
|
|
|
2220
2233
|
// src/render/assemble.ts
|
|
2221
2234
|
function resolvePath(pattern, params) {
|
|
@@ -2255,9 +2268,24 @@ function assembleHTML(template, headData, reactHtml, data) {
|
|
|
2255
2268
|
}
|
|
2256
2269
|
|
|
2257
2270
|
// src/render/index.ts
|
|
2258
|
-
import { createElement as
|
|
2271
|
+
import { createElement as createElement3 } from "react";
|
|
2259
2272
|
import { renderToReadableStream } from "react-dom/server";
|
|
2260
2273
|
|
|
2274
|
+
// src/not-found.ts
|
|
2275
|
+
var NOT_FOUND_BRAND = "FURIN_NOT_FOUND";
|
|
2276
|
+
|
|
2277
|
+
class FurinNotFoundError extends Error {
|
|
2278
|
+
__furinBrand = NOT_FOUND_BRAND;
|
|
2279
|
+
data;
|
|
2280
|
+
constructor(options) {
|
|
2281
|
+
super(options?.message ?? "");
|
|
2282
|
+
this.data = options?.data;
|
|
2283
|
+
}
|
|
2284
|
+
}
|
|
2285
|
+
function isNotFoundError(err) {
|
|
2286
|
+
return err instanceof FurinNotFoundError || typeof err === "object" && err !== null && err.__furinBrand === NOT_FOUND_BRAND;
|
|
2287
|
+
}
|
|
2288
|
+
|
|
2261
2289
|
// ../../node_modules/.bun/evlog@2.14.1+6b630eaba8c4f70c/node_modules/evlog/dist/utils.mjs
|
|
2262
2290
|
function formatDuration(ms) {
|
|
2263
2291
|
if (ms < 1000)
|
|
@@ -3163,15 +3191,16 @@ function finalizeAudit(event) {
|
|
|
3163
3191
|
return;
|
|
3164
3192
|
event.audit = decorateAudit(a, String(event.timestamp));
|
|
3165
3193
|
}
|
|
3166
|
-
// src/
|
|
3194
|
+
// src/router-provider.tsx
|
|
3167
3195
|
import {
|
|
3168
3196
|
createContext,
|
|
3169
|
-
createElement,
|
|
3170
|
-
useCallback,
|
|
3197
|
+
createElement as createElement2,
|
|
3198
|
+
useCallback as useCallback2,
|
|
3171
3199
|
useContext,
|
|
3172
|
-
useEffect,
|
|
3200
|
+
useEffect as useEffect2,
|
|
3201
|
+
useLayoutEffect,
|
|
3173
3202
|
useMemo,
|
|
3174
|
-
useRef,
|
|
3203
|
+
useRef as useRef2,
|
|
3175
3204
|
useState
|
|
3176
3205
|
} from "react";
|
|
3177
3206
|
|
|
@@ -3187,19 +3216,193 @@ function getPublicErrorMessage(error) {
|
|
|
3187
3216
|
return "Something went wrong";
|
|
3188
3217
|
}
|
|
3189
3218
|
|
|
3190
|
-
// src/
|
|
3191
|
-
|
|
3192
|
-
|
|
3193
|
-
|
|
3194
|
-
|
|
3195
|
-
|
|
3196
|
-
|
|
3197
|
-
|
|
3198
|
-
|
|
3199
|
-
|
|
3219
|
+
// src/link.tsx
|
|
3220
|
+
import { createElement, useCallback, useEffect, useRef } from "react";
|
|
3221
|
+
function computeLinkView({
|
|
3222
|
+
to,
|
|
3223
|
+
search,
|
|
3224
|
+
hash,
|
|
3225
|
+
children,
|
|
3226
|
+
activeProps,
|
|
3227
|
+
inactiveProps
|
|
3228
|
+
}, router) {
|
|
3229
|
+
const logicalHref = buildHref(to, search, hash);
|
|
3230
|
+
const logicalHrefWithoutHash = buildHref(to, search, undefined);
|
|
3231
|
+
const isAbsolute = logicalHref.startsWith("http://") || logicalHref.startsWith("https://") || logicalHref.startsWith("//");
|
|
3232
|
+
const href = isAbsolute ? logicalHref : router.basePath + logicalHref;
|
|
3233
|
+
const isActive = !isAbsolute && router.currentHref === normalizeHref(logicalHrefWithoutHash);
|
|
3234
|
+
const resolvedChildren = typeof children === "function" ? children({ isActive }) : children;
|
|
3235
|
+
const extraProps = {
|
|
3236
|
+
...inactiveProps && !isActive ? inactiveProps() : {},
|
|
3237
|
+
...activeProps ? activeProps({ isActive }) : {}
|
|
3238
|
+
};
|
|
3239
|
+
return { logicalHref, href, isActive, resolvedChildren, extraProps };
|
|
3200
3240
|
}
|
|
3201
|
-
function
|
|
3202
|
-
|
|
3241
|
+
function LinkInteractive({
|
|
3242
|
+
to,
|
|
3243
|
+
search,
|
|
3244
|
+
hash,
|
|
3245
|
+
preload,
|
|
3246
|
+
preloadDelay,
|
|
3247
|
+
preloadStaleTime,
|
|
3248
|
+
replace,
|
|
3249
|
+
disabled,
|
|
3250
|
+
resetScroll,
|
|
3251
|
+
activeProps,
|
|
3252
|
+
inactiveProps,
|
|
3253
|
+
onClick,
|
|
3254
|
+
onMouseEnter,
|
|
3255
|
+
onMouseLeave,
|
|
3256
|
+
onFocus,
|
|
3257
|
+
children,
|
|
3258
|
+
href: _href,
|
|
3259
|
+
...anchorProps
|
|
3260
|
+
}) {
|
|
3261
|
+
const router = useRouter();
|
|
3262
|
+
const anchorRef = useRef(null);
|
|
3263
|
+
const intentTimerRef = useRef(null);
|
|
3264
|
+
const { logicalHref, href, isActive, resolvedChildren, extraProps } = computeLinkView({ to, search, hash, children, activeProps, inactiveProps }, router);
|
|
3265
|
+
const effectivePreload = preload ?? router.defaultPreload;
|
|
3266
|
+
const effectiveDelay = preloadDelay ?? router.defaultPreloadDelay;
|
|
3267
|
+
const effectiveStaleTime = preloadStaleTime ?? router.defaultPreloadStaleTime;
|
|
3268
|
+
const triggerPrefetch = useCallback(() => {
|
|
3269
|
+
router.prefetch(logicalHref, { staleTime: effectiveStaleTime });
|
|
3270
|
+
}, [router, logicalHref, effectiveStaleTime]);
|
|
3271
|
+
useEffect(() => {
|
|
3272
|
+
if (effectivePreload === "render") {
|
|
3273
|
+
triggerPrefetch();
|
|
3274
|
+
}
|
|
3275
|
+
}, [effectivePreload, triggerPrefetch]);
|
|
3276
|
+
useEffect(() => {
|
|
3277
|
+
if (effectivePreload !== "viewport" || !anchorRef.current) {
|
|
3278
|
+
return;
|
|
3279
|
+
}
|
|
3280
|
+
const observer = new IntersectionObserver(([entry]) => {
|
|
3281
|
+
if (entry?.isIntersecting) {
|
|
3282
|
+
triggerPrefetch();
|
|
3283
|
+
observer.disconnect();
|
|
3284
|
+
}
|
|
3285
|
+
}, { rootMargin: "200px" });
|
|
3286
|
+
observer.observe(anchorRef.current);
|
|
3287
|
+
return () => observer.disconnect();
|
|
3288
|
+
}, [effectivePreload, triggerPrefetch]);
|
|
3289
|
+
useEffect(() => () => {
|
|
3290
|
+
if (intentTimerRef.current !== null) {
|
|
3291
|
+
clearTimeout(intentTimerRef.current);
|
|
3292
|
+
intentTimerRef.current = null;
|
|
3293
|
+
}
|
|
3294
|
+
}, []);
|
|
3295
|
+
const isInternal = (url) => {
|
|
3296
|
+
try {
|
|
3297
|
+
return new URL(url, window.location.origin).origin === window.location.origin;
|
|
3298
|
+
} catch {
|
|
3299
|
+
return false;
|
|
3300
|
+
}
|
|
3301
|
+
};
|
|
3302
|
+
const handleClick = (e) => {
|
|
3303
|
+
onClick?.(e);
|
|
3304
|
+
if (e.defaultPrevented) {
|
|
3305
|
+
return;
|
|
3306
|
+
}
|
|
3307
|
+
if (disabled) {
|
|
3308
|
+
e.preventDefault();
|
|
3309
|
+
return;
|
|
3310
|
+
}
|
|
3311
|
+
if (e.metaKey || e.ctrlKey || e.shiftKey || e.altKey) {
|
|
3312
|
+
return;
|
|
3313
|
+
}
|
|
3314
|
+
if (anchorProps.target && anchorProps.target !== "_self") {
|
|
3315
|
+
return;
|
|
3316
|
+
}
|
|
3317
|
+
if (!isInternal(href)) {
|
|
3318
|
+
return;
|
|
3319
|
+
}
|
|
3320
|
+
e.preventDefault();
|
|
3321
|
+
router.navigate(logicalHref, { replace, resetScroll: resetScroll ?? true });
|
|
3322
|
+
};
|
|
3323
|
+
const handleMouseEnter = (e) => {
|
|
3324
|
+
onMouseEnter?.(e);
|
|
3325
|
+
if (!disabled && effectivePreload === "intent" && isInternal(href)) {
|
|
3326
|
+
intentTimerRef.current = setTimeout(triggerPrefetch, effectiveDelay);
|
|
3327
|
+
}
|
|
3328
|
+
};
|
|
3329
|
+
const handleMouseLeave = (e) => {
|
|
3330
|
+
onMouseLeave?.(e);
|
|
3331
|
+
if (intentTimerRef.current !== null) {
|
|
3332
|
+
clearTimeout(intentTimerRef.current);
|
|
3333
|
+
intentTimerRef.current = null;
|
|
3334
|
+
}
|
|
3335
|
+
};
|
|
3336
|
+
const handleFocus = (e) => {
|
|
3337
|
+
onFocus?.(e);
|
|
3338
|
+
if (!disabled && effectivePreload === "intent" && isInternal(href)) {
|
|
3339
|
+
triggerPrefetch();
|
|
3340
|
+
}
|
|
3341
|
+
};
|
|
3342
|
+
return createElement("a", {
|
|
3343
|
+
ref: anchorRef,
|
|
3344
|
+
href,
|
|
3345
|
+
"data-furin-link": true,
|
|
3346
|
+
onClick: handleClick,
|
|
3347
|
+
onMouseEnter: handleMouseEnter,
|
|
3348
|
+
onMouseLeave: handleMouseLeave,
|
|
3349
|
+
onFocus: handleFocus,
|
|
3350
|
+
...isActive ? { "data-status": "active" } : {},
|
|
3351
|
+
...anchorProps,
|
|
3352
|
+
...extraProps,
|
|
3353
|
+
...disabled ? { "aria-disabled": true } : {}
|
|
3354
|
+
}, resolvedChildren);
|
|
3355
|
+
}
|
|
3356
|
+
var SSR_FALLBACK_ROUTER = {
|
|
3357
|
+
basePath: "",
|
|
3358
|
+
currentHref: "/",
|
|
3359
|
+
navigate: () => Promise.resolve(),
|
|
3360
|
+
prefetch: () => {},
|
|
3361
|
+
invalidatePrefetch: () => {},
|
|
3362
|
+
refresh: () => Promise.resolve(),
|
|
3363
|
+
isNavigating: false,
|
|
3364
|
+
defaultPreload: "intent",
|
|
3365
|
+
defaultPreloadDelay: 50,
|
|
3366
|
+
defaultPreloadStaleTime: 30000
|
|
3367
|
+
};
|
|
3368
|
+
function renderLinkElement(props, router) {
|
|
3369
|
+
const { href, isActive, resolvedChildren, extraProps } = computeLinkView(props, router);
|
|
3370
|
+
const {
|
|
3371
|
+
to: _to,
|
|
3372
|
+
search: _search,
|
|
3373
|
+
hash: _hash,
|
|
3374
|
+
children: _children,
|
|
3375
|
+
activeProps: _ap,
|
|
3376
|
+
inactiveProps: _ip,
|
|
3377
|
+
disabled,
|
|
3378
|
+
preload: _p,
|
|
3379
|
+
preloadDelay: _pd,
|
|
3380
|
+
preloadStaleTime: _ps,
|
|
3381
|
+
replace: _r,
|
|
3382
|
+
resetScroll: _rs,
|
|
3383
|
+
onClick: _oc,
|
|
3384
|
+
onMouseEnter: _ome,
|
|
3385
|
+
onMouseLeave: _oml,
|
|
3386
|
+
onFocus: _of,
|
|
3387
|
+
href: _href,
|
|
3388
|
+
...anchorProps
|
|
3389
|
+
} = props;
|
|
3390
|
+
return createElement("a", {
|
|
3391
|
+
href,
|
|
3392
|
+
"data-furin-link": true,
|
|
3393
|
+
...isActive ? { "data-status": "active" } : {},
|
|
3394
|
+
...anchorProps,
|
|
3395
|
+
...extraProps,
|
|
3396
|
+
...disabled ? { "aria-disabled": true } : {}
|
|
3397
|
+
}, resolvedChildren);
|
|
3398
|
+
}
|
|
3399
|
+
function Link(props) {
|
|
3400
|
+
if (typeof window === "undefined") {
|
|
3401
|
+
return createElement(RouterContext.Consumer, {
|
|
3402
|
+
children: (routerCtx) => renderLinkElement(props, routerCtx ?? SSR_FALLBACK_ROUTER)
|
|
3403
|
+
});
|
|
3404
|
+
}
|
|
3405
|
+
return createElement(LinkInteractive, props);
|
|
3203
3406
|
}
|
|
3204
3407
|
|
|
3205
3408
|
// src/render/default-screens.tsx
|
|
@@ -3587,7 +3790,7 @@ class FurinNotFoundBoundary extends Component {
|
|
|
3587
3790
|
}
|
|
3588
3791
|
}
|
|
3589
3792
|
|
|
3590
|
-
// src/
|
|
3793
|
+
// src/router-provider.tsx
|
|
3591
3794
|
import { jsxDEV as jsxDEV3 } from "react/jsx-dev-runtime";
|
|
3592
3795
|
function buildHref(to, search, hash) {
|
|
3593
3796
|
let url = to;
|
|
@@ -3610,7 +3813,8 @@ function buildHref(to, search, hash) {
|
|
|
3610
3813
|
}
|
|
3611
3814
|
var RouterContext = createContext(null);
|
|
3612
3815
|
function useRouter() {
|
|
3613
|
-
|
|
3816
|
+
const ctx = useContext(RouterContext);
|
|
3817
|
+
return ctx ?? {
|
|
3614
3818
|
basePath: "",
|
|
3615
3819
|
currentHref: "/",
|
|
3616
3820
|
navigate: (href) => {
|
|
@@ -3629,176 +3833,13 @@ function useRouter() {
|
|
|
3629
3833
|
defaultPreloadStaleTime: 30000
|
|
3630
3834
|
};
|
|
3631
3835
|
}
|
|
3632
|
-
function
|
|
3633
|
-
|
|
3634
|
-
|
|
3635
|
-
|
|
3636
|
-
|
|
3637
|
-
activeProps,
|
|
3638
|
-
inactiveProps
|
|
3639
|
-
}, router) {
|
|
3640
|
-
const logicalHref = buildHref(to, search, hash);
|
|
3641
|
-
const logicalHrefWithoutHash = buildHref(to, search, undefined);
|
|
3642
|
-
const href = router.basePath + logicalHref;
|
|
3643
|
-
const isActive = router.currentHref === logicalHrefWithoutHash;
|
|
3644
|
-
const resolvedChildren = typeof children === "function" ? children({ isActive }) : children;
|
|
3645
|
-
const extraProps = {
|
|
3646
|
-
...inactiveProps && !isActive ? inactiveProps() : {},
|
|
3647
|
-
...activeProps ? activeProps({ isActive }) : {}
|
|
3648
|
-
};
|
|
3649
|
-
return { logicalHref, href, isActive, resolvedChildren, extraProps };
|
|
3650
|
-
}
|
|
3651
|
-
function LinkInteractive({
|
|
3652
|
-
to,
|
|
3653
|
-
search,
|
|
3654
|
-
hash,
|
|
3655
|
-
preload,
|
|
3656
|
-
preloadDelay,
|
|
3657
|
-
preloadStaleTime,
|
|
3658
|
-
replace,
|
|
3659
|
-
disabled,
|
|
3660
|
-
resetScroll,
|
|
3661
|
-
activeProps,
|
|
3662
|
-
inactiveProps,
|
|
3663
|
-
onClick,
|
|
3664
|
-
onMouseEnter,
|
|
3665
|
-
onMouseLeave,
|
|
3666
|
-
onFocus,
|
|
3667
|
-
children,
|
|
3668
|
-
...anchorProps
|
|
3669
|
-
}) {
|
|
3670
|
-
const router = useRouter();
|
|
3671
|
-
const anchorRef = useRef(null);
|
|
3672
|
-
const intentTimerRef = useRef(null);
|
|
3673
|
-
const { logicalHref, href, isActive, resolvedChildren, extraProps } = computeLinkView({ to, search, hash, children, activeProps, inactiveProps }, router);
|
|
3674
|
-
const effectivePreload = preload ?? router.defaultPreload;
|
|
3675
|
-
const effectiveDelay = preloadDelay ?? router.defaultPreloadDelay;
|
|
3676
|
-
const effectiveStaleTime = preloadStaleTime ?? router.defaultPreloadStaleTime;
|
|
3677
|
-
const triggerPrefetch = useCallback(() => {
|
|
3678
|
-
router.prefetch(logicalHref, { staleTime: effectiveStaleTime });
|
|
3679
|
-
}, [router, logicalHref, effectiveStaleTime]);
|
|
3680
|
-
useEffect(() => {
|
|
3681
|
-
if (effectivePreload === "render") {
|
|
3682
|
-
triggerPrefetch();
|
|
3683
|
-
}
|
|
3684
|
-
}, [effectivePreload, triggerPrefetch]);
|
|
3685
|
-
useEffect(() => {
|
|
3686
|
-
if (effectivePreload !== "viewport" || !anchorRef.current) {
|
|
3687
|
-
return;
|
|
3688
|
-
}
|
|
3689
|
-
const observer = new IntersectionObserver(([entry]) => {
|
|
3690
|
-
if (entry?.isIntersecting) {
|
|
3691
|
-
triggerPrefetch();
|
|
3692
|
-
observer.disconnect();
|
|
3693
|
-
}
|
|
3694
|
-
}, { rootMargin: "200px" });
|
|
3695
|
-
observer.observe(anchorRef.current);
|
|
3696
|
-
return () => observer.disconnect();
|
|
3697
|
-
}, [effectivePreload, triggerPrefetch]);
|
|
3698
|
-
const isInternal = (url) => {
|
|
3699
|
-
try {
|
|
3700
|
-
return new URL(url, window.location.origin).origin === window.location.origin;
|
|
3701
|
-
} catch {
|
|
3702
|
-
return false;
|
|
3703
|
-
}
|
|
3704
|
-
};
|
|
3705
|
-
const handleClick = (e) => {
|
|
3706
|
-
onClick?.(e);
|
|
3707
|
-
if (e.defaultPrevented || disabled) {
|
|
3708
|
-
return;
|
|
3709
|
-
}
|
|
3710
|
-
if (e.metaKey || e.ctrlKey || e.shiftKey || e.altKey) {
|
|
3711
|
-
return;
|
|
3712
|
-
}
|
|
3713
|
-
if (anchorProps.target && anchorProps.target !== "_self") {
|
|
3714
|
-
return;
|
|
3715
|
-
}
|
|
3716
|
-
if (!isInternal(href)) {
|
|
3717
|
-
return;
|
|
3718
|
-
}
|
|
3719
|
-
e.preventDefault();
|
|
3720
|
-
router.navigate(logicalHref, { replace, resetScroll: resetScroll ?? true });
|
|
3721
|
-
};
|
|
3722
|
-
const handleMouseEnter = (e) => {
|
|
3723
|
-
onMouseEnter?.(e);
|
|
3724
|
-
if (!disabled && effectivePreload === "intent" && isInternal(href)) {
|
|
3725
|
-
intentTimerRef.current = setTimeout(triggerPrefetch, effectiveDelay);
|
|
3726
|
-
}
|
|
3727
|
-
};
|
|
3728
|
-
const handleMouseLeave = (e) => {
|
|
3729
|
-
onMouseLeave?.(e);
|
|
3730
|
-
if (intentTimerRef.current !== null) {
|
|
3731
|
-
clearTimeout(intentTimerRef.current);
|
|
3732
|
-
intentTimerRef.current = null;
|
|
3733
|
-
}
|
|
3734
|
-
};
|
|
3735
|
-
const handleFocus = (e) => {
|
|
3736
|
-
onFocus?.(e);
|
|
3737
|
-
if (!disabled && effectivePreload === "intent" && isInternal(href)) {
|
|
3738
|
-
triggerPrefetch();
|
|
3739
|
-
}
|
|
3740
|
-
};
|
|
3741
|
-
return createElement("a", {
|
|
3742
|
-
ref: anchorRef,
|
|
3743
|
-
href,
|
|
3744
|
-
onClick: handleClick,
|
|
3745
|
-
onMouseEnter: handleMouseEnter,
|
|
3746
|
-
onMouseLeave: handleMouseLeave,
|
|
3747
|
-
onFocus: handleFocus,
|
|
3748
|
-
...isActive ? { "data-status": "active" } : {},
|
|
3749
|
-
...anchorProps,
|
|
3750
|
-
...extraProps,
|
|
3751
|
-
...disabled ? { "aria-disabled": true } : {}
|
|
3752
|
-
}, resolvedChildren);
|
|
3753
|
-
}
|
|
3754
|
-
var SSR_FALLBACK_ROUTER = {
|
|
3755
|
-
basePath: "",
|
|
3756
|
-
currentHref: "/",
|
|
3757
|
-
navigate: () => Promise.resolve(),
|
|
3758
|
-
prefetch: () => {},
|
|
3759
|
-
invalidatePrefetch: () => {},
|
|
3760
|
-
refresh: () => Promise.resolve(),
|
|
3761
|
-
isNavigating: false,
|
|
3762
|
-
defaultPreload: "intent",
|
|
3763
|
-
defaultPreloadDelay: 50,
|
|
3764
|
-
defaultPreloadStaleTime: 30000
|
|
3765
|
-
};
|
|
3766
|
-
function renderLinkElement(props, router) {
|
|
3767
|
-
const { href, isActive, resolvedChildren, extraProps } = computeLinkView(props, router);
|
|
3768
|
-
const {
|
|
3769
|
-
to: _to,
|
|
3770
|
-
search: _search,
|
|
3771
|
-
hash: _hash,
|
|
3772
|
-
children: _children,
|
|
3773
|
-
activeProps: _ap,
|
|
3774
|
-
inactiveProps: _ip,
|
|
3775
|
-
disabled,
|
|
3776
|
-
preload: _p,
|
|
3777
|
-
preloadDelay: _pd,
|
|
3778
|
-
preloadStaleTime: _ps,
|
|
3779
|
-
replace: _r,
|
|
3780
|
-
resetScroll: _rs,
|
|
3781
|
-
onClick: _oc,
|
|
3782
|
-
onMouseEnter: _ome,
|
|
3783
|
-
onMouseLeave: _oml,
|
|
3784
|
-
onFocus: _of,
|
|
3785
|
-
...anchorProps
|
|
3786
|
-
} = props;
|
|
3787
|
-
return createElement("a", {
|
|
3788
|
-
href,
|
|
3789
|
-
...isActive ? { "data-status": "active" } : {},
|
|
3790
|
-
...anchorProps,
|
|
3791
|
-
...extraProps,
|
|
3792
|
-
...disabled ? { "aria-disabled": true } : {}
|
|
3793
|
-
}, resolvedChildren);
|
|
3794
|
-
}
|
|
3795
|
-
function Link(props) {
|
|
3796
|
-
if (typeof window === "undefined") {
|
|
3797
|
-
return createElement(RouterContext.Consumer, {
|
|
3798
|
-
children: (routerCtx) => renderLinkElement(props, routerCtx ?? SSR_FALLBACK_ROUTER)
|
|
3799
|
-
});
|
|
3836
|
+
function normalizeHref(href) {
|
|
3837
|
+
const url = new URL(href, "http://localhost");
|
|
3838
|
+
let pathname = url.pathname;
|
|
3839
|
+
if (pathname !== "/") {
|
|
3840
|
+
pathname = pathname.replace(/\/+$/g, "");
|
|
3800
3841
|
}
|
|
3801
|
-
return
|
|
3842
|
+
return pathname + url.search + url.hash;
|
|
3802
3843
|
}
|
|
3803
3844
|
|
|
3804
3845
|
// src/render/cache.ts
|
|
@@ -3850,33 +3891,139 @@ async function runInSyntheticRenderScope(fn, initialContext) {
|
|
|
3850
3891
|
}
|
|
3851
3892
|
}
|
|
3852
3893
|
|
|
3853
|
-
// src/render/cache.ts
|
|
3854
|
-
|
|
3855
|
-
|
|
3856
|
-
|
|
3857
|
-
function
|
|
3858
|
-
if (
|
|
3859
|
-
|
|
3894
|
+
// src/render/route-cache.ts
|
|
3895
|
+
function defaultPathFromKey(key) {
|
|
3896
|
+
return key;
|
|
3897
|
+
}
|
|
3898
|
+
function matchesPath(urlPath, path, type) {
|
|
3899
|
+
if (type === "page") {
|
|
3900
|
+
return urlPath === path;
|
|
3901
|
+
}
|
|
3902
|
+
const prefix = path === "/" || path.endsWith("/") ? path : `${path}/`;
|
|
3903
|
+
return urlPath === path || urlPath.startsWith(prefix);
|
|
3904
|
+
}
|
|
3905
|
+
function createRouteCache(options) {
|
|
3906
|
+
const store = new Map;
|
|
3907
|
+
const pathFromKey = options.pathFromKey ?? defaultPathFromKey;
|
|
3908
|
+
const evictOldest = () => {
|
|
3909
|
+
if (options.maxSize === undefined || store.size <= options.maxSize) {
|
|
3910
|
+
return;
|
|
3911
|
+
}
|
|
3912
|
+
const oldest = store.keys().next().value;
|
|
3860
3913
|
if (oldest !== undefined) {
|
|
3861
|
-
|
|
3914
|
+
deleteEntry(oldest);
|
|
3862
3915
|
}
|
|
3863
|
-
}
|
|
3916
|
+
};
|
|
3917
|
+
const deleteEntry = (key) => {
|
|
3918
|
+
const entry = store.get(key);
|
|
3919
|
+
if (entry === undefined) {
|
|
3920
|
+
return false;
|
|
3921
|
+
}
|
|
3922
|
+
store.delete(key);
|
|
3923
|
+
options.onDelete?.(key, entry);
|
|
3924
|
+
return true;
|
|
3925
|
+
};
|
|
3926
|
+
return {
|
|
3927
|
+
name: options.name,
|
|
3928
|
+
store,
|
|
3929
|
+
get size() {
|
|
3930
|
+
return store.size;
|
|
3931
|
+
},
|
|
3932
|
+
get(key) {
|
|
3933
|
+
const entry = store.get(key);
|
|
3934
|
+
if (entry !== undefined && options.maxSize !== undefined) {
|
|
3935
|
+
store.delete(key);
|
|
3936
|
+
store.set(key, entry);
|
|
3937
|
+
}
|
|
3938
|
+
return entry;
|
|
3939
|
+
},
|
|
3940
|
+
set(key, entry) {
|
|
3941
|
+
const previous = store.get(key);
|
|
3942
|
+
if (previous !== undefined) {
|
|
3943
|
+
store.delete(key);
|
|
3944
|
+
}
|
|
3945
|
+
store.set(key, entry);
|
|
3946
|
+
options.onSet?.(key, entry, previous);
|
|
3947
|
+
evictOldest();
|
|
3948
|
+
},
|
|
3949
|
+
delete(key) {
|
|
3950
|
+
return deleteEntry(key);
|
|
3951
|
+
},
|
|
3952
|
+
clear() {
|
|
3953
|
+
for (const key of [...store.keys()]) {
|
|
3954
|
+
deleteEntry(key);
|
|
3955
|
+
}
|
|
3956
|
+
store.clear();
|
|
3957
|
+
},
|
|
3958
|
+
has(key) {
|
|
3959
|
+
return store.has(key);
|
|
3960
|
+
},
|
|
3961
|
+
entries() {
|
|
3962
|
+
return store.entries();
|
|
3963
|
+
},
|
|
3964
|
+
keys() {
|
|
3965
|
+
return store.keys();
|
|
3966
|
+
},
|
|
3967
|
+
invalidatePath(path, type) {
|
|
3968
|
+
let deleted = false;
|
|
3969
|
+
const purgedPaths = [];
|
|
3970
|
+
for (const key of [...store.keys()]) {
|
|
3971
|
+
const urlPath = pathFromKey(key);
|
|
3972
|
+
if (urlPath === null || !matchesPath(urlPath, path, type)) {
|
|
3973
|
+
continue;
|
|
3974
|
+
}
|
|
3975
|
+
deleteEntry(key);
|
|
3976
|
+
deleted = true;
|
|
3977
|
+
purgedPaths.push(urlPath);
|
|
3978
|
+
}
|
|
3979
|
+
return { deleted, purgedPaths: [...new Set(purgedPaths)] };
|
|
3980
|
+
}
|
|
3981
|
+
};
|
|
3864
3982
|
}
|
|
3983
|
+
|
|
3984
|
+
// src/render/cache.ts
|
|
3985
|
+
var MAX_ISR_CACHE_SIZE = 1000;
|
|
3986
|
+
var MAX_SSG_CACHE_SIZE = 1000;
|
|
3987
|
+
var isrRouteCache = createRouteCache({
|
|
3988
|
+
maxSize: MAX_ISR_CACHE_SIZE,
|
|
3989
|
+
name: "render:isr-html"
|
|
3990
|
+
});
|
|
3991
|
+
var ssgRouteCache = createRouteCache({
|
|
3992
|
+
maxSize: MAX_SSG_CACHE_SIZE,
|
|
3993
|
+
name: "render:ssg-html"
|
|
3994
|
+
});
|
|
3995
|
+
var isrCache = isrRouteCache.store;
|
|
3996
|
+
var ssgCache = ssgRouteCache.store;
|
|
3865
3997
|
function getSSGCache(key) {
|
|
3866
|
-
|
|
3867
|
-
if (entry !== undefined) {
|
|
3868
|
-
ssgCache.delete(key);
|
|
3869
|
-
ssgCache.set(key, entry);
|
|
3870
|
-
}
|
|
3871
|
-
return entry;
|
|
3998
|
+
return ssgRouteCache.get(key);
|
|
3872
3999
|
}
|
|
3873
4000
|
function setSSGCache(key, entry) {
|
|
3874
|
-
|
|
3875
|
-
ssgCache.set(key, entry);
|
|
3876
|
-
evictOldest(ssgCache, MAX_SSG_CACHE_SIZE);
|
|
4001
|
+
ssgRouteCache.set(key, entry);
|
|
3877
4002
|
}
|
|
3878
4003
|
var _requestInvalidationScope = new AsyncLocalStorage3;
|
|
3879
4004
|
var _globalPendingInvalidations = new Set;
|
|
4005
|
+
var _cacheInvalidators = new Map;
|
|
4006
|
+
function registerCacheInvalidator(invalidator) {
|
|
4007
|
+
const existing = _cacheInvalidators.get(invalidator.name);
|
|
4008
|
+
if (existing !== undefined && existing !== invalidator) {
|
|
4009
|
+
throw new Error(`Cache invalidator "${invalidator.name}" is already registered with a different instance.`);
|
|
4010
|
+
}
|
|
4011
|
+
if (existing === invalidator) {
|
|
4012
|
+
return () => {
|
|
4013
|
+
if (_cacheInvalidators.get(invalidator.name) === invalidator) {
|
|
4014
|
+
_cacheInvalidators.delete(invalidator.name);
|
|
4015
|
+
}
|
|
4016
|
+
};
|
|
4017
|
+
}
|
|
4018
|
+
_cacheInvalidators.set(invalidator.name, invalidator);
|
|
4019
|
+
return () => {
|
|
4020
|
+
if (_cacheInvalidators.get(invalidator.name) === invalidator) {
|
|
4021
|
+
_cacheInvalidators.delete(invalidator.name);
|
|
4022
|
+
}
|
|
4023
|
+
};
|
|
4024
|
+
}
|
|
4025
|
+
registerCacheInvalidator(isrRouteCache);
|
|
4026
|
+
registerCacheInvalidator(ssgRouteCache);
|
|
3880
4027
|
|
|
3881
4028
|
// src/render/element.tsx
|
|
3882
4029
|
import { jsxDEV as jsxDEV4 } from "react/jsx-dev-runtime";
|
|
@@ -4061,12 +4208,13 @@ function getProductionTemplate() {
|
|
|
4061
4208
|
return null;
|
|
4062
4209
|
}
|
|
4063
4210
|
}
|
|
4211
|
+
|
|
4064
4212
|
// src/runtime-env.ts
|
|
4065
4213
|
var IS_DEV = true;
|
|
4066
4214
|
|
|
4067
4215
|
// src/render/index.ts
|
|
4068
4216
|
function withSSRRouterContext(element, contextValue) {
|
|
4069
|
-
return
|
|
4217
|
+
return createElement3(RouterContext.Provider, { value: contextValue }, element);
|
|
4070
4218
|
}
|
|
4071
4219
|
async function prepareRender(route, ctx, root, basePath, throwOnFailure, precomputedLoaderResult) {
|
|
4072
4220
|
const loaderStart = Date.now();
|
|
@@ -4109,7 +4257,7 @@ async function prepareRender(route, ctx, root, basePath, throwOnFailure, precomp
|
|
|
4109
4257
|
}
|
|
4110
4258
|
const ssrContext = {
|
|
4111
4259
|
basePath: basePath ?? "",
|
|
4112
|
-
currentHref: ctx.path,
|
|
4260
|
+
currentHref: normalizeHref(ctx.path),
|
|
4113
4261
|
navigate: () => Promise.resolve(),
|
|
4114
4262
|
prefetch: () => {},
|
|
4115
4263
|
invalidatePrefetch: () => {},
|
|
@@ -4194,7 +4342,7 @@ var TRAILING_SLASHES_RE = /\/+$/;
|
|
|
4194
4342
|
function pathToOutputFile(urlPath, outDir) {
|
|
4195
4343
|
const normalizedOutDir = resolve2(outDir);
|
|
4196
4344
|
if (urlPath === "/" || urlPath === "") {
|
|
4197
|
-
return
|
|
4345
|
+
return join9(normalizedOutDir, "index.html");
|
|
4198
4346
|
}
|
|
4199
4347
|
const resolved = resolve2(normalizedOutDir, urlPath.slice(1), "index.html");
|
|
4200
4348
|
if (!resolved.startsWith(`${normalizedOutDir}${sep}`)) {
|
|
@@ -4306,7 +4454,7 @@ async function buildStaticTarget(routes, rootDir, buildRoot, root, options) {
|
|
|
4306
4454
|
const ssgRoutes = collectSsgRoutes(routes, onSSR, skippedRoutes);
|
|
4307
4455
|
rmSync3(outDir, { force: true, recursive: true });
|
|
4308
4456
|
ensureDir(outDir);
|
|
4309
|
-
const targetDir =
|
|
4457
|
+
const targetDir = join9(buildRoot, "static");
|
|
4310
4458
|
rmSync3(targetDir, { force: true, recursive: true });
|
|
4311
4459
|
ensureDir(targetDir);
|
|
4312
4460
|
const { entryChunk, cssChunks } = await buildClient(ssgRoutes, {
|
|
@@ -4316,17 +4464,17 @@ async function buildStaticTarget(routes, rootDir, buildRoot, root, options) {
|
|
|
4316
4464
|
publicPath,
|
|
4317
4465
|
basePath
|
|
4318
4466
|
});
|
|
4319
|
-
const publicFavicon =
|
|
4320
|
-
const faviconHref =
|
|
4467
|
+
const publicFavicon = join9(rootDir, "public", "favicon.ico");
|
|
4468
|
+
const faviconHref = existsSync8(publicFavicon) ? `${basePath}/favicon.ico` : undefined;
|
|
4321
4469
|
const shellHtml = generateProdIndexHtml(entryChunk, cssChunks, undefined, faviconHref);
|
|
4322
4470
|
setProductionTemplateContent(shellHtml);
|
|
4323
|
-
const publicSrcDir =
|
|
4324
|
-
if (
|
|
4471
|
+
const publicSrcDir = join9(rootDir, "public");
|
|
4472
|
+
if (existsSync8(publicSrcDir)) {
|
|
4325
4473
|
cpSync2(publicSrcDir, outDir, { recursive: true });
|
|
4326
4474
|
}
|
|
4327
|
-
const clientSrcDir =
|
|
4328
|
-
if (
|
|
4329
|
-
cpSync2(clientSrcDir,
|
|
4475
|
+
const clientSrcDir = join9(targetDir, "client");
|
|
4476
|
+
if (existsSync8(clientSrcDir)) {
|
|
4477
|
+
cpSync2(clientSrcDir, join9(outDir, "_client"), { recursive: true });
|
|
4330
4478
|
}
|
|
4331
4479
|
const tasks = await buildTaskQueue(ssgRoutes, root, outDir, renderedRoutes, skippedRoutes, basePath);
|
|
4332
4480
|
const afterQueueCount = skippedRoutes.length;
|
|
@@ -4339,7 +4487,7 @@ async function buildStaticTarget(routes, rootDir, buildRoot, root, options) {
|
|
|
4339
4487
|
${list}
|
|
4340
4488
|
` + `Set \`onSSR: "skip"\` in your static config to suppress this error.`);
|
|
4341
4489
|
}
|
|
4342
|
-
writeFileSync7(
|
|
4490
|
+
writeFileSync7(join9(outDir, "404.html"), shellHtml);
|
|
4343
4491
|
console.log("[furin] static: wrote 404.html (SPA shell fallback)");
|
|
4344
4492
|
rmSync3(targetDir, { force: true, recursive: true });
|
|
4345
4493
|
console.log(`[furin] static: export complete \u2192 ${toPosixPath(outDir)}` + ` (${renderedRoutes.length} rendered, ${skippedRoutes.length} skipped)`);
|
|
@@ -4373,9 +4521,9 @@ var configSchema = t.Object({
|
|
|
4373
4521
|
});
|
|
4374
4522
|
|
|
4375
4523
|
// src/router.ts
|
|
4376
|
-
import { existsSync as
|
|
4524
|
+
import { existsSync as existsSync9 } from "fs";
|
|
4377
4525
|
import { readdir } from "fs/promises";
|
|
4378
|
-
import { join as
|
|
4526
|
+
import { join as join10, parse as parse2 } from "path";
|
|
4379
4527
|
import { Elysia as Elysia2, t as t2 } from "elysia";
|
|
4380
4528
|
|
|
4381
4529
|
// src/internal.ts
|
|
@@ -4384,11 +4532,6 @@ function getCompileContext() {
|
|
|
4384
4532
|
return _compileCtx;
|
|
4385
4533
|
}
|
|
4386
4534
|
|
|
4387
|
-
// src/render/dev-cache.ts
|
|
4388
|
-
var devISRLoaderCache = new Map;
|
|
4389
|
-
var devSSGLoaderCache = new Map;
|
|
4390
|
-
var sourceFileToCacheKeys = new Map;
|
|
4391
|
-
|
|
4392
4535
|
// src/utils.ts
|
|
4393
4536
|
function isFurinPage(value) {
|
|
4394
4537
|
return typeof value === "object" && value !== null && "__type" in value && value.__type === "FURIN_PAGE";
|
|
@@ -4439,7 +4582,7 @@ async function scanPages(pagesDir) {
|
|
|
4439
4582
|
async function scanRootLayout(pagesDir) {
|
|
4440
4583
|
const rootPath = `${pagesDir}/root.tsx`;
|
|
4441
4584
|
const ctx = getCompileContext();
|
|
4442
|
-
if (!(
|
|
4585
|
+
if (!(existsSync9(rootPath) || ctx?.modules[rootPath])) {
|
|
4443
4586
|
throw new Error("[furin] root.tsx: not found.");
|
|
4444
4587
|
}
|
|
4445
4588
|
const mod = ctx?.modules[rootPath] ?? await import(rootPath);
|
|
@@ -4472,7 +4615,7 @@ function getSourceModuleCandidates(dir, name) {
|
|
|
4472
4615
|
async function loadConventionComponent(dir, name) {
|
|
4473
4616
|
const ctx = getCompileContext();
|
|
4474
4617
|
for (const filePath of getSourceModuleCandidates(dir, name)) {
|
|
4475
|
-
if (
|
|
4618
|
+
if (existsSync9(filePath) || ctx?.modules[filePath]) {
|
|
4476
4619
|
const mod = ctx?.modules[filePath] ?? await import(filePath);
|
|
4477
4620
|
if (mod.default) {
|
|
4478
4621
|
return { component: mod.default, path: filePath };
|
|
@@ -4490,7 +4633,7 @@ async function scanPageFiles(pagesDir, root) {
|
|
|
4490
4633
|
continue;
|
|
4491
4634
|
}
|
|
4492
4635
|
const relativePath = absolutePath.replace(`${pagesDir}/`, "");
|
|
4493
|
-
const fileName =
|
|
4636
|
+
const fileName = parse2(relativePath).name;
|
|
4494
4637
|
if (fileName.startsWith("_") || fileName === "root" || isConventionFileName(fileName)) {
|
|
4495
4638
|
continue;
|
|
4496
4639
|
}
|
|
@@ -4609,7 +4752,7 @@ async function collectPageFilePaths(dir) {
|
|
|
4609
4752
|
const files = [];
|
|
4610
4753
|
const entries = (await readdir(dir, { withFileTypes: true })).sort((a, b) => a.name.localeCompare(b.name));
|
|
4611
4754
|
for (const entry of entries) {
|
|
4612
|
-
const absolutePath =
|
|
4755
|
+
const absolutePath = join10(dir, entry.name);
|
|
4613
4756
|
if (entry.isDirectory()) {
|
|
4614
4757
|
files.push(...await collectPageFilePaths(absolutePath));
|
|
4615
4758
|
continue;
|
|
@@ -4640,7 +4783,7 @@ function filePathToPattern(path) {
|
|
|
4640
4783
|
const parts = path.replaceAll("\\", "/").split("/");
|
|
4641
4784
|
const segments = [];
|
|
4642
4785
|
for (const part of parts) {
|
|
4643
|
-
const name =
|
|
4786
|
+
const name = parse2(part).name;
|
|
4644
4787
|
if (name === "index") {
|
|
4645
4788
|
continue;
|
|
4646
4789
|
}
|
|
@@ -4660,11 +4803,39 @@ function filePathToPattern(path) {
|
|
|
4660
4803
|
|
|
4661
4804
|
// src/build/scan-server.ts
|
|
4662
4805
|
import { readFileSync as readFileSync4 } from "fs";
|
|
4663
|
-
import {
|
|
4806
|
+
import { parse as parse3 } from "yuku-parser";
|
|
4807
|
+
function detectLangFromPath(filePath) {
|
|
4808
|
+
if (filePath.endsWith(".d.ts")) {
|
|
4809
|
+
return "dts";
|
|
4810
|
+
}
|
|
4811
|
+
const ext = filePath.split(".").pop()?.toLowerCase();
|
|
4812
|
+
switch (ext) {
|
|
4813
|
+
case "ts":
|
|
4814
|
+
return "ts";
|
|
4815
|
+
case "tsx":
|
|
4816
|
+
return "tsx";
|
|
4817
|
+
case "jsx":
|
|
4818
|
+
return "jsx";
|
|
4819
|
+
default:
|
|
4820
|
+
return "js";
|
|
4821
|
+
}
|
|
4822
|
+
}
|
|
4664
4823
|
function scanFurinInstances(serverEntryPath) {
|
|
4665
4824
|
const code = readFileSync4(serverEntryPath, "utf8");
|
|
4666
|
-
|
|
4667
|
-
if (
|
|
4825
|
+
let lang = detectLangFromPath(serverEntryPath);
|
|
4826
|
+
if (lang === "dts") {
|
|
4827
|
+
return [];
|
|
4828
|
+
}
|
|
4829
|
+
let parseInput = code;
|
|
4830
|
+
if (lang === "ts" || lang === "tsx") {
|
|
4831
|
+
const transpiler = new Bun.Transpiler({ loader: lang });
|
|
4832
|
+
parseInput = transpiler.transformSync(code);
|
|
4833
|
+
lang = "js";
|
|
4834
|
+
}
|
|
4835
|
+
const { program, diagnostics } = parse3(parseInput, { sourceType: "module", lang });
|
|
4836
|
+
const firstError = diagnostics.find((d) => d.severity === "error");
|
|
4837
|
+
if (firstError) {
|
|
4838
|
+
console.error("[furin] scan-server: parse error:", firstError.message, "in", serverEntryPath);
|
|
4668
4839
|
return [];
|
|
4669
4840
|
}
|
|
4670
4841
|
const results = [];
|
|
@@ -4752,19 +4923,19 @@ function resolvePagesDirFromServer(serverEntry, rootDir) {
|
|
|
4752
4923
|
}
|
|
4753
4924
|
async function buildApp(options) {
|
|
4754
4925
|
const rootDir = resolve3(options.rootDir ?? process.cwd());
|
|
4755
|
-
const buildRoot =
|
|
4926
|
+
const buildRoot = join11(rootDir, BUILD_OUTPUT_DIR);
|
|
4756
4927
|
const serverEntry = (() => {
|
|
4757
4928
|
if (options.target === "static") {
|
|
4758
4929
|
return null;
|
|
4759
4930
|
}
|
|
4760
4931
|
if (options.serverEntry) {
|
|
4761
4932
|
const resolved = resolve3(rootDir, options.serverEntry);
|
|
4762
|
-
if (
|
|
4933
|
+
if (existsSync10(resolved)) {
|
|
4763
4934
|
return resolved;
|
|
4764
4935
|
}
|
|
4765
4936
|
}
|
|
4766
4937
|
const entry = resolve3(rootDir, "src/server.ts");
|
|
4767
|
-
if (!
|
|
4938
|
+
if (!existsSync10(entry)) {
|
|
4768
4939
|
throw new Error("[furin] Entrypoint server.ts not found");
|
|
4769
4940
|
}
|
|
4770
4941
|
return entry;
|
|
@@ -4816,7 +4987,7 @@ async function buildApp(options) {
|
|
|
4816
4987
|
throw new Error(`[furin] Unsupported build target "${target}"`);
|
|
4817
4988
|
}
|
|
4818
4989
|
}
|
|
4819
|
-
writeFileSync8(
|
|
4990
|
+
writeFileSync8(join11(buildRoot, "manifest.json"), `${JSON.stringify(manifest, null, 2)}
|
|
4820
4991
|
`);
|
|
4821
4992
|
return {
|
|
4822
4993
|
manifest,
|