@webtypen/webframez-react 0.0.22 → 0.0.24

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/http.cjs CHANGED
@@ -311,21 +311,38 @@ function toRouteEntry(pagesDir, filePath) {
311
311
  const relativeDir = import_node_path2.default.dirname(import_node_path2.default.relative(pagesDir, filePath)).replace(/\\/g, "/");
312
312
  const segments = relativeDir === "." ? [] : relativeDir.split("/").filter(Boolean);
313
313
  const staticCount = segments.filter((segment) => !segment.startsWith("[")).length;
314
+ const catchAllCount = segments.filter(
315
+ (segment) => segment.startsWith("[...") && segment.endsWith("]")
316
+ ).length;
314
317
  return {
315
318
  filePath,
316
319
  segments,
317
- staticCount
320
+ staticCount,
321
+ catchAllCount
318
322
  };
319
323
  }
320
324
  function matchRoute(entry, pathname) {
321
325
  const targetSegments = splitSegments(pathname);
322
- if (entry.segments.length !== targetSegments.length) {
323
- return null;
324
- }
325
326
  const params = {};
326
327
  for (let index = 0; index < entry.segments.length; index += 1) {
327
328
  const routeSegment = entry.segments[index];
329
+ const isCatchAll = routeSegment.startsWith("[...") && routeSegment.endsWith("]");
330
+ if (isCatchAll) {
331
+ const paramName = routeSegment.slice(4, -1);
332
+ if (!paramName || index !== entry.segments.length - 1) {
333
+ return null;
334
+ }
335
+ const restSegments = targetSegments.slice(index);
336
+ if (restSegments.length === 0) {
337
+ return null;
338
+ }
339
+ params[paramName] = restSegments.map((segment) => decodeURIComponent(segment));
340
+ return params;
341
+ }
328
342
  const targetSegment = targetSegments[index];
343
+ if (typeof targetSegment !== "string") {
344
+ return null;
345
+ }
329
346
  if (routeSegment.startsWith("[") && routeSegment.endsWith("]")) {
330
347
  const paramName = routeSegment.slice(1, -1);
331
348
  if (!paramName) {
@@ -338,6 +355,9 @@ function matchRoute(entry, pathname) {
338
355
  return null;
339
356
  }
340
357
  }
358
+ if (entry.segments.length !== targetSegments.length) {
359
+ return null;
360
+ }
341
361
  return params;
342
362
  }
343
363
  function mergeHead(...configs) {
@@ -389,8 +409,25 @@ function renderHeadToString(head) {
389
409
  }
390
410
  return tags.join("\n");
391
411
  }
392
- function resolveModule(modulePath) {
393
- delete require.cache[modulePath];
412
+ function clearModuleCache(modulePath, rootDir, visited = /* @__PURE__ */ new Set()) {
413
+ const resolvedPath = require.resolve(modulePath);
414
+ if (visited.has(resolvedPath)) {
415
+ return;
416
+ }
417
+ visited.add(resolvedPath);
418
+ const cachedModule = require.cache[resolvedPath];
419
+ if (!cachedModule) {
420
+ return;
421
+ }
422
+ for (const child of cachedModule.children) {
423
+ if (child.id.startsWith(rootDir)) {
424
+ clearModuleCache(child.id, rootDir, visited);
425
+ }
426
+ }
427
+ delete require.cache[resolvedPath];
428
+ }
429
+ function resolveModule(modulePath, rootDir) {
430
+ clearModuleCache(modulePath, rootDir);
394
431
  return require(modulePath);
395
432
  }
396
433
  async function resolveHead(candidate, context) {
@@ -417,6 +454,9 @@ function findBestMatch(entries, pathname) {
417
454
  if (b.entry.staticCount !== a.entry.staticCount) {
418
455
  return b.entry.staticCount - a.entry.staticCount;
419
456
  }
457
+ if (a.entry.catchAllCount !== b.entry.catchAllCount) {
458
+ return a.entry.catchAllCount - b.entry.catchAllCount;
459
+ }
420
460
  return b.entry.segments.length - a.entry.segments.length;
421
461
  });
422
462
  return matches[0] ?? null;
@@ -461,6 +501,9 @@ function createFileRouter(options) {
461
501
  if (b.staticCount !== a.staticCount) {
462
502
  return b.staticCount - a.staticCount;
463
503
  }
504
+ if (a.catchAllCount !== b.catchAllCount) {
505
+ return a.catchAllCount - b.catchAllCount;
506
+ }
464
507
  return b.segments.length - a.segments.length;
465
508
  });
466
509
  }
@@ -471,7 +514,7 @@ function createFileRouter(options) {
471
514
  message,
472
515
  payload
473
516
  };
474
- const layoutModule = import_node_fs.default.existsSync(layoutPath) ? resolveModule(layoutPath) : null;
517
+ const layoutModule = import_node_fs.default.existsSync(layoutPath) ? resolveModule(layoutPath, pagesDir) : null;
475
518
  if (!import_node_fs.default.existsSync(errorPath)) {
476
519
  const fallback = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("main", { style: { fontFamily: "system-ui, sans-serif", padding: 24 }, children: [
477
520
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)("h1", { children: statusCode }),
@@ -485,7 +528,7 @@ function createFileRouter(options) {
485
528
  }
486
529
  };
487
530
  }
488
- const errorModule = resolveModule(errorPath);
531
+ const errorModule = resolveModule(errorPath, pagesDir);
489
532
  const errorNode = await errorModule.default(errorProps);
490
533
  const layoutHead = layoutModule ? await resolveHead(layoutModule, context) : void 0;
491
534
  const errorHead = await resolveHead(errorModule, errorProps);
@@ -534,7 +577,10 @@ function createFileRouter(options) {
534
577
  message: `Invalid middleware '${middlewareNames[0]}'`
535
578
  });
536
579
  }
537
- const middlewareModule = resolveModule(middlewaresPath);
580
+ const middlewareModule = resolveModule(
581
+ middlewaresPath,
582
+ pagesDir
583
+ );
538
584
  const registry = middlewareModule.middlewares;
539
585
  if (!registry) {
540
586
  if (!requiresNamedMiddleware) {
@@ -589,8 +635,8 @@ function createFileRouter(options) {
589
635
  params: match.params
590
636
  };
591
637
  activeContext = context;
592
- const pageModule = resolveModule(match.entry.filePath);
593
- const layoutModule = import_node_fs.default.existsSync(layoutPath) ? resolveModule(layoutPath) : null;
638
+ const pageModule = resolveModule(match.entry.filePath, pagesDir);
639
+ const layoutModule = import_node_fs.default.existsSync(layoutPath) ? resolveModule(layoutPath, pagesDir) : null;
594
640
  const middlewareContext = await resolveMiddlewares(pageModule.middlewares, context);
595
641
  activeContext = middlewareContext;
596
642
  const pageData = await resolvePageData(pageModule, middlewareContext);
package/dist/http.js CHANGED
@@ -286,21 +286,38 @@ function toRouteEntry(pagesDir, filePath) {
286
286
  const relativeDir = path2.dirname(path2.relative(pagesDir, filePath)).replace(/\\/g, "/");
287
287
  const segments = relativeDir === "." ? [] : relativeDir.split("/").filter(Boolean);
288
288
  const staticCount = segments.filter((segment) => !segment.startsWith("[")).length;
289
+ const catchAllCount = segments.filter(
290
+ (segment) => segment.startsWith("[...") && segment.endsWith("]")
291
+ ).length;
289
292
  return {
290
293
  filePath,
291
294
  segments,
292
- staticCount
295
+ staticCount,
296
+ catchAllCount
293
297
  };
294
298
  }
295
299
  function matchRoute(entry, pathname) {
296
300
  const targetSegments = splitSegments(pathname);
297
- if (entry.segments.length !== targetSegments.length) {
298
- return null;
299
- }
300
301
  const params = {};
301
302
  for (let index = 0; index < entry.segments.length; index += 1) {
302
303
  const routeSegment = entry.segments[index];
304
+ const isCatchAll = routeSegment.startsWith("[...") && routeSegment.endsWith("]");
305
+ if (isCatchAll) {
306
+ const paramName = routeSegment.slice(4, -1);
307
+ if (!paramName || index !== entry.segments.length - 1) {
308
+ return null;
309
+ }
310
+ const restSegments = targetSegments.slice(index);
311
+ if (restSegments.length === 0) {
312
+ return null;
313
+ }
314
+ params[paramName] = restSegments.map((segment) => decodeURIComponent(segment));
315
+ return params;
316
+ }
303
317
  const targetSegment = targetSegments[index];
318
+ if (typeof targetSegment !== "string") {
319
+ return null;
320
+ }
304
321
  if (routeSegment.startsWith("[") && routeSegment.endsWith("]")) {
305
322
  const paramName = routeSegment.slice(1, -1);
306
323
  if (!paramName) {
@@ -313,6 +330,9 @@ function matchRoute(entry, pathname) {
313
330
  return null;
314
331
  }
315
332
  }
333
+ if (entry.segments.length !== targetSegments.length) {
334
+ return null;
335
+ }
316
336
  return params;
317
337
  }
318
338
  function mergeHead(...configs) {
@@ -364,8 +384,25 @@ function renderHeadToString(head) {
364
384
  }
365
385
  return tags.join("\n");
366
386
  }
367
- function resolveModule(modulePath) {
368
- delete __require.cache[modulePath];
387
+ function clearModuleCache(modulePath, rootDir, visited = /* @__PURE__ */ new Set()) {
388
+ const resolvedPath = __require.resolve(modulePath);
389
+ if (visited.has(resolvedPath)) {
390
+ return;
391
+ }
392
+ visited.add(resolvedPath);
393
+ const cachedModule = __require.cache[resolvedPath];
394
+ if (!cachedModule) {
395
+ return;
396
+ }
397
+ for (const child of cachedModule.children) {
398
+ if (child.id.startsWith(rootDir)) {
399
+ clearModuleCache(child.id, rootDir, visited);
400
+ }
401
+ }
402
+ delete __require.cache[resolvedPath];
403
+ }
404
+ function resolveModule(modulePath, rootDir) {
405
+ clearModuleCache(modulePath, rootDir);
369
406
  return __require(modulePath);
370
407
  }
371
408
  async function resolveHead(candidate, context) {
@@ -392,6 +429,9 @@ function findBestMatch(entries, pathname) {
392
429
  if (b.entry.staticCount !== a.entry.staticCount) {
393
430
  return b.entry.staticCount - a.entry.staticCount;
394
431
  }
432
+ if (a.entry.catchAllCount !== b.entry.catchAllCount) {
433
+ return a.entry.catchAllCount - b.entry.catchAllCount;
434
+ }
395
435
  return b.entry.segments.length - a.entry.segments.length;
396
436
  });
397
437
  return matches[0] ?? null;
@@ -436,6 +476,9 @@ function createFileRouter(options) {
436
476
  if (b.staticCount !== a.staticCount) {
437
477
  return b.staticCount - a.staticCount;
438
478
  }
479
+ if (a.catchAllCount !== b.catchAllCount) {
480
+ return a.catchAllCount - b.catchAllCount;
481
+ }
439
482
  return b.segments.length - a.segments.length;
440
483
  });
441
484
  }
@@ -446,7 +489,7 @@ function createFileRouter(options) {
446
489
  message,
447
490
  payload
448
491
  };
449
- const layoutModule = fs.existsSync(layoutPath) ? resolveModule(layoutPath) : null;
492
+ const layoutModule = fs.existsSync(layoutPath) ? resolveModule(layoutPath, pagesDir) : null;
450
493
  if (!fs.existsSync(errorPath)) {
451
494
  const fallback = /* @__PURE__ */ jsxs("main", { style: { fontFamily: "system-ui, sans-serif", padding: 24 }, children: [
452
495
  /* @__PURE__ */ jsx("h1", { children: statusCode }),
@@ -460,7 +503,7 @@ function createFileRouter(options) {
460
503
  }
461
504
  };
462
505
  }
463
- const errorModule = resolveModule(errorPath);
506
+ const errorModule = resolveModule(errorPath, pagesDir);
464
507
  const errorNode = await errorModule.default(errorProps);
465
508
  const layoutHead = layoutModule ? await resolveHead(layoutModule, context) : void 0;
466
509
  const errorHead = await resolveHead(errorModule, errorProps);
@@ -509,7 +552,10 @@ function createFileRouter(options) {
509
552
  message: `Invalid middleware '${middlewareNames[0]}'`
510
553
  });
511
554
  }
512
- const middlewareModule = resolveModule(middlewaresPath);
555
+ const middlewareModule = resolveModule(
556
+ middlewaresPath,
557
+ pagesDir
558
+ );
513
559
  const registry = middlewareModule.middlewares;
514
560
  if (!registry) {
515
561
  if (!requiresNamedMiddleware) {
@@ -564,8 +610,8 @@ function createFileRouter(options) {
564
610
  params: match.params
565
611
  };
566
612
  activeContext = context;
567
- const pageModule = resolveModule(match.entry.filePath);
568
- const layoutModule = fs.existsSync(layoutPath) ? resolveModule(layoutPath) : null;
613
+ const pageModule = resolveModule(match.entry.filePath, pagesDir);
614
+ const layoutModule = fs.existsSync(layoutPath) ? resolveModule(layoutPath, pagesDir) : null;
569
615
  const middlewareContext = await resolveMiddlewares(pageModule.middlewares, context);
570
616
  activeContext = middlewareContext;
571
617
  const pageData = await resolvePageData(pageModule, middlewareContext);
package/dist/index.cjs CHANGED
@@ -344,21 +344,38 @@ function toRouteEntry(pagesDir, filePath) {
344
344
  const relativeDir = import_node_path2.default.dirname(import_node_path2.default.relative(pagesDir, filePath)).replace(/\\/g, "/");
345
345
  const segments = relativeDir === "." ? [] : relativeDir.split("/").filter(Boolean);
346
346
  const staticCount = segments.filter((segment) => !segment.startsWith("[")).length;
347
+ const catchAllCount = segments.filter(
348
+ (segment) => segment.startsWith("[...") && segment.endsWith("]")
349
+ ).length;
347
350
  return {
348
351
  filePath,
349
352
  segments,
350
- staticCount
353
+ staticCount,
354
+ catchAllCount
351
355
  };
352
356
  }
353
357
  function matchRoute(entry, pathname) {
354
358
  const targetSegments = splitSegments(pathname);
355
- if (entry.segments.length !== targetSegments.length) {
356
- return null;
357
- }
358
359
  const params = {};
359
360
  for (let index = 0; index < entry.segments.length; index += 1) {
360
361
  const routeSegment = entry.segments[index];
362
+ const isCatchAll = routeSegment.startsWith("[...") && routeSegment.endsWith("]");
363
+ if (isCatchAll) {
364
+ const paramName = routeSegment.slice(4, -1);
365
+ if (!paramName || index !== entry.segments.length - 1) {
366
+ return null;
367
+ }
368
+ const restSegments = targetSegments.slice(index);
369
+ if (restSegments.length === 0) {
370
+ return null;
371
+ }
372
+ params[paramName] = restSegments.map((segment) => decodeURIComponent(segment));
373
+ return params;
374
+ }
361
375
  const targetSegment = targetSegments[index];
376
+ if (typeof targetSegment !== "string") {
377
+ return null;
378
+ }
362
379
  if (routeSegment.startsWith("[") && routeSegment.endsWith("]")) {
363
380
  const paramName = routeSegment.slice(1, -1);
364
381
  if (!paramName) {
@@ -371,6 +388,9 @@ function matchRoute(entry, pathname) {
371
388
  return null;
372
389
  }
373
390
  }
391
+ if (entry.segments.length !== targetSegments.length) {
392
+ return null;
393
+ }
374
394
  return params;
375
395
  }
376
396
  function mergeHead(...configs) {
@@ -422,8 +442,25 @@ function renderHeadToString(head) {
422
442
  }
423
443
  return tags.join("\n");
424
444
  }
425
- function resolveModule(modulePath) {
426
- delete require.cache[modulePath];
445
+ function clearModuleCache(modulePath, rootDir, visited = /* @__PURE__ */ new Set()) {
446
+ const resolvedPath = require.resolve(modulePath);
447
+ if (visited.has(resolvedPath)) {
448
+ return;
449
+ }
450
+ visited.add(resolvedPath);
451
+ const cachedModule = require.cache[resolvedPath];
452
+ if (!cachedModule) {
453
+ return;
454
+ }
455
+ for (const child of cachedModule.children) {
456
+ if (child.id.startsWith(rootDir)) {
457
+ clearModuleCache(child.id, rootDir, visited);
458
+ }
459
+ }
460
+ delete require.cache[resolvedPath];
461
+ }
462
+ function resolveModule(modulePath, rootDir) {
463
+ clearModuleCache(modulePath, rootDir);
427
464
  return require(modulePath);
428
465
  }
429
466
  async function resolveHead(candidate, context) {
@@ -450,6 +487,9 @@ function findBestMatch(entries, pathname) {
450
487
  if (b.entry.staticCount !== a.entry.staticCount) {
451
488
  return b.entry.staticCount - a.entry.staticCount;
452
489
  }
490
+ if (a.entry.catchAllCount !== b.entry.catchAllCount) {
491
+ return a.entry.catchAllCount - b.entry.catchAllCount;
492
+ }
453
493
  return b.entry.segments.length - a.entry.segments.length;
454
494
  });
455
495
  return matches[0] ?? null;
@@ -494,6 +534,9 @@ function createFileRouter(options) {
494
534
  if (b.staticCount !== a.staticCount) {
495
535
  return b.staticCount - a.staticCount;
496
536
  }
537
+ if (a.catchAllCount !== b.catchAllCount) {
538
+ return a.catchAllCount - b.catchAllCount;
539
+ }
497
540
  return b.segments.length - a.segments.length;
498
541
  });
499
542
  }
@@ -504,7 +547,7 @@ function createFileRouter(options) {
504
547
  message,
505
548
  payload
506
549
  };
507
- const layoutModule = import_node_fs.default.existsSync(layoutPath) ? resolveModule(layoutPath) : null;
550
+ const layoutModule = import_node_fs.default.existsSync(layoutPath) ? resolveModule(layoutPath, pagesDir) : null;
508
551
  if (!import_node_fs.default.existsSync(errorPath)) {
509
552
  const fallback = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("main", { style: { fontFamily: "system-ui, sans-serif", padding: 24 }, children: [
510
553
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)("h1", { children: statusCode }),
@@ -518,7 +561,7 @@ function createFileRouter(options) {
518
561
  }
519
562
  };
520
563
  }
521
- const errorModule = resolveModule(errorPath);
564
+ const errorModule = resolveModule(errorPath, pagesDir);
522
565
  const errorNode = await errorModule.default(errorProps);
523
566
  const layoutHead = layoutModule ? await resolveHead(layoutModule, context) : void 0;
524
567
  const errorHead = await resolveHead(errorModule, errorProps);
@@ -567,7 +610,10 @@ function createFileRouter(options) {
567
610
  message: `Invalid middleware '${middlewareNames[0]}'`
568
611
  });
569
612
  }
570
- const middlewareModule = resolveModule(middlewaresPath);
613
+ const middlewareModule = resolveModule(
614
+ middlewaresPath,
615
+ pagesDir
616
+ );
571
617
  const registry = middlewareModule.middlewares;
572
618
  if (!registry) {
573
619
  if (!requiresNamedMiddleware) {
@@ -622,8 +668,8 @@ function createFileRouter(options) {
622
668
  params: match.params
623
669
  };
624
670
  activeContext = context;
625
- const pageModule = resolveModule(match.entry.filePath);
626
- const layoutModule = import_node_fs.default.existsSync(layoutPath) ? resolveModule(layoutPath) : null;
671
+ const pageModule = resolveModule(match.entry.filePath, pagesDir);
672
+ const layoutModule = import_node_fs.default.existsSync(layoutPath) ? resolveModule(layoutPath, pagesDir) : null;
627
673
  const middlewareContext = await resolveMiddlewares(pageModule.middlewares, context);
628
674
  activeContext = middlewareContext;
629
675
  const pageData = await resolvePageData(pageModule, middlewareContext);
package/dist/index.js CHANGED
@@ -308,21 +308,38 @@ function toRouteEntry(pagesDir, filePath) {
308
308
  const relativeDir = path2.dirname(path2.relative(pagesDir, filePath)).replace(/\\/g, "/");
309
309
  const segments = relativeDir === "." ? [] : relativeDir.split("/").filter(Boolean);
310
310
  const staticCount = segments.filter((segment) => !segment.startsWith("[")).length;
311
+ const catchAllCount = segments.filter(
312
+ (segment) => segment.startsWith("[...") && segment.endsWith("]")
313
+ ).length;
311
314
  return {
312
315
  filePath,
313
316
  segments,
314
- staticCount
317
+ staticCount,
318
+ catchAllCount
315
319
  };
316
320
  }
317
321
  function matchRoute(entry, pathname) {
318
322
  const targetSegments = splitSegments(pathname);
319
- if (entry.segments.length !== targetSegments.length) {
320
- return null;
321
- }
322
323
  const params = {};
323
324
  for (let index = 0; index < entry.segments.length; index += 1) {
324
325
  const routeSegment = entry.segments[index];
326
+ const isCatchAll = routeSegment.startsWith("[...") && routeSegment.endsWith("]");
327
+ if (isCatchAll) {
328
+ const paramName = routeSegment.slice(4, -1);
329
+ if (!paramName || index !== entry.segments.length - 1) {
330
+ return null;
331
+ }
332
+ const restSegments = targetSegments.slice(index);
333
+ if (restSegments.length === 0) {
334
+ return null;
335
+ }
336
+ params[paramName] = restSegments.map((segment) => decodeURIComponent(segment));
337
+ return params;
338
+ }
325
339
  const targetSegment = targetSegments[index];
340
+ if (typeof targetSegment !== "string") {
341
+ return null;
342
+ }
326
343
  if (routeSegment.startsWith("[") && routeSegment.endsWith("]")) {
327
344
  const paramName = routeSegment.slice(1, -1);
328
345
  if (!paramName) {
@@ -335,6 +352,9 @@ function matchRoute(entry, pathname) {
335
352
  return null;
336
353
  }
337
354
  }
355
+ if (entry.segments.length !== targetSegments.length) {
356
+ return null;
357
+ }
338
358
  return params;
339
359
  }
340
360
  function mergeHead(...configs) {
@@ -386,8 +406,25 @@ function renderHeadToString(head) {
386
406
  }
387
407
  return tags.join("\n");
388
408
  }
389
- function resolveModule(modulePath) {
390
- delete __require.cache[modulePath];
409
+ function clearModuleCache(modulePath, rootDir, visited = /* @__PURE__ */ new Set()) {
410
+ const resolvedPath = __require.resolve(modulePath);
411
+ if (visited.has(resolvedPath)) {
412
+ return;
413
+ }
414
+ visited.add(resolvedPath);
415
+ const cachedModule = __require.cache[resolvedPath];
416
+ if (!cachedModule) {
417
+ return;
418
+ }
419
+ for (const child of cachedModule.children) {
420
+ if (child.id.startsWith(rootDir)) {
421
+ clearModuleCache(child.id, rootDir, visited);
422
+ }
423
+ }
424
+ delete __require.cache[resolvedPath];
425
+ }
426
+ function resolveModule(modulePath, rootDir) {
427
+ clearModuleCache(modulePath, rootDir);
391
428
  return __require(modulePath);
392
429
  }
393
430
  async function resolveHead(candidate, context) {
@@ -414,6 +451,9 @@ function findBestMatch(entries, pathname) {
414
451
  if (b.entry.staticCount !== a.entry.staticCount) {
415
452
  return b.entry.staticCount - a.entry.staticCount;
416
453
  }
454
+ if (a.entry.catchAllCount !== b.entry.catchAllCount) {
455
+ return a.entry.catchAllCount - b.entry.catchAllCount;
456
+ }
417
457
  return b.entry.segments.length - a.entry.segments.length;
418
458
  });
419
459
  return matches[0] ?? null;
@@ -458,6 +498,9 @@ function createFileRouter(options) {
458
498
  if (b.staticCount !== a.staticCount) {
459
499
  return b.staticCount - a.staticCount;
460
500
  }
501
+ if (a.catchAllCount !== b.catchAllCount) {
502
+ return a.catchAllCount - b.catchAllCount;
503
+ }
461
504
  return b.segments.length - a.segments.length;
462
505
  });
463
506
  }
@@ -468,7 +511,7 @@ function createFileRouter(options) {
468
511
  message,
469
512
  payload
470
513
  };
471
- const layoutModule = fs.existsSync(layoutPath) ? resolveModule(layoutPath) : null;
514
+ const layoutModule = fs.existsSync(layoutPath) ? resolveModule(layoutPath, pagesDir) : null;
472
515
  if (!fs.existsSync(errorPath)) {
473
516
  const fallback = /* @__PURE__ */ jsxs("main", { style: { fontFamily: "system-ui, sans-serif", padding: 24 }, children: [
474
517
  /* @__PURE__ */ jsx("h1", { children: statusCode }),
@@ -482,7 +525,7 @@ function createFileRouter(options) {
482
525
  }
483
526
  };
484
527
  }
485
- const errorModule = resolveModule(errorPath);
528
+ const errorModule = resolveModule(errorPath, pagesDir);
486
529
  const errorNode = await errorModule.default(errorProps);
487
530
  const layoutHead = layoutModule ? await resolveHead(layoutModule, context) : void 0;
488
531
  const errorHead = await resolveHead(errorModule, errorProps);
@@ -531,7 +574,10 @@ function createFileRouter(options) {
531
574
  message: `Invalid middleware '${middlewareNames[0]}'`
532
575
  });
533
576
  }
534
- const middlewareModule = resolveModule(middlewaresPath);
577
+ const middlewareModule = resolveModule(
578
+ middlewaresPath,
579
+ pagesDir
580
+ );
535
581
  const registry = middlewareModule.middlewares;
536
582
  if (!registry) {
537
583
  if (!requiresNamedMiddleware) {
@@ -586,8 +632,8 @@ function createFileRouter(options) {
586
632
  params: match.params
587
633
  };
588
634
  activeContext = context;
589
- const pageModule = resolveModule(match.entry.filePath);
590
- const layoutModule = fs.existsSync(layoutPath) ? resolveModule(layoutPath) : null;
635
+ const pageModule = resolveModule(match.entry.filePath, pagesDir);
636
+ const layoutModule = fs.existsSync(layoutPath) ? resolveModule(layoutPath, pagesDir) : null;
591
637
  const middlewareContext = await resolveMiddlewares(pageModule.middlewares, context);
592
638
  activeContext = middlewareContext;
593
639
  const pageData = await resolvePageData(pageModule, middlewareContext);
package/dist/router.cjs CHANGED
@@ -202,21 +202,38 @@ function toRouteEntry(pagesDir, filePath) {
202
202
  const relativeDir = import_node_path.default.dirname(import_node_path.default.relative(pagesDir, filePath)).replace(/\\/g, "/");
203
203
  const segments = relativeDir === "." ? [] : relativeDir.split("/").filter(Boolean);
204
204
  const staticCount = segments.filter((segment) => !segment.startsWith("[")).length;
205
+ const catchAllCount = segments.filter(
206
+ (segment) => segment.startsWith("[...") && segment.endsWith("]")
207
+ ).length;
205
208
  return {
206
209
  filePath,
207
210
  segments,
208
- staticCount
211
+ staticCount,
212
+ catchAllCount
209
213
  };
210
214
  }
211
215
  function matchRoute(entry, pathname) {
212
216
  const targetSegments = splitSegments(pathname);
213
- if (entry.segments.length !== targetSegments.length) {
214
- return null;
215
- }
216
217
  const params = {};
217
218
  for (let index = 0; index < entry.segments.length; index += 1) {
218
219
  const routeSegment = entry.segments[index];
220
+ const isCatchAll = routeSegment.startsWith("[...") && routeSegment.endsWith("]");
221
+ if (isCatchAll) {
222
+ const paramName = routeSegment.slice(4, -1);
223
+ if (!paramName || index !== entry.segments.length - 1) {
224
+ return null;
225
+ }
226
+ const restSegments = targetSegments.slice(index);
227
+ if (restSegments.length === 0) {
228
+ return null;
229
+ }
230
+ params[paramName] = restSegments.map((segment) => decodeURIComponent(segment));
231
+ return params;
232
+ }
219
233
  const targetSegment = targetSegments[index];
234
+ if (typeof targetSegment !== "string") {
235
+ return null;
236
+ }
220
237
  if (routeSegment.startsWith("[") && routeSegment.endsWith("]")) {
221
238
  const paramName = routeSegment.slice(1, -1);
222
239
  if (!paramName) {
@@ -229,6 +246,9 @@ function matchRoute(entry, pathname) {
229
246
  return null;
230
247
  }
231
248
  }
249
+ if (entry.segments.length !== targetSegments.length) {
250
+ return null;
251
+ }
232
252
  return params;
233
253
  }
234
254
  function mergeHead(...configs) {
@@ -280,8 +300,25 @@ function renderHeadToString(head) {
280
300
  }
281
301
  return tags.join("\n");
282
302
  }
283
- function resolveModule(modulePath) {
284
- delete require.cache[modulePath];
303
+ function clearModuleCache(modulePath, rootDir, visited = /* @__PURE__ */ new Set()) {
304
+ const resolvedPath = require.resolve(modulePath);
305
+ if (visited.has(resolvedPath)) {
306
+ return;
307
+ }
308
+ visited.add(resolvedPath);
309
+ const cachedModule = require.cache[resolvedPath];
310
+ if (!cachedModule) {
311
+ return;
312
+ }
313
+ for (const child of cachedModule.children) {
314
+ if (child.id.startsWith(rootDir)) {
315
+ clearModuleCache(child.id, rootDir, visited);
316
+ }
317
+ }
318
+ delete require.cache[resolvedPath];
319
+ }
320
+ function resolveModule(modulePath, rootDir) {
321
+ clearModuleCache(modulePath, rootDir);
285
322
  return require(modulePath);
286
323
  }
287
324
  async function resolveHead(candidate, context) {
@@ -308,6 +345,9 @@ function findBestMatch(entries, pathname) {
308
345
  if (b.entry.staticCount !== a.entry.staticCount) {
309
346
  return b.entry.staticCount - a.entry.staticCount;
310
347
  }
348
+ if (a.entry.catchAllCount !== b.entry.catchAllCount) {
349
+ return a.entry.catchAllCount - b.entry.catchAllCount;
350
+ }
311
351
  return b.entry.segments.length - a.entry.segments.length;
312
352
  });
313
353
  return matches[0] ?? null;
@@ -352,6 +392,9 @@ function createFileRouter(options) {
352
392
  if (b.staticCount !== a.staticCount) {
353
393
  return b.staticCount - a.staticCount;
354
394
  }
395
+ if (a.catchAllCount !== b.catchAllCount) {
396
+ return a.catchAllCount - b.catchAllCount;
397
+ }
355
398
  return b.segments.length - a.segments.length;
356
399
  });
357
400
  }
@@ -362,7 +405,7 @@ function createFileRouter(options) {
362
405
  message,
363
406
  payload
364
407
  };
365
- const layoutModule = import_node_fs.default.existsSync(layoutPath) ? resolveModule(layoutPath) : null;
408
+ const layoutModule = import_node_fs.default.existsSync(layoutPath) ? resolveModule(layoutPath, pagesDir) : null;
366
409
  if (!import_node_fs.default.existsSync(errorPath)) {
367
410
  const fallback = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("main", { style: { fontFamily: "system-ui, sans-serif", padding: 24 }, children: [
368
411
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)("h1", { children: statusCode }),
@@ -376,7 +419,7 @@ function createFileRouter(options) {
376
419
  }
377
420
  };
378
421
  }
379
- const errorModule = resolveModule(errorPath);
422
+ const errorModule = resolveModule(errorPath, pagesDir);
380
423
  const errorNode = await errorModule.default(errorProps);
381
424
  const layoutHead = layoutModule ? await resolveHead(layoutModule, context) : void 0;
382
425
  const errorHead = await resolveHead(errorModule, errorProps);
@@ -425,7 +468,10 @@ function createFileRouter(options) {
425
468
  message: `Invalid middleware '${middlewareNames[0]}'`
426
469
  });
427
470
  }
428
- const middlewareModule = resolveModule(middlewaresPath);
471
+ const middlewareModule = resolveModule(
472
+ middlewaresPath,
473
+ pagesDir
474
+ );
429
475
  const registry = middlewareModule.middlewares;
430
476
  if (!registry) {
431
477
  if (!requiresNamedMiddleware) {
@@ -480,8 +526,8 @@ function createFileRouter(options) {
480
526
  params: match.params
481
527
  };
482
528
  activeContext = context;
483
- const pageModule = resolveModule(match.entry.filePath);
484
- const layoutModule = import_node_fs.default.existsSync(layoutPath) ? resolveModule(layoutPath) : null;
529
+ const pageModule = resolveModule(match.entry.filePath, pagesDir);
530
+ const layoutModule = import_node_fs.default.existsSync(layoutPath) ? resolveModule(layoutPath, pagesDir) : null;
485
531
  const middlewareContext = await resolveMiddlewares(pageModule.middlewares, context);
486
532
  activeContext = middlewareContext;
487
533
  const pageData = await resolvePageData(pageModule, middlewareContext);
package/dist/router.js CHANGED
@@ -172,21 +172,38 @@ function toRouteEntry(pagesDir, filePath) {
172
172
  const relativeDir = path.dirname(path.relative(pagesDir, filePath)).replace(/\\/g, "/");
173
173
  const segments = relativeDir === "." ? [] : relativeDir.split("/").filter(Boolean);
174
174
  const staticCount = segments.filter((segment) => !segment.startsWith("[")).length;
175
+ const catchAllCount = segments.filter(
176
+ (segment) => segment.startsWith("[...") && segment.endsWith("]")
177
+ ).length;
175
178
  return {
176
179
  filePath,
177
180
  segments,
178
- staticCount
181
+ staticCount,
182
+ catchAllCount
179
183
  };
180
184
  }
181
185
  function matchRoute(entry, pathname) {
182
186
  const targetSegments = splitSegments(pathname);
183
- if (entry.segments.length !== targetSegments.length) {
184
- return null;
185
- }
186
187
  const params = {};
187
188
  for (let index = 0; index < entry.segments.length; index += 1) {
188
189
  const routeSegment = entry.segments[index];
190
+ const isCatchAll = routeSegment.startsWith("[...") && routeSegment.endsWith("]");
191
+ if (isCatchAll) {
192
+ const paramName = routeSegment.slice(4, -1);
193
+ if (!paramName || index !== entry.segments.length - 1) {
194
+ return null;
195
+ }
196
+ const restSegments = targetSegments.slice(index);
197
+ if (restSegments.length === 0) {
198
+ return null;
199
+ }
200
+ params[paramName] = restSegments.map((segment) => decodeURIComponent(segment));
201
+ return params;
202
+ }
189
203
  const targetSegment = targetSegments[index];
204
+ if (typeof targetSegment !== "string") {
205
+ return null;
206
+ }
190
207
  if (routeSegment.startsWith("[") && routeSegment.endsWith("]")) {
191
208
  const paramName = routeSegment.slice(1, -1);
192
209
  if (!paramName) {
@@ -199,6 +216,9 @@ function matchRoute(entry, pathname) {
199
216
  return null;
200
217
  }
201
218
  }
219
+ if (entry.segments.length !== targetSegments.length) {
220
+ return null;
221
+ }
202
222
  return params;
203
223
  }
204
224
  function mergeHead(...configs) {
@@ -250,8 +270,25 @@ function renderHeadToString(head) {
250
270
  }
251
271
  return tags.join("\n");
252
272
  }
253
- function resolveModule(modulePath) {
254
- delete __require.cache[modulePath];
273
+ function clearModuleCache(modulePath, rootDir, visited = /* @__PURE__ */ new Set()) {
274
+ const resolvedPath = __require.resolve(modulePath);
275
+ if (visited.has(resolvedPath)) {
276
+ return;
277
+ }
278
+ visited.add(resolvedPath);
279
+ const cachedModule = __require.cache[resolvedPath];
280
+ if (!cachedModule) {
281
+ return;
282
+ }
283
+ for (const child of cachedModule.children) {
284
+ if (child.id.startsWith(rootDir)) {
285
+ clearModuleCache(child.id, rootDir, visited);
286
+ }
287
+ }
288
+ delete __require.cache[resolvedPath];
289
+ }
290
+ function resolveModule(modulePath, rootDir) {
291
+ clearModuleCache(modulePath, rootDir);
255
292
  return __require(modulePath);
256
293
  }
257
294
  async function resolveHead(candidate, context) {
@@ -278,6 +315,9 @@ function findBestMatch(entries, pathname) {
278
315
  if (b.entry.staticCount !== a.entry.staticCount) {
279
316
  return b.entry.staticCount - a.entry.staticCount;
280
317
  }
318
+ if (a.entry.catchAllCount !== b.entry.catchAllCount) {
319
+ return a.entry.catchAllCount - b.entry.catchAllCount;
320
+ }
281
321
  return b.entry.segments.length - a.entry.segments.length;
282
322
  });
283
323
  return matches[0] ?? null;
@@ -322,6 +362,9 @@ function createFileRouter(options) {
322
362
  if (b.staticCount !== a.staticCount) {
323
363
  return b.staticCount - a.staticCount;
324
364
  }
365
+ if (a.catchAllCount !== b.catchAllCount) {
366
+ return a.catchAllCount - b.catchAllCount;
367
+ }
325
368
  return b.segments.length - a.segments.length;
326
369
  });
327
370
  }
@@ -332,7 +375,7 @@ function createFileRouter(options) {
332
375
  message,
333
376
  payload
334
377
  };
335
- const layoutModule = fs.existsSync(layoutPath) ? resolveModule(layoutPath) : null;
378
+ const layoutModule = fs.existsSync(layoutPath) ? resolveModule(layoutPath, pagesDir) : null;
336
379
  if (!fs.existsSync(errorPath)) {
337
380
  const fallback = /* @__PURE__ */ jsxs("main", { style: { fontFamily: "system-ui, sans-serif", padding: 24 }, children: [
338
381
  /* @__PURE__ */ jsx("h1", { children: statusCode }),
@@ -346,7 +389,7 @@ function createFileRouter(options) {
346
389
  }
347
390
  };
348
391
  }
349
- const errorModule = resolveModule(errorPath);
392
+ const errorModule = resolveModule(errorPath, pagesDir);
350
393
  const errorNode = await errorModule.default(errorProps);
351
394
  const layoutHead = layoutModule ? await resolveHead(layoutModule, context) : void 0;
352
395
  const errorHead = await resolveHead(errorModule, errorProps);
@@ -395,7 +438,10 @@ function createFileRouter(options) {
395
438
  message: `Invalid middleware '${middlewareNames[0]}'`
396
439
  });
397
440
  }
398
- const middlewareModule = resolveModule(middlewaresPath);
441
+ const middlewareModule = resolveModule(
442
+ middlewaresPath,
443
+ pagesDir
444
+ );
399
445
  const registry = middlewareModule.middlewares;
400
446
  if (!registry) {
401
447
  if (!requiresNamedMiddleware) {
@@ -450,8 +496,8 @@ function createFileRouter(options) {
450
496
  params: match.params
451
497
  };
452
498
  activeContext = context;
453
- const pageModule = resolveModule(match.entry.filePath);
454
- const layoutModule = fs.existsSync(layoutPath) ? resolveModule(layoutPath) : null;
499
+ const pageModule = resolveModule(match.entry.filePath, pagesDir);
500
+ const layoutModule = fs.existsSync(layoutPath) ? resolveModule(layoutPath, pagesDir) : null;
455
501
  const middlewareContext = await resolveMiddlewares(pageModule.middlewares, context);
456
502
  activeContext = middlewareContext;
457
503
  const pageData = await resolvePageData(pageModule, middlewareContext);
package/dist/types.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import type { ReactNode } from "react";
2
2
 
3
- export type RouteParams = Record<string, string>;
3
+ export type RouteParams = Record<string, string | string[]>;
4
4
  export type RouteSearchParams = Record<string, string | string[]>;
5
5
 
6
6
  export type AbortRouteOptions = {
@@ -314,21 +314,38 @@ function toRouteEntry(pagesDir, filePath) {
314
314
  const relativeDir = import_node_path2.default.dirname(import_node_path2.default.relative(pagesDir, filePath)).replace(/\\/g, "/");
315
315
  const segments = relativeDir === "." ? [] : relativeDir.split("/").filter(Boolean);
316
316
  const staticCount = segments.filter((segment) => !segment.startsWith("[")).length;
317
+ const catchAllCount = segments.filter(
318
+ (segment) => segment.startsWith("[...") && segment.endsWith("]")
319
+ ).length;
317
320
  return {
318
321
  filePath,
319
322
  segments,
320
- staticCount
323
+ staticCount,
324
+ catchAllCount
321
325
  };
322
326
  }
323
327
  function matchRoute(entry, pathname) {
324
328
  const targetSegments = splitSegments(pathname);
325
- if (entry.segments.length !== targetSegments.length) {
326
- return null;
327
- }
328
329
  const params = {};
329
330
  for (let index = 0; index < entry.segments.length; index += 1) {
330
331
  const routeSegment = entry.segments[index];
332
+ const isCatchAll = routeSegment.startsWith("[...") && routeSegment.endsWith("]");
333
+ if (isCatchAll) {
334
+ const paramName = routeSegment.slice(4, -1);
335
+ if (!paramName || index !== entry.segments.length - 1) {
336
+ return null;
337
+ }
338
+ const restSegments = targetSegments.slice(index);
339
+ if (restSegments.length === 0) {
340
+ return null;
341
+ }
342
+ params[paramName] = restSegments.map((segment) => decodeURIComponent(segment));
343
+ return params;
344
+ }
331
345
  const targetSegment = targetSegments[index];
346
+ if (typeof targetSegment !== "string") {
347
+ return null;
348
+ }
332
349
  if (routeSegment.startsWith("[") && routeSegment.endsWith("]")) {
333
350
  const paramName = routeSegment.slice(1, -1);
334
351
  if (!paramName) {
@@ -341,6 +358,9 @@ function matchRoute(entry, pathname) {
341
358
  return null;
342
359
  }
343
360
  }
361
+ if (entry.segments.length !== targetSegments.length) {
362
+ return null;
363
+ }
344
364
  return params;
345
365
  }
346
366
  function mergeHead(...configs) {
@@ -392,8 +412,25 @@ function renderHeadToString(head) {
392
412
  }
393
413
  return tags.join("\n");
394
414
  }
395
- function resolveModule(modulePath) {
396
- delete require.cache[modulePath];
415
+ function clearModuleCache(modulePath, rootDir, visited = /* @__PURE__ */ new Set()) {
416
+ const resolvedPath = require.resolve(modulePath);
417
+ if (visited.has(resolvedPath)) {
418
+ return;
419
+ }
420
+ visited.add(resolvedPath);
421
+ const cachedModule = require.cache[resolvedPath];
422
+ if (!cachedModule) {
423
+ return;
424
+ }
425
+ for (const child of cachedModule.children) {
426
+ if (child.id.startsWith(rootDir)) {
427
+ clearModuleCache(child.id, rootDir, visited);
428
+ }
429
+ }
430
+ delete require.cache[resolvedPath];
431
+ }
432
+ function resolveModule(modulePath, rootDir) {
433
+ clearModuleCache(modulePath, rootDir);
397
434
  return require(modulePath);
398
435
  }
399
436
  async function resolveHead(candidate, context) {
@@ -420,6 +457,9 @@ function findBestMatch(entries, pathname) {
420
457
  if (b.entry.staticCount !== a.entry.staticCount) {
421
458
  return b.entry.staticCount - a.entry.staticCount;
422
459
  }
460
+ if (a.entry.catchAllCount !== b.entry.catchAllCount) {
461
+ return a.entry.catchAllCount - b.entry.catchAllCount;
462
+ }
423
463
  return b.entry.segments.length - a.entry.segments.length;
424
464
  });
425
465
  return matches[0] ?? null;
@@ -464,6 +504,9 @@ function createFileRouter(options) {
464
504
  if (b.staticCount !== a.staticCount) {
465
505
  return b.staticCount - a.staticCount;
466
506
  }
507
+ if (a.catchAllCount !== b.catchAllCount) {
508
+ return a.catchAllCount - b.catchAllCount;
509
+ }
467
510
  return b.segments.length - a.segments.length;
468
511
  });
469
512
  }
@@ -474,7 +517,7 @@ function createFileRouter(options) {
474
517
  message,
475
518
  payload
476
519
  };
477
- const layoutModule = import_node_fs.default.existsSync(layoutPath) ? resolveModule(layoutPath) : null;
520
+ const layoutModule = import_node_fs.default.existsSync(layoutPath) ? resolveModule(layoutPath, pagesDir) : null;
478
521
  if (!import_node_fs.default.existsSync(errorPath)) {
479
522
  const fallback = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("main", { style: { fontFamily: "system-ui, sans-serif", padding: 24 }, children: [
480
523
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)("h1", { children: statusCode }),
@@ -488,7 +531,7 @@ function createFileRouter(options) {
488
531
  }
489
532
  };
490
533
  }
491
- const errorModule = resolveModule(errorPath);
534
+ const errorModule = resolveModule(errorPath, pagesDir);
492
535
  const errorNode = await errorModule.default(errorProps);
493
536
  const layoutHead = layoutModule ? await resolveHead(layoutModule, context) : void 0;
494
537
  const errorHead = await resolveHead(errorModule, errorProps);
@@ -537,7 +580,10 @@ function createFileRouter(options) {
537
580
  message: `Invalid middleware '${middlewareNames[0]}'`
538
581
  });
539
582
  }
540
- const middlewareModule = resolveModule(middlewaresPath);
583
+ const middlewareModule = resolveModule(
584
+ middlewaresPath,
585
+ pagesDir
586
+ );
541
587
  const registry = middlewareModule.middlewares;
542
588
  if (!registry) {
543
589
  if (!requiresNamedMiddleware) {
@@ -592,8 +638,8 @@ function createFileRouter(options) {
592
638
  params: match.params
593
639
  };
594
640
  activeContext = context;
595
- const pageModule = resolveModule(match.entry.filePath);
596
- const layoutModule = import_node_fs.default.existsSync(layoutPath) ? resolveModule(layoutPath) : null;
641
+ const pageModule = resolveModule(match.entry.filePath, pagesDir);
642
+ const layoutModule = import_node_fs.default.existsSync(layoutPath) ? resolveModule(layoutPath, pagesDir) : null;
597
643
  const middlewareContext = await resolveMiddlewares(pageModule.middlewares, context);
598
644
  activeContext = middlewareContext;
599
645
  const pageData = await resolvePageData(pageModule, middlewareContext);
@@ -286,21 +286,38 @@ function toRouteEntry(pagesDir, filePath) {
286
286
  const relativeDir = path2.dirname(path2.relative(pagesDir, filePath)).replace(/\\/g, "/");
287
287
  const segments = relativeDir === "." ? [] : relativeDir.split("/").filter(Boolean);
288
288
  const staticCount = segments.filter((segment) => !segment.startsWith("[")).length;
289
+ const catchAllCount = segments.filter(
290
+ (segment) => segment.startsWith("[...") && segment.endsWith("]")
291
+ ).length;
289
292
  return {
290
293
  filePath,
291
294
  segments,
292
- staticCount
295
+ staticCount,
296
+ catchAllCount
293
297
  };
294
298
  }
295
299
  function matchRoute(entry, pathname) {
296
300
  const targetSegments = splitSegments(pathname);
297
- if (entry.segments.length !== targetSegments.length) {
298
- return null;
299
- }
300
301
  const params = {};
301
302
  for (let index = 0; index < entry.segments.length; index += 1) {
302
303
  const routeSegment = entry.segments[index];
304
+ const isCatchAll = routeSegment.startsWith("[...") && routeSegment.endsWith("]");
305
+ if (isCatchAll) {
306
+ const paramName = routeSegment.slice(4, -1);
307
+ if (!paramName || index !== entry.segments.length - 1) {
308
+ return null;
309
+ }
310
+ const restSegments = targetSegments.slice(index);
311
+ if (restSegments.length === 0) {
312
+ return null;
313
+ }
314
+ params[paramName] = restSegments.map((segment) => decodeURIComponent(segment));
315
+ return params;
316
+ }
303
317
  const targetSegment = targetSegments[index];
318
+ if (typeof targetSegment !== "string") {
319
+ return null;
320
+ }
304
321
  if (routeSegment.startsWith("[") && routeSegment.endsWith("]")) {
305
322
  const paramName = routeSegment.slice(1, -1);
306
323
  if (!paramName) {
@@ -313,6 +330,9 @@ function matchRoute(entry, pathname) {
313
330
  return null;
314
331
  }
315
332
  }
333
+ if (entry.segments.length !== targetSegments.length) {
334
+ return null;
335
+ }
316
336
  return params;
317
337
  }
318
338
  function mergeHead(...configs) {
@@ -364,8 +384,25 @@ function renderHeadToString(head) {
364
384
  }
365
385
  return tags.join("\n");
366
386
  }
367
- function resolveModule(modulePath) {
368
- delete __require.cache[modulePath];
387
+ function clearModuleCache(modulePath, rootDir, visited = /* @__PURE__ */ new Set()) {
388
+ const resolvedPath = __require.resolve(modulePath);
389
+ if (visited.has(resolvedPath)) {
390
+ return;
391
+ }
392
+ visited.add(resolvedPath);
393
+ const cachedModule = __require.cache[resolvedPath];
394
+ if (!cachedModule) {
395
+ return;
396
+ }
397
+ for (const child of cachedModule.children) {
398
+ if (child.id.startsWith(rootDir)) {
399
+ clearModuleCache(child.id, rootDir, visited);
400
+ }
401
+ }
402
+ delete __require.cache[resolvedPath];
403
+ }
404
+ function resolveModule(modulePath, rootDir) {
405
+ clearModuleCache(modulePath, rootDir);
369
406
  return __require(modulePath);
370
407
  }
371
408
  async function resolveHead(candidate, context) {
@@ -392,6 +429,9 @@ function findBestMatch(entries, pathname) {
392
429
  if (b.entry.staticCount !== a.entry.staticCount) {
393
430
  return b.entry.staticCount - a.entry.staticCount;
394
431
  }
432
+ if (a.entry.catchAllCount !== b.entry.catchAllCount) {
433
+ return a.entry.catchAllCount - b.entry.catchAllCount;
434
+ }
395
435
  return b.entry.segments.length - a.entry.segments.length;
396
436
  });
397
437
  return matches[0] ?? null;
@@ -436,6 +476,9 @@ function createFileRouter(options) {
436
476
  if (b.staticCount !== a.staticCount) {
437
477
  return b.staticCount - a.staticCount;
438
478
  }
479
+ if (a.catchAllCount !== b.catchAllCount) {
480
+ return a.catchAllCount - b.catchAllCount;
481
+ }
439
482
  return b.segments.length - a.segments.length;
440
483
  });
441
484
  }
@@ -446,7 +489,7 @@ function createFileRouter(options) {
446
489
  message,
447
490
  payload
448
491
  };
449
- const layoutModule = fs.existsSync(layoutPath) ? resolveModule(layoutPath) : null;
492
+ const layoutModule = fs.existsSync(layoutPath) ? resolveModule(layoutPath, pagesDir) : null;
450
493
  if (!fs.existsSync(errorPath)) {
451
494
  const fallback = /* @__PURE__ */ jsxs("main", { style: { fontFamily: "system-ui, sans-serif", padding: 24 }, children: [
452
495
  /* @__PURE__ */ jsx("h1", { children: statusCode }),
@@ -460,7 +503,7 @@ function createFileRouter(options) {
460
503
  }
461
504
  };
462
505
  }
463
- const errorModule = resolveModule(errorPath);
506
+ const errorModule = resolveModule(errorPath, pagesDir);
464
507
  const errorNode = await errorModule.default(errorProps);
465
508
  const layoutHead = layoutModule ? await resolveHead(layoutModule, context) : void 0;
466
509
  const errorHead = await resolveHead(errorModule, errorProps);
@@ -509,7 +552,10 @@ function createFileRouter(options) {
509
552
  message: `Invalid middleware '${middlewareNames[0]}'`
510
553
  });
511
554
  }
512
- const middlewareModule = resolveModule(middlewaresPath);
555
+ const middlewareModule = resolveModule(
556
+ middlewaresPath,
557
+ pagesDir
558
+ );
513
559
  const registry = middlewareModule.middlewares;
514
560
  if (!registry) {
515
561
  if (!requiresNamedMiddleware) {
@@ -564,8 +610,8 @@ function createFileRouter(options) {
564
610
  params: match.params
565
611
  };
566
612
  activeContext = context;
567
- const pageModule = resolveModule(match.entry.filePath);
568
- const layoutModule = fs.existsSync(layoutPath) ? resolveModule(layoutPath) : null;
613
+ const pageModule = resolveModule(match.entry.filePath, pagesDir);
614
+ const layoutModule = fs.existsSync(layoutPath) ? resolveModule(layoutPath, pagesDir) : null;
569
615
  const middlewareContext = await resolveMiddlewares(pageModule.middlewares, context);
570
616
  activeContext = middlewareContext;
571
617
  const pageData = await resolvePageData(pageModule, middlewareContext);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webtypen/webframez-react",
3
- "version": "0.0.22",
3
+ "version": "0.0.24",
4
4
  "description": "TypeScript React RSC addition for @webtypen/webframez-core",
5
5
  "homepage": "https://webtypen.de/",
6
6
  "author": {