@absolutejs/absolute 0.19.0-beta.930 → 0.19.0-beta.932

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.
@@ -2552,16 +2552,22 @@ var setConventions = (map) => {
2552
2552
  };
2553
2553
  var isDev = () => true;
2554
2554
  var buildErrorProps = (error) => {
2555
- const message = error instanceof Error ? error.message : String(error);
2556
- const stack = isDev() && error instanceof Error ? error.stack : undefined;
2557
- return { error: { message, stack } };
2555
+ if (error instanceof Error) {
2556
+ return {
2557
+ name: error.name,
2558
+ message: error.message,
2559
+ ...isDev() && error.stack ? { stack: error.stack } : {}
2560
+ };
2561
+ }
2562
+ return { name: "Error", message: String(error) };
2558
2563
  };
2559
2564
  var renderReactError = async (conventionPath, errorProps) => {
2560
2565
  const { createElement } = await import("react");
2561
2566
  const { renderToReadableStream } = await import("react-dom/server");
2562
2567
  const mod = await import(conventionPath);
2563
- const [firstKey] = Object.keys(mod);
2564
- const ErrorComponent = mod.default ?? (firstKey ? mod[firstKey] : undefined);
2568
+ const ErrorComponent = mod.default;
2569
+ if (typeof ErrorComponent !== "function")
2570
+ return null;
2565
2571
  const element = createElement(ErrorComponent, errorProps);
2566
2572
  const stream = await renderToReadableStream(element);
2567
2573
  return new Response(stream, {
@@ -2573,6 +2579,8 @@ var renderSvelteError = async (conventionPath, errorProps) => {
2573
2579
  const { render } = await import("svelte/server");
2574
2580
  const mod = await import(conventionPath);
2575
2581
  const ErrorComponent = mod.default;
2582
+ if (!ErrorComponent)
2583
+ return null;
2576
2584
  const { head, body } = render(ErrorComponent, {
2577
2585
  props: errorProps
2578
2586
  });
@@ -2595,6 +2603,8 @@ var renderVueError = async (conventionPath, errorProps) => {
2595
2603
  const { renderToString } = await import("vue/server-renderer");
2596
2604
  const mod = await import(conventionPath);
2597
2605
  const ErrorComponent = mod.default;
2606
+ if (!ErrorComponent)
2607
+ return null;
2598
2608
  const app = createSSRApp({
2599
2609
  render: () => h(ErrorComponent, errorProps)
2600
2610
  });
@@ -2608,10 +2618,20 @@ var renderVueError = async (conventionPath, errorProps) => {
2608
2618
  };
2609
2619
  var renderAngularError = async (conventionPath, errorProps) => {
2610
2620
  const mod = await import(conventionPath);
2611
- const renderError = mod.default ?? mod.renderError;
2612
- if (typeof renderError !== "function")
2621
+ const renderFn = mod.default;
2622
+ if (typeof renderFn !== "function")
2613
2623
  return null;
2614
- const html = renderError(errorProps);
2624
+ const html = renderFn(errorProps);
2625
+ return new Response(html, {
2626
+ headers: { "Content-Type": "text/html" },
2627
+ status: 500
2628
+ });
2629
+ };
2630
+ var escapeHtml = (value) => value.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;");
2631
+ var replaceErrorTokens = (template, errorProps) => template.replace(/\{\{\s*name\s*\}\}/g, escapeHtml(errorProps.name)).replace(/\{\{\s*message\s*\}\}/g, escapeHtml(errorProps.message)).replace(/\{\{\s*stack\s*\}\}/g, errorProps.stack ? escapeHtml(errorProps.stack) : "");
2632
+ var renderHtmlError = async (conventionPath, errorProps) => {
2633
+ const template = await Bun.file(conventionPath).text();
2634
+ const html = replaceErrorTokens(template, errorProps);
2615
2635
  return new Response(html, {
2616
2636
  headers: { "Content-Type": "text/html" },
2617
2637
  status: 500
@@ -2630,11 +2650,12 @@ var renderEmberNotFound = async () => null;
2630
2650
  var ERROR_RENDERERS = {
2631
2651
  angular: renderAngularError,
2632
2652
  ember: renderEmberError,
2653
+ html: renderHtmlError,
2633
2654
  react: renderReactError,
2634
2655
  svelte: renderSvelteError,
2635
2656
  vue: renderVueError
2636
2657
  };
2637
- var renderConventionError = async (framework, pageName, error) => {
2658
+ var tryFrameworkErrorConvention = async (framework, pageName, errorProps, error) => {
2638
2659
  let conventionPath = resolveErrorConventionPath(framework, pageName);
2639
2660
  if (!conventionPath && error instanceof Error && error.stack) {
2640
2661
  for (const match of error.stack.matchAll(/^\s*at\s+([A-Za-z_$][\w$]*)/gm)) {
@@ -2648,7 +2669,6 @@ var renderConventionError = async (framework, pageName, error) => {
2648
2669
  }
2649
2670
  if (!conventionPath)
2650
2671
  return null;
2651
- const errorProps = buildErrorProps(error);
2652
2672
  const renderer = ERROR_RENDERERS[framework];
2653
2673
  if (!renderer)
2654
2674
  return null;
@@ -2659,12 +2679,25 @@ var renderConventionError = async (framework, pageName, error) => {
2659
2679
  }
2660
2680
  return null;
2661
2681
  };
2682
+ var renderConventionError = async (framework, pageName, error) => {
2683
+ const errorProps = buildErrorProps(error);
2684
+ const frameworkResponse = await tryFrameworkErrorConvention(framework, pageName, errorProps, error);
2685
+ if (frameworkResponse)
2686
+ return frameworkResponse;
2687
+ if (framework !== "html") {
2688
+ const htmlResponse = await tryFrameworkErrorConvention("html", pageName, errorProps, error);
2689
+ if (htmlResponse)
2690
+ return htmlResponse;
2691
+ }
2692
+ return null;
2693
+ };
2662
2694
  var renderReactNotFound = async (conventionPath) => {
2663
2695
  const { createElement } = await import("react");
2664
2696
  const { renderToReadableStream } = await import("react-dom/server");
2665
2697
  const mod = await import(conventionPath);
2666
- const [nfKey] = Object.keys(mod);
2667
- const NotFoundComponent = mod.default ?? (nfKey ? mod[nfKey] : undefined);
2698
+ const NotFoundComponent = mod.default;
2699
+ if (typeof NotFoundComponent !== "function")
2700
+ return null;
2668
2701
  const element = createElement(NotFoundComponent);
2669
2702
  const stream = await renderToReadableStream(element);
2670
2703
  return new Response(stream, {
@@ -2676,6 +2709,8 @@ var renderSvelteNotFound = async (conventionPath) => {
2676
2709
  const { render } = await import("svelte/server");
2677
2710
  const mod = await import(conventionPath);
2678
2711
  const NotFoundComponent = mod.default;
2712
+ if (!NotFoundComponent)
2713
+ return null;
2679
2714
  const { head, body } = render(NotFoundComponent);
2680
2715
  const html = `<!DOCTYPE html><html><head>${head}</head><body>${body}</body></html>`;
2681
2716
  return new Response(html, {
@@ -2688,6 +2723,8 @@ var renderVueNotFound = async (conventionPath) => {
2688
2723
  const { renderToString } = await import("vue/server-renderer");
2689
2724
  const mod = await import(conventionPath);
2690
2725
  const NotFoundComponent = mod.default;
2726
+ if (!NotFoundComponent)
2727
+ return null;
2691
2728
  const app = createSSRApp({
2692
2729
  render: () => h(NotFoundComponent)
2693
2730
  });
@@ -2701,10 +2738,17 @@ var renderVueNotFound = async (conventionPath) => {
2701
2738
  };
2702
2739
  var renderAngularNotFound = async (conventionPath) => {
2703
2740
  const mod = await import(conventionPath);
2704
- const renderNotFound = mod.default ?? mod.renderNotFound;
2705
- if (typeof renderNotFound !== "function")
2741
+ const renderFn = mod.default;
2742
+ if (typeof renderFn !== "function")
2706
2743
  return null;
2707
- const html = renderNotFound();
2744
+ const html = renderFn();
2745
+ return new Response(html, {
2746
+ headers: { "Content-Type": "text/html" },
2747
+ status: 404
2748
+ });
2749
+ };
2750
+ var renderHtmlNotFound = async (conventionPath) => {
2751
+ const html = await Bun.file(conventionPath).text();
2708
2752
  return new Response(html, {
2709
2753
  headers: { "Content-Type": "text/html" },
2710
2754
  status: 404
@@ -2713,6 +2757,7 @@ var renderAngularNotFound = async (conventionPath) => {
2713
2757
  var NOT_FOUND_RENDERERS = {
2714
2758
  angular: renderAngularNotFound,
2715
2759
  ember: renderEmberNotFound,
2760
+ html: renderHtmlNotFound,
2716
2761
  react: renderReactNotFound,
2717
2762
  svelte: renderSvelteNotFound,
2718
2763
  vue: renderVueNotFound
@@ -2735,7 +2780,8 @@ var NOT_FOUND_PRIORITY = [
2735
2780
  "react",
2736
2781
  "svelte",
2737
2782
  "vue",
2738
- "angular"
2783
+ "angular",
2784
+ "html"
2739
2785
  ];
2740
2786
  var renderFirstNotFound = async () => {
2741
2787
  const renderNext = async (frameworks) => {
@@ -2880,5 +2926,5 @@ export {
2880
2926
  handleSveltePageRequest
2881
2927
  };
2882
2928
 
2883
- //# debugId=02F733533EDBECF864756E2164756E21
2929
+ //# debugId=B2EC55571D42A8C664756E2164756E21
2884
2930
  //# sourceMappingURL=server.js.map