astro 4.5.18 → 4.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/dist/@types/astro.d.ts +96 -3
  2. package/dist/core/app/index.js +8 -0
  3. package/dist/core/app/middlewares.d.ts +7 -0
  4. package/dist/core/app/middlewares.js +26 -0
  5. package/dist/core/app/types.d.ts +2 -1
  6. package/dist/core/base-pipeline.js +6 -3
  7. package/dist/core/build/generate.js +3 -2
  8. package/dist/core/build/plugins/plugin-manifest.js +3 -2
  9. package/dist/core/config/schema.d.ts +168 -65
  10. package/dist/core/config/schema.js +20 -13
  11. package/dist/core/constants.js +1 -1
  12. package/dist/core/cookies/cookies.d.ts +3 -11
  13. package/dist/core/cookies/cookies.js +9 -7
  14. package/dist/core/dev/dev.js +1 -1
  15. package/dist/core/errors/dev/utils.js +1 -1
  16. package/dist/core/errors/errors-data.d.ts +23 -0
  17. package/dist/core/errors/errors-data.js +13 -1
  18. package/dist/core/errors/overlay.js +2 -1
  19. package/dist/core/messages.js +2 -2
  20. package/dist/core/middleware/vite-plugin.js +8 -0
  21. package/dist/core/render/index.d.ts +1 -1
  22. package/dist/core/render/index.js +1 -1
  23. package/dist/core/render/{result.js → slots.js} +4 -2
  24. package/dist/core/routing/manifest/create.js +1 -1
  25. package/dist/i18n/index.d.ts +18 -1
  26. package/dist/i18n/index.js +107 -0
  27. package/dist/i18n/middleware.d.ts +1 -1
  28. package/dist/i18n/middleware.js +40 -81
  29. package/dist/i18n/utils.d.ts +2 -2
  30. package/dist/i18n/utils.js +20 -21
  31. package/dist/runtime/client/dev-toolbar/apps/astro.js +6 -1
  32. package/dist/runtime/client/dev-toolbar/apps/audit/rules/a11y.js +1 -1
  33. package/dist/runtime/client/dev-toolbar/apps/settings.js +38 -1
  34. package/dist/runtime/client/dev-toolbar/apps/utils/window.d.ts +2 -1
  35. package/dist/runtime/client/dev-toolbar/apps/utils/window.js +18 -2
  36. package/dist/runtime/client/dev-toolbar/apps/xray.js +6 -1
  37. package/dist/runtime/client/dev-toolbar/entrypoint.js +3 -1
  38. package/dist/runtime/client/dev-toolbar/settings.d.ts +4 -1
  39. package/dist/runtime/client/dev-toolbar/settings.js +2 -1
  40. package/dist/runtime/client/dev-toolbar/toolbar.d.ts +2 -0
  41. package/dist/runtime/client/dev-toolbar/toolbar.js +25 -3
  42. package/dist/runtime/client/dev-toolbar/ui-library/index.d.ts +1 -0
  43. package/dist/runtime/client/dev-toolbar/ui-library/index.js +2 -0
  44. package/dist/runtime/client/dev-toolbar/ui-library/select.d.ts +15 -0
  45. package/dist/runtime/client/dev-toolbar/ui-library/select.js +100 -0
  46. package/dist/runtime/client/dev-toolbar/ui-library/window.d.ts +9 -0
  47. package/dist/runtime/client/dev-toolbar/ui-library/window.js +53 -3
  48. package/dist/runtime/server/render/astro/render-template.d.ts +1 -1
  49. package/dist/virtual-modules/i18n.d.ts +102 -0
  50. package/dist/virtual-modules/i18n.js +86 -6
  51. package/dist/vite-plugin-astro-server/plugin.js +2 -1
  52. package/dist/vite-plugin-astro-server/route.js +1 -1
  53. package/package.json +6 -5
  54. /package/dist/core/render/{result.d.ts → slots.d.ts} +0 -0
@@ -1,3 +1,5 @@
1
+ import { IncorrectStrategyForI18n } from "../core/errors/errors-data.js";
2
+ import { AstroError } from "../core/errors/index.js";
1
3
  import * as I18nInternals from "../i18n/index.js";
2
4
  import { toRoutingStrategy } from "../i18n/utils.js";
3
5
  import { normalizeTheLocale, toCodes, toPaths } from "../i18n/index.js";
@@ -5,9 +7,15 @@ const { trailingSlash, format, site, i18n, isBuild } = (
5
7
  // @ts-expect-error
6
8
  __ASTRO_INTERNAL_I18N_CONFIG__
7
9
  );
8
- const { defaultLocale, locales, domains } = i18n;
10
+ const { defaultLocale, locales, domains, fallback, routing } = i18n;
9
11
  const base = import.meta.env.BASE_URL;
10
- const routing = toRoutingStrategy(i18n);
12
+ const strategy = toRoutingStrategy(routing, domains);
13
+ const noop = (method) => function() {
14
+ throw new AstroError({
15
+ ...IncorrectStrategyForI18n,
16
+ message: IncorrectStrategyForI18n.message(method)
17
+ });
18
+ };
11
19
  const getRelativeLocaleUrl = (locale, path, options) => I18nInternals.getLocaleRelativeUrl({
12
20
  locale,
13
21
  path,
@@ -16,7 +24,7 @@ const getRelativeLocaleUrl = (locale, path, options) => I18nInternals.getLocaleR
16
24
  format,
17
25
  defaultLocale,
18
26
  locales,
19
- strategy: routing,
27
+ strategy,
20
28
  domains,
21
29
  ...options
22
30
  });
@@ -29,7 +37,7 @@ const getAbsoluteLocaleUrl = (locale, path, options) => I18nInternals.getLocaleA
29
37
  site,
30
38
  defaultLocale,
31
39
  locales,
32
- strategy: routing,
40
+ strategy,
33
41
  domains,
34
42
  isBuild,
35
43
  ...options
@@ -41,7 +49,7 @@ const getRelativeLocaleUrlList = (path, options) => I18nInternals.getLocaleRelat
41
49
  format,
42
50
  defaultLocale,
43
51
  locales,
44
- strategy: routing,
52
+ strategy,
45
53
  domains,
46
54
  ...options
47
55
  });
@@ -53,13 +61,79 @@ const getAbsoluteLocaleUrlList = (path, options) => I18nInternals.getLocaleAbsol
53
61
  format,
54
62
  defaultLocale,
55
63
  locales,
56
- strategy: routing,
64
+ strategy,
57
65
  domains,
58
66
  isBuild,
59
67
  ...options
60
68
  });
61
69
  const getPathByLocale = (locale) => I18nInternals.getPathByLocale(locale, locales);
62
70
  const getLocaleByPath = (path) => I18nInternals.getLocaleByPath(path, locales);
71
+ const pathHasLocale = (path) => I18nInternals.pathHasLocale(path, locales);
72
+ let redirectToDefaultLocale;
73
+ if (i18n?.routing === "manual") {
74
+ redirectToDefaultLocale = I18nInternals.redirectToDefaultLocale({
75
+ base,
76
+ trailingSlash,
77
+ format,
78
+ defaultLocale,
79
+ locales,
80
+ strategy,
81
+ domains,
82
+ fallback
83
+ });
84
+ } else {
85
+ redirectToDefaultLocale = noop("redirectToDefaultLocale");
86
+ }
87
+ let notFound;
88
+ if (i18n?.routing === "manual") {
89
+ notFound = I18nInternals.notFound({
90
+ base,
91
+ trailingSlash,
92
+ format,
93
+ defaultLocale,
94
+ locales,
95
+ strategy,
96
+ domains,
97
+ fallback
98
+ });
99
+ } else {
100
+ notFound = noop("notFound");
101
+ }
102
+ let requestHasLocale;
103
+ if (i18n?.routing === "manual") {
104
+ requestHasLocale = I18nInternals.requestHasLocale(locales);
105
+ } else {
106
+ requestHasLocale = noop("requestHasLocale");
107
+ }
108
+ let redirectToFallback;
109
+ if (i18n?.routing === "manual") {
110
+ redirectToFallback = I18nInternals.redirectToFallback({
111
+ base,
112
+ trailingSlash,
113
+ format,
114
+ defaultLocale,
115
+ locales,
116
+ strategy,
117
+ domains,
118
+ fallback
119
+ });
120
+ } else {
121
+ redirectToFallback = noop("useFallback");
122
+ }
123
+ let middleware;
124
+ if (i18n?.routing === "manual") {
125
+ middleware = (customOptions) => {
126
+ const manifest = {
127
+ ...i18n,
128
+ fallback: void 0,
129
+ strategy: toRoutingStrategy(customOptions, {}),
130
+ domainLookupTable: {}
131
+ };
132
+ return I18nInternals.createMiddleware(manifest, base, trailingSlash, format);
133
+ };
134
+ } else {
135
+ middleware = noop("middleware");
136
+ }
63
137
  export {
64
138
  getAbsoluteLocaleUrl,
65
139
  getAbsoluteLocaleUrlList,
@@ -67,7 +141,13 @@ export {
67
141
  getPathByLocale,
68
142
  getRelativeLocaleUrl,
69
143
  getRelativeLocaleUrlList,
144
+ middleware,
70
145
  normalizeTheLocale,
146
+ notFound,
147
+ pathHasLocale,
148
+ redirectToDefaultLocale,
149
+ redirectToFallback,
150
+ requestHasLocale,
71
151
  toCodes,
72
152
  toPaths
73
153
  };
@@ -92,7 +92,7 @@ function createDevelopmentManifest(settings) {
92
92
  if (settings.config.i18n) {
93
93
  i18nManifest = {
94
94
  fallback: settings.config.i18n.fallback,
95
- strategy: toRoutingStrategy(settings.config.i18n),
95
+ strategy: toRoutingStrategy(settings.config.i18n.routing, settings.config.i18n.domains),
96
96
  defaultLocale: settings.config.i18n.defaultLocale,
97
97
  locales: settings.config.i18n.locales,
98
98
  domainLookupTable: {}
@@ -114,6 +114,7 @@ function createDevelopmentManifest(settings) {
114
114
  componentMetadata: /* @__PURE__ */ new Map(),
115
115
  inlinedScripts: /* @__PURE__ */ new Map(),
116
116
  i18n: i18nManifest,
117
+ checkOrigin: settings.config.experimental.security?.csrfProtection?.origin ?? false,
117
118
  middleware(_, next) {
118
119
  return next();
119
120
  }
@@ -115,6 +115,7 @@ async function handleRoute({
115
115
  let options = void 0;
116
116
  let route;
117
117
  const middleware = (await loadMiddleware(loader)).onRequest;
118
+ const locals = Reflect.get(incomingRequest, clientLocalsSymbol);
118
119
  if (!matchedRoute) {
119
120
  if (config.i18n) {
120
121
  const locales = config.i18n.locales;
@@ -176,7 +177,6 @@ async function handleRoute({
176
177
  const filePath = matchedRoute.filePath;
177
178
  const { preloadedComponent } = matchedRoute;
178
179
  route = matchedRoute.route;
179
- const locals = Reflect.get(incomingRequest, clientLocalsSymbol);
180
180
  request = createRequest({
181
181
  base: config.base,
182
182
  url,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "astro",
3
- "version": "4.5.18",
3
+ "version": "4.6.0",
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",
@@ -162,8 +162,8 @@
162
162
  "zod": "^3.22.4",
163
163
  "zod-to-json-schema": "^3.22.4",
164
164
  "@astrojs/internal-helpers": "0.4.0",
165
- "@astrojs/telemetry": "3.0.4",
166
- "@astrojs/markdown-remark": "5.0.0"
165
+ "@astrojs/markdown-remark": "5.1.0",
166
+ "@astrojs/telemetry": "3.1.0"
167
167
  },
168
168
  "optionalDependencies": {
169
169
  "sharp": "^0.32.6"
@@ -212,8 +212,9 @@
212
212
  "astro-scripts": "0.0.14"
213
213
  },
214
214
  "engines": {
215
- "node": ">=18.14.1",
216
- "npm": ">=6.14.0"
215
+ "node": "^18.17.1 || ^20.3.0 || >=21.0.0",
216
+ "npm": ">=9.6.5",
217
+ "pnpm": ">=7.1.0"
217
218
  },
218
219
  "publishConfig": {
219
220
  "provenance": true
File without changes