astro 2.7.3 → 2.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 (107) hide show
  1. package/astro.js +0 -1
  2. package/dist/@types/astro.d.ts +48 -14
  3. package/dist/assets/image-endpoint.js +1 -1
  4. package/dist/assets/services/vendor/squoosh/codecs.js +0 -2
  5. package/dist/assets/vendor/image-size/types/tiff.js +1 -1
  6. package/dist/cli/index.js +54 -5
  7. package/dist/content/utils.d.ts +1 -1
  8. package/dist/content/utils.js +1 -1
  9. package/dist/core/app/index.js +4 -8
  10. package/dist/core/app/node.d.ts +1 -1
  11. package/dist/core/app/types.d.ts +2 -2
  12. package/dist/core/build/generate.d.ts +9 -1
  13. package/dist/core/build/generate.js +56 -67
  14. package/dist/core/build/index.d.ts +1 -1
  15. package/dist/core/build/index.js +19 -1
  16. package/dist/core/build/internal.d.ts +1 -0
  17. package/dist/core/build/plugins/index.js +2 -2
  18. package/dist/core/build/plugins/plugin-analyzer.js +1 -1
  19. package/dist/core/build/plugins/plugin-css.js +1 -1
  20. package/dist/core/build/plugins/plugin-middleware.d.ts +2 -2
  21. package/dist/core/build/plugins/plugin-middleware.js +20 -1
  22. package/dist/core/build/plugins/plugin-pages.js +6 -4
  23. package/dist/core/build/plugins/plugin-renderers.d.ts +2 -3
  24. package/dist/core/build/plugins/plugin-renderers.js +3 -4
  25. package/dist/core/build/plugins/plugin-ssr.js +8 -13
  26. package/dist/core/build/static-build.js +0 -3
  27. package/dist/core/compile/compile.js +0 -1
  28. package/dist/core/config/schema.d.ts +85 -73
  29. package/dist/core/config/schema.js +6 -4
  30. package/dist/core/constants.js +1 -1
  31. package/dist/core/cookies/cookies.js +4 -2
  32. package/dist/core/create-vite.js +2 -2
  33. package/dist/core/dev/dev.js +1 -1
  34. package/dist/core/dev/restart.js +1 -1
  35. package/dist/core/endpoint/dev/index.d.ts +1 -2
  36. package/dist/core/endpoint/dev/index.js +2 -3
  37. package/dist/core/endpoint/index.d.ts +9 -4
  38. package/dist/core/endpoint/index.js +3 -3
  39. package/dist/core/errors/dev/utils.js +2 -2
  40. package/dist/core/errors/errors.d.ts +6 -6
  41. package/dist/core/errors/overlay.d.ts +1 -2
  42. package/dist/core/errors/overlay.js +3 -2
  43. package/dist/core/errors/utils.js +1 -1
  44. package/dist/core/messages.js +2 -2
  45. package/dist/core/middleware/callMiddleware.js +0 -4
  46. package/dist/core/middleware/index.d.ts +31 -2
  47. package/dist/core/middleware/index.js +47 -1
  48. package/dist/core/module-loader/loader.d.ts +1 -0
  49. package/dist/core/render/context.d.ts +2 -6
  50. package/dist/core/render/context.js +4 -8
  51. package/dist/core/render/core.d.ts +2 -23
  52. package/dist/core/render/core.js +2 -74
  53. package/dist/core/render/dev/environment.js +1 -0
  54. package/dist/core/render/dev/index.d.ts +0 -2
  55. package/dist/core/render/dev/index.js +2 -2
  56. package/dist/core/render/dev/vite.js +7 -8
  57. package/dist/core/render/environment.d.ts +14 -8
  58. package/dist/core/render/environment.js +0 -19
  59. package/dist/core/render/index.d.ts +3 -2
  60. package/dist/core/render/index.js +3 -10
  61. package/dist/core/render/params-and-props.d.ts +13 -0
  62. package/dist/core/render/params-and-props.js +57 -0
  63. package/dist/core/render/result.d.ts +14 -4
  64. package/dist/core/render/result.js +10 -11
  65. package/dist/core/render/route-cache.d.ts +3 -2
  66. package/dist/core/render/route-cache.js +13 -7
  67. package/dist/core/routing/manifest/create.js +2 -22
  68. package/dist/events/error.js +6 -2
  69. package/dist/integrations/index.d.ts +8 -4
  70. package/dist/integrations/index.js +8 -8
  71. package/dist/runtime/client/visible.js +1 -2
  72. package/dist/runtime/client/visible.prebuilt.d.ts +1 -1
  73. package/dist/runtime/client/visible.prebuilt.js +1 -1
  74. package/dist/runtime/server/astro-global.js +1 -1
  75. package/dist/runtime/server/astro-island.js +2 -2
  76. package/dist/runtime/server/astro-island.prebuilt.d.ts +1 -1
  77. package/dist/runtime/server/astro-island.prebuilt.js +1 -1
  78. package/dist/runtime/server/endpoint.js +1 -1
  79. package/dist/runtime/server/hydration.d.ts +1 -1
  80. package/dist/runtime/server/jsx.js +2 -2
  81. package/dist/runtime/server/render/astro/instance.js +2 -2
  82. package/dist/runtime/server/render/component.js +1 -1
  83. package/dist/runtime/server/render/head.d.ts +3 -9
  84. package/dist/runtime/server/render/head.js +7 -10
  85. package/dist/runtime/server/render/page.d.ts +1 -1
  86. package/dist/runtime/server/render/page.js +9 -9
  87. package/dist/runtime/server/render/types.d.ts +0 -5
  88. package/dist/runtime/server/render/util.js +11 -3
  89. package/dist/runtime/server/scripts.js +1 -1
  90. package/dist/vite-plugin-astro/compile.js +2 -4
  91. package/dist/vite-plugin-astro/hmr.js +1 -1
  92. package/dist/vite-plugin-astro-postprocess/index.d.ts +1 -6
  93. package/dist/vite-plugin-astro-postprocess/index.js +1 -1
  94. package/dist/vite-plugin-astro-server/plugin.js +2 -2
  95. package/dist/vite-plugin-astro-server/route.js +18 -14
  96. package/dist/vite-plugin-head/index.d.ts +2 -6
  97. package/dist/vite-plugin-head/index.js +2 -4
  98. package/dist/vite-plugin-html/transform/escape.js +2 -2
  99. package/dist/vite-plugin-html/transform/slots.js +1 -1
  100. package/dist/vite-plugin-jsx/import-source.js +1 -1
  101. package/dist/vite-plugin-jsx/tag.d.ts +1 -1
  102. package/dist/vite-plugin-jsx/tag.js +1 -2
  103. package/dist/vite-plugin-markdown/content-entry-type.js +2 -3
  104. package/dist/vite-plugin-scanner/scan.js +1 -1
  105. package/dist/vite-plugin-scripts/index.js +1 -1
  106. package/dist/vite-plugin-ssr-manifest/index.js +1 -1
  107. package/package.json +2 -1
package/astro.js CHANGED
@@ -1,5 +1,4 @@
1
1
  #!/usr/bin/env node
2
- /* eslint-disable no-console */
3
2
  'use strict';
4
3
 
5
4
  // ISOMORPHIC FILE: NO TOP-LEVEL IMPORT/REQUIRE() ALLOWED
@@ -765,7 +765,7 @@ export interface AstroUserConfig {
765
765
  * @docs
766
766
  * @name build.split
767
767
  * @type {boolean}
768
- * @default {false}
768
+ * @default `false`
769
769
  * @version 2.7.0
770
770
  * @description
771
771
  * Defines how the SSR code should be bundled when built.
@@ -784,6 +784,26 @@ export interface AstroUserConfig {
784
784
  * ```
785
785
  */
786
786
  split?: boolean;
787
+ /**
788
+ * @docs
789
+ * @name build.excludeMiddleware
790
+ * @type {boolean}
791
+ * @default {false}
792
+ * @version 2.8.0
793
+ * @description
794
+ * Defines whether or not any SSR middleware code will be bundled when built.
795
+ *
796
+ * When enabled, middleware code is not bundled and imported by all pages during the build. To instead execute and import middleware code manually, set `build.excludeMiddleware: true`:
797
+ *
798
+ * ```js
799
+ * {
800
+ * build: {
801
+ * excludeMiddleware: true
802
+ * }
803
+ * }
804
+ * ```
805
+ */
806
+ excludeMiddleware?: boolean;
787
807
  };
788
808
  /**
789
809
  * @docs
@@ -1665,6 +1685,10 @@ export interface AstroIntegration {
1665
1685
  * the physical file you should import.
1666
1686
  */
1667
1687
  entryPoints: Map<RouteData, URL>;
1688
+ /**
1689
+ * File path of the emitted middleware
1690
+ */
1691
+ middlewareEntryPoint: URL | undefined;
1668
1692
  }) => void | Promise<void>;
1669
1693
  'astro:build:start'?: () => void | Promise<void>;
1670
1694
  'astro:build:setup'?: (options: {
@@ -1737,15 +1761,6 @@ export interface SSRElement {
1737
1761
  props: Record<string, any>;
1738
1762
  children: string;
1739
1763
  }
1740
- export interface SSRMetadata {
1741
- renderers: SSRLoadedRenderer[];
1742
- pathname: string;
1743
- hasHydrationScript: boolean;
1744
- hasDirectives: Set<string>;
1745
- hasRenderedHead: boolean;
1746
- headInTree: boolean;
1747
- clientDirectives: Map<string, string>;
1748
- }
1749
1764
  /**
1750
1765
  * A hint on whether the Astro runtime needs to wait on a component to render head
1751
1766
  * content. The meanings:
@@ -1766,15 +1781,34 @@ export interface SSRResult {
1766
1781
  scripts: Set<SSRElement>;
1767
1782
  links: Set<SSRElement>;
1768
1783
  componentMetadata: Map<string, SSRComponentMetadata>;
1769
- propagators: Map<AstroComponentFactory, AstroComponentInstance>;
1770
- extraHead: Array<string>;
1771
- cookies: AstroCookies | undefined;
1772
1784
  createAstro(Astro: AstroGlobalPartial, props: Record<string, any>, slots: Record<string, any> | null): AstroGlobal;
1773
1785
  resolve: (s: string) => Promise<string>;
1774
1786
  response: ResponseInit;
1775
- scope: number;
1787
+ renderers: SSRLoadedRenderer[];
1788
+ /**
1789
+ * Map of directive name (e.g. `load`) to the directive script code
1790
+ */
1791
+ clientDirectives: Map<string, string>;
1792
+ compressHTML: boolean;
1793
+ /**
1794
+ * Only used for logging
1795
+ */
1796
+ pathname: string;
1797
+ cookies: AstroCookies | undefined;
1776
1798
  _metadata: SSRMetadata;
1777
1799
  }
1800
+ /**
1801
+ * Ephemeral and mutable state during rendering that doesn't rely
1802
+ * on external configuration
1803
+ */
1804
+ export interface SSRMetadata {
1805
+ hasHydrationScript: boolean;
1806
+ hasDirectives: Set<string>;
1807
+ hasRenderedHead: boolean;
1808
+ headInTree: boolean;
1809
+ extraHead: string[];
1810
+ propagators: Map<AstroComponentFactory, AstroComponentInstance>;
1811
+ }
1778
1812
  export interface PreviewServer {
1779
1813
  host?: string;
1780
1814
  port: number;
@@ -23,7 +23,7 @@ const get = async ({ request }) => {
23
23
  }
24
24
  const url = new URL(request.url);
25
25
  const transform = await imageService.parseURL(url, imageServiceConfig);
26
- if (!transform || !transform.src) {
26
+ if (!(transform == null ? void 0 : transform.src)) {
27
27
  throw new Error("Incorrect transform returned by `parseURL`");
28
28
  }
29
29
  let inputBuffer = void 0;
@@ -211,7 +211,6 @@ const codecs = {
211
211
  avif: {
212
212
  name: "AVIF",
213
213
  extension: "avif",
214
- // eslint-disable-next-line no-control-regex
215
214
  detectors: [/^\x00\x00\x00 ftypavif\x00\x00\x00\x00/],
216
215
  dec: () => instantiateEmscriptenWasm(avifDec, avifDecWasm),
217
216
  enc: async () => {
@@ -241,7 +240,6 @@ const codecs = {
241
240
  oxipng: {
242
241
  name: "OxiPNG",
243
242
  extension: "png",
244
- // eslint-disable-next-line no-control-regex
245
243
  detectors: [/^\x89PNG\x0D\x0A\x1A\x0A/],
246
244
  dec: async () => {
247
245
  await pngEncDecInit();
@@ -26,7 +26,7 @@ function nextTag(buffer) {
26
26
  function extractTags(buffer, isBigEndian) {
27
27
  const tags = {};
28
28
  let temp = buffer;
29
- while (temp && temp.length) {
29
+ while (temp == null ? void 0 : temp.length) {
30
30
  const code = readUInt(temp, 16, 0, isBigEndian);
31
31
  const type = readUInt(temp, 16, 2, isBigEndian);
32
32
  const length = readUInt(temp, 32, 4, isBigEndian);
package/dist/cli/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import fs from "fs";
2
2
  import * as colors from "kleur/colors";
3
+ import { arch, platform } from "node:os";
3
4
  import yargs from "yargs-parser";
4
5
  import { ZodError } from "zod";
5
6
  import {
@@ -29,6 +30,7 @@ function printAstroHelp() {
29
30
  ["check", "Check your project for errors."],
30
31
  ["dev", "Start the development server."],
31
32
  ["docs", "Open documentation in your web browser."],
33
+ ["info", "List info about your current Astro setup."],
32
34
  ["preview", "Preview your build locally."],
33
35
  ["sync", "Generate content collection types."],
34
36
  ["telemetry", "Configure telemetry settings."]
@@ -50,6 +52,48 @@ async function printVersion() {
50
52
  console.log();
51
53
  console.log(` ${colors.bgGreen(colors.black(` astro `))} ${colors.green(`v${ASTRO_VERSION}`)}`);
52
54
  }
55
+ async function printInfo({
56
+ cwd,
57
+ flags,
58
+ logging
59
+ }) {
60
+ var _a;
61
+ const whichPm = await import("which-pm");
62
+ const packageManager = await whichPm.default(process.cwd());
63
+ let adapter = "Couldn't determine.";
64
+ let integrations = [];
65
+ const MAX_PADDING = 25;
66
+ function printRow(label, value) {
67
+ const padding = MAX_PADDING - label.length;
68
+ console.log(`${colors.bold(label)}` + " ".repeat(padding) + `${colors.green(value)}`);
69
+ }
70
+ try {
71
+ const { userConfig } = await openConfig({
72
+ cwd,
73
+ flags,
74
+ cmd: "info",
75
+ logging
76
+ });
77
+ if ((_a = userConfig.adapter) == null ? void 0 : _a.name) {
78
+ adapter = userConfig.adapter.name;
79
+ }
80
+ if (userConfig.integrations) {
81
+ integrations = ((userConfig == null ? void 0 : userConfig.integrations) ?? []).filter(Boolean).flat().map((i) => i == null ? void 0 : i.name);
82
+ }
83
+ } catch (_e) {
84
+ }
85
+ console.log();
86
+ printRow("Astro version", `v${ASTRO_VERSION}`);
87
+ printRow("Package manager", packageManager.name);
88
+ printRow("Platform", platform());
89
+ printRow("Architecture", arch());
90
+ printRow("Adapter", adapter);
91
+ let integrationsString = "None or couldn't determine.";
92
+ if (integrations.length > 0) {
93
+ integrationsString = integrations.join(", ");
94
+ }
95
+ printRow("Integrations", integrationsString);
96
+ }
53
97
  function resolveCommand(flags) {
54
98
  const cmd = flags._[2];
55
99
  if (flags.version)
@@ -62,7 +106,8 @@ function resolveCommand(flags) {
62
106
  "build",
63
107
  "preview",
64
108
  "check",
65
- "docs"
109
+ "docs",
110
+ "info"
66
111
  ]);
67
112
  if (supportedCommands.has(cmd)) {
68
113
  return cmd;
@@ -86,6 +131,10 @@ async function handleConfigError(e, { cmd, cwd, flags, logging }) {
86
131
  async function runCommand(cmd, flags) {
87
132
  var _a;
88
133
  const root = flags.root;
134
+ let logging = {
135
+ dest: nodeLogDestination,
136
+ level: "info"
137
+ };
89
138
  switch (cmd) {
90
139
  case "help":
91
140
  printAstroHelp();
@@ -93,11 +142,11 @@ async function runCommand(cmd, flags) {
93
142
  case "version":
94
143
  await printVersion();
95
144
  return process.exit(0);
145
+ case "info": {
146
+ await printInfo({ cwd: root, flags, logging });
147
+ return process.exit(0);
148
+ }
96
149
  }
97
- let logging = {
98
- dest: nodeLogDestination,
99
- level: "info"
100
- };
101
150
  if (flags.verbose) {
102
151
  logging.level = "debug";
103
152
  enableVerboseLogging();
@@ -119,7 +119,7 @@ export declare function getContentEntryIdAndSlug({ entry, contentDir, collection
119
119
  };
120
120
  export declare function getEntryType(entryPath: string, paths: Pick<ContentPaths, 'config' | 'contentDir'>, contentFileExts: string[], dataFileExts: string[], experimentalAssets?: boolean): 'content' | 'data' | 'config' | 'ignored' | 'unsupported';
121
121
  export declare function hasUnderscoreBelowContentDirectoryPath(fileUrl: URL, contentDir: ContentPaths['contentDir']): boolean;
122
- export declare function parseFrontmatter(fileContents: string, filePath: string): matter.GrayMatterFile<string>;
122
+ export declare function parseFrontmatter(fileContents: string): matter.GrayMatterFile<string>;
123
123
  /**
124
124
  * The content config is loaded separately from other `src/` files.
125
125
  * This global observable lets dependent plugins (like the content flag plugin)
@@ -209,7 +209,7 @@ function getYAMLErrorLine(rawData, objectKey) {
209
209
  const numNewlinesBeforeKey = dataBeforeKey.split("\n").length;
210
210
  return numNewlinesBeforeKey;
211
211
  }
212
- function parseFrontmatter(fileContents, filePath) {
212
+ function parseFrontmatter(fileContents) {
213
213
  try {
214
214
  matter.clearCache();
215
215
  return matter(fileContents);
@@ -44,6 +44,7 @@ class App {
44
44
  logging: this.#logging,
45
45
  markdown: manifest.markdown,
46
46
  mode: "production",
47
+ compressHTML: manifest.compressHTML,
47
48
  renderers: manifest.renderers,
48
49
  clientDirectives: manifest.clientDirectives,
49
50
  async resolve(specifier) {
@@ -170,7 +171,6 @@ class App {
170
171
  const url = new URL(request.url);
171
172
  const pathname = prependForwardSlash(this.removeBase(url.pathname));
172
173
  const info = this.#routeDataToRouteInfo.get(routeData);
173
- const isCompressHTML = this.#manifest.compressHTML ?? false;
174
174
  const links = /* @__PURE__ */ new Set();
175
175
  const styles = createStylesheetElementSet(info.styles);
176
176
  let scripts = /* @__PURE__ */ new Set();
@@ -190,7 +190,6 @@ class App {
190
190
  const mod = await page.page();
191
191
  const renderContext = await createRenderContext({
192
192
  request,
193
- origin: url.origin,
194
193
  pathname,
195
194
  componentMetadata: this.#manifest.componentMetadata,
196
195
  scripts,
@@ -219,8 +218,7 @@ class App {
219
218
  mod,
220
219
  renderContext,
221
220
  env: this.#env,
222
- cookies: apiContext.cookies,
223
- isCompressHTML
221
+ cookies: apiContext.cookies
224
222
  });
225
223
  }
226
224
  );
@@ -229,8 +227,7 @@ class App {
229
227
  mod,
230
228
  renderContext,
231
229
  env: this.#env,
232
- cookies: apiContext.cookies,
233
- isCompressHTML
230
+ cookies: apiContext.cookies
234
231
  });
235
232
  }
236
233
  Reflect.set(request, responseSentSymbol, true);
@@ -250,14 +247,13 @@ class App {
250
247
  const handler = mod;
251
248
  const ctx = await createRenderContext({
252
249
  request,
253
- origin: url.origin,
254
250
  pathname,
255
251
  route: routeData,
256
252
  status,
257
253
  env: this.#env,
258
254
  mod: handler
259
255
  });
260
- const result = await callEndpoint(handler, this.#env, ctx, this.#logging, page.onRequest);
256
+ const result = await callEndpoint(handler, this.#env, ctx, page.onRequest);
261
257
  if (result.type === "response") {
262
258
  if (result.response.headers.get("X-Astro-Response") === "Not-Found") {
263
259
  const fourOhFourRequest = new Request(new URL("/404", request.url));
@@ -7,7 +7,7 @@ declare class NodeIncomingMessage extends IncomingMessage {
7
7
  /**
8
8
  * The read-only body property of the Request interface contains a ReadableStream with the body contents that have been added to the request.
9
9
  */
10
- body?: any | undefined;
10
+ body?: unknown;
11
11
  }
12
12
  export declare class NodeApp extends App {
13
13
  match(req: NodeIncomingMessage | Request, opts?: MatchOptions): RouteData | undefined;
@@ -30,8 +30,8 @@ export type SSRManifest = {
30
30
  adapterName: string;
31
31
  routes: RouteInfo[];
32
32
  site?: string;
33
- base?: string;
34
- compressHTML?: boolean;
33
+ base: string;
34
+ compressHTML: boolean;
35
35
  assetsPrefix?: string;
36
36
  markdown: MarkdownRenderingOptions;
37
37
  renderers: SSRLoadedRenderer[];
@@ -1,7 +1,15 @@
1
1
  import type { OutputAsset, OutputChunk } from 'rollup';
2
- import type { AstroSettings } from '../../@types/astro';
2
+ import type { AstroSettings, SSRLoadedRenderer, SSRManifest } from '../../@types/astro';
3
3
  import { type BuildInternals } from '../../core/build/internal.js';
4
4
  import type { StaticBuildOptions } from './types';
5
5
  export declare function rootRelativeFacadeId(facadeId: string, settings: AstroSettings): string;
6
6
  export declare function chunkIsPage(settings: AstroSettings, output: OutputAsset | OutputChunk, internals: BuildInternals): boolean;
7
7
  export declare function generatePages(opts: StaticBuildOptions, internals: BuildInternals): Promise<void>;
8
+ /**
9
+ * It creates a `SSRManifest` from the `AstroSettings`.
10
+ *
11
+ * Renderers needs to be pulled out from the page module emitted during the build.
12
+ * @param settings
13
+ * @param renderers
14
+ */
15
+ export declare function generateRuntimeManifest(settings: AstroSettings, internals: BuildInternals, renderers: SSRLoadedRenderer[]): SSRManifest;
@@ -107,36 +107,35 @@ ${bgGreen(black(` ${verb} static routes `))}`);
107
107
  const manifest = ssrEntryPage.manifest;
108
108
  const ssrEntry = manifest == null ? void 0 : manifest.pageModule;
109
109
  if (ssrEntry) {
110
- await generatePage(opts, internals, pageData, ssrEntry, builtPaths);
110
+ await generatePage(opts, internals, pageData, ssrEntry, builtPaths, manifest);
111
111
  } else {
112
112
  throw new Error(
113
113
  `Unable to find the manifest for the module ${ssrEntryURLPage.toString()}. This is unexpected and likely a bug in Astro, please report.`
114
114
  );
115
115
  }
116
116
  } else {
117
- await generatePage(
118
- opts,
119
- internals,
120
- pageData,
121
- ssrEntryPage,
122
- builtPaths
123
- );
117
+ const ssrEntry = ssrEntryPage;
118
+ const manifest = generateRuntimeManifest(opts.settings, internals, ssrEntry.renderers);
119
+ await generatePage(opts, internals, pageData, ssrEntry, builtPaths, manifest);
124
120
  }
125
121
  }
126
122
  }
127
123
  for (const pageData of eachRedirectPageData(internals)) {
128
124
  const entry = await getEntryForRedirectRoute(pageData.route, internals, outFolder);
129
- await generatePage(opts, internals, pageData, entry, builtPaths);
125
+ const manifest = generateRuntimeManifest(opts.settings, internals, entry.renderers);
126
+ await generatePage(opts, internals, pageData, entry, builtPaths, manifest);
130
127
  }
131
128
  } else {
132
129
  for (const [pageData, filePath] of eachPageDataFromEntryPoint(internals)) {
133
130
  const ssrEntryURLPage = createEntryURL(filePath, outFolder);
134
- const ssrEntryPage = await import(ssrEntryURLPage.toString());
135
- await generatePage(opts, internals, pageData, ssrEntryPage, builtPaths);
131
+ const entry = await import(ssrEntryURLPage.toString());
132
+ const manifest = generateRuntimeManifest(opts.settings, internals, entry.renderers);
133
+ await generatePage(opts, internals, pageData, entry, builtPaths, manifest);
136
134
  }
137
135
  for (const pageData of eachRedirectPageData(internals)) {
138
136
  const entry = await getEntryForRedirectRoute(pageData.route, internals, outFolder);
139
- await generatePage(opts, internals, pageData, entry, builtPaths);
137
+ const manifest = generateRuntimeManifest(opts.settings, internals, entry.renderers);
138
+ await generatePage(opts, internals, pageData, entry, builtPaths, manifest);
140
139
  }
141
140
  }
142
141
  if (opts.settings.config.experimental.assets) {
@@ -166,12 +165,11 @@ async function generateImage(opts, transform, path) {
166
165
  const statsText = generationData.cached ? `(reused cache entry)` : `(before: ${generationData.weight.before}kb, after: ${generationData.weight.after}kb)`;
167
166
  info(opts.logging, null, ` ${green("\u25B6")} ${path} ${dim(statsText)} ${dim(timeIncrease)}`);
168
167
  }
169
- async function generatePage(opts, internals, pageData, ssrEntry, builtPaths) {
168
+ async function generatePage(opts, internals, pageData, ssrEntry, builtPaths, manifest) {
170
169
  if (routeIsRedirect(pageData.route) && !opts.settings.config.experimental.redirects) {
171
170
  throw new Error(`To use redirects first set experimental.redirects to \`true\``);
172
171
  }
173
172
  let timeStart = performance.now();
174
- const renderers = ssrEntry.renderers;
175
173
  const pageInfo = getPageDataByComponent(internals, pageData.route.component);
176
174
  const linkIds = [];
177
175
  const scripts = (pageInfo == null ? void 0 : pageInfo.hoistedScript) ?? null;
@@ -194,8 +192,7 @@ async function generatePage(opts, internals, pageData, ssrEntry, builtPaths) {
194
192
  linkIds,
195
193
  scripts,
196
194
  styles,
197
- mod: pageModule,
198
- renderers
195
+ mod: pageModule
199
196
  };
200
197
  const icon = pageData.route.type === "page" ? green("\u25B6") : magenta("\u03BB");
201
198
  if (isRelativePath(pageData.route.component)) {
@@ -206,7 +203,7 @@ async function generatePage(opts, internals, pageData, ssrEntry, builtPaths) {
206
203
  const paths = await getPathsForRoute(pageData, pageModule, opts, builtPaths);
207
204
  for (let i = 0; i < paths.length; i++) {
208
205
  const path = paths[i];
209
- await generatePath(path, opts, generationOptions, onRequest);
206
+ await generatePath(path, opts, generationOptions, manifest, onRequest);
210
207
  const timeEnd = performance.now();
211
208
  const timeChange = getTimeStat(timeStart, timeEnd);
212
209
  const timeIncrease = `(+${timeChange})`;
@@ -222,27 +219,25 @@ async function getPathsForRoute(pageData, mod, opts, builtPaths) {
222
219
  builtPaths.add(pageData.route.pathname);
223
220
  } else {
224
221
  const route = pageData.route;
225
- const result = await callGetStaticPaths({
222
+ const staticPaths = await callGetStaticPaths({
226
223
  mod,
227
- route: pageData.route,
224
+ route,
225
+ routeCache: opts.routeCache,
228
226
  isValidate: false,
229
227
  logging: opts.logging,
230
228
  ssr: isServerLikeOutput(opts.settings.config)
231
- }).then((_result) => {
232
- const label = _result.staticPaths.length === 1 ? "page" : "pages";
233
- debug(
234
- "build",
235
- `\u251C\u2500\u2500 ${colors.bold(colors.green("\u2714"))} ${route.component} \u2192 ${colors.magenta(
236
- `[${_result.staticPaths.length} ${label}]`
237
- )}`
238
- );
239
- return _result;
240
229
  }).catch((err) => {
241
230
  debug("build", `\u251C\u2500\u2500 ${colors.bold(colors.red("\u2717"))} ${route.component}`);
242
231
  throw err;
243
232
  });
244
- opts.routeCache.set(route, result);
245
- paths = result.staticPaths.map((staticPath) => {
233
+ const label = staticPaths.length === 1 ? "page" : "pages";
234
+ debug(
235
+ "build",
236
+ `\u251C\u2500\u2500 ${colors.bold(colors.green("\u2714"))} ${route.component} \u2192 ${colors.magenta(
237
+ `[${staticPaths.length} ${label}]`
238
+ )}`
239
+ );
240
+ paths = staticPaths.map((staticPath) => {
246
241
  try {
247
242
  return route.generate(staticPath.params);
248
243
  } catch (e) {
@@ -328,17 +323,9 @@ function getUrlForPath(pathname, base, origin, format, routeType) {
328
323
  const url = new URL(buildPathname, origin);
329
324
  return url;
330
325
  }
331
- async function generatePath(pathname, opts, gopts, onRequest) {
326
+ async function generatePath(pathname, opts, gopts, manifest, onRequest) {
332
327
  const { settings, logging, origin, routeCache } = opts;
333
- const {
334
- mod,
335
- internals,
336
- linkIds,
337
- scripts: hoistedScripts,
338
- styles: _styles,
339
- pageData,
340
- renderers
341
- } = gopts;
328
+ const { mod, internals, scripts: hoistedScripts, styles: _styles, pageData } = gopts;
342
329
  if (pageData.route.type === "page") {
343
330
  addPageName(pathname, opts);
344
331
  }
@@ -346,24 +333,16 @@ async function generatePath(pathname, opts, gopts, onRequest) {
346
333
  const links = /* @__PURE__ */ new Set();
347
334
  const scripts = createModuleScriptsSet(
348
335
  hoistedScripts ? [hoistedScripts] : [],
349
- settings.config.base,
350
- settings.config.build.assetsPrefix
351
- );
352
- const styles = createStylesheetElementSet(
353
- _styles,
354
- settings.config.base,
355
- settings.config.build.assetsPrefix
336
+ manifest.base,
337
+ manifest.assetsPrefix
356
338
  );
339
+ const styles = createStylesheetElementSet(_styles, manifest.base, manifest.assetsPrefix);
357
340
  if (settings.scripts.some((script) => script.stage === "page")) {
358
341
  const hashedFilePath = internals.entrySpecifierToBundleMap.get(PAGE_SCRIPT_ID);
359
342
  if (typeof hashedFilePath !== "string") {
360
343
  throw new Error(`Cannot find the built path for ${PAGE_SCRIPT_ID}`);
361
344
  }
362
- const src = createAssetLink(
363
- hashedFilePath,
364
- settings.config.base,
365
- settings.config.build.assetsPrefix
366
- );
345
+ const src = createAssetLink(hashedFilePath, manifest.base, manifest.assetsPrefix);
367
346
  scripts.add({
368
347
  props: { type: "module", src },
369
348
  children: ""
@@ -386,12 +365,13 @@ async function generatePath(pathname, opts, gopts, onRequest) {
386
365
  pageData.route.type
387
366
  );
388
367
  const env = createEnvironment({
389
- adapterName: void 0,
368
+ adapterName: manifest.adapterName,
390
369
  logging,
391
- markdown: settings.config.markdown,
370
+ markdown: manifest.markdown,
392
371
  mode: opts.mode,
393
- renderers,
394
- clientDirectives: settings.clientDirectives,
372
+ renderers: manifest.renderers,
373
+ clientDirectives: manifest.clientDirectives,
374
+ compressHTML: manifest.compressHTML,
395
375
  async resolve(specifier) {
396
376
  const hashedFilePath = internals.entrySpecifierToBundleMap.get(specifier);
397
377
  if (typeof hashedFilePath !== "string") {
@@ -400,22 +380,17 @@ async function generatePath(pathname, opts, gopts, onRequest) {
400
380
  }
401
381
  throw new Error(`Cannot find the built path for ${specifier}`);
402
382
  }
403
- return createAssetLink(
404
- hashedFilePath,
405
- settings.config.base,
406
- settings.config.build.assetsPrefix
407
- );
383
+ return createAssetLink(hashedFilePath, manifest.base, manifest.assetsPrefix);
408
384
  },
409
385
  routeCache,
410
- site: settings.config.site ? new URL(settings.config.base, settings.config.site).toString() : settings.config.site,
386
+ site: manifest.site,
411
387
  ssr,
412
388
  streaming: true
413
389
  });
414
390
  const renderContext = await createRenderContext({
415
- origin,
416
391
  pathname,
417
392
  request: createRequest({ url, headers: new Headers(), logging, ssr }),
418
- componentMetadata: internals.componentMetadata,
393
+ componentMetadata: manifest.componentMetadata,
419
394
  scripts,
420
395
  styles,
421
396
  links,
@@ -431,7 +406,6 @@ async function generatePath(pathname, opts, gopts, onRequest) {
431
406
  endpointHandler,
432
407
  env,
433
408
  renderContext,
434
- logging,
435
409
  onRequest
436
410
  );
437
411
  if (result.type === "response") {
@@ -464,7 +438,6 @@ async function generatePath(pathname, opts, gopts, onRequest) {
464
438
  mod,
465
439
  renderContext,
466
440
  env,
467
- isCompressHTML: settings.config.compressHTML,
468
441
  cookies: apiContext.cookies
469
442
  });
470
443
  }
@@ -474,7 +447,6 @@ async function generatePath(pathname, opts, gopts, onRequest) {
474
447
  mod,
475
448
  renderContext,
476
449
  env,
477
- isCompressHTML: settings.config.compressHTML,
478
450
  cookies: apiContext.cookies
479
451
  });
480
452
  }
@@ -507,8 +479,25 @@ async function generatePath(pathname, opts, gopts, onRequest) {
507
479
  await fs.promises.mkdir(outFolder, { recursive: true });
508
480
  await fs.promises.writeFile(outFile, body, encoding ?? "utf-8");
509
481
  }
482
+ function generateRuntimeManifest(settings, internals, renderers) {
483
+ return {
484
+ assets: /* @__PURE__ */ new Set(),
485
+ entryModules: {},
486
+ routes: [],
487
+ adapterName: "",
488
+ markdown: settings.config.markdown,
489
+ clientDirectives: settings.clientDirectives,
490
+ compressHTML: settings.config.compressHTML,
491
+ renderers,
492
+ base: settings.config.base,
493
+ assetsPrefix: settings.config.build.assetsPrefix,
494
+ site: settings.config.site ? new URL(settings.config.base, settings.config.site).toString() : settings.config.site,
495
+ componentMetadata: internals.componentMetadata
496
+ };
497
+ }
510
498
  export {
511
499
  chunkIsPage,
512
500
  generatePages,
501
+ generateRuntimeManifest,
513
502
  rootRelativeFacadeId
514
503
  };
@@ -1,5 +1,5 @@
1
- import type { AstroSettings, RuntimeMode } from '../../@types/astro';
2
1
  import type yargs from 'yargs-parser';
2
+ import type { AstroSettings, RuntimeMode } from '../../@types/astro';
3
3
  import { type LogOptions } from '../logger/core.js';
4
4
  export interface BuildOptions {
5
5
  mode?: RuntimeMode;
@@ -8,7 +8,7 @@ import {
8
8
  runHookConfigSetup
9
9
  } from "../../integrations/index.js";
10
10
  import { createVite } from "../create-vite.js";
11
- import { debug, info, levels, timerMessage } from "../logger/core.js";
11
+ import { debug, info, levels, timerMessage, warn } from "../logger/core.js";
12
12
  import { printHelp } from "../messages.js";
13
13
  import { apply as applyPolyfill } from "../polyfill.js";
14
14
  import { RouteCache } from "../render/route-cache.js";
@@ -158,6 +158,24 @@ class AstroBuilder {
158
158
  `the outDir cannot be the root folder. Please build to a folder such as dist.`
159
159
  );
160
160
  }
161
+ if (config.build.split === true) {
162
+ if (config.output === "static") {
163
+ warn(
164
+ this.logging,
165
+ "configuration",
166
+ 'The option `build.split` won\'t take effect, because `output` is not `"server"` or `"hybrid"`.'
167
+ );
168
+ }
169
+ }
170
+ if (config.build.excludeMiddleware === true) {
171
+ if (config.output === "static") {
172
+ warn(
173
+ this.logging,
174
+ "configuration",
175
+ 'The option `build.excludeMiddleware` won\'t take effect, because `output` is not `"server"` or `"hybrid"`.'
176
+ );
177
+ }
178
+ }
161
179
  }
162
180
  /** Stats */
163
181
  async printStats({
@@ -64,6 +64,7 @@ export interface BuildInternals {
64
64
  entryPoints: Map<RouteData, URL>;
65
65
  ssrSplitEntryChunks: Map<string, Rollup.OutputChunk>;
66
66
  componentMetadata: SSRResult['componentMetadata'];
67
+ middlewareEntryPoint?: URL;
67
68
  }
68
69
  /**
69
70
  * Creates internal maps used to coordinate the CSS and HTML plugins.