astro 4.7.1 → 4.8.0

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 (222) hide show
  1. package/client.d.ts +1 -0
  2. package/content-module.template.mjs +2 -0
  3. package/dist/@types/astro.d.ts +219 -3
  4. package/dist/actions/consts.d.ts +3 -0
  5. package/dist/actions/consts.js +8 -0
  6. package/dist/actions/index.d.ts +2 -0
  7. package/dist/actions/index.js +72 -0
  8. package/dist/actions/runtime/middleware.d.ts +7 -0
  9. package/dist/actions/runtime/middleware.js +38 -0
  10. package/dist/actions/runtime/route.d.ts +2 -0
  11. package/dist/actions/runtime/route.js +37 -0
  12. package/dist/actions/runtime/store.d.ts +6 -0
  13. package/dist/actions/runtime/store.js +18 -0
  14. package/dist/actions/runtime/utils.d.ts +4 -0
  15. package/dist/actions/runtime/utils.js +23 -0
  16. package/dist/actions/runtime/virtual/client.d.ts +4 -0
  17. package/dist/actions/runtime/virtual/client.js +20 -0
  18. package/dist/actions/runtime/virtual/server.d.ts +21 -0
  19. package/dist/actions/runtime/virtual/server.js +98 -0
  20. package/dist/actions/runtime/virtual/shared.d.ts +37 -0
  21. package/dist/actions/runtime/virtual/shared.js +104 -0
  22. package/dist/actions/utils.d.ts +2 -0
  23. package/dist/actions/utils.js +18 -0
  24. package/dist/assets/build/generate.js +1 -1
  25. package/dist/assets/internal.js +1 -2
  26. package/dist/assets/services/service.js +2 -4
  27. package/dist/assets/services/sharp.js +2 -4
  28. package/dist/assets/services/squoosh.js +2 -4
  29. package/dist/assets/services/vendor/squoosh/avif/avif_node_dec.js +34 -68
  30. package/dist/assets/services/vendor/squoosh/avif/avif_node_enc.js +39 -78
  31. package/dist/assets/services/vendor/squoosh/mozjpeg/mozjpeg_node_dec.js +32 -64
  32. package/dist/assets/services/vendor/squoosh/mozjpeg/mozjpeg_node_enc.js +32 -64
  33. package/dist/assets/services/vendor/squoosh/png/squoosh_png.js +2 -4
  34. package/dist/assets/services/vendor/squoosh/webp/webp_node_dec.js +29 -58
  35. package/dist/assets/services/vendor/squoosh/webp/webp_node_enc.js +29 -58
  36. package/dist/assets/utils/getAssetsPrefix.js +2 -4
  37. package/dist/assets/utils/remotePattern.js +1 -2
  38. package/dist/assets/utils/remoteProbe.js +1 -2
  39. package/dist/assets/utils/vendor/image-size/types/cur.js +1 -2
  40. package/dist/assets/utils/vendor/image-size/types/icns.js +1 -2
  41. package/dist/assets/utils/vendor/image-size/types/ico.js +2 -4
  42. package/dist/assets/utils/vendor/image-size/types/jp2.js +2 -4
  43. package/dist/assets/utils/vendor/image-size/types/utils.js +4 -8
  44. package/dist/assets/vite-plugin-assets.js +1 -1
  45. package/dist/cli/add/babel.d.ts +1 -1
  46. package/dist/cli/add/imports.js +4 -8
  47. package/dist/cli/add/index.js +23 -46
  48. package/dist/cli/add/wrapper.js +1 -2
  49. package/dist/cli/index.js +1 -2
  50. package/dist/cli/info/index.js +1 -2
  51. package/dist/cli/install-package.js +3 -6
  52. package/dist/cli/throw-and-exit.js +1 -2
  53. package/dist/config/index.d.ts +2 -2
  54. package/dist/config/index.js +2 -2
  55. package/dist/content/index.d.ts +1 -1
  56. package/dist/content/index.js +1 -7
  57. package/dist/content/runtime.d.ts +2 -1
  58. package/dist/content/runtime.js +11 -20
  59. package/dist/content/server-listeners.js +5 -10
  60. package/dist/content/types-generator.js +5 -10
  61. package/dist/content/utils.d.ts +0 -4
  62. package/dist/content/utils.js +4 -15
  63. package/dist/content/vite-plugin-content-assets.d.ts +1 -1
  64. package/dist/content/vite-plugin-content-assets.js +14 -47
  65. package/dist/content/vite-plugin-content-imports.js +6 -11
  66. package/dist/content/vite-plugin-content-virtual-mod.js +7 -14
  67. package/dist/core/app/index.js +11 -46
  68. package/dist/core/app/node.js +4 -3
  69. package/dist/core/app/pipeline.d.ts +7 -2
  70. package/dist/core/app/pipeline.js +70 -2
  71. package/dist/core/app/types.d.ts +1 -0
  72. package/dist/core/base-pipeline.d.ts +16 -1
  73. package/dist/core/build/generate.js +15 -61
  74. package/dist/core/build/index.js +2 -4
  75. package/dist/core/build/internal.d.ts +39 -9
  76. package/dist/core/build/internal.js +43 -54
  77. package/dist/core/build/page-data.js +6 -6
  78. package/dist/core/build/pipeline.d.ts +7 -3
  79. package/dist/core/build/pipeline.js +134 -23
  80. package/dist/core/build/plugins/plugin-analyzer.js +11 -32
  81. package/dist/core/build/plugins/plugin-content.d.ts +1 -0
  82. package/dist/core/build/plugins/plugin-content.js +34 -32
  83. package/dist/core/build/plugins/plugin-css.js +23 -51
  84. package/dist/core/build/plugins/plugin-manifest.js +7 -8
  85. package/dist/core/build/plugins/plugin-pages.d.ts +0 -1
  86. package/dist/core/build/plugins/plugin-pages.js +10 -12
  87. package/dist/core/build/plugins/plugin-ssr.js +15 -13
  88. package/dist/core/build/plugins/util.d.ts +26 -11
  89. package/dist/core/build/plugins/util.js +22 -6
  90. package/dist/core/build/static-build.js +30 -25
  91. package/dist/core/build/types.d.ts +6 -6
  92. package/dist/core/client-directive/build.js +1 -2
  93. package/dist/core/config/config.js +2 -7
  94. package/dist/core/config/logging.js +1 -2
  95. package/dist/core/config/schema.d.ts +92 -60
  96. package/dist/core/config/schema.js +6 -2
  97. package/dist/core/config/settings.js +1 -2
  98. package/dist/core/config/timer.js +4 -8
  99. package/dist/core/constants.js +1 -1
  100. package/dist/core/cookies/cookies.js +3 -6
  101. package/dist/core/dev/dev.js +1 -1
  102. package/dist/core/dev/restart.js +1 -2
  103. package/dist/core/errors/errors-data.d.ts +24 -0
  104. package/dist/core/errors/errors-data.js +13 -2
  105. package/dist/core/errors/errors.js +1 -2
  106. package/dist/core/errors/overlay.js +1 -2
  107. package/dist/core/errors/printer.js +2 -4
  108. package/dist/core/errors/zod-error-map.js +2 -4
  109. package/dist/core/fs/index.js +2 -4
  110. package/dist/core/logger/vite.js +9 -18
  111. package/dist/core/messages.js +2 -2
  112. package/dist/core/middleware/callMiddleware.d.ts +3 -2
  113. package/dist/core/middleware/callMiddleware.js +13 -3
  114. package/dist/core/middleware/index.js +12 -8
  115. package/dist/core/middleware/sequence.js +22 -4
  116. package/dist/core/module-loader/vite.js +1 -2
  117. package/dist/core/render/params-and-props.js +2 -4
  118. package/dist/core/render/slots.js +4 -8
  119. package/dist/core/render-context.d.ts +15 -5
  120. package/dist/core/render-context.js +134 -28
  121. package/dist/core/request.js +1 -2
  122. package/dist/core/routing/manifest/create.js +3 -6
  123. package/dist/core/sync/index.js +10 -3
  124. package/dist/core/util.d.ts +2 -0
  125. package/dist/core/util.js +18 -19
  126. package/dist/i18n/index.js +2 -4
  127. package/dist/i18n/middleware.js +1 -2
  128. package/dist/i18n/utils.js +1 -2
  129. package/dist/i18n/vite-plugin-i18n.js +1 -2
  130. package/dist/integrations/hooks.js +5 -1
  131. package/dist/jsx/babel.d.ts +3 -0
  132. package/dist/jsx/babel.js +9 -18
  133. package/dist/jsx/rehype.d.ts +11 -0
  134. package/dist/jsx/rehype.js +197 -0
  135. package/dist/jsx/server.js +20 -14
  136. package/dist/jsx/transform-options.d.ts +3 -0
  137. package/dist/jsx-runtime/index.js +8 -16
  138. package/dist/preferences/index.js +3 -6
  139. package/dist/preferences/store.js +3 -6
  140. package/dist/prefetch/index.js +8 -16
  141. package/dist/prefetch/vite-plugin-prefetch.js +2 -4
  142. package/dist/prerender/metadata.js +1 -2
  143. package/dist/prerender/routing.js +1 -1
  144. package/dist/prerender/utils.d.ts +0 -1
  145. package/dist/prerender/utils.js +2 -5
  146. package/dist/runtime/client/dev-toolbar/apps/astro.js +5 -10
  147. package/dist/runtime/client/dev-toolbar/apps/audit/index.js +5 -10
  148. package/dist/runtime/client/dev-toolbar/apps/audit/rules/a11y.js +45 -90
  149. package/dist/runtime/client/dev-toolbar/apps/audit/rules/index.js +1 -2
  150. package/dist/runtime/client/dev-toolbar/apps/audit/rules/perf.js +16 -32
  151. package/dist/runtime/client/dev-toolbar/apps/audit/ui/audit-list-window.js +2 -4
  152. package/dist/runtime/client/dev-toolbar/apps/audit/ui/audit-ui.js +3 -6
  153. package/dist/runtime/client/dev-toolbar/apps/utils/highlight.js +1 -2
  154. package/dist/runtime/client/dev-toolbar/apps/utils/window.js +4 -8
  155. package/dist/runtime/client/dev-toolbar/entrypoint.js +8 -11
  156. package/dist/runtime/client/dev-toolbar/helpers.js +2 -4
  157. package/dist/runtime/client/dev-toolbar/toolbar.js +11 -22
  158. package/dist/runtime/client/dev-toolbar/ui-library/badge.js +1 -2
  159. package/dist/runtime/client/dev-toolbar/ui-library/button.d.ts +5 -0
  160. package/dist/runtime/client/dev-toolbar/ui-library/button.js +26 -5
  161. package/dist/runtime/client/dev-toolbar/ui-library/index.d.ts +1 -0
  162. package/dist/runtime/client/dev-toolbar/ui-library/index.js +2 -0
  163. package/dist/runtime/client/dev-toolbar/ui-library/radio-checkbox.d.ts +13 -0
  164. package/dist/runtime/client/dev-toolbar/ui-library/radio-checkbox.js +109 -0
  165. package/dist/runtime/client/visible.js +1 -2
  166. package/dist/runtime/server/astro-component.js +2 -4
  167. package/dist/runtime/server/astro-island.js +7 -14
  168. package/dist/runtime/server/astro-island.prebuilt-dev.d.ts +1 -1
  169. package/dist/runtime/server/astro-island.prebuilt-dev.js +1 -1
  170. package/dist/runtime/server/astro-island.prebuilt.d.ts +1 -1
  171. package/dist/runtime/server/astro-island.prebuilt.js +1 -1
  172. package/dist/runtime/server/index.js +3 -6
  173. package/dist/runtime/server/jsx.js +1 -2
  174. package/dist/runtime/server/render/any.js +1 -2
  175. package/dist/runtime/server/render/astro/instance.js +1 -2
  176. package/dist/runtime/server/render/astro/render.js +5 -10
  177. package/dist/runtime/server/render/component.js +6 -11
  178. package/dist/runtime/server/render/dom.js +1 -2
  179. package/dist/runtime/server/render/page.js +1 -2
  180. package/dist/runtime/server/render/script.js +1 -2
  181. package/dist/runtime/server/render/slot.js +1 -2
  182. package/dist/runtime/server/render/tags.js +2 -4
  183. package/dist/runtime/server/render/util.js +2 -4
  184. package/dist/runtime/server/shorthash.js +1 -2
  185. package/dist/runtime/server/transition.js +4 -8
  186. package/dist/runtime/server/util.js +1 -2
  187. package/dist/transitions/events.d.ts +3 -3
  188. package/dist/transitions/events.js +5 -4
  189. package/dist/transitions/router.js +22 -113
  190. package/dist/transitions/swap-functions.d.ts +12 -0
  191. package/dist/transitions/swap-functions.js +105 -0
  192. package/dist/vite-plugin-astro/compile.js +1 -2
  193. package/dist/vite-plugin-astro/hmr.js +5 -10
  194. package/dist/vite-plugin-astro/index.js +2 -4
  195. package/dist/vite-plugin-astro-server/pipeline.d.ts +8 -3
  196. package/dist/vite-plugin-astro-server/pipeline.js +59 -11
  197. package/dist/vite-plugin-astro-server/plugin.js +6 -6
  198. package/dist/vite-plugin-astro-server/response.js +1 -2
  199. package/dist/vite-plugin-astro-server/route.js +36 -42
  200. package/dist/vite-plugin-astro-server/vite.js +1 -2
  201. package/dist/vite-plugin-config-alias/index.js +7 -14
  202. package/dist/vite-plugin-head/index.js +3 -6
  203. package/dist/vite-plugin-html/index.js +1 -2
  204. package/dist/vite-plugin-html/transform/escape.js +2 -4
  205. package/dist/vite-plugin-html/transform/slots.js +1 -2
  206. package/dist/vite-plugin-html/transform/utils.js +1 -2
  207. package/dist/vite-plugin-inject-env-ts/index.js +37 -11
  208. package/dist/vite-plugin-integrations-container/index.js +3 -6
  209. package/dist/vite-plugin-load-fallback/index.js +1 -2
  210. package/dist/vite-plugin-markdown/index.js +1 -2
  211. package/dist/vite-plugin-mdx/index.d.ts +3 -0
  212. package/dist/vite-plugin-mdx/tag.d.ts +2 -0
  213. package/dist/vite-plugin-mdx/tag.js +3 -6
  214. package/dist/vite-plugin-mdx/transform-jsx.d.ts +3 -0
  215. package/dist/vite-plugin-mdx/transform-jsx.js +1 -2
  216. package/dist/vite-plugin-scanner/index.js +4 -6
  217. package/dist/vite-plugin-scanner/scan.js +2 -4
  218. package/dist/vite-plugin-scripts/page-ssr.js +3 -6
  219. package/package.json +18 -14
  220. package/templates/actions.mjs +61 -0
  221. package/types/actions.d.ts +3 -0
  222. package/types/content.d.ts +2 -2
@@ -38,10 +38,6 @@ export declare const collectionConfigParser: z.ZodUnion<[z.ZodObject<{
38
38
  type: "data";
39
39
  schema?: any;
40
40
  }>]>;
41
- export declare function getDotAstroTypeReference({ root, srcDir }: {
42
- root: URL;
43
- srcDir: URL;
44
- }): string;
45
41
  export declare const contentConfigParser: z.ZodObject<{
46
42
  collections: z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodObject<{
47
43
  type: z.ZodDefault<z.ZodOptional<z.ZodLiteral<"content">>>;
@@ -7,7 +7,7 @@ import { normalizePath } from "vite";
7
7
  import { z } from "zod";
8
8
  import { AstroError, AstroErrorData, MarkdownError, errorMap } from "../core/errors/index.js";
9
9
  import { isYAMLException } from "../core/errors/utils.js";
10
- import { CONTENT_FLAGS, CONTENT_TYPES_FILE, PROPAGATED_ASSET_FLAG } from "./consts.js";
10
+ import { CONTENT_FLAGS, PROPAGATED_ASSET_FLAG } from "./consts.js";
11
11
  import { createImage } from "./runtime-assets.js";
12
12
  const collectionConfigParser = z.union([
13
13
  z.object({
@@ -19,13 +19,6 @@ const collectionConfigParser = z.union([
19
19
  schema: z.any().optional()
20
20
  })
21
21
  ]);
22
- function getDotAstroTypeReference({ root, srcDir }) {
23
- const { cacheDir } = getContentPaths({ root, srcDir });
24
- const contentTypesRelativeToSrcDir = normalizePath(
25
- path.relative(fileURLToPath(srcDir), fileURLToPath(new URL(CONTENT_TYPES_FILE, cacheDir)))
26
- );
27
- return `/// <reference path=${JSON.stringify(contentTypesRelativeToSrcDir)} />`;
28
- }
29
22
  const contentConfigParser = z.object({
30
23
  collections: z.record(collectionConfigParser)
31
24
  });
@@ -178,22 +171,19 @@ function getEntryType(entryPath, paths, contentFileExts, dataFileExts) {
178
171
  function hasUnderscoreBelowContentDirectoryPath(fileUrl, contentDir) {
179
172
  const parts = fileUrl.pathname.replace(contentDir.pathname, "").split("/");
180
173
  for (const part of parts) {
181
- if (part.startsWith("_"))
182
- return true;
174
+ if (part.startsWith("_")) return true;
183
175
  }
184
176
  return false;
185
177
  }
186
178
  function getYAMLErrorLine(rawData, objectKey) {
187
- if (!rawData)
188
- return 0;
179
+ if (!rawData) return 0;
189
180
  const indexOfObjectKey = rawData.search(
190
181
  // Match key either at the top of the file or after a newline
191
182
  // Ensures matching on top-level object keys only
192
183
  new RegExp(`(
193
184
  |^)${objectKey}`)
194
185
  );
195
- if (indexOfObjectKey === -1)
196
- return 0;
186
+ if (indexOfObjectKey === -1) return 0;
197
187
  const dataBeforeKey = rawData.substring(0, indexOfObjectKey + 1);
198
188
  const numNewlinesBeforeKey = dataBeforeKey.split("\n").length;
199
189
  return numNewlinesBeforeKey;
@@ -359,7 +349,6 @@ export {
359
349
  getContentPaths,
360
350
  getDataEntryExts,
361
351
  getDataEntryId,
362
- getDotAstroTypeReference,
363
352
  getEntryCollectionName,
364
353
  getEntryConfigByExtMap,
365
354
  getEntryData,
@@ -1,6 +1,6 @@
1
1
  import type { Plugin } from 'vite';
2
2
  import type { AstroSettings } from '../@types/astro.js';
3
- import { type BuildInternals } from '../core/build/internal.js';
3
+ import type { BuildInternals } from '../core/build/internal.js';
4
4
  import type { AstroBuildPlugin } from '../core/build/plugin.js';
5
5
  import type { StaticBuildOptions } from '../core/build/types.js';
6
6
  export declare function astroContentAssetPropagationPlugin({ mode, settings, }: {
@@ -1,8 +1,6 @@
1
1
  import { extname } from "node:path";
2
2
  import { pathToFileURL } from "node:url";
3
3
  import { getAssetsPrefix } from "../assets/utils/getAssetsPrefix.js";
4
- import { getParentModuleInfos, moduleIsTopLevelPage } from "../core/build/graph.js";
5
- import { getPageDataByViteID } from "../core/build/internal.js";
6
4
  import { createViteLoader } from "../core/module-loader/vite.js";
7
5
  import { joinPaths, prependForwardSlash } from "../core/path.js";
8
6
  import { getStylesForURL } from "../vite-plugin-astro-server/css.js";
@@ -124,51 +122,21 @@ function astroConfigBuildPlugin(options, internals) {
124
122
  };
125
123
  for (const chunk of outputs) {
126
124
  if (chunk.type === "chunk" && (chunk.code.includes(LINKS_PLACEHOLDER) || chunk.code.includes(SCRIPTS_PLACEHOLDER))) {
127
- let entryStyles = /* @__PURE__ */ new Set();
128
- let entryLinks = /* @__PURE__ */ new Set();
129
- let entryScripts = /* @__PURE__ */ new Set();
130
- if (options.settings.config.experimental.contentCollectionCache) {
131
- for (const id of chunk.moduleIds) {
132
- const _entryCss = internals.propagatedStylesMap.get(id);
133
- const _entryScripts = internals.propagatedScriptsMap.get(id);
134
- if (_entryCss) {
135
- for (const value of _entryCss) {
136
- if (value.type === "inline")
137
- entryStyles.add(value.content);
138
- if (value.type === "external")
139
- entryLinks.add(value.src);
140
- }
141
- }
142
- if (_entryScripts) {
143
- for (const value of _entryScripts) {
144
- entryScripts.add(value);
145
- }
125
+ const entryStyles = /* @__PURE__ */ new Set();
126
+ const entryLinks = /* @__PURE__ */ new Set();
127
+ const entryScripts = /* @__PURE__ */ new Set();
128
+ for (const id of chunk.moduleIds) {
129
+ const _entryCss = internals.propagatedStylesMap.get(id);
130
+ const _entryScripts = internals.propagatedScriptsMap.get(id);
131
+ if (_entryCss) {
132
+ for (const value of _entryCss) {
133
+ if (value.type === "inline") entryStyles.add(value.content);
134
+ if (value.type === "external") entryLinks.add(value.src);
146
135
  }
147
136
  }
148
- } else {
149
- for (const id of Object.keys(chunk.modules)) {
150
- for (const pageInfo of getParentModuleInfos(id, ssrPluginContext)) {
151
- if (moduleIsTopLevelPage(pageInfo)) {
152
- const pageViteID = pageInfo.id;
153
- const pageData = getPageDataByViteID(internals, pageViteID);
154
- if (!pageData)
155
- continue;
156
- const _entryCss = pageData.propagatedStyles?.get(id);
157
- const _entryScripts = pageData.propagatedScripts?.get(id);
158
- if (_entryCss) {
159
- for (const value of _entryCss) {
160
- if (value.type === "inline")
161
- entryStyles.add(value.content);
162
- if (value.type === "external")
163
- entryLinks.add(value.src);
164
- }
165
- }
166
- if (_entryScripts) {
167
- for (const value of _entryScripts) {
168
- entryScripts.add(value);
169
- }
170
- }
171
- }
137
+ if (_entryScripts) {
138
+ for (const value of _entryScripts) {
139
+ entryScripts.add(value);
172
140
  }
173
141
  }
174
142
  }
@@ -193,8 +161,7 @@ function astroConfigBuildPlugin(options, internals) {
193
161
  const entryFileNames = /* @__PURE__ */ new Set();
194
162
  for (const output of clientOutputs) {
195
163
  for (const clientChunk of output.output) {
196
- if (clientChunk.type !== "chunk")
197
- continue;
164
+ if (clientChunk.type !== "chunk") continue;
198
165
  for (const [id] of Object.entries(clientChunk.modules)) {
199
166
  if (entryScripts.has(id)) {
200
167
  entryFileNames.add(clientChunk.fileName);
@@ -4,7 +4,7 @@ import * as devalue from "devalue";
4
4
  import { getProxyCode } from "../assets/utils/proxy.js";
5
5
  import { AstroError } from "../core/errors/errors.js";
6
6
  import { AstroErrorData } from "../core/errors/index.js";
7
- import { isServerLikeOutput } from "../prerender/utils.js";
7
+ import { isServerLikeOutput } from "../core/util.js";
8
8
  import { CONTENT_FLAG, DATA_FLAG } from "./consts.js";
9
9
  import {
10
10
  getContentEntryExts,
@@ -23,8 +23,7 @@ import {
23
23
  } from "./utils.js";
24
24
  function getContentRendererByViteId(viteId, settings) {
25
25
  let ext = viteId.split(".").pop();
26
- if (!ext)
27
- return void 0;
26
+ if (!ext) return void 0;
28
27
  for (const contentEntryType of settings.contentEntryTypes) {
29
28
  if (Boolean(contentEntryType.getRenderModule) && contentEntryType.extensions.includes("." + ext)) {
30
29
  return contentEntryType.getRenderModule;
@@ -103,8 +102,7 @@ export const _internal = {
103
102
  viteServer.watcher.on("all", async (event, entry) => {
104
103
  if (CHOKIDAR_MODIFIED_EVENTS.includes(event)) {
105
104
  const entryType = getEntryType(entry, contentPaths, contentEntryExts, dataEntryExts);
106
- if (!COLLECTION_TYPES_TO_INVALIDATE_ON.includes(entryType))
107
- return;
105
+ if (!COLLECTION_TYPES_TO_INVALIDATE_ON.includes(entryType)) return;
108
106
  if (entryType === "content" || entryType === "data") {
109
107
  await reloadContentConfigObserver({ fs, settings, viteServer });
110
108
  }
@@ -116,8 +114,7 @@ export const _internal = {
116
114
  viteServer.moduleGraph.invalidateModule(mod);
117
115
  }
118
116
  } catch (e) {
119
- if (e.code === "ERR_CLOSED_SERVER")
120
- break;
117
+ if (e.code === "ERR_CLOSED_SERVER") break;
121
118
  throw e;
122
119
  }
123
120
  }
@@ -132,8 +129,7 @@ export const _internal = {
132
129
  name: "astro:content-render-imports",
133
130
  async transform(contents, viteId) {
134
131
  const contentRenderer = getContentRendererByViteId(viteId, settings);
135
- if (!contentRenderer)
136
- return;
132
+ if (!contentRenderer) return;
137
133
  const fileId = viteId.split("?")[0];
138
134
  return contentRenderer.bind(this)({ viteId, contents, fileUrl: pathToFileURL(fileId) });
139
135
  }
@@ -229,8 +225,7 @@ async function getEntryModuleBaseInfo({
229
225
  }
230
226
  const entry = pathToFileURL(fileId);
231
227
  const collection = getEntryCollectionName({ entry, contentDir });
232
- if (collection === void 0)
233
- throw new AstroError(AstroErrorData.UnknownContentCollectionError);
228
+ if (collection === void 0) throw new AstroError(AstroErrorData.UnknownContentCollectionError);
234
229
  const collectionConfig = contentConfig?.collections[collection];
235
230
  return {
236
231
  collectionConfig,
@@ -7,8 +7,7 @@ import {} from "vite";
7
7
  import { encodeName } from "../core/build/util.js";
8
8
  import { AstroError, AstroErrorData } from "../core/errors/index.js";
9
9
  import { appendForwardSlash, removeFileExtension } from "../core/path.js";
10
- import { rootRelativePath } from "../core/util.js";
11
- import { isServerLikeOutput } from "../prerender/utils.js";
10
+ import { isServerLikeOutput, rootRelativePath } from "../core/util.js";
12
11
  import {
13
12
  CONTENT_FLAG,
14
13
  CONTENT_RENDER_FLAG,
@@ -143,12 +142,9 @@ function getStringifiedCollectionFromLookup(wantedType, relContentDir, lookupMap
143
142
  normalize = (slug) => `${removeFileExtension(encodeName(slug)).replace(relContentDir, "./")}${suffix}`;
144
143
  } else {
145
144
  let suffix = "";
146
- if (wantedType === "content")
147
- suffix = CONTENT_FLAG;
148
- else if (wantedType === "data")
149
- suffix = DATA_FLAG;
150
- else if (wantedType === "render")
151
- suffix = CONTENT_RENDER_FLAG;
145
+ if (wantedType === "content") suffix = CONTENT_FLAG;
146
+ else if (wantedType === "data") suffix = DATA_FLAG;
147
+ else if (wantedType === "render") suffix = CONTENT_RENDER_FLAG;
152
148
  normalize = (slug) => `${slug}?${suffix}`;
153
149
  }
154
150
  for (const { type, entries } of Object.values(lookupMap)) {
@@ -188,11 +184,9 @@ async function generateLookupMap({
188
184
  promises.push(
189
185
  limit(async () => {
190
186
  const entryType = getEntryType(filePath, contentPaths, contentEntryExts, dataEntryExts);
191
- if (entryType !== "content" && entryType !== "data")
192
- return;
187
+ if (entryType !== "content" && entryType !== "data") return;
193
188
  const collection = getEntryCollectionName({ contentDir, entry: pathToFileURL(filePath) });
194
- if (!collection)
195
- throw UnexpectedLookupMapError;
189
+ if (!collection) throw UnexpectedLookupMapError;
196
190
  if (lookupMap[collection]?.type && lookupMap[collection].type !== entryType) {
197
191
  throw new AstroError({
198
192
  ...AstroErrorData.MixedContentDataCollectionError,
@@ -201,8 +195,7 @@ async function generateLookupMap({
201
195
  }
202
196
  if (entryType === "content") {
203
197
  const contentEntryType = contentEntryConfigByExt.get(extname(filePath));
204
- if (!contentEntryType)
205
- throw UnexpectedLookupMapError;
198
+ if (!contentEntryType) throw UnexpectedLookupMapError;
206
199
  const { id, slug: generatedSlug } = await getContentEntryIdAndSlug({
207
200
  entry: pathToFileURL(filePath),
208
201
  contentDir,
@@ -1,6 +1,5 @@
1
1
  import { normalizeTheLocale } from "../../i18n/index.js";
2
2
  import {
3
- DEFAULT_404_COMPONENT,
4
3
  REROUTABLE_STATUS_CODES,
5
4
  REROUTE_DIRECTIVE_HEADER,
6
5
  clientAddressSymbol,
@@ -19,7 +18,6 @@ import {
19
18
  prependForwardSlash,
20
19
  removeTrailingForwardSlash
21
20
  } from "../path.js";
22
- import { RedirectSinglePageBuiltModule } from "../redirects/index.js";
23
21
  import { RenderContext } from "../render-context.js";
24
22
  import { createAssetLink } from "../render/ssr-element.js";
25
23
  import { ensure404Route } from "../routing/astro-designed-error-pages.js";
@@ -44,7 +42,7 @@ class App {
44
42
  routes: manifest.routes.map((route) => route.routeData)
45
43
  });
46
44
  this.#baseWithoutTrailingSlash = removeTrailingForwardSlash(this.#manifest.base);
47
- this.#pipeline = this.#createPipeline(streaming);
45
+ this.#pipeline = this.#createPipeline(this.#manifestData, streaming);
48
46
  this.#adapterLogger = new AstroIntegrationLogger(
49
47
  this.#logger.options,
50
48
  this.#manifest.adapterName
@@ -56,17 +54,18 @@ class App {
56
54
  /**
57
55
  * Creates a pipeline by reading the stored manifest
58
56
  *
57
+ * @param manifestData
59
58
  * @param streaming
60
59
  * @private
61
60
  */
62
- #createPipeline(streaming = false) {
61
+ #createPipeline(manifestData, streaming = false) {
63
62
  if (this.#manifest.checkOrigin) {
64
63
  this.#manifest.middleware = sequence(
65
64
  createOriginCheckMiddleware(),
66
65
  this.#manifest.middleware
67
66
  );
68
67
  }
69
- return AppPipeline.create({
68
+ return AppPipeline.create(manifestData, {
70
69
  logger: this.#logger,
71
70
  manifest: this.#manifest,
72
71
  mode: "production",
@@ -106,15 +105,13 @@ class App {
106
105
  }
107
106
  match(request) {
108
107
  const url = new URL(request.url);
109
- if (this.#manifest.assets.has(url.pathname))
110
- return void 0;
108
+ if (this.#manifest.assets.has(url.pathname)) return void 0;
111
109
  let pathname = this.#computePathnameFromDomain(request);
112
110
  if (!pathname) {
113
111
  pathname = prependForwardSlash(this.removeBase(url.pathname));
114
112
  }
115
113
  let routeData = matchRoute(pathname, this.#manifestData);
116
- if (!routeData || routeData.prerender)
117
- return void 0;
114
+ if (!routeData || routeData.prerender) return void 0;
118
115
  return routeData;
119
116
  }
120
117
  #computePathnameFromDomain(request) {
@@ -210,7 +207,7 @@ class App {
210
207
  }
211
208
  const pathname = this.#getPathnameFromRequest(request);
212
209
  const defaultStatus = this.#getDefaultStatusCode(routeData, pathname);
213
- const mod = await this.#getModuleForRoute(routeData);
210
+ const mod = await this.#pipeline.getModuleForRoute(routeData);
214
211
  let response;
215
212
  try {
216
213
  const renderContext = RenderContext.create({
@@ -245,8 +242,7 @@ class App {
245
242
  return response;
246
243
  }
247
244
  #logRenderOptionsDeprecationWarning() {
248
- if (this.#renderOptionsDeprecationWarningShown)
249
- return;
245
+ if (this.#renderOptionsDeprecationWarningShown) return;
250
246
  this.#logger.warn(
251
247
  "deprecated",
252
248
  `The adapter ${this.#manifest.adapterName} is using a deprecated signature of the 'app.render()' method. From Astro 4.0, locals and routeData are provided as properties on an optional object to this method. Using the old signature will cause an error in Astro 5.0. See https://github.com/withastro/astro/pull/9199 for more information.`
@@ -287,7 +283,7 @@ class App {
287
283
  const override = { status };
288
284
  return this.#mergeResponses(response2, originalResponse, override);
289
285
  }
290
- const mod = await this.#getModuleForRoute(errorRouteData);
286
+ const mod = await this.#pipeline.getModuleForRoute(errorRouteData);
291
287
  try {
292
288
  const renderContext = RenderContext.create({
293
289
  locals,
@@ -354,41 +350,10 @@ class App {
354
350
  }
355
351
  }
356
352
  const route = removeTrailingForwardSlash(routeData.route);
357
- if (route.endsWith("/404"))
358
- return 404;
359
- if (route.endsWith("/500"))
360
- return 500;
353
+ if (route.endsWith("/404")) return 404;
354
+ if (route.endsWith("/500")) return 500;
361
355
  return 200;
362
356
  }
363
- async #getModuleForRoute(route) {
364
- if (route.component === DEFAULT_404_COMPONENT) {
365
- return {
366
- page: async () => ({ default: () => new Response(null, { status: 404 }) }),
367
- renderers: []
368
- };
369
- }
370
- if (route.type === "redirect") {
371
- return RedirectSinglePageBuiltModule;
372
- } else {
373
- if (this.#manifest.pageMap) {
374
- const importComponentInstance = this.#manifest.pageMap.get(route.component);
375
- if (!importComponentInstance) {
376
- throw new Error(
377
- `Unexpectedly unable to find a component instance for route ${route.route}`
378
- );
379
- }
380
- const pageModule = await importComponentInstance();
381
- return pageModule;
382
- } else if (this.#manifest.pageModule) {
383
- const importComponentInstance = this.#manifest.pageModule;
384
- return importComponentInstance;
385
- } else {
386
- throw new Error(
387
- "Astro couldn't find the correct page to render, probably because it wasn't correctly mapped for SSR usage. This is an internal error, please file an issue."
388
- );
389
- }
390
- }
391
- }
392
357
  }
393
358
  export {
394
359
  App,
@@ -36,7 +36,9 @@ class NodeApp extends App {
36
36
  const protocol = req.headers["x-forwarded-proto"] ?? ("encrypted" in req.socket && req.socket.encrypted ? "https" : "http");
37
37
  const hostname = req.headers["x-forwarded-host"] ?? req.headers.host ?? req.headers[":authority"];
38
38
  const port = req.headers["x-forwarded-port"];
39
- const url = `${protocol}://${hostname}${port ? `:${port}` : ""}${req.url}`;
39
+ const portInHostname = typeof hostname === "string" && typeof port === "string" && hostname.endsWith(port);
40
+ const hostnamePort = portInHostname ? hostname : hostname + (port ? `:${port}` : "");
41
+ const url = `${protocol}://${hostnamePort}${req.url}`;
40
42
  const options = {
41
43
  method: req.method || "GET",
42
44
  headers: makeRequestHeaders(req)
@@ -69,8 +71,7 @@ class NodeApp extends App {
69
71
  static async writeResponse(source, destination) {
70
72
  const { status, headers, body } = source;
71
73
  destination.writeHead(status, createOutgoingHttpHeaders(headers));
72
- if (!body)
73
- return destination.end();
74
+ if (!body) return destination.end();
74
75
  try {
75
76
  const reader = body.getReader();
76
77
  destination.on("close", () => {
@@ -1,7 +1,12 @@
1
- import type { RouteData, SSRResult } from '../../@types/astro.js';
1
+ import type { ComponentInstance, ManifestData, RewritePayload, RouteData, SSRResult } from '../../@types/astro.js';
2
2
  import { Pipeline } from '../base-pipeline.js';
3
+ import type { SinglePageBuiltModule } from '../build/types.js';
3
4
  export declare class AppPipeline extends Pipeline {
4
- static create({ logger, manifest, mode, renderers, resolve, serverLike, streaming, }: Pick<AppPipeline, 'logger' | 'manifest' | 'mode' | 'renderers' | 'resolve' | 'serverLike' | 'streaming'>): AppPipeline;
5
+ #private;
6
+ static create(manifestData: ManifestData, { logger, manifest, mode, renderers, resolve, serverLike, streaming, }: Pick<AppPipeline, 'logger' | 'manifest' | 'mode' | 'renderers' | 'resolve' | 'serverLike' | 'streaming'>): AppPipeline;
5
7
  headElements(routeData: RouteData): Pick<SSRResult, 'scripts' | 'styles' | 'links'>;
6
8
  componentMetadata(): void;
9
+ getComponentByRoute(routeData: RouteData): Promise<ComponentInstance>;
10
+ tryRewrite(payload: RewritePayload): Promise<[RouteData, ComponentInstance]>;
11
+ getModuleForRoute(route: RouteData): Promise<SinglePageBuiltModule>;
7
12
  }
@@ -1,7 +1,10 @@
1
1
  import { Pipeline } from "../base-pipeline.js";
2
+ import { DEFAULT_404_COMPONENT } from "../constants.js";
3
+ import { RedirectSinglePageBuiltModule } from "../redirects/component.js";
2
4
  import { createModuleScriptElement, createStylesheetElementSet } from "../render/ssr-element.js";
3
5
  class AppPipeline extends Pipeline {
4
- static create({
6
+ #manifestData;
7
+ static create(manifestData, {
5
8
  logger,
6
9
  manifest,
7
10
  mode,
@@ -10,7 +13,17 @@ class AppPipeline extends Pipeline {
10
13
  serverLike,
11
14
  streaming
12
15
  }) {
13
- return new AppPipeline(logger, manifest, mode, renderers, resolve, serverLike, streaming);
16
+ const pipeline = new AppPipeline(
17
+ logger,
18
+ manifest,
19
+ mode,
20
+ renderers,
21
+ resolve,
22
+ serverLike,
23
+ streaming
24
+ );
25
+ pipeline.#manifestData = manifestData;
26
+ return pipeline;
14
27
  }
15
28
  headElements(routeData) {
16
29
  const routeInfo = this.manifest.routes.find((route) => route.routeData === routeData);
@@ -33,6 +46,61 @@ class AppPipeline extends Pipeline {
33
46
  }
34
47
  componentMetadata() {
35
48
  }
49
+ async getComponentByRoute(routeData) {
50
+ const module = await this.getModuleForRoute(routeData);
51
+ return module.page();
52
+ }
53
+ async tryRewrite(payload) {
54
+ let foundRoute;
55
+ for (const route of this.#manifestData.routes) {
56
+ if (payload instanceof URL) {
57
+ if (route.pattern.test(payload.pathname)) {
58
+ foundRoute = route;
59
+ break;
60
+ }
61
+ } else if (payload instanceof Request) {
62
+ const url = new URL(payload.url);
63
+ if (route.pattern.test(url.pathname)) {
64
+ foundRoute = route;
65
+ break;
66
+ }
67
+ } else if (route.pattern.test(decodeURI(payload))) {
68
+ foundRoute = route;
69
+ break;
70
+ }
71
+ }
72
+ if (foundRoute) {
73
+ const componentInstance = await this.getComponentByRoute(foundRoute);
74
+ return [foundRoute, componentInstance];
75
+ }
76
+ throw new Error("Route not found");
77
+ }
78
+ async getModuleForRoute(route) {
79
+ if (route.component === DEFAULT_404_COMPONENT) {
80
+ return {
81
+ page: async () => ({ default: () => new Response(null, { status: 404 }) }),
82
+ renderers: []
83
+ };
84
+ }
85
+ if (route.type === "redirect") {
86
+ return RedirectSinglePageBuiltModule;
87
+ } else {
88
+ if (this.manifest.pageMap) {
89
+ const importComponentInstance = this.manifest.pageMap.get(route.component);
90
+ if (!importComponentInstance) {
91
+ throw new Error(
92
+ `Unexpectedly unable to find a component instance for route ${route.route}`
93
+ );
94
+ }
95
+ return await importComponentInstance();
96
+ } else if (this.manifest.pageModule) {
97
+ return this.manifest.pageModule;
98
+ }
99
+ throw new Error(
100
+ "Astro couldn't find the correct page to render, probably because it wasn't correctly mapped for SSR usage. This is an internal error, please file an issue."
101
+ );
102
+ }
103
+ }
36
104
  }
37
105
  export {
38
106
  AppPipeline
@@ -52,6 +52,7 @@ export type SSRManifest = {
52
52
  i18n: SSRManifestI18n | undefined;
53
53
  middleware: MiddlewareHandler;
54
54
  checkOrigin: boolean;
55
+ rewritingEnabled: boolean;
55
56
  };
56
57
  export type SSRManifestI18n = {
57
58
  fallback: Record<string, string> | undefined;
@@ -1,4 +1,4 @@
1
- import type { MiddlewareHandler, RouteData, RuntimeMode, SSRLoadedRenderer, SSRManifest, SSRResult } from '../@types/astro.js';
1
+ import type { ComponentInstance, MiddlewareHandler, RewritePayload, RouteData, RuntimeMode, SSRLoadedRenderer, SSRManifest, SSRResult } from '../@types/astro.js';
2
2
  import type { Logger } from './logger/core.js';
3
3
  import { RouteCache } from './render/route-cache.js';
4
4
  /**
@@ -55,6 +55,21 @@ export declare abstract class Pipeline {
55
55
  site?: URL | undefined);
56
56
  abstract headElements(routeData: RouteData): Promise<HeadElements> | HeadElements;
57
57
  abstract componentMetadata(routeData: RouteData): Promise<SSRResult['componentMetadata']> | void;
58
+ /**
59
+ * It attempts to retrieve the `RouteData` that matches the input `url`, and the component that belongs to the `RouteData`.
60
+ *
61
+ * ## Errors
62
+ *
63
+ * - if not `RouteData` is found
64
+ *
65
+ * @param {RewritePayload} rewritePayload
66
+ */
67
+ abstract tryRewrite(rewritePayload: RewritePayload): Promise<[RouteData, ComponentInstance]>;
68
+ /**
69
+ * Tells the pipeline how to retrieve a component give a `RouteData`
70
+ * @param routeData
71
+ */
72
+ abstract getComponentByRoute(routeData: RouteData): Promise<ComponentInstance>;
58
73
  }
59
74
  export interface HeadElements extends Pick<SSRResult, 'scripts' | 'styles' | 'links'> {
60
75
  }