@rangojs/router 0.0.0-experimental.67 → 0.0.0-experimental.69

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.
@@ -1311,6 +1311,57 @@ ${lazyImports.join(",\n")}
1311
1311
  );
1312
1312
  if (wholeFile) return wholeFile;
1313
1313
  }
1314
+ if (!isRscEnv && (hasPrerenderHandlerCode || hasStaticHandlerCode)) {
1315
+ const allBindings = [];
1316
+ if (hasLoaderCode) {
1317
+ allBindings.push(...getBindings(code, getFnNames("createLoader")));
1318
+ }
1319
+ if (hasHandleCode) {
1320
+ allBindings.push(...getBindings(code, getFnNames("createHandle")));
1321
+ }
1322
+ if (hasLocationStateCode) {
1323
+ allBindings.push(
1324
+ ...getBindings(code, getFnNames("createLocationState"))
1325
+ );
1326
+ }
1327
+ if (hasPrerenderHandlerCode) {
1328
+ allBindings.push(
1329
+ ...getBindings(code, getFnNames(PRERENDER_CONFIG.fnName))
1330
+ );
1331
+ }
1332
+ if (hasStaticHandlerCode) {
1333
+ allBindings.push(
1334
+ ...getBindings(code, getFnNames(STATIC_CONFIG.fnName))
1335
+ );
1336
+ }
1337
+ if (allBindings.length > 0 && isExportOnlyFile(code, allBindings)) {
1338
+ const stubs = [];
1339
+ for (const binding of allBindings) {
1340
+ const name = binding.exportNames[0];
1341
+ const stubId = isBuild ? hashId(filePath, name) : `${filePath}#${name}`;
1342
+ const fnCall = code.slice(
1343
+ binding.callExprStart,
1344
+ binding.callOpenParenPos + 1
1345
+ );
1346
+ let brand = "loader";
1347
+ if (hasPrerenderHandlerCode && getFnNames(PRERENDER_CONFIG.fnName).some(
1348
+ (n) => fnCall.includes(n)
1349
+ )) {
1350
+ brand = PRERENDER_CONFIG.brand;
1351
+ } else if (hasStaticHandlerCode && getFnNames(STATIC_CONFIG.fnName).some((n) => fnCall.includes(n))) {
1352
+ brand = STATIC_CONFIG.brand;
1353
+ } else if (hasHandleCode && getFnNames("createHandle").some((n) => fnCall.includes(n))) {
1354
+ brand = "handle";
1355
+ } else if (hasLocationStateCode && getFnNames("createLocationState").some((n) => fnCall.includes(n))) {
1356
+ brand = "locationState";
1357
+ }
1358
+ stubs.push(
1359
+ `export const ${name} = { __brand: "${brand}", $$id: "${stubId}" };`
1360
+ );
1361
+ }
1362
+ return { code: stubs.join("\n") + "\n", map: null };
1363
+ }
1364
+ }
1314
1365
  if (hasStaticHandlerCode && isRscEnv && isBuild) {
1315
1366
  const fnNames = getFnNames(STATIC_CONFIG.fnName);
1316
1367
  const exportNames = getBindings(code, fnNames).map(
@@ -1733,7 +1784,7 @@ import { resolve } from "node:path";
1733
1784
  // package.json
1734
1785
  var package_default = {
1735
1786
  name: "@rangojs/router",
1736
- version: "0.0.0-experimental.67",
1787
+ version: "0.0.0-experimental.69",
1737
1788
  description: "Django-inspired RSC router with composable URL patterns",
1738
1789
  keywords: [
1739
1790
  "react",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rangojs/router",
3
- "version": "0.0.0-experimental.67",
3
+ "version": "0.0.0-experimental.69",
4
4
  "description": "Django-inspired RSC router with composable URL patterns",
5
5
  "keywords": [
6
6
  "react",
@@ -23,6 +23,7 @@ import {
23
23
  getImportedFnNames,
24
24
  collectCreateExportBindings,
25
25
  buildUnsupportedShapeWarning,
26
+ isExportOnlyFile,
26
27
  } from "./expose-ids/export-analysis.js";
27
28
  import {
28
29
  hasCreateLoaderImport,
@@ -462,7 +463,6 @@ ${lazyImports.join(",\n")}
462
463
 
463
464
  // --- StaticHandler: non-RSC whole-file stub replacement ---
464
465
  // When ALL exports are Static() calls, replace the entire file.
465
- // Mixed-export files are handled in the unified pipeline below.
466
466
  if (hasStaticHandlerCode && !isRscEnv) {
467
467
  const fnNames = getFnNames(STATIC_CONFIG.fnName);
468
468
  const bindings = getBindings(code, fnNames);
@@ -476,6 +476,83 @@ ${lazyImports.join(",\n")}
476
476
  if (wholeFile) return wholeFile;
477
477
  }
478
478
 
479
+ // --- Mixed-type whole-file stub replacement (non-RSC) ---
480
+ // When the individual whole-file checks above fail (each only checks
481
+ // one type), the file has mixed exports (e.g. createLoader + Prerender).
482
+ // Gather ALL recognized bindings and check if they cover every export.
483
+ // If yes, replace the entire file with stubs — this strips server-only
484
+ // imports (node:fs, DB clients, etc.) that would crash in the browser.
485
+ //
486
+ // Only applies when the file contains Prerender/Static (the handler
487
+ // types that bring server-only code). Files with only loaders, handles,
488
+ // or locationState are handled correctly by the unified pipeline below.
489
+ if (!isRscEnv && (hasPrerenderHandlerCode || hasStaticHandlerCode)) {
490
+ const allBindings: CreateExportBinding[] = [];
491
+ if (hasLoaderCode) {
492
+ allBindings.push(...getBindings(code, getFnNames("createLoader")));
493
+ }
494
+ if (hasHandleCode) {
495
+ allBindings.push(...getBindings(code, getFnNames("createHandle")));
496
+ }
497
+ if (hasLocationStateCode) {
498
+ allBindings.push(
499
+ ...getBindings(code, getFnNames("createLocationState")),
500
+ );
501
+ }
502
+ if (hasPrerenderHandlerCode) {
503
+ allBindings.push(
504
+ ...getBindings(code, getFnNames(PRERENDER_CONFIG.fnName)),
505
+ );
506
+ }
507
+ if (hasStaticHandlerCode) {
508
+ allBindings.push(
509
+ ...getBindings(code, getFnNames(STATIC_CONFIG.fnName)),
510
+ );
511
+ }
512
+ if (allBindings.length > 0 && isExportOnlyFile(code, allBindings)) {
513
+ const stubs: string[] = [];
514
+ for (const binding of allBindings) {
515
+ const name = binding.exportNames[0];
516
+ const stubId = isBuild
517
+ ? hashId(filePath, name)
518
+ : `${filePath}#${name}`;
519
+ // Determine brand from which type this binding belongs to
520
+ const fnCall = code.slice(
521
+ binding.callExprStart,
522
+ binding.callOpenParenPos + 1,
523
+ );
524
+ let brand = "loader";
525
+ if (
526
+ hasPrerenderHandlerCode &&
527
+ getFnNames(PRERENDER_CONFIG.fnName).some((n) =>
528
+ fnCall.includes(n),
529
+ )
530
+ ) {
531
+ brand = PRERENDER_CONFIG.brand;
532
+ } else if (
533
+ hasStaticHandlerCode &&
534
+ getFnNames(STATIC_CONFIG.fnName).some((n) => fnCall.includes(n))
535
+ ) {
536
+ brand = STATIC_CONFIG.brand;
537
+ } else if (
538
+ hasHandleCode &&
539
+ getFnNames("createHandle").some((n) => fnCall.includes(n))
540
+ ) {
541
+ brand = "handle";
542
+ } else if (
543
+ hasLocationStateCode &&
544
+ getFnNames("createLocationState").some((n) => fnCall.includes(n))
545
+ ) {
546
+ brand = "locationState";
547
+ }
548
+ stubs.push(
549
+ `export const ${name} = { __brand: "${brand}", $$id: "${stubId}" };`,
550
+ );
551
+ }
552
+ return { code: stubs.join("\n") + "\n", map: null };
553
+ }
554
+ }
555
+
479
556
  // --- StaticHandler: RSC build module tracking ---
480
557
  if (hasStaticHandlerCode && isRscEnv && isBuild) {
481
558
  const fnNames = getFnNames(STATIC_CONFIG.fnName);