astro 4.10.2 → 4.11.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/components/Code.astro +9 -0
- package/dist/@types/astro.d.ts +43 -39
- package/dist/actions/runtime/virtual/server.d.ts +1 -1
- package/dist/assets/internal.d.ts +1 -1
- package/dist/assets/internal.js +6 -0
- package/dist/assets/types.d.ts +8 -2
- package/dist/assets/types.js +7 -0
- package/dist/container/index.d.ts +32 -1
- package/dist/container/index.js +45 -0
- package/dist/container/pipeline.d.ts +0 -1
- package/dist/container/pipeline.js +13 -32
- package/dist/container/vite-plugin-container.d.ts +2 -0
- package/dist/container/vite-plugin-container.js +15 -0
- package/dist/content/runtime-assets.d.ts +3 -3
- package/dist/content/types-generator.js +55 -34
- package/dist/content/utils.d.ts +11 -0
- package/dist/content/utils.js +49 -0
- package/dist/content/vite-plugin-content-imports.d.ts +3 -1
- package/dist/content/vite-plugin-content-imports.js +15 -4
- package/dist/core/app/index.d.ts +4 -0
- package/dist/core/app/index.js +17 -6
- package/dist/core/app/pipeline.d.ts +1 -2
- package/dist/core/app/pipeline.js +11 -39
- package/dist/core/base-pipeline.d.ts +0 -9
- package/dist/core/base-pipeline.js +1 -1
- package/dist/core/build/internal.d.ts +4 -0
- package/dist/core/build/internal.js +2 -1
- package/dist/core/build/page-data.js +2 -4
- package/dist/core/build/pipeline.d.ts +1 -2
- package/dist/core/build/pipeline.js +16 -42
- package/dist/core/build/plugins/plugin-chunks.js +6 -0
- package/dist/core/build/plugins/plugin-prerender.js +55 -48
- package/dist/core/build/plugins/plugin-ssr.js +15 -12
- package/dist/core/build/static-build.js +36 -44
- package/dist/core/build/types.d.ts +0 -1
- package/dist/core/config/schema.d.ts +4 -156
- package/dist/core/constants.d.ts +4 -0
- package/dist/core/constants.js +3 -1
- package/dist/core/cookies/cookies.d.ts +5 -0
- package/dist/core/cookies/cookies.js +12 -0
- package/dist/core/cookies/response.d.ts +1 -0
- package/dist/core/cookies/response.js +1 -0
- package/dist/core/create-vite.js +4 -6
- package/dist/core/dev/dev.js +1 -1
- package/dist/core/errors/errors-data.d.ts +40 -11
- package/dist/core/errors/errors-data.js +13 -6
- package/dist/core/messages.js +2 -2
- package/dist/core/render-context.d.ts +1 -1
- package/dist/core/render-context.js +22 -6
- package/dist/core/request.js +7 -1
- package/dist/core/routing/astro-designed-error-pages.d.ts +1 -0
- package/dist/core/routing/astro-designed-error-pages.js +15 -1
- package/dist/core/routing/rewrite.d.ts +10 -0
- package/dist/core/routing/rewrite.js +41 -0
- package/dist/core/util.js +5 -2
- package/dist/env/constants.d.ts +0 -1
- package/dist/env/constants.js +0 -2
- package/dist/env/runtime.d.ts +3 -1
- package/dist/env/runtime.js +8 -1
- package/dist/env/schema.d.ts +2 -78
- package/dist/env/schema.js +1 -17
- package/dist/env/vite-plugin-env.js +15 -15
- package/dist/jsx/server.d.ts +3 -5
- package/dist/jsx/server.js +3 -1
- package/dist/vite-plugin-astro/index.js +1 -1
- package/dist/vite-plugin-astro-server/pipeline.d.ts +1 -2
- package/dist/vite-plugin-astro-server/pipeline.js +15 -42
- package/dist/vite-plugin-astro-server/request.js +1 -1
- package/dist/vite-plugin-astro-server/route.js +53 -94
- package/package.json +8 -7
- package/templates/env/module.mjs +14 -5
- package/templates/env/types.d.ts +1 -12
|
@@ -21,6 +21,10 @@ function getCustom404Route(manifestData) {
|
|
|
21
21
|
const route404 = /^\/404\/?$/;
|
|
22
22
|
return manifestData.routes.find((r) => route404.test(r.route));
|
|
23
23
|
}
|
|
24
|
+
function getCustom500Route(manifestData) {
|
|
25
|
+
const route500 = /^\/500\/?$/;
|
|
26
|
+
return manifestData.routes.find((r) => route500.test(r.route));
|
|
27
|
+
}
|
|
24
28
|
async function matchRoute(pathname, manifestData, pipeline) {
|
|
25
29
|
const { config, logger, routeCache, serverLike, settings } = pipeline;
|
|
26
30
|
const matches = matchAllRoutes(pathname, manifestData);
|
|
@@ -104,11 +108,8 @@ async function handleRoute({
|
|
|
104
108
|
}) {
|
|
105
109
|
const timeStart = performance.now();
|
|
106
110
|
const { config, loader, logger } = pipeline;
|
|
107
|
-
if (!matchedRoute
|
|
108
|
-
|
|
109
|
-
logger.info(null, req({ url: pathname, method: incomingRequest.method, statusCode: 404 }));
|
|
110
|
-
}
|
|
111
|
-
return handle404Response(origin, incomingRequest, incomingResponse);
|
|
111
|
+
if (!matchedRoute) {
|
|
112
|
+
throw new Error("No route matched, and default 404 route was not found.");
|
|
112
113
|
}
|
|
113
114
|
let request;
|
|
114
115
|
let renderContext;
|
|
@@ -117,97 +118,55 @@ async function handleRoute({
|
|
|
117
118
|
let route;
|
|
118
119
|
const middleware = (await loadMiddleware(loader)).onRequest;
|
|
119
120
|
const locals = Reflect.get(incomingRequest, clientLocalsSymbol);
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
route
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
prerender: false,
|
|
162
|
-
segments: [],
|
|
163
|
-
type: "fallback",
|
|
164
|
-
route: "",
|
|
165
|
-
fallbackRoutes: [],
|
|
166
|
-
isIndex: false
|
|
167
|
-
};
|
|
168
|
-
renderContext = RenderContext.create({
|
|
169
|
-
pipeline,
|
|
170
|
-
pathname,
|
|
171
|
-
middleware,
|
|
172
|
-
request,
|
|
173
|
-
routeData: route
|
|
174
|
-
});
|
|
175
|
-
} else {
|
|
176
|
-
const filePath = matchedRoute.filePath;
|
|
177
|
-
const { preloadedComponent } = matchedRoute;
|
|
178
|
-
route = matchedRoute.route;
|
|
179
|
-
request = createRequest({
|
|
180
|
-
base: config.base,
|
|
181
|
-
url,
|
|
182
|
-
headers: incomingRequest.headers,
|
|
183
|
-
method: incomingRequest.method,
|
|
184
|
-
body,
|
|
185
|
-
logger,
|
|
186
|
-
clientAddress: incomingRequest.socket.remoteAddress,
|
|
187
|
-
staticLike: config.output === "static" || route.prerender
|
|
188
|
-
});
|
|
189
|
-
for (const [name, value] of Object.entries(config.server.headers ?? {})) {
|
|
190
|
-
if (value) incomingResponse.setHeader(name, value);
|
|
121
|
+
const filePath = matchedRoute.filePath;
|
|
122
|
+
const { preloadedComponent } = matchedRoute;
|
|
123
|
+
route = matchedRoute.route;
|
|
124
|
+
request = createRequest({
|
|
125
|
+
base: config.base,
|
|
126
|
+
url,
|
|
127
|
+
headers: incomingRequest.headers,
|
|
128
|
+
method: incomingRequest.method,
|
|
129
|
+
body,
|
|
130
|
+
logger,
|
|
131
|
+
clientAddress: incomingRequest.socket.remoteAddress,
|
|
132
|
+
staticLike: config.output === "static" || route.prerender
|
|
133
|
+
});
|
|
134
|
+
for (const [name, value] of Object.entries(config.server.headers ?? {})) {
|
|
135
|
+
if (value) incomingResponse.setHeader(name, value);
|
|
136
|
+
}
|
|
137
|
+
options = {
|
|
138
|
+
pipeline,
|
|
139
|
+
filePath,
|
|
140
|
+
preload: preloadedComponent,
|
|
141
|
+
pathname,
|
|
142
|
+
request,
|
|
143
|
+
route
|
|
144
|
+
};
|
|
145
|
+
mod = preloadedComponent;
|
|
146
|
+
const isPrerendered404 = matchedRoute.route.route === "/404" && matchedRoute.route.prerender;
|
|
147
|
+
renderContext = RenderContext.create({
|
|
148
|
+
locals,
|
|
149
|
+
pipeline,
|
|
150
|
+
pathname,
|
|
151
|
+
middleware: isPrerendered404 ? void 0 : middleware,
|
|
152
|
+
request,
|
|
153
|
+
routeData: route
|
|
154
|
+
});
|
|
155
|
+
let response;
|
|
156
|
+
try {
|
|
157
|
+
response = await renderContext.render(mod);
|
|
158
|
+
} catch (err) {
|
|
159
|
+
const custom500 = getCustom500Route(manifestData);
|
|
160
|
+
if (!custom500) {
|
|
161
|
+
throw err;
|
|
191
162
|
}
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
route
|
|
199
|
-
};
|
|
200
|
-
mod = preloadedComponent;
|
|
201
|
-
renderContext = RenderContext.create({
|
|
202
|
-
locals,
|
|
203
|
-
pipeline,
|
|
204
|
-
pathname,
|
|
205
|
-
middleware,
|
|
206
|
-
request,
|
|
207
|
-
routeData: route
|
|
208
|
-
});
|
|
163
|
+
logger.error("router", err.stack || err.message);
|
|
164
|
+
const filePath500 = new URL(`./${custom500.component}`, config.root);
|
|
165
|
+
const preloaded500Component = await pipeline.preload(custom500, filePath500);
|
|
166
|
+
renderContext.props.error = err;
|
|
167
|
+
response = await renderContext.render(preloaded500Component);
|
|
168
|
+
status = 500;
|
|
209
169
|
}
|
|
210
|
-
let response = await renderContext.render(mod);
|
|
211
170
|
if (isLoggedRequest(pathname)) {
|
|
212
171
|
const timeEnd = performance.now();
|
|
213
172
|
logger.info(
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "astro",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.11.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",
|
|
@@ -118,7 +118,7 @@
|
|
|
118
118
|
"@babel/types": "^7.24.7",
|
|
119
119
|
"@types/babel__core": "^7.20.5",
|
|
120
120
|
"@types/cookie": "^0.6.0",
|
|
121
|
-
"acorn": "^8.
|
|
121
|
+
"acorn": "^8.12.0",
|
|
122
122
|
"aria-query": "^5.3.0",
|
|
123
123
|
"axobject-query": "^4.0.0",
|
|
124
124
|
"boxen": "^7.1.1",
|
|
@@ -157,20 +157,20 @@
|
|
|
157
157
|
"rehype": "^13.0.1",
|
|
158
158
|
"resolve": "^1.22.8",
|
|
159
159
|
"semver": "^7.6.2",
|
|
160
|
-
"shiki": "^1.6.
|
|
160
|
+
"shiki": "^1.6.5",
|
|
161
161
|
"string-width": "^7.1.0",
|
|
162
162
|
"strip-ansi": "^7.1.0",
|
|
163
163
|
"tsconfck": "^3.1.0",
|
|
164
164
|
"unist-util-visit": "^5.0.0",
|
|
165
165
|
"vfile": "^6.0.1",
|
|
166
|
-
"vite": "^5.
|
|
166
|
+
"vite": "^5.3.1",
|
|
167
167
|
"vitefu": "^0.2.5",
|
|
168
168
|
"which-pm": "^2.2.0",
|
|
169
169
|
"yargs-parser": "^21.1.1",
|
|
170
170
|
"zod": "^3.23.8",
|
|
171
171
|
"zod-to-json-schema": "^3.23.0",
|
|
172
|
-
"@astrojs/internal-helpers": "0.4.0",
|
|
173
172
|
"@astrojs/markdown-remark": "5.1.0",
|
|
173
|
+
"@astrojs/internal-helpers": "0.4.0",
|
|
174
174
|
"@astrojs/telemetry": "3.1.0"
|
|
175
175
|
},
|
|
176
176
|
"optionalDependencies": {
|
|
@@ -204,7 +204,7 @@
|
|
|
204
204
|
"eol": "^0.9.1",
|
|
205
205
|
"mdast-util-mdx": "^3.0.0",
|
|
206
206
|
"mdast-util-mdx-jsx": "^3.1.2",
|
|
207
|
-
"memfs": "^4.9.
|
|
207
|
+
"memfs": "^4.9.3",
|
|
208
208
|
"node-mocks-http": "^1.14.1",
|
|
209
209
|
"parse-srcset": "^1.0.2",
|
|
210
210
|
"rehype-autolink-headings": "^7.1.0",
|
|
@@ -212,8 +212,9 @@
|
|
|
212
212
|
"rehype-toc": "^3.0.2",
|
|
213
213
|
"remark-code-titles": "^0.1.2",
|
|
214
214
|
"rollup": "^4.18.0",
|
|
215
|
-
"sass": "^1.77.
|
|
215
|
+
"sass": "^1.77.5",
|
|
216
216
|
"srcset-parse": "^1.1.0",
|
|
217
|
+
"undici": "^6.19.2",
|
|
217
218
|
"unified": "^11.0.4",
|
|
218
219
|
"astro-scripts": "0.0.14"
|
|
219
220
|
},
|
package/templates/env/module.mjs
CHANGED
|
@@ -1,18 +1,27 @@
|
|
|
1
1
|
import { schema } from 'virtual:astro:env/internal';
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
createInvalidVariableError,
|
|
4
|
+
getEnv,
|
|
5
|
+
setOnSetGetEnv,
|
|
6
|
+
validateEnvVariable,
|
|
7
|
+
} from 'astro/env/runtime';
|
|
3
8
|
|
|
4
9
|
export const getSecret = (key) => {
|
|
10
|
+
return getEnv(key);
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
const _internalGetSecret = (key) => {
|
|
5
14
|
const rawVariable = getEnv(key);
|
|
6
15
|
const variable = rawVariable === '' ? undefined : rawVariable;
|
|
7
16
|
const options = schema[key];
|
|
8
17
|
|
|
9
|
-
if (!options) {
|
|
10
|
-
return variable;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
18
|
const result = validateEnvVariable(variable, options);
|
|
14
19
|
if (result.ok) {
|
|
15
20
|
return result.value;
|
|
16
21
|
}
|
|
17
22
|
throw createInvalidVariableError(key, result.type);
|
|
18
23
|
};
|
|
24
|
+
|
|
25
|
+
setOnSetGetEnv((reset) => {
|
|
26
|
+
// @@ON_SET_GET_ENV@@
|
|
27
|
+
});
|
package/templates/env/types.d.ts
CHANGED
|
@@ -5,16 +5,5 @@ declare module 'astro:env/client' {
|
|
|
5
5
|
declare module 'astro:env/server' {
|
|
6
6
|
// @@SERVER@@
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
// @@SECRET_VALUES@@
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
type SecretValue = keyof SecretValues;
|
|
13
|
-
|
|
14
|
-
type Loose<T> = T | (string & {});
|
|
15
|
-
type Strictify<T extends string> = T extends `${infer _}` ? T : never;
|
|
16
|
-
|
|
17
|
-
export const getSecret: <TKey extends Loose<SecretValue>>(
|
|
18
|
-
key: TKey
|
|
19
|
-
) => TKey extends Strictify<SecretValue> ? SecretValues[TKey] : string | undefined;
|
|
8
|
+
export const getSecret: (key: string) => string | undefined;
|
|
20
9
|
}
|