@reckona/mreact-router 0.0.175 → 0.0.176

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.
Files changed (64) hide show
  1. package/dist/adapters/cloudflare.d.ts.map +1 -1
  2. package/dist/adapters/cloudflare.js +5 -49
  3. package/dist/adapters/cloudflare.js.map +1 -1
  4. package/dist/build.d.ts +1 -0
  5. package/dist/build.d.ts.map +1 -1
  6. package/dist/build.js +90 -0
  7. package/dist/build.js.map +1 -1
  8. package/dist/built-assets.d.ts +11 -0
  9. package/dist/built-assets.d.ts.map +1 -0
  10. package/dist/built-assets.js +130 -0
  11. package/dist/built-assets.js.map +1 -0
  12. package/dist/built-runtime.d.ts +53 -0
  13. package/dist/built-runtime.d.ts.map +1 -0
  14. package/dist/built-runtime.js +178 -0
  15. package/dist/built-runtime.js.map +1 -0
  16. package/dist/built-server-module-artifacts.d.ts +19 -0
  17. package/dist/built-server-module-artifacts.d.ts.map +1 -0
  18. package/dist/built-server-module-artifacts.js +217 -0
  19. package/dist/built-server-module-artifacts.js.map +1 -0
  20. package/dist/client-manifest-assets.d.ts +16 -0
  21. package/dist/client-manifest-assets.d.ts.map +1 -0
  22. package/dist/client-manifest-assets.js +60 -0
  23. package/dist/client-manifest-assets.js.map +1 -0
  24. package/dist/client.d.ts.map +1 -1
  25. package/dist/client.js +31 -3
  26. package/dist/client.js.map +1 -1
  27. package/dist/node-server.d.ts +29 -0
  28. package/dist/node-server.d.ts.map +1 -0
  29. package/dist/node-server.js +81 -0
  30. package/dist/node-server.js.map +1 -0
  31. package/dist/render.d.ts +9 -0
  32. package/dist/render.d.ts.map +1 -1
  33. package/dist/render.js +20 -41
  34. package/dist/render.js.map +1 -1
  35. package/dist/route-dispatch.d.ts +2 -0
  36. package/dist/route-dispatch.d.ts.map +1 -0
  37. package/dist/route-dispatch.js +16 -0
  38. package/dist/route-dispatch.js.map +1 -0
  39. package/dist/route-loader-runtime.d.ts +22 -0
  40. package/dist/route-loader-runtime.d.ts.map +1 -0
  41. package/dist/route-loader-runtime.js +30 -0
  42. package/dist/route-loader-runtime.js.map +1 -0
  43. package/dist/routes.d.ts +2 -0
  44. package/dist/routes.d.ts.map +1 -1
  45. package/dist/routes.js +48 -1
  46. package/dist/routes.js.map +1 -1
  47. package/dist/serve.d.ts +4 -3
  48. package/dist/serve.d.ts.map +1 -1
  49. package/dist/serve.js +84 -582
  50. package/dist/serve.js.map +1 -1
  51. package/package.json +11 -11
  52. package/src/adapters/cloudflare.ts +5 -60
  53. package/src/build.ts +143 -0
  54. package/src/built-assets.ts +164 -0
  55. package/src/built-runtime.ts +312 -0
  56. package/src/built-server-module-artifacts.ts +340 -0
  57. package/src/client-manifest-assets.ts +92 -0
  58. package/src/client.ts +31 -3
  59. package/src/node-server.ts +129 -0
  60. package/src/render.ts +38 -60
  61. package/src/route-dispatch.ts +17 -0
  62. package/src/route-loader-runtime.ts +54 -0
  63. package/src/routes.ts +70 -1
  64. package/src/serve.ts +105 -863
package/dist/build.js CHANGED
@@ -270,6 +270,7 @@ export async function buildApp(options) {
270
270
  ...clientBundle.styles.flatMap((style) => style.css),
271
271
  ...(navigationRuntimeScript === undefined ? [] : [navigationRuntimeScript]),
272
272
  ])).sort();
273
+ const serverModuleClosureFiles = buildServerModuleClosureManifest(serverModules, sourceAnalysis);
273
274
  const prerenderedRoutes = shouldTrackBuildPhases === false
274
275
  ? await prerenderStaticRoutes({
275
276
  appDir: project.routesDir,
@@ -341,6 +342,9 @@ export async function buildApp(options) {
341
342
  ...(serverActionManifest.allowedActions.length === 0
342
343
  ? {}
343
344
  : { serverActionManifest: serverActionManifest.allowedActions }),
345
+ ...(Object.keys(serverModuleClosureFiles).length === 0
346
+ ? {}
347
+ : { serverModuleClosureFiles }),
344
348
  ...(Object.keys(serverModuleArtifacts.files).length === 0
345
349
  ? {}
346
350
  : { serverModuleFiles: serverModuleArtifacts.files }),
@@ -559,6 +563,92 @@ function analyzeBuildSource(source, filename) {
559
563
  function buildSourceAnalysisForFile(sourceAnalysis, projectRoot, file) {
560
564
  return sourceAnalysis.byFile.get(relative(projectRoot, file).split(sep).join("/"));
561
565
  }
566
+ function buildServerModuleClosureManifest(serverModules, sourceAnalysis) {
567
+ const sourceFiles = new Set(sourceAnalysis.byFile.keys());
568
+ const closureFiles = {};
569
+ for (const file of Object.keys(serverModules).sort()) {
570
+ const closure = [];
571
+ collectManifestServerModuleClosureFiles(file, sourceAnalysis, sourceFiles, new Set(), closure);
572
+ if (closure.length > 0) {
573
+ closureFiles[file] = closure;
574
+ }
575
+ }
576
+ return closureFiles;
577
+ }
578
+ function collectManifestServerModuleClosureFiles(file, sourceAnalysis, sourceFiles, seen, closure) {
579
+ if (seen.has(file)) {
580
+ return;
581
+ }
582
+ seen.add(file);
583
+ closure.push(file);
584
+ const source = sourceAnalysis.byFile.get(file)?.source;
585
+ if (source === undefined) {
586
+ return;
587
+ }
588
+ for (const specifier of localManifestServerModuleSpecifiers(source)) {
589
+ const resolved = resolveManifestLocalServerSourceImport(file, specifier, sourceFiles);
590
+ if (resolved !== undefined) {
591
+ collectManifestServerModuleClosureFiles(resolved, sourceAnalysis, sourceFiles, seen, closure);
592
+ }
593
+ }
594
+ }
595
+ const localManifestServerModuleImportPattern = /\b(?:import|export)\s+(?:type\s+)?(?:[^"']*?\s+from\s*)?["'](?<source>\.{1,2}\/[^"']+)["']/g;
596
+ function localManifestServerModuleSpecifiers(code) {
597
+ const specifiers = new Set();
598
+ localManifestServerModuleImportPattern.lastIndex = 0;
599
+ for (const match of code.matchAll(localManifestServerModuleImportPattern)) {
600
+ const source = match.groups?.source;
601
+ if (source !== undefined) {
602
+ specifiers.add(source);
603
+ }
604
+ }
605
+ return Array.from(specifiers);
606
+ }
607
+ function resolveManifestLocalServerSourceImport(fromFile, specifier, sourceFiles) {
608
+ const base = resolveManifestRelativePath(manifestDirname(fromFile), specifier);
609
+ for (const candidate of manifestLocalServerSourceImportCandidates(base)) {
610
+ if (sourceFiles.has(candidate)) {
611
+ return candidate;
612
+ }
613
+ }
614
+ return undefined;
615
+ }
616
+ function manifestLocalServerSourceImportCandidates(base) {
617
+ const candidates = [base];
618
+ if (base.endsWith(".js")) {
619
+ const withoutJs = base.slice(0, -".js".length);
620
+ candidates.push(`${withoutJs}.ts`, `${withoutJs}.tsx`, `${withoutJs}.mreact.tsx`);
621
+ }
622
+ else if (base.endsWith(".jsx")) {
623
+ const withoutJsx = base.slice(0, -".jsx".length);
624
+ candidates.push(`${withoutJsx}.tsx`, `${withoutJsx}.mreact.tsx`);
625
+ }
626
+ else if (base.endsWith(".mreact")) {
627
+ candidates.push(`${base}.tsx`);
628
+ }
629
+ else {
630
+ candidates.push(`${base}.ts`, `${base}.tsx`, `${base}.mreact.tsx`, `${base}/index.ts`, `${base}/index.tsx`, `${base}/index.mreact.tsx`);
631
+ }
632
+ return candidates;
633
+ }
634
+ function manifestDirname(file) {
635
+ const index = file.lastIndexOf("/");
636
+ return index === -1 ? "" : file.slice(0, index);
637
+ }
638
+ function resolveManifestRelativePath(fromDir, specifier) {
639
+ const segments = fromDir === "" ? [] : fromDir.split("/");
640
+ for (const segment of specifier.split("/")) {
641
+ if (segment === "" || segment === ".") {
642
+ continue;
643
+ }
644
+ if (segment === "..") {
645
+ segments.pop();
646
+ continue;
647
+ }
648
+ segments.push(segment);
649
+ }
650
+ return segments.join("/");
651
+ }
562
652
  function canUseBuildServerActionPlaceholders(references) {
563
653
  return references.every((reference) => reference.expression === reference.exportName &&
564
654
  /^[A-Za-z_$][\w$]*$/u.test(reference.expression));