astro 1.5.0 → 1.5.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/astro-jsx.d.ts +8 -6
- package/config.d.ts +1 -1
- package/dist/core/add/index.js +1 -1
- package/dist/core/app/index.js +45 -43
- package/dist/core/build/common.js +2 -1
- package/dist/core/build/generate.js +14 -30
- package/dist/core/build/static-build.js +1 -1
- package/dist/core/config/schema.js +12 -1
- package/dist/core/config/tsconfig.js +5 -6
- package/dist/core/constants.js +1 -1
- package/dist/core/dev/index.js +1 -1
- package/dist/core/endpoint/dev/index.d.ts +2 -1
- package/dist/core/endpoint/dev/index.js +13 -9
- package/dist/core/endpoint/index.d.ts +4 -3
- package/dist/core/endpoint/index.js +16 -8
- package/dist/core/messages.js +2 -2
- package/dist/core/render/context.d.ts +20 -0
- package/dist/core/render/context.js +15 -0
- package/dist/core/render/core.d.ts +4 -24
- package/dist/core/render/core.js +26 -47
- package/dist/core/render/dev/environment.d.ts +9 -0
- package/dist/core/render/dev/environment.js +30 -0
- package/dist/core/render/dev/index.d.ts +22 -5
- package/dist/core/render/dev/index.js +38 -69
- package/dist/core/render/dev/resolve.d.ts +2 -0
- package/dist/core/render/dev/resolve.js +14 -0
- package/dist/core/render/environment.d.ts +29 -0
- package/dist/core/render/environment.js +21 -0
- package/dist/core/render/index.d.ts +6 -0
- package/dist/core/render/index.js +13 -0
- package/dist/core/render/renderer.d.ts +9 -0
- package/dist/core/render/renderer.js +23 -0
- package/dist/core/render/result.js +1 -1
- package/dist/core/routing/manifest/create.js +14 -5
- package/dist/core/routing/manifest/generator.js +8 -3
- package/dist/jsx/component.d.ts +1 -0
- package/dist/jsx/component.js +10 -0
- package/dist/jsx/index.d.ts +2 -0
- package/dist/jsx/index.js +6 -0
- package/dist/jsx-runtime/index.js +1 -1
- package/dist/runtime/server/index.d.ts +1 -0
- package/dist/runtime/server/index.js +2 -0
- package/dist/vite-plugin-astro-server/index.js +47 -60
- package/env.d.ts +1 -1
- package/package.json +5 -2
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import mime from "mime";
|
|
2
2
|
import { Readable } from "stream";
|
|
3
|
-
import { getSetCookiesFromResponse } from "../core/cookies/index.js";
|
|
3
|
+
import { attachToResponse, getSetCookiesFromResponse } from "../core/cookies/index.js";
|
|
4
4
|
import { call as callEndpoint } from "../core/endpoint/dev/index.js";
|
|
5
5
|
import {
|
|
6
6
|
collectErrorMetadata,
|
|
@@ -10,9 +10,8 @@ import {
|
|
|
10
10
|
import { error, info, warn } from "../core/logger/core.js";
|
|
11
11
|
import * as msg from "../core/messages.js";
|
|
12
12
|
import { appendForwardSlash } from "../core/path.js";
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import { RouteCache } from "../core/render/route-cache.js";
|
|
13
|
+
import { createDevelopmentEnvironment, preload, renderPage } from "../core/render/dev/index.js";
|
|
14
|
+
import { getParamsAndProps, GetParamsAndPropsError } from "../core/render/index.js";
|
|
16
15
|
import { createRequest } from "../core/request.js";
|
|
17
16
|
import { createRouteManifest, matchAllRoutes } from "../core/routing/index.js";
|
|
18
17
|
import { resolvePages } from "../core/util.js";
|
|
@@ -68,7 +67,7 @@ async function writeWebResponse(res, webResponse) {
|
|
|
68
67
|
async function writeSSRResult(webResponse, res) {
|
|
69
68
|
return writeWebResponse(res, webResponse);
|
|
70
69
|
}
|
|
71
|
-
async function handle404Response(origin,
|
|
70
|
+
async function handle404Response(origin, req, res) {
|
|
72
71
|
const pathname = decodeURI(new URL(origin + req.url).pathname);
|
|
73
72
|
const html = notFoundTemplate({
|
|
74
73
|
statusCode: 404,
|
|
@@ -129,11 +128,12 @@ function baseMiddleware(settings, logging) {
|
|
|
129
128
|
next();
|
|
130
129
|
};
|
|
131
130
|
}
|
|
132
|
-
async function matchRoute(pathname,
|
|
131
|
+
async function matchRoute(pathname, env, manifest) {
|
|
132
|
+
const { logging, settings, routeCache } = env;
|
|
133
133
|
const matches = matchAllRoutes(pathname, manifest);
|
|
134
134
|
for await (const maybeRoute of matches) {
|
|
135
135
|
const filePath = new URL(`./${maybeRoute.component}`, settings.config.root);
|
|
136
|
-
const preloadedComponent = await preload({
|
|
136
|
+
const preloadedComponent = await preload({ env, filePath });
|
|
137
137
|
const [, mod] = preloadedComponent;
|
|
138
138
|
const paramsAndPropsRes = await getParamsAndProps({
|
|
139
139
|
mod,
|
|
@@ -163,7 +163,7 @@ async function matchRoute(pathname, routeCache, viteServer, logging, manifest, s
|
|
|
163
163
|
const custom404 = getCustom404Route(settings, manifest);
|
|
164
164
|
if (custom404) {
|
|
165
165
|
const filePath = new URL(`./${custom404.component}`, settings.config.root);
|
|
166
|
-
const preloadedComponent = await preload({
|
|
166
|
+
const preloadedComponent = await preload({ env, filePath });
|
|
167
167
|
const [, mod] = preloadedComponent;
|
|
168
168
|
return {
|
|
169
169
|
route: custom404,
|
|
@@ -174,8 +174,9 @@ async function matchRoute(pathname, routeCache, viteServer, logging, manifest, s
|
|
|
174
174
|
}
|
|
175
175
|
return void 0;
|
|
176
176
|
}
|
|
177
|
-
async function handleRequest(
|
|
177
|
+
async function handleRequest(env, manifest, req, res) {
|
|
178
178
|
var _a;
|
|
179
|
+
const { settings, viteServer } = env;
|
|
179
180
|
const { config } = settings;
|
|
180
181
|
const origin = `${viteServer.config.server.https ? "https" : "http"}://${req.headers.host}`;
|
|
181
182
|
const buildingToSSR = config.output === "server";
|
|
@@ -201,39 +202,30 @@ async function handleRequest(routeCache, viteServer, logging, manifest, settings
|
|
|
201
202
|
}
|
|
202
203
|
let filePath;
|
|
203
204
|
try {
|
|
204
|
-
const matchedRoute = await matchRoute(
|
|
205
|
-
pathname,
|
|
206
|
-
routeCache,
|
|
207
|
-
viteServer,
|
|
208
|
-
logging,
|
|
209
|
-
manifest,
|
|
210
|
-
settings
|
|
211
|
-
);
|
|
205
|
+
const matchedRoute = await matchRoute(pathname, env, manifest);
|
|
212
206
|
filePath = matchedRoute == null ? void 0 : matchedRoute.filePath;
|
|
213
|
-
return await handleRoute(
|
|
214
|
-
matchedRoute,
|
|
215
|
-
url,
|
|
216
|
-
pathname,
|
|
217
|
-
body,
|
|
218
|
-
origin,
|
|
219
|
-
routeCache,
|
|
220
|
-
viteServer,
|
|
221
|
-
manifest,
|
|
222
|
-
logging,
|
|
223
|
-
settings,
|
|
224
|
-
req,
|
|
225
|
-
res
|
|
226
|
-
);
|
|
207
|
+
return await handleRoute(matchedRoute, url, pathname, body, origin, env, manifest, req, res);
|
|
227
208
|
} catch (_err) {
|
|
228
209
|
const err = fixViteErrorMessage(_err, viteServer, filePath);
|
|
229
210
|
const errorWithMetadata = collectErrorMetadata(err);
|
|
230
|
-
error(logging, null, msg.formatErrorMessage(errorWithMetadata));
|
|
211
|
+
error(env.logging, null, msg.formatErrorMessage(errorWithMetadata));
|
|
231
212
|
handle500Response(viteServer, origin, req, res, errorWithMetadata);
|
|
232
213
|
}
|
|
233
214
|
}
|
|
234
|
-
|
|
215
|
+
function isRedirect(statusCode) {
|
|
216
|
+
return statusCode >= 300 && statusCode < 400;
|
|
217
|
+
}
|
|
218
|
+
function throwIfRedirectNotAllowed(response, config) {
|
|
219
|
+
if (config.output !== "server" && isRedirect(response.status)) {
|
|
220
|
+
throw new Error(
|
|
221
|
+
`Redirects are only available when using output: 'server'. Update your Astro config if you need SSR features.`
|
|
222
|
+
);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
async function handleRoute(matchedRoute, url, pathname, body, origin, env, manifest, req, res) {
|
|
226
|
+
const { logging, settings } = env;
|
|
235
227
|
if (!matchedRoute) {
|
|
236
|
-
return handle404Response(origin,
|
|
228
|
+
return handle404Response(origin, req, res);
|
|
237
229
|
}
|
|
238
230
|
const { config } = settings;
|
|
239
231
|
const filePath = matchedRoute.filePath;
|
|
@@ -251,50 +243,38 @@ async function handleRoute(matchedRoute, url, pathname, body, origin, routeCache
|
|
|
251
243
|
const paramsAndPropsRes = await getParamsAndProps({
|
|
252
244
|
mod,
|
|
253
245
|
route,
|
|
254
|
-
routeCache,
|
|
246
|
+
routeCache: env.routeCache,
|
|
255
247
|
pathname,
|
|
256
248
|
logging,
|
|
257
249
|
ssr: config.output === "server"
|
|
258
250
|
});
|
|
259
251
|
const options = {
|
|
260
|
-
|
|
252
|
+
env,
|
|
261
253
|
filePath,
|
|
262
|
-
logging,
|
|
263
|
-
mode: "development",
|
|
264
254
|
origin,
|
|
255
|
+
preload: preloadedComponent,
|
|
265
256
|
pathname,
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
viteServer,
|
|
269
|
-
request
|
|
257
|
+
request,
|
|
258
|
+
route
|
|
270
259
|
};
|
|
271
260
|
if (route.type === "endpoint") {
|
|
272
261
|
const result = await callEndpoint(options);
|
|
273
262
|
if (result.type === "response") {
|
|
274
263
|
if (result.response.headers.get("X-Astro-Response") === "Not-Found") {
|
|
275
|
-
const fourOhFourRoute = await matchRoute(
|
|
276
|
-
"/404",
|
|
277
|
-
routeCache,
|
|
278
|
-
viteServer,
|
|
279
|
-
logging,
|
|
280
|
-
manifest,
|
|
281
|
-
settings
|
|
282
|
-
);
|
|
264
|
+
const fourOhFourRoute = await matchRoute("/404", env, manifest);
|
|
283
265
|
return handleRoute(
|
|
284
266
|
fourOhFourRoute,
|
|
285
267
|
new URL("/404", url),
|
|
286
268
|
"/404",
|
|
287
269
|
body,
|
|
288
270
|
origin,
|
|
289
|
-
|
|
290
|
-
viteServer,
|
|
271
|
+
env,
|
|
291
272
|
manifest,
|
|
292
|
-
logging,
|
|
293
|
-
settings,
|
|
294
273
|
req,
|
|
295
274
|
res
|
|
296
275
|
);
|
|
297
276
|
}
|
|
277
|
+
throwIfRedirectNotAllowed(result.response, config);
|
|
298
278
|
await writeWebResponse(res, result.response);
|
|
299
279
|
} else {
|
|
300
280
|
let contentType = "text/plain";
|
|
@@ -303,11 +283,18 @@ async function handleRoute(matchedRoute, url, pathname, body, origin, routeCache
|
|
|
303
283
|
if (computedMimeType) {
|
|
304
284
|
contentType = computedMimeType;
|
|
305
285
|
}
|
|
306
|
-
|
|
307
|
-
|
|
286
|
+
const response = new Response(result.body, {
|
|
287
|
+
status: 200,
|
|
288
|
+
headers: {
|
|
289
|
+
"Content-Type": `${contentType};charset=utf-8`
|
|
290
|
+
}
|
|
291
|
+
});
|
|
292
|
+
attachToResponse(response, result.cookies);
|
|
293
|
+
await writeWebResponse(res, response);
|
|
308
294
|
}
|
|
309
295
|
} else {
|
|
310
|
-
const result = await
|
|
296
|
+
const result = await renderPage(options);
|
|
297
|
+
throwIfRedirectNotAllowed(result, config);
|
|
311
298
|
return await writeSSRResult(result, res);
|
|
312
299
|
}
|
|
313
300
|
}
|
|
@@ -315,10 +302,10 @@ function createPlugin({ settings, logging }) {
|
|
|
315
302
|
return {
|
|
316
303
|
name: "astro:server",
|
|
317
304
|
configureServer(viteServer) {
|
|
318
|
-
let
|
|
305
|
+
let env = createDevelopmentEnvironment(settings, logging, viteServer);
|
|
319
306
|
let manifest = createRouteManifest({ settings }, logging);
|
|
320
307
|
function rebuildManifest(needsManifestRebuild, file) {
|
|
321
|
-
routeCache.clearAll();
|
|
308
|
+
env.routeCache.clearAll();
|
|
322
309
|
if (needsManifestRebuild) {
|
|
323
310
|
manifest = createRouteManifest({ settings }, logging);
|
|
324
311
|
}
|
|
@@ -337,7 +324,7 @@ function createPlugin({ settings, logging }) {
|
|
|
337
324
|
if (!req.url || !req.method) {
|
|
338
325
|
throw new Error("Incomplete request");
|
|
339
326
|
}
|
|
340
|
-
handleRequest(
|
|
327
|
+
handleRequest(env, manifest, req, res);
|
|
341
328
|
});
|
|
342
329
|
};
|
|
343
330
|
},
|
package/env.d.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
// As such, if the typings you're trying to add should be available inside ex: React components, they should instead
|
|
5
5
|
// be inside `client-base.d.ts`
|
|
6
6
|
|
|
7
|
-
type Astro = import('./dist/@types/astro').AstroGlobal;
|
|
7
|
+
type Astro = import('./dist/@types/astro.js').AstroGlobal;
|
|
8
8
|
|
|
9
9
|
// We have to duplicate the description here because editors won't show the JSDoc comment from the imported type
|
|
10
10
|
// However, they will for its properties, ex: Astro.request will show the AstroGlobal.request description
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "astro",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.2",
|
|
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",
|
|
@@ -37,7 +37,10 @@
|
|
|
37
37
|
"./tsconfigs/*": "./tsconfigs/*.json",
|
|
38
38
|
"./jsx/*": "./dist/jsx/*",
|
|
39
39
|
"./jsx-runtime": "./dist/jsx-runtime/index.js",
|
|
40
|
-
"./config":
|
|
40
|
+
"./config": {
|
|
41
|
+
"types": "./config.d.ts",
|
|
42
|
+
"default": "./config.mjs"
|
|
43
|
+
},
|
|
41
44
|
"./app": "./dist/core/app/index.js",
|
|
42
45
|
"./app/node": "./dist/core/app/node.js",
|
|
43
46
|
"./client/*": "./dist/runtime/client/*",
|