@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.
@@ -3474,16 +3474,22 @@ var setConventions = (map) => {
3474
3474
  };
3475
3475
  var isDev = () => true;
3476
3476
  var buildErrorProps = (error) => {
3477
- const message = error instanceof Error ? error.message : String(error);
3478
- const stack = isDev() && error instanceof Error ? error.stack : undefined;
3479
- return { error: { message, stack } };
3477
+ if (error instanceof Error) {
3478
+ return {
3479
+ name: error.name,
3480
+ message: error.message,
3481
+ ...isDev() && error.stack ? { stack: error.stack } : {}
3482
+ };
3483
+ }
3484
+ return { name: "Error", message: String(error) };
3480
3485
  };
3481
3486
  var renderReactError = async (conventionPath, errorProps) => {
3482
3487
  const { createElement } = await import("react");
3483
3488
  const { renderToReadableStream } = await import("react-dom/server");
3484
3489
  const mod = await import(conventionPath);
3485
- const [firstKey] = Object.keys(mod);
3486
- const ErrorComponent = mod.default ?? (firstKey ? mod[firstKey] : undefined);
3490
+ const ErrorComponent = mod.default;
3491
+ if (typeof ErrorComponent !== "function")
3492
+ return null;
3487
3493
  const element = createElement(ErrorComponent, errorProps);
3488
3494
  const stream = await renderToReadableStream(element);
3489
3495
  return new Response(stream, {
@@ -3495,6 +3501,8 @@ var renderSvelteError = async (conventionPath, errorProps) => {
3495
3501
  const { render } = await import("svelte/server");
3496
3502
  const mod = await import(conventionPath);
3497
3503
  const ErrorComponent = mod.default;
3504
+ if (!ErrorComponent)
3505
+ return null;
3498
3506
  const { head, body } = render(ErrorComponent, {
3499
3507
  props: errorProps
3500
3508
  });
@@ -3517,6 +3525,8 @@ var renderVueError = async (conventionPath, errorProps) => {
3517
3525
  const { renderToString } = await import("vue/server-renderer");
3518
3526
  const mod = await import(conventionPath);
3519
3527
  const ErrorComponent = mod.default;
3528
+ if (!ErrorComponent)
3529
+ return null;
3520
3530
  const app = createSSRApp({
3521
3531
  render: () => h(ErrorComponent, errorProps)
3522
3532
  });
@@ -3530,10 +3540,20 @@ var renderVueError = async (conventionPath, errorProps) => {
3530
3540
  };
3531
3541
  var renderAngularError = async (conventionPath, errorProps) => {
3532
3542
  const mod = await import(conventionPath);
3533
- const renderError = mod.default ?? mod.renderError;
3534
- if (typeof renderError !== "function")
3543
+ const renderFn = mod.default;
3544
+ if (typeof renderFn !== "function")
3535
3545
  return null;
3536
- const html = renderError(errorProps);
3546
+ const html = renderFn(errorProps);
3547
+ return new Response(html, {
3548
+ headers: { "Content-Type": "text/html" },
3549
+ status: 500
3550
+ });
3551
+ };
3552
+ var escapeHtml = (value) => value.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;");
3553
+ 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) : "");
3554
+ var renderHtmlError = async (conventionPath, errorProps) => {
3555
+ const template = await Bun.file(conventionPath).text();
3556
+ const html = replaceErrorTokens(template, errorProps);
3537
3557
  return new Response(html, {
3538
3558
  headers: { "Content-Type": "text/html" },
3539
3559
  status: 500
@@ -3552,11 +3572,12 @@ var renderEmberNotFound = async () => null;
3552
3572
  var ERROR_RENDERERS = {
3553
3573
  angular: renderAngularError,
3554
3574
  ember: renderEmberError,
3575
+ html: renderHtmlError,
3555
3576
  react: renderReactError,
3556
3577
  svelte: renderSvelteError,
3557
3578
  vue: renderVueError
3558
3579
  };
3559
- var renderConventionError = async (framework, pageName, error) => {
3580
+ var tryFrameworkErrorConvention = async (framework, pageName, errorProps, error) => {
3560
3581
  let conventionPath = resolveErrorConventionPath(framework, pageName);
3561
3582
  if (!conventionPath && error instanceof Error && error.stack) {
3562
3583
  for (const match of error.stack.matchAll(/^\s*at\s+([A-Za-z_$][\w$]*)/gm)) {
@@ -3570,7 +3591,6 @@ var renderConventionError = async (framework, pageName, error) => {
3570
3591
  }
3571
3592
  if (!conventionPath)
3572
3593
  return null;
3573
- const errorProps = buildErrorProps(error);
3574
3594
  const renderer = ERROR_RENDERERS[framework];
3575
3595
  if (!renderer)
3576
3596
  return null;
@@ -3581,12 +3601,25 @@ var renderConventionError = async (framework, pageName, error) => {
3581
3601
  }
3582
3602
  return null;
3583
3603
  };
3604
+ var renderConventionError = async (framework, pageName, error) => {
3605
+ const errorProps = buildErrorProps(error);
3606
+ const frameworkResponse = await tryFrameworkErrorConvention(framework, pageName, errorProps, error);
3607
+ if (frameworkResponse)
3608
+ return frameworkResponse;
3609
+ if (framework !== "html") {
3610
+ const htmlResponse = await tryFrameworkErrorConvention("html", pageName, errorProps, error);
3611
+ if (htmlResponse)
3612
+ return htmlResponse;
3613
+ }
3614
+ return null;
3615
+ };
3584
3616
  var renderReactNotFound = async (conventionPath) => {
3585
3617
  const { createElement } = await import("react");
3586
3618
  const { renderToReadableStream } = await import("react-dom/server");
3587
3619
  const mod = await import(conventionPath);
3588
- const [nfKey] = Object.keys(mod);
3589
- const NotFoundComponent = mod.default ?? (nfKey ? mod[nfKey] : undefined);
3620
+ const NotFoundComponent = mod.default;
3621
+ if (typeof NotFoundComponent !== "function")
3622
+ return null;
3590
3623
  const element = createElement(NotFoundComponent);
3591
3624
  const stream = await renderToReadableStream(element);
3592
3625
  return new Response(stream, {
@@ -3598,6 +3631,8 @@ var renderSvelteNotFound = async (conventionPath) => {
3598
3631
  const { render } = await import("svelte/server");
3599
3632
  const mod = await import(conventionPath);
3600
3633
  const NotFoundComponent = mod.default;
3634
+ if (!NotFoundComponent)
3635
+ return null;
3601
3636
  const { head, body } = render(NotFoundComponent);
3602
3637
  const html = `<!DOCTYPE html><html><head>${head}</head><body>${body}</body></html>`;
3603
3638
  return new Response(html, {
@@ -3610,6 +3645,8 @@ var renderVueNotFound = async (conventionPath) => {
3610
3645
  const { renderToString } = await import("vue/server-renderer");
3611
3646
  const mod = await import(conventionPath);
3612
3647
  const NotFoundComponent = mod.default;
3648
+ if (!NotFoundComponent)
3649
+ return null;
3613
3650
  const app = createSSRApp({
3614
3651
  render: () => h(NotFoundComponent)
3615
3652
  });
@@ -3623,10 +3660,17 @@ var renderVueNotFound = async (conventionPath) => {
3623
3660
  };
3624
3661
  var renderAngularNotFound = async (conventionPath) => {
3625
3662
  const mod = await import(conventionPath);
3626
- const renderNotFound = mod.default ?? mod.renderNotFound;
3627
- if (typeof renderNotFound !== "function")
3663
+ const renderFn = mod.default;
3664
+ if (typeof renderFn !== "function")
3628
3665
  return null;
3629
- const html = renderNotFound();
3666
+ const html = renderFn();
3667
+ return new Response(html, {
3668
+ headers: { "Content-Type": "text/html" },
3669
+ status: 404
3670
+ });
3671
+ };
3672
+ var renderHtmlNotFound = async (conventionPath) => {
3673
+ const html = await Bun.file(conventionPath).text();
3630
3674
  return new Response(html, {
3631
3675
  headers: { "Content-Type": "text/html" },
3632
3676
  status: 404
@@ -3635,6 +3679,7 @@ var renderAngularNotFound = async (conventionPath) => {
3635
3679
  var NOT_FOUND_RENDERERS = {
3636
3680
  angular: renderAngularNotFound,
3637
3681
  ember: renderEmberNotFound,
3682
+ html: renderHtmlNotFound,
3638
3683
  react: renderReactNotFound,
3639
3684
  svelte: renderSvelteNotFound,
3640
3685
  vue: renderVueNotFound
@@ -3657,7 +3702,8 @@ var NOT_FOUND_PRIORITY = [
3657
3702
  "react",
3658
3703
  "svelte",
3659
3704
  "vue",
3660
- "angular"
3705
+ "angular",
3706
+ "html"
3661
3707
  ];
3662
3708
  var renderFirstNotFound = async () => {
3663
3709
  const renderNext = async (frameworks) => {
@@ -3939,5 +3985,5 @@ export {
3939
3985
  createTypedIsland
3940
3986
  };
3941
3987
 
3942
- //# debugId=76F703206AC2F94E64756E2164756E21
3988
+ //# debugId=CB4490FD3D9DB75864756E2164756E21
3943
3989
  //# sourceMappingURL=index.js.map