astro 5.0.1 → 5.0.3

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 (38) hide show
  1. package/components/Image.astro +2 -2
  2. package/components/Picture.astro +2 -2
  3. package/dist/assets/utils/resolveImports.js +1 -1
  4. package/dist/cli/info/index.d.ts +2 -0
  5. package/dist/cli/info/index.js +71 -26
  6. package/dist/container/index.js +2 -1
  7. package/dist/content/content-layer.js +3 -3
  8. package/dist/content/vite-plugin-content-virtual-mod.js +2 -4
  9. package/dist/core/app/index.d.ts +1 -0
  10. package/dist/core/app/index.js +23 -16
  11. package/dist/core/build/generate.js +4 -2
  12. package/dist/core/build/index.js +2 -2
  13. package/dist/core/build/plugins/plugin-renderers.js +1 -1
  14. package/dist/core/build/plugins/plugin-ssr.js +1 -1
  15. package/dist/core/build/static-build.d.ts +2 -1
  16. package/dist/core/build/static-build.js +13 -15
  17. package/dist/core/config/schema.d.ts +18 -20
  18. package/dist/core/config/schema.js +14 -8
  19. package/dist/core/config/validate.js +2 -1
  20. package/dist/core/constants.js +1 -1
  21. package/dist/core/dev/container.js +2 -1
  22. package/dist/core/dev/dev.js +2 -2
  23. package/dist/core/errors/errors-data.d.ts +15 -15
  24. package/dist/core/errors/errors-data.js +8 -8
  25. package/dist/core/errors/zod-error-map.js +46 -26
  26. package/dist/core/messages.js +6 -4
  27. package/dist/core/render-context.d.ts +3 -2
  28. package/dist/core/render-context.js +14 -8
  29. package/dist/core/request.d.ts +2 -1
  30. package/dist/core/request.js +3 -6
  31. package/dist/core/sync/index.d.ts +1 -0
  32. package/dist/core/sync/index.js +3 -0
  33. package/dist/i18n/index.js +2 -2
  34. package/dist/runtime/server/render/component.js +0 -6
  35. package/dist/types/public/config.d.ts +3 -3
  36. package/dist/vite-plugin-astro-server/route.js +6 -4
  37. package/package.json +1 -1
  38. package/templates/content/types.d.ts +3 -1
@@ -1,4 +1,4 @@
1
- const ASTRO_VERSION = "5.0.1";
1
+ const ASTRO_VERSION = "5.0.3";
2
2
  const REROUTE_DIRECTIVE_HEADER = "X-Astro-Reroute";
3
3
  const REWRITE_DIRECTIVE_HEADER_KEY = "X-Astro-Rewrite";
4
4
  const REWRITE_DIRECTIVE_HEADER_VALUE = "yes";
@@ -66,7 +66,8 @@ async function createContainer({
66
66
  mode,
67
67
  logger,
68
68
  skip: {
69
- content: true
69
+ content: true,
70
+ cleanup: true
70
71
  },
71
72
  force: inlineConfig?.force,
72
73
  manifest
@@ -22,7 +22,7 @@ async function dev(inlineConfig) {
22
22
  await telemetry.record([]);
23
23
  const restart = await createContainerWithAutomaticRestart({ inlineConfig, fs });
24
24
  const logger = restart.container.logger;
25
- const currentVersion = "5.0.1";
25
+ const currentVersion = "5.0.3";
26
26
  const isPrerelease = currentVersion.includes("-");
27
27
  if (!isPrerelease) {
28
28
  try {
@@ -69,7 +69,7 @@ async function dev(inlineConfig) {
69
69
  await attachContentServerListeners(restart.container);
70
70
  let store;
71
71
  try {
72
- const dataStoreFile = getDataStoreFile(restart.container.settings);
72
+ const dataStoreFile = getDataStoreFile(restart.container.settings, true);
73
73
  if (existsSync(dataStoreFile)) {
74
74
  store = await MutableDataStore.fromFile(dataStoreFile);
75
75
  }
@@ -30,7 +30,7 @@ export declare const UnknownCompilerError: {
30
30
  * @docs
31
31
  * @see
32
32
  * - [Official integrations](https://docs.astro.build/en/guides/integrations-guide/#official-integrations)
33
- * - [Astro.clientAddress](https://docs.astro.build/en/reference/api-reference/#astroclientaddress)
33
+ * - [Astro.clientAddress](https://docs.astro.build/en/reference/api-reference/#clientaddress)
34
34
  * @description
35
35
  * The adapter you're using unfortunately does not support `Astro.clientAddress`.
36
36
  */
@@ -43,7 +43,7 @@ export declare const ClientAddressNotAvailable: {
43
43
  * @docs
44
44
  * @see
45
45
  * - [On-demand rendering](https://docs.astro.build/en/guides/on-demand-rendering/)
46
- * - [Astro.clientAddress](https://docs.astro.build/en/reference/api-reference/#astroclientaddress)
46
+ * - [Astro.clientAddress](https://docs.astro.build/en/reference/api-reference/#clientaddress)
47
47
  * @description
48
48
  * The `Astro.clientAddress` property cannot be used inside prerendered routes.
49
49
  */
@@ -56,7 +56,7 @@ export declare const PrerenderClientAddressNotAvailable: {
56
56
  * @docs
57
57
  * @see
58
58
  * - [Enabling SSR in Your Project](https://docs.astro.build/en/guides/on-demand-rendering/)
59
- * - [Astro.clientAddress](https://docs.astro.build/en/reference/api-reference/#astroclientaddress)
59
+ * - [Astro.clientAddress](https://docs.astro.build/en/reference/api-reference/#clientaddress)
60
60
  * @description
61
61
  * The `Astro.clientAddress` property is only available when [Server-side rendering](https://docs.astro.build/en/guides/on-demand-rendering/) is enabled.
62
62
  *
@@ -71,7 +71,7 @@ export declare const StaticClientAddressNotAvailable: {
71
71
  /**
72
72
  * @docs
73
73
  * @see
74
- * - [getStaticPaths()](https://docs.astro.build/en/reference/api-reference/#getstaticpaths)
74
+ * - [getStaticPaths()](https://docs.astro.build/en/reference/routing-reference/#getstaticpaths)
75
75
  * @description
76
76
  * A [dynamic route](https://docs.astro.build/en/guides/routing/#dynamic-routes) was matched, but no corresponding path was found for the requested parameters. This is often caused by a typo in either the generated or the requested path.
77
77
  */
@@ -176,7 +176,7 @@ export declare const NoClientOnlyHint: {
176
176
  /**
177
177
  * @docs
178
178
  * @see
179
- * - [`getStaticPaths()`](https://docs.astro.build/en/reference/api-reference/#getstaticpaths)
179
+ * - [`getStaticPaths()`](https://docs.astro.build/en/reference/routing-reference/#getstaticpaths)
180
180
  * - [`params`](https://docs.astro.build/en/reference/api-reference/#params)
181
181
  * @description
182
182
  * The `params` property in `getStaticPaths`'s return value (an array of objects) should also be an object.
@@ -201,7 +201,7 @@ export declare const InvalidGetStaticPathParam: {
201
201
  /**
202
202
  * @docs
203
203
  * @see
204
- * - [`getStaticPaths()`](https://docs.astro.build/en/reference/api-reference/#getstaticpaths)
204
+ * - [`getStaticPaths()`](https://docs.astro.build/en/reference/routing-reference/#getstaticpaths)
205
205
  * @description
206
206
  * `getStaticPaths`'s return value must be an array of objects. In most cases, this error happens because an array of array was returned. Using [`.flatMap()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flatMap) or a [`.flat()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flat) call may be useful.
207
207
  *
@@ -223,7 +223,7 @@ export declare const InvalidGetStaticPathsEntry: {
223
223
  /**
224
224
  * @docs
225
225
  * @see
226
- * - [`getStaticPaths()`](https://docs.astro.build/en/reference/api-reference/#getstaticpaths)
226
+ * - [`getStaticPaths()`](https://docs.astro.build/en/reference/routing-reference/#getstaticpaths)
227
227
  * - [`params`](https://docs.astro.build/en/reference/api-reference/#params)
228
228
  * @description
229
229
  * `getStaticPaths`'s return value must be an array of objects.
@@ -246,7 +246,7 @@ export declare const InvalidGetStaticPathsReturn: {
246
246
  /**
247
247
  * @docs
248
248
  * @see
249
- * - [`getStaticPaths()`](https://docs.astro.build/en/reference/api-reference/#getstaticpaths)
249
+ * - [`getStaticPaths()`](https://docs.astro.build/en/reference/routing-reference/#getstaticpaths)
250
250
  * - [`params`](https://docs.astro.build/en/reference/api-reference/#params)
251
251
  * @description
252
252
  * Every route specified by `getStaticPaths` require a `params` property specifying the path parameters needed to match the route.
@@ -272,7 +272,7 @@ export declare const GetStaticPathsExpectedParams: {
272
272
  /**
273
273
  * @docs
274
274
  * @see
275
- * - [`getStaticPaths()`](https://docs.astro.build/en/reference/api-reference/#getstaticpaths)
275
+ * - [`getStaticPaths()`](https://docs.astro.build/en/reference/routing-reference/#getstaticpaths)
276
276
  * - [`params`](https://docs.astro.build/en/reference/api-reference/#params)
277
277
  * @description
278
278
  * Since `params` are encoded into the URL, only certain types are supported as values.
@@ -313,7 +313,7 @@ export declare const GetStaticPathsInvalidRouteParam: {
313
313
  * @docs
314
314
  * @see
315
315
  * - [Dynamic Routes](https://docs.astro.build/en/guides/routing/#dynamic-routes)
316
- * - [`getStaticPaths()`](https://docs.astro.build/en/reference/api-reference/#getstaticpaths)
316
+ * - [`getStaticPaths()`](https://docs.astro.build/en/reference/routing-reference/#getstaticpaths)
317
317
  * - [Server-side Rendering](https://docs.astro.build/en/guides/on-demand-rendering/)
318
318
  * @description
319
319
  * In [Static Mode](https://docs.astro.build/en/guides/routing/#static-ssg-mode), all routes must be determined at build time. As such, dynamic routes must `export` a `getStaticPaths` function returning the different paths to generate.
@@ -367,7 +367,7 @@ export declare const AdapterSupportOutputMismatch: {
367
367
  /**
368
368
  * @docs
369
369
  * @see
370
- * - [On-demand Rendering](https://5-0-0-beta.docs.astro.build/en/guides/on-demand-rendering/)
370
+ * - [On-demand Rendering](https://docs.astro.build/en/guides/on-demand-rendering/)
371
371
  * @description
372
372
  * To use server islands, the same constraints exist as for sever-side rendering, so an adapter is needed.
373
373
  */
@@ -526,7 +526,7 @@ export declare const UnsupportedImageConversion: {
526
526
  /**
527
527
  * @docs
528
528
  * @see
529
- * - [`getStaticPaths()`](https://docs.astro.build/en/reference/api-reference/#getstaticpaths)
529
+ * - [`getStaticPaths()`](https://docs.astro.build/en/reference/routing-reference/#getstaticpaths)
530
530
  * - [`params`](https://docs.astro.build/en/reference/api-reference/#params)
531
531
  * @description
532
532
  * The endpoint is prerendered with an `undefined` param so the generated path will collide with another route.
@@ -1112,7 +1112,7 @@ export declare const ServerOnlyModule: {
1112
1112
  *
1113
1113
  * @see
1114
1114
  * - [Request.clone()](https://developer.mozilla.org/en-US/docs/Web/API/Request/clone)
1115
- * - [Astro.rewrite](https://docs.astro.build/en/reference/api-reference/#astrorewrite)
1115
+ * - [Astro.rewrite](https://docs.astro.build/en/reference/api-reference/#rewrite)
1116
1116
  */
1117
1117
  export declare const RewriteWithBodyUsed: {
1118
1118
  name: string;
@@ -1500,7 +1500,7 @@ export declare const UnsupportedConfigTransformError: {
1500
1500
  /**
1501
1501
  * @docs
1502
1502
  * @see
1503
- * - [On-demand rendering](https://5-0-0-beta.docs.astro.build/en/guides/on-demand-rendering/)
1503
+ * - [On-demand rendering](https://docs.astro.build/en/guides/on-demand-rendering/)
1504
1504
  * @description
1505
1505
  * Your project must have a server output to create backend functions with Actions.
1506
1506
  */
@@ -1537,7 +1537,7 @@ export declare const ActionNotFoundError: {
1537
1537
  /**
1538
1538
  * @docs
1539
1539
  * @see
1540
- * - [`Astro.callAction()` reference](https://docs.astro.build/en/reference/api-reference/#astrocallaction)
1540
+ * - [`Astro.callAction()` reference](https://docs.astro.build/en/reference/api-reference/#callaction)
1541
1541
  * @description
1542
1542
  * Action called from a server page or endpoint without using `Astro.callAction()`.
1543
1543
  */
@@ -63,31 +63,31 @@ const InvalidGetStaticPathParam = {
63
63
  name: "InvalidGetStaticPathParam",
64
64
  title: "Invalid value returned by a `getStaticPaths` path.",
65
65
  message: (paramType) => `Invalid params given to \`getStaticPaths\` path. Expected an \`object\`, got \`${paramType}\``,
66
- hint: "See https://docs.astro.build/en/reference/api-reference/#getstaticpaths for more information on getStaticPaths."
66
+ hint: "See https://docs.astro.build/en/reference/routing-reference/#getstaticpaths for more information on getStaticPaths."
67
67
  };
68
68
  const InvalidGetStaticPathsEntry = {
69
69
  name: "InvalidGetStaticPathsEntry",
70
70
  title: "Invalid entry inside getStaticPath's return value",
71
71
  message: (entryType) => `Invalid entry returned by getStaticPaths. Expected an object, got \`${entryType}\``,
72
- hint: "If you're using a `.map` call, you might be looking for `.flatMap()` instead. See https://docs.astro.build/en/reference/api-reference/#getstaticpaths for more information on getStaticPaths."
72
+ hint: "If you're using a `.map` call, you might be looking for `.flatMap()` instead. See https://docs.astro.build/en/reference/routing-reference/#getstaticpaths for more information on getStaticPaths."
73
73
  };
74
74
  const InvalidGetStaticPathsReturn = {
75
75
  name: "InvalidGetStaticPathsReturn",
76
76
  title: "Invalid value returned by getStaticPaths.",
77
77
  message: (returnType) => `Invalid type returned by \`getStaticPaths\`. Expected an \`array\`, got \`${returnType}\``,
78
- hint: "See https://docs.astro.build/en/reference/api-reference/#getstaticpaths for more information on getStaticPaths."
78
+ hint: "See https://docs.astro.build/en/reference/routing-reference/#getstaticpaths for more information on getStaticPaths."
79
79
  };
80
80
  const GetStaticPathsExpectedParams = {
81
81
  name: "GetStaticPathsExpectedParams",
82
82
  title: "Missing params property on `getStaticPaths` route.",
83
83
  message: "Missing or empty required `params` property on `getStaticPaths` route.",
84
- hint: "See https://docs.astro.build/en/reference/api-reference/#getstaticpaths for more information on getStaticPaths."
84
+ hint: "See https://docs.astro.build/en/reference/routing-reference/#getstaticpaths for more information on getStaticPaths."
85
85
  };
86
86
  const GetStaticPathsInvalidRouteParam = {
87
87
  name: "GetStaticPathsInvalidRouteParam",
88
88
  title: "Invalid value for `getStaticPaths` route parameter.",
89
89
  message: (key, value, valueType) => `Invalid getStaticPaths route parameter for \`${key}\`. Expected undefined, a string or a number, received \`${valueType}\` (\`${value}\`)`,
90
- hint: "See https://docs.astro.build/en/reference/api-reference/#getstaticpaths for more information on getStaticPaths."
90
+ hint: "See https://docs.astro.build/en/reference/routing-reference/#getstaticpaths for more information on getStaticPaths."
91
91
  };
92
92
  const GetStaticPathsRequired = {
93
93
  name: "GetStaticPathsRequired",
@@ -117,7 +117,7 @@ const NoAdapterInstalledServerIslands = {
117
117
  name: "NoAdapterInstalledServerIslands",
118
118
  title: "Cannot use Server Islands without an adapter.",
119
119
  message: `Cannot use server islands without an adapter. Please install and configure the appropriate server adapter for your final deployment.`,
120
- hint: "See https://5-0-0-beta.docs.astro.build/en/guides/on-demand-rendering/ for more information."
120
+ hint: "See https://docs.astro.build/en/guides/on-demand-rendering/ for more information."
121
121
  };
122
122
  const NoMatchingImport = {
123
123
  name: "NoMatchingImport",
@@ -591,7 +591,7 @@ const ActionsWithoutServerOutputError = {
591
591
  name: "ActionsWithoutServerOutputError",
592
592
  title: "Actions must be used with server output.",
593
593
  message: "A server is required to create callable backend functions. To deploy routes to a server, add an adapter to your Astro config and configure your route for on-demand rendering",
594
- hint: "Add an adapter and enable on-demand rendering: https://5-0-0-beta.docs.astro.build/en/guides/on-demand-rendering/"
594
+ hint: "Add an adapter and enable on-demand rendering: https://docs.astro.build/en/guides/on-demand-rendering/"
595
595
  };
596
596
  const ActionsReturnedInvalidDataError = {
597
597
  name: "ActionsReturnedInvalidDataError",
@@ -609,7 +609,7 @@ const ActionCalledFromServerError = {
609
609
  name: "ActionCalledFromServerError",
610
610
  title: "Action unexpected called from the server.",
611
611
  message: "Action called from a server page or endpoint without using `Astro.callAction()`. This wrapper must be used to call actions from server code.",
612
- hint: "See the `Astro.callAction()` reference for usage examples: https://docs.astro.build/en/reference/api-reference/#astrocallaction"
612
+ hint: "See the `Astro.callAction()` reference for usage examples: https://docs.astro.build/en/reference/api-reference/#callaction"
613
613
  };
614
614
  const UnknownError = { name: "UnknownError", title: "Unknown Error." };
615
615
  export {
@@ -16,24 +16,45 @@ const errorMap = (baseError, ctx) => {
16
16
  }
17
17
  }
18
18
  }
19
- let messages = [
20
- prefix(
21
- baseErrorPath,
22
- typeOrLiteralErrByPath.size ? "Did not match union:" : "Did not match union."
23
- )
24
- ];
19
+ const messages = [prefix(baseErrorPath, "Did not match union.")];
20
+ const details = [...typeOrLiteralErrByPath.entries()].filter(([, error]) => error.expected.length === baseError.unionErrors.length).map(
21
+ ([key, error]) => key === baseErrorPath ? (
22
+ // Avoid printing the key again if it's a base error
23
+ `> ${getTypeOrLiteralMsg(error)}`
24
+ ) : `> ${prefix(key, getTypeOrLiteralMsg(error))}`
25
+ );
26
+ if (details.length === 0) {
27
+ const expectedShapes = [];
28
+ for (const unionError of baseError.unionErrors) {
29
+ const expectedShape = [];
30
+ for (const issue of unionError.issues) {
31
+ if (issue.code === "invalid_union") {
32
+ return errorMap(issue, ctx);
33
+ }
34
+ const relativePath = flattenErrorPath(issue.path).replace(baseErrorPath, "").replace(leadingPeriod, "");
35
+ if ("expected" in issue && typeof issue.expected === "string") {
36
+ expectedShape.push(
37
+ relativePath ? `${relativePath}: ${issue.expected}` : issue.expected
38
+ );
39
+ } else {
40
+ expectedShape.push(relativePath);
41
+ }
42
+ }
43
+ if (expectedShape.length === 1 && !expectedShape[0]?.includes(":")) {
44
+ expectedShapes.push(expectedShape.join(""));
45
+ } else {
46
+ expectedShapes.push(`{ ${expectedShape.join("; ")} }`);
47
+ }
48
+ }
49
+ if (expectedShapes.length) {
50
+ details.push("> Expected type `" + expectedShapes.join(" | ") + "`");
51
+ details.push("> Received `" + stringify(ctx.data) + "`");
52
+ }
53
+ }
25
54
  return {
26
- message: messages.concat(
27
- [...typeOrLiteralErrByPath.entries()].filter(([, error]) => error.expected.length === baseError.unionErrors.length).map(
28
- ([key, error]) => key === baseErrorPath ? (
29
- // Avoid printing the key again if it's a base error
30
- `> ${getTypeOrLiteralMsg(error)}`
31
- ) : `> ${prefix(key, getTypeOrLiteralMsg(error))}`
32
- )
33
- ).join("\n")
55
+ message: messages.concat(details).join("\n")
34
56
  };
35
- }
36
- if (baseError.code === "invalid_literal" || baseError.code === "invalid_type") {
57
+ } else if (baseError.code === "invalid_literal" || baseError.code === "invalid_type") {
37
58
  return {
38
59
  message: prefix(
39
60
  baseErrorPath,
@@ -51,26 +72,25 @@ const errorMap = (baseError, ctx) => {
51
72
  }
52
73
  };
53
74
  const getTypeOrLiteralMsg = (error) => {
54
- if (error.received === "undefined") return "Required";
75
+ if (typeof error.received === "undefined" || error.received === "undefined") return "Required";
55
76
  const expectedDeduped = new Set(error.expected);
56
77
  switch (error.code) {
57
78
  case "invalid_type":
58
- return `Expected type \`${unionExpectedVals(expectedDeduped)}\`, received ${JSON.stringify(
79
+ return `Expected type \`${unionExpectedVals(expectedDeduped)}\`, received \`${stringify(
59
80
  error.received
60
- )}`;
81
+ )}\``;
61
82
  case "invalid_literal":
62
- return `Expected \`${unionExpectedVals(expectedDeduped)}\`, received ${JSON.stringify(
83
+ return `Expected \`${unionExpectedVals(expectedDeduped)}\`, received \`${stringify(
63
84
  error.received
64
- )}`;
85
+ )}\``;
65
86
  }
66
87
  };
67
88
  const prefix = (key, msg) => key.length ? `**${key}**: ${msg}` : msg;
68
- const unionExpectedVals = (expectedVals) => [...expectedVals].map((expectedVal, idx) => {
69
- if (idx === 0) return JSON.stringify(expectedVal);
70
- const sep = " | ";
71
- return `${sep}${JSON.stringify(expectedVal)}`;
72
- }).join("");
89
+ const unionExpectedVals = (expectedVals) => [...expectedVals].map((expectedVal) => stringify(expectedVal)).join(" | ");
73
90
  const flattenErrorPath = (errorPath) => errorPath.join(".");
91
+ const stringify = (val) => JSON.stringify(val, null, 1).split(newlinePlusWhitespace).join(" ");
92
+ const newlinePlusWhitespace = /\n\s*/;
93
+ const leadingPeriod = /^\./;
74
94
  export {
75
95
  errorMap
76
96
  };
@@ -38,7 +38,7 @@ function serverStart({
38
38
  host,
39
39
  base
40
40
  }) {
41
- const version = "5.0.1";
41
+ const version = "5.0.3";
42
42
  const localPrefix = `${dim("\u2503")} Local `;
43
43
  const networkPrefix = `${dim("\u2503")} Network `;
44
44
  const emptyPrefix = " ".repeat(11);
@@ -179,13 +179,15 @@ function getNetworkLogging(host) {
179
179
  return "visible";
180
180
  }
181
181
  }
182
+ const codeRegex = /`([^`]+)`/g;
182
183
  function formatConfigErrorMessage(err) {
183
184
  const errorList = err.issues.map(
184
- (issue) => ` ! ${bold(issue.path.join("."))} ${red(issue.message + ".")}`
185
+ (issue) => `! ${renderErrorMarkdown(issue.message, "cli")}`.replaceAll(codeRegex, blue("$1")).split("\n").map((line, index) => index === 0 ? red(line) : " " + line).join("\n")
185
186
  );
186
187
  return `${red("[config]")} Astro found issue(s) with your configuration:
188
+
187
189
  ${errorList.join(
188
- "\n"
190
+ "\n\n"
189
191
  )}`;
190
192
  }
191
193
  const STACK_LINE_REGEXP = /^\s+at /g;
@@ -274,7 +276,7 @@ function printHelp({
274
276
  message.push(
275
277
  linebreak(),
276
278
  ` ${bgGreen(black(` ${commandName} `))} ${green(
277
- `v${"5.0.1"}`
279
+ `v${"5.0.3"}`
278
280
  )} ${headline}`
279
281
  );
280
282
  }
@@ -19,6 +19,7 @@ export declare class RenderContext {
19
19
  request: Request;
20
20
  routeData: RouteData;
21
21
  status: number;
22
+ clientAddress: string | undefined;
22
23
  protected cookies: AstroCookies;
23
24
  params: import("../types/public/common.js").Params;
24
25
  protected url: URL;
@@ -33,7 +34,7 @@ export declare class RenderContext {
33
34
  * A safety net in case of loops
34
35
  */
35
36
  counter: number;
36
- static create({ locals, middleware, pathname, pipeline, request, routeData, status, props, partial, }: Pick<RenderContext, 'pathname' | 'pipeline' | 'request' | 'routeData'> & Partial<Pick<RenderContext, 'locals' | 'middleware' | 'status' | 'props' | 'partial'>>): Promise<RenderContext>;
37
+ static create({ locals, middleware, pathname, pipeline, request, routeData, clientAddress, status, props, partial, }: Pick<RenderContext, 'pathname' | 'pipeline' | 'request' | 'routeData' | 'clientAddress'> & Partial<Pick<RenderContext, 'locals' | 'middleware' | 'status' | 'props' | 'partial'>>): Promise<RenderContext>;
37
38
  /**
38
39
  * The main function of the RenderContext.
39
40
  *
@@ -59,7 +60,7 @@ export declare class RenderContext {
59
60
  */
60
61
  createAstro(result: SSRResult, astroStaticPartial: AstroGlobalPartial, props: Record<string, any>, slotValues: Record<string, any> | null): AstroGlobal;
61
62
  createAstroPagePartial(result: SSRResult, astroStaticPartial: AstroGlobalPartial): Omit<AstroGlobal, 'props' | 'self' | 'slots'>;
62
- clientAddress(): string;
63
+ getClientAddress(): string;
63
64
  computeCurrentLocale(): string | undefined;
64
65
  computePreferredLocale(): string | undefined;
65
66
  computePreferredLocaleList(): string[] | undefined;
@@ -29,7 +29,7 @@ import { copyRequest, getOriginPathname, setOriginPathname } from "./routing/rew
29
29
  import { SERVER_ISLAND_COMPONENT } from "./server-islands/endpoint.js";
30
30
  const apiContextRoutesSymbol = Symbol.for("context.routes");
31
31
  class RenderContext {
32
- constructor(pipeline, locals, middleware, pathname, request, routeData, status, cookies = new AstroCookies(request), params = getParams(routeData, pathname), url = new URL(request.url), props = {}, partial = void 0) {
32
+ constructor(pipeline, locals, middleware, pathname, request, routeData, status, clientAddress, cookies = new AstroCookies(request), params = getParams(routeData, pathname), url = new URL(request.url), props = {}, partial = void 0) {
33
33
  this.pipeline = pipeline;
34
34
  this.locals = locals;
35
35
  this.middleware = middleware;
@@ -37,6 +37,7 @@ class RenderContext {
37
37
  this.request = request;
38
38
  this.routeData = routeData;
39
39
  this.status = status;
40
+ this.clientAddress = clientAddress;
40
41
  this.cookies = cookies;
41
42
  this.params = params;
42
43
  this.url = url;
@@ -58,6 +59,7 @@ class RenderContext {
58
59
  pipeline,
59
60
  request,
60
61
  routeData,
62
+ clientAddress,
61
63
  status = 200,
62
64
  props,
63
65
  partial = void 0
@@ -72,6 +74,7 @@ class RenderContext {
72
74
  request,
73
75
  routeData,
74
76
  status,
77
+ clientAddress,
75
78
  void 0,
76
79
  void 0,
77
80
  void 0,
@@ -245,7 +248,7 @@ class RenderContext {
245
248
  routePattern: this.routeData.route,
246
249
  isPrerendered: this.routeData.prerender,
247
250
  get clientAddress() {
248
- return renderContext.clientAddress();
251
+ return renderContext.getClientAddress();
249
252
  },
250
253
  get currentLocale() {
251
254
  return renderContext.computeCurrentLocale();
@@ -393,7 +396,7 @@ class RenderContext {
393
396
  isPrerendered: this.routeData.prerender,
394
397
  cookies,
395
398
  get clientAddress() {
396
- return renderContext.clientAddress();
399
+ return renderContext.getClientAddress();
397
400
  },
398
401
  get currentLocale() {
399
402
  return renderContext.computeCurrentLocale();
@@ -421,14 +424,17 @@ class RenderContext {
421
424
  }
422
425
  };
423
426
  }
424
- clientAddress() {
425
- const { pipeline, request } = this;
427
+ getClientAddress() {
428
+ const { pipeline, request, routeData, clientAddress } = this;
429
+ if (routeData.prerender) {
430
+ throw new AstroError(AstroErrorData.PrerenderClientAddressNotAvailable);
431
+ }
432
+ if (clientAddress) {
433
+ return clientAddress;
434
+ }
426
435
  if (clientAddressSymbol in request) {
427
436
  return Reflect.get(request, clientAddressSymbol);
428
437
  }
429
- if (request.body === null) {
430
- throw new AstroError(AstroErrorData.PrerenderClientAddressNotAvailable);
431
- }
432
438
  if (pipeline.adapterName) {
433
439
  throw new AstroError({
434
440
  ...AstroErrorData.ClientAddressNotAvailable,
@@ -18,6 +18,7 @@ export interface CreateRequestOptions {
18
18
  * @default false
19
19
  */
20
20
  isPrerendered?: boolean;
21
+ routePattern: string;
21
22
  }
22
23
  /**
23
24
  * Used by astro internals to create a web standard request object.
@@ -26,5 +27,5 @@ export interface CreateRequestOptions {
26
27
  *
27
28
  * This is used by the static build to create fake requests for prerendering, and by the dev server to convert node requests into the standard request object.
28
29
  */
29
- export declare function createRequest({ url, headers, clientAddress, method, body, logger, locals, isPrerendered, }: CreateRequestOptions): Request;
30
+ export declare function createRequest({ url, headers, method, body, logger, locals, isPrerendered, routePattern, }: CreateRequestOptions): Request;
30
31
  export {};
@@ -1,14 +1,13 @@
1
- const clientAddressSymbol = Symbol.for("astro.clientAddress");
2
1
  const clientLocalsSymbol = Symbol.for("astro.locals");
3
2
  function createRequest({
4
3
  url,
5
4
  headers,
6
- clientAddress,
7
5
  method = "GET",
8
6
  body = void 0,
9
7
  logger,
10
8
  locals,
11
- isPrerendered = false
9
+ isPrerendered = false,
10
+ routePattern
12
11
  }) {
13
12
  const headersObj = isPrerendered ? void 0 : headers instanceof Headers ? headers : new Headers(
14
13
  // Filter out HTTP/2 pseudo-headers. These are internally-generated headers added to all HTTP/2 requests with trusted metadata about the request.
@@ -35,7 +34,7 @@ function createRequest({
35
34
  get() {
36
35
  logger.warn(
37
36
  null,
38
- `\`Astro.request.headers\` is not available on prerendered pages. If you need access to request headers, make sure that the page is server rendered using \`export const prerender = false;\` or by setting \`output\` to \`"server"\` in your Astro config to make all your pages server rendered.`
37
+ `\`Astro.request.headers\` was used when rendering the route \`${routePattern}'\`. \`Astro.request.headers\` is not available on prerendered pages. If you need access to request headers, make sure that the page is server-rendered using \`export const prerender = false;\` or by setting \`output\` to \`"server"\` in your Astro config to make all your pages server-rendered by default.`
39
38
  );
40
39
  return _headers;
41
40
  },
@@ -43,8 +42,6 @@ function createRequest({
43
42
  _headers = newHeaders;
44
43
  }
45
44
  });
46
- } else if (clientAddress) {
47
- Reflect.set(request, clientAddressSymbol, clientAddress);
48
45
  }
49
46
  Reflect.set(request, clientLocalsSymbol, locals ?? {});
50
47
  return request;
@@ -9,6 +9,7 @@ export type SyncOptions = {
9
9
  force?: boolean;
10
10
  skip?: {
11
11
  content?: boolean;
12
+ cleanup?: boolean;
12
13
  };
13
14
  manifest: ManifestData;
14
15
  };
@@ -98,6 +98,9 @@ async function syncInternal({
98
98
  store
99
99
  });
100
100
  await contentLayer.sync();
101
+ if (!skip?.cleanup) {
102
+ contentLayer.dispose();
103
+ }
101
104
  settings.timer.end("Sync content layer");
102
105
  } else {
103
106
  const paths = getContentPaths(settings.config, fs);
@@ -239,9 +239,9 @@ function redirectToFallback({
239
239
  newPathname = context.url.pathname.replace(`/${urlLocale}`, `/${pathFallbackLocale}`);
240
240
  }
241
241
  if (fallbackType === "rewrite") {
242
- return await context.rewrite(newPathname);
242
+ return await context.rewrite(newPathname + context.url.search);
243
243
  } else {
244
- return context.redirect(newPathname);
244
+ return context.redirect(newPathname + context.url.search);
245
245
  }
246
246
  }
247
247
  }
@@ -209,12 +209,6 @@ If you're still stuck, please open an issue on GitHub or join us at https://astr
209
209
  }
210
210
  } else {
211
211
  if (metadata.hydrate === "only") {
212
- const rendererName = rendererAliases.has(metadata.hydrateArgs) ? rendererAliases.get(metadata.hydrateArgs) : metadata.hydrateArgs;
213
- if (!clientOnlyValues.has(rendererName)) {
214
- console.warn(
215
- `The client:only directive for ${metadata.displayName} is not recognized. The renderer ${renderer.name} will be used. If you intended to use a different renderer, please provide a valid client:only directive.`
216
- );
217
- }
218
212
  html = await renderSlotToString(result, slots?.fallback);
219
213
  } else {
220
214
  const componentRenderStartTime = performance.now();
@@ -286,7 +286,7 @@ export interface ViteUserConfig extends OriginalViteUserConfig {
286
286
  * @type {string}
287
287
  * @default `"."` (current working directory)
288
288
  * @summary Set the project root. The project root is the directory where your Astro project (and all `src`, `public` and `package.json` files) live.
289
- * @description You should only provide this option if you run the `astro` CLI commands in a directory other than the project root directory. Usually, this option is provided via the CLI instead of the [Astro config file](https://docs.astro.build/en/guides/configuring-astro/#supported-config-file-types), since Astro needs to know your project root before it can locate your config file.
289
+ * @description You should only provide this option if you run the `astro` CLI commands in a directory other than the project root directory. Usually, this option is provided via the CLI instead of the Astro config file, since Astro needs to know your project root before it can locate your config file.
290
290
  *
291
291
  * If you provide a relative path (ex: `--root: './my-project'`) Astro will resolve it against your current working directory.
292
292
  *
@@ -1852,7 +1852,7 @@ export interface ViteUserConfig extends OriginalViteUserConfig {
1852
1852
  * For a complete overview, and to give feedback on this experimental API,
1853
1853
  * see the [Feature RFC](https://github.com/withastro/roadmap/pull/1035).
1854
1854
  */
1855
- svg?: {
1855
+ svg?: boolean | {
1856
1856
  /**
1857
1857
  *
1858
1858
  * @name experimental.svg.mode
@@ -1872,7 +1872,7 @@ export interface ViteUserConfig extends OriginalViteUserConfig {
1872
1872
  * <Logo size={24} mode="sprite" />
1873
1873
  * ```
1874
1874
  */
1875
- mode?: SvgRenderMode;
1875
+ mode: SvgRenderMode;
1876
1876
  };
1877
1877
  };
1878
1878
  }
@@ -114,8 +114,8 @@ async function handleRoute({
114
114
  method: incomingRequest.method,
115
115
  body,
116
116
  logger,
117
- clientAddress: incomingRequest.socket.remoteAddress,
118
- isPrerendered: route.prerender
117
+ isPrerendered: route.prerender,
118
+ routePattern: route.component
119
119
  });
120
120
  for (const [name, value] of Object.entries(config.server.headers ?? {})) {
121
121
  if (value) incomingResponse.setHeader(name, value);
@@ -127,7 +127,8 @@ async function handleRoute({
127
127
  pathname,
128
128
  middleware: isDefaultPrerendered404(matchedRoute.route) ? void 0 : middleware,
129
129
  request,
130
- routeData: route
130
+ routeData: route,
131
+ clientAddress: incomingRequest.socket.remoteAddress
131
132
  });
132
133
  let response;
133
134
  let statusCode = 200;
@@ -180,7 +181,8 @@ async function handleRoute({
180
181
  pathname,
181
182
  middleware: isDefaultPrerendered404(fourOhFourRoute.route) ? void 0 : middleware,
182
183
  request,
183
- routeData: fourOhFourRoute.route
184
+ routeData: fourOhFourRoute.route,
185
+ clientAddress: incomingRequest.socket.remoteAddress
184
186
  });
185
187
  response = await renderContext.render(fourOhFourRoute.preloadedComponent);
186
188
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "astro",
3
- "version": "5.0.1",
3
+ "version": "5.0.3",
4
4
  "description": "Astro is a modern site builder with web best practices, performance, and DX front-of-mind.",
5
5
  "type": "module",
6
6
  "author": "withastro",
@@ -92,7 +92,9 @@ declare module 'astro:content' {
92
92
  collection: C,
93
93
  id: E,
94
94
  ): E extends keyof DataEntryMap[C]
95
- ? Promise<DataEntryMap[C][E]>
95
+ ? string extends keyof DataEntryMap[C]
96
+ ? Promise<DataEntryMap[C][E]> | undefined
97
+ : Promise<DataEntryMap[C][E]>
96
98
  : Promise<CollectionEntry<C> | undefined>;
97
99
 
98
100
  /** Resolve an array of entry references from the same collection */