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
@@ -18,60 +18,24 @@ import {
18
18
  } from "../../core/path.js";
19
19
  import { toRoutingStrategy } from "../../i18n/utils.js";
20
20
  import { runHookBuildGenerated } from "../../integrations/hooks.js";
21
- import { getOutputDirectory, isServerLikeOutput } from "../../prerender/utils.js";
21
+ import { getOutputDirectory } from "../../prerender/utils.js";
22
22
  import { NoPrerenderedRoutesWithDomains } from "../errors/errors-data.js";
23
23
  import { AstroError, AstroErrorData } from "../errors/index.js";
24
- import { routeIsFallback } from "../redirects/helpers.js";
25
- import {
26
- RedirectSinglePageBuiltModule,
27
- getRedirectLocationOrThrow,
28
- routeIsRedirect
29
- } from "../redirects/index.js";
24
+ import { getRedirectLocationOrThrow, routeIsRedirect } from "../redirects/index.js";
30
25
  import { RenderContext } from "../render-context.js";
31
26
  import { callGetStaticPaths } from "../render/route-cache.js";
32
27
  import { createRequest } from "../request.js";
33
28
  import { matchRoute } from "../routing/match.js";
34
- import { getOutputFilename } from "../util.js";
29
+ import { getOutputFilename, isServerLikeOutput } from "../util.js";
35
30
  import { getOutDirWithinCwd, getOutFile, getOutFolder } from "./common.js";
36
- import {
37
- cssOrder,
38
- getEntryFilePathFromComponentPath,
39
- getPageDataByComponent,
40
- mergeInlineCss
41
- } from "./internal.js";
31
+ import { cssOrder, mergeInlineCss } from "./internal.js";
42
32
  import { BuildPipeline } from "./pipeline.js";
33
+ import { ASTRO_PAGE_MODULE_ID } from "./plugins/plugin-pages.js";
34
+ import { getVirtualModulePageName } from "./plugins/util.js";
43
35
  import { getTimeStat, shouldAppendForwardSlash } from "./util.js";
44
36
  function createEntryURL(filePath, outFolder) {
45
37
  return new URL("./" + filePath + `?time=${Date.now()}`, outFolder);
46
38
  }
47
- async function getEntryForRedirectRoute(route, internals, outFolder) {
48
- if (route.type !== "redirect") {
49
- throw new Error(`Expected a redirect route.`);
50
- }
51
- if (route.redirectRoute) {
52
- const filePath = getEntryFilePathFromComponentPath(internals, route.redirectRoute.component);
53
- if (filePath) {
54
- const url = createEntryURL(filePath, outFolder);
55
- const ssrEntryPage = await import(url.toString());
56
- return ssrEntryPage;
57
- }
58
- }
59
- return RedirectSinglePageBuiltModule;
60
- }
61
- async function getEntryForFallbackRoute(route, internals, outFolder) {
62
- if (route.type !== "fallback") {
63
- throw new Error(`Expected a redirect route.`);
64
- }
65
- if (route.redirectRoute) {
66
- const filePath = getEntryFilePathFromComponentPath(internals, route.redirectRoute.component);
67
- if (filePath) {
68
- const url = createEntryURL(filePath, outFolder);
69
- const ssrEntryPage = await import(url.toString());
70
- return ssrEntryPage;
71
- }
72
- }
73
- return RedirectSinglePageBuiltModule;
74
- }
75
39
  function rootRelativeFacadeId(facadeId, settings) {
76
40
  return facadeId.slice(fileURLToPath(settings.config.root).length);
77
41
  }
@@ -133,13 +97,13 @@ ${bgGreen(black(` ${verb} static routes `))}`);
133
97
  message: NoPrerenderedRoutesWithDomains.message(pageData.component)
134
98
  });
135
99
  }
136
- const ssrEntryURLPage = createEntryURL(filePath, outFolder);
137
- const ssrEntryPage = await import(ssrEntryURLPage.toString());
100
+ const ssrEntryPage = await pipeline.retrieveSsrEntry(pageData.route, filePath);
138
101
  if (options.settings.adapter?.adapterFeatures?.functionPerRoute) {
139
102
  const ssrEntry = ssrEntryPage?.pageModule;
140
103
  if (ssrEntry) {
141
104
  await generatePage(pageData, ssrEntry, builtPaths, pipeline);
142
105
  } else {
106
+ const ssrEntryURLPage = createEntryURL(filePath, outFolder);
143
107
  throw new Error(
144
108
  `Unable to find the manifest for the module ${ssrEntryURLPage.toString()}. This is unexpected and likely a bug in Astro, please report.`
145
109
  );
@@ -152,17 +116,8 @@ ${bgGreen(black(` ${verb} static routes `))}`);
152
116
  }
153
117
  } else {
154
118
  for (const [pageData, filePath] of pagesToGenerate) {
155
- if (routeIsRedirect(pageData.route)) {
156
- const entry = await getEntryForRedirectRoute(pageData.route, internals, outFolder);
157
- await generatePage(pageData, entry, builtPaths, pipeline);
158
- } else if (routeIsFallback(pageData.route)) {
159
- const entry = await getEntryForFallbackRoute(pageData.route, internals, outFolder);
160
- await generatePage(pageData, entry, builtPaths, pipeline);
161
- } else {
162
- const ssrEntryURLPage = createEntryURL(filePath, outFolder);
163
- const entry = await import(ssrEntryURLPage.toString());
164
- await generatePage(pageData, entry, builtPaths, pipeline);
165
- }
119
+ const entry = await pipeline.retrieveSsrEntry(pageData.route, filePath);
120
+ await generatePage(pageData, entry, builtPaths, pipeline);
166
121
  }
167
122
  }
168
123
  logger.info(
@@ -175,11 +130,11 @@ ${bgGreen(black(` ${verb} static routes `))}`);
175
130
  logger.info("SKIP_FORMAT", `${bgGreen(black(` generating optimized images `))}`);
176
131
  const totalCount = Array.from(staticImageList.values()).map((x) => x.transforms.size).reduce((a, b) => a + b, 0);
177
132
  const cpuCount = os.cpus().length;
178
- const assetsCreationpipeline = await prepareAssetsGenerationEnv(pipeline, totalCount);
133
+ const assetsCreationPipeline = await prepareAssetsGenerationEnv(pipeline, totalCount);
179
134
  const queue = new PQueue({ concurrency: Math.max(cpuCount, 1) });
180
135
  const assetsTimer = performance.now();
181
136
  for (const [originalPath, transforms] of staticImageList) {
182
- await generateImagesForPath(originalPath, transforms, assetsCreationpipeline, queue);
137
+ await generateImagesForPath(originalPath, transforms, assetsCreationPipeline, queue);
183
138
  }
184
139
  await queue.onIdle();
185
140
  const assetsTimeEnd = performance.now();
@@ -192,10 +147,9 @@ ${bgGreen(black(` ${verb} static routes `))}`);
192
147
  async function generatePage(pageData, ssrEntry, builtPaths, pipeline) {
193
148
  const { config, internals, logger } = pipeline;
194
149
  const pageModulePromise = ssrEntry.page;
195
- const pageInfo = getPageDataByComponent(internals, pageData.route.component);
196
150
  const styles = pageData.styles.sort(cssOrder).map(({ sheet }) => sheet).reduce(mergeInlineCss, []);
197
151
  const linkIds = [];
198
- const scripts = pageInfo?.hoistedScript ?? null;
152
+ const scripts = pageData.hoistedScript ?? null;
199
153
  if (!pageModulePromise) {
200
154
  throw new Error(
201
155
  `Unable to find the module for ${pageData.component}. This is unexpected and likely a bug in Astro, please report.`
@@ -387,8 +341,7 @@ async function generatePath(pathname, pipeline, gopts, route) {
387
341
  route.redirect = location.toString();
388
342
  }
389
343
  } else {
390
- if (!response.body)
391
- return;
344
+ if (!response.body) return;
392
345
  body = Buffer.from(await response.arrayBuffer());
393
346
  }
394
347
  const outFolder = getOutFolder(config, pathname, route);
@@ -434,6 +387,7 @@ function createBuildManifest(settings, internals, renderers, middleware) {
434
387
  i18n: i18nManifest,
435
388
  buildFormat: settings.config.build.format,
436
389
  middleware,
390
+ rewritingEnabled: settings.config.experimental.rewriting,
437
391
  checkOrigin: settings.config.experimental.security?.csrfProtection?.origin ?? false
438
392
  };
439
393
  }
@@ -11,7 +11,6 @@ import {
11
11
  runHookConfigDone,
12
12
  runHookConfigSetup
13
13
  } from "../../integrations/hooks.js";
14
- import { isServerLikeOutput } from "../../prerender/utils.js";
15
14
  import { resolveConfig } from "../config/config.js";
16
15
  import { createNodeLogger } from "../config/logging.js";
17
16
  import { createSettings } from "../config/settings.js";
@@ -19,7 +18,7 @@ import { createVite } from "../create-vite.js";
19
18
  import { levels, timerMessage } from "../logger/core.js";
20
19
  import { apply as applyPolyfill } from "../polyfill.js";
21
20
  import { createRouteManifest } from "../routing/index.js";
22
- import { ensureProcessNodeEnv } from "../util.js";
21
+ import { ensureProcessNodeEnv, isServerLikeOutput } from "../util.js";
23
22
  import { collectPagesData } from "./page-data.js";
24
23
  import { staticBuild, viteBuild } from "./static-build.js";
25
24
  import { getTimeStat } from "./util.js";
@@ -134,8 +133,7 @@ class AstroBuilder {
134
133
  await staticBuild(opts, internals, ssrOutputChunkNames);
135
134
  this.timer.assetsStart = performance.now();
136
135
  Object.keys(assets).map((k) => {
137
- if (!assets[k])
138
- return;
136
+ if (!assets[k]) return;
139
137
  const filePath = new URL(`file://${k}`);
140
138
  fs.mkdirSync(new URL("./", filePath), { recursive: true });
141
139
  fs.writeFileSync(filePath, assets[k], "utf8");
@@ -1,7 +1,7 @@
1
1
  import type { Rollup } from 'vite';
2
2
  import type { RouteData, SSRResult } from '../../@types/astro.js';
3
3
  import type { PageOptions } from '../../vite-plugin-astro/types.js';
4
- import type { AllPagesData, PageBuildData, StylesheetAsset, ViteID } from './types.js';
4
+ import type { PageBuildData, StylesheetAsset, ViteID } from './types.js';
5
5
  export interface BuildInternals {
6
6
  /**
7
7
  * Each CSS module is named with a chunk id derived from the Astro pages they
@@ -27,7 +27,7 @@ export interface BuildInternals {
27
27
  /**
28
28
  * A map for page-specific information.
29
29
  */
30
- pagesByComponent: Map<string, PageBuildData>;
30
+ pagesByKeys: Map<string, PageBuildData>;
31
31
  /**
32
32
  * A map for page-specific output.
33
33
  */
@@ -67,7 +67,15 @@ export interface BuildInternals {
67
67
  discoveredScripts: Set<string>;
68
68
  cachedClientEntries: string[];
69
69
  cacheManifestUsed: boolean;
70
+ /**
71
+ * Map of propagated module ids (usually something like `/Users/...blog.mdx?astroPropagatedAssets`)
72
+ * to a set of stylesheets that it uses.
73
+ */
70
74
  propagatedStylesMap: Map<string, Set<StylesheetAsset>>;
75
+ /**
76
+ * Map of propagated module ids (usually something like `/Users/...blog.mdx?astroPropagatedAssets`)
77
+ * to a set of hoisted scripts that it uses.
78
+ */
71
79
  propagatedScriptsMap: Map<string, Set<string>>;
72
80
  staticFiles: Set<string>;
73
81
  ssrEntryChunk?: Rollup.OutputChunk;
@@ -90,12 +98,31 @@ export declare function trackPageData(internals: BuildInternals, component: stri
90
98
  export declare function trackClientOnlyPageDatas(internals: BuildInternals, pageData: PageBuildData, clientOnlys: string[]): void;
91
99
  export declare function getPageDatasByChunk(internals: BuildInternals, chunk: Rollup.RenderedChunk): Generator<PageBuildData, void, unknown>;
92
100
  export declare function getPageDatasByClientOnlyID(internals: BuildInternals, viteid: ViteID): Generator<PageBuildData, void, unknown>;
93
- export declare function getPageDataByComponent(internals: BuildInternals, component: string): PageBuildData | undefined;
101
+ /**
102
+ * From its route and component, get the page data from the build internals.
103
+ * @param internals Build Internals with all the pages
104
+ * @param route The route of the page, used to identify the page
105
+ * @param component The component of the page, used to identify the page
106
+ */
107
+ export declare function getPageData(internals: BuildInternals, route: string, component: string): PageBuildData | undefined;
108
+ /**
109
+ * Get all pages datas from the build internals, using a specific component.
110
+ * @param internals Build Internals with all the pages
111
+ * @param component path to the component, used to identify related pages
112
+ */
113
+ export declare function getPagesDatasByComponent(internals: BuildInternals, component: string): PageBuildData[];
114
+ /**
115
+ * Map internals.pagesByKeys to a new map with the public key instead of the internal key.
116
+ * This function is only used to avoid breaking changes in the Integrations API, after we changed the way
117
+ * we identify pages, from the entrypoint component to an internal key.
118
+ * If the page component is unique -> the public key is the component path. (old behavior)
119
+ * If the page component is shared -> the public key is the internal key. (new behavior)
120
+ * The new behavior on shared entrypoint it's not a breaking change, because it was not supported before.
121
+ * @param pagesByKeys A map of all page data by their internal key
122
+ */
123
+ export declare function getPageDatasWithPublicKey(pagesByKeys: Map<string, PageBuildData>): Map<string, PageBuildData>;
94
124
  export declare function getPageDataByViteID(internals: BuildInternals, viteid: ViteID): PageBuildData | undefined;
95
125
  export declare function hasPageDataByViteID(internals: BuildInternals, viteid: ViteID): boolean;
96
- export declare function eachPageData(internals: BuildInternals): Generator<PageBuildData, void, undefined>;
97
- export declare function eachPageFromAllPages(allPages: AllPagesData): Generator<[string, PageBuildData]>;
98
- export declare function eachPageDataFromEntryPoint(internals: BuildInternals): Generator<[PageBuildData, string]>;
99
126
  export declare function hasPrerenderedPages(internals: BuildInternals): boolean;
100
127
  interface OrderInfo {
101
128
  depth: number;
@@ -109,7 +136,10 @@ interface OrderInfo {
109
136
  */
110
137
  export declare function cssOrder(a: OrderInfo, b: OrderInfo): 1 | -1;
111
138
  export declare function mergeInlineCss(acc: Array<StylesheetAsset>, current: StylesheetAsset): Array<StylesheetAsset>;
112
- export declare function isHoistedScript(internals: BuildInternals, id: string): boolean;
113
- export declare function getPageDatasByHoistedScriptId(internals: BuildInternals, id: string): Generator<PageBuildData, void, unknown>;
114
- export declare function getEntryFilePathFromComponentPath(internals: BuildInternals, path: string): string | undefined;
139
+ /**
140
+ * Get all pages data from the build internals, using a specific hoisted script id.
141
+ * @param internals Build Internals with all the pages
142
+ * @param id Hoisted script id, used to identify the pages using it
143
+ */
144
+ export declare function getPageDatasByHoistedScriptId(internals: BuildInternals, id: string): PageBuildData[];
115
145
  export {};
@@ -1,11 +1,6 @@
1
1
  import { prependForwardSlash, removeFileExtension } from "../path.js";
2
2
  import { viteID } from "../util.js";
3
- import {
4
- ASTRO_PAGE_RESOLVED_MODULE_ID,
5
- getVirtualModulePageIdFromPath
6
- } from "./plugins/plugin-pages.js";
7
- import { RESOLVED_SPLIT_MODULE_ID } from "./plugins/plugin-ssr.js";
8
- import { ASTRO_PAGE_EXTENSION_POST_PATTERN } from "./plugins/util.js";
3
+ import { makePageDataKey } from "./plugins/util.js";
9
4
  function createBuildInternals() {
10
5
  const hoistedScriptIdToHoistedMap = /* @__PURE__ */ new Map();
11
6
  const hoistedScriptIdToPagesMap = /* @__PURE__ */ new Map();
@@ -17,7 +12,7 @@ function createBuildInternals() {
17
12
  inlinedScripts: /* @__PURE__ */ new Map(),
18
13
  entrySpecifierToBundleMap: /* @__PURE__ */ new Map(),
19
14
  pageToBundleMap: /* @__PURE__ */ new Map(),
20
- pagesByComponent: /* @__PURE__ */ new Map(),
15
+ pagesByKeys: /* @__PURE__ */ new Map(),
21
16
  pageOptionsByPage: /* @__PURE__ */ new Map(),
22
17
  pagesByViteID: /* @__PURE__ */ new Map(),
23
18
  pagesByClientOnly: /* @__PURE__ */ new Map(),
@@ -35,7 +30,7 @@ function createBuildInternals() {
35
30
  }
36
31
  function trackPageData(internals, component, pageData, componentModuleId, componentURL) {
37
32
  pageData.moduleSpecifier = componentModuleId;
38
- internals.pagesByComponent.set(component, pageData);
33
+ internals.pagesByKeys.set(pageData.key, pageData);
39
34
  internals.pagesByViteID.set(viteID(componentURL), pageData);
40
35
  }
41
36
  function trackClientOnlyPageDatas(internals, pageData, clientOnlys) {
@@ -77,12 +72,39 @@ function* getPageDatasByClientOnlyID(internals, viteid) {
77
72
  }
78
73
  }
79
74
  }
80
- function getPageDataByComponent(internals, component) {
81
- if (internals.pagesByComponent.has(component)) {
82
- return internals.pagesByComponent.get(component);
75
+ function getPageData(internals, route, component) {
76
+ let pageData = internals.pagesByKeys.get(makePageDataKey(route, component));
77
+ if (pageData) {
78
+ return pageData;
83
79
  }
84
80
  return void 0;
85
81
  }
82
+ function getPagesDatasByComponent(internals, component) {
83
+ const pageDatas = [];
84
+ internals.pagesByKeys.forEach((pageData) => {
85
+ if (component === pageData.component) pageDatas.push(pageData);
86
+ });
87
+ return pageDatas;
88
+ }
89
+ function getPageDatasWithPublicKey(pagesByKeys) {
90
+ const pagesWithPublicKey = /* @__PURE__ */ new Map();
91
+ const pagesByComponentsArray = Array.from(pagesByKeys.values()).map((pageData) => {
92
+ return { component: pageData.component, pageData };
93
+ });
94
+ const pagesWithUniqueComponent = pagesByComponentsArray.filter((page) => {
95
+ return pagesByComponentsArray.filter((p) => p.component === page.component).length === 1;
96
+ });
97
+ pagesWithUniqueComponent.forEach((page) => {
98
+ pagesWithPublicKey.set(page.component, page.pageData);
99
+ });
100
+ const pagesWithSharedComponent = pagesByComponentsArray.filter((page) => {
101
+ return pagesByComponentsArray.filter((p) => p.component === page.component).length > 1;
102
+ });
103
+ pagesWithSharedComponent.forEach((page) => {
104
+ pagesWithPublicKey.set(page.pageData.key, page.pageData);
105
+ });
106
+ return pagesWithPublicKey;
107
+ }
86
108
  function getPageDataByViteID(internals, viteid) {
87
109
  if (internals.pagesByViteID.has(viteid)) {
88
110
  return internals.pagesByViteID.get(viteid);
@@ -92,32 +114,8 @@ function getPageDataByViteID(internals, viteid) {
92
114
  function hasPageDataByViteID(internals, viteid) {
93
115
  return internals.pagesByViteID.has(viteid);
94
116
  }
95
- function* eachPageData(internals) {
96
- yield* internals.pagesByComponent.values();
97
- }
98
- function* eachPageFromAllPages(allPages) {
99
- for (const [path, pageData] of Object.entries(allPages)) {
100
- yield [path, pageData];
101
- }
102
- }
103
- function* eachPageDataFromEntryPoint(internals) {
104
- for (const [entrypoint, filePath] of internals.entrySpecifierToBundleMap) {
105
- if (entrypoint.includes(ASTRO_PAGE_RESOLVED_MODULE_ID) || entrypoint.includes(RESOLVED_SPLIT_MODULE_ID)) {
106
- const [, pageName] = entrypoint.split(":");
107
- const pageData = internals.pagesByComponent.get(
108
- `${pageName.replace(ASTRO_PAGE_EXTENSION_POST_PATTERN, ".")}`
109
- );
110
- if (!pageData) {
111
- throw new Error(
112
- "Build failed. Astro couldn't find the emitted page from " + pageName + " pattern"
113
- );
114
- }
115
- yield [pageData, filePath];
116
- }
117
- }
118
- }
119
117
  function hasPrerenderedPages(internals) {
120
- for (const pageData of eachPageData(internals)) {
118
+ for (const pageData of internals.pagesByKeys.values()) {
121
119
  if (pageData.route.prerender) {
122
120
  return true;
123
121
  }
@@ -156,39 +154,30 @@ function mergeInlineCss(acc, current) {
156
154
  acc.push(current);
157
155
  return acc;
158
156
  }
159
- function isHoistedScript(internals, id) {
160
- return internals.hoistedScriptIdToPagesMap.has(id);
161
- }
162
- function* getPageDatasByHoistedScriptId(internals, id) {
157
+ function getPageDatasByHoistedScriptId(internals, id) {
163
158
  const set = internals.hoistedScriptIdToPagesMap.get(id);
159
+ const pageDatas = [];
164
160
  if (set) {
165
161
  for (const pageId of set) {
166
- const pageData = getPageDataByComponent(internals, pageId.slice(1));
167
- if (pageData) {
168
- yield pageData;
169
- }
162
+ getPagesDatasByComponent(internals, pageId.slice(1)).forEach((pageData) => {
163
+ pageDatas.push(pageData);
164
+ });
170
165
  }
171
166
  }
172
- }
173
- function getEntryFilePathFromComponentPath(internals, path) {
174
- const id = getVirtualModulePageIdFromPath(path);
175
- return internals.entrySpecifierToBundleMap.get(id);
167
+ return pageDatas;
176
168
  }
177
169
  export {
178
170
  createBuildInternals,
179
171
  cssOrder,
180
- eachPageData,
181
- eachPageDataFromEntryPoint,
182
- eachPageFromAllPages,
183
- getEntryFilePathFromComponentPath,
184
- getPageDataByComponent,
172
+ getPageData,
185
173
  getPageDataByViteID,
186
174
  getPageDatasByChunk,
187
175
  getPageDatasByClientOnlyID,
188
176
  getPageDatasByHoistedScriptId,
177
+ getPageDatasWithPublicKey,
178
+ getPagesDatasByComponent,
189
179
  hasPageDataByViteID,
190
180
  hasPrerenderedPages,
191
- isHoistedScript,
192
181
  mergeInlineCss,
193
182
  trackClientOnlyPageDatas,
194
183
  trackPageData
@@ -1,5 +1,6 @@
1
1
  import * as colors from "kleur/colors";
2
2
  import { debug } from "../logger/core.js";
3
+ import { makePageDataKey } from "./plugins/util.js";
3
4
  async function collectPagesData(opts) {
4
5
  const { settings, manifest } = opts;
5
6
  const assets = {};
@@ -10,6 +11,7 @@ async function collectPagesData(opts) {
10
11
  clearInterval(dataCollectionLogTimeout);
11
12
  }, 3e4);
12
13
  for (const route of manifest.routes) {
14
+ const key = makePageDataKey(route.route, route.component);
13
15
  if (route.pathname) {
14
16
  const routeCollectionLogTimeout = setInterval(() => {
15
17
  opts.logger.info(
@@ -21,13 +23,12 @@ async function collectPagesData(opts) {
21
23
  clearInterval(routeCollectionLogTimeout);
22
24
  }, 1e4);
23
25
  builtPaths.add(route.pathname);
24
- allPages[route.component] = {
26
+ allPages[key] = {
27
+ key,
25
28
  component: route.component,
26
29
  route,
27
30
  moduleSpecifier: "",
28
31
  styles: [],
29
- propagatedStyles: /* @__PURE__ */ new Map(),
30
- propagatedScripts: /* @__PURE__ */ new Map(),
31
32
  hoistedScript: void 0,
32
33
  hasSharedModules: false
33
34
  };
@@ -43,13 +44,12 @@ async function collectPagesData(opts) {
43
44
  }
44
45
  continue;
45
46
  }
46
- allPages[route.component] = {
47
+ allPages[key] = {
48
+ key,
47
49
  component: route.component,
48
50
  route,
49
51
  moduleSpecifier: "",
50
52
  styles: [],
51
- propagatedStyles: /* @__PURE__ */ new Map(),
52
- propagatedScripts: /* @__PURE__ */ new Map(),
53
53
  hoistedScript: void 0,
54
54
  hasSharedModules: false
55
55
  };
@@ -1,17 +1,19 @@
1
- import type { RouteData, SSRResult } from '../../@types/astro.js';
1
+ import type { ComponentInstance, RewritePayload, RouteData, SSRResult } from '../../@types/astro.js';
2
2
  import type { SSRManifest } from '../app/types.js';
3
3
  import { Pipeline } from '../render/index.js';
4
4
  import { type BuildInternals } from './internal.js';
5
- import type { PageBuildData, StaticBuildOptions } from './types.js';
5
+ import type { PageBuildData, SinglePageBuiltModule, StaticBuildOptions } from './types.js';
6
6
  /**
7
7
  * The build pipeline is responsible to gather the files emitted by the SSR build and generate the pages by executing these files.
8
8
  */
9
9
  export declare class BuildPipeline extends Pipeline {
10
+ #private;
10
11
  readonly internals: BuildInternals;
11
12
  readonly manifest: SSRManifest;
12
13
  readonly options: StaticBuildOptions;
13
14
  readonly config: import("../../@types/astro.js").AstroConfig;
14
15
  readonly settings: import("../../@types/astro.js").AstroSettings;
16
+ get outFolder(): URL;
15
17
  private constructor();
16
18
  static create({ internals, manifest, options, }: Pick<BuildPipeline, 'internals' | 'manifest' | 'options'>): BuildPipeline;
17
19
  /**
@@ -32,8 +34,10 @@ export declare class BuildPipeline extends Pipeline {
32
34
  componentMetadata(): void;
33
35
  /**
34
36
  * It collects the routes to generate during the build.
35
- *
36
37
  * It returns a map of page information and their relative entry point as a string.
37
38
  */
38
39
  retrieveRoutesToGenerate(): Map<PageBuildData, string>;
40
+ getComponentByRoute(routeData: RouteData): Promise<ComponentInstance>;
41
+ tryRewrite(payload: RewritePayload): Promise<[RouteData, ComponentInstance]>;
42
+ retrieveSsrEntry(route: RouteData, filePath: string): Promise<SinglePageBuiltModule>;
39
43
  }