astro 7.0.0-alpha.0 → 7.0.0-alpha.2

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 (251) hide show
  1. package/components/Code.astro +1 -1
  2. package/dist/actions/handler.d.ts +32 -0
  3. package/dist/actions/handler.js +45 -0
  4. package/dist/actions/runtime/server.js +1 -1
  5. package/dist/assets/build/generate.js +1 -1
  6. package/dist/assets/build/remote.d.ts +3 -2
  7. package/dist/assets/build/remote.js +16 -9
  8. package/dist/assets/endpoint/dev.js +1 -1
  9. package/dist/assets/endpoint/generic.js +8 -20
  10. package/dist/assets/endpoint/loadImage.d.ts +11 -0
  11. package/dist/assets/endpoint/loadImage.js +19 -0
  12. package/dist/assets/endpoint/shared.js +7 -2
  13. package/dist/assets/fonts/config.d.ts +4 -4
  14. package/dist/assets/fonts/core/optimize-fallbacks.js +38 -13
  15. package/dist/assets/fonts/definitions.d.ts +2 -2
  16. package/dist/assets/fonts/infra/system-fallbacks-provider.d.ts +2 -2
  17. package/dist/assets/fonts/infra/system-fallbacks-provider.js +46 -9
  18. package/dist/assets/fonts/types.d.ts +1 -0
  19. package/dist/assets/index.d.ts +1 -0
  20. package/dist/assets/index.js +2 -0
  21. package/dist/assets/internal.js +22 -3
  22. package/dist/assets/services/service.d.ts +1 -1
  23. package/dist/assets/services/service.js +9 -9
  24. package/dist/assets/services/sharp.js +53 -18
  25. package/dist/assets/utils/generateImageStylesCSS.js +26 -6
  26. package/dist/assets/utils/index.d.ts +1 -0
  27. package/dist/assets/utils/index.js +2 -0
  28. package/dist/assets/utils/inferSourceFormat.d.ts +8 -3
  29. package/dist/assets/utils/inferSourceFormat.js +15 -4
  30. package/dist/assets/utils/metadata.js +1 -1
  31. package/dist/assets/utils/redirectValidation.d.ts +48 -0
  32. package/dist/assets/utils/redirectValidation.js +48 -0
  33. package/dist/assets/utils/remoteProbe.js +25 -2
  34. package/dist/assets/utils/vendor/image-size/types/svg.js +1 -1
  35. package/dist/cli/add/index.js +7 -58
  36. package/dist/cli/dev/background.d.ts +16 -0
  37. package/dist/cli/dev/background.js +116 -0
  38. package/dist/cli/dev/index.js +82 -3
  39. package/dist/cli/dev/logs.d.ts +6 -0
  40. package/dist/cli/dev/logs.js +72 -0
  41. package/dist/cli/dev/status.d.ts +15 -0
  42. package/dist/cli/dev/status.js +27 -0
  43. package/dist/cli/dev/stop.d.ts +12 -0
  44. package/dist/cli/dev/stop.js +43 -0
  45. package/dist/cli/infra/build-time-astro-version-provider.js +1 -1
  46. package/dist/container/index.js +18 -14
  47. package/dist/content/content-layer.js +16 -11
  48. package/dist/content/data-store.d.ts +1 -1
  49. package/dist/content/loaders/types.d.ts +1 -1
  50. package/dist/content/runtime-assets.d.ts +2 -2
  51. package/dist/content/runtime.d.ts +1 -1
  52. package/dist/content/runtime.js +9 -4
  53. package/dist/content/server-listeners.js +0 -4
  54. package/dist/content/types-generator.js +5 -1
  55. package/dist/content/utils.d.ts +1 -1
  56. package/dist/content/utils.js +1 -1
  57. package/dist/content/vite-plugin-content-assets.js +1 -0
  58. package/dist/content/vite-plugin-content-virtual-mod.js +9 -1
  59. package/dist/core/app/base.d.ts +42 -15
  60. package/dist/core/app/base.js +151 -375
  61. package/dist/core/app/dev/app.d.ts +3 -2
  62. package/dist/core/app/dev/app.js +4 -60
  63. package/dist/core/app/entrypoints/node.d.ts +1 -1
  64. package/dist/core/app/entrypoints/node.js +2 -0
  65. package/dist/core/app/entrypoints/virtual/dev.js +2 -0
  66. package/dist/core/app/entrypoints/virtual/prod.js +4 -1
  67. package/dist/core/app/node.d.ts +16 -0
  68. package/dist/core/app/node.js +59 -13
  69. package/dist/core/app/prepare-response.d.ts +11 -0
  70. package/dist/core/app/prepare-response.js +18 -0
  71. package/dist/core/app/render-options.d.ts +11 -0
  72. package/dist/core/app/render-options.js +11 -0
  73. package/dist/core/base-pipeline.d.ts +48 -1
  74. package/dist/core/base-pipeline.js +63 -8
  75. package/dist/core/build/app.d.ts +3 -4
  76. package/dist/core/build/app.js +3 -17
  77. package/dist/core/build/generate.js +8 -1
  78. package/dist/core/build/index.d.ts +0 -11
  79. package/dist/core/build/index.js +0 -3
  80. package/dist/core/build/internal.d.ts +7 -0
  81. package/dist/core/build/plugins/plugin-chunk-imports.d.ts +6 -0
  82. package/dist/core/build/plugins/plugin-chunk-imports.js +29 -17
  83. package/dist/core/build/plugins/plugin-css.js +40 -1
  84. package/dist/core/build/plugins/plugin-internals.js +1 -1
  85. package/dist/core/build/plugins/plugin-manifest.js +11 -1
  86. package/dist/core/build/static-build.js +22 -141
  87. package/dist/core/build/types.d.ts +0 -1
  88. package/dist/core/build/util.js +8 -1
  89. package/dist/core/build/vite-build-config.d.ts +28 -0
  90. package/dist/core/build/vite-build-config.js +165 -0
  91. package/dist/core/cache/handler.d.ts +29 -0
  92. package/dist/core/cache/handler.js +81 -0
  93. package/dist/core/compile/style.js +18 -1
  94. package/dist/core/config/index.d.ts +1 -1
  95. package/dist/core/config/index.js +4 -1
  96. package/dist/core/config/merge.js +4 -0
  97. package/dist/core/config/schemas/base.d.ts +25 -13
  98. package/dist/core/config/schemas/base.js +39 -10
  99. package/dist/core/config/schemas/relative.d.ts +76 -49
  100. package/dist/core/config/schemas/relative.js +2 -3
  101. package/dist/core/config/settings.js +2 -4
  102. package/dist/core/config/tsconfig.d.ts +24 -9
  103. package/dist/core/config/tsconfig.js +54 -45
  104. package/dist/core/config/validate.js +59 -0
  105. package/dist/core/constants.d.ts +27 -1
  106. package/dist/core/constants.js +14 -1
  107. package/dist/core/cookies/cookies.d.ts +7 -2
  108. package/dist/core/cookies/cookies.js +11 -4
  109. package/dist/core/cookies/response.d.ts +1 -1
  110. package/dist/core/cookies/response.js +1 -2
  111. package/dist/core/create-vite.js +18 -1
  112. package/dist/core/csp/config.js +17 -5
  113. package/dist/core/csp/runtime.js +6 -4
  114. package/dist/core/dev/dev.d.ts +1 -0
  115. package/dist/core/dev/dev.js +4 -13
  116. package/dist/core/dev/lockfile.d.ts +54 -0
  117. package/dist/core/dev/lockfile.js +93 -0
  118. package/dist/core/errors/build-handler.d.ts +17 -0
  119. package/dist/core/errors/build-handler.js +22 -0
  120. package/dist/core/errors/default-handler.d.ts +14 -0
  121. package/dist/core/errors/default-handler.js +144 -0
  122. package/dist/core/errors/dev-handler.d.ts +21 -0
  123. package/dist/core/errors/dev-handler.js +82 -0
  124. package/dist/core/errors/errors-data.d.ts +43 -38
  125. package/dist/core/errors/errors-data.js +79 -73
  126. package/dist/core/errors/handler.d.ts +9 -0
  127. package/dist/core/errors/handler.js +0 -0
  128. package/dist/core/errors/zod-error-map.js +30 -1
  129. package/dist/core/fetch/default-handler.d.ts +17 -0
  130. package/dist/core/fetch/default-handler.js +45 -0
  131. package/dist/core/fetch/fetch-state.d.ts +230 -0
  132. package/dist/core/fetch/fetch-state.js +896 -0
  133. package/dist/core/fetch/index.d.ts +61 -0
  134. package/dist/core/fetch/index.js +121 -0
  135. package/dist/core/fetch/types.d.ts +25 -0
  136. package/dist/core/fetch/types.js +0 -0
  137. package/dist/core/fetch/vite-plugin.d.ts +5 -0
  138. package/dist/core/fetch/vite-plugin.js +76 -0
  139. package/dist/core/hono/index.d.ts +21 -0
  140. package/dist/core/hono/index.js +101 -0
  141. package/dist/core/i18n/domain.d.ts +12 -0
  142. package/dist/core/i18n/domain.js +66 -0
  143. package/dist/core/i18n/handler.d.ts +18 -0
  144. package/dist/core/i18n/handler.js +122 -0
  145. package/dist/core/logger/core.d.ts +9 -1
  146. package/dist/core/logger/core.js +17 -1
  147. package/dist/core/messages/runtime.d.ts +0 -3
  148. package/dist/core/messages/runtime.js +1 -9
  149. package/dist/core/middleware/astro-middleware.d.ts +27 -0
  150. package/dist/core/middleware/astro-middleware.js +51 -0
  151. package/dist/core/module-loader/vite.js +1 -2
  152. package/dist/core/pages/handler.d.ts +20 -0
  153. package/dist/core/pages/handler.js +75 -0
  154. package/dist/core/preview/index.js +6 -5
  155. package/dist/core/preview/static-preview-server.js +5 -2
  156. package/dist/core/redirects/render.d.ts +2 -2
  157. package/dist/core/redirects/render.js +7 -8
  158. package/dist/core/render/params-and-props.js +2 -2
  159. package/dist/core/render/route-cache.d.ts +1 -0
  160. package/dist/core/render/route-cache.js +4 -4
  161. package/dist/core/render/slots.js +9 -2
  162. package/dist/core/rewrites/handler.d.ts +37 -0
  163. package/dist/core/rewrites/handler.js +67 -0
  164. package/dist/core/routing/3xx.js +8 -4
  165. package/dist/core/routing/create-manifest.js +11 -1
  166. package/dist/core/routing/handler.d.ts +17 -0
  167. package/dist/core/routing/handler.js +171 -0
  168. package/dist/core/routing/match.d.ts +0 -7
  169. package/dist/core/routing/match.js +0 -5
  170. package/dist/core/routing/parse-route.js +1 -1
  171. package/dist/core/routing/pattern.js +1 -1
  172. package/dist/core/routing/rewrite.js +2 -5
  173. package/dist/core/routing/router.d.ts +8 -0
  174. package/dist/core/routing/router.js +28 -0
  175. package/dist/core/routing/trailing-slash-handler.d.ts +18 -0
  176. package/dist/core/routing/trailing-slash-handler.js +67 -0
  177. package/dist/core/routing/validation.js +1 -1
  178. package/dist/core/server-islands/vite-plugin-server-islands.d.ts +6 -1
  179. package/dist/core/server-islands/vite-plugin-server-islands.js +13 -3
  180. package/dist/core/session/config.d.ts +1 -1
  181. package/dist/core/session/drivers.d.ts +1 -1
  182. package/dist/core/session/handler.d.ts +11 -0
  183. package/dist/core/session/handler.js +33 -0
  184. package/dist/core/session/runtime.js +7 -2
  185. package/dist/core/util/normalized-url.d.ts +10 -0
  186. package/dist/core/util/normalized-url.js +24 -0
  187. package/dist/core/util/pathname.d.ts +10 -1
  188. package/dist/core/util/pathname.js +13 -4
  189. package/dist/environments.js +1 -1
  190. package/dist/events/session.d.ts +8 -0
  191. package/dist/events/session.js +11 -0
  192. package/dist/i18n/middleware.d.ts +10 -0
  193. package/dist/i18n/middleware.js +4 -88
  194. package/dist/i18n/utils.js +2 -2
  195. package/dist/jsx/rehype.d.ts +1 -1
  196. package/dist/manifest/virtual-module.js +3 -1
  197. package/dist/markdown/index.d.ts +4 -0
  198. package/dist/markdown/index.js +14 -0
  199. package/dist/prefetch/index.js +12 -7
  200. package/dist/prerender/utils.js +5 -1
  201. package/dist/runtime/client/dev-toolbar/apps/audit/rules/a11y.js +9 -0
  202. package/dist/runtime/server/astro-island.js +57 -20
  203. package/dist/runtime/server/astro-island.prebuilt-dev.d.ts +1 -1
  204. package/dist/runtime/server/astro-island.prebuilt-dev.js +1 -1
  205. package/dist/runtime/server/astro-island.prebuilt.d.ts +1 -1
  206. package/dist/runtime/server/astro-island.prebuilt.js +1 -1
  207. package/dist/runtime/server/jsx.js +1 -1
  208. package/dist/runtime/server/render/common.js +10 -4
  209. package/dist/runtime/server/render/component.js +8 -6
  210. package/dist/runtime/server/render/head.js +1 -5
  211. package/dist/runtime/server/render/server-islands.js +2 -1
  212. package/dist/runtime/server/render/util.js +2 -2
  213. package/dist/runtime/server/scripts.js +6 -0
  214. package/dist/runtime/server/transition.d.ts +1 -6
  215. package/dist/runtime/server/transition.js +0 -8
  216. package/dist/transitions/events.d.ts +0 -14
  217. package/dist/transitions/events.js +0 -14
  218. package/dist/transitions/index.d.ts +0 -1
  219. package/dist/transitions/index.js +0 -2
  220. package/dist/transitions/vite-plugin-transitions.js +2 -4
  221. package/dist/types/public/config.d.ts +96 -14
  222. package/dist/types/public/content.d.ts +5 -5
  223. package/dist/types/public/index.d.ts +2 -1
  224. package/dist/types/public/integrations.d.ts +11 -3
  225. package/dist/types/public/internal.d.ts +1 -1
  226. package/dist/types/public/manifest.d.ts +1 -1
  227. package/dist/virtual-modules/i18n.d.ts +2 -2
  228. package/dist/virtual-modules/i18n.js +1 -1
  229. package/dist/vite-plugin-app/app.d.ts +13 -6
  230. package/dist/vite-plugin-app/app.js +51 -89
  231. package/dist/vite-plugin-app/createAstroServerApp.d.ts +3 -1
  232. package/dist/vite-plugin-app/createAstroServerApp.js +4 -3
  233. package/dist/vite-plugin-astro-server/plugin.js +11 -5
  234. package/dist/vite-plugin-astro-server/route-guard.d.ts +33 -0
  235. package/dist/vite-plugin-astro-server/route-guard.js +42 -23
  236. package/dist/vite-plugin-dev-status/index.d.ts +2 -0
  237. package/dist/vite-plugin-dev-status/index.js +15 -0
  238. package/dist/vite-plugin-head/index.js +36 -19
  239. package/dist/vite-plugin-hmr-reload/index.d.ts +1 -1
  240. package/dist/vite-plugin-hmr-reload/index.js +23 -1
  241. package/dist/vite-plugin-integrations-container/index.js +15 -6
  242. package/dist/vite-plugin-markdown/content-entry-type.js +7 -4
  243. package/dist/vite-plugin-markdown/images.js +9 -11
  244. package/dist/vite-plugin-markdown/index.js +12 -11
  245. package/dist/vite-plugin-utils/index.d.ts +1 -0
  246. package/dist/vite-plugin-utils/index.js +10 -1
  247. package/package.json +23 -16
  248. package/templates/content/types.d.ts +1 -0
  249. package/types/transitions.d.ts +0 -7
  250. package/dist/core/render-context.d.ts +0 -77
  251. package/dist/core/render-context.js +0 -826
@@ -0,0 +1,144 @@
1
+ import { FetchState } from "../fetch/fetch-state.js";
2
+ import { prepareResponse } from "../app/prepare-response.js";
3
+ import { attachCookiesToResponse } from "../cookies/index.js";
4
+ import { getCookiesFromResponse } from "../cookies/response.js";
5
+ import { AstroMiddleware } from "../middleware/astro-middleware.js";
6
+ import { PagesHandler } from "../pages/handler.js";
7
+ import { matchRoute } from "../routing/match.js";
8
+ import { provideSession } from "../session/handler.js";
9
+ class DefaultErrorHandler {
10
+ #app;
11
+ #astroMiddleware;
12
+ #pagesHandler;
13
+ constructor(app) {
14
+ this.#app = app;
15
+ this.#astroMiddleware = new AstroMiddleware(app.pipeline);
16
+ this.#pagesHandler = new PagesHandler(app.pipeline);
17
+ }
18
+ async renderError(request, {
19
+ status,
20
+ response: originalResponse,
21
+ skipMiddleware = false,
22
+ error,
23
+ pathname,
24
+ ...resolvedRenderOptions
25
+ }) {
26
+ const app = this.#app;
27
+ const resolvedPathname = pathname ?? new FetchState(app.pipeline, request).pathname;
28
+ const errorRoutePath = `/${status}${app.manifest.trailingSlash === "always" ? "/" : ""}`;
29
+ const errorRouteData = matchRoute(errorRoutePath, app.manifestData);
30
+ const url = new URL(request.url);
31
+ if (errorRouteData) {
32
+ if (errorRouteData.prerender) {
33
+ const maybeDotHtml = errorRouteData.route.endsWith(`/${status}`) ? ".html" : "";
34
+ const statusURL = new URL(`${app.baseWithoutTrailingSlash}/${status}${maybeDotHtml}`, url);
35
+ if (statusURL.toString() !== request.url && resolvedRenderOptions.prerenderedErrorPageFetch) {
36
+ const response2 = await resolvedRenderOptions.prerenderedErrorPageFetch(
37
+ statusURL.toString()
38
+ );
39
+ const override = { status, removeContentEncodingHeaders: true };
40
+ const newResponse = mergeResponses(response2, originalResponse, override);
41
+ prepareResponse(newResponse, resolvedRenderOptions);
42
+ return newResponse;
43
+ }
44
+ }
45
+ const mod = await app.pipeline.getComponentByRoute(errorRouteData);
46
+ const errorState = new FetchState(app.pipeline, request);
47
+ errorState.skipMiddleware = skipMiddleware;
48
+ errorState.clientAddress = resolvedRenderOptions.clientAddress;
49
+ errorState.routeData = errorRouteData;
50
+ errorState.pathname = resolvedPathname;
51
+ errorState.status = status;
52
+ errorState.componentInstance = mod;
53
+ errorState.locals = resolvedRenderOptions.locals ?? {};
54
+ errorState.initialProps = { error };
55
+ try {
56
+ await provideSession(errorState);
57
+ const response2 = await this.#astroMiddleware.handle(
58
+ errorState,
59
+ this.#pagesHandler.handle.bind(this.#pagesHandler)
60
+ );
61
+ const newResponse = mergeResponses(response2, originalResponse);
62
+ prepareResponse(newResponse, resolvedRenderOptions);
63
+ return newResponse;
64
+ } catch {
65
+ if (skipMiddleware === false) {
66
+ return this.renderError(request, {
67
+ ...resolvedRenderOptions,
68
+ status,
69
+ response: originalResponse,
70
+ skipMiddleware: true,
71
+ pathname: resolvedPathname
72
+ });
73
+ }
74
+ } finally {
75
+ await errorState.finalizeAll();
76
+ }
77
+ }
78
+ const response = mergeResponses(new Response(null, { status }), originalResponse);
79
+ prepareResponse(response, resolvedRenderOptions);
80
+ return response;
81
+ }
82
+ }
83
+ function mergeResponses(newResponse, originalResponse, override) {
84
+ let newResponseHeaders = newResponse.headers;
85
+ if (override?.removeContentEncodingHeaders) {
86
+ newResponseHeaders = new Headers(newResponseHeaders);
87
+ newResponseHeaders.delete("Content-Encoding");
88
+ newResponseHeaders.delete("Content-Length");
89
+ }
90
+ if (!originalResponse) {
91
+ if (override !== void 0) {
92
+ return new Response(newResponse.body, {
93
+ status: override.status,
94
+ statusText: newResponse.statusText,
95
+ headers: newResponseHeaders
96
+ });
97
+ }
98
+ return newResponse;
99
+ }
100
+ const status = override?.status ? override.status : originalResponse.status === 200 ? newResponse.status : originalResponse.status;
101
+ try {
102
+ originalResponse.headers.delete("Content-type");
103
+ originalResponse.headers.delete("Content-Length");
104
+ originalResponse.headers.delete("Transfer-Encoding");
105
+ } catch {
106
+ }
107
+ const newHeaders = new Headers();
108
+ const seen = /* @__PURE__ */ new Set();
109
+ for (const [name, value] of originalResponse.headers) {
110
+ newHeaders.append(name, value);
111
+ seen.add(name.toLowerCase());
112
+ }
113
+ for (const [name, value] of newResponseHeaders) {
114
+ if (!seen.has(name.toLowerCase())) {
115
+ newHeaders.append(name, value);
116
+ }
117
+ }
118
+ const mergedResponse = new Response(newResponse.body, {
119
+ status,
120
+ statusText: status === 200 ? newResponse.statusText : originalResponse.statusText,
121
+ // If you're looking at here for possible bugs, it means that it's not a bug.
122
+ // With the middleware, users can meddle with headers, and we should pass to the 404/500.
123
+ // If users see something weird, it's because they are setting some headers they should not.
124
+ //
125
+ // Although, we don't want it to replace the content-type, because the error page must return `text/html`
126
+ headers: newHeaders
127
+ });
128
+ const originalCookies = getCookiesFromResponse(originalResponse);
129
+ const newCookies = getCookiesFromResponse(newResponse);
130
+ if (originalCookies) {
131
+ if (newCookies) {
132
+ for (const cookieValue of newCookies.consume()) {
133
+ originalResponse.headers.append("set-cookie", cookieValue);
134
+ }
135
+ }
136
+ attachCookiesToResponse(mergedResponse, originalCookies);
137
+ } else if (newCookies) {
138
+ attachCookiesToResponse(mergedResponse, newCookies);
139
+ }
140
+ return mergedResponse;
141
+ }
142
+ export {
143
+ DefaultErrorHandler
144
+ };
@@ -0,0 +1,21 @@
1
+ import type { BaseApp, RenderErrorOptions } from '../app/base.js';
2
+ import type { Pipeline } from '../base-pipeline.js';
3
+ import type { ErrorHandler } from './handler.js';
4
+ export interface DevErrorHandlerOptions {
5
+ /**
6
+ * Whether to inject CSP meta tags into the rendered error page response.
7
+ * The Vite dev server injects them; the non-runnable dev pipeline does not.
8
+ */
9
+ shouldInjectCspMetaTags: boolean;
10
+ }
11
+ /**
12
+ * The dev-server error handler. Renders custom 404/500 routes if the user
13
+ * has them, otherwise throws so Vite's dev overlay is shown. Shared between
14
+ * the Vite dev server (`AstroServerApp`) and the non-runnable dev pipeline
15
+ * (`DevApp`); only `shouldInjectCspMetaTags` differs between them.
16
+ */
17
+ export declare class DevErrorHandler implements ErrorHandler {
18
+ #private;
19
+ constructor(app: BaseApp<Pipeline>, options: DevErrorHandlerOptions);
20
+ renderError(request: Request, { skipMiddleware, error, status, response: _response, pathname, ...resolvedRenderOptions }: RenderErrorOptions): Promise<Response>;
21
+ }
@@ -0,0 +1,82 @@
1
+ import { FetchState } from "../fetch/fetch-state.js";
2
+ import { AstroMiddleware } from "../middleware/astro-middleware.js";
3
+ import { PagesHandler } from "../pages/handler.js";
4
+ import { getCustom404Route, getCustom500Route } from "../routing/helpers.js";
5
+ import { isAstroError } from "./index.js";
6
+ import { MiddlewareNoDataOrNextCalled, MiddlewareNotAResponse } from "./errors-data.js";
7
+ class DevErrorHandler {
8
+ #app;
9
+ #shouldInjectCspMetaTags;
10
+ #astroMiddleware;
11
+ #pagesHandler;
12
+ constructor(app, options) {
13
+ this.#app = app;
14
+ this.#shouldInjectCspMetaTags = options.shouldInjectCspMetaTags;
15
+ this.#astroMiddleware = new AstroMiddleware(app.pipeline);
16
+ this.#pagesHandler = new PagesHandler(app.pipeline);
17
+ }
18
+ async renderError(request, {
19
+ skipMiddleware = false,
20
+ error,
21
+ status,
22
+ response: _response,
23
+ pathname,
24
+ ...resolvedRenderOptions
25
+ }) {
26
+ if (isAstroError(error) && [MiddlewareNoDataOrNextCalled.name, MiddlewareNotAResponse.name].includes(error.name)) {
27
+ throw error;
28
+ }
29
+ const app = this.#app;
30
+ const shouldInjectCspMetaTags = this.#shouldInjectCspMetaTags;
31
+ const resolvedPathname = pathname ?? new FetchState(app.pipeline, request).pathname;
32
+ const renderRoute = async (routeData) => {
33
+ try {
34
+ const preloadedComponent = await app.pipeline.getComponentByRoute(routeData);
35
+ const errorState = new FetchState(app.pipeline, request);
36
+ errorState.skipMiddleware = skipMiddleware;
37
+ errorState.clientAddress = resolvedRenderOptions.clientAddress;
38
+ errorState.shouldInjectCspMetaTags = shouldInjectCspMetaTags ? !!app.manifest.csp : false;
39
+ errorState.routeData = routeData;
40
+ errorState.pathname = resolvedPathname;
41
+ errorState.status = status;
42
+ errorState.componentInstance = preloadedComponent;
43
+ errorState.locals = resolvedRenderOptions.locals ?? {};
44
+ errorState.initialProps = { error };
45
+ const response = await this.#astroMiddleware.handle(
46
+ errorState,
47
+ this.#pagesHandler.handle.bind(this.#pagesHandler)
48
+ );
49
+ if (error) {
50
+ app.logger.error("router", error.stack || error.message);
51
+ }
52
+ return response;
53
+ } catch (_err) {
54
+ if (skipMiddleware === false) {
55
+ return this.renderError(request, {
56
+ ...resolvedRenderOptions,
57
+ status: 500,
58
+ skipMiddleware: true,
59
+ error: _err,
60
+ pathname: resolvedPathname
61
+ });
62
+ }
63
+ throw _err;
64
+ }
65
+ };
66
+ if (status === 404) {
67
+ const custom404 = getCustom404Route(app.manifestData);
68
+ if (custom404) {
69
+ return renderRoute(custom404);
70
+ }
71
+ }
72
+ const custom500 = getCustom500Route(app.manifestData);
73
+ if (!custom500) {
74
+ throw error;
75
+ } else {
76
+ return renderRoute(custom500);
77
+ }
78
+ }
79
+ }
80
+ export {
81
+ DevErrorHandler
82
+ };
@@ -30,7 +30,7 @@ export declare const UnknownCompilerError: {
30
30
  * @docs
31
31
  * @see
32
32
  * - [Official integrations](https://docs.astro.build/en/guides/integrations/#official-integrations)
33
- * - [Astro.clientAddress](https://docs.astro.build/en/reference/api-reference/#clientaddress)
33
+ * - [`Astro.clientAddress`](https://docs.astro.build/en/reference/api-reference/#clientaddress)
34
34
  * @description
35
35
  * The adapter you're using unfortunately does not support `Astro.clientAddress`.
36
36
  */
@@ -43,7 +43,7 @@ export declare const ClientAddressNotAvailable: {
43
43
  * @docs
44
44
  * @see
45
45
  * - [On-demand rendering](https://docs.astro.build/en/guides/on-demand-rendering/)
46
- * - [Astro.clientAddress](https://docs.astro.build/en/reference/api-reference/#clientaddress)
46
+ * - [`Astro.clientAddress`](https://docs.astro.build/en/reference/api-reference/#clientaddress)
47
47
  * @description
48
48
  * The `Astro.clientAddress` property cannot be used inside prerendered routes.
49
49
  */
@@ -56,7 +56,7 @@ export declare const PrerenderClientAddressNotAvailable: {
56
56
  * @docs
57
57
  * @see
58
58
  * - [Enabling SSR in Your Project](https://docs.astro.build/en/guides/on-demand-rendering/)
59
- * - [Astro.clientAddress](https://docs.astro.build/en/reference/api-reference/#clientaddress)
59
+ * - [`Astro.clientAddress`](https://docs.astro.build/en/reference/api-reference/#clientaddress)
60
60
  * @description
61
61
  * The `Astro.clientAddress` property is only available when [Server-side rendering](https://docs.astro.build/en/guides/on-demand-rendering/) is enabled.
62
62
  *
@@ -71,7 +71,7 @@ export declare const StaticClientAddressNotAvailable: {
71
71
  /**
72
72
  * @docs
73
73
  * @see
74
- * - [getStaticPaths()](https://docs.astro.build/en/reference/routing-reference/#getstaticpaths)
74
+ * - [`getStaticPaths()`](https://docs.astro.build/en/reference/routing-reference/#getstaticpaths)
75
75
  * @description
76
76
  * A [dynamic route](https://docs.astro.build/en/guides/routing/#dynamic-routes) was matched, but no corresponding path was found for the requested parameters. This is often caused by a typo in either the generated or the requested path.
77
77
  */
@@ -95,7 +95,7 @@ export declare const NoMatchingStaticPathFound: {
95
95
  * statusText: 'Not found'
96
96
  * });
97
97
  *
98
- * // Alternatively, for redirects, Astro.redirect also returns an instance of Response
98
+ * // Alternatively, for redirects, `Astro.redirect()` also returns an instance of `Response`
99
99
  * return Astro.redirect('/login');
100
100
  * ---
101
101
  * ```
@@ -179,14 +179,14 @@ export declare const NoClientOnlyHint: {
179
179
  * - [`getStaticPaths()`](https://docs.astro.build/en/reference/routing-reference/#getstaticpaths)
180
180
  * - [`params`](https://docs.astro.build/en/reference/api-reference/#params)
181
181
  * @description
182
- * The `params` property in `getStaticPaths`'s return value (an array of objects) should also be an object.
182
+ * The `params` property in `getStaticPaths()`'s return value (an array of objects) should also be an object.
183
183
  *
184
184
  * ```astro title="pages/blog/[id].astro"
185
185
  * ---
186
186
  * export async function getStaticPaths() {
187
187
  * return [
188
- * { params: { slug: "blog" } },
189
- * { params: { slug: "about" } }
188
+ * { params: { id: "blog" } },
189
+ * { params: { id: "about" } }
190
190
  * ];
191
191
  *}
192
192
  *---
@@ -203,13 +203,13 @@ export declare const InvalidGetStaticPathParam: {
203
203
  * @see
204
204
  * - [`getStaticPaths()`](https://docs.astro.build/en/reference/routing-reference/#getstaticpaths)
205
205
  * @description
206
- * `getStaticPaths`'s return value must be an array of objects. In most cases, this error happens because an array of array was returned. Using [`.flatMap()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flatMap) or a [`.flat()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flat) call may be useful.
206
+ * `getStaticPaths()`'s return value must be an array of objects. In most cases, this error happens because an array of arrays was returned. Using [`.flatMap()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flatMap) or a [`.flat()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flat) call may be useful.
207
207
  *
208
208
  * ```ts title="pages/blog/[id].astro"
209
209
  * export async function getStaticPaths() {
210
210
  * return [ // <-- Array
211
- * { params: { slug: "blog" } }, // <-- Object
212
- * { params: { slug: "about" } }
211
+ * { params: { id: "blog" } }, // <-- Object
212
+ * { params: { id: "about" } }
213
213
  * ];
214
214
  *}
215
215
  * ```
@@ -226,13 +226,13 @@ export declare const InvalidGetStaticPathsEntry: {
226
226
  * - [`getStaticPaths()`](https://docs.astro.build/en/reference/routing-reference/#getstaticpaths)
227
227
  * - [`params`](https://docs.astro.build/en/reference/api-reference/#params)
228
228
  * @description
229
- * `getStaticPaths`'s return value must be an array of objects.
229
+ * `getStaticPaths()`'s return value must be an array of objects.
230
230
  *
231
231
  * ```ts title="pages/blog/[id].astro"
232
232
  * export async function getStaticPaths() {
233
233
  * return [ // <-- Array
234
- * { params: { slug: "blog" } },
235
- * { params: { slug: "about" } }
234
+ * { params: { id: "blog" } },
235
+ * { params: { id: "about" } }
236
236
  * ];
237
237
  *}
238
238
  * ```
@@ -249,7 +249,7 @@ export declare const InvalidGetStaticPathsReturn: {
249
249
  * - [`getStaticPaths()`](https://docs.astro.build/en/reference/routing-reference/#getstaticpaths)
250
250
  * - [`params`](https://docs.astro.build/en/reference/api-reference/#params)
251
251
  * @description
252
- * Every route specified by `getStaticPaths` require a `params` property specifying the path parameters needed to match the route.
252
+ * Every route specified by `getStaticPaths()` requires a `params` property specifying the path parameters needed to match the route.
253
253
  *
254
254
  * For instance, the following code:
255
255
  * ```astro title="pages/blog/[id].astro"
@@ -315,9 +315,9 @@ export declare const GetStaticPathsInvalidRouteParam: {
315
315
  * @see
316
316
  * - [Dynamic Routes](https://docs.astro.build/en/guides/routing/#dynamic-routes)
317
317
  * - [`getStaticPaths()`](https://docs.astro.build/en/reference/routing-reference/#getstaticpaths)
318
- * - [Server-side Rendering](https://docs.astro.build/en/guides/on-demand-rendering/)
318
+ * - [Server-side rendering](https://docs.astro.build/en/guides/on-demand-rendering/)
319
319
  * @description
320
- * In [Static Mode](https://docs.astro.build/en/guides/routing/#static-ssg-mode), all routes must be determined at build time. As such, dynamic routes must `export` a `getStaticPaths` function returning the different paths to generate.
320
+ * In [Static Mode](https://docs.astro.build/en/guides/routing/#static-ssg-mode), all routes must be determined at build time. As such, dynamic routes must `export` a `getStaticPaths()` function returning the different paths to generate.
321
321
  */
322
322
  export declare const GetStaticPathsRequired: {
323
323
  name: string;
@@ -340,7 +340,7 @@ export declare const ReservedSlotName: {
340
340
  /**
341
341
  * @docs
342
342
  * @see
343
- * - [Server-side Rendering](https://docs.astro.build/en/guides/on-demand-rendering/)
343
+ * - [Server-side rendering](https://docs.astro.build/en/guides/on-demand-rendering/)
344
344
  * @description
345
345
  * To use server-side rendering, an adapter needs to be installed so Astro knows how to generate the proper output for your targeted deployment platform.
346
346
  */
@@ -353,7 +353,7 @@ export declare const NoAdapterInstalled: {
353
353
  /**
354
354
  * @docs
355
355
  * @see
356
- * - [Server-side Rendering](https://docs.astro.build/en/guides/on-demand-rendering/)
356
+ * - [Server-side rendering](https://docs.astro.build/en/guides/on-demand-rendering/)
357
357
  * @description
358
358
  * The currently configured adapter does not support server-side rendering, which is required for the current project setup.
359
359
  *
@@ -370,7 +370,7 @@ export declare const AdapterSupportOutputMismatch: {
370
370
  * @see
371
371
  * - [On-demand Rendering](https://docs.astro.build/en/guides/on-demand-rendering/)
372
372
  * @description
373
- * To use server islands, the same constraints exist as for sever-side rendering, so an adapter is needed.
373
+ * To use server islands, the same constraints exist as for server-side rendering, so an adapter is needed.
374
374
  */
375
375
  export declare const NoAdapterInstalledServerIslands: {
376
376
  name: string;
@@ -400,7 +400,7 @@ export declare const NoMatchingImport: {
400
400
  export declare const InvalidPrerenderExport: {
401
401
  name: string;
402
402
  title: string;
403
- message(prefix: string, suffix: string, isHydridOutput: boolean): string;
403
+ message(prefix: string, suffix: string, isHybridOutput: boolean): string;
404
404
  hint: string;
405
405
  };
406
406
  /**
@@ -648,7 +648,7 @@ export declare const ExpectedNotESMImage: {
648
648
  * @docs
649
649
  * @see
650
650
  * - [Images](https://docs.astro.build/en/guides/images/)
651
- * - [getImage()](https://docs.astro.build/en/reference/modules/astro-assets/#getimage)
651
+ * - [`getImage()`](https://docs.astro.build/en/reference/modules/astro-assets/#getimage)
652
652
  * @description
653
653
  * The `getImage()` function is only available on the server. To use images on the client, either render the `src` from `getImage()` during the server render so it can be used in client-side scripts, or use a standard `<img>` tag.
654
654
  *
@@ -867,7 +867,7 @@ export declare const MiddlewareCantBeLoaded: {
867
867
  * @see
868
868
  * - [Images](https://docs.astro.build/en/guides/images/)
869
869
  * @description
870
- * When using the default image services, `Image`'s and `getImage`'s `src` parameter must be either an imported image or an URL, it cannot be a string of a filepath.
870
+ * When using the default image services, `Image`'s and `getImage`'s `src` parameter must be either an imported image or a URL, it cannot be a string of a filepath.
871
871
  *
872
872
  * For local images from content collections, you can use the [image() schema helper](https://docs.astro.build/en/guides/images/#images-in-content-collections) to resolve the images.
873
873
  *
@@ -923,7 +923,7 @@ export declare const AstroGlobNoMatch: {
923
923
  /**
924
924
  * @docs
925
925
  * @see
926
- * - [Astro.redirect](https://docs.astro.build/en/reference/api-reference/#redirect)
926
+ * - [`Astro.redirect()`](https://docs.astro.build/en/reference/api-reference/#redirect)
927
927
  * @description
928
928
  * A redirect must be given a location with the `Location` header.
929
929
  */
@@ -934,7 +934,7 @@ export declare const RedirectWithNoLocation: {
934
934
  /**
935
935
  * @docs
936
936
  * @see
937
- * - [Astro.redirect](https://docs.astro.build/en/reference/api-reference/#redirect)
937
+ * - [`Astro.redirect()`](https://docs.astro.build/en/reference/api-reference/#redirect)
938
938
  * @description
939
939
  * An external redirect must start with http or https, and must be a valid URL.
940
940
  */
@@ -946,17 +946,22 @@ export declare const UnsupportedExternalRedirect: {
946
946
  };
947
947
  /**
948
948
  * @docs
949
+ * @message
950
+ * **Example error message:**<br/>
951
+ * InvalidRedirectDestination: The redirect from "/posts" to "/blog" is invalid. The destination "/blog" does not match any existing route in your project.
949
952
  * @see
950
953
  * - [Configured redirects](https://docs.astro.build/en/guides/routing/#configured-redirects)
951
954
  * @description
952
- * A dynamic redirect destination must match an existing route pattern.
955
+ * A dynamic redirect destination must match an existing route pattern and include
956
+ * all dynamic parameters from the source route.
953
957
  * This error occurs when a redirect with dynamic parameters points to a destination
954
- * that doesn't correspond to any page in your project.
958
+ * that doesn't correspond to any page in your project, or when the destination route
959
+ * has fewer dynamic parameters than the source route.
955
960
  */
956
961
  export declare const InvalidRedirectDestination: {
957
962
  name: string;
958
963
  title: string;
959
- message: (from: string, to: string) => string;
964
+ message(from: string, to: string, missingParams?: string[]): string;
960
965
  hint: string;
961
966
  };
962
967
  /**
@@ -1051,7 +1056,7 @@ export declare const FailedToFindPageMapSSR: {
1051
1056
  /**
1052
1057
  * @docs
1053
1058
  * @description
1054
- * Astro can't find the requested locale. All supported locales must be configured in [i18n.locales](/en/reference/configuration-reference/#i18nlocales) and have corresponding directories within `src/pages/`.
1059
+ * Astro can't find the requested locale. All supported locales must be configured in [`i18n.locales`](https://docs.astro.build/en/reference/configuration-reference/#i18nlocales) and have corresponding directories within `src/pages/`.
1055
1060
  */
1056
1061
  export declare const MissingLocale: {
1057
1062
  name: string;
@@ -1108,7 +1113,7 @@ export declare const MissingMiddlewareForInternationalization: {
1108
1113
  /**
1109
1114
  * @docs
1110
1115
  * @description
1111
- * An invalid i18n middleware configuration was detected.
1116
+ * An invalid i18n middleware configuration was detected.
1112
1117
  */
1113
1118
  export declare const InvalidI18nMiddlewareConfiguration: {
1114
1119
  name: string;
@@ -1165,7 +1170,7 @@ export declare const i18nNotEnabled: {
1165
1170
  /**
1166
1171
  * @docs
1167
1172
  * @description
1168
- * An i18n utility tried to use the locale from a URL path that does not contain one. You can prevent this error by using pathHasLocale to check URLs for a locale first before using i18n utilities.
1173
+ * An i18n utility tried to use the locale from a URL path that does not contain one. You can prevent this error by using `pathHasLocale` to check URLs for a locale first before using i18n utilities.
1169
1174
  *
1170
1175
  */
1171
1176
  export declare const i18nNoLocaleFoundInPath: {
@@ -1176,7 +1181,7 @@ export declare const i18nNoLocaleFoundInPath: {
1176
1181
  /**
1177
1182
  * @docs
1178
1183
  * @description
1179
- * Astro couldn't find a route matching the one provided by the user
1184
+ * Astro couldn't find a route matching the one provided by the user.
1180
1185
  */
1181
1186
  export declare const RouteNotFound: {
1182
1187
  name: string;
@@ -1291,7 +1296,7 @@ export declare const CannotDetermineWeightAndStyleFromFontFile: {
1291
1296
  /**
1292
1297
  * @docs
1293
1298
  * @description
1294
- * Cannot fetch the given font file
1299
+ * Cannot fetch the given font file.
1295
1300
  * @message
1296
1301
  * An error occurred while fetching font file from the given URL.
1297
1302
  */
@@ -1304,7 +1309,7 @@ export declare const CannotFetchFontFile: {
1304
1309
  /**
1305
1310
  * @docs
1306
1311
  * @description
1307
- * Font family not found
1312
+ * Font family not found.
1308
1313
  * @message
1309
1314
  * No data was found for the `cssVariable` passed to the `<Font />` component.
1310
1315
  */
@@ -1317,7 +1322,7 @@ export declare const FontFamilyNotFound: {
1317
1322
  /**
1318
1323
  * @docs
1319
1324
  * @description
1320
- * Font file URL not found
1325
+ * Font file URL not found.
1321
1326
  * @message
1322
1327
  * The URL passed to the `experimental_getFontFileURL()` function is invalid.
1323
1328
  */
@@ -1340,9 +1345,9 @@ export declare const MissingGetFontFileRequestUrl: {
1340
1345
  /**
1341
1346
  * @docs
1342
1347
  * @description
1343
- * Unavailable Astro global in getStaticPaths
1348
+ * Unavailable Astro global in `getStaticPaths()`.
1344
1349
  * @message
1345
- * The Astro global is not available in getStaticPaths().
1350
+ * The Astro global is not available in `getStaticPaths()`.
1346
1351
  */
1347
1352
  export declare const UnavailableAstroGlobal: {
1348
1353
  name: string;
@@ -1475,7 +1480,7 @@ export declare const UnknownConfigError: {
1475
1480
  * @see
1476
1481
  * - [--config](https://docs.astro.build/en/reference/cli-reference/#--config-path)
1477
1482
  * @description
1478
- * The specified configuration file using `--config` could not be found. Make sure that it exists or that the path is correct
1483
+ * The specified configuration file using `--config` could not be found. Make sure that it exists or that the path is correct.
1479
1484
  */
1480
1485
  export declare const ConfigNotFound: {
1481
1486
  name: string;