astro 4.3.7 → 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/components/Image.astro +4 -0
- package/components/Picture.astro +4 -0
- 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/assets/internal.js +14 -0
- package/dist/assets/types.d.ts +23 -2
- package/dist/assets/utils/metadata.js +3 -3
- package/dist/assets/utils/remoteProbe.d.ts +2 -0
- package/dist/assets/utils/remoteProbe.js +35 -0
- package/dist/assets/utils/vendor/image-size/detector.d.ts +2 -0
- package/dist/assets/utils/vendor/image-size/detector.js +24 -0
- package/dist/assets/utils/vendor/image-size/lookup.d.ts +10 -0
- package/dist/assets/utils/vendor/image-size/lookup.js +26 -0
- package/dist/assets/utils/vendor/image-size/types/bmp.d.ts +2 -0
- package/dist/assets/utils/vendor/image-size/types/bmp.js +11 -0
- package/dist/assets/utils/vendor/image-size/types/cur.d.ts +2 -0
- package/dist/assets/utils/vendor/image-size/types/cur.js +17 -0
- package/dist/assets/utils/vendor/image-size/types/dds.d.ts +2 -0
- package/dist/assets/utils/vendor/image-size/types/dds.js +11 -0
- package/dist/assets/utils/vendor/image-size/types/gif.d.ts +2 -0
- package/dist/assets/utils/vendor/image-size/types/gif.js +12 -0
- package/dist/assets/utils/vendor/image-size/types/heif.d.ts +2 -0
- package/dist/assets/utils/vendor/image-size/types/heif.js +53 -0
- package/dist/assets/utils/vendor/image-size/types/icns.d.ts +2 -0
- package/dist/assets/utils/vendor/image-size/types/icns.js +85 -0
- package/dist/assets/utils/vendor/image-size/types/ico.d.ts +2 -0
- package/dist/assets/utils/vendor/image-size/types/ico.js +43 -0
- package/dist/assets/utils/vendor/image-size/types/index.d.ts +3 -0
- package/dist/assets/utils/vendor/image-size/types/index.js +43 -0
- package/dist/assets/utils/vendor/image-size/types/interface.d.ts +13 -0
- package/dist/assets/utils/vendor/image-size/types/interface.js +0 -0
- package/dist/assets/utils/vendor/image-size/types/j2c.d.ts +2 -0
- package/dist/assets/utils/vendor/image-size/types/j2c.js +12 -0
- package/dist/assets/utils/vendor/image-size/types/jp2.d.ts +2 -0
- package/dist/assets/utils/vendor/image-size/types/jp2.js +25 -0
- package/dist/assets/utils/vendor/image-size/types/jpg.d.ts +2 -0
- package/dist/assets/utils/vendor/image-size/types/jpg.js +97 -0
- package/dist/assets/utils/vendor/image-size/types/ktx.d.ts +2 -0
- package/dist/assets/utils/vendor/image-size/types/ktx.js +19 -0
- package/dist/assets/utils/vendor/image-size/types/png.d.ts +2 -0
- package/dist/assets/utils/vendor/image-size/types/png.js +34 -0
- package/dist/assets/utils/vendor/image-size/types/pnm.d.ts +2 -0
- package/dist/assets/utils/vendor/image-size/types/pnm.js +69 -0
- package/dist/assets/utils/vendor/image-size/types/psd.d.ts +2 -0
- package/dist/assets/utils/vendor/image-size/types/psd.js +11 -0
- package/dist/assets/utils/vendor/image-size/types/svg.d.ts +2 -0
- package/dist/assets/utils/vendor/image-size/types/svg.js +94 -0
- package/dist/assets/utils/vendor/image-size/types/tga.d.ts +2 -0
- package/dist/assets/utils/vendor/image-size/types/tga.js +15 -0
- package/dist/assets/utils/vendor/image-size/types/tiff.d.ts +2 -0
- package/dist/assets/utils/vendor/image-size/types/tiff.js +66 -0
- package/dist/assets/utils/vendor/image-size/types/utils.d.ts +15 -0
- package/dist/assets/utils/vendor/image-size/types/utils.js +60 -0
- package/dist/assets/utils/vendor/image-size/types/webp.d.ts +2 -0
- package/dist/assets/utils/vendor/image-size/types/webp.js +52 -0
- package/dist/cli/add/babel.d.ts +1 -1
- package/dist/cli/add/index.js +10 -3
- 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/runtime.js +3 -1
- package/dist/content/types-generator.js +7 -27
- 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/plugins/plugin-css.js +6 -5
- package/dist/core/build/plugins/plugin-hoisted-scripts.js +6 -5
- package/dist/core/build/plugins/util.d.ts +2 -1
- package/dist/core/build/plugins/util.js +12 -1
- 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 +16 -3
- package/dist/core/errors/errors-data.js +9 -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/manifest/create.js +11 -27
- 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 +20 -21
- package/dist/runtime/client/dev-toolbar/apps/astro.js +14 -10
- package/dist/runtime/client/dev-toolbar/apps/audit/a11y.js +2 -2
- package/dist/runtime/client/dev-toolbar/apps/audit/index.d.ts +1 -1
- package/dist/runtime/client/dev-toolbar/apps/audit/index.js +115 -6
- package/dist/runtime/client/dev-toolbar/apps/audit/perf.d.ts +2 -0
- package/dist/runtime/client/dev-toolbar/apps/audit/perf.js +110 -0
- package/dist/runtime/client/dev-toolbar/apps/utils/highlight.d.ts +1 -1
- package/dist/runtime/client/dev-toolbar/apps/utils/highlight.js +6 -1
- package/dist/runtime/client/dev-toolbar/ui-library/card.js +1 -1
- package/dist/runtime/server/astro-island.js +10 -1
- package/dist/runtime/server/astro-island.prebuilt-dev.d.ts +7 -0
- package/dist/runtime/server/astro-island.prebuilt-dev.js +4 -0
- package/dist/runtime/server/astro-island.prebuilt.d.ts +1 -1
- package/dist/runtime/server/astro-island.prebuilt.js +1 -1
- package/dist/runtime/server/endpoint.js +2 -2
- package/dist/runtime/server/render/astro/render.d.ts +1 -0
- package/dist/runtime/server/render/astro/render.js +81 -2
- package/dist/runtime/server/render/component.js +6 -0
- package/dist/runtime/server/render/page.js +15 -2
- package/dist/runtime/server/render/util.d.ts +7 -0
- package/dist/runtime/server/render/util.js +15 -0
- package/dist/runtime/server/scripts.js +2 -4
- package/dist/runtime/server/transition.js +14 -1
- 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 +7 -12
- 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
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
import { AstroError, AstroErrorData } from "../errors/index.js";
|
|
2
2
|
import { routeIsFallback } from "../redirects/helpers.js";
|
|
3
3
|
import { routeIsRedirect } from "../redirects/index.js";
|
|
4
|
-
import { getParams } from "../routing/params.js";
|
|
5
4
|
import { callGetStaticPaths, findPathItemByKey } from "./route-cache.js";
|
|
6
|
-
async function
|
|
7
|
-
const { logger, mod, route, routeCache, pathname,
|
|
5
|
+
async function getProps(opts) {
|
|
6
|
+
const { logger, mod, routeData: route, routeCache, pathname, serverLike } = opts;
|
|
8
7
|
if (!route || route.pathname) {
|
|
9
|
-
return
|
|
8
|
+
return {};
|
|
10
9
|
}
|
|
11
|
-
const params = getRouteParams(route, pathname) ?? {};
|
|
12
10
|
if (routeIsRedirect(route) || routeIsFallback(route)) {
|
|
13
|
-
return
|
|
11
|
+
return {};
|
|
14
12
|
}
|
|
13
|
+
const params = getParams(route, pathname);
|
|
15
14
|
if (mod) {
|
|
16
15
|
validatePrerenderEndpointCollision(route, mod, params);
|
|
17
16
|
}
|
|
@@ -20,10 +19,10 @@ async function getParamsAndProps(opts) {
|
|
|
20
19
|
route,
|
|
21
20
|
routeCache,
|
|
22
21
|
logger,
|
|
23
|
-
ssr
|
|
22
|
+
ssr: serverLike
|
|
24
23
|
});
|
|
25
24
|
const matchedStaticPath = findPathItemByKey(staticPaths, params, route, logger);
|
|
26
|
-
if (!matchedStaticPath && (
|
|
25
|
+
if (!matchedStaticPath && (serverLike ? route.prerender : true)) {
|
|
27
26
|
throw new AstroError({
|
|
28
27
|
...AstroErrorData.NoMatchingStaticPathFound,
|
|
29
28
|
message: AstroErrorData.NoMatchingStaticPathFound.message(pathname),
|
|
@@ -31,15 +30,23 @@ async function getParamsAndProps(opts) {
|
|
|
31
30
|
});
|
|
32
31
|
}
|
|
33
32
|
const props = matchedStaticPath?.props ? { ...matchedStaticPath.props } : {};
|
|
34
|
-
return
|
|
33
|
+
return props;
|
|
35
34
|
}
|
|
36
|
-
function
|
|
37
|
-
if (route.params.length)
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
35
|
+
function getParams(route, pathname) {
|
|
36
|
+
if (!route.params.length)
|
|
37
|
+
return {};
|
|
38
|
+
const paramsMatch = route.pattern.exec(decodeURIComponent(pathname));
|
|
39
|
+
if (!paramsMatch)
|
|
40
|
+
return {};
|
|
41
|
+
const params = {};
|
|
42
|
+
route.params.forEach((key, i) => {
|
|
43
|
+
if (key.startsWith("...")) {
|
|
44
|
+
params[key.slice(3)] = paramsMatch[i + 1] ? paramsMatch[i + 1] : void 0;
|
|
45
|
+
} else {
|
|
46
|
+
params[key] = paramsMatch[i + 1];
|
|
41
47
|
}
|
|
42
|
-
}
|
|
48
|
+
});
|
|
49
|
+
return params;
|
|
43
50
|
}
|
|
44
51
|
function validatePrerenderEndpointCollision(route, mod, params) {
|
|
45
52
|
if (route.type === "endpoint" && mod.getStaticPaths) {
|
|
@@ -59,5 +66,6 @@ function validatePrerenderEndpointCollision(route, mod, params) {
|
|
|
59
66
|
}
|
|
60
67
|
}
|
|
61
68
|
export {
|
|
62
|
-
|
|
69
|
+
getParams,
|
|
70
|
+
getProps
|
|
63
71
|
};
|
|
@@ -23,16 +23,17 @@ export interface CreateResultArgs {
|
|
|
23
23
|
* Used for `Astro.site`
|
|
24
24
|
*/
|
|
25
25
|
site: string | undefined;
|
|
26
|
-
links
|
|
27
|
-
scripts
|
|
28
|
-
styles
|
|
29
|
-
componentMetadata
|
|
26
|
+
links: Set<SSRElement>;
|
|
27
|
+
scripts: Set<SSRElement>;
|
|
28
|
+
styles: Set<SSRElement>;
|
|
29
|
+
componentMetadata: SSRResult['componentMetadata'];
|
|
30
30
|
request: Request;
|
|
31
31
|
status: number;
|
|
32
32
|
locals: App.Locals;
|
|
33
|
-
cookies
|
|
33
|
+
cookies: AstroCookies;
|
|
34
34
|
locales: Locales | undefined;
|
|
35
35
|
defaultLocale: string | undefined;
|
|
36
|
+
route: string;
|
|
36
37
|
routingStrategy: RoutingStrategies | undefined;
|
|
37
38
|
}
|
|
38
39
|
export declare function createResult(args: CreateResultArgs): SSRResult;
|
|
@@ -7,9 +7,8 @@ import {
|
|
|
7
7
|
computeCurrentLocale,
|
|
8
8
|
computePreferredLocale,
|
|
9
9
|
computePreferredLocaleList
|
|
10
|
-
} from "
|
|
11
|
-
|
|
12
|
-
const responseSentSymbol = Symbol.for("astro.responseSent");
|
|
10
|
+
} from "../../i18n/utils.js";
|
|
11
|
+
import { clientAddressSymbol, responseSentSymbol } from "../constants.js";
|
|
13
12
|
function getFunctionExpression(slot) {
|
|
14
13
|
if (!slot)
|
|
15
14
|
return;
|
|
@@ -160,7 +159,7 @@ function createResult(args) {
|
|
|
160
159
|
}
|
|
161
160
|
if (args.locales) {
|
|
162
161
|
currentLocale = computeCurrentLocale(
|
|
163
|
-
|
|
162
|
+
url.pathname,
|
|
164
163
|
args.locales,
|
|
165
164
|
args.routingStrategy,
|
|
166
165
|
args.defaultLocale
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { APIContext, ComponentInstance, MiddlewareHandler, RouteData } from '../@types/astro.js';
|
|
2
|
+
import { AstroCookies } from './cookies/index.js';
|
|
3
|
+
import { type Pipeline } from './render/index.js';
|
|
4
|
+
export declare class RenderContext {
|
|
5
|
+
#private;
|
|
6
|
+
readonly pipeline: Pipeline;
|
|
7
|
+
locals: App.Locals;
|
|
8
|
+
readonly middleware: MiddlewareHandler;
|
|
9
|
+
readonly pathname: string;
|
|
10
|
+
readonly request: Request;
|
|
11
|
+
readonly routeData: RouteData;
|
|
12
|
+
status: number;
|
|
13
|
+
readonly cookies: AstroCookies;
|
|
14
|
+
readonly params: import("../@types/astro.js").Params;
|
|
15
|
+
private constructor();
|
|
16
|
+
static create({ locals, middleware, pathname, pipeline, request, routeData, status, }: Pick<RenderContext, 'pathname' | 'pipeline' | 'request' | 'routeData'> & Partial<Pick<RenderContext, 'locals' | 'middleware' | 'status'>>): RenderContext;
|
|
17
|
+
/**
|
|
18
|
+
* The main function of the RenderContext.
|
|
19
|
+
*
|
|
20
|
+
* Use this function to render any route known to Astro.
|
|
21
|
+
* It attempts to render a route. A route can be a:
|
|
22
|
+
*
|
|
23
|
+
* - page
|
|
24
|
+
* - redirect
|
|
25
|
+
* - endpoint
|
|
26
|
+
* - fallback
|
|
27
|
+
*/
|
|
28
|
+
render(componentInstance: ComponentInstance | undefined): Promise<Response>;
|
|
29
|
+
createAPIContext(props: APIContext['props']): APIContext;
|
|
30
|
+
createResult(mod: ComponentInstance): Promise<import("../@types/astro.js").SSRResult>;
|
|
31
|
+
get i18nData(): Pick<APIContext<Record<string, any>, Record<string, string | undefined>>, "currentLocale" | "preferredLocale" | "preferredLocaleList">;
|
|
32
|
+
}
|
|
@@ -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,
|
|
@@ -121,33 +121,19 @@ function routeComparator(a, b) {
|
|
|
121
121
|
return aHasSpread ? 1 : -1;
|
|
122
122
|
}
|
|
123
123
|
}
|
|
124
|
-
|
|
124
|
+
const aLength = a.segments.length;
|
|
125
|
+
const bLength = b.segments.length;
|
|
126
|
+
if (aLength !== bLength) {
|
|
125
127
|
const aEndsInRest = a.segments.at(-1)?.some((part) => part.spread);
|
|
126
128
|
const bEndsInRest = b.segments.at(-1)?.some((part) => part.spread);
|
|
127
|
-
if (
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
if (a.isIndex !== b.isIndex) {
|
|
135
|
-
if (a.isIndex) {
|
|
136
|
-
const followingBSegment = b.segments.at(a.segments.length);
|
|
137
|
-
const followingBSegmentIsStatic = followingBSegment?.every(
|
|
138
|
-
(part) => !part.dynamic && !part.spread
|
|
139
|
-
);
|
|
140
|
-
return followingBSegmentIsStatic ? 1 : -1;
|
|
129
|
+
if (aEndsInRest !== bEndsInRest && Math.abs(aLength - bLength) === 1) {
|
|
130
|
+
if (aLength > bLength && aEndsInRest) {
|
|
131
|
+
return 1;
|
|
132
|
+
}
|
|
133
|
+
if (bLength > aLength && bEndsInRest) {
|
|
134
|
+
return -1;
|
|
135
|
+
}
|
|
141
136
|
}
|
|
142
|
-
const followingASegment = a.segments.at(b.segments.length);
|
|
143
|
-
const followingASegmentIsStatic = followingASegment?.every(
|
|
144
|
-
(part) => !part.dynamic && !part.spread
|
|
145
|
-
);
|
|
146
|
-
return followingASegmentIsStatic ? -1 : 1;
|
|
147
|
-
}
|
|
148
|
-
const aLength = a.isIndex ? a.segments.length + 1 : a.segments.length;
|
|
149
|
-
const bLength = b.isIndex ? b.segments.length + 1 : b.segments.length;
|
|
150
|
-
if (aLength !== bLength) {
|
|
151
137
|
return aLength > bLength ? -1 : 1;
|
|
152
138
|
}
|
|
153
139
|
if (a.type === "endpoint" !== (b.type === "endpoint")) {
|
|
@@ -492,9 +478,7 @@ function createRouteManifest(params, logger) {
|
|
|
492
478
|
if (i18n.routing === "pathname-prefix-always") {
|
|
493
479
|
const defaultLocaleRoutes = routesByLocale.get(i18n.defaultLocale);
|
|
494
480
|
if (defaultLocaleRoutes) {
|
|
495
|
-
const indexDefaultRoute = defaultLocaleRoutes.find((
|
|
496
|
-
return routeData.component.includes("index");
|
|
497
|
-
});
|
|
481
|
+
const indexDefaultRoute = defaultLocaleRoutes.find(({ route }) => route === "/") ?? defaultLocaleRoutes.find(({ route }) => route === `/${i18n.defaultLocale}`);
|
|
498
482
|
if (indexDefaultRoute) {
|
|
499
483
|
const pathname = "/";
|
|
500
484
|
const route = "/";
|
|
@@ -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;
|