astro 4.4.0 → 4.4.1
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/@types/astro.d.ts +42 -42
- package/dist/assets/build/generate.d.ts +1 -1
- package/dist/assets/build/generate.js +1 -2
- package/dist/cli/add/babel.d.ts +1 -1
- package/dist/cli/add/index.js +1 -1
- package/dist/cli/db/index.js +2 -0
- package/dist/cli/info/index.js +2 -0
- package/dist/cli/preferences/index.js +2 -0
- package/dist/content/types-generator.js +4 -4
- package/dist/core/app/index.js +39 -122
- package/dist/core/app/pipeline.d.ts +7 -0
- package/dist/core/app/pipeline.js +39 -0
- package/dist/core/base-pipeline.d.ts +59 -0
- package/dist/core/base-pipeline.js +27 -0
- package/dist/core/build/generate.d.ts +1 -1
- package/dist/core/build/generate.js +39 -109
- package/dist/core/build/index.js +0 -4
- package/dist/core/build/{buildPipeline.d.ts → pipeline.d.ts} +13 -13
- package/dist/core/build/pipeline.js +180 -0
- package/dist/core/build/types.d.ts +0 -2
- package/dist/core/constants.d.ts +10 -1
- package/dist/core/constants.js +14 -4
- package/dist/core/dev/dev.js +1 -1
- package/dist/core/dev/restart.js +1 -1
- package/dist/core/endpoint/index.d.ts +5 -4
- package/dist/core/endpoint/index.js +7 -34
- package/dist/core/errors/errors-data.d.ts +2 -2
- package/dist/core/messages.js +2 -2
- package/dist/core/middleware/callMiddleware.d.ts +1 -1
- package/dist/core/middleware/callMiddleware.js +2 -9
- package/dist/core/middleware/index.d.ts +2 -2
- package/dist/core/middleware/index.js +74 -9
- package/dist/core/module-loader/vite.js +4 -4
- package/dist/core/preview/index.js +2 -0
- package/dist/core/preview/static-preview-server.js +1 -7
- package/dist/core/redirects/helpers.d.ts +1 -3
- package/dist/core/redirects/helpers.js +0 -29
- package/dist/core/redirects/index.d.ts +2 -1
- package/dist/core/redirects/index.js +3 -3
- package/dist/core/redirects/render.d.ts +2 -0
- package/dist/core/redirects/render.js +33 -0
- package/dist/core/render/index.d.ts +7 -13
- package/dist/core/render/index.js +7 -7
- package/dist/core/render/params-and-props.d.ts +8 -3
- package/dist/core/render/params-and-props.js +24 -16
- package/dist/core/render/result.d.ts +6 -5
- package/dist/core/render/result.js +3 -4
- package/dist/core/render-context.d.ts +32 -0
- package/dist/core/render-context.js +219 -0
- package/dist/core/routing/index.d.ts +0 -1
- package/dist/core/routing/index.js +0 -2
- package/dist/core/routing/params.d.ts +1 -7
- package/dist/core/routing/params.js +0 -15
- package/dist/core/sync/index.js +3 -3
- package/dist/i18n/middleware.d.ts +0 -5
- package/dist/i18n/middleware.js +61 -69
- package/dist/i18n/utils.d.ts +25 -0
- package/dist/{core/render/context.js → i18n/utils.js} +3 -49
- package/dist/prerender/routing.d.ts +1 -1
- package/dist/prerender/routing.js +2 -3
- package/dist/runtime/client/dev-toolbar/apps/astro.js +13 -9
- package/dist/runtime/client/dev-toolbar/apps/audit/a11y.js +2 -2
- package/dist/runtime/server/endpoint.js +2 -2
- package/dist/vite-plugin-astro/hmr.d.ts +1 -0
- package/dist/vite-plugin-astro/hmr.js +7 -4
- package/dist/vite-plugin-astro-server/error.d.ts +2 -2
- package/dist/vite-plugin-astro-server/error.js +2 -5
- package/dist/vite-plugin-astro-server/index.d.ts +0 -6
- package/dist/vite-plugin-astro-server/index.js +0 -19
- package/dist/vite-plugin-astro-server/pipeline.d.ts +19 -0
- package/dist/vite-plugin-astro-server/pipeline.js +117 -0
- package/dist/vite-plugin-astro-server/plugin.js +3 -4
- package/dist/vite-plugin-astro-server/request.d.ts +3 -4
- package/dist/vite-plugin-astro-server/request.js +6 -9
- package/dist/vite-plugin-astro-server/route.d.ts +3 -4
- package/dist/vite-plugin-astro-server/route.js +34 -162
- package/dist/vite-plugin-dev-toolbar/vite-plugin-dev-toolbar.js +3 -3
- package/package.json +3 -8
- package/dist/core/app/ssrPipeline.d.ts +0 -3
- package/dist/core/app/ssrPipeline.js +0 -6
- package/dist/core/build/buildPipeline.js +0 -150
- package/dist/core/pipeline.d.ts +0 -39
- package/dist/core/pipeline.js +0 -107
- package/dist/core/render/context.d.ts +0 -52
- package/dist/core/render/core.d.ts +0 -10
- package/dist/core/render/core.js +0 -65
- package/dist/core/render/environment.d.ts +0 -34
- package/dist/core/render/environment.js +0 -6
- package/dist/runtime/server/consts.d.ts +0 -1
- package/dist/runtime/server/consts.js +0 -4
- package/dist/vite-plugin-astro-server/devPipeline.d.ts +0 -22
- package/dist/vite-plugin-astro-server/devPipeline.js +0 -65
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import { renderEndpoint } from "../runtime/server/endpoint.js";
|
|
2
|
+
import { attachCookiesToResponse } from "./cookies/index.js";
|
|
3
|
+
import { callMiddleware } from "./middleware/callMiddleware.js";
|
|
4
|
+
import { sequence } from "./middleware/index.js";
|
|
5
|
+
import { AstroCookies } from "./cookies/index.js";
|
|
6
|
+
import { createResult } from "./render/index.js";
|
|
7
|
+
import { renderPage } from "../runtime/server/index.js";
|
|
8
|
+
import {
|
|
9
|
+
ASTRO_VERSION,
|
|
10
|
+
ROUTE_TYPE_HEADER,
|
|
11
|
+
clientAddressSymbol,
|
|
12
|
+
clientLocalsSymbol
|
|
13
|
+
} from "./constants.js";
|
|
14
|
+
import { getParams, getProps } from "./render/index.js";
|
|
15
|
+
import { AstroError, AstroErrorData } from "./errors/index.js";
|
|
16
|
+
import {
|
|
17
|
+
computeCurrentLocale,
|
|
18
|
+
computePreferredLocale,
|
|
19
|
+
computePreferredLocaleList
|
|
20
|
+
} from "../i18n/utils.js";
|
|
21
|
+
import { renderRedirect } from "./redirects/render.js";
|
|
22
|
+
class RenderContext {
|
|
23
|
+
constructor(pipeline, locals, middleware, pathname, request, routeData, status, cookies = new AstroCookies(request), params = getParams(routeData, pathname)) {
|
|
24
|
+
this.pipeline = pipeline;
|
|
25
|
+
this.locals = locals;
|
|
26
|
+
this.middleware = middleware;
|
|
27
|
+
this.pathname = pathname;
|
|
28
|
+
this.request = request;
|
|
29
|
+
this.routeData = routeData;
|
|
30
|
+
this.status = status;
|
|
31
|
+
this.cookies = cookies;
|
|
32
|
+
this.params = params;
|
|
33
|
+
}
|
|
34
|
+
static create({
|
|
35
|
+
locals = {},
|
|
36
|
+
middleware,
|
|
37
|
+
pathname,
|
|
38
|
+
pipeline,
|
|
39
|
+
request,
|
|
40
|
+
routeData,
|
|
41
|
+
status = 200
|
|
42
|
+
}) {
|
|
43
|
+
return new RenderContext(
|
|
44
|
+
pipeline,
|
|
45
|
+
locals,
|
|
46
|
+
sequence(...pipeline.internalMiddleware, middleware ?? pipeline.middleware),
|
|
47
|
+
pathname,
|
|
48
|
+
request,
|
|
49
|
+
routeData,
|
|
50
|
+
status
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* The main function of the RenderContext.
|
|
55
|
+
*
|
|
56
|
+
* Use this function to render any route known to Astro.
|
|
57
|
+
* It attempts to render a route. A route can be a:
|
|
58
|
+
*
|
|
59
|
+
* - page
|
|
60
|
+
* - redirect
|
|
61
|
+
* - endpoint
|
|
62
|
+
* - fallback
|
|
63
|
+
*/
|
|
64
|
+
async render(componentInstance) {
|
|
65
|
+
const { cookies, middleware, pathname, pipeline, routeData } = this;
|
|
66
|
+
const { logger, routeCache, serverLike, streaming } = pipeline;
|
|
67
|
+
const props = await getProps({
|
|
68
|
+
mod: componentInstance,
|
|
69
|
+
routeData,
|
|
70
|
+
routeCache,
|
|
71
|
+
pathname,
|
|
72
|
+
logger,
|
|
73
|
+
serverLike
|
|
74
|
+
});
|
|
75
|
+
const apiContext = this.createAPIContext(props);
|
|
76
|
+
const { type } = routeData;
|
|
77
|
+
const lastNext = type === "endpoint" ? () => renderEndpoint(componentInstance, apiContext, serverLike, logger) : type === "redirect" ? () => renderRedirect(this) : type === "page" ? async () => {
|
|
78
|
+
const result = await this.createResult(componentInstance);
|
|
79
|
+
const response2 = await renderPage(
|
|
80
|
+
result,
|
|
81
|
+
componentInstance?.default,
|
|
82
|
+
props,
|
|
83
|
+
{},
|
|
84
|
+
streaming,
|
|
85
|
+
routeData
|
|
86
|
+
);
|
|
87
|
+
response2.headers.set(ROUTE_TYPE_HEADER, "page");
|
|
88
|
+
return response2;
|
|
89
|
+
} : type === "fallback" ? () => new Response(null, { status: 500, headers: { [ROUTE_TYPE_HEADER]: "fallback" } }) : () => {
|
|
90
|
+
throw new Error("Unknown type of route: " + type);
|
|
91
|
+
};
|
|
92
|
+
const response = await callMiddleware(middleware, apiContext, lastNext);
|
|
93
|
+
if (response.headers.get(ROUTE_TYPE_HEADER)) {
|
|
94
|
+
response.headers.delete(ROUTE_TYPE_HEADER);
|
|
95
|
+
}
|
|
96
|
+
attachCookiesToResponse(response, cookies);
|
|
97
|
+
return response;
|
|
98
|
+
}
|
|
99
|
+
createAPIContext(props) {
|
|
100
|
+
const renderContext = this;
|
|
101
|
+
const { cookies, i18nData, params, pipeline, request } = this;
|
|
102
|
+
const { currentLocale, preferredLocale, preferredLocaleList } = i18nData;
|
|
103
|
+
const generator = `Astro v${ASTRO_VERSION}`;
|
|
104
|
+
const redirect = (path, status = 302) => new Response(null, { status, headers: { Location: path } });
|
|
105
|
+
const site = pipeline.site ? new URL(pipeline.site) : void 0;
|
|
106
|
+
const url = new URL(request.url);
|
|
107
|
+
return {
|
|
108
|
+
cookies,
|
|
109
|
+
currentLocale,
|
|
110
|
+
generator,
|
|
111
|
+
params,
|
|
112
|
+
preferredLocale,
|
|
113
|
+
preferredLocaleList,
|
|
114
|
+
props,
|
|
115
|
+
redirect,
|
|
116
|
+
request,
|
|
117
|
+
site,
|
|
118
|
+
url,
|
|
119
|
+
get clientAddress() {
|
|
120
|
+
if (clientAddressSymbol in request) {
|
|
121
|
+
return Reflect.get(request, clientAddressSymbol);
|
|
122
|
+
}
|
|
123
|
+
if (pipeline.adapterName) {
|
|
124
|
+
throw new AstroError({
|
|
125
|
+
...AstroErrorData.ClientAddressNotAvailable,
|
|
126
|
+
message: AstroErrorData.ClientAddressNotAvailable.message(pipeline.adapterName)
|
|
127
|
+
});
|
|
128
|
+
} else {
|
|
129
|
+
throw new AstroError(AstroErrorData.StaticClientAddressNotAvailable);
|
|
130
|
+
}
|
|
131
|
+
},
|
|
132
|
+
get locals() {
|
|
133
|
+
return renderContext.locals;
|
|
134
|
+
},
|
|
135
|
+
// TODO(breaking): disallow replacing the locals object
|
|
136
|
+
set locals(val) {
|
|
137
|
+
if (typeof val !== "object") {
|
|
138
|
+
throw new AstroError(AstroErrorData.LocalsNotAnObject);
|
|
139
|
+
} else {
|
|
140
|
+
renderContext.locals = val;
|
|
141
|
+
Reflect.set(request, clientLocalsSymbol, val);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
async createResult(mod) {
|
|
147
|
+
const { cookies, locals, params, pathname, pipeline, request, routeData, status } = this;
|
|
148
|
+
const {
|
|
149
|
+
adapterName,
|
|
150
|
+
clientDirectives,
|
|
151
|
+
compressHTML,
|
|
152
|
+
i18n,
|
|
153
|
+
manifest,
|
|
154
|
+
logger,
|
|
155
|
+
renderers,
|
|
156
|
+
resolve,
|
|
157
|
+
site,
|
|
158
|
+
serverLike
|
|
159
|
+
} = pipeline;
|
|
160
|
+
const { links, scripts, styles } = await pipeline.headElements(routeData);
|
|
161
|
+
const componentMetadata = await pipeline.componentMetadata(routeData) ?? manifest.componentMetadata;
|
|
162
|
+
const { defaultLocale, locales, routing: routingStrategy } = i18n ?? {};
|
|
163
|
+
const partial = Boolean(mod.partial);
|
|
164
|
+
return createResult({
|
|
165
|
+
adapterName,
|
|
166
|
+
clientDirectives,
|
|
167
|
+
componentMetadata,
|
|
168
|
+
compressHTML,
|
|
169
|
+
cookies,
|
|
170
|
+
defaultLocale,
|
|
171
|
+
locales,
|
|
172
|
+
locals,
|
|
173
|
+
logger,
|
|
174
|
+
links,
|
|
175
|
+
params,
|
|
176
|
+
partial,
|
|
177
|
+
pathname,
|
|
178
|
+
renderers,
|
|
179
|
+
resolve,
|
|
180
|
+
request,
|
|
181
|
+
route: routeData.route,
|
|
182
|
+
routingStrategy,
|
|
183
|
+
site,
|
|
184
|
+
scripts,
|
|
185
|
+
ssr: serverLike,
|
|
186
|
+
status,
|
|
187
|
+
styles
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* API Context may be created multiple times per request, i18n data needs to be computed only once.
|
|
192
|
+
* So, it is computed and saved here on creation of the first APIContext and reused for later ones.
|
|
193
|
+
*/
|
|
194
|
+
#i18nData;
|
|
195
|
+
get i18nData() {
|
|
196
|
+
if (this.#i18nData)
|
|
197
|
+
return this.#i18nData;
|
|
198
|
+
const {
|
|
199
|
+
pipeline: { i18n },
|
|
200
|
+
request,
|
|
201
|
+
routeData
|
|
202
|
+
} = this;
|
|
203
|
+
if (!i18n)
|
|
204
|
+
return {
|
|
205
|
+
currentLocale: void 0,
|
|
206
|
+
preferredLocale: void 0,
|
|
207
|
+
preferredLocaleList: void 0
|
|
208
|
+
};
|
|
209
|
+
const { defaultLocale, locales, routing } = i18n;
|
|
210
|
+
return this.#i18nData = {
|
|
211
|
+
currentLocale: computeCurrentLocale(routeData.route, locales, routing, defaultLocale),
|
|
212
|
+
preferredLocale: computePreferredLocale(request, locales),
|
|
213
|
+
preferredLocaleList: computePreferredLocaleList(request, locales)
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
export {
|
|
218
|
+
RenderContext
|
|
219
|
+
};
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
export { createRouteManifest } from './manifest/create.js';
|
|
2
2
|
export { deserializeRouteData, serializeRouteData } from './manifest/serialization.js';
|
|
3
3
|
export { matchAllRoutes, matchRoute } from './match.js';
|
|
4
|
-
export { getParams } from './params.js';
|
|
5
4
|
export { validateDynamicRouteModule, validateGetStaticPathsResult } from './validation.js';
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import { createRouteManifest } from "./manifest/create.js";
|
|
2
2
|
import { deserializeRouteData, serializeRouteData } from "./manifest/serialization.js";
|
|
3
3
|
import { matchAllRoutes, matchRoute } from "./match.js";
|
|
4
|
-
import { getParams } from "./params.js";
|
|
5
4
|
import { validateDynamicRouteModule, validateGetStaticPathsResult } from "./validation.js";
|
|
6
5
|
export {
|
|
7
6
|
createRouteManifest,
|
|
8
7
|
deserializeRouteData,
|
|
9
|
-
getParams,
|
|
10
8
|
matchAllRoutes,
|
|
11
9
|
matchRoute,
|
|
12
10
|
serializeRouteData,
|
|
@@ -1,10 +1,4 @@
|
|
|
1
|
-
import type { GetStaticPathsItem,
|
|
2
|
-
/**
|
|
3
|
-
* given an array of params like `['x', 'y', 'z']` for
|
|
4
|
-
* src/routes/[x]/[y]/[z]/svelte, create a function
|
|
5
|
-
* that turns a RegExpExecArray into ({ x, y, z })
|
|
6
|
-
*/
|
|
7
|
-
export declare function getParams(array: string[]): (match: RegExpExecArray) => Params;
|
|
1
|
+
import type { GetStaticPathsItem, RouteData } from '../../@types/astro.js';
|
|
8
2
|
/**
|
|
9
3
|
* given a route's Params object, validate parameter
|
|
10
4
|
* values and create a stringified key for the route
|
|
@@ -1,19 +1,5 @@
|
|
|
1
1
|
import { trimSlashes } from "../path.js";
|
|
2
2
|
import { validateGetStaticPathsParameter } from "./validation.js";
|
|
3
|
-
function getParams(array) {
|
|
4
|
-
const fn = (match) => {
|
|
5
|
-
const params = {};
|
|
6
|
-
array.forEach((key, i) => {
|
|
7
|
-
if (key.startsWith("...")) {
|
|
8
|
-
params[key.slice(3)] = match[i + 1] ? match[i + 1] : void 0;
|
|
9
|
-
} else {
|
|
10
|
-
params[key] = match[i + 1];
|
|
11
|
-
}
|
|
12
|
-
});
|
|
13
|
-
return params;
|
|
14
|
-
};
|
|
15
|
-
return fn;
|
|
16
|
-
}
|
|
17
3
|
function stringifyParams(params, route) {
|
|
18
4
|
const validatedParams = Object.entries(params).reduce((acc, next) => {
|
|
19
5
|
validateGetStaticPathsParameter(next, route.component);
|
|
@@ -26,6 +12,5 @@ function stringifyParams(params, route) {
|
|
|
26
12
|
return JSON.stringify(route.generate(validatedParams));
|
|
27
13
|
}
|
|
28
14
|
export {
|
|
29
|
-
getParams,
|
|
30
15
|
stringifyParams
|
|
31
16
|
};
|
package/dist/core/sync/index.js
CHANGED
|
@@ -53,12 +53,12 @@ async function syncInternal(settings, { logger, fs }) {
|
|
|
53
53
|
{ settings, logger, mode: "build", command: "build", fs }
|
|
54
54
|
)
|
|
55
55
|
);
|
|
56
|
-
const
|
|
57
|
-
tempViteServer.
|
|
56
|
+
const hotSend = tempViteServer.hot.send;
|
|
57
|
+
tempViteServer.hot.send = (payload) => {
|
|
58
58
|
if (payload.type === "error") {
|
|
59
59
|
throw payload.err;
|
|
60
60
|
}
|
|
61
|
-
return
|
|
61
|
+
return hotSend(payload);
|
|
62
62
|
};
|
|
63
63
|
try {
|
|
64
64
|
const contentTypesGenerator = await createContentTypesGenerator({
|
|
@@ -1,7 +1,2 @@
|
|
|
1
1
|
import type { MiddlewareHandler, SSRManifest } from '../@types/astro.js';
|
|
2
|
-
import type { PipelineHookFunction } from '../core/pipeline.js';
|
|
3
2
|
export declare function createI18nMiddleware(i18n: SSRManifest['i18n'], base: SSRManifest['base'], trailingSlash: SSRManifest['trailingSlash'], buildFormat: SSRManifest['buildFormat']): MiddlewareHandler;
|
|
4
|
-
/**
|
|
5
|
-
* This pipeline hook attaches a `RouteData` object to the `Request`
|
|
6
|
-
*/
|
|
7
|
-
export declare const i18nPipelineHook: PipelineHookFunction;
|
package/dist/i18n/middleware.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { appendForwardSlash, joinPaths } from "@astrojs/internal-helpers/path";
|
|
2
2
|
import { getPathByLocale, normalizeTheLocale } from "./index.js";
|
|
3
3
|
import { shouldAppendForwardSlash } from "../core/build/util.js";
|
|
4
|
-
import {
|
|
5
|
-
const routeDataSymbol = Symbol.for(ROUTE_DATA_SYMBOL);
|
|
4
|
+
import { ROUTE_TYPE_HEADER } from "../core/constants.js";
|
|
6
5
|
function pathnameHasLocale(pathname, locales) {
|
|
7
6
|
const segments = pathname.split("/");
|
|
8
7
|
for (const segment of segments) {
|
|
@@ -65,99 +64,93 @@ function createI18nMiddleware(i18n, base, trailingSlash, buildFormat) {
|
|
|
65
64
|
return void 0;
|
|
66
65
|
};
|
|
67
66
|
return async (context, next) => {
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
|
|
67
|
+
const response = await next();
|
|
68
|
+
const type = response.headers.get(ROUTE_TYPE_HEADER);
|
|
69
|
+
if (type !== "page" && type !== "fallback") {
|
|
70
|
+
return response;
|
|
71
71
|
}
|
|
72
|
-
const currentLocale = context
|
|
73
|
-
const url = context.url;
|
|
72
|
+
const { url, currentLocale } = context;
|
|
74
73
|
const { locales, defaultLocale, fallback, routing } = i18n;
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
case "domains-prefix-other-locales": {
|
|
79
|
-
if (localeHasntDomain(i18n, currentLocale)) {
|
|
80
|
-
const result = prefixOtherLocales(url, response);
|
|
81
|
-
if (result) {
|
|
82
|
-
return result;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
break;
|
|
86
|
-
}
|
|
87
|
-
case "pathname-prefix-other-locales": {
|
|
74
|
+
switch (i18n.routing) {
|
|
75
|
+
case "domains-prefix-other-locales": {
|
|
76
|
+
if (localeHasntDomain(i18n, currentLocale)) {
|
|
88
77
|
const result = prefixOtherLocales(url, response);
|
|
89
78
|
if (result) {
|
|
90
79
|
return result;
|
|
91
80
|
}
|
|
92
|
-
break;
|
|
93
81
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
}
|
|
101
|
-
break;
|
|
82
|
+
break;
|
|
83
|
+
}
|
|
84
|
+
case "pathname-prefix-other-locales": {
|
|
85
|
+
const result = prefixOtherLocales(url, response);
|
|
86
|
+
if (result) {
|
|
87
|
+
return result;
|
|
102
88
|
}
|
|
103
|
-
|
|
89
|
+
break;
|
|
90
|
+
}
|
|
91
|
+
case "domains-prefix-always-no-redirect": {
|
|
92
|
+
if (localeHasntDomain(i18n, currentLocale)) {
|
|
104
93
|
const result = prefixAlwaysNoRedirect(url, response);
|
|
105
94
|
if (result) {
|
|
106
95
|
return result;
|
|
107
96
|
}
|
|
108
|
-
break;
|
|
109
97
|
}
|
|
110
|
-
|
|
98
|
+
break;
|
|
99
|
+
}
|
|
100
|
+
case "pathname-prefix-always-no-redirect": {
|
|
101
|
+
const result = prefixAlwaysNoRedirect(url, response);
|
|
102
|
+
if (result) {
|
|
103
|
+
return result;
|
|
104
|
+
}
|
|
105
|
+
break;
|
|
106
|
+
}
|
|
107
|
+
case "pathname-prefix-always": {
|
|
108
|
+
const result = prefixAlways(url, response, context);
|
|
109
|
+
if (result) {
|
|
110
|
+
return result;
|
|
111
|
+
}
|
|
112
|
+
break;
|
|
113
|
+
}
|
|
114
|
+
case "domains-prefix-always": {
|
|
115
|
+
if (localeHasntDomain(i18n, currentLocale)) {
|
|
111
116
|
const result = prefixAlways(url, response, context);
|
|
112
117
|
if (result) {
|
|
113
118
|
return result;
|
|
114
119
|
}
|
|
115
|
-
break;
|
|
116
|
-
}
|
|
117
|
-
case "domains-prefix-always": {
|
|
118
|
-
if (localeHasntDomain(i18n, currentLocale)) {
|
|
119
|
-
const result = prefixAlways(url, response, context);
|
|
120
|
-
if (result) {
|
|
121
|
-
return result;
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
break;
|
|
125
120
|
}
|
|
121
|
+
break;
|
|
126
122
|
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
}
|
|
136
|
-
} else if (locale.path === segment) {
|
|
123
|
+
}
|
|
124
|
+
if (response.status >= 300 && fallback) {
|
|
125
|
+
const fallbackKeys = i18n.fallback ? Object.keys(i18n.fallback) : [];
|
|
126
|
+
const segments = url.pathname.split("/");
|
|
127
|
+
const urlLocale = segments.find((segment) => {
|
|
128
|
+
for (const locale of locales) {
|
|
129
|
+
if (typeof locale === "string") {
|
|
130
|
+
if (locale === segment) {
|
|
137
131
|
return true;
|
|
138
132
|
}
|
|
133
|
+
} else if (locale.path === segment) {
|
|
134
|
+
return true;
|
|
139
135
|
}
|
|
140
|
-
return false;
|
|
141
|
-
});
|
|
142
|
-
if (urlLocale && fallbackKeys.includes(urlLocale)) {
|
|
143
|
-
const fallbackLocale = fallback[urlLocale];
|
|
144
|
-
const pathFallbackLocale = getPathByLocale(fallbackLocale, locales);
|
|
145
|
-
let newPathname;
|
|
146
|
-
if (pathFallbackLocale === defaultLocale && routing === "pathname-prefix-other-locales") {
|
|
147
|
-
newPathname = url.pathname.replace(`/${urlLocale}`, ``);
|
|
148
|
-
} else {
|
|
149
|
-
newPathname = url.pathname.replace(`/${urlLocale}`, `/${pathFallbackLocale}`);
|
|
150
|
-
}
|
|
151
|
-
return context.redirect(newPathname);
|
|
152
136
|
}
|
|
137
|
+
return false;
|
|
138
|
+
});
|
|
139
|
+
if (urlLocale && fallbackKeys.includes(urlLocale)) {
|
|
140
|
+
const fallbackLocale = fallback[urlLocale];
|
|
141
|
+
const pathFallbackLocale = getPathByLocale(fallbackLocale, locales);
|
|
142
|
+
let newPathname;
|
|
143
|
+
if (pathFallbackLocale === defaultLocale && routing === "pathname-prefix-other-locales") {
|
|
144
|
+
newPathname = url.pathname.replace(`/${urlLocale}`, ``);
|
|
145
|
+
} else {
|
|
146
|
+
newPathname = url.pathname.replace(`/${urlLocale}`, `/${pathFallbackLocale}`);
|
|
147
|
+
}
|
|
148
|
+
return context.redirect(newPathname);
|
|
153
149
|
}
|
|
154
150
|
}
|
|
155
151
|
return response;
|
|
156
152
|
};
|
|
157
153
|
}
|
|
158
|
-
const i18nPipelineHook = (ctx) => {
|
|
159
|
-
Reflect.set(ctx.request, routeDataSymbol, ctx.route);
|
|
160
|
-
};
|
|
161
154
|
function localeHasntDomain(i18n, currentLocale) {
|
|
162
155
|
for (const domainLocale of Object.values(i18n.domainLookupTable)) {
|
|
163
156
|
if (domainLocale === currentLocale) {
|
|
@@ -167,6 +160,5 @@ function localeHasntDomain(i18n, currentLocale) {
|
|
|
167
160
|
return true;
|
|
168
161
|
}
|
|
169
162
|
export {
|
|
170
|
-
createI18nMiddleware
|
|
171
|
-
i18nPipelineHook
|
|
163
|
+
createI18nMiddleware
|
|
172
164
|
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Locales } from '../@types/astro.js';
|
|
2
|
+
import type { RoutingStrategies } from '../core/config/schema.js';
|
|
3
|
+
type BrowserLocale = {
|
|
4
|
+
locale: string;
|
|
5
|
+
qualityValue: number | undefined;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Parses the value of the `Accept-Header` language:
|
|
9
|
+
*
|
|
10
|
+
* More info: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Language
|
|
11
|
+
*
|
|
12
|
+
* Complex example: `fr-CH, fr;q=0.9, en;q=0.8, de;q=0.7, *;q=0.5`
|
|
13
|
+
*
|
|
14
|
+
*/
|
|
15
|
+
export declare function parseLocale(header: string): BrowserLocale[];
|
|
16
|
+
/**
|
|
17
|
+
* Set the current locale by parsing the value passed from the `Accept-Header`.
|
|
18
|
+
*
|
|
19
|
+
* If multiple locales are present in the header, they are sorted by their quality value and the highest is selected as current locale.
|
|
20
|
+
*
|
|
21
|
+
*/
|
|
22
|
+
export declare function computePreferredLocale(request: Request, locales: Locales): string | undefined;
|
|
23
|
+
export declare function computePreferredLocaleList(request: Request, locales: Locales): string[];
|
|
24
|
+
export declare function computeCurrentLocale(pathname: string, locales: Locales, routingStrategy: RoutingStrategies | undefined, defaultLocale: string | undefined): undefined | string;
|
|
25
|
+
export {};
|
|
@@ -1,44 +1,4 @@
|
|
|
1
|
-
import { normalizeTheLocale, toCodes } from "
|
|
2
|
-
import { AstroError, AstroErrorData } from "../errors/index.js";
|
|
3
|
-
import { getParamsAndProps } from "./params-and-props.js";
|
|
4
|
-
import { ROUTE_DATA_SYMBOL } from "../constants.js";
|
|
5
|
-
const clientLocalsSymbol = Symbol.for("astro.locals");
|
|
6
|
-
const routeDataSymbol = Symbol.for(ROUTE_DATA_SYMBOL);
|
|
7
|
-
async function createRenderContext(options) {
|
|
8
|
-
const request = options.request;
|
|
9
|
-
const pathname = options.pathname ?? new URL(request.url).pathname;
|
|
10
|
-
const [params, props] = await getParamsAndProps({
|
|
11
|
-
mod: options.mod,
|
|
12
|
-
route: options.route,
|
|
13
|
-
routeCache: options.env.routeCache,
|
|
14
|
-
pathname,
|
|
15
|
-
logger: options.env.logger,
|
|
16
|
-
ssr: options.env.ssr
|
|
17
|
-
});
|
|
18
|
-
const context = {
|
|
19
|
-
...options,
|
|
20
|
-
pathname,
|
|
21
|
-
params,
|
|
22
|
-
props,
|
|
23
|
-
locales: options.locales,
|
|
24
|
-
routing: options.routing,
|
|
25
|
-
defaultLocale: options.defaultLocale
|
|
26
|
-
};
|
|
27
|
-
Object.defineProperty(context, "locals", {
|
|
28
|
-
enumerable: true,
|
|
29
|
-
get() {
|
|
30
|
-
return Reflect.get(request, clientLocalsSymbol);
|
|
31
|
-
},
|
|
32
|
-
set(val) {
|
|
33
|
-
if (typeof val !== "object") {
|
|
34
|
-
throw new AstroError(AstroErrorData.LocalsNotAnObject);
|
|
35
|
-
} else {
|
|
36
|
-
Reflect.set(request, clientLocalsSymbol, val);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
|
-
return context;
|
|
41
|
-
}
|
|
1
|
+
import { normalizeTheLocale, toCodes } from "./index.js";
|
|
42
2
|
function parseLocale(header) {
|
|
43
3
|
if (header === "*") {
|
|
44
4
|
return [{ locale: header, qualityValue: void 0 }];
|
|
@@ -149,13 +109,8 @@ function computePreferredLocaleList(request, locales) {
|
|
|
149
109
|
}
|
|
150
110
|
return result;
|
|
151
111
|
}
|
|
152
|
-
function computeCurrentLocale(
|
|
153
|
-
const
|
|
154
|
-
if (!routeData) {
|
|
155
|
-
return defaultLocale;
|
|
156
|
-
}
|
|
157
|
-
const pathname = routeData.pathname ?? new URL(request.url).pathname;
|
|
158
|
-
for (const segment of pathname.split("/").filter(Boolean)) {
|
|
112
|
+
function computeCurrentLocale(pathname, locales, routingStrategy, defaultLocale) {
|
|
113
|
+
for (const segment of pathname.split("/")) {
|
|
159
114
|
for (const locale of locales) {
|
|
160
115
|
if (typeof locale === "string") {
|
|
161
116
|
if (!segment.includes(locale))
|
|
@@ -185,6 +140,5 @@ export {
|
|
|
185
140
|
computeCurrentLocale,
|
|
186
141
|
computePreferredLocale,
|
|
187
142
|
computePreferredLocaleList,
|
|
188
|
-
createRenderContext,
|
|
189
143
|
parseLocale
|
|
190
144
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { AstroSettings, ComponentInstance, RouteData } from '../@types/astro.js';
|
|
2
|
-
import type DevPipeline from '../vite-plugin-astro-server/
|
|
2
|
+
import type { DevPipeline } from '../vite-plugin-astro-server/pipeline.js';
|
|
3
3
|
type GetSortedPreloadedMatchesParams = {
|
|
4
4
|
pipeline: DevPipeline;
|
|
5
5
|
matches: RouteData[];
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { RedirectComponentInstance, routeIsRedirect } from "../core/redirects/index.js";
|
|
2
|
-
import { preload } from "../vite-plugin-astro-server/index.js";
|
|
3
2
|
import { getPrerenderStatus } from "./metadata.js";
|
|
4
3
|
async function getSortedPreloadedMatches({
|
|
5
4
|
pipeline,
|
|
@@ -28,10 +27,10 @@ async function preloadAndSetPrerenderStatus({
|
|
|
28
27
|
});
|
|
29
28
|
continue;
|
|
30
29
|
}
|
|
31
|
-
const preloadedComponent = await preload(
|
|
30
|
+
const preloadedComponent = await pipeline.preload(filePath);
|
|
32
31
|
const prerenderStatus = getPrerenderStatus({
|
|
33
32
|
filePath,
|
|
34
|
-
loader: pipeline.
|
|
33
|
+
loader: pipeline.loader
|
|
35
34
|
});
|
|
36
35
|
if (prerenderStatus !== void 0) {
|
|
37
36
|
route.prerender = prerenderStatus;
|
|
@@ -10,23 +10,27 @@ var astro_default = {
|
|
|
10
10
|
async init(canvas, eventTarget) {
|
|
11
11
|
createCanvas();
|
|
12
12
|
document.addEventListener("astro:after-swap", createCanvas);
|
|
13
|
+
document.addEventListener("astro:after-swap", fetchIntegrationData);
|
|
13
14
|
eventTarget.addEventListener("app-toggled", async (event) => {
|
|
14
15
|
resetDebugButton();
|
|
15
16
|
if (!(event instanceof CustomEvent))
|
|
16
17
|
return;
|
|
17
18
|
if (event.detail.state === true) {
|
|
18
19
|
if (!integrationData)
|
|
19
|
-
|
|
20
|
-
cache: "no-cache"
|
|
21
|
-
}).then((res) => res.json()).then((data) => {
|
|
22
|
-
integrationData = data;
|
|
23
|
-
integrationData.data = integrationData.data.map((integration) => {
|
|
24
|
-
return integration;
|
|
25
|
-
});
|
|
26
|
-
refreshIntegrationList();
|
|
27
|
-
});
|
|
20
|
+
fetchIntegrationData();
|
|
28
21
|
}
|
|
29
22
|
});
|
|
23
|
+
function fetchIntegrationData() {
|
|
24
|
+
fetch("https://astro.build/api/v1/dev-overlay/", {
|
|
25
|
+
cache: "no-cache"
|
|
26
|
+
}).then((res) => res.json()).then((data) => {
|
|
27
|
+
integrationData = data;
|
|
28
|
+
integrationData.data = integrationData.data.map((integration) => {
|
|
29
|
+
return integration;
|
|
30
|
+
});
|
|
31
|
+
refreshIntegrationList();
|
|
32
|
+
});
|
|
33
|
+
}
|
|
30
34
|
function createCanvas() {
|
|
31
35
|
const links = [
|
|
32
36
|
{
|
|
@@ -307,8 +307,8 @@ const a11y = [
|
|
|
307
307
|
message: "Headings and anchors must have an accessible name, which can come from: inner text, aria-label, aria-labelledby, an img with alt property, or an svg with a tag <title></title>.",
|
|
308
308
|
selector: a11y_required_content.join(","),
|
|
309
309
|
match(element) {
|
|
310
|
-
const innerText = element.innerText
|
|
311
|
-
if (innerText !== "")
|
|
310
|
+
const innerText = element.innerText?.trim();
|
|
311
|
+
if (innerText && innerText !== "")
|
|
312
312
|
return false;
|
|
313
313
|
const ariaLabel = element.getAttribute("aria-label")?.trim();
|
|
314
314
|
if (ariaLabel && ariaLabel !== "")
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { bold } from "kleur/colors";
|
|
2
|
-
import { REROUTE_DIRECTIVE_HEADER } from "
|
|
2
|
+
import { REROUTABLE_STATUS_CODES, REROUTE_DIRECTIVE_HEADER } from "../../core/constants.js";
|
|
3
3
|
async function renderEndpoint(mod, context, ssr, logger) {
|
|
4
4
|
const { request, url } = context;
|
|
5
5
|
const method = request.method.toUpperCase();
|
|
@@ -30,7 +30,7 @@ Found handlers: ${Object.keys(mod).map((exp) => JSON.stringify(exp)).join(", ")}
|
|
|
30
30
|
return new Response(null, { status: 500 });
|
|
31
31
|
}
|
|
32
32
|
const response = await handler.call(mod, context);
|
|
33
|
-
if (
|
|
33
|
+
if (REROUTABLE_STATUS_CODES.includes(response.status)) {
|
|
34
34
|
response.headers.set(REROUTE_DIRECTIVE_HEADER, "no");
|
|
35
35
|
}
|
|
36
36
|
return response;
|
|
@@ -9,3 +9,4 @@ export interface HandleHotUpdateOptions {
|
|
|
9
9
|
astroFileToCompileMetadata: Map<string, CompileMetadata>;
|
|
10
10
|
}
|
|
11
11
|
export declare function handleHotUpdate(ctx: HmrContext, { logger, compile, astroFileToCssAstroDeps, astroFileToCompileMetadata }: HandleHotUpdateOptions): Promise<import("vite").ModuleNode[] | undefined>;
|
|
12
|
+
export declare function isStyleOnlyChanged(oldCode: string, newCode: string): boolean;
|