@teyik0/furin 0.1.0-alpha.12 → 0.1.0-alpha.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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 +110 -116
- package/dist/build/server-routes-entry.ts +55 -0
- package/dist/cli/index.js +114 -120
- package/dist/env.d.ts +50 -0
- package/dist/furin.js +11 -7
- package/dist/internal.js +17 -0
- package/dist/link.js +9 -7
- package/dist/plugin/index.js +9 -7
- package/dist/render/index.ts +870 -0
- package/dist/render/shell.ts +187 -0
- package/dist/router-provider.d.ts +2 -1
- package/dist/router.js +10 -2
- package/dist/router.ts +1034 -0
- package/dist/runtime-env.js +10 -0
- package/package.json +42 -13
- package/src/adapter/bun.ts +4 -1
- package/src/build/entry-template.ts +13 -6
- package/src/build/scan-server.ts +32 -3
- package/src/link.tsx +2 -1
- package/src/plugin/transform-client.ts +10 -8
- package/src/render/index.ts +4 -3
- package/src/router-provider.tsx +10 -8
package/dist/cli/index.js
CHANGED
|
@@ -2,18 +2,18 @@
|
|
|
2
2
|
// @bun
|
|
3
3
|
|
|
4
4
|
// src/cli/index.ts
|
|
5
|
-
import { existsSync as
|
|
5
|
+
import { existsSync as existsSync10 } from "fs";
|
|
6
6
|
import { resolve as resolve5 } from "path";
|
|
7
7
|
import { parseArgs } from "util";
|
|
8
8
|
|
|
9
9
|
// src/build/index.ts
|
|
10
|
-
import { existsSync as
|
|
11
|
-
import { join as
|
|
10
|
+
import { existsSync as existsSync8, writeFileSync as writeFileSync6 } from "fs";
|
|
11
|
+
import { join as join9, relative as relative4, resolve as resolve3 } from "path";
|
|
12
12
|
|
|
13
13
|
// src/adapter/bun.ts
|
|
14
|
-
import { existsSync as
|
|
15
|
-
import { dirname as dirname2, join as
|
|
16
|
-
import { fileURLToPath } from "url";
|
|
14
|
+
import { existsSync as existsSync5, rmSync as rmSync2, writeFileSync as writeFileSync4 } from "fs";
|
|
15
|
+
import { dirname as dirname2, join as join6, resolve } from "path";
|
|
16
|
+
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
17
17
|
|
|
18
18
|
// src/build/client.ts
|
|
19
19
|
import { existsSync as existsSync2, mkdirSync as mkdirSync2, writeFileSync } from "fs";
|
|
@@ -1157,7 +1157,7 @@ class MagicString {
|
|
|
1157
1157
|
}
|
|
1158
1158
|
|
|
1159
1159
|
// src/plugin/transform-client.ts
|
|
1160
|
-
import {
|
|
1160
|
+
import { parse } from "yuku-parser";
|
|
1161
1161
|
var bunTranspiler = new Bun.Transpiler({
|
|
1162
1162
|
loader: "tsx",
|
|
1163
1163
|
tsconfig: {
|
|
@@ -1308,9 +1308,10 @@ function removeUnusedSpecifiers(s, code, decl, refs) {
|
|
|
1308
1308
|
}
|
|
1309
1309
|
function deadCodeElimination(s) {
|
|
1310
1310
|
const code = s.toString();
|
|
1311
|
-
const { program,
|
|
1312
|
-
|
|
1313
|
-
|
|
1311
|
+
const { program, diagnostics } = parse(code, { sourceType: "module" });
|
|
1312
|
+
const firstError = diagnostics.find((d) => d.severity === "error");
|
|
1313
|
+
if (firstError) {
|
|
1314
|
+
console.error("[furin] DCE: failed to parse transformed output:", firstError.message);
|
|
1314
1315
|
return s;
|
|
1315
1316
|
}
|
|
1316
1317
|
const fresh = new MagicString(code);
|
|
@@ -1360,9 +1361,10 @@ function removeServerExports(s, source, program) {
|
|
|
1360
1361
|
}
|
|
1361
1362
|
function transformForClient(code, filename) {
|
|
1362
1363
|
const plainJs = bunTranspiler.transformSync(code);
|
|
1363
|
-
const { program,
|
|
1364
|
-
|
|
1365
|
-
|
|
1364
|
+
const { program, diagnostics } = parse(plainJs, { sourceType: "module" });
|
|
1365
|
+
const firstError = diagnostics.find((d) => d.severity === "error");
|
|
1366
|
+
if (firstError) {
|
|
1367
|
+
throw new Error(`Failed to parse ${filename}: ${firstError.message}`);
|
|
1366
1368
|
}
|
|
1367
1369
|
let s = new MagicString(plainJs);
|
|
1368
1370
|
const removedServerCode = removeServerExports(s, plainJs, program);
|
|
@@ -1804,14 +1806,19 @@ ${transformed}`;
|
|
|
1804
1806
|
}
|
|
1805
1807
|
|
|
1806
1808
|
// src/build/compile-entry.ts
|
|
1807
|
-
import { existsSync as
|
|
1808
|
-
import { join as
|
|
1809
|
+
import { existsSync as existsSync4, writeFileSync as writeFileSync2 } from "fs";
|
|
1810
|
+
import { join as join4, relative as relative2 } from "path";
|
|
1809
1811
|
|
|
1810
1812
|
// src/build/entry-template.ts
|
|
1811
|
-
import {
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
var
|
|
1813
|
+
import { existsSync as existsSync3 } from "fs";
|
|
1814
|
+
import { dirname, join as join3 } from "path";
|
|
1815
|
+
import { fileURLToPath } from "url";
|
|
1816
|
+
var _pkgRoot = dirname(dirname(fileURLToPath(import.meta.resolve("@teyik0/furin"))));
|
|
1817
|
+
var _pkgSrcDirRaw = existsSync3(join3(_pkgRoot, "src", "furin.ts")) ? join3(_pkgRoot, "src") : join3(_pkgRoot, "dist");
|
|
1818
|
+
var _pkgSrcDir = _pkgSrcDirRaw.replace(/\\/g, "/");
|
|
1819
|
+
var _ext = _pkgSrcDir.endsWith("/src") ? ".ts" : ".js";
|
|
1820
|
+
var INTERNAL_MODULE_PATH = `${_pkgSrcDir}/internal${_ext}`;
|
|
1821
|
+
var RUNTIME_ENV_MODULE_PATH = `${_pkgSrcDir}/runtime-env${_ext}`;
|
|
1815
1822
|
function collectConventionPaths(rootConventions, routeMetadata) {
|
|
1816
1823
|
const paths = [];
|
|
1817
1824
|
if (rootConventions?.errorPath) {
|
|
@@ -1908,7 +1915,7 @@ function generateCompileEntry(options) {
|
|
|
1908
1915
|
const assetImports = [];
|
|
1909
1916
|
let embeddedBlock = [];
|
|
1910
1917
|
if (embed) {
|
|
1911
|
-
if (!
|
|
1918
|
+
if (!existsSync4(embed.clientDir)) {
|
|
1912
1919
|
throw new Error(`[furin] Client directory not found: ${embed.clientDir}. Run the client build first.`);
|
|
1913
1920
|
}
|
|
1914
1921
|
const clientFiles = collectFilesRecursive(embed.clientDir);
|
|
@@ -1928,9 +1935,9 @@ function generateCompileEntry(options) {
|
|
|
1928
1935
|
}
|
|
1929
1936
|
}
|
|
1930
1937
|
if (templateVarName === null) {
|
|
1931
|
-
throw new Error(`[furin] Embed mode requires a client index.html at ${
|
|
1938
|
+
throw new Error(`[furin] Embed mode requires a client index.html at ${join4(embed.clientDir, "index.html")}. Run the client build first.`);
|
|
1932
1939
|
}
|
|
1933
|
-
if (publicDir &&
|
|
1940
|
+
if (publicDir && existsSync4(publicDir)) {
|
|
1934
1941
|
const publicFiles = collectFilesRecursive(publicDir);
|
|
1935
1942
|
for (const file of publicFiles) {
|
|
1936
1943
|
const varName = `_asset${assetIndex++}`;
|
|
@@ -1961,14 +1968,14 @@ function generateCompileEntry(options) {
|
|
|
1961
1968
|
rootConventions,
|
|
1962
1969
|
routeMetadata
|
|
1963
1970
|
});
|
|
1964
|
-
const entryPath =
|
|
1971
|
+
const entryPath = join4(outDir, "_compile-entry.ts");
|
|
1965
1972
|
writeFileSync2(entryPath, source);
|
|
1966
1973
|
return entryPath;
|
|
1967
1974
|
}
|
|
1968
1975
|
|
|
1969
1976
|
// src/build/server-routes-entry.ts
|
|
1970
1977
|
import { writeFileSync as writeFileSync3 } from "fs";
|
|
1971
|
-
import { join as
|
|
1978
|
+
import { join as join5 } from "path";
|
|
1972
1979
|
function generateServerRoutesEntry(options) {
|
|
1973
1980
|
const { buildId, outDir, rootPath, routes, serverEntry, rootConventions, routeMetadata } = options;
|
|
1974
1981
|
ensureDir(outDir);
|
|
@@ -1981,13 +1988,14 @@ function generateServerRoutesEntry(options) {
|
|
|
1981
1988
|
rootConventions,
|
|
1982
1989
|
routeMetadata
|
|
1983
1990
|
});
|
|
1984
|
-
const entryPath =
|
|
1991
|
+
const entryPath = join5(outDir, "server.ts");
|
|
1985
1992
|
writeFileSync3(entryPath, source);
|
|
1986
1993
|
return entryPath;
|
|
1987
1994
|
}
|
|
1988
1995
|
|
|
1989
1996
|
// src/adapter/bun.ts
|
|
1990
|
-
var
|
|
1997
|
+
var _pkgRoot2 = dirname2(dirname2(fileURLToPath2(import.meta.resolve("@teyik0/furin"))));
|
|
1998
|
+
var _pkgSrcDir2 = existsSync5(join6(_pkgRoot2, "src", "furin.ts")) ? join6(_pkgRoot2, "src") : join6(_pkgRoot2, "dist");
|
|
1991
1999
|
var BUILD_ID_INPUT_PATHS = [
|
|
1992
2000
|
`${_pkgSrcDir2}/build/compile-entry.ts`,
|
|
1993
2001
|
`${_pkgSrcDir2}/build/entry-template.ts`,
|
|
@@ -2018,13 +2026,13 @@ async function createBuildFingerprint(entryChunk, cssChunks, routes, root, serve
|
|
|
2018
2026
|
}
|
|
2019
2027
|
}
|
|
2020
2028
|
for (const path of BUILD_ID_INPUT_PATHS) {
|
|
2021
|
-
if (!
|
|
2029
|
+
if (!existsSync5(path)) {
|
|
2022
2030
|
console.warn(`[furin] Warning: build fingerprint input "${toPosixPath(path)}" is missing \u2014 ` + "the generated build ID may not reflect all framework changes.");
|
|
2023
2031
|
}
|
|
2024
2032
|
fingerprintPaths.add(path);
|
|
2025
2033
|
}
|
|
2026
2034
|
const fileParts = await Promise.all([...fingerprintPaths].sort().map(async (path) => {
|
|
2027
|
-
const content =
|
|
2035
|
+
const content = existsSync5(path) ? await Bun.file(path).text() : "";
|
|
2028
2036
|
return `${toPosixPath(path)}:${content}`;
|
|
2029
2037
|
}));
|
|
2030
2038
|
const routeParts = routes.map((route) => JSON.stringify({ mode: route.mode, path: toPosixPath(route.path), pattern: route.pattern })).sort();
|
|
@@ -2068,18 +2076,18 @@ async function buildBunTarget(routes, rootDir, buildRoot, root, serverEntry, opt
|
|
|
2068
2076
|
const buildFingerprint = await createBuildFingerprint(entryChunk, cssChunks, routes, root, serverEntry);
|
|
2069
2077
|
const buildId = Bun.hash(buildFingerprint).toString(16).slice(0, 12);
|
|
2070
2078
|
targetManifest.buildId = buildId;
|
|
2071
|
-
const clientDir =
|
|
2072
|
-
writeFileSync4(
|
|
2079
|
+
const clientDir = join6(targetDir, "client");
|
|
2080
|
+
writeFileSync4(join6(clientDir, "index.html"), generateProdIndexHtml(entryChunk, cssChunks, buildId));
|
|
2073
2081
|
const routeManifest = routes.map((r) => ({ pattern: r.pattern, path: r.path, mode: r.mode }));
|
|
2074
|
-
const publicDir =
|
|
2075
|
-
const targetPublicDir = publicDir ?
|
|
2082
|
+
const publicDir = existsSync5(join6(rootDir, "public")) ? join6(rootDir, "public") : undefined;
|
|
2083
|
+
const targetPublicDir = publicDir ? join6(targetDir, "public") : undefined;
|
|
2076
2084
|
if (publicDir && targetPublicDir && options.compile !== "embed") {
|
|
2077
2085
|
copyDirRecursive(publicDir, targetPublicDir);
|
|
2078
2086
|
}
|
|
2079
2087
|
const { rootConventions, routeMetadata } = buildCompileMetadata(root, routes);
|
|
2080
2088
|
if (options.compile && serverEntry) {
|
|
2081
|
-
const clientDir2 =
|
|
2082
|
-
const outfile =
|
|
2089
|
+
const clientDir2 = join6(targetDir, "client");
|
|
2090
|
+
const outfile = join6(targetDir, "server");
|
|
2083
2091
|
const entryPath = generateCompileEntry({
|
|
2084
2092
|
buildId,
|
|
2085
2093
|
rootPath: root.path,
|
|
@@ -2100,7 +2108,7 @@ async function buildBunTarget(routes, rootDir, buildRoot, root, serverEntry, opt
|
|
|
2100
2108
|
plugins: options.plugins
|
|
2101
2109
|
});
|
|
2102
2110
|
console.log(`[furin] Server binary: ${outfile}`);
|
|
2103
|
-
targetManifest.serverPath = toPosixPath(
|
|
2111
|
+
targetManifest.serverPath = toPosixPath(join6(targetManifest.targetDir, "server"));
|
|
2104
2112
|
if (options.compile === "embed") {
|
|
2105
2113
|
rmSync2(clientDir2, { force: true, recursive: true });
|
|
2106
2114
|
targetManifest.clientDir = null;
|
|
@@ -2124,8 +2132,8 @@ async function buildBunTarget(routes, rootDir, buildRoot, root, serverEntry, opt
|
|
|
2124
2132
|
sourcemap: "linked",
|
|
2125
2133
|
plugins: options.plugins
|
|
2126
2134
|
});
|
|
2127
|
-
console.log(`[furin] Server bundle: ${toPosixPath(
|
|
2128
|
-
targetManifest.serverPath = toPosixPath(
|
|
2135
|
+
console.log(`[furin] Server bundle: ${toPosixPath(join6(targetManifest.targetDir, "server.js"))}`);
|
|
2136
|
+
targetManifest.serverPath = toPosixPath(join6(targetManifest.targetDir, "server.js"));
|
|
2129
2137
|
}
|
|
2130
2138
|
for (const file of [
|
|
2131
2139
|
"_compile-entry.ts",
|
|
@@ -2133,14 +2141,14 @@ async function buildBunTarget(routes, rootDir, buildRoot, root, serverEntry, opt
|
|
|
2133
2141
|
"server.ts",
|
|
2134
2142
|
"_hydrate.tsx"
|
|
2135
2143
|
]) {
|
|
2136
|
-
rmSync2(
|
|
2144
|
+
rmSync2(join6(targetDir, file), { force: true });
|
|
2137
2145
|
}
|
|
2138
2146
|
return targetManifest;
|
|
2139
2147
|
}
|
|
2140
2148
|
|
|
2141
2149
|
// src/adapter/static.ts
|
|
2142
|
-
import { cpSync as cpSync2, existsSync as
|
|
2143
|
-
import { dirname as dirname3, isAbsolute, join as
|
|
2150
|
+
import { cpSync as cpSync2, existsSync as existsSync6, rmSync as rmSync3, writeFileSync as writeFileSync5 } from "fs";
|
|
2151
|
+
import { dirname as dirname3, isAbsolute, join as join7, relative as relative3, resolve as resolve2, sep } from "path";
|
|
2144
2152
|
|
|
2145
2153
|
// src/render/assemble.ts
|
|
2146
2154
|
function resolvePath(pattern, params) {
|
|
@@ -3142,7 +3150,7 @@ function computeLinkView({
|
|
|
3142
3150
|
const logicalHrefWithoutHash = buildHref(to, search, undefined);
|
|
3143
3151
|
const isAbsolute = logicalHref.startsWith("http://") || logicalHref.startsWith("https://") || logicalHref.startsWith("//");
|
|
3144
3152
|
const href = isAbsolute ? logicalHref : router.basePath + logicalHref;
|
|
3145
|
-
const isActive = router.currentHref === logicalHrefWithoutHash;
|
|
3153
|
+
const isActive = !isAbsolute && router.currentHref === normalizeHref(logicalHrefWithoutHash);
|
|
3146
3154
|
const resolvedChildren = typeof children === "function" ? children({ isActive }) : children;
|
|
3147
3155
|
const extraProps = {
|
|
3148
3156
|
...inactiveProps && !isActive ? inactiveProps() : {},
|
|
@@ -3745,6 +3753,14 @@ function useRouter() {
|
|
|
3745
3753
|
defaultPreloadStaleTime: 30000
|
|
3746
3754
|
};
|
|
3747
3755
|
}
|
|
3756
|
+
function normalizeHref(href) {
|
|
3757
|
+
const url = new URL(href, "http://localhost");
|
|
3758
|
+
let pathname = url.pathname;
|
|
3759
|
+
if (pathname !== "/") {
|
|
3760
|
+
pathname = pathname.replace(/\/+$/g, "");
|
|
3761
|
+
}
|
|
3762
|
+
return pathname + url.search + url.hash;
|
|
3763
|
+
}
|
|
3748
3764
|
|
|
3749
3765
|
// src/render/cache.ts
|
|
3750
3766
|
import { AsyncLocalStorage as AsyncLocalStorage3 } from "async_hooks";
|
|
@@ -4112,6 +4128,7 @@ function getProductionTemplate() {
|
|
|
4112
4128
|
return null;
|
|
4113
4129
|
}
|
|
4114
4130
|
}
|
|
4131
|
+
|
|
4115
4132
|
// src/runtime-env.ts
|
|
4116
4133
|
var IS_DEV = true;
|
|
4117
4134
|
|
|
@@ -4160,7 +4177,7 @@ async function prepareRender(route, ctx, root, basePath, throwOnFailure, precomp
|
|
|
4160
4177
|
}
|
|
4161
4178
|
const ssrContext = {
|
|
4162
4179
|
basePath: basePath ?? "",
|
|
4163
|
-
currentHref: ctx.path,
|
|
4180
|
+
currentHref: normalizeHref(ctx.path),
|
|
4164
4181
|
navigate: () => Promise.resolve(),
|
|
4165
4182
|
prefetch: () => {},
|
|
4166
4183
|
invalidatePrefetch: () => {},
|
|
@@ -4245,7 +4262,7 @@ var TRAILING_SLASHES_RE = /\/+$/;
|
|
|
4245
4262
|
function pathToOutputFile(urlPath, outDir) {
|
|
4246
4263
|
const normalizedOutDir = resolve2(outDir);
|
|
4247
4264
|
if (urlPath === "/" || urlPath === "") {
|
|
4248
|
-
return
|
|
4265
|
+
return join7(normalizedOutDir, "index.html");
|
|
4249
4266
|
}
|
|
4250
4267
|
const resolved = resolve2(normalizedOutDir, urlPath.slice(1), "index.html");
|
|
4251
4268
|
if (!resolved.startsWith(`${normalizedOutDir}${sep}`)) {
|
|
@@ -4357,7 +4374,7 @@ async function buildStaticTarget(routes, rootDir, buildRoot, root, options) {
|
|
|
4357
4374
|
const ssgRoutes = collectSsgRoutes(routes, onSSR, skippedRoutes);
|
|
4358
4375
|
rmSync3(outDir, { force: true, recursive: true });
|
|
4359
4376
|
ensureDir(outDir);
|
|
4360
|
-
const targetDir =
|
|
4377
|
+
const targetDir = join7(buildRoot, "static");
|
|
4361
4378
|
rmSync3(targetDir, { force: true, recursive: true });
|
|
4362
4379
|
ensureDir(targetDir);
|
|
4363
4380
|
const { entryChunk, cssChunks } = await buildClient(ssgRoutes, {
|
|
@@ -4367,17 +4384,17 @@ async function buildStaticTarget(routes, rootDir, buildRoot, root, options) {
|
|
|
4367
4384
|
publicPath,
|
|
4368
4385
|
basePath
|
|
4369
4386
|
});
|
|
4370
|
-
const publicFavicon =
|
|
4371
|
-
const faviconHref =
|
|
4387
|
+
const publicFavicon = join7(rootDir, "public", "favicon.ico");
|
|
4388
|
+
const faviconHref = existsSync6(publicFavicon) ? `${basePath}/favicon.ico` : undefined;
|
|
4372
4389
|
const shellHtml = generateProdIndexHtml(entryChunk, cssChunks, undefined, faviconHref);
|
|
4373
4390
|
setProductionTemplateContent(shellHtml);
|
|
4374
|
-
const publicSrcDir =
|
|
4375
|
-
if (
|
|
4391
|
+
const publicSrcDir = join7(rootDir, "public");
|
|
4392
|
+
if (existsSync6(publicSrcDir)) {
|
|
4376
4393
|
cpSync2(publicSrcDir, outDir, { recursive: true });
|
|
4377
4394
|
}
|
|
4378
|
-
const clientSrcDir =
|
|
4379
|
-
if (
|
|
4380
|
-
cpSync2(clientSrcDir,
|
|
4395
|
+
const clientSrcDir = join7(targetDir, "client");
|
|
4396
|
+
if (existsSync6(clientSrcDir)) {
|
|
4397
|
+
cpSync2(clientSrcDir, join7(outDir, "_client"), { recursive: true });
|
|
4381
4398
|
}
|
|
4382
4399
|
const tasks = await buildTaskQueue(ssgRoutes, root, outDir, renderedRoutes, skippedRoutes, basePath);
|
|
4383
4400
|
const afterQueueCount = skippedRoutes.length;
|
|
@@ -4390,7 +4407,7 @@ async function buildStaticTarget(routes, rootDir, buildRoot, root, options) {
|
|
|
4390
4407
|
${list}
|
|
4391
4408
|
` + `Set \`onSSR: "skip"\` in your static config to suppress this error.`);
|
|
4392
4409
|
}
|
|
4393
|
-
writeFileSync5(
|
|
4410
|
+
writeFileSync5(join7(outDir, "404.html"), shellHtml);
|
|
4394
4411
|
console.log("[furin] static: wrote 404.html (SPA shell fallback)");
|
|
4395
4412
|
rmSync3(targetDir, { force: true, recursive: true });
|
|
4396
4413
|
console.log(`[furin] static: export complete \u2192 ${toPosixPath(outDir)}` + ` (${renderedRoutes.length} rendered, ${skippedRoutes.length} skipped)`);
|
|
@@ -4424,9 +4441,9 @@ var configSchema = t.Object({
|
|
|
4424
4441
|
});
|
|
4425
4442
|
|
|
4426
4443
|
// src/router.ts
|
|
4427
|
-
import { existsSync as
|
|
4444
|
+
import { existsSync as existsSync7 } from "fs";
|
|
4428
4445
|
import { readdir } from "fs/promises";
|
|
4429
|
-
import { join as
|
|
4446
|
+
import { join as join8, parse as parse2 } from "path";
|
|
4430
4447
|
import { Elysia as Elysia2, t as t2 } from "elysia";
|
|
4431
4448
|
|
|
4432
4449
|
// src/internal.ts
|
|
@@ -4435,57 +4452,6 @@ function getCompileContext() {
|
|
|
4435
4452
|
return _compileCtx;
|
|
4436
4453
|
}
|
|
4437
4454
|
|
|
4438
|
-
// src/render/dev-cache.ts
|
|
4439
|
-
var sourceFileToCacheKeys = new Map;
|
|
4440
|
-
function indexEntryDependencies(cacheKey, deps) {
|
|
4441
|
-
for (const dep of deps) {
|
|
4442
|
-
let bucket = sourceFileToCacheKeys.get(dep);
|
|
4443
|
-
if (!bucket) {
|
|
4444
|
-
bucket = new Set;
|
|
4445
|
-
sourceFileToCacheKeys.set(dep, bucket);
|
|
4446
|
-
}
|
|
4447
|
-
bucket.add(cacheKey);
|
|
4448
|
-
}
|
|
4449
|
-
}
|
|
4450
|
-
function unindexEntryDependencies(cacheKey, deps) {
|
|
4451
|
-
for (const dep of deps) {
|
|
4452
|
-
const bucket = sourceFileToCacheKeys.get(dep);
|
|
4453
|
-
if (!bucket) {
|
|
4454
|
-
continue;
|
|
4455
|
-
}
|
|
4456
|
-
bucket.delete(cacheKey);
|
|
4457
|
-
if (bucket.size === 0) {
|
|
4458
|
-
sourceFileToCacheKeys.delete(dep);
|
|
4459
|
-
}
|
|
4460
|
-
}
|
|
4461
|
-
}
|
|
4462
|
-
function createDevLoaderCache(name) {
|
|
4463
|
-
return createRouteCache({
|
|
4464
|
-
name,
|
|
4465
|
-
onDelete: (key, entry) => {
|
|
4466
|
-
unindexEntryDependencies(key, entry.dependencies);
|
|
4467
|
-
},
|
|
4468
|
-
onSet: (key, entry, previous) => {
|
|
4469
|
-
if (previous) {
|
|
4470
|
-
unindexEntryDependencies(key, previous.dependencies);
|
|
4471
|
-
}
|
|
4472
|
-
indexEntryDependencies(key, entry.dependencies);
|
|
4473
|
-
},
|
|
4474
|
-
pathFromKey: urlPathFromCacheKey
|
|
4475
|
-
});
|
|
4476
|
-
}
|
|
4477
|
-
var devISRLoaderCache = createDevLoaderCache("render:dev-isr-loader");
|
|
4478
|
-
var devSSGLoaderCache = createDevLoaderCache("render:dev-ssg-loader");
|
|
4479
|
-
function urlPathFromCacheKey(key) {
|
|
4480
|
-
const sep2 = key.lastIndexOf(":/");
|
|
4481
|
-
if (sep2 === -1) {
|
|
4482
|
-
return null;
|
|
4483
|
-
}
|
|
4484
|
-
return key.slice(sep2 + 1);
|
|
4485
|
-
}
|
|
4486
|
-
registerCacheInvalidator(devISRLoaderCache);
|
|
4487
|
-
registerCacheInvalidator(devSSGLoaderCache);
|
|
4488
|
-
|
|
4489
4455
|
// src/utils.ts
|
|
4490
4456
|
function isFurinPage(value) {
|
|
4491
4457
|
return typeof value === "object" && value !== null && "__type" in value && value.__type === "FURIN_PAGE";
|
|
@@ -4536,7 +4502,7 @@ async function scanPages(pagesDir) {
|
|
|
4536
4502
|
async function scanRootLayout(pagesDir) {
|
|
4537
4503
|
const rootPath = `${pagesDir}/root.tsx`;
|
|
4538
4504
|
const ctx = getCompileContext();
|
|
4539
|
-
if (!(
|
|
4505
|
+
if (!(existsSync7(rootPath) || ctx?.modules[rootPath])) {
|
|
4540
4506
|
throw new Error("[furin] root.tsx: not found.");
|
|
4541
4507
|
}
|
|
4542
4508
|
const mod = ctx?.modules[rootPath] ?? await import(rootPath);
|
|
@@ -4569,7 +4535,7 @@ function getSourceModuleCandidates(dir, name) {
|
|
|
4569
4535
|
async function loadConventionComponent(dir, name) {
|
|
4570
4536
|
const ctx = getCompileContext();
|
|
4571
4537
|
for (const filePath of getSourceModuleCandidates(dir, name)) {
|
|
4572
|
-
if (
|
|
4538
|
+
if (existsSync7(filePath) || ctx?.modules[filePath]) {
|
|
4573
4539
|
const mod = ctx?.modules[filePath] ?? await import(filePath);
|
|
4574
4540
|
if (mod.default) {
|
|
4575
4541
|
return { component: mod.default, path: filePath };
|
|
@@ -4587,7 +4553,7 @@ async function scanPageFiles(pagesDir, root) {
|
|
|
4587
4553
|
continue;
|
|
4588
4554
|
}
|
|
4589
4555
|
const relativePath = absolutePath.replace(`${pagesDir}/`, "");
|
|
4590
|
-
const fileName =
|
|
4556
|
+
const fileName = parse2(relativePath).name;
|
|
4591
4557
|
if (fileName.startsWith("_") || fileName === "root" || isConventionFileName(fileName)) {
|
|
4592
4558
|
continue;
|
|
4593
4559
|
}
|
|
@@ -4706,7 +4672,7 @@ async function collectPageFilePaths(dir) {
|
|
|
4706
4672
|
const files = [];
|
|
4707
4673
|
const entries = (await readdir(dir, { withFileTypes: true })).sort((a, b) => a.name.localeCompare(b.name));
|
|
4708
4674
|
for (const entry of entries) {
|
|
4709
|
-
const absolutePath =
|
|
4675
|
+
const absolutePath = join8(dir, entry.name);
|
|
4710
4676
|
if (entry.isDirectory()) {
|
|
4711
4677
|
files.push(...await collectPageFilePaths(absolutePath));
|
|
4712
4678
|
continue;
|
|
@@ -4737,7 +4703,7 @@ function filePathToPattern(path) {
|
|
|
4737
4703
|
const parts = path.replaceAll("\\", "/").split("/");
|
|
4738
4704
|
const segments = [];
|
|
4739
4705
|
for (const part of parts) {
|
|
4740
|
-
const name =
|
|
4706
|
+
const name = parse2(part).name;
|
|
4741
4707
|
if (name === "index") {
|
|
4742
4708
|
continue;
|
|
4743
4709
|
}
|
|
@@ -4757,11 +4723,39 @@ function filePathToPattern(path) {
|
|
|
4757
4723
|
|
|
4758
4724
|
// src/build/scan-server.ts
|
|
4759
4725
|
import { readFileSync as readFileSync2 } from "fs";
|
|
4760
|
-
import {
|
|
4726
|
+
import { parse as parse3 } from "yuku-parser";
|
|
4727
|
+
function detectLangFromPath(filePath) {
|
|
4728
|
+
if (filePath.endsWith(".d.ts")) {
|
|
4729
|
+
return "dts";
|
|
4730
|
+
}
|
|
4731
|
+
const ext = filePath.split(".").pop()?.toLowerCase();
|
|
4732
|
+
switch (ext) {
|
|
4733
|
+
case "ts":
|
|
4734
|
+
return "ts";
|
|
4735
|
+
case "tsx":
|
|
4736
|
+
return "tsx";
|
|
4737
|
+
case "jsx":
|
|
4738
|
+
return "jsx";
|
|
4739
|
+
default:
|
|
4740
|
+
return "js";
|
|
4741
|
+
}
|
|
4742
|
+
}
|
|
4761
4743
|
function scanFurinInstances(serverEntryPath) {
|
|
4762
4744
|
const code = readFileSync2(serverEntryPath, "utf8");
|
|
4763
|
-
|
|
4764
|
-
if (
|
|
4745
|
+
let lang = detectLangFromPath(serverEntryPath);
|
|
4746
|
+
if (lang === "dts") {
|
|
4747
|
+
return [];
|
|
4748
|
+
}
|
|
4749
|
+
let parseInput = code;
|
|
4750
|
+
if (lang === "ts" || lang === "tsx") {
|
|
4751
|
+
const transpiler = new Bun.Transpiler({ loader: lang });
|
|
4752
|
+
parseInput = transpiler.transformSync(code);
|
|
4753
|
+
lang = "js";
|
|
4754
|
+
}
|
|
4755
|
+
const { program, diagnostics } = parse3(parseInput, { sourceType: "module", lang });
|
|
4756
|
+
const firstError = diagnostics.find((d) => d.severity === "error");
|
|
4757
|
+
if (firstError) {
|
|
4758
|
+
console.error("[furin] scan-server: parse error:", firstError.message, "in", serverEntryPath);
|
|
4765
4759
|
return [];
|
|
4766
4760
|
}
|
|
4767
4761
|
const results = [];
|
|
@@ -4849,19 +4843,19 @@ function resolvePagesDirFromServer(serverEntry, rootDir) {
|
|
|
4849
4843
|
}
|
|
4850
4844
|
async function buildApp(options) {
|
|
4851
4845
|
const rootDir = resolve3(options.rootDir ?? process.cwd());
|
|
4852
|
-
const buildRoot =
|
|
4846
|
+
const buildRoot = join9(rootDir, BUILD_OUTPUT_DIR);
|
|
4853
4847
|
const serverEntry = (() => {
|
|
4854
4848
|
if (options.target === "static") {
|
|
4855
4849
|
return null;
|
|
4856
4850
|
}
|
|
4857
4851
|
if (options.serverEntry) {
|
|
4858
4852
|
const resolved = resolve3(rootDir, options.serverEntry);
|
|
4859
|
-
if (
|
|
4853
|
+
if (existsSync8(resolved)) {
|
|
4860
4854
|
return resolved;
|
|
4861
4855
|
}
|
|
4862
4856
|
}
|
|
4863
4857
|
const entry = resolve3(rootDir, "src/server.ts");
|
|
4864
|
-
if (!
|
|
4858
|
+
if (!existsSync8(entry)) {
|
|
4865
4859
|
throw new Error("[furin] Entrypoint server.ts not found");
|
|
4866
4860
|
}
|
|
4867
4861
|
return entry;
|
|
@@ -4913,7 +4907,7 @@ async function buildApp(options) {
|
|
|
4913
4907
|
throw new Error(`[furin] Unsupported build target "${target}"`);
|
|
4914
4908
|
}
|
|
4915
4909
|
}
|
|
4916
|
-
writeFileSync6(
|
|
4910
|
+
writeFileSync6(join9(buildRoot, "manifest.json"), `${JSON.stringify(manifest, null, 2)}
|
|
4917
4911
|
`);
|
|
4918
4912
|
return {
|
|
4919
4913
|
manifest,
|
|
@@ -4922,7 +4916,7 @@ async function buildApp(options) {
|
|
|
4922
4916
|
}
|
|
4923
4917
|
|
|
4924
4918
|
// src/cli/config.ts
|
|
4925
|
-
import { existsSync as
|
|
4919
|
+
import { existsSync as existsSync9 } from "fs";
|
|
4926
4920
|
import { resolve as resolve4 } from "path";
|
|
4927
4921
|
import { pathToFileURL } from "url";
|
|
4928
4922
|
import { TypeCompiler } from "elysia/type-system";
|
|
@@ -4934,7 +4928,7 @@ var DEFAULT_CONFIG_FILENAMES = [
|
|
|
4934
4928
|
];
|
|
4935
4929
|
async function loadCliConfig(cwd, explicitConfigPath) {
|
|
4936
4930
|
const rootDir = resolve4(cwd);
|
|
4937
|
-
const configPath = explicitConfigPath ? resolve4(rootDir, explicitConfigPath) : DEFAULT_CONFIG_FILENAMES.map((filename) => resolve4(rootDir, filename)).find((path) =>
|
|
4931
|
+
const configPath = explicitConfigPath ? resolve4(rootDir, explicitConfigPath) : DEFAULT_CONFIG_FILENAMES.map((filename) => resolve4(rootDir, filename)).find((path) => existsSync9(path));
|
|
4938
4932
|
if (!configPath) {
|
|
4939
4933
|
return {
|
|
4940
4934
|
configPath: null,
|
|
@@ -5012,7 +5006,7 @@ if (command === "build") {
|
|
|
5012
5006
|
const isStaticTarget = target === "static";
|
|
5013
5007
|
const resolvedServerEntry = isStaticTarget ? undefined : (() => {
|
|
5014
5008
|
const entry = resolve5(config.rootDir, config.serverEntry ?? "src/server.ts");
|
|
5015
|
-
if (!
|
|
5009
|
+
if (!existsSync10(entry)) {
|
|
5016
5010
|
const expected = config.serverEntry ?? "src/server.ts";
|
|
5017
5011
|
throw new Error(`[furin] Entrypoint ${expected} not found`);
|
|
5018
5012
|
}
|
package/dist/env.d.ts
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// Global type declarations shipped by Furin.
|
|
2
|
+
// Referenced automatically via furin-env.d.ts — no user config needed.
|
|
3
|
+
|
|
4
|
+
declare module "*.css" {}
|
|
5
|
+
declare module "*.svg" {
|
|
6
|
+
const src: string;
|
|
7
|
+
export default src;
|
|
8
|
+
}
|
|
9
|
+
declare module "*.png" {
|
|
10
|
+
const src: string;
|
|
11
|
+
export default src;
|
|
12
|
+
}
|
|
13
|
+
declare module "*.jpg" {
|
|
14
|
+
const src: string;
|
|
15
|
+
export default src;
|
|
16
|
+
}
|
|
17
|
+
declare module "*.jpeg" {
|
|
18
|
+
const src: string;
|
|
19
|
+
export default src;
|
|
20
|
+
}
|
|
21
|
+
declare module "*.gif" {
|
|
22
|
+
const src: string;
|
|
23
|
+
export default src;
|
|
24
|
+
}
|
|
25
|
+
declare module "*.webp" {
|
|
26
|
+
const src: string;
|
|
27
|
+
export default src;
|
|
28
|
+
}
|
|
29
|
+
declare module "*.avif" {
|
|
30
|
+
const src: string;
|
|
31
|
+
export default src;
|
|
32
|
+
}
|
|
33
|
+
declare module "*.ico" {
|
|
34
|
+
const src: string;
|
|
35
|
+
export default src;
|
|
36
|
+
}
|
|
37
|
+
declare module "*.woff" {
|
|
38
|
+
const src: string;
|
|
39
|
+
export default src;
|
|
40
|
+
}
|
|
41
|
+
declare module "*.woff2" {
|
|
42
|
+
const src: string;
|
|
43
|
+
export default src;
|
|
44
|
+
}
|
|
45
|
+
declare module "*.mdx" {
|
|
46
|
+
import type { ComponentType } from "react";
|
|
47
|
+
|
|
48
|
+
const MDXComponent: ComponentType;
|
|
49
|
+
export default MDXComponent;
|
|
50
|
+
}
|
package/dist/furin.js
CHANGED
|
@@ -1513,7 +1513,7 @@ function computeLinkView({
|
|
|
1513
1513
|
const logicalHrefWithoutHash = buildHref(to, search, undefined);
|
|
1514
1514
|
const isAbsolute = logicalHref.startsWith("http://") || logicalHref.startsWith("https://") || logicalHref.startsWith("//");
|
|
1515
1515
|
const href = isAbsolute ? logicalHref : router.basePath + logicalHref;
|
|
1516
|
-
const isActive = router.currentHref === logicalHrefWithoutHash;
|
|
1516
|
+
const isActive = !isAbsolute && router.currentHref === normalizeHref(logicalHrefWithoutHash);
|
|
1517
1517
|
const resolvedChildren = typeof children === "function" ? children({ isActive }) : children;
|
|
1518
1518
|
const extraProps = {
|
|
1519
1519
|
...inactiveProps && !isActive ? inactiveProps() : {},
|
|
@@ -2127,10 +2127,16 @@ function useRouter() {
|
|
|
2127
2127
|
defaultPreloadStaleTime: 30000
|
|
2128
2128
|
};
|
|
2129
2129
|
}
|
|
2130
|
+
function normalizeHref(href) {
|
|
2131
|
+
const url = new URL(href, "http://localhost");
|
|
2132
|
+
let pathname = url.pathname;
|
|
2133
|
+
if (pathname !== "/") {
|
|
2134
|
+
pathname = pathname.replace(/\/+$/g, "");
|
|
2135
|
+
}
|
|
2136
|
+
return pathname + url.search + url.hash;
|
|
2137
|
+
}
|
|
2130
2138
|
var RouterContext;
|
|
2131
2139
|
var init_router_provider = __esm(() => {
|
|
2132
|
-
init_boundaries();
|
|
2133
|
-
init_default_screens();
|
|
2134
2140
|
RouterContext = createContext(null);
|
|
2135
2141
|
});
|
|
2136
2142
|
|
|
@@ -2515,7 +2521,7 @@ async function prepareRender(route, ctx, root, basePath, throwOnFailure, precomp
|
|
|
2515
2521
|
}
|
|
2516
2522
|
const ssrContext = {
|
|
2517
2523
|
basePath: basePath ?? "",
|
|
2518
|
-
currentHref: ctx.path,
|
|
2524
|
+
currentHref: normalizeHref(ctx.path),
|
|
2519
2525
|
navigate: () => Promise.resolve(),
|
|
2520
2526
|
prefetch: () => {},
|
|
2521
2527
|
invalidatePrefetch: () => {},
|
|
@@ -2685,7 +2691,7 @@ async function renderRootNotFound(root, request) {
|
|
|
2685
2691
|
const notFoundError = new FurinNotFoundError(undefined);
|
|
2686
2692
|
const notFoundContext = {
|
|
2687
2693
|
basePath: "",
|
|
2688
|
-
currentHref: request ? new URL(request.url).pathname : "/",
|
|
2694
|
+
currentHref: request ? normalizeHref(new URL(request.url).pathname) : "/",
|
|
2689
2695
|
navigate: () => Promise.resolve(),
|
|
2690
2696
|
prefetch: () => {},
|
|
2691
2697
|
invalidatePrefetch: () => {},
|
|
@@ -2950,8 +2956,6 @@ var init_render = __esm(() => {
|
|
|
2950
2956
|
init_loaders();
|
|
2951
2957
|
init_shell();
|
|
2952
2958
|
init_template();
|
|
2953
|
-
init_assemble();
|
|
2954
|
-
init_element();
|
|
2955
2959
|
init_loaders();
|
|
2956
2960
|
init_context_logger();
|
|
2957
2961
|
init_shell();
|
package/dist/internal.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// src/internal.ts
|
|
3
|
+
var _compileCtx = null;
|
|
4
|
+
function __setCompileContext(ctx) {
|
|
5
|
+
_compileCtx = ctx;
|
|
6
|
+
}
|
|
7
|
+
function getCompileContext() {
|
|
8
|
+
return _compileCtx;
|
|
9
|
+
}
|
|
10
|
+
function __resetCompileContext() {
|
|
11
|
+
_compileCtx = null;
|
|
12
|
+
}
|
|
13
|
+
export {
|
|
14
|
+
getCompileContext,
|
|
15
|
+
__setCompileContext,
|
|
16
|
+
__resetCompileContext
|
|
17
|
+
};
|