@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.
package/dist/vue/index.js CHANGED
@@ -3837,16 +3837,22 @@ var setConventions = (map) => {
3837
3837
  };
3838
3838
  var isDev = () => true;
3839
3839
  var buildErrorProps = (error) => {
3840
- const message = error instanceof Error ? error.message : String(error);
3841
- const stack = isDev() && error instanceof Error ? error.stack : undefined;
3842
- return { error: { message, stack } };
3840
+ if (error instanceof Error) {
3841
+ return {
3842
+ name: error.name,
3843
+ message: error.message,
3844
+ ...isDev() && error.stack ? { stack: error.stack } : {}
3845
+ };
3846
+ }
3847
+ return { name: "Error", message: String(error) };
3843
3848
  };
3844
3849
  var renderReactError = async (conventionPath, errorProps) => {
3845
3850
  const { createElement } = await import("react");
3846
3851
  const { renderToReadableStream } = await import("react-dom/server");
3847
3852
  const mod = await import(conventionPath);
3848
- const [firstKey] = Object.keys(mod);
3849
- const ErrorComponent = mod.default ?? (firstKey ? mod[firstKey] : undefined);
3853
+ const ErrorComponent = mod.default;
3854
+ if (typeof ErrorComponent !== "function")
3855
+ return null;
3850
3856
  const element = createElement(ErrorComponent, errorProps);
3851
3857
  const stream = await renderToReadableStream(element);
3852
3858
  return new Response(stream, {
@@ -3858,6 +3864,8 @@ var renderSvelteError = async (conventionPath, errorProps) => {
3858
3864
  const { render } = await import("svelte/server");
3859
3865
  const mod = await import(conventionPath);
3860
3866
  const ErrorComponent = mod.default;
3867
+ if (!ErrorComponent)
3868
+ return null;
3861
3869
  const { head, body } = render(ErrorComponent, {
3862
3870
  props: errorProps
3863
3871
  });
@@ -3880,6 +3888,8 @@ var renderVueError = async (conventionPath, errorProps) => {
3880
3888
  const { renderToString } = await import("vue/server-renderer");
3881
3889
  const mod = await import(conventionPath);
3882
3890
  const ErrorComponent = mod.default;
3891
+ if (!ErrorComponent)
3892
+ return null;
3883
3893
  const app = createSSRApp({
3884
3894
  render: () => h4(ErrorComponent, errorProps)
3885
3895
  });
@@ -3893,10 +3903,20 @@ var renderVueError = async (conventionPath, errorProps) => {
3893
3903
  };
3894
3904
  var renderAngularError = async (conventionPath, errorProps) => {
3895
3905
  const mod = await import(conventionPath);
3896
- const renderError = mod.default ?? mod.renderError;
3897
- if (typeof renderError !== "function")
3906
+ const renderFn = mod.default;
3907
+ if (typeof renderFn !== "function")
3898
3908
  return null;
3899
- const html = renderError(errorProps);
3909
+ const html = renderFn(errorProps);
3910
+ return new Response(html, {
3911
+ headers: { "Content-Type": "text/html" },
3912
+ status: 500
3913
+ });
3914
+ };
3915
+ var escapeHtml = (value) => value.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;");
3916
+ 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) : "");
3917
+ var renderHtmlError = async (conventionPath, errorProps) => {
3918
+ const template = await Bun.file(conventionPath).text();
3919
+ const html = replaceErrorTokens(template, errorProps);
3900
3920
  return new Response(html, {
3901
3921
  headers: { "Content-Type": "text/html" },
3902
3922
  status: 500
@@ -3915,11 +3935,12 @@ var renderEmberNotFound = async () => null;
3915
3935
  var ERROR_RENDERERS = {
3916
3936
  angular: renderAngularError,
3917
3937
  ember: renderEmberError,
3938
+ html: renderHtmlError,
3918
3939
  react: renderReactError,
3919
3940
  svelte: renderSvelteError,
3920
3941
  vue: renderVueError
3921
3942
  };
3922
- var renderConventionError = async (framework, pageName, error) => {
3943
+ var tryFrameworkErrorConvention = async (framework, pageName, errorProps, error) => {
3923
3944
  let conventionPath = resolveErrorConventionPath(framework, pageName);
3924
3945
  if (!conventionPath && error instanceof Error && error.stack) {
3925
3946
  for (const match of error.stack.matchAll(/^\s*at\s+([A-Za-z_$][\w$]*)/gm)) {
@@ -3933,7 +3954,6 @@ var renderConventionError = async (framework, pageName, error) => {
3933
3954
  }
3934
3955
  if (!conventionPath)
3935
3956
  return null;
3936
- const errorProps = buildErrorProps(error);
3937
3957
  const renderer = ERROR_RENDERERS[framework];
3938
3958
  if (!renderer)
3939
3959
  return null;
@@ -3944,12 +3964,25 @@ var renderConventionError = async (framework, pageName, error) => {
3944
3964
  }
3945
3965
  return null;
3946
3966
  };
3967
+ var renderConventionError = async (framework, pageName, error) => {
3968
+ const errorProps = buildErrorProps(error);
3969
+ const frameworkResponse = await tryFrameworkErrorConvention(framework, pageName, errorProps, error);
3970
+ if (frameworkResponse)
3971
+ return frameworkResponse;
3972
+ if (framework !== "html") {
3973
+ const htmlResponse = await tryFrameworkErrorConvention("html", pageName, errorProps, error);
3974
+ if (htmlResponse)
3975
+ return htmlResponse;
3976
+ }
3977
+ return null;
3978
+ };
3947
3979
  var renderReactNotFound = async (conventionPath) => {
3948
3980
  const { createElement } = await import("react");
3949
3981
  const { renderToReadableStream } = await import("react-dom/server");
3950
3982
  const mod = await import(conventionPath);
3951
- const [nfKey] = Object.keys(mod);
3952
- const NotFoundComponent = mod.default ?? (nfKey ? mod[nfKey] : undefined);
3983
+ const NotFoundComponent = mod.default;
3984
+ if (typeof NotFoundComponent !== "function")
3985
+ return null;
3953
3986
  const element = createElement(NotFoundComponent);
3954
3987
  const stream = await renderToReadableStream(element);
3955
3988
  return new Response(stream, {
@@ -3961,6 +3994,8 @@ var renderSvelteNotFound = async (conventionPath) => {
3961
3994
  const { render } = await import("svelte/server");
3962
3995
  const mod = await import(conventionPath);
3963
3996
  const NotFoundComponent = mod.default;
3997
+ if (!NotFoundComponent)
3998
+ return null;
3964
3999
  const { head, body } = render(NotFoundComponent);
3965
4000
  const html = `<!DOCTYPE html><html><head>${head}</head><body>${body}</body></html>`;
3966
4001
  return new Response(html, {
@@ -3973,6 +4008,8 @@ var renderVueNotFound = async (conventionPath) => {
3973
4008
  const { renderToString } = await import("vue/server-renderer");
3974
4009
  const mod = await import(conventionPath);
3975
4010
  const NotFoundComponent = mod.default;
4011
+ if (!NotFoundComponent)
4012
+ return null;
3976
4013
  const app = createSSRApp({
3977
4014
  render: () => h4(NotFoundComponent)
3978
4015
  });
@@ -3986,10 +4023,17 @@ var renderVueNotFound = async (conventionPath) => {
3986
4023
  };
3987
4024
  var renderAngularNotFound = async (conventionPath) => {
3988
4025
  const mod = await import(conventionPath);
3989
- const renderNotFound = mod.default ?? mod.renderNotFound;
3990
- if (typeof renderNotFound !== "function")
4026
+ const renderFn = mod.default;
4027
+ if (typeof renderFn !== "function")
3991
4028
  return null;
3992
- const html = renderNotFound();
4029
+ const html = renderFn();
4030
+ return new Response(html, {
4031
+ headers: { "Content-Type": "text/html" },
4032
+ status: 404
4033
+ });
4034
+ };
4035
+ var renderHtmlNotFound = async (conventionPath) => {
4036
+ const html = await Bun.file(conventionPath).text();
3993
4037
  return new Response(html, {
3994
4038
  headers: { "Content-Type": "text/html" },
3995
4039
  status: 404
@@ -3998,6 +4042,7 @@ var renderAngularNotFound = async (conventionPath) => {
3998
4042
  var NOT_FOUND_RENDERERS = {
3999
4043
  angular: renderAngularNotFound,
4000
4044
  ember: renderEmberNotFound,
4045
+ html: renderHtmlNotFound,
4001
4046
  react: renderReactNotFound,
4002
4047
  svelte: renderSvelteNotFound,
4003
4048
  vue: renderVueNotFound
@@ -4020,7 +4065,8 @@ var NOT_FOUND_PRIORITY = [
4020
4065
  "react",
4021
4066
  "svelte",
4022
4067
  "vue",
4023
- "angular"
4068
+ "angular",
4069
+ "html"
4024
4070
  ];
4025
4071
  var renderFirstNotFound = async () => {
4026
4072
  const renderNext = async (frameworks) => {
@@ -4598,5 +4644,5 @@ export {
4598
4644
  Image
4599
4645
  };
4600
4646
 
4601
- //# debugId=3885F1541221AF7364756E2164756E21
4647
+ //# debugId=C533BB46082E586D64756E2164756E21
4602
4648
  //# sourceMappingURL=index.js.map