astro 4.4.0 → 4.4.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 (100) hide show
  1. package/dist/@types/astro.d.ts +42 -42
  2. package/dist/assets/build/generate.d.ts +1 -1
  3. package/dist/assets/build/generate.js +1 -2
  4. package/dist/cli/add/babel.d.ts +1 -1
  5. package/dist/cli/add/index.js +1 -1
  6. package/dist/cli/db/index.js +2 -0
  7. package/dist/cli/info/index.js +2 -0
  8. package/dist/cli/preferences/index.js +2 -0
  9. package/dist/content/types-generator.js +4 -4
  10. package/dist/core/app/index.js +40 -123
  11. package/dist/core/app/pipeline.d.ts +7 -0
  12. package/dist/core/app/pipeline.js +39 -0
  13. package/dist/core/app/types.d.ts +2 -2
  14. package/dist/core/base-pipeline.d.ts +59 -0
  15. package/dist/core/base-pipeline.js +27 -0
  16. package/dist/core/build/generate.d.ts +1 -1
  17. package/dist/core/build/generate.js +41 -110
  18. package/dist/core/build/index.js +0 -4
  19. package/dist/core/build/{buildPipeline.d.ts → pipeline.d.ts} +13 -13
  20. package/dist/core/build/pipeline.js +180 -0
  21. package/dist/core/build/plugins/plugin-manifest.js +3 -2
  22. package/dist/core/build/types.d.ts +0 -2
  23. package/dist/core/config/schema.d.ts +37 -54
  24. package/dist/core/config/schema.js +10 -39
  25. package/dist/core/constants.d.ts +10 -1
  26. package/dist/core/constants.js +14 -4
  27. package/dist/core/dev/dev.js +1 -1
  28. package/dist/core/dev/restart.js +1 -1
  29. package/dist/core/endpoint/index.d.ts +6 -5
  30. package/dist/core/endpoint/index.js +7 -34
  31. package/dist/core/errors/errors-data.d.ts +3 -3
  32. package/dist/core/messages.js +2 -2
  33. package/dist/core/middleware/callMiddleware.d.ts +1 -1
  34. package/dist/core/middleware/callMiddleware.js +2 -9
  35. package/dist/core/middleware/index.d.ts +2 -2
  36. package/dist/core/middleware/index.js +74 -9
  37. package/dist/core/module-loader/vite.js +4 -4
  38. package/dist/core/preview/index.js +2 -0
  39. package/dist/core/preview/static-preview-server.js +1 -7
  40. package/dist/core/redirects/helpers.d.ts +1 -3
  41. package/dist/core/redirects/helpers.js +0 -29
  42. package/dist/core/redirects/index.d.ts +2 -1
  43. package/dist/core/redirects/index.js +3 -3
  44. package/dist/core/redirects/render.d.ts +2 -0
  45. package/dist/core/redirects/render.js +33 -0
  46. package/dist/core/render/index.d.ts +7 -13
  47. package/dist/core/render/index.js +7 -7
  48. package/dist/core/render/params-and-props.d.ts +8 -3
  49. package/dist/core/render/params-and-props.js +24 -16
  50. package/dist/core/render/result.d.ts +8 -7
  51. package/dist/core/render/result.js +4 -5
  52. package/dist/core/render-context.d.ts +32 -0
  53. package/dist/core/render-context.js +219 -0
  54. package/dist/core/routing/index.d.ts +0 -1
  55. package/dist/core/routing/index.js +0 -2
  56. package/dist/core/routing/manifest/create.js +5 -3
  57. package/dist/core/routing/params.d.ts +1 -7
  58. package/dist/core/routing/params.js +0 -15
  59. package/dist/core/sync/index.js +3 -3
  60. package/dist/i18n/index.d.ts +4 -4
  61. package/dist/i18n/index.js +2 -2
  62. package/dist/i18n/middleware.d.ts +0 -5
  63. package/dist/i18n/middleware.js +62 -70
  64. package/dist/i18n/utils.d.ts +26 -0
  65. package/dist/{core/render/context.js → i18n/utils.js} +32 -50
  66. package/dist/prerender/routing.d.ts +1 -1
  67. package/dist/prerender/routing.js +2 -3
  68. package/dist/runtime/client/dev-toolbar/apps/astro.js +13 -9
  69. package/dist/runtime/client/dev-toolbar/apps/audit/a11y.js +2 -2
  70. package/dist/runtime/server/endpoint.js +2 -2
  71. package/dist/virtual-modules/i18n.js +7 -5
  72. package/dist/vite-plugin-astro/hmr.d.ts +1 -0
  73. package/dist/vite-plugin-astro/hmr.js +7 -4
  74. package/dist/vite-plugin-astro-server/error.d.ts +2 -2
  75. package/dist/vite-plugin-astro-server/error.js +2 -5
  76. package/dist/vite-plugin-astro-server/index.d.ts +0 -6
  77. package/dist/vite-plugin-astro-server/index.js +0 -19
  78. package/dist/vite-plugin-astro-server/pipeline.d.ts +19 -0
  79. package/dist/vite-plugin-astro-server/pipeline.js +117 -0
  80. package/dist/vite-plugin-astro-server/plugin.js +5 -5
  81. package/dist/vite-plugin-astro-server/request.d.ts +3 -4
  82. package/dist/vite-plugin-astro-server/request.js +6 -9
  83. package/dist/vite-plugin-astro-server/route.d.ts +3 -4
  84. package/dist/vite-plugin-astro-server/route.js +34 -162
  85. package/dist/vite-plugin-dev-toolbar/vite-plugin-dev-toolbar.js +3 -3
  86. package/package.json +3 -8
  87. package/dist/core/app/ssrPipeline.d.ts +0 -3
  88. package/dist/core/app/ssrPipeline.js +0 -6
  89. package/dist/core/build/buildPipeline.js +0 -150
  90. package/dist/core/pipeline.d.ts +0 -39
  91. package/dist/core/pipeline.js +0 -107
  92. package/dist/core/render/context.d.ts +0 -52
  93. package/dist/core/render/core.d.ts +0 -10
  94. package/dist/core/render/core.js +0 -65
  95. package/dist/core/render/environment.d.ts +0 -34
  96. package/dist/core/render/environment.js +0 -6
  97. package/dist/runtime/server/consts.d.ts +0 -1
  98. package/dist/runtime/server/consts.js +0 -4
  99. package/dist/vite-plugin-astro-server/devPipeline.d.ts +0 -22
  100. package/dist/vite-plugin-astro-server/devPipeline.js +0 -65
@@ -7,7 +7,6 @@ import { z } from 'zod';
7
7
  import 'mdast-util-to-hast';
8
8
  import 'shikiji-core';
9
9
  type ShikiTheme = NonNullable<ShikiConfig['theme']>;
10
- export type RoutingStrategies = 'pathname-prefix-always' | 'pathname-prefix-other-locales' | 'pathname-prefix-always-no-redirect' | 'domains-prefix-always' | 'domains-prefix-other-locales' | 'domains-prefix-always-no-redirect';
11
10
  export declare const AstroConfigSchema: z.ZodObject<{
12
11
  root: z.ZodEffects<z.ZodDefault<z.ZodOptional<z.ZodString>>, URL, string | undefined>;
13
12
  srcDir: z.ZodEffects<z.ZodDefault<z.ZodOptional<z.ZodString>>, URL, string | undefined>;
@@ -238,7 +237,7 @@ export declare const AstroConfigSchema: z.ZodObject<{
238
237
  smartypants?: boolean | undefined;
239
238
  }>>;
240
239
  vite: z.ZodDefault<z.ZodType<ViteUserConfig, z.ZodTypeDef, ViteUserConfig>>;
241
- i18n: z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodOptional<z.ZodObject<{
240
+ i18n: z.ZodOptional<z.ZodEffects<z.ZodOptional<z.ZodObject<{
242
241
  defaultLocale: z.ZodString;
243
242
  locales: z.ZodArray<z.ZodUnion<[z.ZodString, z.ZodObject<{
244
243
  path: z.ZodString;
@@ -300,34 +299,16 @@ export declare const AstroConfigSchema: z.ZodObject<{
300
299
  strategy?: "pathname" | undefined;
301
300
  } | undefined;
302
301
  }>>, {
303
- routing: RoutingStrategies;
304
- defaultLocale: string;
305
- locales: (string | {
306
- path: string;
307
- codes: [string, ...string[]];
308
- })[];
309
- domains?: Record<string, string> | undefined;
310
- fallback?: Record<string, string> | undefined;
311
- } | undefined, {
312
- defaultLocale: string;
313
- locales: (string | {
314
- path: string;
315
- codes: [string, ...string[]];
316
- })[];
317
- domains?: Record<string, string> | undefined;
318
- fallback?: Record<string, string> | undefined;
319
- routing?: {
320
- prefixDefaultLocale?: boolean | undefined;
321
- redirectToDefaultLocale?: boolean | undefined;
322
- strategy?: "pathname" | undefined;
323
- } | undefined;
324
- } | undefined>, {
325
- routing: RoutingStrategies;
326
302
  defaultLocale: string;
327
303
  locales: (string | {
328
304
  path: string;
329
305
  codes: [string, ...string[]];
330
306
  })[];
307
+ routing: {
308
+ prefixDefaultLocale: boolean;
309
+ redirectToDefaultLocale: boolean;
310
+ strategy: "pathname";
311
+ };
331
312
  domains?: Record<string, string> | undefined;
332
313
  fallback?: Record<string, string> | undefined;
333
314
  } | undefined, {
@@ -455,12 +436,16 @@ export declare const AstroConfigSchema: z.ZodObject<{
455
436
  defaultStrategy?: "tap" | "hover" | "viewport" | "load" | undefined;
456
437
  } | undefined;
457
438
  i18n?: {
458
- routing: RoutingStrategies;
459
439
  defaultLocale: string;
460
440
  locales: (string | {
461
441
  path: string;
462
442
  codes: [string, ...string[]];
463
443
  })[];
444
+ routing: {
445
+ prefixDefaultLocale: boolean;
446
+ redirectToDefaultLocale: boolean;
447
+ strategy: "pathname";
448
+ };
464
449
  domains?: Record<string, string> | undefined;
465
450
  fallback?: Record<string, string> | undefined;
466
451
  } | undefined;
@@ -733,7 +718,7 @@ export declare function createRelativeSchema(cmd: string, fileProtocolRoot: stri
733
718
  smartypants?: boolean | undefined;
734
719
  }>>;
735
720
  vite: z.ZodDefault<z.ZodType<ViteUserConfig, z.ZodTypeDef, ViteUserConfig>>;
736
- i18n: z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodOptional<z.ZodObject<{
721
+ i18n: z.ZodOptional<z.ZodEffects<z.ZodOptional<z.ZodObject<{
737
722
  defaultLocale: z.ZodString;
738
723
  locales: z.ZodArray<z.ZodUnion<[z.ZodString, z.ZodObject<{
739
724
  path: z.ZodString;
@@ -795,34 +780,16 @@ export declare function createRelativeSchema(cmd: string, fileProtocolRoot: stri
795
780
  strategy?: "pathname" | undefined;
796
781
  } | undefined;
797
782
  }>>, {
798
- routing: RoutingStrategies;
799
- defaultLocale: string;
800
- locales: (string | {
801
- path: string;
802
- codes: [string, ...string[]];
803
- })[];
804
- domains?: Record<string, string> | undefined;
805
- fallback?: Record<string, string> | undefined;
806
- } | undefined, {
807
- defaultLocale: string;
808
- locales: (string | {
809
- path: string;
810
- codes: [string, ...string[]];
811
- })[];
812
- domains?: Record<string, string> | undefined;
813
- fallback?: Record<string, string> | undefined;
814
- routing?: {
815
- prefixDefaultLocale?: boolean | undefined;
816
- redirectToDefaultLocale?: boolean | undefined;
817
- strategy?: "pathname" | undefined;
818
- } | undefined;
819
- } | undefined>, {
820
- routing: RoutingStrategies;
821
783
  defaultLocale: string;
822
784
  locales: (string | {
823
785
  path: string;
824
786
  codes: [string, ...string[]];
825
787
  })[];
788
+ routing: {
789
+ prefixDefaultLocale: boolean;
790
+ redirectToDefaultLocale: boolean;
791
+ strategy: "pathname";
792
+ };
826
793
  domains?: Record<string, string> | undefined;
827
794
  fallback?: Record<string, string> | undefined;
828
795
  } | undefined, {
@@ -1010,12 +977,16 @@ export declare function createRelativeSchema(cmd: string, fileProtocolRoot: stri
1010
977
  defaultStrategy?: "tap" | "hover" | "viewport" | "load" | undefined;
1011
978
  } | undefined;
1012
979
  i18n?: {
1013
- routing: RoutingStrategies;
1014
980
  defaultLocale: string;
1015
981
  locales: (string | {
1016
982
  path: string;
1017
983
  codes: [string, ...string[]];
1018
984
  })[];
985
+ routing: {
986
+ prefixDefaultLocale: boolean;
987
+ redirectToDefaultLocale: boolean;
988
+ strategy: "pathname";
989
+ };
1019
990
  domains?: Record<string, string> | undefined;
1020
991
  fallback?: Record<string, string> | undefined;
1021
992
  } | undefined;
@@ -1203,12 +1174,16 @@ export declare function createRelativeSchema(cmd: string, fileProtocolRoot: stri
1203
1174
  defaultStrategy?: "tap" | "hover" | "viewport" | "load" | undefined;
1204
1175
  } | undefined;
1205
1176
  i18n?: {
1206
- routing: RoutingStrategies;
1207
1177
  defaultLocale: string;
1208
1178
  locales: (string | {
1209
1179
  path: string;
1210
1180
  codes: [string, ...string[]];
1211
1181
  })[];
1182
+ routing: {
1183
+ prefixDefaultLocale: boolean;
1184
+ redirectToDefaultLocale: boolean;
1185
+ strategy: "pathname";
1186
+ };
1212
1187
  domains?: Record<string, string> | undefined;
1213
1188
  fallback?: Record<string, string> | undefined;
1214
1189
  } | undefined;
@@ -1396,12 +1371,16 @@ export declare function createRelativeSchema(cmd: string, fileProtocolRoot: stri
1396
1371
  defaultStrategy?: "tap" | "hover" | "viewport" | "load" | undefined;
1397
1372
  } | undefined;
1398
1373
  i18n?: {
1399
- routing: RoutingStrategies;
1400
1374
  defaultLocale: string;
1401
1375
  locales: (string | {
1402
1376
  path: string;
1403
1377
  codes: [string, ...string[]];
1404
1378
  })[];
1379
+ routing: {
1380
+ prefixDefaultLocale: boolean;
1381
+ redirectToDefaultLocale: boolean;
1382
+ strategy: "pathname";
1383
+ };
1405
1384
  domains?: Record<string, string> | undefined;
1406
1385
  fallback?: Record<string, string> | undefined;
1407
1386
  } | undefined;
@@ -1589,12 +1568,16 @@ export declare function createRelativeSchema(cmd: string, fileProtocolRoot: stri
1589
1568
  defaultStrategy?: "tap" | "hover" | "viewport" | "load" | undefined;
1590
1569
  } | undefined;
1591
1570
  i18n?: {
1592
- routing: RoutingStrategies;
1593
1571
  defaultLocale: string;
1594
1572
  locales: (string | {
1595
1573
  path: string;
1596
1574
  codes: [string, ...string[]];
1597
1575
  })[];
1576
+ routing: {
1577
+ prefixDefaultLocale: boolean;
1578
+ redirectToDefaultLocale: boolean;
1579
+ strategy: "pathname";
1580
+ };
1598
1581
  domains?: Record<string, string> | undefined;
1599
1582
  fallback?: Record<string, string> | undefined;
1600
1583
  } | undefined;
@@ -217,36 +217,7 @@ const AstroConfigSchema = z.object({
217
217
  message: "The option `i18n.redirectToDefaultLocale` is only useful when the `i18n.prefixDefaultLocale` is set to `true`. Remove the option `i18n.redirectToDefaultLocale`, or change its value to `true`."
218
218
  }
219
219
  )
220
- }).optional().transform((i18n) => {
221
- if (i18n) {
222
- let { routing, domains } = i18n;
223
- let strategy;
224
- const hasDomains = domains ? Object.keys(domains).length > 0 : false;
225
- if (!hasDomains) {
226
- if (routing.prefixDefaultLocale === true) {
227
- if (routing.redirectToDefaultLocale) {
228
- strategy = "pathname-prefix-always";
229
- } else {
230
- strategy = "pathname-prefix-always-no-redirect";
231
- }
232
- } else {
233
- strategy = "pathname-prefix-other-locales";
234
- }
235
- } else {
236
- if (routing.prefixDefaultLocale === true) {
237
- if (routing.redirectToDefaultLocale) {
238
- strategy = "domains-prefix-always";
239
- } else {
240
- strategy = "domains-prefix-always-no-redirect";
241
- }
242
- } else {
243
- strategy = "domains-prefix-other-locales";
244
- }
245
- }
246
- return { ...i18n, routing: strategy };
247
- }
248
- return void 0;
249
- }).superRefine((i18n, ctx) => {
220
+ }).optional().superRefine((i18n, ctx) => {
250
221
  if (i18n) {
251
222
  const { defaultLocale, locales: _locales, fallback, domains, routing } = i18n;
252
223
  const locales = _locales.map((locale) => {
@@ -286,15 +257,14 @@ const AstroConfigSchema = z.object({
286
257
  }
287
258
  if (domains) {
288
259
  const entries = Object.entries(domains);
289
- if (entries.length > 0) {
290
- if (routing !== "domains-prefix-other-locales" && routing !== "domains-prefix-always-no-redirect" && routing !== "domains-prefix-always") {
291
- ctx.addIssue({
292
- code: z.ZodIssueCode.custom,
293
- message: `When specifying some domains, the property \`i18n.routingStrategy\` must be set to \`"domains"\`.`
294
- });
295
- }
260
+ const hasDomains = domains ? Object.keys(domains).length > 0 : false;
261
+ if (entries.length > 0 && !hasDomains) {
262
+ ctx.addIssue({
263
+ code: z.ZodIssueCode.custom,
264
+ message: `When specifying some domains, the property \`i18n.routingStrategy\` must be set to \`"domains"\`.`
265
+ });
296
266
  }
297
- for (const [domainKey, domainValue] of Object.entries(domains)) {
267
+ for (const [domainKey, domainValue] of entries) {
298
268
  if (!locales.includes(domainKey)) {
299
269
  ctx.addIssue({
300
270
  code: z.ZodIssueCode.custom,
@@ -394,7 +364,8 @@ function createRelativeSchema(cmd, fileProtocolRoot) {
394
364
  }).superRefine((configuration, ctx) => {
395
365
  const { site, experimental, i18n, output } = configuration;
396
366
  if (experimental.i18nDomains) {
397
- if (i18n?.routing === "domains-prefix-other-locales" || i18n?.routing === "domains-prefix-always-no-redirect" || i18n?.routing === "domains-prefix-always") {
367
+ const hasDomains = i18n?.domains ? Object.keys(i18n.domains).length > 0 : false;
368
+ if (hasDomains) {
398
369
  if (!site) {
399
370
  ctx.addIssue({
400
371
  code: z.ZodIssueCode.custom,
@@ -1,4 +1,13 @@
1
1
  export declare const ASTRO_VERSION: string;
2
+ export declare const REROUTE_DIRECTIVE_HEADER = "X-Astro-Reroute";
3
+ export declare const ROUTE_TYPE_HEADER = "X-Astro-Route-Type";
4
+ /**
5
+ * A response with one of these status codes will be rewritten
6
+ * with the result of rendering the respective error page.
7
+ */
8
+ export declare const REROUTABLE_STATUS_CODES: number[];
9
+ export declare const clientAddressSymbol: unique symbol;
10
+ export declare const clientLocalsSymbol: unique symbol;
11
+ export declare const responseSentSymbol: unique symbol;
2
12
  export declare const SUPPORTED_MARKDOWN_FILE_EXTENSIONS: readonly [".markdown", ".mdown", ".mkdn", ".mkd", ".mdwn", ".md"];
3
13
  export declare const MIDDLEWARE_PATH_SEGMENT_NAME = "middleware";
4
- export declare const ROUTE_DATA_SYMBOL = "astro.routeData";
@@ -1,4 +1,10 @@
1
- const ASTRO_VERSION = "4.4.0";
1
+ const ASTRO_VERSION = "4.4.2";
2
+ const REROUTE_DIRECTIVE_HEADER = "X-Astro-Reroute";
3
+ const ROUTE_TYPE_HEADER = "X-Astro-Route-Type";
4
+ const REROUTABLE_STATUS_CODES = [404, 500];
5
+ const clientAddressSymbol = Symbol.for("astro.clientAddress");
6
+ const clientLocalsSymbol = Symbol.for("astro.locals");
7
+ const responseSentSymbol = Symbol.for("astro.responseSent");
2
8
  const SUPPORTED_MARKDOWN_FILE_EXTENSIONS = [
3
9
  ".markdown",
4
10
  ".mdown",
@@ -8,10 +14,14 @@ const SUPPORTED_MARKDOWN_FILE_EXTENSIONS = [
8
14
  ".md"
9
15
  ];
10
16
  const MIDDLEWARE_PATH_SEGMENT_NAME = "middleware";
11
- const ROUTE_DATA_SYMBOL = "astro.routeData";
12
17
  export {
13
18
  ASTRO_VERSION,
14
19
  MIDDLEWARE_PATH_SEGMENT_NAME,
15
- ROUTE_DATA_SYMBOL,
16
- SUPPORTED_MARKDOWN_FILE_EXTENSIONS
20
+ REROUTABLE_STATUS_CODES,
21
+ REROUTE_DIRECTIVE_HEADER,
22
+ ROUTE_TYPE_HEADER,
23
+ SUPPORTED_MARKDOWN_FILE_EXTENSIONS,
24
+ clientAddressSymbol,
25
+ clientLocalsSymbol,
26
+ responseSentSymbol
17
27
  };
@@ -23,7 +23,7 @@ async function dev(inlineConfig) {
23
23
  base: restart.container.settings.config.base
24
24
  })
25
25
  );
26
- const currentVersion = "4.4.0";
26
+ const currentVersion = "4.4.2";
27
27
  if (currentVersion.includes("-")) {
28
28
  logger.warn("SKIP_FORMAT", msg.prerelease({ currentVersion }));
29
29
  }
@@ -54,7 +54,7 @@ async function restartContainer(container) {
54
54
  formatErrorMessage(collectErrorMetadata(error), logger.level() === "debug") + "\n"
55
55
  );
56
56
  }
57
- container.viteServer.ws.send({
57
+ container.viteServer.hot.send({
58
58
  type: "error",
59
59
  err: {
60
60
  message: error.message,
@@ -1,6 +1,6 @@
1
- import type { APIContext, EndpointHandler, Locales, MiddlewareHandler, Params } from '../../@types/astro.js';
2
- import { type Environment, type RenderContext } from '../render/index.js';
3
- import type { RoutingStrategies } from '../config/schema.js';
1
+ import type { APIContext, Locales, Params } from '../../@types/astro.js';
2
+ import type { AstroCookies } from '../cookies/index.js';
3
+ import { type RoutingStrategies } from '../../i18n/utils.js';
4
4
  type CreateAPIContext = {
5
5
  request: Request;
6
6
  params: Params;
@@ -10,12 +10,13 @@ type CreateAPIContext = {
10
10
  locales: Locales | undefined;
11
11
  routingStrategy: RoutingStrategies | undefined;
12
12
  defaultLocale: string | undefined;
13
+ route: string;
14
+ cookies: AstroCookies;
13
15
  };
14
16
  /**
15
17
  * Creates a context that holds all the information needed to handle an Astro endpoint.
16
18
  *
17
19
  * @param {CreateAPIContext} payload
18
20
  */
19
- export declare function createAPIContext({ request, params, site, props, adapterName, locales, routingStrategy, defaultLocale, }: CreateAPIContext): APIContext;
20
- export declare function callEndpoint(mod: EndpointHandler, env: Environment, ctx: RenderContext, onRequest: MiddlewareHandler | undefined): Promise<Response>;
21
+ export declare function createAPIContext({ request, params, site, props, adapterName, locales, routingStrategy, defaultLocale, route, cookies, }: CreateAPIContext): APIContext;
21
22
  export {};
@@ -1,16 +1,10 @@
1
- import { renderEndpoint } from "../../runtime/server/index.js";
2
- import { ASTRO_VERSION } from "../constants.js";
3
- import { AstroCookies, attachCookiesToResponse } from "../cookies/index.js";
1
+ import { ASTRO_VERSION, clientAddressSymbol, clientLocalsSymbol } from "../constants.js";
4
2
  import { AstroError, AstroErrorData } from "../errors/index.js";
5
- import { callMiddleware } from "../middleware/callMiddleware.js";
6
3
  import {
7
4
  computeCurrentLocale,
8
5
  computePreferredLocale,
9
6
  computePreferredLocaleList
10
- } from "../render/context.js";
11
- import {} from "../render/index.js";
12
- const clientAddressSymbol = Symbol.for("astro.clientAddress");
13
- const clientLocalsSymbol = Symbol.for("astro.locals");
7
+ } from "../../i18n/utils.js";
14
8
  function createAPIContext({
15
9
  request,
16
10
  params,
@@ -19,13 +13,15 @@ function createAPIContext({
19
13
  adapterName,
20
14
  locales,
21
15
  routingStrategy,
22
- defaultLocale
16
+ defaultLocale,
17
+ route,
18
+ cookies
23
19
  }) {
24
20
  let preferredLocale = void 0;
25
21
  let preferredLocaleList = void 0;
26
22
  let currentLocale = void 0;
27
23
  const context = {
28
- cookies: new AstroCookies(request),
24
+ cookies,
29
25
  request,
30
26
  params,
31
27
  site: site ? new URL(site) : void 0,
@@ -64,7 +60,7 @@ function createAPIContext({
64
60
  return currentLocale;
65
61
  }
66
62
  if (locales) {
67
- currentLocale = computeCurrentLocale(request, locales, routingStrategy, defaultLocale);
63
+ currentLocale = computeCurrentLocale(route, locales, routingStrategy, defaultLocale);
68
64
  }
69
65
  return currentLocale;
70
66
  },
@@ -104,29 +100,6 @@ function createAPIContext({
104
100
  };
105
101
  return context;
106
102
  }
107
- async function callEndpoint(mod, env, ctx, onRequest) {
108
- const context = createAPIContext({
109
- request: ctx.request,
110
- params: ctx.params,
111
- props: ctx.props,
112
- site: env.site,
113
- adapterName: env.adapterName,
114
- routingStrategy: ctx.routing,
115
- defaultLocale: ctx.defaultLocale,
116
- locales: ctx.locales
117
- });
118
- let response;
119
- if (onRequest) {
120
- response = await callMiddleware(onRequest, context, async () => {
121
- return await renderEndpoint(mod, context, env.ssr, env.logger);
122
- });
123
- } else {
124
- response = await renderEndpoint(mod, context, env.ssr, env.logger);
125
- }
126
- attachCookiesToResponse(response, context.cookies);
127
- return response;
128
- }
129
103
  export {
130
- callEndpoint,
131
104
  createAPIContext
132
105
  };
@@ -458,7 +458,7 @@ export declare const InvalidImageService: {
458
458
  * - [Images](https://docs.astro.build/en/guides/images/)
459
459
  * - [Image component#width-and-height-required](https://docs.astro.build/en/guides/images/#width-and-height-required-for-images-in-public)
460
460
  * @description
461
- * For remote images, `width` and `height` cannot automatically be inferred from the original file. To avoid cumulative layout shift (CLS), either specify these two properties, or set [inferSize`](https://docs.astro.build/en/guides/images/#infersize) to `true` to fetch a remote image's original dimensions.
461
+ * For remote images, `width` and `height` cannot automatically be inferred from the original file. To avoid cumulative layout shift (CLS), either specify these two properties, or set [`inferSize`](https://docs.astro.build/en/guides/images/#infersize) to `true` to fetch a remote image's original dimensions.
462
462
  *
463
463
  * If your image is inside your `src` folder, you probably meant to import it instead. See [the Imports guide for more information](https://docs.astro.build/en/guides/imports/#other-assets).
464
464
  */
@@ -473,7 +473,7 @@ export declare const MissingImageDimension: {
473
473
  * @message
474
474
  * Failed to get the dimensions for `IMAGE_URL`.
475
475
  * @description
476
- * Determining the remote image's dimensions failed. This is typically caused by an incorrect URL or attempting to infer the size of an image in the public folder which is not possible. Here is where the probing logic lives in Astro's [sourcecode](https://github.com/withastro/astro/blob/main/packages/astro/src/assets/utils/image-size/).
476
+ * Determining the remote image's dimensions failed. This is typically caused by an incorrect URL or attempting to infer the size of an image in the public folder which is not possible.
477
477
  */
478
478
  export declare const FailedToFetchRemoteImageDimensions: {
479
479
  name: string;
@@ -776,7 +776,7 @@ export declare const LocalImageUsedWrongly: {
776
776
  * @see
777
777
  * - [Astro.glob](https://docs.astro.build/en/reference/api-reference/#astroglob)
778
778
  * @description
779
- * `Astro.glob()` can only be used in `.astro` files. You can use [`import.meta.glob()`](https://vitejs.dev/guide/features.html#glob-import) instead to acheive the same result.
779
+ * `Astro.glob()` can only be used in `.astro` files. You can use [`import.meta.glob()`](https://vitejs.dev/guide/features.html#glob-import) instead to achieve the same result.
780
780
  */
781
781
  export declare const AstroGlobUsedOutside: {
782
782
  name: string;
@@ -36,7 +36,7 @@ function serverStart({
36
36
  host,
37
37
  base
38
38
  }) {
39
- const version = "4.4.0";
39
+ const version = "4.4.2";
40
40
  const localPrefix = `${dim("\u2503")} Local `;
41
41
  const networkPrefix = `${dim("\u2503")} Network `;
42
42
  const emptyPrefix = " ".repeat(11);
@@ -261,7 +261,7 @@ function printHelp({
261
261
  message.push(
262
262
  linebreak(),
263
263
  ` ${bgGreen(black(` ${commandName} `))} ${green(
264
- `v${"4.4.0"}`
264
+ `v${"4.4.2"}`
265
265
  )} ${headline}`
266
266
  );
267
267
  }
@@ -33,4 +33,4 @@ import type { APIContext, MiddlewareHandler } from '../../@types/astro.js';
33
33
  * @param apiContext The API context
34
34
  * @param responseFunction A callback function that should return a promise with the response
35
35
  */
36
- export declare function callMiddleware(onRequest: MiddlewareHandler, apiContext: APIContext, responseFunction: () => Promise<Response>): Promise<Response>;
36
+ export declare function callMiddleware(onRequest: MiddlewareHandler, apiContext: APIContext, responseFunction: () => Promise<Response> | Response): Promise<Response>;
@@ -1,4 +1,3 @@
1
- import { attachCookiesToResponse, responseHasCookies } from "../cookies/index.js";
2
1
  import { AstroError, AstroErrorData } from "../errors/index.js";
3
2
  async function callMiddleware(onRequest, apiContext, responseFunction) {
4
3
  let nextCalled = false;
@@ -15,7 +14,7 @@ async function callMiddleware(onRequest, apiContext, responseFunction) {
15
14
  if (value instanceof Response === false) {
16
15
  throw new AstroError(AstroErrorData.MiddlewareNotAResponse);
17
16
  }
18
- return ensureCookiesAttached(apiContext, value);
17
+ return value;
19
18
  } else {
20
19
  if (responseFunctionPromise) {
21
20
  return responseFunctionPromise;
@@ -28,16 +27,10 @@ async function callMiddleware(onRequest, apiContext, responseFunction) {
28
27
  } else if (value instanceof Response === false) {
29
28
  throw new AstroError(AstroErrorData.MiddlewareNotAResponse);
30
29
  } else {
31
- return ensureCookiesAttached(apiContext, value);
30
+ return value;
32
31
  }
33
32
  });
34
33
  }
35
- function ensureCookiesAttached(apiContext, response) {
36
- if (apiContext.cookies !== void 0 && !responseHasCookies(response)) {
37
- attachCookiesToResponse(response, apiContext.cookies);
38
- }
39
- return response;
40
- }
41
34
  export {
42
35
  callMiddleware
43
36
  };
@@ -1,4 +1,4 @@
1
- import type { MiddlewareHandler, Params } from '../../@types/astro.js';
1
+ import type { APIContext, MiddlewareHandler, Params } from '../../@types/astro.js';
2
2
  import { sequence } from './sequence.js';
3
3
  declare function defineMiddleware(fn: MiddlewareHandler): MiddlewareHandler;
4
4
  /**
@@ -21,7 +21,7 @@ export type CreateContext = {
21
21
  /**
22
22
  * Creates a context to be passed to Astro middleware `onRequest` function.
23
23
  */
24
- declare function createContext({ request, params, userDefinedLocales }: CreateContext): import("../../@types/astro.js").APIContext<Record<string, any>, Record<string, string | undefined>>;
24
+ declare function createContext({ request, params, userDefinedLocales, }: CreateContext): APIContext;
25
25
  /**
26
26
  * It attempts to serialize `value` and return it as a string.
27
27
  *
@@ -1,18 +1,83 @@
1
- import { createAPIContext } from "../endpoint/index.js";
1
+ import { AstroCookies } from "../cookies/index.js";
2
2
  import { sequence } from "./sequence.js";
3
+ import { ASTRO_VERSION } from "../constants.js";
4
+ import { AstroError, AstroErrorData } from "../errors/index.js";
5
+ import {
6
+ computeCurrentLocale,
7
+ computePreferredLocale,
8
+ computePreferredLocaleList
9
+ } from "../../i18n/utils.js";
10
+ const clientAddressSymbol = Symbol.for("astro.clientAddress");
11
+ const clientLocalsSymbol = Symbol.for("astro.locals");
3
12
  function defineMiddleware(fn) {
4
13
  return fn;
5
14
  }
6
- function createContext({ request, params, userDefinedLocales = [] }) {
7
- return createAPIContext({
15
+ function createContext({
16
+ request,
17
+ params = {},
18
+ userDefinedLocales = []
19
+ }) {
20
+ let preferredLocale = void 0;
21
+ let preferredLocaleList = void 0;
22
+ let currentLocale = void 0;
23
+ const url = new URL(request.url);
24
+ const route = url.pathname;
25
+ return {
26
+ cookies: new AstroCookies(request),
8
27
  request,
9
- params: params ?? {},
10
- props: {},
28
+ params,
11
29
  site: void 0,
12
- locales: userDefinedLocales,
13
- defaultLocale: void 0,
14
- routingStrategy: void 0
15
- });
30
+ generator: `Astro v${ASTRO_VERSION}`,
31
+ props: {},
32
+ redirect(path, status) {
33
+ return new Response(null, {
34
+ status: status || 302,
35
+ headers: {
36
+ Location: path
37
+ }
38
+ });
39
+ },
40
+ get preferredLocale() {
41
+ return preferredLocale ??= computePreferredLocale(request, userDefinedLocales);
42
+ },
43
+ get preferredLocaleList() {
44
+ return preferredLocaleList ??= computePreferredLocaleList(request, userDefinedLocales);
45
+ },
46
+ get currentLocale() {
47
+ return currentLocale ??= computeCurrentLocale(
48
+ route,
49
+ userDefinedLocales,
50
+ void 0,
51
+ void 0
52
+ );
53
+ },
54
+ url,
55
+ get clientAddress() {
56
+ if (clientAddressSymbol in request) {
57
+ return Reflect.get(request, clientAddressSymbol);
58
+ }
59
+ throw new AstroError(AstroErrorData.StaticClientAddressNotAvailable);
60
+ },
61
+ get locals() {
62
+ let locals = Reflect.get(request, clientLocalsSymbol);
63
+ if (locals === void 0) {
64
+ locals = {};
65
+ Reflect.set(request, clientLocalsSymbol, locals);
66
+ }
67
+ if (typeof locals !== "object") {
68
+ throw new AstroError(AstroErrorData.LocalsNotAnObject);
69
+ }
70
+ return locals;
71
+ },
72
+ // We define a custom property, so we can check the value passed to locals
73
+ set locals(val) {
74
+ if (typeof val !== "object") {
75
+ throw new AstroError(AstroErrorData.LocalsNotAnObject);
76
+ } else {
77
+ Reflect.set(request, clientLocalsSymbol, val);
78
+ }
79
+ }
80
+ };
16
81
  }
17
82
  function isLocalsSerializable(value) {
18
83
  let type = typeof value;
@@ -24,8 +24,8 @@ function createViteLoader(viteServer) {
24
24
  events.emit("file-change", args);
25
25
  }
26
26
  });
27
- const _wsSend = viteServer.ws.send;
28
- viteServer.ws.send = function(...args) {
27
+ const _wsSend = viteServer.hot.send;
28
+ viteServer.hot.send = function(...args) {
29
29
  if (isTsconfigUpdated) {
30
30
  isTsconfigUpdated = false;
31
31
  return;
@@ -63,13 +63,13 @@ function createViteLoader(viteServer) {
63
63
  return viteServer.ssrFixStacktrace(err);
64
64
  },
65
65
  clientReload() {
66
- viteServer.ws.send({
66
+ viteServer.hot.send({
67
67
  type: "full-reload",
68
68
  path: "*"
69
69
  });
70
70
  },
71
71
  webSocketSend(msg) {
72
- return viteServer.ws.send(msg);
72
+ return viteServer.hot.send(msg);
73
73
  },
74
74
  isHttps() {
75
75
  return !!viteServer.config.server.https;
@@ -11,7 +11,9 @@ import { createSettings } from "../config/settings.js";
11
11
  import createStaticPreviewServer from "./static-preview-server.js";
12
12
  import { getResolvedHostForHttpServer } from "./util.js";
13
13
  import { ensureProcessNodeEnv } from "../util.js";
14
+ import { apply as applyPolyfills } from "../polyfill.js";
14
15
  async function preview(inlineConfig) {
16
+ applyPolyfills();
15
17
  ensureProcessNodeEnv("production");
16
18
  const logger = createNodeLogger(inlineConfig);
17
19
  const { userConfig, astroConfig } = await resolveConfig(inlineConfig ?? {}, "preview");