astro 4.16.6 → 4.16.7
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/dist/actions/runtime/middleware.js +8 -3
- package/dist/assets/endpoint/node.js +4 -0
- package/dist/content/content-layer.js +3 -3
- package/dist/content/types-generator.js +10 -3
- package/dist/core/app/node.js +1 -1
- package/dist/core/constants.d.ts +4 -0
- package/dist/core/constants.js +3 -1
- package/dist/core/dev/dev.js +1 -1
- package/dist/core/messages.js +2 -2
- package/dist/core/render-context.js +4 -30
- package/dist/core/routing/rewrite.d.ts +9 -0
- package/dist/core/routing/rewrite.js +38 -1
- package/dist/core/server-islands/endpoint.js +1 -1
- package/dist/runtime/server/render/astro/head-and-content.js +1 -1
- package/dist/runtime/server/render/astro/instance.js +1 -1
- package/dist/runtime/server/render/astro/render-template.js +1 -1
- package/package.json +6 -6
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { yellow } from "kleur/colors";
|
|
2
2
|
import { defineMiddleware } from "../../core/middleware/index.js";
|
|
3
|
+
import { getOriginPathname } from "../../core/routing/rewrite.js";
|
|
3
4
|
import { ACTION_QUERY_PARAMS } from "../consts.js";
|
|
4
5
|
import { formContentTypes, hasContentType } from "./utils.js";
|
|
5
6
|
import { getAction } from "./virtual/get-action.js";
|
|
@@ -11,7 +12,7 @@ const onRequest = defineMiddleware(async (context, next) => {
|
|
|
11
12
|
if (context.request.method === "POST") {
|
|
12
13
|
console.warn(
|
|
13
14
|
yellow("[astro:actions]"),
|
|
14
|
-
|
|
15
|
+
"POST requests should not be sent to prerendered pages. If you're using Actions, disable prerendering with `export const prerender = false`."
|
|
15
16
|
);
|
|
16
17
|
}
|
|
17
18
|
return next();
|
|
@@ -84,10 +85,14 @@ async function redirectWithResult({
|
|
|
84
85
|
actionResult: serializeActionResult(actionResult)
|
|
85
86
|
});
|
|
86
87
|
if (actionResult.error) {
|
|
87
|
-
const
|
|
88
|
-
if (!
|
|
88
|
+
const referer2 = context.request.headers.get("Referer");
|
|
89
|
+
if (!referer2) {
|
|
89
90
|
throw new Error("Internal: Referer unexpectedly missing from Action POST request.");
|
|
90
91
|
}
|
|
92
|
+
return context.redirect(referer2);
|
|
93
|
+
}
|
|
94
|
+
const referer = getOriginPathname(context.request);
|
|
95
|
+
if (referer) {
|
|
91
96
|
return context.redirect(referer);
|
|
92
97
|
}
|
|
93
98
|
return context.redirect(context.url.pathname);
|
|
@@ -18,6 +18,10 @@ async function loadLocalImage(src, url) {
|
|
|
18
18
|
fileUrl = pathToFileURL(removeQueryString(replaceFileSystemReferences(src)));
|
|
19
19
|
} else {
|
|
20
20
|
try {
|
|
21
|
+
const idx = url.pathname.indexOf("/_image");
|
|
22
|
+
if (idx > 0) {
|
|
23
|
+
src = src.slice(idx);
|
|
24
|
+
}
|
|
21
25
|
fileUrl = new URL("." + src, outDir);
|
|
22
26
|
const filePath = fileURLToPath(fileUrl);
|
|
23
27
|
if (!isAbsolute(filePath) || !filePath.startsWith(assetsDirPath)) {
|
|
@@ -121,7 +121,7 @@ class ContentLayer {
|
|
|
121
121
|
logger.info("Content config changed");
|
|
122
122
|
shouldClear = true;
|
|
123
123
|
}
|
|
124
|
-
if (previousAstroVersion !== "4.16.
|
|
124
|
+
if (previousAstroVersion !== "4.16.7") {
|
|
125
125
|
logger.info("Astro version changed");
|
|
126
126
|
shouldClear = true;
|
|
127
127
|
}
|
|
@@ -129,8 +129,8 @@ class ContentLayer {
|
|
|
129
129
|
logger.info("Clearing content store");
|
|
130
130
|
this.#store.clearAll();
|
|
131
131
|
}
|
|
132
|
-
if ("4.16.
|
|
133
|
-
await this.#store.metaStore().set("astro-version", "4.16.
|
|
132
|
+
if ("4.16.7") {
|
|
133
|
+
await this.#store.metaStore().set("astro-version", "4.16.7");
|
|
134
134
|
}
|
|
135
135
|
if (currentConfigDigest) {
|
|
136
136
|
await this.#store.metaStore().set("config-digest", currentConfigDigest);
|
|
@@ -5,7 +5,6 @@ import { bold, cyan } from "kleur/colors";
|
|
|
5
5
|
import { normalizePath } from "vite";
|
|
6
6
|
import { z } from "zod";
|
|
7
7
|
import { zodToJsonSchema } from "zod-to-json-schema";
|
|
8
|
-
import { printNode, zodToTs } from "zod-to-ts";
|
|
9
8
|
import { AstroError } from "../core/errors/errors.js";
|
|
10
9
|
import { AstroErrorData } from "../core/errors/index.js";
|
|
11
10
|
import { isRelativePath } from "../core/path.js";
|
|
@@ -294,8 +293,16 @@ async function typeForCollection(collection, collectionKey) {
|
|
|
294
293
|
if (collection?.type === CONTENT_LAYER_TYPE) {
|
|
295
294
|
const schema = await getContentLayerSchema(collection, collectionKey);
|
|
296
295
|
if (schema) {
|
|
297
|
-
|
|
298
|
-
|
|
296
|
+
try {
|
|
297
|
+
const zodToTs = await import("zod-to-ts");
|
|
298
|
+
const ast = zodToTs.zodToTs(schema);
|
|
299
|
+
return zodToTs.printNode(ast.node);
|
|
300
|
+
} catch (err) {
|
|
301
|
+
if (err.message.includes("Cannot find package 'typescript'")) {
|
|
302
|
+
return "any";
|
|
303
|
+
}
|
|
304
|
+
throw err;
|
|
305
|
+
}
|
|
299
306
|
}
|
|
300
307
|
}
|
|
301
308
|
return "any";
|
package/dist/core/app/node.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import { Http2ServerResponse } from "node:http2";
|
|
3
|
+
import { clientAddressSymbol } from "../constants.js";
|
|
3
4
|
import { deserializeManifest } from "./common.js";
|
|
4
5
|
import { createOutgoingHttpHeaders } from "./createOutgoingHttpHeaders.js";
|
|
5
6
|
import { App } from "./index.js";
|
|
6
7
|
import { apply } from "../polyfill.js";
|
|
7
|
-
const clientAddressSymbol = Symbol.for("astro.clientAddress");
|
|
8
8
|
class NodeApp extends App {
|
|
9
9
|
match(req) {
|
|
10
10
|
if (!(req instanceof Request)) {
|
package/dist/core/constants.d.ts
CHANGED
|
@@ -57,6 +57,10 @@ export declare const clientAddressSymbol: unique symbol;
|
|
|
57
57
|
* Use judiciously, as locals are now stored within `RenderContext` by default. Tacking it onto request is no longer necessary.
|
|
58
58
|
*/
|
|
59
59
|
export declare const clientLocalsSymbol: unique symbol;
|
|
60
|
+
/**
|
|
61
|
+
* Use this symbol to set and retrieve the original pathname of a request. This is useful when working with redirects and rewrites
|
|
62
|
+
*/
|
|
63
|
+
export declare const originPathnameSymbol: unique symbol;
|
|
60
64
|
/**
|
|
61
65
|
* The symbol used as a field on the response object to keep track of streaming.
|
|
62
66
|
*
|
package/dist/core/constants.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const ASTRO_VERSION = "4.16.
|
|
1
|
+
const ASTRO_VERSION = "4.16.7";
|
|
2
2
|
const REROUTE_DIRECTIVE_HEADER = "X-Astro-Reroute";
|
|
3
3
|
const REWRITE_DIRECTIVE_HEADER_KEY = "X-Astro-Rewrite";
|
|
4
4
|
const REWRITE_DIRECTIVE_HEADER_VALUE = "yes";
|
|
@@ -9,6 +9,7 @@ const REDIRECT_STATUS_CODES = [301, 302, 303, 307, 308, 300, 304];
|
|
|
9
9
|
const REROUTABLE_STATUS_CODES = [404, 500];
|
|
10
10
|
const clientAddressSymbol = Symbol.for("astro.clientAddress");
|
|
11
11
|
const clientLocalsSymbol = Symbol.for("astro.locals");
|
|
12
|
+
const originPathnameSymbol = Symbol.for("astro.originPathname");
|
|
12
13
|
const responseSentSymbol = Symbol.for("astro.responseSent");
|
|
13
14
|
const SUPPORTED_MARKDOWN_FILE_EXTENSIONS = [
|
|
14
15
|
".markdown",
|
|
@@ -33,5 +34,6 @@ export {
|
|
|
33
34
|
SUPPORTED_MARKDOWN_FILE_EXTENSIONS,
|
|
34
35
|
clientAddressSymbol,
|
|
35
36
|
clientLocalsSymbol,
|
|
37
|
+
originPathnameSymbol,
|
|
36
38
|
responseSentSymbol
|
|
37
39
|
};
|
package/dist/core/dev/dev.js
CHANGED
|
@@ -22,7 +22,7 @@ async function dev(inlineConfig) {
|
|
|
22
22
|
await telemetry.record([]);
|
|
23
23
|
const restart = await createContainerWithAutomaticRestart({ inlineConfig, fs });
|
|
24
24
|
const logger = restart.container.logger;
|
|
25
|
-
const currentVersion = "4.16.
|
|
25
|
+
const currentVersion = "4.16.7";
|
|
26
26
|
const isPrerelease = currentVersion.includes("-");
|
|
27
27
|
if (!isPrerelease) {
|
|
28
28
|
try {
|
package/dist/core/messages.js
CHANGED
|
@@ -38,7 +38,7 @@ function serverStart({
|
|
|
38
38
|
host,
|
|
39
39
|
base
|
|
40
40
|
}) {
|
|
41
|
-
const version = "4.16.
|
|
41
|
+
const version = "4.16.7";
|
|
42
42
|
const localPrefix = `${dim("\u2503")} Local `;
|
|
43
43
|
const networkPrefix = `${dim("\u2503")} Network `;
|
|
44
44
|
const emptyPrefix = " ".repeat(11);
|
|
@@ -270,7 +270,7 @@ function printHelp({
|
|
|
270
270
|
message.push(
|
|
271
271
|
linebreak(),
|
|
272
272
|
` ${bgGreen(black(` ${commandName} `))} ${green(
|
|
273
|
-
`v${"4.16.
|
|
273
|
+
`v${"4.16.7"}`
|
|
274
274
|
)} ${headline}`
|
|
275
275
|
);
|
|
276
276
|
}
|
|
@@ -24,6 +24,7 @@ import { callMiddleware } from "./middleware/callMiddleware.js";
|
|
|
24
24
|
import { sequence } from "./middleware/index.js";
|
|
25
25
|
import { renderRedirect } from "./redirects/render.js";
|
|
26
26
|
import { Slots, getParams, getProps } from "./render/index.js";
|
|
27
|
+
import { copyRequest, setOriginPathname } from "./routing/rewrite.js";
|
|
27
28
|
const apiContextRoutesSymbol = Symbol.for("context.routes");
|
|
28
29
|
class RenderContext {
|
|
29
30
|
constructor(pipeline, locals, middleware, pathname, request, routeData, status, cookies = new AstroCookies(request), params = getParams(routeData, pathname), url = new URL(request.url), props = {}, partial = void 0) {
|
|
@@ -60,6 +61,7 @@ class RenderContext {
|
|
|
60
61
|
partial = void 0
|
|
61
62
|
}) {
|
|
62
63
|
const pipelineMiddleware = await pipeline.getMiddleware();
|
|
64
|
+
setOriginPathname(request, pathname);
|
|
63
65
|
return new RenderContext(
|
|
64
66
|
pipeline,
|
|
65
67
|
locals,
|
|
@@ -121,7 +123,7 @@ class RenderContext {
|
|
|
121
123
|
if (payload instanceof Request) {
|
|
122
124
|
this.request = payload;
|
|
123
125
|
} else {
|
|
124
|
-
this.request =
|
|
126
|
+
this.request = copyRequest(newUrl, this.request);
|
|
125
127
|
}
|
|
126
128
|
this.isRewriting = true;
|
|
127
129
|
this.url = new URL(this.request.url);
|
|
@@ -205,7 +207,7 @@ class RenderContext {
|
|
|
205
207
|
if (reroutePayload instanceof Request) {
|
|
206
208
|
this.request = reroutePayload;
|
|
207
209
|
} else {
|
|
208
|
-
this.request =
|
|
210
|
+
this.request = copyRequest(newUrl, this.request);
|
|
209
211
|
}
|
|
210
212
|
this.url = new URL(this.request.url);
|
|
211
213
|
this.cookies = new AstroCookies(this.request);
|
|
@@ -461,34 +463,6 @@ class RenderContext {
|
|
|
461
463
|
if (!i18n) return;
|
|
462
464
|
return this.#preferredLocaleList ??= computePreferredLocaleList(request, i18n.locales);
|
|
463
465
|
}
|
|
464
|
-
/**
|
|
465
|
-
* Utility function that creates a new `Request` with a new URL from an old `Request`.
|
|
466
|
-
*
|
|
467
|
-
* @param newUrl The new `URL`
|
|
468
|
-
* @param oldRequest The old `Request`
|
|
469
|
-
*/
|
|
470
|
-
#copyRequest(newUrl, oldRequest) {
|
|
471
|
-
if (oldRequest.bodyUsed) {
|
|
472
|
-
throw new AstroError(AstroErrorData.RewriteWithBodyUsed);
|
|
473
|
-
}
|
|
474
|
-
return new Request(newUrl, {
|
|
475
|
-
method: oldRequest.method,
|
|
476
|
-
headers: oldRequest.headers,
|
|
477
|
-
body: oldRequest.body,
|
|
478
|
-
referrer: oldRequest.referrer,
|
|
479
|
-
referrerPolicy: oldRequest.referrerPolicy,
|
|
480
|
-
mode: oldRequest.mode,
|
|
481
|
-
credentials: oldRequest.credentials,
|
|
482
|
-
cache: oldRequest.cache,
|
|
483
|
-
redirect: oldRequest.redirect,
|
|
484
|
-
integrity: oldRequest.integrity,
|
|
485
|
-
signal: oldRequest.signal,
|
|
486
|
-
keepalive: oldRequest.keepalive,
|
|
487
|
-
// https://fetch.spec.whatwg.org/#dom-request-duplex
|
|
488
|
-
// @ts-expect-error It isn't part of the types, but undici accepts it and it allows to carry over the body to a new request
|
|
489
|
-
duplex: "half"
|
|
490
|
-
});
|
|
491
|
-
}
|
|
492
466
|
}
|
|
493
467
|
export {
|
|
494
468
|
RenderContext,
|
|
@@ -18,3 +18,12 @@ export interface FindRouteToRewriteResult {
|
|
|
18
18
|
* 2.
|
|
19
19
|
*/
|
|
20
20
|
export declare function findRouteToRewrite({ payload, routes, request, trailingSlash, buildFormat, base, }: FindRouteToRewrite): FindRouteToRewriteResult;
|
|
21
|
+
/**
|
|
22
|
+
* Utility function that creates a new `Request` with a new URL from an old `Request`.
|
|
23
|
+
*
|
|
24
|
+
* @param newUrl The new `URL`
|
|
25
|
+
* @param oldRequest The old `Request`
|
|
26
|
+
*/
|
|
27
|
+
export declare function copyRequest(newUrl: URL, oldRequest: Request): Request;
|
|
28
|
+
export declare function setOriginPathname(request: Request, pathname: string): void;
|
|
29
|
+
export declare function getOriginPathname(request: Request): string | undefined;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { shouldAppendForwardSlash } from "../build/util.js";
|
|
2
|
+
import { originPathnameSymbol } from "../constants.js";
|
|
3
|
+
import { AstroError, AstroErrorData } from "../errors/index.js";
|
|
2
4
|
import { appendForwardSlash, removeTrailingForwardSlash } from "../path.js";
|
|
3
5
|
import { DEFAULT_404_ROUTE } from "./astro-designed-error-pages.js";
|
|
4
6
|
function findRouteToRewrite({
|
|
@@ -44,6 +46,41 @@ function findRouteToRewrite({
|
|
|
44
46
|
}
|
|
45
47
|
}
|
|
46
48
|
}
|
|
49
|
+
function copyRequest(newUrl, oldRequest) {
|
|
50
|
+
if (oldRequest.bodyUsed) {
|
|
51
|
+
throw new AstroError(AstroErrorData.RewriteWithBodyUsed);
|
|
52
|
+
}
|
|
53
|
+
return new Request(newUrl, {
|
|
54
|
+
method: oldRequest.method,
|
|
55
|
+
headers: oldRequest.headers,
|
|
56
|
+
body: oldRequest.body,
|
|
57
|
+
referrer: oldRequest.referrer,
|
|
58
|
+
referrerPolicy: oldRequest.referrerPolicy,
|
|
59
|
+
mode: oldRequest.mode,
|
|
60
|
+
credentials: oldRequest.credentials,
|
|
61
|
+
cache: oldRequest.cache,
|
|
62
|
+
redirect: oldRequest.redirect,
|
|
63
|
+
integrity: oldRequest.integrity,
|
|
64
|
+
signal: oldRequest.signal,
|
|
65
|
+
keepalive: oldRequest.keepalive,
|
|
66
|
+
// https://fetch.spec.whatwg.org/#dom-request-duplex
|
|
67
|
+
// @ts-expect-error It isn't part of the types, but undici accepts it and it allows to carry over the body to a new request
|
|
68
|
+
duplex: "half"
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
function setOriginPathname(request, pathname) {
|
|
72
|
+
Reflect.set(request, originPathnameSymbol, encodeURIComponent(pathname));
|
|
73
|
+
}
|
|
74
|
+
function getOriginPathname(request) {
|
|
75
|
+
const origin = Reflect.get(request, originPathnameSymbol);
|
|
76
|
+
if (origin) {
|
|
77
|
+
return decodeURIComponent(origin);
|
|
78
|
+
}
|
|
79
|
+
return void 0;
|
|
80
|
+
}
|
|
47
81
|
export {
|
|
48
|
-
|
|
82
|
+
copyRequest,
|
|
83
|
+
findRouteToRewrite,
|
|
84
|
+
getOriginPathname,
|
|
85
|
+
setOriginPathname
|
|
49
86
|
};
|
|
@@ -30,7 +30,7 @@ function ensureServerIslandRoute(config, routeManifest) {
|
|
|
30
30
|
if (routeManifest.routes.some((route) => route.route === "/_server-islands/[name]")) {
|
|
31
31
|
return;
|
|
32
32
|
}
|
|
33
|
-
routeManifest.routes.
|
|
33
|
+
routeManifest.routes.unshift(getServerIslandRouteData(config));
|
|
34
34
|
}
|
|
35
35
|
function createEndpoint(manifest) {
|
|
36
36
|
const page = async (result) => {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const headAndContentSym = Symbol.for("astro.headAndContent");
|
|
2
2
|
function isHeadAndContent(obj) {
|
|
3
|
-
return typeof obj === "object" && !!obj[headAndContentSym];
|
|
3
|
+
return typeof obj === "object" && obj !== null && !!obj[headAndContentSym];
|
|
4
4
|
}
|
|
5
5
|
function createHeadAndContent(head, content) {
|
|
6
6
|
return {
|
|
@@ -67,7 +67,7 @@ function createAstroComponentInstance(result, displayName, factory, props, slots
|
|
|
67
67
|
return instance;
|
|
68
68
|
}
|
|
69
69
|
function isAstroComponentInstance(obj) {
|
|
70
|
-
return typeof obj === "object" && !!obj[astroComponentInstanceSym];
|
|
70
|
+
return typeof obj === "object" && obj !== null && !!obj[astroComponentInstanceSym];
|
|
71
71
|
}
|
|
72
72
|
export {
|
|
73
73
|
AstroComponentInstance,
|
|
@@ -42,7 +42,7 @@ class RenderTemplateResult {
|
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
44
|
function isRenderTemplateResult(obj) {
|
|
45
|
-
return typeof obj === "object" && !!obj[renderTemplateResultSym];
|
|
45
|
+
return typeof obj === "object" && obj !== null && !!obj[renderTemplateResultSym];
|
|
46
46
|
}
|
|
47
47
|
function renderTemplate(htmlParts, ...expressions) {
|
|
48
48
|
return new RenderTemplateResult(htmlParts, expressions);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "astro",
|
|
3
|
-
"version": "4.16.
|
|
3
|
+
"version": "4.16.7",
|
|
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",
|
|
@@ -116,7 +116,7 @@
|
|
|
116
116
|
"@rollup/pluginutils": "^5.1.2",
|
|
117
117
|
"@types/babel__core": "^7.20.5",
|
|
118
118
|
"@types/cookie": "^0.6.0",
|
|
119
|
-
"acorn": "^8.
|
|
119
|
+
"acorn": "^8.13.0",
|
|
120
120
|
"aria-query": "^5.3.2",
|
|
121
121
|
"axobject-query": "^4.1.0",
|
|
122
122
|
"boxen": "8.0.1",
|
|
@@ -155,7 +155,7 @@
|
|
|
155
155
|
"rehype": "^13.0.2",
|
|
156
156
|
"semver": "^7.6.3",
|
|
157
157
|
"shiki": "^1.22.0",
|
|
158
|
-
"tinyexec": "^0.3.
|
|
158
|
+
"tinyexec": "^0.3.1",
|
|
159
159
|
"tsconfck": "^3.1.4",
|
|
160
160
|
"unist-util-visit": "^5.0.0",
|
|
161
161
|
"vfile": "^6.0.3",
|
|
@@ -167,8 +167,8 @@
|
|
|
167
167
|
"zod": "^3.23.8",
|
|
168
168
|
"zod-to-json-schema": "^3.23.3",
|
|
169
169
|
"zod-to-ts": "^1.2.0",
|
|
170
|
-
"@astrojs/markdown-remark": "5.3.0",
|
|
171
170
|
"@astrojs/internal-helpers": "0.4.1",
|
|
171
|
+
"@astrojs/markdown-remark": "5.3.0",
|
|
172
172
|
"@astrojs/telemetry": "3.1.0"
|
|
173
173
|
},
|
|
174
174
|
"optionalDependencies": {
|
|
@@ -176,7 +176,7 @@
|
|
|
176
176
|
},
|
|
177
177
|
"devDependencies": {
|
|
178
178
|
"@astrojs/check": "^0.9.4",
|
|
179
|
-
"@playwright/test": "^1.48.
|
|
179
|
+
"@playwright/test": "^1.48.1",
|
|
180
180
|
"@types/aria-query": "^5.0.4",
|
|
181
181
|
"@types/common-ancestor-path": "^1.0.2",
|
|
182
182
|
"@types/cssesc": "^3.0.2",
|
|
@@ -205,7 +205,7 @@
|
|
|
205
205
|
"rehype-toc": "^3.0.2",
|
|
206
206
|
"remark-code-titles": "^0.1.2",
|
|
207
207
|
"rollup": "^4.24.0",
|
|
208
|
-
"sass": "^1.
|
|
208
|
+
"sass": "^1.80.3",
|
|
209
209
|
"undici": "^6.20.1",
|
|
210
210
|
"unified": "^11.0.5",
|
|
211
211
|
"astro-scripts": "0.0.14"
|