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
@@ -1,21 +1,21 @@
1
- import { getOutputDirectory, isServerLikeOutput } from "../../prerender/utils.js";
1
+ import { getOutputDirectory } from "../../prerender/utils.js";
2
2
  import { BEFORE_HYDRATION_SCRIPT_ID, PAGE_SCRIPT_ID } from "../../vite-plugin-scripts/index.js";
3
+ import { RouteNotFound } from "../errors/errors-data.js";
4
+ import { AstroError } from "../errors/index.js";
3
5
  import { routeIsFallback, routeIsRedirect } from "../redirects/helpers.js";
6
+ import { RedirectSinglePageBuiltModule } from "../redirects/index.js";
4
7
  import { Pipeline } from "../render/index.js";
5
8
  import {
6
9
  createAssetLink,
7
10
  createModuleScriptsSet,
8
11
  createStylesheetElementSet
9
12
  } from "../render/ssr-element.js";
10
- import {
11
- cssOrder,
12
- getPageDataByComponent,
13
- mergeInlineCss
14
- } from "./internal.js";
13
+ import { isServerLikeOutput } from "../util.js";
14
+ import { getOutDirWithinCwd } from "./common.js";
15
+ import { cssOrder, getPageData, mergeInlineCss } from "./internal.js";
15
16
  import { ASTRO_PAGE_MODULE_ID, ASTRO_PAGE_RESOLVED_MODULE_ID } from "./plugins/plugin-pages.js";
16
17
  import { RESOLVED_SPLIT_MODULE_ID } from "./plugins/plugin-ssr.js";
17
- import { getVirtualModulePageNameFromPath } from "./plugins/util.js";
18
- import { ASTRO_PAGE_EXTENSION_POST_PATTERN } from "./plugins/util.js";
18
+ import { getPagesFromVirtualModulePageName, getVirtualModulePageName } from "./plugins/util.js";
19
19
  import { i18nHasFallback } from "./util.js";
20
20
  class BuildPipeline extends Pipeline {
21
21
  constructor(internals, manifest, options, config = options.settings.config, settings = options.settings) {
@@ -53,6 +53,16 @@ class BuildPipeline extends Pipeline {
53
53
  this.config = config;
54
54
  this.settings = settings;
55
55
  }
56
+ #componentsInterner = /* @__PURE__ */ new WeakMap();
57
+ /**
58
+ * This cache is needed to map a single `RouteData` to its file path.
59
+ * @private
60
+ */
61
+ #routesByFilePath = /* @__PURE__ */ new WeakMap();
62
+ get outFolder() {
63
+ const ssr = isServerLikeOutput(this.settings.config);
64
+ return ssr ? this.settings.config.build.server : getOutDirWithinCwd(this.settings.config.outDir);
65
+ }
56
66
  static create({
57
67
  internals,
58
68
  manifest,
@@ -107,7 +117,7 @@ class BuildPipeline extends Pipeline {
107
117
  settings
108
118
  } = this;
109
119
  const links = /* @__PURE__ */ new Set();
110
- const pageBuildData = getPageDataByComponent(internals, routeData.component);
120
+ const pageBuildData = getPageData(internals, routeData.route, routeData.component);
111
121
  const scripts = createModuleScriptsSet(
112
122
  pageBuildData?.hoistedScript ? [pageBuildData.hoistedScript] : [],
113
123
  base,
@@ -140,38 +150,139 @@ class BuildPipeline extends Pipeline {
140
150
  }
141
151
  /**
142
152
  * It collects the routes to generate during the build.
143
- *
144
153
  * It returns a map of page information and their relative entry point as a string.
145
154
  */
146
155
  retrieveRoutesToGenerate() {
147
156
  const pages = /* @__PURE__ */ new Map();
148
- for (const [entrypoint, filePath] of this.internals.entrySpecifierToBundleMap) {
149
- if (entrypoint.includes(ASTRO_PAGE_RESOLVED_MODULE_ID) || entrypoint.includes(RESOLVED_SPLIT_MODULE_ID)) {
150
- const [, pageName] = entrypoint.split(":");
151
- const pageData = this.internals.pagesByComponent.get(
152
- `${pageName.replace(ASTRO_PAGE_EXTENSION_POST_PATTERN, ".")}`
153
- );
154
- if (!pageData) {
155
- throw new Error(
156
- "Build failed. Astro couldn't find the emitted page from " + pageName + " pattern"
157
+ for (const [virtualModulePageName, filePath] of this.internals.entrySpecifierToBundleMap) {
158
+ if (virtualModulePageName.includes(ASTRO_PAGE_RESOLVED_MODULE_ID) || virtualModulePageName.includes(RESOLVED_SPLIT_MODULE_ID)) {
159
+ let pageDatas = [];
160
+ if (virtualModulePageName.includes(ASTRO_PAGE_RESOLVED_MODULE_ID)) {
161
+ pageDatas.push(
162
+ ...getPagesFromVirtualModulePageName(
163
+ this.internals,
164
+ ASTRO_PAGE_RESOLVED_MODULE_ID,
165
+ virtualModulePageName
166
+ )
167
+ );
168
+ }
169
+ if (virtualModulePageName.includes(RESOLVED_SPLIT_MODULE_ID)) {
170
+ pageDatas.push(
171
+ ...getPagesFromVirtualModulePageName(
172
+ this.internals,
173
+ RESOLVED_SPLIT_MODULE_ID,
174
+ virtualModulePageName
175
+ )
157
176
  );
158
177
  }
159
- pages.set(pageData, filePath);
178
+ for (const pageData of pageDatas) {
179
+ pages.set(pageData, filePath);
180
+ }
160
181
  }
161
182
  }
162
- for (const [path, pageData] of this.internals.pagesByComponent.entries()) {
183
+ for (const pageData of this.internals.pagesByKeys.values()) {
163
184
  if (routeIsRedirect(pageData.route)) {
164
- pages.set(pageData, path);
185
+ pages.set(pageData, pageData.component);
165
186
  } else if (routeIsFallback(pageData.route) && (i18nHasFallback(this.config) || routeIsFallback(pageData.route) && pageData.route.route === "/")) {
166
- const moduleSpecifier = getVirtualModulePageNameFromPath(ASTRO_PAGE_MODULE_ID, path);
187
+ const moduleSpecifier = getVirtualModulePageName(ASTRO_PAGE_MODULE_ID, pageData.component);
167
188
  const filePath = this.internals.entrySpecifierToBundleMap.get(moduleSpecifier);
168
189
  if (filePath) {
169
190
  pages.set(pageData, filePath);
170
191
  }
171
192
  }
172
193
  }
194
+ for (const [buildData, filePath] of pages.entries()) {
195
+ this.#routesByFilePath.set(buildData.route, filePath);
196
+ }
173
197
  return pages;
174
198
  }
199
+ async getComponentByRoute(routeData) {
200
+ if (this.#componentsInterner.has(routeData)) {
201
+ const entry = this.#componentsInterner.get(routeData);
202
+ return await entry.page();
203
+ } else {
204
+ const filePath = this.#routesByFilePath.get(routeData);
205
+ const module = await this.retrieveSsrEntry(routeData, filePath);
206
+ return module.page();
207
+ }
208
+ }
209
+ async tryRewrite(payload) {
210
+ let foundRoute;
211
+ for (const route of this.options.manifest.routes) {
212
+ if (payload instanceof URL) {
213
+ if (route.pattern.test(payload.pathname)) {
214
+ foundRoute = route;
215
+ break;
216
+ }
217
+ } else if (payload instanceof Request) {
218
+ const url = new URL(payload.url);
219
+ if (route.pattern.test(url.pathname)) {
220
+ foundRoute = route;
221
+ break;
222
+ }
223
+ } else if (route.pattern.test(decodeURI(payload))) {
224
+ foundRoute = route;
225
+ break;
226
+ }
227
+ }
228
+ if (foundRoute) {
229
+ const componentInstance = await this.getComponentByRoute(foundRoute);
230
+ return [foundRoute, componentInstance];
231
+ } else {
232
+ throw new AstroError(RouteNotFound);
233
+ }
234
+ }
235
+ async retrieveSsrEntry(route, filePath) {
236
+ if (this.#componentsInterner.has(route)) {
237
+ return this.#componentsInterner.get(route);
238
+ }
239
+ let entry;
240
+ if (routeIsRedirect(route)) {
241
+ entry = await this.#getEntryForRedirectRoute(route, this.internals, this.outFolder);
242
+ } else if (routeIsFallback(route)) {
243
+ entry = await this.#getEntryForFallbackRoute(route, this.internals, this.outFolder);
244
+ } else {
245
+ const ssrEntryURLPage = createEntryURL(filePath, this.outFolder);
246
+ entry = await import(ssrEntryURLPage.toString());
247
+ }
248
+ this.#componentsInterner.set(route, entry);
249
+ return entry;
250
+ }
251
+ async #getEntryForFallbackRoute(route, internals, outFolder) {
252
+ if (route.type !== "fallback") {
253
+ throw new Error(`Expected a redirect route.`);
254
+ }
255
+ if (route.redirectRoute) {
256
+ const filePath = getEntryFilePath(this.internals, route.redirectRoute);
257
+ if (filePath) {
258
+ const url = createEntryURL(filePath, outFolder);
259
+ const ssrEntryPage = await import(url.toString());
260
+ return ssrEntryPage;
261
+ }
262
+ }
263
+ return RedirectSinglePageBuiltModule;
264
+ }
265
+ async #getEntryForRedirectRoute(route, internals, outFolder) {
266
+ if (route.type !== "redirect") {
267
+ throw new Error(`Expected a redirect route.`);
268
+ }
269
+ if (route.redirectRoute) {
270
+ const filePath = getEntryFilePath(this.internals, route.redirectRoute);
271
+ if (filePath) {
272
+ const url = createEntryURL(filePath, outFolder);
273
+ const ssrEntryPage = await import(url.toString());
274
+ return ssrEntryPage;
275
+ }
276
+ }
277
+ return RedirectSinglePageBuiltModule;
278
+ }
279
+ }
280
+ function createEntryURL(filePath, outFolder) {
281
+ return new URL("./" + filePath + `?time=${Date.now()}`, outFolder);
282
+ }
283
+ function getEntryFilePath(internals, pageData) {
284
+ const id = "\0" + getVirtualModulePageName(ASTRO_PAGE_MODULE_ID, pageData.component);
285
+ return internals.entrySpecifierToBundleMap.get(id);
175
286
  }
176
287
  export {
177
288
  BuildPipeline
@@ -27,29 +27,12 @@ function vitePluginAnalyzer(options, internals) {
27
27
  if (hoistedScripts.size) {
28
28
  for (const parentInfo of getParentModuleInfos(from, this, isPropagatedAsset)) {
29
29
  if (isPropagatedAsset(parentInfo.id)) {
30
- for (const nestedParentInfo of getParentModuleInfos(from, this)) {
31
- if (moduleIsTopLevelPage(nestedParentInfo)) {
32
- for (const hid of hoistedScripts) {
33
- if (!pageScripts.has(nestedParentInfo.id)) {
34
- pageScripts.set(nestedParentInfo.id, {
35
- hoistedSet: /* @__PURE__ */ new Set(),
36
- propagatedMapByImporter: /* @__PURE__ */ new Map()
37
- });
38
- }
39
- const entry = pageScripts.get(nestedParentInfo.id);
40
- if (!entry.propagatedMapByImporter.has(parentInfo.id)) {
41
- entry.propagatedMapByImporter.set(parentInfo.id, /* @__PURE__ */ new Set());
42
- }
43
- entry.propagatedMapByImporter.get(parentInfo.id).add(hid);
44
- }
45
- }
46
- }
30
+ internals.propagatedScriptsMap.set(parentInfo.id, hoistedScripts);
47
31
  } else if (moduleIsTopLevelPage(parentInfo)) {
48
32
  for (const hid of hoistedScripts) {
49
33
  if (!pageScripts.has(parentInfo.id)) {
50
34
  pageScripts.set(parentInfo.id, {
51
- hoistedSet: /* @__PURE__ */ new Set(),
52
- propagatedMapByImporter: /* @__PURE__ */ new Map()
35
+ hoistedSet: /* @__PURE__ */ new Set()
53
36
  });
54
37
  }
55
38
  pageScripts.get(parentInfo.id)?.hoistedSet.add(hid);
@@ -59,10 +42,14 @@ function vitePluginAnalyzer(options, internals) {
59
42
  }
60
43
  },
61
44
  finalize() {
62
- for (const [pageId, { hoistedSet, propagatedMapByImporter }] of pageScripts) {
45
+ for (const propagatedScripts of internals.propagatedScriptsMap.values()) {
46
+ for (const propagatedScript of propagatedScripts) {
47
+ internals.discoveredScripts.add(propagatedScript);
48
+ }
49
+ }
50
+ for (const [pageId, { hoistedSet }] of pageScripts) {
63
51
  const pageData = getPageDataByViteID(internals, pageId);
64
- if (!pageData)
65
- continue;
52
+ if (!pageData) continue;
66
53
  const { component } = pageData;
67
54
  const astroModuleId = prependForwardSlash(component);
68
55
  const uniqueHoistedId = JSON.stringify(Array.from(hoistedSet).sort());
@@ -74,12 +61,6 @@ function vitePluginAnalyzer(options, internals) {
74
61
  uniqueHoistedIds.set(uniqueHoistedId, moduleId);
75
62
  }
76
63
  internals.discoveredScripts.add(moduleId);
77
- pageData.propagatedScripts = propagatedMapByImporter;
78
- for (const propagatedScripts of propagatedMapByImporter.values()) {
79
- for (const propagatedScript of propagatedScripts) {
80
- internals.discoveredScripts.add(propagatedScript);
81
- }
82
- }
83
64
  if (internals.hoistedScriptIdToPagesMap.has(moduleId)) {
84
65
  const pages = internals.hoistedScriptIdToPagesMap.get(moduleId);
85
66
  pages.add(astroModuleId);
@@ -100,8 +81,7 @@ function vitePluginAnalyzer(options, internals) {
100
81
  const ids = this.getModuleIds();
101
82
  for (const id of ids) {
102
83
  const info = this.getModuleInfo(id);
103
- if (!info?.meta?.astro)
104
- continue;
84
+ if (!info?.meta?.astro) continue;
105
85
  const astro = info.meta.astro;
106
86
  const pageData = getPageDataByViteID(internals, id);
107
87
  if (pageData) {
@@ -135,8 +115,7 @@ function vitePluginAnalyzer(options, internals) {
135
115
  }
136
116
  for (const pageInfo of getTopLevelPageModuleInfos(id, this)) {
137
117
  const newPageData = getPageDataByViteID(internals, pageInfo.id);
138
- if (!newPageData)
139
- continue;
118
+ if (!newPageData) continue;
140
119
  trackClientOnlyPageDatas(internals, newPageData, clientOnlys);
141
120
  }
142
121
  }
@@ -1,4 +1,5 @@
1
1
  import { type BuildInternals } from '../internal.js';
2
2
  import type { AstroBuildPlugin } from '../plugin.js';
3
3
  import type { StaticBuildOptions } from '../types.js';
4
+ export declare function copyContentToCache(opts: StaticBuildOptions): Promise<void>;
4
5
  export declare function pluginContent(opts: StaticBuildOptions, internals: BuildInternals): AstroBuildPlugin;
@@ -9,7 +9,6 @@ import {
9
9
  generateContentEntryFile,
10
10
  generateLookupMap
11
11
  } from "../../../content/vite-plugin-content-virtual-mod.js";
12
- import { isServerLikeOutput } from "../../../prerender/utils.js";
13
12
  import { configPaths } from "../../config/index.js";
14
13
  import { emptyDir } from "../../fs/index.js";
15
14
  import {
@@ -18,6 +17,7 @@ import {
18
17
  removeFileExtension,
19
18
  removeLeadingForwardSlash
20
19
  } from "../../path.js";
20
+ import { isContentCollectionsCacheEnabled } from "../../util.js";
21
21
  import { addRollupInput } from "../add-rollup-input.js";
22
22
  import { CHUNKS_PATH } from "../consts.js";
23
23
  import {} from "../internal.js";
@@ -40,14 +40,14 @@ function createContentManifest() {
40
40
  configs: ""
41
41
  };
42
42
  }
43
+ const getContentRoot = (config) => new URL("./content/", config.outDir);
44
+ const getContentCacheDir = (config) => new URL(CONTENT_CACHE_DIR, config.cacheDir);
45
+ const getCacheTmp = (contentCacheDir) => new URL("./.tmp/", contentCacheDir);
43
46
  function vitePluginContent(opts, lookupMap, internals, cachedBuildOutput) {
44
47
  const { config } = opts.settings;
45
- const { cacheDir } = config;
46
- const distRoot = config.outDir;
47
- const distContentRoot = new URL("./content/", distRoot);
48
- const contentCacheDir = new URL(CONTENT_CACHE_DIR, cacheDir);
48
+ const distContentRoot = getContentRoot(config);
49
+ const contentCacheDir = getContentCacheDir(config);
49
50
  const contentManifestFile = new URL(CONTENT_MANIFEST_FILE, contentCacheDir);
50
- const cacheTmp = new URL("./.tmp/", contentCacheDir);
51
51
  let oldManifest = createContentManifest();
52
52
  let newManifest = createContentManifest();
53
53
  let entries;
@@ -105,6 +105,10 @@ function vitePluginContent(opts, lookupMap, internals, cachedBuildOutput) {
105
105
  await copyFiles(cached, dist, true);
106
106
  }
107
107
  }
108
+ const cacheExists = fsMod.existsSync(contentCacheDir);
109
+ if (cacheExists) {
110
+ await copyFiles(contentCacheDir, distContentRoot, false);
111
+ }
108
112
  }
109
113
  if (entries.buildFromSource.length === 0) {
110
114
  newOptions = addRollupInput(newOptions, [virtualEmptyModuleId]);
@@ -115,6 +119,7 @@ function vitePluginContent(opts, lookupMap, internals, cachedBuildOutput) {
115
119
  outputOptions(outputOptions) {
116
120
  const rootPath = normalizePath(fileURLToPath(opts.settings.config.root));
117
121
  const srcPath = normalizePath(fileURLToPath(opts.settings.config.srcDir));
122
+ const entryCache = /* @__PURE__ */ new Map();
118
123
  extendManualChunks(outputOptions, {
119
124
  before(id, meta) {
120
125
  if (id.startsWith(srcPath) && id.slice(srcPath.length).startsWith("content")) {
@@ -127,7 +132,11 @@ function vitePluginContent(opts, lookupMap, internals, cachedBuildOutput) {
127
132
  return resultId;
128
133
  }
129
134
  const [srcRelativePath, flag] = id.replace(rootPath, "/").split("?");
130
- const collectionEntry = findEntryFromSrcRelativePath(lookupMap, srcRelativePath);
135
+ const collectionEntry = findEntryFromSrcRelativePath(
136
+ lookupMap,
137
+ srcRelativePath,
138
+ entryCache
139
+ );
131
140
  if (collectionEntry) {
132
141
  let suffix = ".mjs";
133
142
  if (flag === PROPAGATED_ASSET_FLAG) {
@@ -169,12 +178,10 @@ export default {}`
169
178
  code,
170
179
  fileName: "content/entry.mjs"
171
180
  });
172
- if (!injectedEmptyFile)
173
- return;
181
+ if (!injectedEmptyFile) return;
174
182
  Object.keys(bundle).forEach((key) => {
175
183
  const mod = bundle[key];
176
- if (mod.type === "asset")
177
- return;
184
+ if (mod.type === "asset") return;
178
185
  if (mod.facadeModuleId === resolvedVirtualEmptyModuleId) {
179
186
  delete bundle[key];
180
187
  }
@@ -184,8 +191,7 @@ export default {}`
184
191
  const clientComponents = /* @__PURE__ */ new Set([
185
192
  ...oldManifest.clientEntries,
186
193
  ...internals.discoveredHydratedComponents.keys(),
187
- ...internals.discoveredClientOnlyComponents.keys(),
188
- ...internals.discoveredScripts
194
+ ...internals.discoveredClientOnlyComponents.keys()
189
195
  ]);
190
196
  const serverComponents = /* @__PURE__ */ new Set([
191
197
  ...oldManifest.serverEntries,
@@ -201,21 +207,12 @@ export default {}`
201
207
  await fsMod.promises.writeFile(contentManifestFile, JSON.stringify(newManifest), {
202
208
  encoding: "utf8"
203
209
  });
204
- await fsMod.promises.mkdir(cacheTmp, { recursive: true });
205
- await copyFiles(distContentRoot, cacheTmp, true);
206
- if (cacheExists && currentManifestState === "valid") {
207
- await copyFiles(contentCacheDir, distContentRoot, false);
208
- }
209
- await copyFiles(cacheTmp, contentCacheDir);
210
- await fsMod.promises.rm(cacheTmp, { recursive: true, force: true });
211
210
  }
212
211
  };
213
212
  }
214
- const entryCache = /* @__PURE__ */ new Map();
215
- function findEntryFromSrcRelativePath(lookupMap, srcRelativePath) {
213
+ function findEntryFromSrcRelativePath(lookupMap, srcRelativePath, entryCache) {
216
214
  let value = entryCache.get(srcRelativePath);
217
- if (value)
218
- return value;
215
+ if (value) return value;
219
216
  for (const collection of Object.values(lookupMap)) {
220
217
  for (const entry of Object.values(collection)) {
221
218
  for (const entryFile of Object.values(entry)) {
@@ -335,6 +332,16 @@ function collectionTypeToFlag(type) {
335
332
  const name = type[0].toUpperCase() + type.slice(1);
336
333
  return `astro${name}CollectionEntry`;
337
334
  }
335
+ async function copyContentToCache(opts) {
336
+ const { config } = opts.settings;
337
+ const distContentRoot = getContentRoot(config);
338
+ const contentCacheDir = getContentCacheDir(config);
339
+ const cacheTmp = getCacheTmp(contentCacheDir);
340
+ await fsMod.promises.mkdir(cacheTmp, { recursive: true });
341
+ await copyFiles(distContentRoot, cacheTmp, true);
342
+ await copyFiles(cacheTmp, contentCacheDir);
343
+ await fsMod.promises.rm(cacheTmp, { recursive: true, force: true });
344
+ }
338
345
  function pluginContent(opts, internals) {
339
346
  const { cacheDir, outDir } = opts.settings.config;
340
347
  const chunksFolder = "./" + CHUNKS_PATH;
@@ -347,10 +354,7 @@ function pluginContent(opts, internals) {
347
354
  targets: ["server"],
348
355
  hooks: {
349
356
  async "build:before"() {
350
- if (!opts.settings.config.experimental.contentCollectionCache) {
351
- return { vitePlugin: void 0 };
352
- }
353
- if (isServerLikeOutput(opts.settings.config)) {
357
+ if (!isContentCollectionsCacheEnabled(opts.settings.config)) {
354
358
  return { vitePlugin: void 0 };
355
359
  }
356
360
  const lookupMap = await generateLookupMap({ settings: opts.settings, fs: fsMod });
@@ -359,10 +363,7 @@ function pluginContent(opts, internals) {
359
363
  };
360
364
  },
361
365
  async "build:post"() {
362
- if (!opts.settings.config.experimental.contentCollectionCache) {
363
- return;
364
- }
365
- if (isServerLikeOutput(opts.settings.config)) {
366
+ if (!isContentCollectionsCacheEnabled(opts.settings.config)) {
366
367
  return;
367
368
  }
368
369
  for (const { cached, dist } of cachedBuildOutput) {
@@ -375,5 +376,6 @@ function pluginContent(opts, internals) {
375
376
  };
376
377
  }
377
378
  export {
379
+ copyContentToCache,
378
380
  pluginContent
379
381
  };
@@ -1,5 +1,4 @@
1
1
  import { isBuildableCSSRequest } from "../../../vite-plugin-astro-server/util.js";
2
- import { RESOLVED_VIRTUAL_MODULE_ID as ASTRO_CONTENT_VIRTUAL_MODULE_ID } from "../../../content/consts.js";
3
2
  import { hasAssetPropagationFlag } from "../../../content/index.js";
4
3
  import * as assetName from "../css-asset-name.js";
5
4
  import {
@@ -8,11 +7,9 @@ import {
8
7
  moduleIsTopLevelPage
9
8
  } from "../graph.js";
10
9
  import {
11
- eachPageData,
12
10
  getPageDataByViteID,
13
11
  getPageDatasByClientOnlyID,
14
- getPageDatasByHoistedScriptId,
15
- isHoistedScript
12
+ getPageDatasByHoistedScriptId
16
13
  } from "../internal.js";
17
14
  import { extendManualChunks, shouldInlineAsset } from "./util.js";
18
15
  function pluginCSS(options, internals) {
@@ -37,8 +34,7 @@ function rollupPluginAstroBuildCSS(options) {
37
34
  const { settings } = buildOptions;
38
35
  let resolvedConfig;
39
36
  const pagesToCss = {};
40
- const pagesToPropagatedCss = {};
41
- const isContentCollectionCache = options.buildOptions.settings.config.output === "static" && options.buildOptions.settings.config.experimental.contentCollectionCache;
37
+ const moduleIdToPropagatedCss = {};
42
38
  const cssBuildPlugin = {
43
39
  name: "astro:rollup-plugin-build-css",
44
40
  outputOptions(outputOptions) {
@@ -68,13 +64,10 @@ function rollupPluginAstroBuildCSS(options) {
68
64
  },
69
65
  async generateBundle(_outputOptions, bundle) {
70
66
  for (const [, chunk] of Object.entries(bundle)) {
71
- if (chunk.type !== "chunk")
72
- continue;
73
- if ("viteMetadata" in chunk === false)
74
- continue;
67
+ if (chunk.type !== "chunk") continue;
68
+ if ("viteMetadata" in chunk === false) continue;
75
69
  const meta = chunk.viteMetadata;
76
- if (meta.importedCss.size < 1)
77
- continue;
70
+ if (meta.importedCss.size < 1) continue;
78
71
  if (options.target === "client") {
79
72
  for (const id of Object.keys(chunk.modules)) {
80
73
  for (const pageData of getParentClientOnlys(id, this, internals)) {
@@ -89,19 +82,9 @@ function rollupPluginAstroBuildCSS(options) {
89
82
  const parentModuleInfos = getParentExtendedModuleInfos(id, this, hasAssetPropagationFlag);
90
83
  for (const { info: pageInfo, depth, order } of parentModuleInfos) {
91
84
  if (hasAssetPropagationFlag(pageInfo.id)) {
92
- const walkId = isContentCollectionCache ? ASTRO_CONTENT_VIRTUAL_MODULE_ID : id;
93
- for (const parentInfo of getParentModuleInfos(walkId, this)) {
94
- if (moduleIsTopLevelPage(parentInfo) === false)
95
- continue;
96
- const pageViteID = parentInfo.id;
97
- const pageData = getPageDataByViteID(internals, pageViteID);
98
- if (pageData === void 0)
99
- continue;
100
- for (const css of meta.importedCss) {
101
- const propagatedStyles = pagesToPropagatedCss[pageData.moduleSpecifier] ??= {};
102
- const existingCss = propagatedStyles[pageInfo.id] ??= /* @__PURE__ */ new Set();
103
- existingCss.add(css);
104
- }
85
+ const propagatedCss = moduleIdToPropagatedCss[pageInfo.id] ??= /* @__PURE__ */ new Set();
86
+ for (const css of meta.importedCss) {
87
+ propagatedCss.add(css);
105
88
  }
106
89
  } else if (moduleIsTopLevelPage(pageInfo)) {
107
90
  const pageViteID = pageInfo.id;
@@ -109,7 +92,7 @@ function rollupPluginAstroBuildCSS(options) {
109
92
  if (pageData) {
110
93
  appendCSSToPage(pageData, meta, pagesToCss, depth, order);
111
94
  }
112
- } else if (options.target === "client" && isHoistedScript(internals, pageInfo.id)) {
95
+ } else if (options.target === "client" && internals.hoistedScriptIdToPagesMap.has(pageInfo.id)) {
113
96
  for (const pageData of getPageDatasByHoistedScriptId(internals, pageInfo.id)) {
114
97
  appendCSSToPage(pageData, meta, pagesToCss, -1, order);
115
98
  }
@@ -142,14 +125,12 @@ function rollupPluginAstroBuildCSS(options) {
142
125
  resolvedConfig = config;
143
126
  },
144
127
  generateBundle(_, bundle) {
145
- if (resolvedConfig.build.cssCodeSplit)
146
- return;
128
+ if (resolvedConfig.build.cssCodeSplit) return;
147
129
  const cssChunk = Object.values(bundle).find(
148
130
  (chunk) => chunk.type === "asset" && chunk.name === "style.css"
149
131
  );
150
- if (cssChunk === void 0)
151
- return;
152
- for (const pageData of eachPageData(internals)) {
132
+ if (cssChunk === void 0) return;
133
+ for (const pageData of internals.pagesByKeys.values()) {
153
134
  const cssToInfoMap = pagesToCss[pageData.moduleSpecifier] ??= {};
154
135
  cssToInfoMap[cssChunk.fileName] = { depth: -1, order: -1 };
155
136
  }
@@ -169,33 +150,24 @@ function rollupPluginAstroBuildCSS(options) {
169
150
  return;
170
151
  const toBeInlined = inlineConfig === "always" ? true : inlineConfig === "never" ? false : shouldInlineAsset(stylesheet.source, stylesheet.fileName, assetsInlineLimit);
171
152
  const sheet = toBeInlined ? { type: "inline", content: stylesheet.source } : { type: "external", src: stylesheet.fileName };
172
- const pages = Array.from(eachPageData(internals));
173
153
  let sheetAddedToPage = false;
174
- pages.forEach((pageData) => {
154
+ internals.pagesByKeys.forEach((pageData) => {
175
155
  const orderingInfo = pagesToCss[pageData.moduleSpecifier]?.[stylesheet.fileName];
176
156
  if (orderingInfo !== void 0) {
177
157
  pageData.styles.push({ ...orderingInfo, sheet });
178
158
  sheetAddedToPage = true;
179
- return;
180
159
  }
181
- const propagatedPaths = pagesToPropagatedCss[pageData.moduleSpecifier];
182
- if (propagatedPaths === void 0)
183
- return;
184
- Object.entries(propagatedPaths).forEach(([pageInfoId, css]) => {
185
- if (css.has(stylesheet.fileName) !== true)
186
- return;
187
- if (pageData.styles.some((s) => s.sheet === sheet))
188
- return;
189
- let propagatedStyles;
190
- if (isContentCollectionCache) {
191
- propagatedStyles = internals.propagatedStylesMap.get(pageInfoId) ?? internals.propagatedStylesMap.set(pageInfoId, /* @__PURE__ */ new Set()).get(pageInfoId);
192
- } else {
193
- propagatedStyles = pageData.propagatedStyles.get(pageInfoId) ?? pageData.propagatedStyles.set(pageInfoId, /* @__PURE__ */ new Set()).get(pageInfoId);
194
- }
195
- propagatedStyles.add(sheet);
196
- sheetAddedToPage = true;
197
- });
198
160
  });
161
+ for (const moduleId in moduleIdToPropagatedCss) {
162
+ if (!moduleIdToPropagatedCss[moduleId].has(stylesheet.fileName)) continue;
163
+ let propagatedStyles = internals.propagatedStylesMap.get(moduleId);
164
+ if (!propagatedStyles) {
165
+ propagatedStyles = /* @__PURE__ */ new Set();
166
+ internals.propagatedStylesMap.set(moduleId, propagatedStyles);
167
+ }
168
+ propagatedStyles.add(sheet);
169
+ sheetAddedToPage = true;
170
+ }
199
171
  if (toBeInlined && sheetAddedToPage) {
200
172
  delete bundle[id];
201
173
  for (const chunk of Object.values(bundle)) {
@@ -11,6 +11,7 @@ import { serializeRouteData } from "../../routing/index.js";
11
11
  import { addRollupInput } from "../add-rollup-input.js";
12
12
  import { getOutFile, getOutFolder } from "../common.js";
13
13
  import { cssOrder, mergeInlineCss } from "../internal.js";
14
+ import { makePageDataKey } from "./util.js";
14
15
  const manifestReplace = "@@ASTRO_MANIFEST_REPLACE@@";
15
16
  const replaceExp = new RegExp(`['"]${manifestReplace}['"]`, "g");
16
17
  const SSR_MANIFEST_VIRTUAL_MODULE_ID = "@astrojs-manifest";
@@ -128,10 +129,8 @@ function buildManifest(opts, internals, staticFiles) {
128
129
  }
129
130
  };
130
131
  for (const route of opts.manifest.routes) {
131
- if (!route.prerender)
132
- continue;
133
- if (!route.pathname)
134
- continue;
132
+ if (!route.prerender) continue;
133
+ if (!route.pathname) continue;
135
134
  const outFolder = getOutFolder(opts.settings.config, route.pathname, route);
136
135
  const outFile = getOutFile(opts.settings.config, outFolder, route.pathname, route);
137
136
  const file = outFile.toString().replace(opts.settings.config.build.client.toString(), "");
@@ -145,9 +144,8 @@ function buildManifest(opts, internals, staticFiles) {
145
144
  staticFiles.push(file);
146
145
  }
147
146
  for (const route of opts.manifest.routes) {
148
- const pageData = internals.pagesByComponent.get(route.component);
149
- if (route.prerender || !pageData)
150
- continue;
147
+ const pageData = internals.pagesByKeys.get(makePageDataKey(route.route, route.component));
148
+ if (route.prerender || !pageData) continue;
151
149
  const scripts = [];
152
150
  if (pageData.hoistedScript) {
153
151
  const shouldPrefixAssetPath = pageData.hoistedScript.type === "external";
@@ -214,7 +212,8 @@ function buildManifest(opts, internals, staticFiles) {
214
212
  assets: staticFiles.map(prefixAssetPath),
215
213
  i18n: i18nManifest,
216
214
  buildFormat: settings.config.build.format,
217
- checkOrigin: settings.config.experimental.security?.csrfProtection?.origin ?? false
215
+ checkOrigin: settings.config.experimental.security?.csrfProtection?.origin ?? false,
216
+ rewritingEnabled: settings.config.experimental.rewriting
218
217
  };
219
218
  }
220
219
  export {
@@ -3,5 +3,4 @@ import type { AstroBuildPlugin } from '../plugin.js';
3
3
  import type { StaticBuildOptions } from '../types.js';
4
4
  export declare const ASTRO_PAGE_MODULE_ID = "@astro-page:";
5
5
  export declare const ASTRO_PAGE_RESOLVED_MODULE_ID: string;
6
- export declare function getVirtualModulePageIdFromPath(path: string): string;
7
6
  export declare function pluginPages(opts: StaticBuildOptions, internals: BuildInternals): AstroBuildPlugin;