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
|
@@ -15,6 +15,7 @@ import {
|
|
|
15
15
|
responseSentSymbol
|
|
16
16
|
} from "./constants.js";
|
|
17
17
|
import { AstroCookies, attachCookiesToResponse } from "./cookies/index.js";
|
|
18
|
+
import { getFromResponse } from "./cookies/response.js";
|
|
18
19
|
import { AstroError, AstroErrorData } from "./errors/index.js";
|
|
19
20
|
import { callMiddleware } from "./middleware/callMiddleware.js";
|
|
20
21
|
import { sequence } from "./middleware/index.js";
|
|
@@ -52,7 +53,8 @@ class RenderContext {
|
|
|
52
53
|
pipeline,
|
|
53
54
|
request,
|
|
54
55
|
routeData,
|
|
55
|
-
status = 200
|
|
56
|
+
status = 200,
|
|
57
|
+
props
|
|
56
58
|
}) {
|
|
57
59
|
return new RenderContext(
|
|
58
60
|
pipeline,
|
|
@@ -61,7 +63,11 @@ class RenderContext {
|
|
|
61
63
|
pathname,
|
|
62
64
|
request,
|
|
63
65
|
routeData,
|
|
64
|
-
status
|
|
66
|
+
status,
|
|
67
|
+
void 0,
|
|
68
|
+
void 0,
|
|
69
|
+
void 0,
|
|
70
|
+
props
|
|
65
71
|
);
|
|
66
72
|
}
|
|
67
73
|
/**
|
|
@@ -113,14 +119,16 @@ class RenderContext {
|
|
|
113
119
|
);
|
|
114
120
|
}
|
|
115
121
|
}
|
|
122
|
+
let response2;
|
|
116
123
|
switch (this.routeData.type) {
|
|
117
|
-
case "endpoint":
|
|
118
|
-
|
|
124
|
+
case "endpoint": {
|
|
125
|
+
response2 = await renderEndpoint(componentInstance, ctx, serverLike, logger);
|
|
126
|
+
break;
|
|
127
|
+
}
|
|
119
128
|
case "redirect":
|
|
120
129
|
return renderRedirect(this);
|
|
121
130
|
case "page": {
|
|
122
131
|
const result = await this.createResult(componentInstance);
|
|
123
|
-
let response2;
|
|
124
132
|
try {
|
|
125
133
|
response2 = await renderPage(
|
|
126
134
|
result,
|
|
@@ -138,12 +146,17 @@ class RenderContext {
|
|
|
138
146
|
if (this.routeData.route === "/404" || this.routeData.route === "/500" || this.isRewriting) {
|
|
139
147
|
response2.headers.set(REROUTE_DIRECTIVE_HEADER, "no");
|
|
140
148
|
}
|
|
141
|
-
|
|
149
|
+
break;
|
|
142
150
|
}
|
|
143
151
|
case "fallback": {
|
|
144
152
|
return new Response(null, { status: 500, headers: { [ROUTE_TYPE_HEADER]: "fallback" } });
|
|
145
153
|
}
|
|
146
154
|
}
|
|
155
|
+
const responseCookies = getFromResponse(response2);
|
|
156
|
+
if (responseCookies) {
|
|
157
|
+
cookies.merge(responseCookies);
|
|
158
|
+
}
|
|
159
|
+
return response2;
|
|
147
160
|
};
|
|
148
161
|
const response = await callMiddleware(
|
|
149
162
|
middleware,
|
|
@@ -436,6 +449,9 @@ class RenderContext {
|
|
|
436
449
|
* @param oldRequest The old `Request`
|
|
437
450
|
*/
|
|
438
451
|
#copyRequest(newUrl, oldRequest) {
|
|
452
|
+
if (oldRequest.bodyUsed) {
|
|
453
|
+
throw new AstroError(AstroErrorData.RewriteWithBodyUsed);
|
|
454
|
+
}
|
|
439
455
|
return new Request(newUrl, {
|
|
440
456
|
method: oldRequest.method,
|
|
441
457
|
headers: oldRequest.headers,
|
package/dist/core/request.js
CHANGED
|
@@ -12,7 +12,13 @@ function createRequest({
|
|
|
12
12
|
locals,
|
|
13
13
|
staticLike = false
|
|
14
14
|
}) {
|
|
15
|
-
const headersObj = staticLike ? void 0 : headers instanceof Headers ? headers : new Headers(
|
|
15
|
+
const headersObj = staticLike ? void 0 : headers instanceof Headers ? headers : new Headers(
|
|
16
|
+
// Filter out HTTP/2 pseudo-headers. These are internally-generated headers added to all HTTP/2 requests with trusted metadata about the request.
|
|
17
|
+
// Examples include `:method`, `:scheme`, `:authority`, and `:path`.
|
|
18
|
+
// They are always prefixed with a colon to distinguish them from other headers, and it is an error to add the to a Headers object manually.
|
|
19
|
+
// See https://httpwg.org/specs/rfc7540.html#HttpRequest
|
|
20
|
+
Object.entries(headers).filter(([name]) => !name.startsWith(":"))
|
|
21
|
+
);
|
|
16
22
|
if (typeof url === "string") url = new URL(url);
|
|
17
23
|
const imageEndpoint = prependForwardSlash(appendForwardSlash(base)) + "_image";
|
|
18
24
|
if (staticLike && url.pathname !== imageEndpoint) {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { ManifestData, RouteData } from '../../@types/astro.js';
|
|
2
2
|
export declare const DEFAULT_404_ROUTE: RouteData;
|
|
3
|
+
export declare const DEFAULT_500_ROUTE: RouteData;
|
|
3
4
|
export declare function ensure404Route(manifest: ManifestData): ManifestData;
|
|
4
5
|
export declare function default404Page({ pathname }: {
|
|
5
6
|
pathname: string;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import notFoundTemplate from "../../template/4xx.js";
|
|
2
|
-
import { DEFAULT_404_COMPONENT } from "../constants.js";
|
|
2
|
+
import { DEFAULT_404_COMPONENT, DEFAULT_500_COMPONENT } from "../constants.js";
|
|
3
3
|
const DEFAULT_404_ROUTE = {
|
|
4
4
|
component: DEFAULT_404_COMPONENT,
|
|
5
5
|
generate: () => "",
|
|
@@ -13,6 +13,19 @@ const DEFAULT_404_ROUTE = {
|
|
|
13
13
|
fallbackRoutes: [],
|
|
14
14
|
isIndex: false
|
|
15
15
|
};
|
|
16
|
+
const DEFAULT_500_ROUTE = {
|
|
17
|
+
component: DEFAULT_500_COMPONENT,
|
|
18
|
+
generate: () => "",
|
|
19
|
+
params: [],
|
|
20
|
+
pattern: /\/500/,
|
|
21
|
+
prerender: false,
|
|
22
|
+
pathname: "/500",
|
|
23
|
+
segments: [[{ content: "500", dynamic: false, spread: false }]],
|
|
24
|
+
type: "page",
|
|
25
|
+
route: "/500",
|
|
26
|
+
fallbackRoutes: [],
|
|
27
|
+
isIndex: false
|
|
28
|
+
};
|
|
16
29
|
function ensure404Route(manifest) {
|
|
17
30
|
if (!manifest.routes.some((route) => route.route === "/404")) {
|
|
18
31
|
manifest.routes.push(DEFAULT_404_ROUTE);
|
|
@@ -33,6 +46,7 @@ async function default404Page({ pathname }) {
|
|
|
33
46
|
default404Page.isAstroComponentFactory = true;
|
|
34
47
|
export {
|
|
35
48
|
DEFAULT_404_ROUTE,
|
|
49
|
+
DEFAULT_500_ROUTE,
|
|
36
50
|
default404Page,
|
|
37
51
|
ensure404Route
|
|
38
52
|
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { AstroConfig, RewritePayload, RouteData } from '../../@types/astro.js';
|
|
2
|
+
export type FindRouteToRewrite = {
|
|
3
|
+
payload: RewritePayload;
|
|
4
|
+
routes: RouteData[];
|
|
5
|
+
request: Request;
|
|
6
|
+
trailingSlash: AstroConfig['trailingSlash'];
|
|
7
|
+
buildFormat: AstroConfig['build']['format'];
|
|
8
|
+
base: AstroConfig['base'];
|
|
9
|
+
};
|
|
10
|
+
export declare function findRouteToRewrite({ payload, routes, request, trailingSlash, buildFormat, base, }: FindRouteToRewrite): [RouteData, URL];
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { shouldAppendForwardSlash } from "../build/util.js";
|
|
2
|
+
import { appendForwardSlash, removeTrailingForwardSlash } from "../path.js";
|
|
3
|
+
import { DEFAULT_404_ROUTE } from "./astro-designed-error-pages.js";
|
|
4
|
+
function findRouteToRewrite({
|
|
5
|
+
payload,
|
|
6
|
+
routes,
|
|
7
|
+
request,
|
|
8
|
+
trailingSlash,
|
|
9
|
+
buildFormat,
|
|
10
|
+
base
|
|
11
|
+
}) {
|
|
12
|
+
let finalUrl = void 0;
|
|
13
|
+
if (payload instanceof URL) {
|
|
14
|
+
finalUrl = payload;
|
|
15
|
+
} else if (payload instanceof Request) {
|
|
16
|
+
finalUrl = new URL(payload.url);
|
|
17
|
+
} else {
|
|
18
|
+
finalUrl = new URL(payload, new URL(request.url).origin);
|
|
19
|
+
}
|
|
20
|
+
let foundRoute;
|
|
21
|
+
for (const route of routes) {
|
|
22
|
+
const pathname = shouldAppendForwardSlash(trailingSlash, buildFormat) ? appendForwardSlash(finalUrl.pathname) : base !== "/" ? removeTrailingForwardSlash(finalUrl.pathname) : finalUrl.pathname;
|
|
23
|
+
if (route.pattern.test(decodeURI(pathname))) {
|
|
24
|
+
foundRoute = route;
|
|
25
|
+
break;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
if (foundRoute) {
|
|
29
|
+
return [foundRoute, finalUrl];
|
|
30
|
+
} else {
|
|
31
|
+
const custom404 = routes.find((route) => route.route === "/404");
|
|
32
|
+
if (custom404) {
|
|
33
|
+
return [custom404, finalUrl];
|
|
34
|
+
} else {
|
|
35
|
+
return [DEFAULT_404_ROUTE, finalUrl];
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
export {
|
|
40
|
+
findRouteToRewrite
|
|
41
|
+
};
|
package/dist/core/util.js
CHANGED
|
@@ -78,8 +78,11 @@ function isInjectedRoute(file, settings) {
|
|
|
78
78
|
return false;
|
|
79
79
|
}
|
|
80
80
|
function isPublicRoute(file, config) {
|
|
81
|
-
const
|
|
82
|
-
const
|
|
81
|
+
const rootDir = config.root.toString();
|
|
82
|
+
const pagesDir = resolvePages(config).toString();
|
|
83
|
+
const fileDir = file.toString();
|
|
84
|
+
const normalizedDir = fileDir.startsWith(pagesDir) ? fileDir.slice(pagesDir.length) : fileDir.slice(rootDir.length);
|
|
85
|
+
const parts = normalizedDir.replace(pagesDir.toString(), "").split("/").slice(1);
|
|
83
86
|
for (const part of parts) {
|
|
84
87
|
if (part.startsWith("_")) return false;
|
|
85
88
|
}
|
package/dist/env/constants.d.ts
CHANGED
|
@@ -4,7 +4,6 @@ export declare const VIRTUAL_MODULES_IDS: {
|
|
|
4
4
|
internal: string;
|
|
5
5
|
};
|
|
6
6
|
export declare const VIRTUAL_MODULES_IDS_VALUES: Set<string>;
|
|
7
|
-
export declare const PUBLIC_PREFIX = "PUBLIC_";
|
|
8
7
|
export declare const ENV_TYPES_FILE = "env.d.ts";
|
|
9
8
|
export declare const MODULE_TEMPLATE_URL: URL;
|
|
10
9
|
export declare const TYPES_TEMPLATE_URL: URL;
|
package/dist/env/constants.js
CHANGED
|
@@ -4,7 +4,6 @@ const VIRTUAL_MODULES_IDS = {
|
|
|
4
4
|
internal: "virtual:astro:env/internal"
|
|
5
5
|
};
|
|
6
6
|
const VIRTUAL_MODULES_IDS_VALUES = new Set(Object.values(VIRTUAL_MODULES_IDS));
|
|
7
|
-
const PUBLIC_PREFIX = "PUBLIC_";
|
|
8
7
|
const ENV_TYPES_FILE = "env.d.ts";
|
|
9
8
|
const PKG_BASE = new URL("../../", import.meta.url);
|
|
10
9
|
const MODULE_TEMPLATE_URL = new URL("templates/env/module.mjs", PKG_BASE);
|
|
@@ -12,7 +11,6 @@ const TYPES_TEMPLATE_URL = new URL("templates/env/types.d.ts", PKG_BASE);
|
|
|
12
11
|
export {
|
|
13
12
|
ENV_TYPES_FILE,
|
|
14
13
|
MODULE_TEMPLATE_URL,
|
|
15
|
-
PUBLIC_PREFIX,
|
|
16
14
|
TYPES_TEMPLATE_URL,
|
|
17
15
|
VIRTUAL_MODULES_IDS,
|
|
18
16
|
VIRTUAL_MODULES_IDS_VALUES
|
package/dist/env/runtime.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { AstroError, AstroErrorData } from '../core/errors/index.js';
|
|
2
2
|
export { validateEnvVariable } from './validators.js';
|
|
3
3
|
export type GetEnv = (key: string) => string | undefined;
|
|
4
|
-
export declare function setGetEnv(fn: GetEnv): void;
|
|
4
|
+
export declare function setGetEnv(fn: GetEnv, reset?: boolean): void;
|
|
5
|
+
declare let _onSetGetEnv: (reset: boolean) => void;
|
|
6
|
+
export declare function setOnSetGetEnv(fn: typeof _onSetGetEnv): void;
|
|
5
7
|
export declare function getEnv(...args: Parameters<GetEnv>): string | undefined;
|
|
6
8
|
export declare function createInvalidVariableError(...args: Parameters<typeof AstroErrorData.EnvInvalidVariable.message>): AstroError;
|
package/dist/env/runtime.js
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
import { AstroError, AstroErrorData } from "../core/errors/index.js";
|
|
2
2
|
import { validateEnvVariable } from "./validators.js";
|
|
3
3
|
let _getEnv = (key) => process.env[key];
|
|
4
|
-
function setGetEnv(fn) {
|
|
4
|
+
function setGetEnv(fn, reset = false) {
|
|
5
5
|
_getEnv = fn;
|
|
6
|
+
_onSetGetEnv(reset);
|
|
7
|
+
}
|
|
8
|
+
let _onSetGetEnv = (reset) => {
|
|
9
|
+
};
|
|
10
|
+
function setOnSetGetEnv(fn) {
|
|
11
|
+
_onSetGetEnv = fn;
|
|
6
12
|
}
|
|
7
13
|
function getEnv(...args) {
|
|
8
14
|
return _getEnv(...args);
|
|
@@ -17,5 +23,6 @@ export {
|
|
|
17
23
|
createInvalidVariableError,
|
|
18
24
|
getEnv,
|
|
19
25
|
setGetEnv,
|
|
26
|
+
setOnSetGetEnv,
|
|
20
27
|
validateEnvVariable
|
|
21
28
|
};
|
package/dist/env/schema.d.ts
CHANGED
|
@@ -220,7 +220,7 @@ declare const EnvFieldMetadata: z.ZodUnion<[z.ZodObject<{
|
|
|
220
220
|
context: "server";
|
|
221
221
|
access: "secret";
|
|
222
222
|
}>]>;
|
|
223
|
-
export declare const EnvSchema: z.
|
|
223
|
+
export declare const EnvSchema: z.ZodRecord<z.ZodString, z.ZodIntersection<z.ZodUnion<[z.ZodObject<{
|
|
224
224
|
context: z.ZodLiteral<"client">;
|
|
225
225
|
access: z.ZodLiteral<"public">;
|
|
226
226
|
}, "strip", z.ZodTypeAny, {
|
|
@@ -344,83 +344,7 @@ export declare const EnvSchema: z.ZodEffects<z.ZodRecord<z.ZodString, z.ZodInter
|
|
|
344
344
|
values: string[];
|
|
345
345
|
default?: string | undefined;
|
|
346
346
|
optional?: boolean | undefined;
|
|
347
|
-
}>]
|
|
348
|
-
context: "client";
|
|
349
|
-
access: "public";
|
|
350
|
-
} | {
|
|
351
|
-
context: "server";
|
|
352
|
-
access: "public";
|
|
353
|
-
} | {
|
|
354
|
-
context: "server";
|
|
355
|
-
access: "secret";
|
|
356
|
-
}) & ({
|
|
357
|
-
type: "string";
|
|
358
|
-
length?: number | undefined;
|
|
359
|
-
includes?: string | undefined;
|
|
360
|
-
endsWith?: string | undefined;
|
|
361
|
-
startsWith?: string | undefined;
|
|
362
|
-
default?: string | undefined;
|
|
363
|
-
url?: boolean | undefined;
|
|
364
|
-
optional?: boolean | undefined;
|
|
365
|
-
min?: number | undefined;
|
|
366
|
-
max?: number | undefined;
|
|
367
|
-
} | {
|
|
368
|
-
type: "number";
|
|
369
|
-
default?: number | undefined;
|
|
370
|
-
optional?: boolean | undefined;
|
|
371
|
-
min?: number | undefined;
|
|
372
|
-
max?: number | undefined;
|
|
373
|
-
gt?: number | undefined;
|
|
374
|
-
lt?: number | undefined;
|
|
375
|
-
int?: boolean | undefined;
|
|
376
|
-
} | {
|
|
377
|
-
type: "boolean";
|
|
378
|
-
default?: boolean | undefined;
|
|
379
|
-
optional?: boolean | undefined;
|
|
380
|
-
} | {
|
|
381
|
-
type: "enum";
|
|
382
|
-
values: string[];
|
|
383
|
-
default?: string | undefined;
|
|
384
|
-
optional?: boolean | undefined;
|
|
385
|
-
})>, Record<string, ({
|
|
386
|
-
context: "client";
|
|
387
|
-
access: "public";
|
|
388
|
-
} | {
|
|
389
|
-
context: "server";
|
|
390
|
-
access: "public";
|
|
391
|
-
} | {
|
|
392
|
-
context: "server";
|
|
393
|
-
access: "secret";
|
|
394
|
-
}) & ({
|
|
395
|
-
type: "string";
|
|
396
|
-
length?: number | undefined;
|
|
397
|
-
includes?: string | undefined;
|
|
398
|
-
endsWith?: string | undefined;
|
|
399
|
-
startsWith?: string | undefined;
|
|
400
|
-
default?: string | undefined;
|
|
401
|
-
url?: boolean | undefined;
|
|
402
|
-
optional?: boolean | undefined;
|
|
403
|
-
min?: number | undefined;
|
|
404
|
-
max?: number | undefined;
|
|
405
|
-
} | {
|
|
406
|
-
type: "number";
|
|
407
|
-
default?: number | undefined;
|
|
408
|
-
optional?: boolean | undefined;
|
|
409
|
-
min?: number | undefined;
|
|
410
|
-
max?: number | undefined;
|
|
411
|
-
gt?: number | undefined;
|
|
412
|
-
lt?: number | undefined;
|
|
413
|
-
int?: boolean | undefined;
|
|
414
|
-
} | {
|
|
415
|
-
type: "boolean";
|
|
416
|
-
default?: boolean | undefined;
|
|
417
|
-
optional?: boolean | undefined;
|
|
418
|
-
} | {
|
|
419
|
-
type: "enum";
|
|
420
|
-
values: string[];
|
|
421
|
-
default?: string | undefined;
|
|
422
|
-
optional?: boolean | undefined;
|
|
423
|
-
})>>;
|
|
347
|
+
}>]>>>;
|
|
424
348
|
type Prettify<T> = {
|
|
425
349
|
[K in keyof T]: T[K];
|
|
426
350
|
} & {};
|
package/dist/env/schema.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
import { PUBLIC_PREFIX } from "./constants.js";
|
|
3
2
|
const StringSchema = z.object({
|
|
4
3
|
type: z.literal("string"),
|
|
5
4
|
optional: z.boolean().optional(),
|
|
@@ -76,22 +75,7 @@ const EnvSchema = z.record(
|
|
|
76
75
|
message: "A valid variable name can only contain uppercase letters and underscores."
|
|
77
76
|
}),
|
|
78
77
|
z.intersection(EnvFieldMetadata, EnvFieldType)
|
|
79
|
-
)
|
|
80
|
-
for (const [key, value] of Object.entries(schema)) {
|
|
81
|
-
if (key.startsWith(PUBLIC_PREFIX) && value.access !== "public") {
|
|
82
|
-
ctx.addIssue({
|
|
83
|
-
code: z.ZodIssueCode.custom,
|
|
84
|
-
message: `An environment variable whose name is prefixed by "${PUBLIC_PREFIX}" must be public.`
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
if (value.access === "public" && !key.startsWith(PUBLIC_PREFIX)) {
|
|
88
|
-
ctx.addIssue({
|
|
89
|
-
code: z.ZodIssueCode.custom,
|
|
90
|
-
message: `An environment variable that is public must have a name prefixed by "${PUBLIC_PREFIX}".`
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
});
|
|
78
|
+
);
|
|
95
79
|
export {
|
|
96
80
|
EnvSchema
|
|
97
81
|
};
|
|
@@ -46,9 +46,8 @@ function astroEnv({
|
|
|
46
46
|
fs,
|
|
47
47
|
content: getDts({
|
|
48
48
|
fs,
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
serverSecret: serverTemplates.types.secret
|
|
49
|
+
client: clientTemplates.types,
|
|
50
|
+
server: serverTemplates.types
|
|
52
51
|
})
|
|
53
52
|
});
|
|
54
53
|
},
|
|
@@ -119,13 +118,12 @@ function validatePublicVariables({
|
|
|
119
118
|
return valid;
|
|
120
119
|
}
|
|
121
120
|
function getDts({
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
serverSecret,
|
|
121
|
+
client,
|
|
122
|
+
server,
|
|
125
123
|
fs
|
|
126
124
|
}) {
|
|
127
125
|
const template = fs.readFileSync(TYPES_TEMPLATE_URL, "utf-8");
|
|
128
|
-
return template.replace("// @@CLIENT@@",
|
|
126
|
+
return template.replace("// @@CLIENT@@", client).replace("// @@SERVER@@", server);
|
|
129
127
|
}
|
|
130
128
|
function getClientTemplates({
|
|
131
129
|
validatedVariables
|
|
@@ -148,26 +146,28 @@ function getServerTemplates({
|
|
|
148
146
|
fs
|
|
149
147
|
}) {
|
|
150
148
|
let module = fs.readFileSync(MODULE_TEMPLATE_URL, "utf-8");
|
|
151
|
-
let
|
|
152
|
-
let
|
|
149
|
+
let types = "";
|
|
150
|
+
let onSetGetEnv = "";
|
|
153
151
|
for (const { key, type, value } of validatedVariables.filter((e) => e.context === "server")) {
|
|
154
152
|
module += `export const ${key} = ${JSON.stringify(value)};`;
|
|
155
|
-
|
|
153
|
+
types += `export const ${key}: ${type};
|
|
156
154
|
`;
|
|
157
155
|
}
|
|
158
156
|
for (const [key, options] of Object.entries(schema)) {
|
|
159
157
|
if (!(options.context === "server" && options.access === "secret")) {
|
|
160
158
|
continue;
|
|
161
159
|
}
|
|
162
|
-
|
|
160
|
+
types += `export const ${key}: ${getEnvFieldType(options)};
|
|
161
|
+
`;
|
|
162
|
+
module += `export let ${key} = _internalGetSecret(${JSON.stringify(key)});
|
|
163
|
+
`;
|
|
164
|
+
onSetGetEnv += `${key} = reset ? undefined : _internalGetSecret(${JSON.stringify(key)});
|
|
163
165
|
`;
|
|
164
166
|
}
|
|
167
|
+
module = module.replace("// @@ON_SET_GET_ENV@@", onSetGetEnv);
|
|
165
168
|
return {
|
|
166
169
|
module,
|
|
167
|
-
types
|
|
168
|
-
public: publicTypes,
|
|
169
|
-
secret: secretTypes
|
|
170
|
-
}
|
|
170
|
+
types
|
|
171
171
|
};
|
|
172
172
|
}
|
|
173
173
|
export {
|
package/dist/jsx/server.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { NamedSSRLoadedRendererValue } from '../@types/astro.js';
|
|
1
2
|
export declare function check(Component: any, props: any, { default: children, ...slotted }?: {
|
|
2
3
|
default?: null | undefined;
|
|
3
4
|
}): Promise<any>;
|
|
@@ -6,8 +7,5 @@ export declare function renderToStaticMarkup(this: any, Component: any, props?:
|
|
|
6
7
|
}): Promise<{
|
|
7
8
|
html: any;
|
|
8
9
|
}>;
|
|
9
|
-
declare const
|
|
10
|
-
|
|
11
|
-
renderToStaticMarkup: typeof renderToStaticMarkup;
|
|
12
|
-
};
|
|
13
|
-
export default _default;
|
|
10
|
+
declare const renderer: NamedSSRLoadedRendererValue;
|
|
11
|
+
export default renderer;
|
package/dist/jsx/server.js
CHANGED
|
@@ -44,10 +44,12 @@ function throwEnhancedErrorIfMdxComponent(error, Component) {
|
|
|
44
44
|
});
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
|
-
|
|
47
|
+
const renderer = {
|
|
48
|
+
name: "astro:jsx",
|
|
48
49
|
check,
|
|
49
50
|
renderToStaticMarkup
|
|
50
51
|
};
|
|
52
|
+
var server_default = renderer;
|
|
51
53
|
export {
|
|
52
54
|
check,
|
|
53
55
|
server_default as default,
|
|
@@ -148,7 +148,7 @@ File: ${id}`
|
|
|
148
148
|
},
|
|
149
149
|
async transform(source, id) {
|
|
150
150
|
const parsedId = parseAstroRequest(id);
|
|
151
|
-
if (!
|
|
151
|
+
if (!parsedId.filename.endsWith(".astro") || parsedId.query.astro) {
|
|
152
152
|
return;
|
|
153
153
|
}
|
|
154
154
|
const filename = normalizePath(parsedId.filename);
|
|
@@ -19,7 +19,6 @@ export declare class DevPipeline extends Pipeline {
|
|
|
19
19
|
preload(routeData: RouteData, filePath: URL): Promise<ComponentInstance>;
|
|
20
20
|
clearRouteCache(): void;
|
|
21
21
|
getComponentByRoute(routeData: RouteData): Promise<ComponentInstance>;
|
|
22
|
-
tryRewrite(payload: RewritePayload, request: Request,
|
|
22
|
+
tryRewrite(payload: RewritePayload, request: Request, _sourceRoute: RouteData): Promise<[RouteData, ComponentInstance, URL]>;
|
|
23
23
|
setManifestData(manifestData: ManifestData): void;
|
|
24
|
-
rewriteKnownRoute(route: string, sourceRoute: RouteData): ComponentInstance;
|
|
25
24
|
}
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import { fileURLToPath } from "node:url";
|
|
2
2
|
import { getInfoOutput } from "../cli/info/index.js";
|
|
3
3
|
import {} from "../core/base-pipeline.js";
|
|
4
|
+
import { shouldAppendForwardSlash } from "../core/build/util.js";
|
|
4
5
|
import { ASTRO_VERSION, DEFAULT_404_COMPONENT } from "../core/constants.js";
|
|
5
6
|
import { enhanceViteSSRError } from "../core/errors/dev/index.js";
|
|
6
|
-
import {
|
|
7
|
+
import { RewriteEncounteredAnError } from "../core/errors/errors-data.js";
|
|
7
8
|
import { AggregateError, AstroError, CSSError, MarkdownError } from "../core/errors/index.js";
|
|
9
|
+
import { prependForwardSlash, removeTrailingForwardSlash } from "../core/path.js";
|
|
8
10
|
import { Pipeline, loadRenderer } from "../core/render/index.js";
|
|
9
11
|
import { DEFAULT_404_ROUTE, default404Page } from "../core/routing/astro-designed-error-pages.js";
|
|
12
|
+
import { findRouteToRewrite } from "../core/routing/rewrite.js";
|
|
10
13
|
import { isPage, isServerLikeOutput, resolveIdToUrl, viteID } from "../core/util.js";
|
|
11
14
|
import { PAGE_SCRIPT_ID } from "../vite-plugin-scripts/index.js";
|
|
12
15
|
import { getStylesForURL } from "./css.js";
|
|
@@ -133,54 +136,24 @@ class DevPipeline extends Pipeline {
|
|
|
133
136
|
return await this.preload(routeData, filePath);
|
|
134
137
|
}
|
|
135
138
|
}
|
|
136
|
-
async tryRewrite(payload, request,
|
|
137
|
-
let foundRoute;
|
|
139
|
+
async tryRewrite(payload, request, _sourceRoute) {
|
|
138
140
|
if (!this.manifestData) {
|
|
139
141
|
throw new Error("Missing manifest data. This is an internal error, please file an issue.");
|
|
140
142
|
}
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
foundRoute = route;
|
|
152
|
-
break;
|
|
153
|
-
} else if (finalUrl.pathname === "/404") {
|
|
154
|
-
foundRoute = DEFAULT_404_ROUTE;
|
|
155
|
-
break;
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
if (foundRoute && finalUrl) {
|
|
159
|
-
if (foundRoute.pathname === "/404") {
|
|
160
|
-
const componentInstance = this.rewriteKnownRoute(foundRoute.pathname, sourceRoute);
|
|
161
|
-
return [foundRoute, componentInstance, finalUrl];
|
|
162
|
-
} else {
|
|
163
|
-
const componentInstance = await this.getComponentByRoute(foundRoute);
|
|
164
|
-
return [foundRoute, componentInstance, finalUrl];
|
|
165
|
-
}
|
|
166
|
-
} else {
|
|
167
|
-
throw new AstroError({
|
|
168
|
-
...RewriteEncounteredAnError,
|
|
169
|
-
message: RewriteEncounteredAnError.message(payload.toString())
|
|
170
|
-
});
|
|
171
|
-
}
|
|
143
|
+
const [foundRoute, finalUrl] = findRouteToRewrite({
|
|
144
|
+
payload,
|
|
145
|
+
request,
|
|
146
|
+
routes: this.manifestData?.routes,
|
|
147
|
+
trailingSlash: this.config.trailingSlash,
|
|
148
|
+
buildFormat: this.config.build.format,
|
|
149
|
+
base: this.config.base
|
|
150
|
+
});
|
|
151
|
+
const componentInstance = await this.getComponentByRoute(foundRoute);
|
|
152
|
+
return [foundRoute, componentInstance, finalUrl];
|
|
172
153
|
}
|
|
173
154
|
setManifestData(manifestData) {
|
|
174
155
|
this.manifestData = manifestData;
|
|
175
156
|
}
|
|
176
|
-
rewriteKnownRoute(route, sourceRoute) {
|
|
177
|
-
if (isServerLikeOutput(this.config) && sourceRoute.prerender) {
|
|
178
|
-
if (route === "/404") {
|
|
179
|
-
return { default: default404Page };
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
throw new AstroError(InvalidRewrite404);
|
|
183
|
-
}
|
|
184
157
|
}
|
|
185
158
|
export {
|
|
186
159
|
DevPipeline
|
|
@@ -11,7 +11,7 @@ async function handleRequest({
|
|
|
11
11
|
incomingResponse
|
|
12
12
|
}) {
|
|
13
13
|
const { config, loader } = pipeline;
|
|
14
|
-
const origin = `${loader.isHttps() ? "https" : "http"}://${incomingRequest.headers.host}`;
|
|
14
|
+
const origin = `${loader.isHttps() ? "https" : "http"}://${incomingRequest.headers[":authority"] ?? incomingRequest.headers.host}`;
|
|
15
15
|
const url = new URL(origin + incomingRequest.url);
|
|
16
16
|
let pathname;
|
|
17
17
|
if (config.trailingSlash === "never" && !incomingRequest.url) {
|