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.
- package/dist/@types/astro.d.ts +42 -42
- package/dist/assets/build/generate.d.ts +1 -1
- package/dist/assets/build/generate.js +1 -2
- package/dist/cli/add/babel.d.ts +1 -1
- package/dist/cli/add/index.js +1 -1
- package/dist/cli/db/index.js +2 -0
- package/dist/cli/info/index.js +2 -0
- package/dist/cli/preferences/index.js +2 -0
- package/dist/content/types-generator.js +4 -4
- package/dist/core/app/index.js +40 -123
- package/dist/core/app/pipeline.d.ts +7 -0
- package/dist/core/app/pipeline.js +39 -0
- package/dist/core/app/types.d.ts +2 -2
- package/dist/core/base-pipeline.d.ts +59 -0
- package/dist/core/base-pipeline.js +27 -0
- package/dist/core/build/generate.d.ts +1 -1
- package/dist/core/build/generate.js +41 -110
- package/dist/core/build/index.js +0 -4
- package/dist/core/build/{buildPipeline.d.ts → pipeline.d.ts} +13 -13
- package/dist/core/build/pipeline.js +180 -0
- package/dist/core/build/plugins/plugin-manifest.js +3 -2
- package/dist/core/build/types.d.ts +0 -2
- package/dist/core/config/schema.d.ts +37 -54
- package/dist/core/config/schema.js +10 -39
- package/dist/core/constants.d.ts +10 -1
- package/dist/core/constants.js +14 -4
- package/dist/core/dev/dev.js +1 -1
- package/dist/core/dev/restart.js +1 -1
- package/dist/core/endpoint/index.d.ts +6 -5
- package/dist/core/endpoint/index.js +7 -34
- package/dist/core/errors/errors-data.d.ts +3 -3
- package/dist/core/messages.js +2 -2
- package/dist/core/middleware/callMiddleware.d.ts +1 -1
- package/dist/core/middleware/callMiddleware.js +2 -9
- package/dist/core/middleware/index.d.ts +2 -2
- package/dist/core/middleware/index.js +74 -9
- package/dist/core/module-loader/vite.js +4 -4
- package/dist/core/preview/index.js +2 -0
- package/dist/core/preview/static-preview-server.js +1 -7
- package/dist/core/redirects/helpers.d.ts +1 -3
- package/dist/core/redirects/helpers.js +0 -29
- package/dist/core/redirects/index.d.ts +2 -1
- package/dist/core/redirects/index.js +3 -3
- package/dist/core/redirects/render.d.ts +2 -0
- package/dist/core/redirects/render.js +33 -0
- package/dist/core/render/index.d.ts +7 -13
- package/dist/core/render/index.js +7 -7
- package/dist/core/render/params-and-props.d.ts +8 -3
- package/dist/core/render/params-and-props.js +24 -16
- package/dist/core/render/result.d.ts +8 -7
- package/dist/core/render/result.js +4 -5
- package/dist/core/render-context.d.ts +32 -0
- package/dist/core/render-context.js +219 -0
- package/dist/core/routing/index.d.ts +0 -1
- package/dist/core/routing/index.js +0 -2
- package/dist/core/routing/manifest/create.js +5 -3
- package/dist/core/routing/params.d.ts +1 -7
- package/dist/core/routing/params.js +0 -15
- package/dist/core/sync/index.js +3 -3
- package/dist/i18n/index.d.ts +4 -4
- package/dist/i18n/index.js +2 -2
- package/dist/i18n/middleware.d.ts +0 -5
- package/dist/i18n/middleware.js +62 -70
- package/dist/i18n/utils.d.ts +26 -0
- package/dist/{core/render/context.js → i18n/utils.js} +32 -50
- package/dist/prerender/routing.d.ts +1 -1
- package/dist/prerender/routing.js +2 -3
- package/dist/runtime/client/dev-toolbar/apps/astro.js +13 -9
- package/dist/runtime/client/dev-toolbar/apps/audit/a11y.js +2 -2
- package/dist/runtime/server/endpoint.js +2 -2
- package/dist/virtual-modules/i18n.js +7 -5
- package/dist/vite-plugin-astro/hmr.d.ts +1 -0
- package/dist/vite-plugin-astro/hmr.js +7 -4
- package/dist/vite-plugin-astro-server/error.d.ts +2 -2
- package/dist/vite-plugin-astro-server/error.js +2 -5
- package/dist/vite-plugin-astro-server/index.d.ts +0 -6
- package/dist/vite-plugin-astro-server/index.js +0 -19
- package/dist/vite-plugin-astro-server/pipeline.d.ts +19 -0
- package/dist/vite-plugin-astro-server/pipeline.js +117 -0
- package/dist/vite-plugin-astro-server/plugin.js +5 -5
- package/dist/vite-plugin-astro-server/request.d.ts +3 -4
- package/dist/vite-plugin-astro-server/request.js +6 -9
- package/dist/vite-plugin-astro-server/route.d.ts +3 -4
- package/dist/vite-plugin-astro-server/route.js +34 -162
- package/dist/vite-plugin-dev-toolbar/vite-plugin-dev-toolbar.js +3 -3
- package/package.json +3 -8
- package/dist/core/app/ssrPipeline.d.ts +0 -3
- package/dist/core/app/ssrPipeline.js +0 -6
- package/dist/core/build/buildPipeline.js +0 -150
- package/dist/core/pipeline.d.ts +0 -39
- package/dist/core/pipeline.js +0 -107
- package/dist/core/render/context.d.ts +0 -52
- package/dist/core/render/core.d.ts +0 -10
- package/dist/core/render/core.js +0 -65
- package/dist/core/render/environment.d.ts +0 -34
- package/dist/core/render/environment.js +0 -6
- package/dist/runtime/server/consts.d.ts +0 -1
- package/dist/runtime/server/consts.js +0 -4
- package/dist/vite-plugin-astro-server/devPipeline.d.ts +0 -22
- 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.
|
|
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.
|
|
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().
|
|
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
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
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
|
|
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
|
-
|
|
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,
|
package/dist/core/constants.d.ts
CHANGED
|
@@ -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";
|
package/dist/core/constants.js
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
const ASTRO_VERSION = "4.4.
|
|
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
|
-
|
|
16
|
-
|
|
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
|
};
|
package/dist/core/dev/dev.js
CHANGED
|
@@ -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.
|
|
26
|
+
const currentVersion = "4.4.2";
|
|
27
27
|
if (currentVersion.includes("-")) {
|
|
28
28
|
logger.warn("SKIP_FORMAT", msg.prerelease({ currentVersion }));
|
|
29
29
|
}
|
package/dist/core/dev/restart.js
CHANGED
|
@@ -54,7 +54,7 @@ async function restartContainer(container) {
|
|
|
54
54
|
formatErrorMessage(collectErrorMetadata(error), logger.level() === "debug") + "\n"
|
|
55
55
|
);
|
|
56
56
|
}
|
|
57
|
-
container.viteServer.
|
|
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,
|
|
2
|
-
import
|
|
3
|
-
import type
|
|
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 {
|
|
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 "
|
|
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
|
|
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(
|
|
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.
|
|
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
|
|
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;
|
package/dist/core/messages.js
CHANGED
|
@@ -36,7 +36,7 @@ function serverStart({
|
|
|
36
36
|
host,
|
|
37
37
|
base
|
|
38
38
|
}) {
|
|
39
|
-
const version = "4.4.
|
|
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.
|
|
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
|
|
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
|
|
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):
|
|
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 {
|
|
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({
|
|
7
|
-
|
|
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
|
|
10
|
-
props: {},
|
|
28
|
+
params,
|
|
11
29
|
site: void 0,
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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.
|
|
28
|
-
viteServer.
|
|
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.
|
|
66
|
+
viteServer.hot.send({
|
|
67
67
|
type: "full-reload",
|
|
68
68
|
path: "*"
|
|
69
69
|
});
|
|
70
70
|
},
|
|
71
71
|
webSocketSend(msg) {
|
|
72
|
-
return viteServer.
|
|
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");
|