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.
- package/client.d.ts +86 -0
- package/components/Code.astro +37 -4
- package/components/Image.astro +2 -2
- package/components/Picture.astro +19 -5
- package/components/ViewTransitions.astro +39 -38
- package/content-module.template.mjs +4 -14
- package/dist/@types/astro.d.ts +223 -5
- package/dist/assets/build/generate.d.ts +2 -1
- package/dist/assets/build/generate.js +16 -5
- package/dist/assets/consts.d.ts +1 -0
- package/dist/assets/consts.js +2 -0
- package/dist/assets/endpoint/generic.js +6 -2
- package/dist/assets/internal.js +11 -2
- package/dist/assets/services/service.d.ts +10 -10
- package/dist/assets/services/service.js +2 -1
- package/dist/assets/services/vendor/squoosh/image-pool.d.ts +1 -2
- package/dist/assets/types.d.ts +19 -9
- package/dist/assets/utils/emitAsset.js +5 -0
- package/dist/assets/utils/metadata.d.ts +1 -2
- package/dist/assets/utils/proxy.d.ts +1 -0
- package/dist/assets/utils/proxy.js +16 -0
- package/dist/assets/utils/queryParams.d.ts +1 -1
- package/dist/assets/utils/transformToPath.d.ts +1 -1
- package/dist/assets/utils/transformToPath.js +8 -3
- package/dist/assets/vite-plugin-assets.js +26 -11
- package/dist/cli/build/index.js +1 -1
- package/dist/content/consts.d.ts +1 -0
- package/dist/content/consts.js +2 -0
- package/dist/content/runtime-assets.d.ts +9 -1
- package/dist/content/runtime-assets.js +1 -1
- package/dist/content/runtime.d.ts +1 -0
- package/dist/content/runtime.js +8 -2
- package/dist/content/utils.d.ts +1 -0
- package/dist/content/utils.js +9 -0
- package/dist/content/vite-plugin-content-assets.js +49 -23
- package/dist/content/vite-plugin-content-imports.js +9 -3
- package/dist/content/vite-plugin-content-virtual-mod.d.ts +17 -12
- package/dist/content/vite-plugin-content-virtual-mod.js +136 -57
- package/dist/core/app/index.js +19 -4
- package/dist/core/app/types.d.ts +7 -1
- package/dist/core/build/buildPipeline.js +17 -4
- package/dist/core/build/common.js +2 -0
- package/dist/core/build/generate.js +64 -34
- package/dist/core/build/index.d.ts +0 -8
- package/dist/core/build/index.js +9 -2
- package/dist/core/build/internal.d.ts +11 -1
- package/dist/core/build/internal.js +23 -1
- package/dist/core/build/page-data.js +46 -18
- package/dist/core/build/plugin.d.ts +12 -10
- package/dist/core/build/plugin.js +14 -22
- package/dist/core/build/plugins/index.js +4 -0
- package/dist/core/build/plugins/plugin-alias-resolve.js +1 -1
- package/dist/core/build/plugins/plugin-analyzer.js +1 -1
- package/dist/core/build/plugins/plugin-chunks.d.ts +4 -0
- package/dist/core/build/plugins/plugin-chunks.js +31 -0
- package/dist/core/build/plugins/plugin-component-entry.js +1 -1
- package/dist/core/build/plugins/plugin-content.d.ts +4 -0
- package/dist/core/build/plugins/plugin-content.js +273 -0
- package/dist/core/build/plugins/plugin-css.js +9 -4
- package/dist/core/build/plugins/plugin-hoisted-scripts.js +1 -1
- package/dist/core/build/plugins/plugin-internals.js +1 -1
- package/dist/core/build/plugins/plugin-manifest.js +14 -5
- package/dist/core/build/plugins/plugin-middleware.d.ts +1 -3
- package/dist/core/build/plugins/plugin-middleware.js +5 -57
- package/dist/core/build/plugins/plugin-pages.js +3 -3
- package/dist/core/build/plugins/plugin-prerender.js +2 -5
- package/dist/core/build/plugins/plugin-renderers.js +1 -1
- package/dist/core/build/plugins/plugin-ssr.js +6 -5
- package/dist/core/build/plugins/util.d.ts +3 -3
- package/dist/core/build/static-build.d.ts +2 -1
- package/dist/core/build/static-build.js +52 -28
- package/dist/core/build/types.d.ts +1 -1
- package/dist/core/build/util.d.ts +7 -0
- package/dist/core/build/util.js +37 -1
- package/dist/core/compile/compile.js +1 -0
- package/dist/core/config/config.js +3 -0
- package/dist/core/config/schema.d.ts +208 -0
- package/dist/core/config/schema.js +72 -4
- package/dist/core/config/settings.js +1 -0
- package/dist/core/constants.js +1 -1
- package/dist/core/create-vite.js +9 -3
- package/dist/core/dev/dev.js +1 -1
- package/dist/core/endpoint/index.d.ts +4 -3
- package/dist/core/endpoint/index.js +29 -3
- package/dist/core/errors/errors-data.d.ts +11 -0
- package/dist/core/errors/errors-data.js +17 -0
- package/dist/core/messages.js +2 -2
- package/dist/core/middleware/index.d.ts +7 -3
- package/dist/core/middleware/index.js +3 -2
- package/dist/core/middleware/loadMiddleware.d.ts +1 -2
- package/dist/core/middleware/loadMiddleware.js +3 -4
- package/dist/core/middleware/sequence.d.ts +2 -2
- package/dist/core/middleware/sequence.js +3 -2
- package/dist/core/middleware/vite-plugin.d.ts +9 -0
- package/dist/core/middleware/vite-plugin.js +101 -0
- package/dist/core/pipeline.d.ts +1 -1
- package/dist/core/pipeline.js +6 -4
- package/dist/core/preview/static-preview-server.js +3 -1
- package/dist/core/preview/vite-plugin-astro-preview.js +13 -2
- package/dist/core/redirects/helpers.d.ts +1 -0
- package/dist/core/redirects/helpers.js +4 -0
- package/dist/core/render/context.d.ts +24 -1
- package/dist/core/render/context.js +96 -2
- package/dist/core/render/core.d.ts +2 -14
- package/dist/core/render/core.js +12 -52
- package/dist/core/render/index.d.ts +2 -3
- package/dist/core/render/index.js +3 -4
- package/dist/core/render/params-and-props.d.ts +1 -1
- package/dist/core/render/params-and-props.js +5 -2
- package/dist/core/render/result.d.ts +1 -0
- package/dist/core/render/result.js +23 -0
- package/dist/core/render/route-cache.d.ts +1 -1
- package/dist/core/render/route-cache.js +17 -11
- package/dist/core/routing/manifest/create.js +118 -4
- package/dist/core/sync/index.d.ts +2 -24
- package/dist/i18n/index.d.ts +54 -0
- package/dist/i18n/index.js +91 -0
- package/dist/i18n/middleware.d.ts +2 -0
- package/dist/i18n/middleware.js +62 -0
- package/dist/i18n/vite-plugin-i18n.d.ts +7 -0
- package/dist/i18n/vite-plugin-i18n.js +62 -0
- package/dist/integrations/astroFeaturesValidation.js +4 -1
- package/dist/integrations/index.js +12 -0
- package/dist/prefetch/index.d.ts +31 -0
- package/dist/prefetch/index.js +176 -0
- package/dist/prefetch/vite-plugin-prefetch.d.ts +5 -0
- package/dist/prefetch/vite-plugin-prefetch.js +43 -0
- package/dist/runtime/client/dev-overlay/entrypoint.js +2 -2
- package/dist/runtime/client/dev-overlay/overlay.d.ts +10 -2
- package/dist/runtime/client/dev-overlay/overlay.js +47 -28
- package/dist/runtime/client/dev-overlay/plugins/astro.d.ts +1 -0
- package/dist/runtime/client/dev-overlay/plugins/astro.js +44 -9
- package/dist/runtime/client/dev-overlay/plugins/audit.d.ts +2 -1
- package/dist/runtime/client/dev-overlay/plugins/audit.js +101 -24
- package/dist/runtime/client/dev-overlay/plugins/xray.d.ts +1 -0
- package/dist/runtime/client/dev-overlay/plugins/xray.js +22 -0
- package/dist/runtime/client/dev-overlay/ui-library/card.js +2 -0
- package/dist/runtime/client/dev-overlay/ui-library/icons.d.ts +3 -0
- package/dist/runtime/client/dev-overlay/ui-library/icons.js +4 -1
- package/dist/runtime/client/dev-overlay/ui-library/tooltip.js +1 -0
- package/dist/runtime/client/dev-overlay/ui-library/window.js +1 -0
- package/dist/runtime/server/index.d.ts +0 -2
- package/dist/runtime/server/render/component.js +3 -5
- package/dist/transitions/router.d.ts +1 -0
- package/dist/transitions/router.js +10 -5
- package/dist/transitions/vite-plugin-transitions.d.ts +4 -1
- package/dist/transitions/vite-plugin-transitions.js +7 -1
- package/dist/vite-plugin-astro-server/devPipeline.d.ts +1 -0
- package/dist/vite-plugin-astro-server/devPipeline.js +2 -0
- package/dist/vite-plugin-astro-server/plugin.js +11 -1
- package/dist/vite-plugin-astro-server/route.js +113 -51
- package/dist/vite-plugin-head/index.js +1 -1
- package/dist/vite-plugin-markdown/index.js +1 -0
- package/dist/vite-plugin-scripts/index.js +2 -1
- package/package.json +7 -5
- package/tsconfigs/base.json +1 -1
- package/dist/core/endpoint/dev/index.d.ts +0 -2
- 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 {
|
|
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
|
-
|
|
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
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
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
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
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,
|
|
@@ -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
|
-
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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",
|
package/tsconfigs/base.json
CHANGED
|
@@ -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
|
|
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,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
|
-
};
|