astro 4.10.0 → 4.10.2

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 (43) hide show
  1. package/client.d.ts +0 -4
  2. package/dist/@types/astro.d.ts +1 -1
  3. package/dist/config/index.d.ts +2 -2
  4. package/dist/config/index.js +4 -4
  5. package/dist/container/pipeline.d.ts +1 -1
  6. package/dist/container/pipeline.js +17 -18
  7. package/dist/content/runtime.js +2 -2
  8. package/dist/content/types-generator.js +2 -4
  9. package/dist/core/app/index.js +0 -4
  10. package/dist/core/app/pipeline.d.ts +1 -1
  11. package/dist/core/app/pipeline.js +4 -4
  12. package/dist/core/base-pipeline.d.ts +1 -1
  13. package/dist/core/build/generate.js +2 -1
  14. package/dist/core/build/pipeline.d.ts +1 -1
  15. package/dist/core/build/pipeline.js +4 -4
  16. package/dist/core/config/schema.d.ts +498 -2
  17. package/dist/core/constants.js +1 -1
  18. package/dist/core/dev/dev.js +1 -1
  19. package/dist/core/errors/errors-data.d.ts +11 -0
  20. package/dist/core/errors/errors-data.js +6 -0
  21. package/dist/core/messages.js +2 -2
  22. package/dist/core/render-context.d.ts +1 -1
  23. package/dist/core/render-context.js +25 -22
  24. package/dist/core/routing/params.js +1 -1
  25. package/dist/env/config.d.ts +2 -1
  26. package/dist/env/config.js +4 -0
  27. package/dist/env/constants.d.ts +0 -1
  28. package/dist/env/constants.js +1 -3
  29. package/dist/env/schema.d.ts +264 -210
  30. package/dist/env/schema.js +47 -63
  31. package/dist/env/setup.d.ts +1 -0
  32. package/dist/env/setup.js +4 -0
  33. package/dist/env/validators.js +73 -10
  34. package/dist/env/vite-plugin-env.js +6 -5
  35. package/dist/i18n/index.d.ts +1 -1
  36. package/dist/i18n/index.js +4 -11
  37. package/dist/runtime/server/render/astro/render.js +8 -2
  38. package/dist/vite-plugin-astro-server/pipeline.d.ts +1 -1
  39. package/dist/vite-plugin-astro-server/pipeline.js +4 -4
  40. package/dist/vite-plugin-astro-server/request.js +2 -2
  41. package/package.json +13 -12
  42. package/dist/virtual-modules/env-setup.d.ts +0 -1
  43. package/dist/virtual-modules/env-setup.js +0 -4
@@ -1,4 +1,4 @@
1
- const ASTRO_VERSION = "4.10.0";
1
+ const ASTRO_VERSION = "4.10.2";
2
2
  const REROUTE_DIRECTIVE_HEADER = "X-Astro-Reroute";
3
3
  const ROUTE_TYPE_HEADER = "X-Astro-Route-Type";
4
4
  const DEFAULT_404_COMPONENT = "astro-default-404.astro";
@@ -19,7 +19,7 @@ async function dev(inlineConfig) {
19
19
  await telemetry.record([]);
20
20
  const restart = await createContainerWithAutomaticRestart({ inlineConfig, fs });
21
21
  const logger = restart.container.logger;
22
- const currentVersion = "4.10.0";
22
+ const currentVersion = "4.10.2";
23
23
  const isPrerelease = currentVersion.includes("-");
24
24
  if (!isPrerelease) {
25
25
  try {
@@ -1068,6 +1068,17 @@ export declare const i18nNotEnabled: {
1068
1068
  message: string;
1069
1069
  hint: string;
1070
1070
  };
1071
+ /**
1072
+ * @docs
1073
+ * @description
1074
+ * An i18n utility tried to use the locale from a URL path that does not contain one. You can prevent this error by using pathHasLocale to check URLs for a locale first before using i18n utilities.
1075
+ *
1076
+ */
1077
+ export declare const i18nNoLocaleFoundInPath: {
1078
+ name: string;
1079
+ title: string;
1080
+ message: string;
1081
+ };
1071
1082
  /**
1072
1083
  * @docs
1073
1084
  * @description
@@ -385,6 +385,11 @@ const i18nNotEnabled = {
385
385
  message: "The `astro:i18n` module can not be used without enabling i18n in your Astro config.",
386
386
  hint: "See https://docs.astro.build/en/guides/internationalization for a guide on setting up i18n."
387
387
  };
388
+ const i18nNoLocaleFoundInPath = {
389
+ name: "i18nNoLocaleFoundInPath",
390
+ title: "The path doesn't contain any locale",
391
+ message: "You tried to use an i18n utility on a path that doesn't contain any locale. You can use `pathHasLocale` first to determine if the path has a locale."
392
+ };
388
393
  const RouteNotFound = {
389
394
  name: "RouteNotFound",
390
395
  title: "Route not found.",
@@ -642,5 +647,6 @@ export {
642
647
  UnsupportedConfigTransformError,
643
648
  UnsupportedImageConversion,
644
649
  UnsupportedImageFormat,
650
+ i18nNoLocaleFoundInPath,
645
651
  i18nNotEnabled
646
652
  };
@@ -37,7 +37,7 @@ function serverStart({
37
37
  host,
38
38
  base
39
39
  }) {
40
- const version = "4.10.0";
40
+ const version = "4.10.2";
41
41
  const localPrefix = `${dim("\u2503")} Local `;
42
42
  const networkPrefix = `${dim("\u2503")} Network `;
43
43
  const emptyPrefix = " ".repeat(11);
@@ -269,7 +269,7 @@ function printHelp({
269
269
  message.push(
270
270
  linebreak(),
271
271
  ` ${bgGreen(black(` ${commandName} `))} ${green(
272
- `v${"4.10.0"}`
272
+ `v${"4.10.2"}`
273
273
  )} ${headline}`
274
274
  );
275
275
  }
@@ -11,7 +11,7 @@ export declare class RenderContext {
11
11
  readonly pipeline: Pipeline;
12
12
  locals: App.Locals;
13
13
  readonly middleware: MiddlewareHandler;
14
- readonly pathname: string;
14
+ pathname: string;
15
15
  request: Request;
16
16
  routeData: RouteData;
17
17
  status: number;
@@ -8,7 +8,6 @@ import { renderEndpoint } from "../runtime/server/endpoint.js";
8
8
  import { renderPage } from "../runtime/server/index.js";
9
9
  import {
10
10
  ASTRO_VERSION,
11
- DEFAULT_404_COMPONENT,
12
11
  REROUTE_DIRECTIVE_HEADER,
13
12
  ROUTE_TYPE_HEADER,
14
13
  clientAddressSymbol,
@@ -77,13 +76,13 @@ class RenderContext {
77
76
  * - fallback
78
77
  */
79
78
  async render(componentInstance, slots = {}) {
80
- const { cookies, middleware, pathname, pipeline } = this;
81
- const { logger, routeCache, serverLike, streaming } = pipeline;
79
+ const { cookies, middleware, pipeline } = this;
80
+ const { logger, serverLike, streaming } = pipeline;
82
81
  const props = Object.keys(this.props).length > 0 ? this.props : await getProps({
83
82
  mod: componentInstance,
84
83
  routeData: this.routeData,
85
- routeCache,
86
- pathname,
84
+ routeCache: this.pipeline.routeCache,
85
+ pathname: this.pathname,
87
86
  logger,
88
87
  serverLike
89
88
  });
@@ -173,7 +172,7 @@ class RenderContext {
173
172
  const redirect = (path, status = 302) => new Response(null, { status, headers: { Location: path } });
174
173
  const rewrite = async (reroutePayload) => {
175
174
  pipeline.logger.debug("router", "Called rewriting to:", reroutePayload);
176
- const [routeData, component] = await pipeline.tryRewrite(
175
+ const [routeData, component, newURL] = await pipeline.tryRewrite(
177
176
  reroutePayload,
178
177
  this.request,
179
178
  this.originalRoute
@@ -182,15 +181,13 @@ class RenderContext {
182
181
  if (reroutePayload instanceof Request) {
183
182
  this.request = reroutePayload;
184
183
  } else {
185
- this.request = this.#copyRequest(
186
- new URL(routeData.pathname ?? routeData.route, this.url.origin),
187
- this.request
188
- );
184
+ this.request = this.#copyRequest(newURL, this.request);
189
185
  }
190
- this.url = new URL(this.request.url);
186
+ this.url = newURL;
191
187
  this.cookies = new AstroCookies(this.request);
192
- this.params = getParams(routeData, url.toString());
188
+ this.params = getParams(routeData, this.url.pathname);
193
189
  this.isRewriting = true;
190
+ this.pathname = this.url.pathname;
194
191
  return await this.render(component);
195
192
  };
196
193
  return {
@@ -289,10 +286,18 @@ class RenderContext {
289
286
  * The page level partial is used as the prototype of the user-visible `Astro` global object, which is instantiated once per use of a component.
290
287
  */
291
288
  createAstro(result, astroStaticPartial, props, slotValues) {
292
- const astroPagePartial = this.#astroPagePartial ??= this.createAstroPagePartial(
293
- result,
294
- astroStaticPartial
295
- );
289
+ let astroPagePartial;
290
+ if (this.isRewriting) {
291
+ astroPagePartial = this.#astroPagePartial = this.createAstroPagePartial(
292
+ result,
293
+ astroStaticPartial
294
+ );
295
+ } else {
296
+ astroPagePartial = this.#astroPagePartial ??= this.createAstroPagePartial(
297
+ result,
298
+ astroStaticPartial
299
+ );
300
+ }
296
301
  const astroComponentPartial = { props, self: null };
297
302
  const Astro = Object.assign(
298
303
  Object.create(astroPagePartial),
@@ -327,7 +332,7 @@ class RenderContext {
327
332
  };
328
333
  const rewrite = async (reroutePayload) => {
329
334
  pipeline.logger.debug("router", "Calling rewrite: ", reroutePayload);
330
- const [routeData, component] = await pipeline.tryRewrite(
335
+ const [routeData, component, newURL] = await pipeline.tryRewrite(
331
336
  reroutePayload,
332
337
  this.request,
333
338
  this.originalRoute
@@ -336,14 +341,12 @@ class RenderContext {
336
341
  if (reroutePayload instanceof Request) {
337
342
  this.request = reroutePayload;
338
343
  } else {
339
- this.request = this.#copyRequest(
340
- new URL(routeData.pathname ?? routeData.route, this.url.origin),
341
- this.request
342
- );
344
+ this.request = this.#copyRequest(newURL, this.request);
343
345
  }
344
346
  this.url = new URL(this.request.url);
345
347
  this.cookies = new AstroCookies(this.request);
346
- this.params = getParams(routeData, url.toString());
348
+ this.params = getParams(routeData, this.url.pathname);
349
+ this.pathname = this.url.pathname;
347
350
  this.isRewriting = true;
348
351
  return await this.render(component);
349
352
  };
@@ -9,7 +9,7 @@ function stringifyParams(params, route) {
9
9
  }
10
10
  return acc;
11
11
  }, {});
12
- return JSON.stringify(route.generate(validatedParams));
12
+ return route.generate(validatedParams);
13
13
  }
14
14
  export {
15
15
  stringifyParams
@@ -1,4 +1,4 @@
1
- import type { BooleanField, BooleanFieldInput, NumberField, NumberFieldInput, StringField, StringFieldInput } from './schema.js';
1
+ import type { BooleanField, BooleanFieldInput, EnumField, EnumFieldInput, NumberField, NumberFieldInput, StringField, StringFieldInput } from './schema.js';
2
2
  /**
3
3
  * Return a valid env field to use in this Astro config for `experimental.env.schema`.
4
4
  */
@@ -6,4 +6,5 @@ export declare const envField: {
6
6
  string: (options: StringFieldInput) => StringField;
7
7
  number: (options: NumberFieldInput) => NumberField;
8
8
  boolean: (options: BooleanFieldInput) => BooleanField;
9
+ enum: <T extends string>(options: EnumFieldInput<T>) => EnumField;
9
10
  };
@@ -10,6 +10,10 @@ const envField = {
10
10
  boolean: (options) => ({
11
11
  ...options,
12
12
  type: "boolean"
13
+ }),
14
+ enum: (options) => ({
15
+ ...options,
16
+ type: "enum"
13
17
  })
14
18
  };
15
19
  export {
@@ -4,7 +4,6 @@ export declare const VIRTUAL_MODULES_IDS: {
4
4
  internal: string;
5
5
  };
6
6
  export declare const VIRTUAL_MODULES_IDS_VALUES: Set<string>;
7
- export declare const VIRTUAL_MODULE_SETUP_ID = "astro:env/setup";
8
7
  export declare const PUBLIC_PREFIX = "PUBLIC_";
9
8
  export declare const ENV_TYPES_FILE = "env.d.ts";
10
9
  export declare const MODULE_TEMPLATE_URL: URL;
@@ -4,7 +4,6 @@ const VIRTUAL_MODULES_IDS = {
4
4
  internal: "virtual:astro:env/internal"
5
5
  };
6
6
  const VIRTUAL_MODULES_IDS_VALUES = new Set(Object.values(VIRTUAL_MODULES_IDS));
7
- const VIRTUAL_MODULE_SETUP_ID = "astro:env/setup";
8
7
  const PUBLIC_PREFIX = "PUBLIC_";
9
8
  const ENV_TYPES_FILE = "env.d.ts";
10
9
  const PKG_BASE = new URL("../../", import.meta.url);
@@ -16,6 +15,5 @@ export {
16
15
  PUBLIC_PREFIX,
17
16
  TYPES_TEMPLATE_URL,
18
17
  VIRTUAL_MODULES_IDS,
19
- VIRTUAL_MODULES_IDS_VALUES,
20
- VIRTUAL_MODULE_SETUP_ID
18
+ VIRTUAL_MODULES_IDS_VALUES
21
19
  };