astro 3.4.3 → 3.5.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 (158) hide show
  1. package/client.d.ts +86 -0
  2. package/components/Code.astro +37 -4
  3. package/components/Image.astro +2 -2
  4. package/components/Picture.astro +19 -5
  5. package/components/ViewTransitions.astro +39 -38
  6. package/content-module.template.mjs +4 -14
  7. package/dist/@types/astro.d.ts +223 -5
  8. package/dist/assets/build/generate.d.ts +2 -1
  9. package/dist/assets/build/generate.js +16 -5
  10. package/dist/assets/consts.d.ts +1 -0
  11. package/dist/assets/consts.js +2 -0
  12. package/dist/assets/endpoint/generic.js +6 -2
  13. package/dist/assets/internal.js +11 -2
  14. package/dist/assets/services/service.d.ts +10 -10
  15. package/dist/assets/services/service.js +2 -1
  16. package/dist/assets/services/vendor/squoosh/image-pool.d.ts +1 -2
  17. package/dist/assets/types.d.ts +19 -9
  18. package/dist/assets/utils/emitAsset.js +5 -0
  19. package/dist/assets/utils/metadata.d.ts +1 -2
  20. package/dist/assets/utils/proxy.d.ts +1 -0
  21. package/dist/assets/utils/proxy.js +16 -0
  22. package/dist/assets/utils/queryParams.d.ts +1 -1
  23. package/dist/assets/utils/transformToPath.d.ts +1 -1
  24. package/dist/assets/utils/transformToPath.js +8 -3
  25. package/dist/assets/vite-plugin-assets.js +26 -11
  26. package/dist/cli/build/index.js +1 -1
  27. package/dist/content/consts.d.ts +1 -0
  28. package/dist/content/consts.js +2 -0
  29. package/dist/content/runtime-assets.d.ts +9 -1
  30. package/dist/content/runtime-assets.js +1 -1
  31. package/dist/content/runtime.d.ts +1 -0
  32. package/dist/content/runtime.js +8 -2
  33. package/dist/content/utils.d.ts +1 -0
  34. package/dist/content/utils.js +9 -0
  35. package/dist/content/vite-plugin-content-assets.js +49 -23
  36. package/dist/content/vite-plugin-content-imports.js +9 -3
  37. package/dist/content/vite-plugin-content-virtual-mod.d.ts +17 -12
  38. package/dist/content/vite-plugin-content-virtual-mod.js +136 -57
  39. package/dist/core/app/index.js +19 -4
  40. package/dist/core/app/types.d.ts +7 -1
  41. package/dist/core/build/buildPipeline.js +17 -4
  42. package/dist/core/build/common.js +2 -0
  43. package/dist/core/build/generate.js +64 -34
  44. package/dist/core/build/index.d.ts +0 -8
  45. package/dist/core/build/index.js +9 -2
  46. package/dist/core/build/internal.d.ts +11 -1
  47. package/dist/core/build/internal.js +23 -1
  48. package/dist/core/build/page-data.js +46 -18
  49. package/dist/core/build/plugin.d.ts +12 -10
  50. package/dist/core/build/plugin.js +14 -22
  51. package/dist/core/build/plugins/index.js +4 -0
  52. package/dist/core/build/plugins/plugin-alias-resolve.js +1 -1
  53. package/dist/core/build/plugins/plugin-analyzer.js +1 -1
  54. package/dist/core/build/plugins/plugin-chunks.d.ts +4 -0
  55. package/dist/core/build/plugins/plugin-chunks.js +31 -0
  56. package/dist/core/build/plugins/plugin-component-entry.js +1 -1
  57. package/dist/core/build/plugins/plugin-content.d.ts +4 -0
  58. package/dist/core/build/plugins/plugin-content.js +273 -0
  59. package/dist/core/build/plugins/plugin-css.js +9 -4
  60. package/dist/core/build/plugins/plugin-hoisted-scripts.js +1 -1
  61. package/dist/core/build/plugins/plugin-internals.js +1 -1
  62. package/dist/core/build/plugins/plugin-manifest.js +14 -5
  63. package/dist/core/build/plugins/plugin-middleware.d.ts +1 -3
  64. package/dist/core/build/plugins/plugin-middleware.js +5 -57
  65. package/dist/core/build/plugins/plugin-pages.js +3 -3
  66. package/dist/core/build/plugins/plugin-prerender.js +2 -5
  67. package/dist/core/build/plugins/plugin-renderers.js +1 -1
  68. package/dist/core/build/plugins/plugin-ssr.js +6 -5
  69. package/dist/core/build/plugins/util.d.ts +3 -3
  70. package/dist/core/build/static-build.d.ts +2 -1
  71. package/dist/core/build/static-build.js +52 -28
  72. package/dist/core/build/types.d.ts +1 -1
  73. package/dist/core/build/util.d.ts +7 -0
  74. package/dist/core/build/util.js +37 -1
  75. package/dist/core/compile/compile.js +1 -0
  76. package/dist/core/config/config.js +3 -0
  77. package/dist/core/config/schema.d.ts +208 -0
  78. package/dist/core/config/schema.js +72 -4
  79. package/dist/core/config/settings.js +1 -0
  80. package/dist/core/constants.js +1 -1
  81. package/dist/core/create-vite.js +9 -3
  82. package/dist/core/dev/dev.js +1 -1
  83. package/dist/core/endpoint/index.d.ts +4 -3
  84. package/dist/core/endpoint/index.js +29 -3
  85. package/dist/core/errors/errors-data.d.ts +11 -0
  86. package/dist/core/errors/errors-data.js +17 -0
  87. package/dist/core/messages.js +2 -2
  88. package/dist/core/middleware/index.d.ts +7 -3
  89. package/dist/core/middleware/index.js +3 -2
  90. package/dist/core/middleware/loadMiddleware.d.ts +1 -2
  91. package/dist/core/middleware/loadMiddleware.js +3 -4
  92. package/dist/core/middleware/sequence.d.ts +2 -2
  93. package/dist/core/middleware/sequence.js +3 -2
  94. package/dist/core/middleware/vite-plugin.d.ts +9 -0
  95. package/dist/core/middleware/vite-plugin.js +101 -0
  96. package/dist/core/pipeline.d.ts +1 -1
  97. package/dist/core/pipeline.js +6 -4
  98. package/dist/core/preview/static-preview-server.js +3 -1
  99. package/dist/core/preview/vite-plugin-astro-preview.js +13 -2
  100. package/dist/core/redirects/helpers.d.ts +1 -0
  101. package/dist/core/redirects/helpers.js +4 -0
  102. package/dist/core/render/context.d.ts +24 -1
  103. package/dist/core/render/context.js +96 -2
  104. package/dist/core/render/core.d.ts +2 -14
  105. package/dist/core/render/core.js +12 -52
  106. package/dist/core/render/index.d.ts +2 -3
  107. package/dist/core/render/index.js +3 -4
  108. package/dist/core/render/params-and-props.d.ts +1 -1
  109. package/dist/core/render/params-and-props.js +5 -2
  110. package/dist/core/render/result.d.ts +1 -0
  111. package/dist/core/render/result.js +23 -0
  112. package/dist/core/render/route-cache.d.ts +1 -1
  113. package/dist/core/render/route-cache.js +17 -11
  114. package/dist/core/routing/manifest/create.js +118 -4
  115. package/dist/core/sync/index.d.ts +2 -24
  116. package/dist/i18n/index.d.ts +54 -0
  117. package/dist/i18n/index.js +91 -0
  118. package/dist/i18n/middleware.d.ts +2 -0
  119. package/dist/i18n/middleware.js +62 -0
  120. package/dist/i18n/vite-plugin-i18n.d.ts +7 -0
  121. package/dist/i18n/vite-plugin-i18n.js +62 -0
  122. package/dist/integrations/astroFeaturesValidation.js +4 -1
  123. package/dist/integrations/index.js +12 -0
  124. package/dist/prefetch/index.d.ts +31 -0
  125. package/dist/prefetch/index.js +176 -0
  126. package/dist/prefetch/vite-plugin-prefetch.d.ts +5 -0
  127. package/dist/prefetch/vite-plugin-prefetch.js +43 -0
  128. package/dist/runtime/client/dev-overlay/entrypoint.js +2 -2
  129. package/dist/runtime/client/dev-overlay/overlay.d.ts +10 -2
  130. package/dist/runtime/client/dev-overlay/overlay.js +47 -28
  131. package/dist/runtime/client/dev-overlay/plugins/astro.d.ts +1 -0
  132. package/dist/runtime/client/dev-overlay/plugins/astro.js +44 -9
  133. package/dist/runtime/client/dev-overlay/plugins/audit.d.ts +2 -1
  134. package/dist/runtime/client/dev-overlay/plugins/audit.js +101 -24
  135. package/dist/runtime/client/dev-overlay/plugins/xray.d.ts +1 -0
  136. package/dist/runtime/client/dev-overlay/plugins/xray.js +22 -0
  137. package/dist/runtime/client/dev-overlay/ui-library/card.js +2 -0
  138. package/dist/runtime/client/dev-overlay/ui-library/icons.d.ts +3 -0
  139. package/dist/runtime/client/dev-overlay/ui-library/icons.js +4 -1
  140. package/dist/runtime/client/dev-overlay/ui-library/tooltip.js +1 -0
  141. package/dist/runtime/client/dev-overlay/ui-library/window.js +1 -0
  142. package/dist/runtime/server/index.d.ts +0 -2
  143. package/dist/runtime/server/render/component.js +3 -5
  144. package/dist/transitions/router.d.ts +1 -0
  145. package/dist/transitions/router.js +10 -5
  146. package/dist/transitions/vite-plugin-transitions.d.ts +4 -1
  147. package/dist/transitions/vite-plugin-transitions.js +7 -1
  148. package/dist/vite-plugin-astro-server/devPipeline.d.ts +1 -0
  149. package/dist/vite-plugin-astro-server/devPipeline.js +2 -0
  150. package/dist/vite-plugin-astro-server/plugin.js +11 -1
  151. package/dist/vite-plugin-astro-server/route.js +113 -51
  152. package/dist/vite-plugin-head/index.js +1 -1
  153. package/dist/vite-plugin-markdown/index.js +1 -0
  154. package/dist/vite-plugin-scripts/index.js +2 -1
  155. package/package.json +7 -5
  156. package/tsconfigs/base.json +1 -1
  157. package/dist/core/endpoint/dev/index.d.ts +0 -2
  158. package/dist/core/endpoint/dev/index.js +0 -17
@@ -1,10 +1,15 @@
1
1
  import { fileURLToPath } from "node:url";
2
2
  import { AstroErrorData, isAstroError } from "../core/errors/index.js";
3
+ import { sequence } from "../core/middleware/index.js";
3
4
  import { loadMiddleware } from "../core/middleware/loadMiddleware.js";
4
- import { createRenderContext, getParamsAndProps } from "../core/render/index.js";
5
+ import {
6
+ createRenderContext,
7
+ getParamsAndProps
8
+ } from "../core/render/index.js";
5
9
  import { createRequest } from "../core/request.js";
6
10
  import { matchAllRoutes } from "../core/routing/index.js";
7
11
  import { isPage, resolveIdToUrl } from "../core/util.js";
12
+ import { createI18nMiddleware } from "../i18n/middleware.js";
8
13
  import { getSortedPreloadedMatches } from "../prerender/routing.js";
9
14
  import { isServerLikeOutput } from "../prerender/utils.js";
10
15
  import { PAGE_SCRIPT_ID } from "../vite-plugin-scripts/index.js";
@@ -22,7 +27,7 @@ function getCustom404Route(manifestData) {
22
27
  async function matchRoute(pathname, manifestData, pipeline) {
23
28
  const env = pipeline.getEnvironment();
24
29
  const { routeCache, logger } = env;
25
- const matches = matchAllRoutes(pathname, manifestData);
30
+ let matches = matchAllRoutes(pathname, manifestData);
26
31
  const preloadedMatches = await getSortedPreloadedMatches({
27
32
  pipeline,
28
33
  matches,
@@ -96,67 +101,124 @@ async function handleRoute({
96
101
  manifest
97
102
  }) {
98
103
  const env = pipeline.getEnvironment();
99
- const settings = pipeline.getSettings();
100
104
  const config = pipeline.getConfig();
101
105
  const moduleLoader = pipeline.getModuleLoader();
102
106
  const { logger } = env;
103
- if (!matchedRoute) {
107
+ if (!matchedRoute && !config.experimental.i18n) {
104
108
  return handle404Response(origin, incomingRequest, incomingResponse);
105
109
  }
106
- const filePath = matchedRoute.filePath;
107
- const { route, preloadedComponent } = matchedRoute;
108
110
  const buildingToSSR = isServerLikeOutput(config);
109
- const request = createRequest({
110
- url,
111
- headers: buildingToSSR ? incomingRequest.headers : new Headers(),
112
- method: incomingRequest.method,
113
- body,
114
- logger,
115
- ssr: buildingToSSR,
116
- clientAddress: buildingToSSR ? incomingRequest.socket.remoteAddress : void 0,
117
- locals: Reflect.get(incomingRequest, clientLocalsSymbol)
118
- // Allows adapters to pass in locals in dev mode.
119
- });
120
- for (const [name, value] of Object.entries(config.server.headers ?? {})) {
121
- if (value)
122
- incomingResponse.setHeader(name, value);
123
- }
124
- const options = {
125
- env,
126
- filePath,
127
- preload: preloadedComponent,
128
- pathname,
129
- request,
130
- route
131
- };
132
- const middleware = await loadMiddleware(moduleLoader, settings.config.srcDir);
133
- if (middleware) {
134
- options.middleware = middleware;
111
+ let request;
112
+ let renderContext;
113
+ let mod = void 0;
114
+ let options = void 0;
115
+ let route;
116
+ const middleware = await loadMiddleware(moduleLoader);
117
+ if (!matchedRoute) {
118
+ if (config.experimental.i18n) {
119
+ const locales = config.experimental.i18n.locales;
120
+ const pathNameHasLocale = pathname.split("/").filter(Boolean).some((segment) => {
121
+ return locales.includes(segment);
122
+ });
123
+ if (!pathNameHasLocale && pathname !== "/") {
124
+ return handle404Response(origin, incomingRequest, incomingResponse);
125
+ }
126
+ request = createRequest({
127
+ url,
128
+ headers: buildingToSSR ? incomingRequest.headers : new Headers(),
129
+ logger,
130
+ ssr: buildingToSSR
131
+ });
132
+ route = {
133
+ component: "",
134
+ generate(_data) {
135
+ return "";
136
+ },
137
+ params: [],
138
+ pattern: new RegExp(""),
139
+ prerender: false,
140
+ segments: [],
141
+ type: "fallback",
142
+ route: ""
143
+ };
144
+ renderContext = await createRenderContext({
145
+ request,
146
+ pathname,
147
+ env,
148
+ mod,
149
+ route
150
+ });
151
+ } else {
152
+ return handle404Response(origin, incomingRequest, incomingResponse);
153
+ }
154
+ } else {
155
+ const filePath = matchedRoute.filePath;
156
+ const { preloadedComponent } = matchedRoute;
157
+ route = matchedRoute.route;
158
+ request = createRequest({
159
+ url,
160
+ headers: buildingToSSR ? incomingRequest.headers : new Headers(),
161
+ method: incomingRequest.method,
162
+ body,
163
+ logger,
164
+ ssr: buildingToSSR,
165
+ clientAddress: buildingToSSR ? incomingRequest.socket.remoteAddress : void 0,
166
+ locals: Reflect.get(incomingRequest, clientLocalsSymbol)
167
+ // Allows adapters to pass in locals in dev mode.
168
+ });
169
+ for (const [name, value] of Object.entries(config.server.headers ?? {})) {
170
+ if (value)
171
+ incomingResponse.setHeader(name, value);
172
+ }
173
+ options = {
174
+ env,
175
+ filePath,
176
+ preload: preloadedComponent,
177
+ pathname,
178
+ request,
179
+ route
180
+ };
181
+ if (middleware) {
182
+ options.middleware = middleware;
183
+ }
184
+ mod = options.preload;
185
+ const { scripts, links, styles, metadata } = await getScriptsAndStyles({
186
+ pipeline,
187
+ filePath: options.filePath
188
+ });
189
+ const i18n = pipeline.getConfig().experimental.i18n;
190
+ renderContext = await createRenderContext({
191
+ request: options.request,
192
+ pathname: options.pathname,
193
+ scripts,
194
+ links,
195
+ styles,
196
+ componentMetadata: metadata,
197
+ route: options.route,
198
+ mod,
199
+ env,
200
+ locales: i18n ? i18n.locales : void 0
201
+ });
135
202
  }
136
- const mod = options.preload;
137
- const { scripts, links, styles, metadata } = await getScriptsAndStyles({
138
- pipeline,
139
- filePath: options.filePath
140
- });
141
- const renderContext = await createRenderContext({
142
- request: options.request,
143
- pathname: options.pathname,
144
- scripts,
145
- links,
146
- styles,
147
- componentMetadata: metadata,
148
- route: options.route,
149
- mod,
150
- env
151
- });
152
- const onRequest = options.middleware?.onRequest;
153
- if (onRequest) {
203
+ const onRequest = middleware?.onRequest;
204
+ if (config.experimental.i18n) {
205
+ const i18Middleware = createI18nMiddleware(config.experimental.i18n, config.base);
206
+ if (i18Middleware) {
207
+ if (onRequest) {
208
+ pipeline.setMiddlewareFunction(sequence(i18Middleware, onRequest));
209
+ } else {
210
+ pipeline.setMiddlewareFunction(i18Middleware);
211
+ }
212
+ } else if (onRequest) {
213
+ pipeline.setMiddlewareFunction(onRequest);
214
+ }
215
+ } else if (onRequest) {
154
216
  pipeline.setMiddlewareFunction(onRequest);
155
217
  }
156
218
  let response = await pipeline.renderRoute(renderContext, mod);
157
219
  if (response.status === 404 && has404Route(manifestData)) {
158
220
  const fourOhFourRoute = await matchRoute("/404", manifestData, pipeline);
159
- if (fourOhFourRoute?.route !== options.route)
221
+ if (options && fourOhFourRoute?.route !== options.route)
160
222
  return handleRoute({
161
223
  ...options,
162
224
  matchedRoute: fourOhFourRoute,
@@ -71,7 +71,7 @@ function configHeadVitePlugin() {
71
71
  }
72
72
  function astroHeadBuildPlugin(internals) {
73
73
  return {
74
- build: "ssr",
74
+ targets: ["server"],
75
75
  hooks: {
76
76
  "build:before"() {
77
77
  return {
@@ -60,6 +60,7 @@ function markdown({ settings, logger }) {
60
60
  const raw = safeMatter(rawFile, id);
61
61
  const fileURL = pathToFileURL(fileId);
62
62
  const renderResult = await processor.render(raw.content, {
63
+ // @ts-expect-error passing internal prop
63
64
  fileURL,
64
65
  frontmatter: raw.data
65
66
  }).catch((err) => {
@@ -29,7 +29,8 @@ function astroScriptsPlugin({ settings }) {
29
29
  },
30
30
  buildStart() {
31
31
  const hasHydrationScripts = settings.scripts.some((s) => s.stage === "before-hydration");
32
- if (hasHydrationScripts && env?.command === "build" && !env?.ssrBuild) {
32
+ const isSsrBuild = env?.ssrBuild || env?.isSsrBuild;
33
+ if (hasHydrationScripts && env?.command === "build" && !isSsrBuild) {
33
34
  this.emitFile({
34
35
  type: "chunk",
35
36
  id: BEFORE_HYDRATION_SCRIPT_ID,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "astro",
3
- "version": "3.4.3",
3
+ "version": "3.5.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",
@@ -78,7 +78,9 @@
78
78
  "default": "./dist/core/middleware/namespace.js"
79
79
  },
80
80
  "./transitions": "./dist/transitions/index.js",
81
- "./transitions/router": "./dist/transitions/router.js"
81
+ "./transitions/router": "./dist/transitions/router.js",
82
+ "./prefetch": "./dist/prefetch/index.js",
83
+ "./i18n": "./dist/i18n/index.js"
82
84
  },
83
85
  "imports": {
84
86
  "#astro/*": "./dist/*.js"
@@ -107,7 +109,7 @@
107
109
  "vendor"
108
110
  ],
109
111
  "dependencies": {
110
- "@astrojs/compiler": "^2.1.0",
112
+ "@astrojs/compiler": "^2.3.0",
111
113
  "@babel/core": "^7.22.10",
112
114
  "@babel/generator": "^7.22.10",
113
115
  "@babel/parser": "^7.22.10",
@@ -163,7 +165,7 @@
163
165
  "yargs-parser": "^21.1.1",
164
166
  "zod": "^3.22.4",
165
167
  "@astrojs/internal-helpers": "0.2.1",
166
- "@astrojs/markdown-remark": "3.3.0",
168
+ "@astrojs/markdown-remark": "3.4.0",
167
169
  "@astrojs/telemetry": "3.0.4"
168
170
  },
169
171
  "optionalDependencies": {
@@ -198,7 +200,7 @@
198
200
  "chai": "^4.3.7",
199
201
  "cheerio": "1.0.0-rc.12",
200
202
  "eol": "^0.9.1",
201
- "memfs": "^4.2.1",
203
+ "memfs": "^4.6.0",
202
204
  "mocha": "^10.2.0",
203
205
  "node-mocks-http": "^1.13.0",
204
206
  "parse-srcset": "^1.0.2",
@@ -4,7 +4,7 @@
4
4
  // Enable top-level await, and other modern ESM features.
5
5
  "target": "ESNext",
6
6
  "module": "ESNext",
7
- // Enable node-style module resolution, for things like npm package imports.
7
+ // Enable module resolution without file extensions on relative paths, for things like npm package imports.
8
8
  "moduleResolution": "Bundler",
9
9
  // Allow importing TypeScript files using their native extension (.ts(x)).
10
10
  "allowImportingTsExtensions": true,
@@ -1,2 +0,0 @@
1
- import { type SSROptions } from '../../render/index.js';
2
- export declare function call(options: SSROptions): Promise<Response>;
@@ -1,17 +0,0 @@
1
- import { createRenderContext } from "../../render/index.js";
2
- import { callEndpoint } from "../index.js";
3
- async function call(options) {
4
- const { env, preload, middleware } = options;
5
- const endpointHandler = preload;
6
- const ctx = await createRenderContext({
7
- request: options.request,
8
- pathname: options.pathname,
9
- route: options.route,
10
- env,
11
- mod: preload
12
- });
13
- return await callEndpoint(endpointHandler, env, ctx, middleware?.onRequest);
14
- }
15
- export {
16
- call
17
- };