@teyik0/furin 0.9.0-alpha.2 → 0.9.0-alpha.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/build/index.js +46 -58
- package/dist/cli/index.js +46 -58
- package/dist/client/dev-error-overlay.ts +18 -0
- package/dist/furin.js +5 -2
- package/dist/plugin/client-plugin.d.ts +1 -1
- package/dist/plugin/index.js +5 -4
- package/package.json +2 -2
- package/src/build/hydrate.ts +2 -0
- package/src/client/dev-error-overlay.ts +18 -0
- package/src/plugin/client-plugin.ts +13 -8
- package/src/plugin/route-registry.ts +4 -21
- package/src/server/dev-page-plugin.ts +5 -2
package/dist/build/index.js
CHANGED
|
@@ -1741,7 +1741,7 @@ import { writeFileSync as writeFileSync2 } from "fs";
|
|
|
1741
1741
|
import { join as join6 } from "path";
|
|
1742
1742
|
|
|
1743
1743
|
// src/plugin/route-registry.ts
|
|
1744
|
-
import {
|
|
1744
|
+
import { join as join5, resolve as resolve2 } from "path";
|
|
1745
1745
|
|
|
1746
1746
|
// src/plugin/route-modules.ts
|
|
1747
1747
|
import { existsSync as existsSync5, readFileSync, realpathSync, statSync } from "fs";
|
|
@@ -2231,7 +2231,6 @@ var ROUTES_REGISTRY_SPECIFIER = "furin/routes?registry";
|
|
|
2231
2231
|
var COMPOSABLE_ROUTES_REGISTRY_SPECIFIER = "furin/routes?registry=composable";
|
|
2232
2232
|
var ROUTES_REGISTRY_FILTER = /^furin\/routes\?registry(?:=composable)?$/;
|
|
2233
2233
|
var ROUTE_FILE_FILTER = /^furin-route-file:.+$/;
|
|
2234
|
-
var ROUTE_FILES_NAMESPACE = "furin-route-files";
|
|
2235
2234
|
var ROUTES_REGISTRY_FILE_FILTER = /[\\/]\.furin-routes-registry(?:-composable)?\.ts\?furin-virtual$/;
|
|
2236
2235
|
var CLIENT_ROUTES_NAMESPACE = "furin-routes-client";
|
|
2237
2236
|
var CLIENT_ROUTES_FILTER = /^(?:@teyik0\/furin|furin)\/routes$/;
|
|
@@ -2363,7 +2362,6 @@ function serverProxySource(instance, includeRootCatchAll) {
|
|
|
2363
2362
|
}
|
|
2364
2363
|
function createRoutesPlugin(options) {
|
|
2365
2364
|
const routeFilesBySpecifier = new Map;
|
|
2366
|
-
const routeFilesByResolvedPath = new Map;
|
|
2367
2365
|
const registryVirtualPath = join5(resolve2(primaryInstance(options.instances).pagesDir), ".furin-routes-registry.ts?furin-virtual");
|
|
2368
2366
|
const composableRegistryVirtualPath = join5(resolve2(primaryInstance(options.instances).pagesDir), ".furin-routes-registry-composable.ts?furin-virtual");
|
|
2369
2367
|
const instancesBySpecifier = new Map(options.instances.flatMap((instance) => [
|
|
@@ -2415,20 +2413,7 @@ function createRoutesPlugin(options) {
|
|
|
2415
2413
|
if (!routeFile) {
|
|
2416
2414
|
throw new Error(`[furin] Unknown route module: ${path}`);
|
|
2417
2415
|
}
|
|
2418
|
-
|
|
2419
|
-
routeFilesByResolvedPath.set(resolvedPath, routeFile);
|
|
2420
|
-
return { namespace: ROUTE_FILES_NAMESPACE, path: resolvedPath };
|
|
2421
|
-
});
|
|
2422
|
-
build.onLoad({ filter: VIRTUAL_ROUTES_FILTER, namespace: ROUTE_FILES_NAMESPACE }, async ({ path }) => {
|
|
2423
|
-
const routeFile = routeFilesByResolvedPath.get(path);
|
|
2424
|
-
if (!routeFile) {
|
|
2425
|
-
throw new Error(`[furin] Unknown route module: ${path}`);
|
|
2426
|
-
}
|
|
2427
|
-
return {
|
|
2428
|
-
contents: await Bun.file(routeFile.sourcePath).text(),
|
|
2429
|
-
loader: detectLoaderFromPath(routeFile.sourcePath),
|
|
2430
|
-
resolveDir: dirname5(routeFile.sourcePath)
|
|
2431
|
-
};
|
|
2416
|
+
return { path: routeFile.sourcePath };
|
|
2432
2417
|
});
|
|
2433
2418
|
for (const { instance, namespace, includeRootCatchAll } of instancesBySpecifier.values()) {
|
|
2434
2419
|
build.onLoad({ filter: VIRTUAL_ROUTES_FILTER, namespace }, () => ({
|
|
@@ -5335,7 +5320,7 @@ function pruneOrphanedCode(module, forced, retained) {
|
|
|
5335
5320
|
|
|
5336
5321
|
// src/plugin/transform-client-module.ts
|
|
5337
5322
|
import { realpathSync as realpathSync2 } from "fs";
|
|
5338
|
-
import { dirname as
|
|
5323
|
+
import { dirname as dirname5 } from "path";
|
|
5339
5324
|
var FURIN_CLIENT_MODULES = new Set(["@teyik0/furin/client", "furin/client"]);
|
|
5340
5325
|
var SERVER_LOAD = '() => Promise.reject(new Error("[furin] clientModule() can only be loaded in the browser."))';
|
|
5341
5326
|
function clientModuleKey(modulePath) {
|
|
@@ -5390,7 +5375,7 @@ function rewriteClientModules(module, environment) {
|
|
|
5390
5375
|
}
|
|
5391
5376
|
let key;
|
|
5392
5377
|
try {
|
|
5393
|
-
key = JSON.stringify(clientModuleKey(Bun.resolveSync(specifier,
|
|
5378
|
+
key = JSON.stringify(clientModuleKey(Bun.resolveSync(specifier, dirname5(filename))));
|
|
5394
5379
|
} catch (error) {
|
|
5395
5380
|
throw new Error(`[furin] Cannot resolve clientModule import ${JSON.stringify(specifier)} in ${filename}`, { cause: error });
|
|
5396
5381
|
}
|
|
@@ -5857,7 +5842,7 @@ function assertInstalledRscVersions() {
|
|
|
5857
5842
|
}
|
|
5858
5843
|
|
|
5859
5844
|
// src/rsc/build/client-references.ts
|
|
5860
|
-
import { dirname as
|
|
5845
|
+
import { dirname as dirname7 } from "path";
|
|
5861
5846
|
|
|
5862
5847
|
// ../../node_modules/.bun/cjs-module-lexer@2.3.0/node_modules/cjs-module-lexer/dist/lexer.mjs
|
|
5863
5848
|
var A;
|
|
@@ -6042,9 +6027,9 @@ function initSync() {
|
|
|
6042
6027
|
import { readFileSync as readFileSync2 } from "fs";
|
|
6043
6028
|
|
|
6044
6029
|
// src/rsc/build/paths.ts
|
|
6045
|
-
import { dirname as
|
|
6030
|
+
import { dirname as dirname6, join as join7 } from "path";
|
|
6046
6031
|
import { fileURLToPath as fileURLToPath3 } from "url";
|
|
6047
|
-
var SOURCE_DIR =
|
|
6032
|
+
var SOURCE_DIR = dirname6(fileURLToPath3(import.meta.resolve("@teyik0/furin/rsc")));
|
|
6048
6033
|
var CLIENT_REFERENCE_RUNTIME_PATH = join7(SOURCE_DIR, "rsc/client-references.ts");
|
|
6049
6034
|
var BUNDLED_CLIENT_CODEC_PATH = join7(SOURCE_DIR, "rsc/bundled-client-codec.ts");
|
|
6050
6035
|
|
|
@@ -6167,7 +6152,7 @@ function clientReferencesPlugin(references) {
|
|
|
6167
6152
|
contents: isCommonJsModule(source, sourcePath) ? source : `${source}
|
|
6168
6153
|
${clientRegistration(sourcePath, path, prefix, references)}`,
|
|
6169
6154
|
loader: detectLoaderFromPath(sourcePath),
|
|
6170
|
-
resolveDir:
|
|
6155
|
+
resolveDir: dirname7(sourcePath)
|
|
6171
6156
|
};
|
|
6172
6157
|
});
|
|
6173
6158
|
build.onLoad({ filter: SCRIPTS }, async ({ path }) => {
|
|
@@ -6184,7 +6169,7 @@ registerClientModule(${JSON.stringify(clientModuleId(path))}, implementation);`
|
|
|
6184
6169
|
export * from ${JSON.stringify(path + IMPLEMENTATION)};
|
|
6185
6170
|
${names.length > 0 ? `export { ${names.map((name) => JSON.stringify(name)).join(", ")} } from ${JSON.stringify(path + IMPLEMENTATION)};` : ""}`,
|
|
6186
6171
|
loader: "js",
|
|
6187
|
-
resolveDir:
|
|
6172
|
+
resolveDir: dirname7(path)
|
|
6188
6173
|
};
|
|
6189
6174
|
});
|
|
6190
6175
|
}
|
|
@@ -6223,7 +6208,7 @@ async function exportedNames(source, path, visited) {
|
|
|
6223
6208
|
}
|
|
6224
6209
|
}
|
|
6225
6210
|
for (const specifier of reexports) {
|
|
6226
|
-
const dependency = Bun.resolveSync(specifier,
|
|
6211
|
+
const dependency = Bun.resolveSync(specifier, dirname7(path));
|
|
6227
6212
|
const exported = await exportedNames(await Bun.file(dependency).text(), dependency, visited);
|
|
6228
6213
|
for (const name of exported) {
|
|
6229
6214
|
if (name !== "default") {
|
|
@@ -6439,20 +6424,20 @@ function exportStaticFromBundle(path, cwd, options) {
|
|
|
6439
6424
|
// src/adapter/runtime-build.ts
|
|
6440
6425
|
import { existsSync as existsSync10, realpathSync as realpathSync4, writeFileSync as writeFileSync6 } from "fs";
|
|
6441
6426
|
import { createRequire } from "module";
|
|
6442
|
-
import { dirname as
|
|
6427
|
+
import { dirname as dirname11, isAbsolute as isAbsolute5, join as join12, relative as relative5, resolve as resolve7 } from "path";
|
|
6443
6428
|
import { fileURLToPath as fileURLToPath7 } from "url";
|
|
6444
6429
|
|
|
6445
6430
|
// src/build/client.ts
|
|
6446
6431
|
import { existsSync as existsSync9, mkdirSync as mkdirSync3 } from "fs";
|
|
6447
|
-
import { basename as basename4, dirname as
|
|
6432
|
+
import { basename as basename4, dirname as dirname10, join as join11, sep as sep2 } from "path";
|
|
6448
6433
|
import { fileURLToPath as fileURLToPath6 } from "url";
|
|
6449
6434
|
|
|
6450
6435
|
// src/plugin/client-plugin.ts
|
|
6451
|
-
import { dirname as
|
|
6436
|
+
import { dirname as dirname9, isAbsolute as isAbsolute4, resolve as resolve4 } from "path";
|
|
6452
6437
|
|
|
6453
6438
|
// src/plugin/hmr-dependencies.ts
|
|
6454
6439
|
import { readFileSync as readFileSync4 } from "fs";
|
|
6455
|
-
import { dirname as
|
|
6440
|
+
import { dirname as dirname8, isAbsolute as isAbsolute3, resolve as resolve3 } from "path";
|
|
6456
6441
|
function hmrDependencySignature(imports, filename) {
|
|
6457
6442
|
const routePath = resolve3(filename);
|
|
6458
6443
|
const visited = new Set;
|
|
@@ -6461,7 +6446,7 @@ function hmrDependencySignature(imports, filename) {
|
|
|
6461
6446
|
if (specifier === "furin" || specifier.startsWith("furin/") || specifier === "@teyik0/furin" || specifier.startsWith("@teyik0/furin/")) {
|
|
6462
6447
|
return true;
|
|
6463
6448
|
}
|
|
6464
|
-
const path = Bun.resolveSync(specifier,
|
|
6449
|
+
const path = Bun.resolveSync(specifier, dirname8(importer));
|
|
6465
6450
|
if (path === routePath) {
|
|
6466
6451
|
return false;
|
|
6467
6452
|
}
|
|
@@ -7325,11 +7310,12 @@ function stripServerCode(path, source) {
|
|
|
7325
7310
|
var ELYSIA_FILTER = /^elysia$/;
|
|
7326
7311
|
var BUN_BUILTIN_FILTER = /^bun:/;
|
|
7327
7312
|
var ANY_FILTER = /.*/;
|
|
7328
|
-
var
|
|
7313
|
+
var elysiaStub = (typeModule) => `export * as t from ${JSON.stringify(typeModule)};
|
|
7329
7314
|
export class NotFoundError extends Error { constructor(m) { super(m); this.name = "NotFoundError"; } }
|
|
7330
7315
|
export class ValidationError extends Error { constructor(m) { super(m); this.name = "ValidationError"; } }
|
|
7331
7316
|
export default {};
|
|
7332
7317
|
`;
|
|
7318
|
+
var ELYSIA_STUB_PREFIX = "elysia-stub:";
|
|
7333
7319
|
function trackHydrationTopology(filePath, source, topologyPaths) {
|
|
7334
7320
|
const normalizedPath = filePath.replaceAll("\\", "/");
|
|
7335
7321
|
if (!(normalizedPath.includes("/.furin/") && normalizedPath.endsWith("/_hydrate.tsx"))) {
|
|
@@ -7338,7 +7324,7 @@ function trackHydrationTopology(filePath, source, topologyPaths) {
|
|
|
7338
7324
|
const transpiler = new Bun.Transpiler({ loader: "tsx" });
|
|
7339
7325
|
for (const imported of transpiler.scanImports(source)) {
|
|
7340
7326
|
if (isAbsolute4(imported.path) || imported.path.startsWith(".")) {
|
|
7341
|
-
topologyPaths.add(resolve4(
|
|
7327
|
+
topologyPaths.add(resolve4(dirname9(filePath), imported.path.split("?")[0]));
|
|
7342
7328
|
}
|
|
7343
7329
|
}
|
|
7344
7330
|
}
|
|
@@ -7367,16 +7353,16 @@ function createClientStripPlugin({ mode }) {
|
|
|
7367
7353
|
environmentGuardPlugin("client").setup(build);
|
|
7368
7354
|
const topologyPaths = new Set;
|
|
7369
7355
|
const loadedSources = new Map;
|
|
7370
|
-
build.onResolve({ filter: ELYSIA_FILTER }, () => ({
|
|
7356
|
+
build.onResolve({ filter: ELYSIA_FILTER }, (args) => ({
|
|
7371
7357
|
namespace: "furin-stubs",
|
|
7372
|
-
path: "elysia
|
|
7358
|
+
path: ELYSIA_STUB_PREFIX + Bun.resolveSync("elysia/type", args.resolveDir)
|
|
7373
7359
|
}));
|
|
7374
7360
|
build.onResolve({ filter: BUN_BUILTIN_FILTER }, () => ({
|
|
7375
7361
|
namespace: "furin-stubs",
|
|
7376
7362
|
path: "bun-builtin-stub"
|
|
7377
7363
|
}));
|
|
7378
7364
|
build.onLoad({ filter: ANY_FILTER, namespace: "furin-stubs" }, (args) => ({
|
|
7379
|
-
contents: args.path
|
|
7365
|
+
contents: args.path.startsWith(ELYSIA_STUB_PREFIX) ? elysiaStub(args.path.slice(ELYSIA_STUB_PREFIX.length)) : "",
|
|
7380
7366
|
loader: "js"
|
|
7381
7367
|
}));
|
|
7382
7368
|
build.onLoad({ filter: SCRIPT_FILE_FILTER }, async (args) => {
|
|
@@ -8030,6 +8016,7 @@ if (__deferred && __deferred._chunks) {
|
|
|
8030
8016
|
// with the server (stale deploy) or the server returned something we
|
|
8031
8017
|
// don't know how to hydrate. Bail loudly; the page stays static.
|
|
8032
8018
|
log.error({ action: "hydrate_no_match", pathname });
|
|
8019
|
+
if (import.meta.hot) throw new Error(\`[furin] No client route matches \${pathname}; the page stays static.\`);
|
|
8033
8020
|
return;
|
|
8034
8021
|
}
|
|
8035
8022
|
app = createElement(DocumentProvider, { value: documentState }, app);
|
|
@@ -8096,6 +8083,7 @@ if (__deferred && __deferred._chunks) {
|
|
|
8096
8083
|
log.info({ action: "hydrate_complete", pathname });
|
|
8097
8084
|
})().catch((err: unknown) => {
|
|
8098
8085
|
log.error({ action: "hydrate_failed", pathname, error: String(err) });
|
|
8086
|
+
if (import.meta.hot) console.error("[furin] Hydration failed:", err);
|
|
8099
8087
|
window.dispatchEvent(
|
|
8100
8088
|
new CustomEvent("furin:client-error", { detail: { error: err, phase: "hydrate" } })
|
|
8101
8089
|
);
|
|
@@ -8160,7 +8148,7 @@ function writeClientPreloadManifest(metafile, outputPaths, entryChunkPath, route
|
|
|
8160
8148
|
}
|
|
8161
8149
|
|
|
8162
8150
|
// src/build/client.ts
|
|
8163
|
-
var CLIENT_DIST_DIR = `${join11(
|
|
8151
|
+
var CLIENT_DIST_DIR = `${join11(dirname10(dirname10(fileURLToPath6(import.meta.resolve("@teyik0/furin")))), "dist")}${sep2}`;
|
|
8164
8152
|
async function buildClient(routes, {
|
|
8165
8153
|
outDir,
|
|
8166
8154
|
rootLayout,
|
|
@@ -8263,7 +8251,7 @@ async function buildClient(routes, {
|
|
|
8263
8251
|
}
|
|
8264
8252
|
|
|
8265
8253
|
// src/adapter/runtime-build.ts
|
|
8266
|
-
var _pkgRoot2 =
|
|
8254
|
+
var _pkgRoot2 = dirname11(dirname11(fileURLToPath7(import.meta.resolve("@teyik0/furin"))));
|
|
8267
8255
|
var _pkgSrcDir2 = existsSync10(join12(_pkgRoot2, "src", "furin.ts")) ? join12(_pkgRoot2, "src") : join12(_pkgRoot2, "dist");
|
|
8268
8256
|
var _ext2 = ".ts";
|
|
8269
8257
|
function frameworkSourceModule(path) {
|
|
@@ -8325,7 +8313,7 @@ function nearestFingerprintFile(directory, names, boundary) {
|
|
|
8325
8313
|
return path;
|
|
8326
8314
|
}
|
|
8327
8315
|
}
|
|
8328
|
-
const parent =
|
|
8316
|
+
const parent = dirname11(current);
|
|
8329
8317
|
current = parent === current || current === boundary ? undefined : parent;
|
|
8330
8318
|
}
|
|
8331
8319
|
return;
|
|
@@ -8380,7 +8368,7 @@ async function createBuildFingerprint(entryChunk, cssChunks, routes, root, serve
|
|
|
8380
8368
|
}
|
|
8381
8369
|
const relativePath = toPosixPath(relative5(rootBoundary, path));
|
|
8382
8370
|
const manifestBoundary = relativePath === ".." || relativePath.startsWith("../") || isAbsolute5(relativePath) ? undefined : rootBoundary;
|
|
8383
|
-
const manifest = nearestFingerprintFile(
|
|
8371
|
+
const manifest = nearestFingerprintFile(dirname11(path), ["package.json"], manifestBoundary);
|
|
8384
8372
|
if (manifest) {
|
|
8385
8373
|
fingerprintPaths.add(manifest);
|
|
8386
8374
|
await visit(manifest);
|
|
@@ -8389,7 +8377,7 @@ async function createBuildFingerprint(entryChunk, cssChunks, routes, root, serve
|
|
|
8389
8377
|
await Promise.all(transpiler.scanImports(content).flatMap(({ path: specifier, kind }) => {
|
|
8390
8378
|
let dependency;
|
|
8391
8379
|
try {
|
|
8392
|
-
dependency = kind === "require-call" || kind === "require-resolve" ? createRequire(path).resolve(specifier) : Bun.resolveSync(specifier,
|
|
8380
|
+
dependency = kind === "require-call" || kind === "require-resolve" ? createRequire(path).resolve(specifier) : Bun.resolveSync(specifier, dirname11(path));
|
|
8393
8381
|
} catch {
|
|
8394
8382
|
return [];
|
|
8395
8383
|
}
|
|
@@ -8473,7 +8461,7 @@ function pprRuntimePlugin(apps) {
|
|
|
8473
8461
|
return;
|
|
8474
8462
|
}
|
|
8475
8463
|
build.onResolve({ filter: PPR_ROUTE_IMPORT_RE }, ({ path, importer }) => {
|
|
8476
|
-
const absolute = resolve7(
|
|
8464
|
+
const absolute = resolve7(dirname11(importer.split("?")[0]), path);
|
|
8477
8465
|
if (absolute !== pprPath && `${absolute}.ts` !== pprPath) {
|
|
8478
8466
|
return;
|
|
8479
8467
|
}
|
|
@@ -8499,7 +8487,7 @@ function mixedRuntimePlugin(apps) {
|
|
|
8499
8487
|
return;
|
|
8500
8488
|
}
|
|
8501
8489
|
build.onResolve({ filter: MIXED_CACHE_IMPORT_RE }, ({ path, importer }) => {
|
|
8502
|
-
const absolute = resolve7(
|
|
8490
|
+
const absolute = resolve7(dirname11(importer.split("?")[0]), path);
|
|
8503
8491
|
if (absolute !== mixedPath && `${absolute}.ts` !== mixedPath) {
|
|
8504
8492
|
return;
|
|
8505
8493
|
}
|
|
@@ -8529,7 +8517,7 @@ async function buildRuntimeApp(app, projectRoot, targetDir, serverEntry, options
|
|
|
8529
8517
|
basePath: prefix,
|
|
8530
8518
|
clientDirName,
|
|
8531
8519
|
clientLogging: options.clientLogging ?? false,
|
|
8532
|
-
metafilePath: options.analyze ? join12(
|
|
8520
|
+
metafilePath: options.analyze ? join12(dirname11(targetDir), "analysis", `${targetName}-${clientDirName}.json`) : undefined,
|
|
8533
8521
|
optimizeImports: options.optimizeImports,
|
|
8534
8522
|
outDir: targetDir,
|
|
8535
8523
|
pages: { pagesDir: app.pagesDir, style: app.style },
|
|
@@ -8572,16 +8560,16 @@ ${entryChunk}`, cssChunks, routes, root, serverEntry, modulePaths, projectRoot);
|
|
|
8572
8560
|
}
|
|
8573
8561
|
|
|
8574
8562
|
// src/adapter/server-bundle.ts
|
|
8575
|
-
import { dirname as
|
|
8563
|
+
import { dirname as dirname14, relative as relative8 } from "path";
|
|
8576
8564
|
|
|
8577
8565
|
// src/build/elysia-aot.ts
|
|
8578
8566
|
import { fork } from "child_process";
|
|
8579
8567
|
import { existsSync as existsSync11, realpathSync as realpathSync5 } from "fs";
|
|
8580
|
-
import { dirname as
|
|
8568
|
+
import { dirname as dirname12, join as join13, relative as relative6, resolve as resolve8 } from "path";
|
|
8581
8569
|
import { fileURLToPath as fileURLToPath8 } from "url";
|
|
8582
8570
|
var AOT_NAMESPACE = "furin-elysia-aot";
|
|
8583
|
-
var ELYSIA_RESOLVE_DIR =
|
|
8584
|
-
var AOT_PROCESS_PATH = join13(
|
|
8571
|
+
var ELYSIA_RESOLVE_DIR = dirname12(Bun.resolveSync("elysia", import.meta.dir));
|
|
8572
|
+
var AOT_PROCESS_PATH = join13(dirname12(dirname12(fileURLToPath8(import.meta.resolve("@teyik0/furin")))), "src/build/elysia-aot-worker.ts");
|
|
8585
8573
|
var SOURCE_FILTER = /\.[cm]?[jt]sx?$/;
|
|
8586
8574
|
var ELYSIA_IMPORT_FILTER = /^elysia(?:\/(?!compiled$|type$).*)?$/;
|
|
8587
8575
|
var ELYSIA_VIRTUAL_IMPORT_FILTER = /^elysia\/(?:compiled|type)$/;
|
|
@@ -8775,7 +8763,7 @@ function elysiaAot(entry, expected) {
|
|
|
8775
8763
|
}
|
|
8776
8764
|
|
|
8777
8765
|
// src/build/production-instrumentation.ts
|
|
8778
|
-
import { dirname as
|
|
8766
|
+
import { dirname as dirname13, relative as relative7, resolve as resolve9 } from "path";
|
|
8779
8767
|
var INSTRUMENTATION_IMPORT = /(?:^|[/\\])devtools[/\\]instrumentation(?:\.ts|\.js)?$/;
|
|
8780
8768
|
var DEV_PAGE_PLUGIN_IMPORT = /(?:^|[/\\])server[/\\]dev-page-plugin(?:\.ts|\.js)?$/;
|
|
8781
8769
|
var DEV_RUNTIME_IMPORT = /(?:^|[/\\])server[/\\]dev[/\\](?:browser-events|diagnostics|graph|plugin|runtime)(?:\.ts|\.js)?$/;
|
|
@@ -8802,7 +8790,7 @@ function productionInstrumentationPlugin() {
|
|
|
8802
8790
|
name: "furin-production-instrumentation",
|
|
8803
8791
|
setup(build) {
|
|
8804
8792
|
build.onResolve({ filter: PRODUCTION_BOUNDARY_IMPORT }, (args) => {
|
|
8805
|
-
const importPath = resolve9(
|
|
8793
|
+
const importPath = resolve9(dirname13(args.importer), args.path);
|
|
8806
8794
|
if (!isFurinRuntimePath(importPath)) {
|
|
8807
8795
|
return;
|
|
8808
8796
|
}
|
|
@@ -8838,7 +8826,7 @@ var PRERENDER_SNAPSHOT_RE = /^\.\/furin-prerender\.json$/;
|
|
|
8838
8826
|
var ELYSIA_STATIC_IMPORT_RE = /^@elysia\/static$/;
|
|
8839
8827
|
var MATCH_ALL_RE = /.*/;
|
|
8840
8828
|
var STATIC_STUB_NAMESPACE = "furin-platform-assets-stub";
|
|
8841
|
-
var FURIN_RUNTIME_ROOT2 =
|
|
8829
|
+
var FURIN_RUNTIME_ROOT2 = dirname14(import.meta.dir);
|
|
8842
8830
|
function isFurinRuntimeImporter(importer) {
|
|
8843
8831
|
if (importer === "") {
|
|
8844
8832
|
return false;
|
|
@@ -9271,7 +9259,7 @@ export declare const prefix: string;
|
|
|
9271
9259
|
|
|
9272
9260
|
// src/adapter/static.ts
|
|
9273
9261
|
import { cpSync as cpSync2, existsSync as existsSync15, rmSync as rmSync6, writeFileSync as writeFileSync9 } from "fs";
|
|
9274
|
-
import { dirname as
|
|
9262
|
+
import { dirname as dirname15, isAbsolute as isAbsolute6, join as join17, parse as parse3, relative as relative12, resolve as resolve11, sep as sep3, win32 } from "path";
|
|
9275
9263
|
var TRAILING_SLASHES_RE = /\/+$/;
|
|
9276
9264
|
var STATIC_RENDER_ORIGIN = "http://localhost";
|
|
9277
9265
|
function pathToOutputFile(urlPath, outDir, fileName) {
|
|
@@ -9396,7 +9384,7 @@ async function collectStaticOutputs(exported, outDir, basePath, onSSR, skippedRo
|
|
|
9396
9384
|
return outputs;
|
|
9397
9385
|
}
|
|
9398
9386
|
function writeStaticOutput(output) {
|
|
9399
|
-
ensureDir(
|
|
9387
|
+
ensureDir(dirname15(output.htmlFile));
|
|
9400
9388
|
writeFileSync9(output.htmlFile, output.html);
|
|
9401
9389
|
if (output.data !== null) {
|
|
9402
9390
|
writeFileSync9(output.dataFile, output.data);
|
|
@@ -9595,7 +9583,7 @@ import {
|
|
|
9595
9583
|
symlinkSync,
|
|
9596
9584
|
writeFileSync as writeFileSync10
|
|
9597
9585
|
} from "fs";
|
|
9598
|
-
import { basename as basename6, dirname as
|
|
9586
|
+
import { basename as basename6, dirname as dirname16, join as join18, relative as relative13 } from "path";
|
|
9599
9587
|
import { fileURLToPath as fileURLToPath9, pathToFileURL as pathToFileURL3 } from "url";
|
|
9600
9588
|
|
|
9601
9589
|
// src/adapter/vercel/data.ts
|
|
@@ -9640,7 +9628,7 @@ function assertRegions(regions) {
|
|
|
9640
9628
|
}
|
|
9641
9629
|
}
|
|
9642
9630
|
function frameworkVersion() {
|
|
9643
|
-
const packageRoot =
|
|
9631
|
+
const packageRoot = dirname16(dirname16(fileURLToPath9(import.meta.resolve("@teyik0/furin"))));
|
|
9644
9632
|
const packageJson = JSON.parse(readFileSync8(join18(packageRoot, "package.json"), "utf8"));
|
|
9645
9633
|
return packageJson.version;
|
|
9646
9634
|
}
|
|
@@ -9781,8 +9769,8 @@ async function addPrerenderFallback(job, response, functionsDir) {
|
|
|
9781
9769
|
const { spec } = job;
|
|
9782
9770
|
const fallback = `${basename6(spec.functionName)}.prerender-fallback.html`;
|
|
9783
9771
|
const location = response.headers.get("location") ?? undefined;
|
|
9784
|
-
const fallbackPath = join18(
|
|
9785
|
-
ensureDir(
|
|
9772
|
+
const fallbackPath = join18(dirname16(join18(functionsDir, spec.functionName)), fallback);
|
|
9773
|
+
ensureDir(dirname16(fallbackPath));
|
|
9786
9774
|
writeFileSync10(fallbackPath, await response.text());
|
|
9787
9775
|
spec.config.fallback = fallback;
|
|
9788
9776
|
spec.config.initialHeaders = {
|
|
@@ -9856,8 +9844,8 @@ async function buildBootstrap(serverFunctionDir) {
|
|
|
9856
9844
|
}
|
|
9857
9845
|
function createFunctionAlias(functionsDir, serverFunctionDir, functionName) {
|
|
9858
9846
|
const aliasPath = join18(functionsDir, `${functionName}.func`);
|
|
9859
|
-
ensureDir(
|
|
9860
|
-
const target = relative13(
|
|
9847
|
+
ensureDir(dirname16(aliasPath));
|
|
9848
|
+
const target = relative13(dirname16(aliasPath), serverFunctionDir);
|
|
9861
9849
|
symlinkSync(target, aliasPath, process.platform === "win32" ? "junction" : "dir");
|
|
9862
9850
|
}
|
|
9863
9851
|
function copyStaticAssets(output, staticDir) {
|
package/dist/cli/index.js
CHANGED
|
@@ -1748,7 +1748,7 @@ import { writeFileSync as writeFileSync2 } from "fs";
|
|
|
1748
1748
|
import { join as join6 } from "path";
|
|
1749
1749
|
|
|
1750
1750
|
// src/plugin/route-registry.ts
|
|
1751
|
-
import {
|
|
1751
|
+
import { join as join5, resolve as resolve2 } from "path";
|
|
1752
1752
|
|
|
1753
1753
|
// src/plugin/route-modules.ts
|
|
1754
1754
|
import { existsSync as existsSync5, readFileSync, realpathSync, statSync } from "fs";
|
|
@@ -2238,7 +2238,6 @@ var ROUTES_REGISTRY_SPECIFIER = "furin/routes?registry";
|
|
|
2238
2238
|
var COMPOSABLE_ROUTES_REGISTRY_SPECIFIER = "furin/routes?registry=composable";
|
|
2239
2239
|
var ROUTES_REGISTRY_FILTER = /^furin\/routes\?registry(?:=composable)?$/;
|
|
2240
2240
|
var ROUTE_FILE_FILTER = /^furin-route-file:.+$/;
|
|
2241
|
-
var ROUTE_FILES_NAMESPACE = "furin-route-files";
|
|
2242
2241
|
var ROUTES_REGISTRY_FILE_FILTER = /[\\/]\.furin-routes-registry(?:-composable)?\.ts\?furin-virtual$/;
|
|
2243
2242
|
var CLIENT_ROUTES_NAMESPACE = "furin-routes-client";
|
|
2244
2243
|
var CLIENT_ROUTES_FILTER = /^(?:@teyik0\/furin|furin)\/routes$/;
|
|
@@ -2370,7 +2369,6 @@ function serverProxySource(instance, includeRootCatchAll) {
|
|
|
2370
2369
|
}
|
|
2371
2370
|
function createRoutesPlugin(options) {
|
|
2372
2371
|
const routeFilesBySpecifier = new Map;
|
|
2373
|
-
const routeFilesByResolvedPath = new Map;
|
|
2374
2372
|
const registryVirtualPath = join5(resolve2(primaryInstance(options.instances).pagesDir), ".furin-routes-registry.ts?furin-virtual");
|
|
2375
2373
|
const composableRegistryVirtualPath = join5(resolve2(primaryInstance(options.instances).pagesDir), ".furin-routes-registry-composable.ts?furin-virtual");
|
|
2376
2374
|
const instancesBySpecifier = new Map(options.instances.flatMap((instance) => [
|
|
@@ -2422,20 +2420,7 @@ function createRoutesPlugin(options) {
|
|
|
2422
2420
|
if (!routeFile) {
|
|
2423
2421
|
throw new Error(`[furin] Unknown route module: ${path}`);
|
|
2424
2422
|
}
|
|
2425
|
-
|
|
2426
|
-
routeFilesByResolvedPath.set(resolvedPath, routeFile);
|
|
2427
|
-
return { namespace: ROUTE_FILES_NAMESPACE, path: resolvedPath };
|
|
2428
|
-
});
|
|
2429
|
-
build.onLoad({ filter: VIRTUAL_ROUTES_FILTER, namespace: ROUTE_FILES_NAMESPACE }, async ({ path }) => {
|
|
2430
|
-
const routeFile = routeFilesByResolvedPath.get(path);
|
|
2431
|
-
if (!routeFile) {
|
|
2432
|
-
throw new Error(`[furin] Unknown route module: ${path}`);
|
|
2433
|
-
}
|
|
2434
|
-
return {
|
|
2435
|
-
contents: await Bun.file(routeFile.sourcePath).text(),
|
|
2436
|
-
loader: detectLoaderFromPath(routeFile.sourcePath),
|
|
2437
|
-
resolveDir: dirname5(routeFile.sourcePath)
|
|
2438
|
-
};
|
|
2423
|
+
return { path: routeFile.sourcePath };
|
|
2439
2424
|
});
|
|
2440
2425
|
for (const { instance, namespace, includeRootCatchAll } of instancesBySpecifier.values()) {
|
|
2441
2426
|
build.onLoad({ filter: VIRTUAL_ROUTES_FILTER, namespace }, () => ({
|
|
@@ -5342,7 +5327,7 @@ function pruneOrphanedCode(module, forced, retained) {
|
|
|
5342
5327
|
|
|
5343
5328
|
// src/plugin/transform-client-module.ts
|
|
5344
5329
|
import { realpathSync as realpathSync2 } from "fs";
|
|
5345
|
-
import { dirname as
|
|
5330
|
+
import { dirname as dirname5 } from "path";
|
|
5346
5331
|
var FURIN_CLIENT_MODULES = new Set(["@teyik0/furin/client", "furin/client"]);
|
|
5347
5332
|
var SERVER_LOAD = '() => Promise.reject(new Error("[furin] clientModule() can only be loaded in the browser."))';
|
|
5348
5333
|
function clientModuleKey(modulePath) {
|
|
@@ -5397,7 +5382,7 @@ function rewriteClientModules(module, environment) {
|
|
|
5397
5382
|
}
|
|
5398
5383
|
let key;
|
|
5399
5384
|
try {
|
|
5400
|
-
key = JSON.stringify(clientModuleKey(Bun.resolveSync(specifier,
|
|
5385
|
+
key = JSON.stringify(clientModuleKey(Bun.resolveSync(specifier, dirname5(filename))));
|
|
5401
5386
|
} catch (error) {
|
|
5402
5387
|
throw new Error(`[furin] Cannot resolve clientModule import ${JSON.stringify(specifier)} in ${filename}`, { cause: error });
|
|
5403
5388
|
}
|
|
@@ -5864,7 +5849,7 @@ function assertInstalledRscVersions() {
|
|
|
5864
5849
|
}
|
|
5865
5850
|
|
|
5866
5851
|
// src/rsc/build/client-references.ts
|
|
5867
|
-
import { dirname as
|
|
5852
|
+
import { dirname as dirname7 } from "path";
|
|
5868
5853
|
|
|
5869
5854
|
// ../../node_modules/.bun/cjs-module-lexer@2.3.0/node_modules/cjs-module-lexer/dist/lexer.mjs
|
|
5870
5855
|
var A;
|
|
@@ -6049,9 +6034,9 @@ function initSync() {
|
|
|
6049
6034
|
import { readFileSync as readFileSync2 } from "fs";
|
|
6050
6035
|
|
|
6051
6036
|
// src/rsc/build/paths.ts
|
|
6052
|
-
import { dirname as
|
|
6037
|
+
import { dirname as dirname6, join as join7 } from "path";
|
|
6053
6038
|
import { fileURLToPath as fileURLToPath3 } from "url";
|
|
6054
|
-
var SOURCE_DIR =
|
|
6039
|
+
var SOURCE_DIR = dirname6(fileURLToPath3(import.meta.resolve("@teyik0/furin/rsc")));
|
|
6055
6040
|
var CLIENT_REFERENCE_RUNTIME_PATH = join7(SOURCE_DIR, "rsc/client-references.ts");
|
|
6056
6041
|
var BUNDLED_CLIENT_CODEC_PATH = join7(SOURCE_DIR, "rsc/bundled-client-codec.ts");
|
|
6057
6042
|
|
|
@@ -6174,7 +6159,7 @@ function clientReferencesPlugin(references) {
|
|
|
6174
6159
|
contents: isCommonJsModule(source, sourcePath) ? source : `${source}
|
|
6175
6160
|
${clientRegistration(sourcePath, path, prefix, references)}`,
|
|
6176
6161
|
loader: detectLoaderFromPath(sourcePath),
|
|
6177
|
-
resolveDir:
|
|
6162
|
+
resolveDir: dirname7(sourcePath)
|
|
6178
6163
|
};
|
|
6179
6164
|
});
|
|
6180
6165
|
build.onLoad({ filter: SCRIPTS }, async ({ path }) => {
|
|
@@ -6191,7 +6176,7 @@ registerClientModule(${JSON.stringify(clientModuleId(path))}, implementation);`
|
|
|
6191
6176
|
export * from ${JSON.stringify(path + IMPLEMENTATION)};
|
|
6192
6177
|
${names.length > 0 ? `export { ${names.map((name) => JSON.stringify(name)).join(", ")} } from ${JSON.stringify(path + IMPLEMENTATION)};` : ""}`,
|
|
6193
6178
|
loader: "js",
|
|
6194
|
-
resolveDir:
|
|
6179
|
+
resolveDir: dirname7(path)
|
|
6195
6180
|
};
|
|
6196
6181
|
});
|
|
6197
6182
|
}
|
|
@@ -6230,7 +6215,7 @@ async function exportedNames(source, path, visited) {
|
|
|
6230
6215
|
}
|
|
6231
6216
|
}
|
|
6232
6217
|
for (const specifier of reexports) {
|
|
6233
|
-
const dependency = Bun.resolveSync(specifier,
|
|
6218
|
+
const dependency = Bun.resolveSync(specifier, dirname7(path));
|
|
6234
6219
|
const exported = await exportedNames(await Bun.file(dependency).text(), dependency, visited);
|
|
6235
6220
|
for (const name of exported) {
|
|
6236
6221
|
if (name !== "default") {
|
|
@@ -6446,20 +6431,20 @@ function exportStaticFromBundle(path, cwd, options) {
|
|
|
6446
6431
|
// src/adapter/runtime-build.ts
|
|
6447
6432
|
import { existsSync as existsSync10, realpathSync as realpathSync4, writeFileSync as writeFileSync6 } from "fs";
|
|
6448
6433
|
import { createRequire } from "module";
|
|
6449
|
-
import { dirname as
|
|
6434
|
+
import { dirname as dirname11, isAbsolute as isAbsolute5, join as join12, relative as relative5, resolve as resolve7 } from "path";
|
|
6450
6435
|
import { fileURLToPath as fileURLToPath7 } from "url";
|
|
6451
6436
|
|
|
6452
6437
|
// src/build/client.ts
|
|
6453
6438
|
import { existsSync as existsSync9, mkdirSync as mkdirSync3 } from "fs";
|
|
6454
|
-
import { basename as basename4, dirname as
|
|
6439
|
+
import { basename as basename4, dirname as dirname10, join as join11, sep as sep2 } from "path";
|
|
6455
6440
|
import { fileURLToPath as fileURLToPath6 } from "url";
|
|
6456
6441
|
|
|
6457
6442
|
// src/plugin/client-plugin.ts
|
|
6458
|
-
import { dirname as
|
|
6443
|
+
import { dirname as dirname9, isAbsolute as isAbsolute4, resolve as resolve4 } from "path";
|
|
6459
6444
|
|
|
6460
6445
|
// src/plugin/hmr-dependencies.ts
|
|
6461
6446
|
import { readFileSync as readFileSync4 } from "fs";
|
|
6462
|
-
import { dirname as
|
|
6447
|
+
import { dirname as dirname8, isAbsolute as isAbsolute3, resolve as resolve3 } from "path";
|
|
6463
6448
|
function hmrDependencySignature(imports, filename) {
|
|
6464
6449
|
const routePath = resolve3(filename);
|
|
6465
6450
|
const visited = new Set;
|
|
@@ -6468,7 +6453,7 @@ function hmrDependencySignature(imports, filename) {
|
|
|
6468
6453
|
if (specifier === "furin" || specifier.startsWith("furin/") || specifier === "@teyik0/furin" || specifier.startsWith("@teyik0/furin/")) {
|
|
6469
6454
|
return true;
|
|
6470
6455
|
}
|
|
6471
|
-
const path = Bun.resolveSync(specifier,
|
|
6456
|
+
const path = Bun.resolveSync(specifier, dirname8(importer));
|
|
6472
6457
|
if (path === routePath) {
|
|
6473
6458
|
return false;
|
|
6474
6459
|
}
|
|
@@ -7332,11 +7317,12 @@ function stripServerCode(path, source) {
|
|
|
7332
7317
|
var ELYSIA_FILTER = /^elysia$/;
|
|
7333
7318
|
var BUN_BUILTIN_FILTER = /^bun:/;
|
|
7334
7319
|
var ANY_FILTER = /.*/;
|
|
7335
|
-
var
|
|
7320
|
+
var elysiaStub = (typeModule) => `export * as t from ${JSON.stringify(typeModule)};
|
|
7336
7321
|
export class NotFoundError extends Error { constructor(m) { super(m); this.name = "NotFoundError"; } }
|
|
7337
7322
|
export class ValidationError extends Error { constructor(m) { super(m); this.name = "ValidationError"; } }
|
|
7338
7323
|
export default {};
|
|
7339
7324
|
`;
|
|
7325
|
+
var ELYSIA_STUB_PREFIX = "elysia-stub:";
|
|
7340
7326
|
function trackHydrationTopology(filePath, source, topologyPaths) {
|
|
7341
7327
|
const normalizedPath = filePath.replaceAll("\\", "/");
|
|
7342
7328
|
if (!(normalizedPath.includes("/.furin/") && normalizedPath.endsWith("/_hydrate.tsx"))) {
|
|
@@ -7345,7 +7331,7 @@ function trackHydrationTopology(filePath, source, topologyPaths) {
|
|
|
7345
7331
|
const transpiler = new Bun.Transpiler({ loader: "tsx" });
|
|
7346
7332
|
for (const imported of transpiler.scanImports(source)) {
|
|
7347
7333
|
if (isAbsolute4(imported.path) || imported.path.startsWith(".")) {
|
|
7348
|
-
topologyPaths.add(resolve4(
|
|
7334
|
+
topologyPaths.add(resolve4(dirname9(filePath), imported.path.split("?")[0]));
|
|
7349
7335
|
}
|
|
7350
7336
|
}
|
|
7351
7337
|
}
|
|
@@ -7374,16 +7360,16 @@ function createClientStripPlugin({ mode }) {
|
|
|
7374
7360
|
environmentGuardPlugin("client").setup(build);
|
|
7375
7361
|
const topologyPaths = new Set;
|
|
7376
7362
|
const loadedSources = new Map;
|
|
7377
|
-
build.onResolve({ filter: ELYSIA_FILTER }, () => ({
|
|
7363
|
+
build.onResolve({ filter: ELYSIA_FILTER }, (args) => ({
|
|
7378
7364
|
namespace: "furin-stubs",
|
|
7379
|
-
path: "elysia
|
|
7365
|
+
path: ELYSIA_STUB_PREFIX + Bun.resolveSync("elysia/type", args.resolveDir)
|
|
7380
7366
|
}));
|
|
7381
7367
|
build.onResolve({ filter: BUN_BUILTIN_FILTER }, () => ({
|
|
7382
7368
|
namespace: "furin-stubs",
|
|
7383
7369
|
path: "bun-builtin-stub"
|
|
7384
7370
|
}));
|
|
7385
7371
|
build.onLoad({ filter: ANY_FILTER, namespace: "furin-stubs" }, (args) => ({
|
|
7386
|
-
contents: args.path
|
|
7372
|
+
contents: args.path.startsWith(ELYSIA_STUB_PREFIX) ? elysiaStub(args.path.slice(ELYSIA_STUB_PREFIX.length)) : "",
|
|
7387
7373
|
loader: "js"
|
|
7388
7374
|
}));
|
|
7389
7375
|
build.onLoad({ filter: SCRIPT_FILE_FILTER }, async (args) => {
|
|
@@ -8037,6 +8023,7 @@ if (__deferred && __deferred._chunks) {
|
|
|
8037
8023
|
// with the server (stale deploy) or the server returned something we
|
|
8038
8024
|
// don't know how to hydrate. Bail loudly; the page stays static.
|
|
8039
8025
|
log.error({ action: "hydrate_no_match", pathname });
|
|
8026
|
+
if (import.meta.hot) throw new Error(\`[furin] No client route matches \${pathname}; the page stays static.\`);
|
|
8040
8027
|
return;
|
|
8041
8028
|
}
|
|
8042
8029
|
app = createElement(DocumentProvider, { value: documentState }, app);
|
|
@@ -8103,6 +8090,7 @@ if (__deferred && __deferred._chunks) {
|
|
|
8103
8090
|
log.info({ action: "hydrate_complete", pathname });
|
|
8104
8091
|
})().catch((err: unknown) => {
|
|
8105
8092
|
log.error({ action: "hydrate_failed", pathname, error: String(err) });
|
|
8093
|
+
if (import.meta.hot) console.error("[furin] Hydration failed:", err);
|
|
8106
8094
|
window.dispatchEvent(
|
|
8107
8095
|
new CustomEvent("furin:client-error", { detail: { error: err, phase: "hydrate" } })
|
|
8108
8096
|
);
|
|
@@ -8167,7 +8155,7 @@ function writeClientPreloadManifest(metafile, outputPaths, entryChunkPath, route
|
|
|
8167
8155
|
}
|
|
8168
8156
|
|
|
8169
8157
|
// src/build/client.ts
|
|
8170
|
-
var CLIENT_DIST_DIR = `${join11(
|
|
8158
|
+
var CLIENT_DIST_DIR = `${join11(dirname10(dirname10(fileURLToPath6(import.meta.resolve("@teyik0/furin")))), "dist")}${sep2}`;
|
|
8171
8159
|
async function buildClient(routes, {
|
|
8172
8160
|
outDir,
|
|
8173
8161
|
rootLayout,
|
|
@@ -8270,7 +8258,7 @@ async function buildClient(routes, {
|
|
|
8270
8258
|
}
|
|
8271
8259
|
|
|
8272
8260
|
// src/adapter/runtime-build.ts
|
|
8273
|
-
var _pkgRoot2 =
|
|
8261
|
+
var _pkgRoot2 = dirname11(dirname11(fileURLToPath7(import.meta.resolve("@teyik0/furin"))));
|
|
8274
8262
|
var _pkgSrcDir2 = existsSync10(join12(_pkgRoot2, "src", "furin.ts")) ? join12(_pkgRoot2, "src") : join12(_pkgRoot2, "dist");
|
|
8275
8263
|
var _ext2 = ".ts";
|
|
8276
8264
|
function frameworkSourceModule(path) {
|
|
@@ -8332,7 +8320,7 @@ function nearestFingerprintFile(directory, names, boundary) {
|
|
|
8332
8320
|
return path;
|
|
8333
8321
|
}
|
|
8334
8322
|
}
|
|
8335
|
-
const parent =
|
|
8323
|
+
const parent = dirname11(current);
|
|
8336
8324
|
current = parent === current || current === boundary ? undefined : parent;
|
|
8337
8325
|
}
|
|
8338
8326
|
return;
|
|
@@ -8387,7 +8375,7 @@ async function createBuildFingerprint(entryChunk, cssChunks, routes, root, serve
|
|
|
8387
8375
|
}
|
|
8388
8376
|
const relativePath = toPosixPath(relative5(rootBoundary, path));
|
|
8389
8377
|
const manifestBoundary = relativePath === ".." || relativePath.startsWith("../") || isAbsolute5(relativePath) ? undefined : rootBoundary;
|
|
8390
|
-
const manifest = nearestFingerprintFile(
|
|
8378
|
+
const manifest = nearestFingerprintFile(dirname11(path), ["package.json"], manifestBoundary);
|
|
8391
8379
|
if (manifest) {
|
|
8392
8380
|
fingerprintPaths.add(manifest);
|
|
8393
8381
|
await visit(manifest);
|
|
@@ -8396,7 +8384,7 @@ async function createBuildFingerprint(entryChunk, cssChunks, routes, root, serve
|
|
|
8396
8384
|
await Promise.all(transpiler.scanImports(content).flatMap(({ path: specifier, kind }) => {
|
|
8397
8385
|
let dependency;
|
|
8398
8386
|
try {
|
|
8399
|
-
dependency = kind === "require-call" || kind === "require-resolve" ? createRequire(path).resolve(specifier) : Bun.resolveSync(specifier,
|
|
8387
|
+
dependency = kind === "require-call" || kind === "require-resolve" ? createRequire(path).resolve(specifier) : Bun.resolveSync(specifier, dirname11(path));
|
|
8400
8388
|
} catch {
|
|
8401
8389
|
return [];
|
|
8402
8390
|
}
|
|
@@ -8480,7 +8468,7 @@ function pprRuntimePlugin(apps) {
|
|
|
8480
8468
|
return;
|
|
8481
8469
|
}
|
|
8482
8470
|
build.onResolve({ filter: PPR_ROUTE_IMPORT_RE }, ({ path, importer }) => {
|
|
8483
|
-
const absolute = resolve7(
|
|
8471
|
+
const absolute = resolve7(dirname11(importer.split("?")[0]), path);
|
|
8484
8472
|
if (absolute !== pprPath && `${absolute}.ts` !== pprPath) {
|
|
8485
8473
|
return;
|
|
8486
8474
|
}
|
|
@@ -8506,7 +8494,7 @@ function mixedRuntimePlugin(apps) {
|
|
|
8506
8494
|
return;
|
|
8507
8495
|
}
|
|
8508
8496
|
build.onResolve({ filter: MIXED_CACHE_IMPORT_RE }, ({ path, importer }) => {
|
|
8509
|
-
const absolute = resolve7(
|
|
8497
|
+
const absolute = resolve7(dirname11(importer.split("?")[0]), path);
|
|
8510
8498
|
if (absolute !== mixedPath && `${absolute}.ts` !== mixedPath) {
|
|
8511
8499
|
return;
|
|
8512
8500
|
}
|
|
@@ -8536,7 +8524,7 @@ async function buildRuntimeApp(app, projectRoot, targetDir, serverEntry, options
|
|
|
8536
8524
|
basePath: prefix,
|
|
8537
8525
|
clientDirName,
|
|
8538
8526
|
clientLogging: options.clientLogging ?? false,
|
|
8539
|
-
metafilePath: options.analyze ? join12(
|
|
8527
|
+
metafilePath: options.analyze ? join12(dirname11(targetDir), "analysis", `${targetName}-${clientDirName}.json`) : undefined,
|
|
8540
8528
|
optimizeImports: options.optimizeImports,
|
|
8541
8529
|
outDir: targetDir,
|
|
8542
8530
|
pages: { pagesDir: app.pagesDir, style: app.style },
|
|
@@ -8579,16 +8567,16 @@ ${entryChunk}`, cssChunks, routes, root, serverEntry, modulePaths, projectRoot);
|
|
|
8579
8567
|
}
|
|
8580
8568
|
|
|
8581
8569
|
// src/adapter/server-bundle.ts
|
|
8582
|
-
import { dirname as
|
|
8570
|
+
import { dirname as dirname14, relative as relative8 } from "path";
|
|
8583
8571
|
|
|
8584
8572
|
// src/build/elysia-aot.ts
|
|
8585
8573
|
import { fork } from "child_process";
|
|
8586
8574
|
import { existsSync as existsSync11, realpathSync as realpathSync5 } from "fs";
|
|
8587
|
-
import { dirname as
|
|
8575
|
+
import { dirname as dirname12, join as join13, relative as relative6, resolve as resolve8 } from "path";
|
|
8588
8576
|
import { fileURLToPath as fileURLToPath8 } from "url";
|
|
8589
8577
|
var AOT_NAMESPACE = "furin-elysia-aot";
|
|
8590
|
-
var ELYSIA_RESOLVE_DIR =
|
|
8591
|
-
var AOT_PROCESS_PATH = join13(
|
|
8578
|
+
var ELYSIA_RESOLVE_DIR = dirname12(Bun.resolveSync("elysia", import.meta.dir));
|
|
8579
|
+
var AOT_PROCESS_PATH = join13(dirname12(dirname12(fileURLToPath8(import.meta.resolve("@teyik0/furin")))), "src/build/elysia-aot-worker.ts");
|
|
8592
8580
|
var SOURCE_FILTER = /\.[cm]?[jt]sx?$/;
|
|
8593
8581
|
var ELYSIA_IMPORT_FILTER = /^elysia(?:\/(?!compiled$|type$).*)?$/;
|
|
8594
8582
|
var ELYSIA_VIRTUAL_IMPORT_FILTER = /^elysia\/(?:compiled|type)$/;
|
|
@@ -8782,7 +8770,7 @@ function elysiaAot(entry, expected) {
|
|
|
8782
8770
|
}
|
|
8783
8771
|
|
|
8784
8772
|
// src/build/production-instrumentation.ts
|
|
8785
|
-
import { dirname as
|
|
8773
|
+
import { dirname as dirname13, relative as relative7, resolve as resolve9 } from "path";
|
|
8786
8774
|
var INSTRUMENTATION_IMPORT = /(?:^|[/\\])devtools[/\\]instrumentation(?:\.ts|\.js)?$/;
|
|
8787
8775
|
var DEV_PAGE_PLUGIN_IMPORT = /(?:^|[/\\])server[/\\]dev-page-plugin(?:\.ts|\.js)?$/;
|
|
8788
8776
|
var DEV_RUNTIME_IMPORT = /(?:^|[/\\])server[/\\]dev[/\\](?:browser-events|diagnostics|graph|plugin|runtime)(?:\.ts|\.js)?$/;
|
|
@@ -8809,7 +8797,7 @@ function productionInstrumentationPlugin() {
|
|
|
8809
8797
|
name: "furin-production-instrumentation",
|
|
8810
8798
|
setup(build) {
|
|
8811
8799
|
build.onResolve({ filter: PRODUCTION_BOUNDARY_IMPORT }, (args) => {
|
|
8812
|
-
const importPath = resolve9(
|
|
8800
|
+
const importPath = resolve9(dirname13(args.importer), args.path);
|
|
8813
8801
|
if (!isFurinRuntimePath(importPath)) {
|
|
8814
8802
|
return;
|
|
8815
8803
|
}
|
|
@@ -8845,7 +8833,7 @@ var PRERENDER_SNAPSHOT_RE = /^\.\/furin-prerender\.json$/;
|
|
|
8845
8833
|
var ELYSIA_STATIC_IMPORT_RE = /^@elysia\/static$/;
|
|
8846
8834
|
var MATCH_ALL_RE = /.*/;
|
|
8847
8835
|
var STATIC_STUB_NAMESPACE = "furin-platform-assets-stub";
|
|
8848
|
-
var FURIN_RUNTIME_ROOT2 =
|
|
8836
|
+
var FURIN_RUNTIME_ROOT2 = dirname14(import.meta.dir);
|
|
8849
8837
|
function isFurinRuntimeImporter(importer) {
|
|
8850
8838
|
if (importer === "") {
|
|
8851
8839
|
return false;
|
|
@@ -9278,7 +9266,7 @@ export declare const prefix: string;
|
|
|
9278
9266
|
|
|
9279
9267
|
// src/adapter/static.ts
|
|
9280
9268
|
import { cpSync as cpSync2, existsSync as existsSync15, rmSync as rmSync6, writeFileSync as writeFileSync9 } from "fs";
|
|
9281
|
-
import { dirname as
|
|
9269
|
+
import { dirname as dirname15, isAbsolute as isAbsolute6, join as join17, parse as parse3, relative as relative12, resolve as resolve11, sep as sep3, win32 } from "path";
|
|
9282
9270
|
var TRAILING_SLASHES_RE = /\/+$/;
|
|
9283
9271
|
var STATIC_RENDER_ORIGIN = "http://localhost";
|
|
9284
9272
|
function pathToOutputFile(urlPath, outDir, fileName) {
|
|
@@ -9403,7 +9391,7 @@ async function collectStaticOutputs(exported, outDir, basePath, onSSR, skippedRo
|
|
|
9403
9391
|
return outputs;
|
|
9404
9392
|
}
|
|
9405
9393
|
function writeStaticOutput(output) {
|
|
9406
|
-
ensureDir(
|
|
9394
|
+
ensureDir(dirname15(output.htmlFile));
|
|
9407
9395
|
writeFileSync9(output.htmlFile, output.html);
|
|
9408
9396
|
if (output.data !== null) {
|
|
9409
9397
|
writeFileSync9(output.dataFile, output.data);
|
|
@@ -9602,7 +9590,7 @@ import {
|
|
|
9602
9590
|
symlinkSync,
|
|
9603
9591
|
writeFileSync as writeFileSync10
|
|
9604
9592
|
} from "fs";
|
|
9605
|
-
import { basename as basename6, dirname as
|
|
9593
|
+
import { basename as basename6, dirname as dirname16, join as join18, relative as relative13 } from "path";
|
|
9606
9594
|
import { fileURLToPath as fileURLToPath9, pathToFileURL as pathToFileURL3 } from "url";
|
|
9607
9595
|
|
|
9608
9596
|
// src/adapter/vercel/data.ts
|
|
@@ -9647,7 +9635,7 @@ function assertRegions(regions) {
|
|
|
9647
9635
|
}
|
|
9648
9636
|
}
|
|
9649
9637
|
function frameworkVersion() {
|
|
9650
|
-
const packageRoot =
|
|
9638
|
+
const packageRoot = dirname16(dirname16(fileURLToPath9(import.meta.resolve("@teyik0/furin"))));
|
|
9651
9639
|
const packageJson = JSON.parse(readFileSync8(join18(packageRoot, "package.json"), "utf8"));
|
|
9652
9640
|
return packageJson.version;
|
|
9653
9641
|
}
|
|
@@ -9788,8 +9776,8 @@ async function addPrerenderFallback(job, response, functionsDir) {
|
|
|
9788
9776
|
const { spec } = job;
|
|
9789
9777
|
const fallback = `${basename6(spec.functionName)}.prerender-fallback.html`;
|
|
9790
9778
|
const location = response.headers.get("location") ?? undefined;
|
|
9791
|
-
const fallbackPath = join18(
|
|
9792
|
-
ensureDir(
|
|
9779
|
+
const fallbackPath = join18(dirname16(join18(functionsDir, spec.functionName)), fallback);
|
|
9780
|
+
ensureDir(dirname16(fallbackPath));
|
|
9793
9781
|
writeFileSync10(fallbackPath, await response.text());
|
|
9794
9782
|
spec.config.fallback = fallback;
|
|
9795
9783
|
spec.config.initialHeaders = {
|
|
@@ -9863,8 +9851,8 @@ async function buildBootstrap(serverFunctionDir) {
|
|
|
9863
9851
|
}
|
|
9864
9852
|
function createFunctionAlias(functionsDir, serverFunctionDir, functionName) {
|
|
9865
9853
|
const aliasPath = join18(functionsDir, `${functionName}.func`);
|
|
9866
|
-
ensureDir(
|
|
9867
|
-
const target = relative13(
|
|
9854
|
+
ensureDir(dirname16(aliasPath));
|
|
9855
|
+
const target = relative13(dirname16(aliasPath), serverFunctionDir);
|
|
9868
9856
|
symlinkSync(target, aliasPath, process.platform === "win32" ? "junction" : "dir");
|
|
9869
9857
|
}
|
|
9870
9858
|
function copyStaticAssets(output, staticDir) {
|
|
@@ -186,6 +186,24 @@ window.addEventListener("furin:client-error", (event) => {
|
|
|
186
186
|
reportClientError(detail).catch(() => undefined);
|
|
187
187
|
});
|
|
188
188
|
|
|
189
|
+
// A module evaluation error (a bundle SyntaxError, a top-level throw in an
|
|
190
|
+
// imported module) stops the hydrate entry before its catch exists. The dev
|
|
191
|
+
// bundle holds the entry's static graph, so report errors from that script
|
|
192
|
+
// until the entry mounts its root; afterwards React boundaries and Bun HMR
|
|
193
|
+
// own runtime errors.
|
|
194
|
+
window.addEventListener("error", (event) => {
|
|
195
|
+
if ((window as { __FURIN_ROOT__?: unknown }).__FURIN_ROOT__ !== undefined) {
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
const entry = document.querySelector<HTMLScriptElement>("script[data-furin-entry][src]");
|
|
199
|
+
if (!entry || event.filename !== entry.src) {
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
reportClientError({ error: event.error ?? event.message, phase: "hydrate" }).catch(
|
|
203
|
+
() => undefined
|
|
204
|
+
);
|
|
205
|
+
});
|
|
206
|
+
|
|
189
207
|
// Retry only failures from before this update, including when reporting is still
|
|
190
208
|
// in flight or server readiness has already dismissed the overlay.
|
|
191
209
|
window.addEventListener("furin:hmr-before-update", () => {
|
package/dist/furin.js
CHANGED
|
@@ -21433,11 +21433,12 @@ function transformDevSource(raw, filePath, options) {
|
|
|
21433
21433
|
for (const graph of developmentGraphs()) {
|
|
21434
21434
|
graph.clearSourceErrors(filePath);
|
|
21435
21435
|
}
|
|
21436
|
+
const source = raw.startsWith("#!") ? `//${raw.slice(2)}` : raw;
|
|
21436
21437
|
try {
|
|
21437
21438
|
if (!options.renderFragment) {
|
|
21438
|
-
recordDevImports(
|
|
21439
|
+
recordDevImports(source, filePath);
|
|
21439
21440
|
}
|
|
21440
|
-
const server = parseModule(
|
|
21441
|
+
const server = parseModule(source, filePath);
|
|
21441
21442
|
for (const statement of server.program.body) {
|
|
21442
21443
|
if (statement.type === "ImportDeclaration" && statement.specifiers.length === 0 && CSS_IMPORT.test(statement.source.value)) {
|
|
21443
21444
|
removeRange(server, statement.start, statement.end);
|
|
@@ -22886,6 +22887,7 @@ if (__deferred && __deferred._chunks) {
|
|
|
22886
22887
|
// with the server (stale deploy) or the server returned something we
|
|
22887
22888
|
// don't know how to hydrate. Bail loudly; the page stays static.
|
|
22888
22889
|
log.error({ action: "hydrate_no_match", pathname });
|
|
22890
|
+
if (import.meta.hot) throw new Error(\`[furin] No client route matches \${pathname}; the page stays static.\`);
|
|
22889
22891
|
return;
|
|
22890
22892
|
}
|
|
22891
22893
|
app = createElement(DocumentProvider, { value: documentState }, app);
|
|
@@ -22952,6 +22954,7 @@ if (__deferred && __deferred._chunks) {
|
|
|
22952
22954
|
log.info({ action: "hydrate_complete", pathname });
|
|
22953
22955
|
})().catch((err: unknown) => {
|
|
22954
22956
|
log.error({ action: "hydrate_failed", pathname, error: String(err) });
|
|
22957
|
+
if (import.meta.hot) console.error("[furin] Hydration failed:", err);
|
|
22955
22958
|
window.dispatchEvent(
|
|
22956
22959
|
new CustomEvent("furin:client-error", { detail: { error: err, phase: "hydrate" } })
|
|
22957
22960
|
);
|
|
@@ -9,7 +9,7 @@ interface ClientStripPluginOptions {
|
|
|
9
9
|
/**
|
|
10
10
|
* Furin's browser-graph plugin, shared by the dev server (bunfig
|
|
11
11
|
* `[serve.static] plugins`) and the production client build:
|
|
12
|
-
* 1. Stubs `elysia` for the browser with
|
|
12
|
+
* 1. Stubs `elysia` for the browser with its schema builder only.
|
|
13
13
|
* 2. Stubs `bun:*` builtins with an empty module (safety net — DCE removes
|
|
14
14
|
* loader imports before they reach the browser bundle in practice).
|
|
15
15
|
* 3. Strips server-only code (loader, query, params) from page files before
|
package/dist/plugin/index.js
CHANGED
|
@@ -4302,11 +4302,12 @@ function stripServerCode(path, source) {
|
|
|
4302
4302
|
var ELYSIA_FILTER = /^elysia$/;
|
|
4303
4303
|
var BUN_BUILTIN_FILTER = /^bun:/;
|
|
4304
4304
|
var ANY_FILTER = /.*/;
|
|
4305
|
-
var
|
|
4305
|
+
var elysiaStub = (typeModule) => `export * as t from ${JSON.stringify(typeModule)};
|
|
4306
4306
|
export class NotFoundError extends Error { constructor(m) { super(m); this.name = "NotFoundError"; } }
|
|
4307
4307
|
export class ValidationError extends Error { constructor(m) { super(m); this.name = "ValidationError"; } }
|
|
4308
4308
|
export default {};
|
|
4309
4309
|
`;
|
|
4310
|
+
var ELYSIA_STUB_PREFIX = "elysia-stub:";
|
|
4310
4311
|
function trackHydrationTopology(filePath, source, topologyPaths) {
|
|
4311
4312
|
const normalizedPath = filePath.replaceAll("\\", "/");
|
|
4312
4313
|
if (!(normalizedPath.includes("/.furin/") && normalizedPath.endsWith("/_hydrate.tsx"))) {
|
|
@@ -4344,16 +4345,16 @@ function createClientStripPlugin({ mode }) {
|
|
|
4344
4345
|
environmentGuardPlugin("client").setup(build);
|
|
4345
4346
|
const topologyPaths = new Set;
|
|
4346
4347
|
const loadedSources = new Map;
|
|
4347
|
-
build.onResolve({ filter: ELYSIA_FILTER }, () => ({
|
|
4348
|
+
build.onResolve({ filter: ELYSIA_FILTER }, (args) => ({
|
|
4348
4349
|
namespace: "furin-stubs",
|
|
4349
|
-
path: "elysia
|
|
4350
|
+
path: ELYSIA_STUB_PREFIX + Bun.resolveSync("elysia/type", args.resolveDir)
|
|
4350
4351
|
}));
|
|
4351
4352
|
build.onResolve({ filter: BUN_BUILTIN_FILTER }, () => ({
|
|
4352
4353
|
namespace: "furin-stubs",
|
|
4353
4354
|
path: "bun-builtin-stub"
|
|
4354
4355
|
}));
|
|
4355
4356
|
build.onLoad({ filter: ANY_FILTER, namespace: "furin-stubs" }, (args) => ({
|
|
4356
|
-
contents: args.path
|
|
4357
|
+
contents: args.path.startsWith(ELYSIA_STUB_PREFIX) ? elysiaStub(args.path.slice(ELYSIA_STUB_PREFIX.length)) : "",
|
|
4357
4358
|
loader: "js"
|
|
4358
4359
|
}));
|
|
4359
4360
|
build.onLoad({ filter: SCRIPT_FILE_FILTER }, async (args) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@teyik0/furin",
|
|
3
|
-
"version": "0.9.0-alpha.
|
|
3
|
+
"version": "0.9.0-alpha.3",
|
|
4
4
|
"description": "React meta-framework powered by Elysia and Bun with file-based routing, SSR, SSG, and ISR.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -173,7 +173,7 @@
|
|
|
173
173
|
"test:dev": "bun run generate:sync-prisma && bun test --changed --parallel --isolate --max-concurrency 4 --bail --timeout 15000",
|
|
174
174
|
"test:hmr:soak": "FURIN_WEBVIEW_TESTS=1 FURIN_HMR_SOAK_TESTS=1 bun test tests/browser/hmr-conformance.webview.test.ts -t 'tracks memory' --timeout 3600000",
|
|
175
175
|
"test:webview": "FURIN_WEBVIEW_TESTS=1 bun test tests/browser --timeout 60000",
|
|
176
|
-
"tscheck": "bun run generate:sync-prisma &&
|
|
176
|
+
"tscheck": "bun run generate:sync-prisma && bun check"
|
|
177
177
|
},
|
|
178
178
|
"dependencies": {
|
|
179
179
|
"@elysia/eden": "^2.0.0-rc.1",
|
package/src/build/hydrate.ts
CHANGED
|
@@ -419,6 +419,7 @@ if (__deferred && __deferred._chunks) {
|
|
|
419
419
|
// with the server (stale deploy) or the server returned something we
|
|
420
420
|
// don't know how to hydrate. Bail loudly; the page stays static.
|
|
421
421
|
log.error({ action: "hydrate_no_match", pathname });
|
|
422
|
+
if (import.meta.hot) throw new Error(\`[furin] No client route matches \${pathname}; the page stays static.\`);
|
|
422
423
|
return;
|
|
423
424
|
}
|
|
424
425
|
app = createElement(DocumentProvider, { value: documentState }, app);
|
|
@@ -485,6 +486,7 @@ if (__deferred && __deferred._chunks) {
|
|
|
485
486
|
log.info({ action: "hydrate_complete", pathname });
|
|
486
487
|
})().catch((err: unknown) => {
|
|
487
488
|
log.error({ action: "hydrate_failed", pathname, error: String(err) });
|
|
489
|
+
if (import.meta.hot) console.error("[furin] Hydration failed:", err);
|
|
488
490
|
window.dispatchEvent(
|
|
489
491
|
new CustomEvent("furin:client-error", { detail: { error: err, phase: "hydrate" } })
|
|
490
492
|
);
|
|
@@ -186,6 +186,24 @@ window.addEventListener("furin:client-error", (event) => {
|
|
|
186
186
|
reportClientError(detail).catch(() => undefined);
|
|
187
187
|
});
|
|
188
188
|
|
|
189
|
+
// A module evaluation error (a bundle SyntaxError, a top-level throw in an
|
|
190
|
+
// imported module) stops the hydrate entry before its catch exists. The dev
|
|
191
|
+
// bundle holds the entry's static graph, so report errors from that script
|
|
192
|
+
// until the entry mounts its root; afterwards React boundaries and Bun HMR
|
|
193
|
+
// own runtime errors.
|
|
194
|
+
window.addEventListener("error", (event) => {
|
|
195
|
+
if ((window as { __FURIN_ROOT__?: unknown }).__FURIN_ROOT__ !== undefined) {
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
const entry = document.querySelector<HTMLScriptElement>("script[data-furin-entry][src]");
|
|
199
|
+
if (!entry || event.filename !== entry.src) {
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
reportClientError({ error: event.error ?? event.message, phase: "hydrate" }).catch(
|
|
203
|
+
() => undefined
|
|
204
|
+
);
|
|
205
|
+
});
|
|
206
|
+
|
|
189
207
|
// Retry only failures from before this update, including when reporting is still
|
|
190
208
|
// in flight or server readiness has already dismissed the overlay.
|
|
191
209
|
window.addEventListener("furin:hmr-before-update", () => {
|
|
@@ -8,14 +8,16 @@ const ELYSIA_FILTER = /^elysia$/;
|
|
|
8
8
|
const BUN_BUILTIN_FILTER = /^bun:/;
|
|
9
9
|
const ANY_FILTER = /.*/;
|
|
10
10
|
|
|
11
|
-
//
|
|
12
|
-
//
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
// Browser stub for elysia: the server stays out of the bundle, but `t` is
|
|
12
|
+
// Elysia's browser-safe schema builder, so a schema shared with the client
|
|
13
|
+
// is the same JSON Schema on both sides. `typeModule` is its resolved path.
|
|
14
|
+
const elysiaStub = (typeModule: string) => `\
|
|
15
|
+
export * as t from ${JSON.stringify(typeModule)};
|
|
15
16
|
export class NotFoundError extends Error { constructor(m) { super(m); this.name = "NotFoundError"; } }
|
|
16
17
|
export class ValidationError extends Error { constructor(m) { super(m); this.name = "ValidationError"; } }
|
|
17
18
|
export default {};
|
|
18
19
|
`;
|
|
20
|
+
const ELYSIA_STUB_PREFIX = "elysia-stub:";
|
|
19
21
|
|
|
20
22
|
/** Records the route modules imported by the dev `.furin/_hydrate.tsx` entry. */
|
|
21
23
|
function trackHydrationTopology(filePath: string, source: string, topologyPaths: Set<string>) {
|
|
@@ -72,7 +74,7 @@ interface ClientStripPluginOptions {
|
|
|
72
74
|
/**
|
|
73
75
|
* Furin's browser-graph plugin, shared by the dev server (bunfig
|
|
74
76
|
* `[serve.static] plugins`) and the production client build:
|
|
75
|
-
* 1. Stubs `elysia` for the browser with
|
|
77
|
+
* 1. Stubs `elysia` for the browser with its schema builder only.
|
|
76
78
|
* 2. Stubs `bun:*` builtins with an empty module (safety net — DCE removes
|
|
77
79
|
* loader imports before they reach the browser bundle in practice).
|
|
78
80
|
* 3. Strips server-only code (loader, query, params) from page files before
|
|
@@ -90,9 +92,10 @@ export function createClientStripPlugin({ mode }: ClientStripPluginOptions): Bun
|
|
|
90
92
|
{ contents: string; loader: Bun.Loader; isRouteModule: boolean }
|
|
91
93
|
>();
|
|
92
94
|
// ── browser stubs ───────────────────────────────────────────────────────
|
|
93
|
-
|
|
95
|
+
// Resolved from the importer, so it is the app's own elysia install.
|
|
96
|
+
build.onResolve({ filter: ELYSIA_FILTER }, (args) => ({
|
|
94
97
|
namespace: "furin-stubs",
|
|
95
|
-
path: "elysia
|
|
98
|
+
path: ELYSIA_STUB_PREFIX + Bun.resolveSync("elysia/type", args.resolveDir),
|
|
96
99
|
}));
|
|
97
100
|
|
|
98
101
|
build.onResolve({ filter: BUN_BUILTIN_FILTER }, () => ({
|
|
@@ -101,7 +104,9 @@ export function createClientStripPlugin({ mode }: ClientStripPluginOptions): Bun
|
|
|
101
104
|
}));
|
|
102
105
|
|
|
103
106
|
build.onLoad({ filter: ANY_FILTER, namespace: "furin-stubs" }, (args) => ({
|
|
104
|
-
contents: args.path
|
|
107
|
+
contents: args.path.startsWith(ELYSIA_STUB_PREFIX)
|
|
108
|
+
? elysiaStub(args.path.slice(ELYSIA_STUB_PREFIX.length))
|
|
109
|
+
: "",
|
|
105
110
|
loader: "js",
|
|
106
111
|
}));
|
|
107
112
|
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { detectLoaderFromPath } from "../server/lang-detect.ts";
|
|
1
|
+
import { join, resolve } from "node:path";
|
|
3
2
|
import {
|
|
4
3
|
loadRouteModule,
|
|
5
4
|
type RouteModuleInfo,
|
|
@@ -21,7 +20,6 @@ const ROUTES_REGISTRY_SPECIFIER = "furin/routes?registry";
|
|
|
21
20
|
const COMPOSABLE_ROUTES_REGISTRY_SPECIFIER = "furin/routes?registry=composable";
|
|
22
21
|
const ROUTES_REGISTRY_FILTER = /^furin\/routes\?registry(?:=composable)?$/;
|
|
23
22
|
const ROUTE_FILE_FILTER = /^furin-route-file:.+$/;
|
|
24
|
-
const ROUTE_FILES_NAMESPACE = "furin-route-files";
|
|
25
23
|
const ROUTES_REGISTRY_FILE_FILTER =
|
|
26
24
|
/[\\/]\.furin-routes-registry(?:-composable)?\.ts\?furin-virtual$/;
|
|
27
25
|
const CLIENT_ROUTES_NAMESPACE = "furin-routes-client";
|
|
@@ -246,7 +244,6 @@ function serverProxySource(instance: RouteInstanceSpec, includeRootCatchAll: boo
|
|
|
246
244
|
|
|
247
245
|
export function createRoutesPlugin(options: CreateRoutesPluginOptions): Bun.BunPlugin {
|
|
248
246
|
const routeFilesBySpecifier = new Map<string, RouteModuleInfo>();
|
|
249
|
-
const routeFilesByResolvedPath = new Map<string, RouteModuleInfo>();
|
|
250
247
|
const registryVirtualPath = join(
|
|
251
248
|
resolve(primaryInstance(options.instances).pagesDir),
|
|
252
249
|
".furin-routes-registry.ts?furin-virtual"
|
|
@@ -314,29 +311,15 @@ export function createRoutesPlugin(options: CreateRoutesPluginOptions): Bun.BunP
|
|
|
314
311
|
}
|
|
315
312
|
return { contents, loader: "ts" };
|
|
316
313
|
});
|
|
314
|
+
// Route files resolve to their real path so the file-namespace server
|
|
315
|
+
// transforms apply and the bundle keeps one copy of each route module.
|
|
317
316
|
build.onResolve({ filter: ROUTE_FILE_FILTER }, ({ path }) => {
|
|
318
317
|
const routeFile = routeFilesBySpecifier.get(path);
|
|
319
318
|
if (!routeFile) {
|
|
320
319
|
throw new Error(`[furin] Unknown route module: ${path}`);
|
|
321
320
|
}
|
|
322
|
-
|
|
323
|
-
routeFilesByResolvedPath.set(resolvedPath, routeFile);
|
|
324
|
-
return { namespace: ROUTE_FILES_NAMESPACE, path: resolvedPath };
|
|
321
|
+
return { path: routeFile.sourcePath };
|
|
325
322
|
});
|
|
326
|
-
build.onLoad(
|
|
327
|
-
{ filter: VIRTUAL_ROUTES_FILTER, namespace: ROUTE_FILES_NAMESPACE },
|
|
328
|
-
async ({ path }) => {
|
|
329
|
-
const routeFile = routeFilesByResolvedPath.get(path);
|
|
330
|
-
if (!routeFile) {
|
|
331
|
-
throw new Error(`[furin] Unknown route module: ${path}`);
|
|
332
|
-
}
|
|
333
|
-
return {
|
|
334
|
-
contents: await Bun.file(routeFile.sourcePath).text(),
|
|
335
|
-
loader: detectLoaderFromPath(routeFile.sourcePath),
|
|
336
|
-
resolveDir: dirname(routeFile.sourcePath),
|
|
337
|
-
};
|
|
338
|
-
}
|
|
339
|
-
);
|
|
340
323
|
for (const { instance, namespace, includeRootCatchAll } of instancesBySpecifier.values()) {
|
|
341
324
|
build.onLoad({ filter: VIRTUAL_ROUTES_FILTER, namespace }, () => ({
|
|
342
325
|
contents: serverProxySource(instance, includeRootCatchAll),
|
|
@@ -179,12 +179,15 @@ export function transformDevSource(
|
|
|
179
179
|
for (const graph of developmentGraphs()) {
|
|
180
180
|
graph.clearSourceErrors(filePath);
|
|
181
181
|
}
|
|
182
|
+
// The parsers reject a shebang (e.g. a workspace package's CLI entry). An imported module
|
|
183
|
+
// never needs one: keep it as a same-length comment so every offset and line stays put.
|
|
184
|
+
const source = raw.startsWith("#!") ? `//${raw.slice(2)}` : raw;
|
|
182
185
|
try {
|
|
183
186
|
if (!options.renderFragment) {
|
|
184
|
-
recordDevImports(
|
|
187
|
+
recordDevImports(source, filePath);
|
|
185
188
|
}
|
|
186
189
|
// CSS belongs to Bun's browser graph; importing it here also registers it with --hot.
|
|
187
|
-
const server = parseModule(
|
|
190
|
+
const server = parseModule(source, filePath);
|
|
188
191
|
for (const statement of server.program.body) {
|
|
189
192
|
if (
|
|
190
193
|
statement.type === "ImportDeclaration" &&
|