@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/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);
|
|
@@ -1884,14 +1886,19 @@ ${transformed}`;
|
|
|
1884
1886
|
}
|
|
1885
1887
|
|
|
1886
1888
|
// src/build/compile-entry.ts
|
|
1887
|
-
import { existsSync as
|
|
1888
|
-
import { join as
|
|
1889
|
+
import { existsSync as existsSync6, writeFileSync as writeFileSync4 } from "fs";
|
|
1890
|
+
import { join as join6, relative as relative2 } from "path";
|
|
1889
1891
|
|
|
1890
1892
|
// src/build/entry-template.ts
|
|
1891
|
-
import {
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
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}`;
|
|
1895
1902
|
function collectConventionPaths(rootConventions, routeMetadata) {
|
|
1896
1903
|
const paths = [];
|
|
1897
1904
|
if (rootConventions?.errorPath) {
|
|
@@ -1988,7 +1995,7 @@ function generateCompileEntry(options) {
|
|
|
1988
1995
|
const assetImports = [];
|
|
1989
1996
|
let embeddedBlock = [];
|
|
1990
1997
|
if (embed) {
|
|
1991
|
-
if (!
|
|
1998
|
+
if (!existsSync6(embed.clientDir)) {
|
|
1992
1999
|
throw new Error(`[furin] Client directory not found: ${embed.clientDir}. Run the client build first.`);
|
|
1993
2000
|
}
|
|
1994
2001
|
const clientFiles = collectFilesRecursive(embed.clientDir);
|
|
@@ -2008,9 +2015,9 @@ function generateCompileEntry(options) {
|
|
|
2008
2015
|
}
|
|
2009
2016
|
}
|
|
2010
2017
|
if (templateVarName === null) {
|
|
2011
|
-
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.`);
|
|
2012
2019
|
}
|
|
2013
|
-
if (publicDir &&
|
|
2020
|
+
if (publicDir && existsSync6(publicDir)) {
|
|
2014
2021
|
const publicFiles = collectFilesRecursive(publicDir);
|
|
2015
2022
|
for (const file of publicFiles) {
|
|
2016
2023
|
const varName = `_asset${assetIndex++}`;
|
|
@@ -2041,14 +2048,14 @@ function generateCompileEntry(options) {
|
|
|
2041
2048
|
rootConventions,
|
|
2042
2049
|
routeMetadata
|
|
2043
2050
|
});
|
|
2044
|
-
const entryPath =
|
|
2051
|
+
const entryPath = join6(outDir, "_compile-entry.ts");
|
|
2045
2052
|
writeFileSync4(entryPath, source);
|
|
2046
2053
|
return entryPath;
|
|
2047
2054
|
}
|
|
2048
2055
|
|
|
2049
2056
|
// src/build/server-routes-entry.ts
|
|
2050
2057
|
import { writeFileSync as writeFileSync5 } from "fs";
|
|
2051
|
-
import { join as
|
|
2058
|
+
import { join as join7 } from "path";
|
|
2052
2059
|
function generateServerRoutesEntry(options) {
|
|
2053
2060
|
const { buildId, outDir, rootPath, routes, serverEntry, rootConventions, routeMetadata } = options;
|
|
2054
2061
|
ensureDir(outDir);
|
|
@@ -2061,13 +2068,14 @@ function generateServerRoutesEntry(options) {
|
|
|
2061
2068
|
rootConventions,
|
|
2062
2069
|
routeMetadata
|
|
2063
2070
|
});
|
|
2064
|
-
const entryPath =
|
|
2071
|
+
const entryPath = join7(outDir, "server.ts");
|
|
2065
2072
|
writeFileSync5(entryPath, source);
|
|
2066
2073
|
return entryPath;
|
|
2067
2074
|
}
|
|
2068
2075
|
|
|
2069
2076
|
// src/adapter/bun.ts
|
|
2070
|
-
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");
|
|
2071
2079
|
var BUILD_ID_INPUT_PATHS = [
|
|
2072
2080
|
`${_pkgSrcDir2}/build/compile-entry.ts`,
|
|
2073
2081
|
`${_pkgSrcDir2}/build/entry-template.ts`,
|
|
@@ -2098,13 +2106,13 @@ async function createBuildFingerprint(entryChunk, cssChunks, routes, root, serve
|
|
|
2098
2106
|
}
|
|
2099
2107
|
}
|
|
2100
2108
|
for (const path of BUILD_ID_INPUT_PATHS) {
|
|
2101
|
-
if (!
|
|
2109
|
+
if (!existsSync7(path)) {
|
|
2102
2110
|
console.warn(`[furin] Warning: build fingerprint input "${toPosixPath(path)}" is missing \u2014 ` + "the generated build ID may not reflect all framework changes.");
|
|
2103
2111
|
}
|
|
2104
2112
|
fingerprintPaths.add(path);
|
|
2105
2113
|
}
|
|
2106
2114
|
const fileParts = await Promise.all([...fingerprintPaths].sort().map(async (path) => {
|
|
2107
|
-
const content =
|
|
2115
|
+
const content = existsSync7(path) ? await Bun.file(path).text() : "";
|
|
2108
2116
|
return `${toPosixPath(path)}:${content}`;
|
|
2109
2117
|
}));
|
|
2110
2118
|
const routeParts = routes.map((route) => JSON.stringify({ mode: route.mode, path: toPosixPath(route.path), pattern: route.pattern })).sort();
|
|
@@ -2148,18 +2156,18 @@ async function buildBunTarget(routes, rootDir, buildRoot, root, serverEntry, opt
|
|
|
2148
2156
|
const buildFingerprint = await createBuildFingerprint(entryChunk, cssChunks, routes, root, serverEntry);
|
|
2149
2157
|
const buildId = Bun.hash(buildFingerprint).toString(16).slice(0, 12);
|
|
2150
2158
|
targetManifest.buildId = buildId;
|
|
2151
|
-
const clientDir =
|
|
2152
|
-
writeFileSync6(
|
|
2159
|
+
const clientDir = join8(targetDir, "client");
|
|
2160
|
+
writeFileSync6(join8(clientDir, "index.html"), generateProdIndexHtml(entryChunk, cssChunks, buildId));
|
|
2153
2161
|
const routeManifest = routes.map((r) => ({ pattern: r.pattern, path: r.path, mode: r.mode }));
|
|
2154
|
-
const publicDir =
|
|
2155
|
-
const targetPublicDir = publicDir ?
|
|
2162
|
+
const publicDir = existsSync7(join8(rootDir, "public")) ? join8(rootDir, "public") : undefined;
|
|
2163
|
+
const targetPublicDir = publicDir ? join8(targetDir, "public") : undefined;
|
|
2156
2164
|
if (publicDir && targetPublicDir && options.compile !== "embed") {
|
|
2157
2165
|
copyDirRecursive(publicDir, targetPublicDir);
|
|
2158
2166
|
}
|
|
2159
2167
|
const { rootConventions, routeMetadata } = buildCompileMetadata(root, routes);
|
|
2160
2168
|
if (options.compile && serverEntry) {
|
|
2161
|
-
const clientDir2 =
|
|
2162
|
-
const outfile =
|
|
2169
|
+
const clientDir2 = join8(targetDir, "client");
|
|
2170
|
+
const outfile = join8(targetDir, "server");
|
|
2163
2171
|
const entryPath = generateCompileEntry({
|
|
2164
2172
|
buildId,
|
|
2165
2173
|
rootPath: root.path,
|
|
@@ -2180,7 +2188,7 @@ async function buildBunTarget(routes, rootDir, buildRoot, root, serverEntry, opt
|
|
|
2180
2188
|
plugins: options.plugins
|
|
2181
2189
|
});
|
|
2182
2190
|
console.log(`[furin] Server binary: ${outfile}`);
|
|
2183
|
-
targetManifest.serverPath = toPosixPath(
|
|
2191
|
+
targetManifest.serverPath = toPosixPath(join8(targetManifest.targetDir, "server"));
|
|
2184
2192
|
if (options.compile === "embed") {
|
|
2185
2193
|
rmSync2(clientDir2, { force: true, recursive: true });
|
|
2186
2194
|
targetManifest.clientDir = null;
|
|
@@ -2204,8 +2212,8 @@ async function buildBunTarget(routes, rootDir, buildRoot, root, serverEntry, opt
|
|
|
2204
2212
|
sourcemap: "linked",
|
|
2205
2213
|
plugins: options.plugins
|
|
2206
2214
|
});
|
|
2207
|
-
console.log(`[furin] Server bundle: ${toPosixPath(
|
|
2208
|
-
targetManifest.serverPath = toPosixPath(
|
|
2215
|
+
console.log(`[furin] Server bundle: ${toPosixPath(join8(targetManifest.targetDir, "server.js"))}`);
|
|
2216
|
+
targetManifest.serverPath = toPosixPath(join8(targetManifest.targetDir, "server.js"));
|
|
2209
2217
|
}
|
|
2210
2218
|
for (const file of [
|
|
2211
2219
|
"_compile-entry.ts",
|
|
@@ -2213,14 +2221,14 @@ async function buildBunTarget(routes, rootDir, buildRoot, root, serverEntry, opt
|
|
|
2213
2221
|
"server.ts",
|
|
2214
2222
|
"_hydrate.tsx"
|
|
2215
2223
|
]) {
|
|
2216
|
-
rmSync2(
|
|
2224
|
+
rmSync2(join8(targetDir, file), { force: true });
|
|
2217
2225
|
}
|
|
2218
2226
|
return targetManifest;
|
|
2219
2227
|
}
|
|
2220
2228
|
|
|
2221
2229
|
// src/adapter/static.ts
|
|
2222
|
-
import { cpSync as cpSync2, existsSync as
|
|
2223
|
-
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";
|
|
2224
2232
|
|
|
2225
2233
|
// src/render/assemble.ts
|
|
2226
2234
|
function resolvePath(pattern, params) {
|
|
@@ -3222,7 +3230,7 @@ function computeLinkView({
|
|
|
3222
3230
|
const logicalHrefWithoutHash = buildHref(to, search, undefined);
|
|
3223
3231
|
const isAbsolute = logicalHref.startsWith("http://") || logicalHref.startsWith("https://") || logicalHref.startsWith("//");
|
|
3224
3232
|
const href = isAbsolute ? logicalHref : router.basePath + logicalHref;
|
|
3225
|
-
const isActive = router.currentHref === logicalHrefWithoutHash;
|
|
3233
|
+
const isActive = !isAbsolute && router.currentHref === normalizeHref(logicalHrefWithoutHash);
|
|
3226
3234
|
const resolvedChildren = typeof children === "function" ? children({ isActive }) : children;
|
|
3227
3235
|
const extraProps = {
|
|
3228
3236
|
...inactiveProps && !isActive ? inactiveProps() : {},
|
|
@@ -3825,6 +3833,14 @@ function useRouter() {
|
|
|
3825
3833
|
defaultPreloadStaleTime: 30000
|
|
3826
3834
|
};
|
|
3827
3835
|
}
|
|
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, "");
|
|
3841
|
+
}
|
|
3842
|
+
return pathname + url.search + url.hash;
|
|
3843
|
+
}
|
|
3828
3844
|
|
|
3829
3845
|
// src/render/cache.ts
|
|
3830
3846
|
import { AsyncLocalStorage as AsyncLocalStorage3 } from "async_hooks";
|
|
@@ -4192,6 +4208,7 @@ function getProductionTemplate() {
|
|
|
4192
4208
|
return null;
|
|
4193
4209
|
}
|
|
4194
4210
|
}
|
|
4211
|
+
|
|
4195
4212
|
// src/runtime-env.ts
|
|
4196
4213
|
var IS_DEV = true;
|
|
4197
4214
|
|
|
@@ -4240,7 +4257,7 @@ async function prepareRender(route, ctx, root, basePath, throwOnFailure, precomp
|
|
|
4240
4257
|
}
|
|
4241
4258
|
const ssrContext = {
|
|
4242
4259
|
basePath: basePath ?? "",
|
|
4243
|
-
currentHref: ctx.path,
|
|
4260
|
+
currentHref: normalizeHref(ctx.path),
|
|
4244
4261
|
navigate: () => Promise.resolve(),
|
|
4245
4262
|
prefetch: () => {},
|
|
4246
4263
|
invalidatePrefetch: () => {},
|
|
@@ -4325,7 +4342,7 @@ var TRAILING_SLASHES_RE = /\/+$/;
|
|
|
4325
4342
|
function pathToOutputFile(urlPath, outDir) {
|
|
4326
4343
|
const normalizedOutDir = resolve2(outDir);
|
|
4327
4344
|
if (urlPath === "/" || urlPath === "") {
|
|
4328
|
-
return
|
|
4345
|
+
return join9(normalizedOutDir, "index.html");
|
|
4329
4346
|
}
|
|
4330
4347
|
const resolved = resolve2(normalizedOutDir, urlPath.slice(1), "index.html");
|
|
4331
4348
|
if (!resolved.startsWith(`${normalizedOutDir}${sep}`)) {
|
|
@@ -4437,7 +4454,7 @@ async function buildStaticTarget(routes, rootDir, buildRoot, root, options) {
|
|
|
4437
4454
|
const ssgRoutes = collectSsgRoutes(routes, onSSR, skippedRoutes);
|
|
4438
4455
|
rmSync3(outDir, { force: true, recursive: true });
|
|
4439
4456
|
ensureDir(outDir);
|
|
4440
|
-
const targetDir =
|
|
4457
|
+
const targetDir = join9(buildRoot, "static");
|
|
4441
4458
|
rmSync3(targetDir, { force: true, recursive: true });
|
|
4442
4459
|
ensureDir(targetDir);
|
|
4443
4460
|
const { entryChunk, cssChunks } = await buildClient(ssgRoutes, {
|
|
@@ -4447,17 +4464,17 @@ async function buildStaticTarget(routes, rootDir, buildRoot, root, options) {
|
|
|
4447
4464
|
publicPath,
|
|
4448
4465
|
basePath
|
|
4449
4466
|
});
|
|
4450
|
-
const publicFavicon =
|
|
4451
|
-
const faviconHref =
|
|
4467
|
+
const publicFavicon = join9(rootDir, "public", "favicon.ico");
|
|
4468
|
+
const faviconHref = existsSync8(publicFavicon) ? `${basePath}/favicon.ico` : undefined;
|
|
4452
4469
|
const shellHtml = generateProdIndexHtml(entryChunk, cssChunks, undefined, faviconHref);
|
|
4453
4470
|
setProductionTemplateContent(shellHtml);
|
|
4454
|
-
const publicSrcDir =
|
|
4455
|
-
if (
|
|
4471
|
+
const publicSrcDir = join9(rootDir, "public");
|
|
4472
|
+
if (existsSync8(publicSrcDir)) {
|
|
4456
4473
|
cpSync2(publicSrcDir, outDir, { recursive: true });
|
|
4457
4474
|
}
|
|
4458
|
-
const clientSrcDir =
|
|
4459
|
-
if (
|
|
4460
|
-
cpSync2(clientSrcDir,
|
|
4475
|
+
const clientSrcDir = join9(targetDir, "client");
|
|
4476
|
+
if (existsSync8(clientSrcDir)) {
|
|
4477
|
+
cpSync2(clientSrcDir, join9(outDir, "_client"), { recursive: true });
|
|
4461
4478
|
}
|
|
4462
4479
|
const tasks = await buildTaskQueue(ssgRoutes, root, outDir, renderedRoutes, skippedRoutes, basePath);
|
|
4463
4480
|
const afterQueueCount = skippedRoutes.length;
|
|
@@ -4470,7 +4487,7 @@ async function buildStaticTarget(routes, rootDir, buildRoot, root, options) {
|
|
|
4470
4487
|
${list}
|
|
4471
4488
|
` + `Set \`onSSR: "skip"\` in your static config to suppress this error.`);
|
|
4472
4489
|
}
|
|
4473
|
-
writeFileSync7(
|
|
4490
|
+
writeFileSync7(join9(outDir, "404.html"), shellHtml);
|
|
4474
4491
|
console.log("[furin] static: wrote 404.html (SPA shell fallback)");
|
|
4475
4492
|
rmSync3(targetDir, { force: true, recursive: true });
|
|
4476
4493
|
console.log(`[furin] static: export complete \u2192 ${toPosixPath(outDir)}` + ` (${renderedRoutes.length} rendered, ${skippedRoutes.length} skipped)`);
|
|
@@ -4504,9 +4521,9 @@ var configSchema = t.Object({
|
|
|
4504
4521
|
});
|
|
4505
4522
|
|
|
4506
4523
|
// src/router.ts
|
|
4507
|
-
import { existsSync as
|
|
4524
|
+
import { existsSync as existsSync9 } from "fs";
|
|
4508
4525
|
import { readdir } from "fs/promises";
|
|
4509
|
-
import { join as
|
|
4526
|
+
import { join as join10, parse as parse2 } from "path";
|
|
4510
4527
|
import { Elysia as Elysia2, t as t2 } from "elysia";
|
|
4511
4528
|
|
|
4512
4529
|
// src/internal.ts
|
|
@@ -4515,57 +4532,6 @@ function getCompileContext() {
|
|
|
4515
4532
|
return _compileCtx;
|
|
4516
4533
|
}
|
|
4517
4534
|
|
|
4518
|
-
// src/render/dev-cache.ts
|
|
4519
|
-
var sourceFileToCacheKeys = new Map;
|
|
4520
|
-
function indexEntryDependencies(cacheKey, deps) {
|
|
4521
|
-
for (const dep of deps) {
|
|
4522
|
-
let bucket = sourceFileToCacheKeys.get(dep);
|
|
4523
|
-
if (!bucket) {
|
|
4524
|
-
bucket = new Set;
|
|
4525
|
-
sourceFileToCacheKeys.set(dep, bucket);
|
|
4526
|
-
}
|
|
4527
|
-
bucket.add(cacheKey);
|
|
4528
|
-
}
|
|
4529
|
-
}
|
|
4530
|
-
function unindexEntryDependencies(cacheKey, deps) {
|
|
4531
|
-
for (const dep of deps) {
|
|
4532
|
-
const bucket = sourceFileToCacheKeys.get(dep);
|
|
4533
|
-
if (!bucket) {
|
|
4534
|
-
continue;
|
|
4535
|
-
}
|
|
4536
|
-
bucket.delete(cacheKey);
|
|
4537
|
-
if (bucket.size === 0) {
|
|
4538
|
-
sourceFileToCacheKeys.delete(dep);
|
|
4539
|
-
}
|
|
4540
|
-
}
|
|
4541
|
-
}
|
|
4542
|
-
function createDevLoaderCache(name) {
|
|
4543
|
-
return createRouteCache({
|
|
4544
|
-
name,
|
|
4545
|
-
onDelete: (key, entry) => {
|
|
4546
|
-
unindexEntryDependencies(key, entry.dependencies);
|
|
4547
|
-
},
|
|
4548
|
-
onSet: (key, entry, previous) => {
|
|
4549
|
-
if (previous) {
|
|
4550
|
-
unindexEntryDependencies(key, previous.dependencies);
|
|
4551
|
-
}
|
|
4552
|
-
indexEntryDependencies(key, entry.dependencies);
|
|
4553
|
-
},
|
|
4554
|
-
pathFromKey: urlPathFromCacheKey
|
|
4555
|
-
});
|
|
4556
|
-
}
|
|
4557
|
-
var devISRLoaderCache = createDevLoaderCache("render:dev-isr-loader");
|
|
4558
|
-
var devSSGLoaderCache = createDevLoaderCache("render:dev-ssg-loader");
|
|
4559
|
-
function urlPathFromCacheKey(key) {
|
|
4560
|
-
const sep2 = key.lastIndexOf(":/");
|
|
4561
|
-
if (sep2 === -1) {
|
|
4562
|
-
return null;
|
|
4563
|
-
}
|
|
4564
|
-
return key.slice(sep2 + 1);
|
|
4565
|
-
}
|
|
4566
|
-
registerCacheInvalidator(devISRLoaderCache);
|
|
4567
|
-
registerCacheInvalidator(devSSGLoaderCache);
|
|
4568
|
-
|
|
4569
4535
|
// src/utils.ts
|
|
4570
4536
|
function isFurinPage(value) {
|
|
4571
4537
|
return typeof value === "object" && value !== null && "__type" in value && value.__type === "FURIN_PAGE";
|
|
@@ -4616,7 +4582,7 @@ async function scanPages(pagesDir) {
|
|
|
4616
4582
|
async function scanRootLayout(pagesDir) {
|
|
4617
4583
|
const rootPath = `${pagesDir}/root.tsx`;
|
|
4618
4584
|
const ctx = getCompileContext();
|
|
4619
|
-
if (!(
|
|
4585
|
+
if (!(existsSync9(rootPath) || ctx?.modules[rootPath])) {
|
|
4620
4586
|
throw new Error("[furin] root.tsx: not found.");
|
|
4621
4587
|
}
|
|
4622
4588
|
const mod = ctx?.modules[rootPath] ?? await import(rootPath);
|
|
@@ -4649,7 +4615,7 @@ function getSourceModuleCandidates(dir, name) {
|
|
|
4649
4615
|
async function loadConventionComponent(dir, name) {
|
|
4650
4616
|
const ctx = getCompileContext();
|
|
4651
4617
|
for (const filePath of getSourceModuleCandidates(dir, name)) {
|
|
4652
|
-
if (
|
|
4618
|
+
if (existsSync9(filePath) || ctx?.modules[filePath]) {
|
|
4653
4619
|
const mod = ctx?.modules[filePath] ?? await import(filePath);
|
|
4654
4620
|
if (mod.default) {
|
|
4655
4621
|
return { component: mod.default, path: filePath };
|
|
@@ -4667,7 +4633,7 @@ async function scanPageFiles(pagesDir, root) {
|
|
|
4667
4633
|
continue;
|
|
4668
4634
|
}
|
|
4669
4635
|
const relativePath = absolutePath.replace(`${pagesDir}/`, "");
|
|
4670
|
-
const fileName =
|
|
4636
|
+
const fileName = parse2(relativePath).name;
|
|
4671
4637
|
if (fileName.startsWith("_") || fileName === "root" || isConventionFileName(fileName)) {
|
|
4672
4638
|
continue;
|
|
4673
4639
|
}
|
|
@@ -4786,7 +4752,7 @@ async function collectPageFilePaths(dir) {
|
|
|
4786
4752
|
const files = [];
|
|
4787
4753
|
const entries = (await readdir(dir, { withFileTypes: true })).sort((a, b) => a.name.localeCompare(b.name));
|
|
4788
4754
|
for (const entry of entries) {
|
|
4789
|
-
const absolutePath =
|
|
4755
|
+
const absolutePath = join10(dir, entry.name);
|
|
4790
4756
|
if (entry.isDirectory()) {
|
|
4791
4757
|
files.push(...await collectPageFilePaths(absolutePath));
|
|
4792
4758
|
continue;
|
|
@@ -4817,7 +4783,7 @@ function filePathToPattern(path) {
|
|
|
4817
4783
|
const parts = path.replaceAll("\\", "/").split("/");
|
|
4818
4784
|
const segments = [];
|
|
4819
4785
|
for (const part of parts) {
|
|
4820
|
-
const name =
|
|
4786
|
+
const name = parse2(part).name;
|
|
4821
4787
|
if (name === "index") {
|
|
4822
4788
|
continue;
|
|
4823
4789
|
}
|
|
@@ -4837,11 +4803,39 @@ function filePathToPattern(path) {
|
|
|
4837
4803
|
|
|
4838
4804
|
// src/build/scan-server.ts
|
|
4839
4805
|
import { readFileSync as readFileSync4 } from "fs";
|
|
4840
|
-
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
|
+
}
|
|
4841
4823
|
function scanFurinInstances(serverEntryPath) {
|
|
4842
4824
|
const code = readFileSync4(serverEntryPath, "utf8");
|
|
4843
|
-
|
|
4844
|
-
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);
|
|
4845
4839
|
return [];
|
|
4846
4840
|
}
|
|
4847
4841
|
const results = [];
|
|
@@ -4929,19 +4923,19 @@ function resolvePagesDirFromServer(serverEntry, rootDir) {
|
|
|
4929
4923
|
}
|
|
4930
4924
|
async function buildApp(options) {
|
|
4931
4925
|
const rootDir = resolve3(options.rootDir ?? process.cwd());
|
|
4932
|
-
const buildRoot =
|
|
4926
|
+
const buildRoot = join11(rootDir, BUILD_OUTPUT_DIR);
|
|
4933
4927
|
const serverEntry = (() => {
|
|
4934
4928
|
if (options.target === "static") {
|
|
4935
4929
|
return null;
|
|
4936
4930
|
}
|
|
4937
4931
|
if (options.serverEntry) {
|
|
4938
4932
|
const resolved = resolve3(rootDir, options.serverEntry);
|
|
4939
|
-
if (
|
|
4933
|
+
if (existsSync10(resolved)) {
|
|
4940
4934
|
return resolved;
|
|
4941
4935
|
}
|
|
4942
4936
|
}
|
|
4943
4937
|
const entry = resolve3(rootDir, "src/server.ts");
|
|
4944
|
-
if (!
|
|
4938
|
+
if (!existsSync10(entry)) {
|
|
4945
4939
|
throw new Error("[furin] Entrypoint server.ts not found");
|
|
4946
4940
|
}
|
|
4947
4941
|
return entry;
|
|
@@ -4993,7 +4987,7 @@ async function buildApp(options) {
|
|
|
4993
4987
|
throw new Error(`[furin] Unsupported build target "${target}"`);
|
|
4994
4988
|
}
|
|
4995
4989
|
}
|
|
4996
|
-
writeFileSync8(
|
|
4990
|
+
writeFileSync8(join11(buildRoot, "manifest.json"), `${JSON.stringify(manifest, null, 2)}
|
|
4997
4991
|
`);
|
|
4998
4992
|
return {
|
|
4999
4993
|
manifest,
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { writeFileSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { buildEntrySource } from "./entry-template";
|
|
4
|
+
import { ensureDir } from "./shared";
|
|
5
|
+
|
|
6
|
+
export interface ServerRoutesEntryOptions {
|
|
7
|
+
buildId?: string;
|
|
8
|
+
outDir: string;
|
|
9
|
+
rootConventions?: { errorPath?: string; notFoundPath?: string };
|
|
10
|
+
rootPath: string;
|
|
11
|
+
routeMetadata?: Record<
|
|
12
|
+
string,
|
|
13
|
+
{
|
|
14
|
+
segmentBoundaries: Array<{
|
|
15
|
+
depth: number;
|
|
16
|
+
path: string;
|
|
17
|
+
errorPath?: string;
|
|
18
|
+
notFoundPath?: string;
|
|
19
|
+
}>;
|
|
20
|
+
}
|
|
21
|
+
>;
|
|
22
|
+
routes: Array<{ mode: "ssr" | "ssg" | "isr"; path: string; pattern: string }>;
|
|
23
|
+
serverEntry: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Generates `server.ts` — an intermediate entry used to produce `server.js`.
|
|
28
|
+
*
|
|
29
|
+
* Equivalent to `_compile-entry.ts` but for disk (non-binary) production builds:
|
|
30
|
+
* 1. Statically imports every page module so Bun bundles them into server.js
|
|
31
|
+
* 2. Sets production mode and registers everything in a single CompileContext
|
|
32
|
+
* 3. Imports server.ts to boot the app
|
|
33
|
+
*
|
|
34
|
+
* This file is intermediate: `adapter/bun.ts` runs `Bun.build()` on it to produce
|
|
35
|
+
* the self-contained `server.js` bundle, then deletes this file.
|
|
36
|
+
*/
|
|
37
|
+
export function generateServerRoutesEntry(options: ServerRoutesEntryOptions): string {
|
|
38
|
+
const { buildId, outDir, rootPath, routes, serverEntry, rootConventions, routeMetadata } =
|
|
39
|
+
options;
|
|
40
|
+
ensureDir(outDir);
|
|
41
|
+
const source = buildEntrySource({
|
|
42
|
+
buildId,
|
|
43
|
+
headerComment: "// Auto-generated by furin build — do not edit",
|
|
44
|
+
rootPath,
|
|
45
|
+
routes,
|
|
46
|
+
serverEntry,
|
|
47
|
+
rootConventions,
|
|
48
|
+
routeMetadata,
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
// Named "server.ts" so Bun.build() outputs "server.js"
|
|
52
|
+
const entryPath = join(outDir, "server.ts");
|
|
53
|
+
writeFileSync(entryPath, source);
|
|
54
|
+
return entryPath;
|
|
55
|
+
}
|