astro 4.10.3 → 4.11.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/Code.astro +9 -0
- package/dist/@types/astro.d.ts +0 -2
- package/dist/actions/runtime/store.d.ts +0 -1
- package/dist/actions/runtime/virtual/server.d.ts +1 -1
- package/dist/assets/build/remote.d.ts +0 -1
- package/dist/assets/internal.d.ts +1 -1
- package/dist/assets/internal.js +6 -0
- package/dist/assets/services/vendor/squoosh/avif/avif_node_dec.wasm.d.ts +0 -1
- package/dist/assets/services/vendor/squoosh/avif/avif_node_enc.wasm.d.ts +0 -1
- package/dist/assets/services/vendor/squoosh/codecs.d.ts +0 -1
- package/dist/assets/services/vendor/squoosh/image.d.ts +0 -1
- package/dist/assets/services/vendor/squoosh/image_data.d.ts +0 -1
- package/dist/assets/services/vendor/squoosh/impl.d.ts +0 -1
- package/dist/assets/services/vendor/squoosh/mozjpeg/mozjpeg_node_dec.wasm.d.ts +0 -1
- package/dist/assets/services/vendor/squoosh/mozjpeg/mozjpeg_node_enc.wasm.d.ts +0 -1
- package/dist/assets/services/vendor/squoosh/png/squoosh_oxipng_bg.wasm.d.ts +0 -1
- package/dist/assets/services/vendor/squoosh/png/squoosh_png_bg.wasm.d.ts +0 -1
- package/dist/assets/services/vendor/squoosh/resize/squoosh_resize_bg.wasm.d.ts +0 -1
- package/dist/assets/services/vendor/squoosh/rotate/rotate.wasm.d.ts +0 -1
- package/dist/assets/services/vendor/squoosh/utils/workerPool.d.ts +0 -1
- package/dist/assets/services/vendor/squoosh/webp/webp_node_dec.wasm.d.ts +0 -1
- package/dist/assets/services/vendor/squoosh/webp/webp_node_enc.wasm.d.ts +0 -1
- package/dist/assets/types.d.ts +8 -2
- package/dist/assets/types.js +7 -0
- package/dist/cli/add/babel.d.ts +6 -6
- package/dist/config/index.d.ts +1 -1
- package/dist/config/vite-plugin-content-listen.d.ts +0 -1
- package/dist/container/pipeline.d.ts +0 -1
- package/dist/container/pipeline.js +13 -32
- package/dist/content/runtime-assets.d.ts +3 -3
- package/dist/content/server-listeners.d.ts +0 -1
- package/dist/content/types-generator.d.ts +1 -2
- package/dist/content/types-generator.js +27 -6
- package/dist/content/utils.d.ts +0 -1
- package/dist/content/vite-plugin-content-imports.d.ts +0 -1
- package/dist/content/vite-plugin-content-virtual-mod.d.ts +0 -1
- package/dist/core/app/createOutgoingHttpHeaders.d.ts +0 -1
- package/dist/core/app/index.d.ts +4 -0
- package/dist/core/app/index.js +17 -6
- package/dist/core/app/node.d.ts +0 -1
- 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/build/pipeline.d.ts +1 -2
- package/dist/core/build/pipeline.js +16 -42
- package/dist/core/build/plugins/plugin-analyzer.js +14 -12
- package/dist/core/config/config.d.ts +0 -1
- package/dist/core/config/schema.d.ts +0 -2
- package/dist/core/config/vite-load.d.ts +0 -1
- package/dist/core/constants.js +1 -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 +3 -2
- package/dist/core/create-vite.d.ts +0 -1
- package/dist/core/create-vite.js +0 -4
- package/dist/core/dev/container.d.ts +0 -3
- package/dist/core/dev/dev.d.ts +0 -2
- package/dist/core/dev/dev.js +1 -1
- package/dist/core/dev/restart.d.ts +0 -1
- package/dist/core/errors/errors-data.d.ts +21 -12
- package/dist/core/errors/errors-data.js +7 -6
- package/dist/core/messages.js +2 -2
- package/dist/core/module-loader/loader.d.ts +0 -1
- package/dist/core/preview/static-preview-server.d.ts +0 -1
- package/dist/core/render-context.d.ts +1 -1
- package/dist/core/render-context.js +20 -6
- package/dist/core/request.d.ts +0 -1
- package/dist/core/request.js +7 -1
- package/dist/core/routing/manifest/create.d.ts +0 -1
- package/dist/core/routing/rewrite.d.ts +10 -0
- package/dist/core/routing/rewrite.js +41 -0
- package/dist/env/vite-plugin-env.d.ts +0 -1
- package/dist/integrations/hooks.d.ts +1 -2
- package/dist/jsx/rehype.d.ts +2 -8
- package/dist/runtime/client/dev-toolbar/helpers.d.ts +1 -1
- package/dist/runtime/client/dev-toolbar/settings.d.ts +1 -1
- package/dist/runtime/server/render/page.js +11 -2
- package/dist/transitions/events.d.ts +0 -1
- package/dist/transitions/router.js +6 -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/plugin.d.ts +0 -1
- package/dist/vite-plugin-astro-server/request.d.ts +0 -1
- package/dist/vite-plugin-astro-server/request.js +1 -1
- package/dist/vite-plugin-astro-server/response.d.ts +0 -1
- package/dist/vite-plugin-astro-server/route.d.ts +0 -1
- package/dist/vite-plugin-astro-server/route.js +39 -97
- package/dist/vite-plugin-inject-env-ts/index.d.ts +0 -1
- package/dist/vite-plugin-load-fallback/index.d.ts +0 -1
- package/package.json +12 -11
package/components/Code.astro
CHANGED
|
@@ -3,6 +3,7 @@ import type { ThemePresets } from '@astrojs/markdown-remark';
|
|
|
3
3
|
import type {
|
|
4
4
|
BuiltinLanguage,
|
|
5
5
|
LanguageRegistration,
|
|
6
|
+
ShikiTransformer,
|
|
6
7
|
SpecialLanguage,
|
|
7
8
|
ThemeRegistration,
|
|
8
9
|
ThemeRegistrationRaw,
|
|
@@ -50,6 +51,12 @@ interface Props extends Omit<HTMLAttributes<'pre'>, 'lang'> {
|
|
|
50
51
|
* @default false
|
|
51
52
|
*/
|
|
52
53
|
inline?: boolean;
|
|
54
|
+
/**
|
|
55
|
+
* Shiki transformers to customize the generated HTML by manipulating the hast tree.
|
|
56
|
+
* Supports all transformers listed here: https://shiki.style/packages/transformers#transformers
|
|
57
|
+
* Instructions for custom transformers: https://shiki.style/guide/transformers
|
|
58
|
+
*/
|
|
59
|
+
transformers?: ShikiTransformer[];
|
|
53
60
|
}
|
|
54
61
|
|
|
55
62
|
const {
|
|
@@ -59,6 +66,7 @@ const {
|
|
|
59
66
|
themes = {},
|
|
60
67
|
wrap = false,
|
|
61
68
|
inline = false,
|
|
69
|
+
transformers = [],
|
|
62
70
|
...rest
|
|
63
71
|
} = Astro.props;
|
|
64
72
|
|
|
@@ -85,6 +93,7 @@ const highlighter = await getCachedHighlighter({
|
|
|
85
93
|
theme,
|
|
86
94
|
themes,
|
|
87
95
|
wrap,
|
|
96
|
+
transformers,
|
|
88
97
|
});
|
|
89
98
|
|
|
90
99
|
const html = await highlighter.highlight(code, typeof lang === 'string' ? lang : lang.name, {
|
package/dist/@types/astro.d.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
-
/// <reference types="node" resolution-mode="require"/>
|
|
3
1
|
import type { OutgoingHttpHeaders } from 'node:http';
|
|
4
2
|
import type { AddressInfo } from 'node:net';
|
|
5
3
|
import type { MarkdownHeading, MarkdownVFile, RehypePlugins, RemarkPlugins, RemarkRehype, ShikiConfig } from '@astrojs/markdown-remark';
|
|
@@ -14,7 +14,7 @@ export type ActionClient<TOutput, TAccept extends Accept, TInputSchema extends I
|
|
|
14
14
|
} : ((input?: any) => Promise<Awaited<TOutput>>) & {
|
|
15
15
|
safe: (input?: any) => Promise<SafeResult<never, Awaited<TOutput>>>;
|
|
16
16
|
};
|
|
17
|
-
export declare function defineAction<TOutput, TAccept extends Accept
|
|
17
|
+
export declare function defineAction<TOutput, TAccept extends Accept, TInputSchema extends InputSchema<Accept> | undefined = TAccept extends 'form' ? z.ZodType<FormData> : undefined>({ accept, input: inputSchema, handler, }: {
|
|
18
18
|
input?: TInputSchema;
|
|
19
19
|
accept?: TAccept;
|
|
20
20
|
handler: Handler<TInputSchema, TOutput>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { AstroConfig } from '../@types/astro.js';
|
|
2
2
|
import { type ImageService } from './services/service.js';
|
|
3
|
-
import type
|
|
3
|
+
import { type GetImageResult, type UnresolvedImageTransform } from './types.js';
|
|
4
4
|
export declare function getConfiguredImageService(): Promise<ImageService>;
|
|
5
5
|
export declare function getImage(options: UnresolvedImageTransform, imageConfig: AstroConfig['image']): Promise<GetImageResult>;
|
package/dist/assets/internal.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { AstroError, AstroErrorData } from "../core/errors/index.js";
|
|
2
2
|
import { DEFAULT_HASH_PROPS } from "./consts.js";
|
|
3
3
|
import { isLocalService } from "./services/service.js";
|
|
4
|
+
import {
|
|
5
|
+
isImageMetadata
|
|
6
|
+
} from "./types.js";
|
|
4
7
|
import { isESMImportedImage, isRemoteImage, resolveSrc } from "./utils/imageKind.js";
|
|
5
8
|
import { probe } from "./utils/remoteProbe.js";
|
|
6
9
|
async function getConfiguredImageService() {
|
|
@@ -36,6 +39,9 @@ async function getImage(options, imageConfig) {
|
|
|
36
39
|
)
|
|
37
40
|
});
|
|
38
41
|
}
|
|
42
|
+
if (isImageMetadata(options)) {
|
|
43
|
+
throw new AstroError(AstroErrorData.ExpectedNotESMImage);
|
|
44
|
+
}
|
|
39
45
|
const service = await getConfiguredImageService();
|
|
40
46
|
const resolvedOptions = {
|
|
41
47
|
...options,
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="node" resolution-mode="require"/>
|
|
2
1
|
import ImageData from './image_data.js';
|
|
3
2
|
export declare function decodeBuffer(_buffer: Buffer | Uint8Array): Promise<ImageData>;
|
|
4
3
|
export declare function rotate(image: ImageData, numRotations: number): Promise<ImageData>;
|
package/dist/assets/types.d.ts
CHANGED
|
@@ -20,16 +20,20 @@ declare global {
|
|
|
20
20
|
referencedImages?: Set<string>;
|
|
21
21
|
};
|
|
22
22
|
}
|
|
23
|
+
declare const isESMImport: unique symbol;
|
|
24
|
+
export type OmitBrand<T> = Omit<T, typeof isESMImport>;
|
|
23
25
|
/**
|
|
24
26
|
* Type returned by ESM imports of images
|
|
25
27
|
*/
|
|
26
|
-
export
|
|
28
|
+
export type ImageMetadata = {
|
|
27
29
|
src: string;
|
|
28
30
|
width: number;
|
|
29
31
|
height: number;
|
|
30
32
|
format: ImageInputFormat;
|
|
31
33
|
orientation?: number;
|
|
32
|
-
|
|
34
|
+
[isESMImport]?: true;
|
|
35
|
+
};
|
|
36
|
+
export declare function isImageMetadata(src: any): src is ImageMetadata;
|
|
33
37
|
/**
|
|
34
38
|
* A yet to be completed with an url `SrcSetValue`. Other hooks will only see a resolved value, where the URL of the image has been added.
|
|
35
39
|
*/
|
|
@@ -49,6 +53,8 @@ export type UnresolvedImageTransform = Omit<ImageTransform, 'src'> & {
|
|
|
49
53
|
default: ImageMetadata;
|
|
50
54
|
}>;
|
|
51
55
|
inferSize?: boolean;
|
|
56
|
+
} & {
|
|
57
|
+
[isESMImport]?: never;
|
|
52
58
|
};
|
|
53
59
|
/**
|
|
54
60
|
* Options accepted by the image transformation service.
|
package/dist/assets/types.js
CHANGED
package/dist/cli/add/babel.d.ts
CHANGED
|
@@ -2,16 +2,16 @@ import parser from '@babel/parser';
|
|
|
2
2
|
import traverse from '@babel/traverse';
|
|
3
3
|
import * as t from '@babel/types';
|
|
4
4
|
export declare const visit: {
|
|
5
|
-
<S>(parent: traverse.Node, opts: traverse.TraverseOptions<S>, scope: traverse.Scope | undefined, state: S, parentPath?: traverse.NodePath
|
|
6
|
-
(parent: traverse.Node, opts?: traverse.TraverseOptions
|
|
5
|
+
<S>(parent: traverse.Node, opts: traverse.TraverseOptions<S>, scope: traverse.Scope | undefined, state: S, parentPath?: traverse.NodePath): void;
|
|
6
|
+
(parent: traverse.Node, opts?: traverse.TraverseOptions, scope?: traverse.Scope, state?: any, parentPath?: traverse.NodePath): void;
|
|
7
7
|
visitors: typeof traverse.visitors;
|
|
8
8
|
verify: typeof traverse.visitors.verify;
|
|
9
9
|
explode: typeof traverse.visitors.explode;
|
|
10
10
|
cheap: (node: traverse.Node, enter: (node: traverse.Node) => void) => void;
|
|
11
|
-
node: (node: traverse.Node, opts: traverse.TraverseOptions
|
|
12
|
-
clearNode: (node: traverse.Node, opts?: traverse.RemovePropertiesOptions
|
|
13
|
-
removeProperties: (tree: traverse.Node, opts?: traverse.RemovePropertiesOptions
|
|
14
|
-
hasType: (tree: traverse.Node, type: "
|
|
11
|
+
node: (node: traverse.Node, opts: traverse.TraverseOptions, scope?: traverse.Scope, state?: any, path?: traverse.NodePath, skipKeys?: Record<string, boolean>) => void;
|
|
12
|
+
clearNode: (node: traverse.Node, opts?: traverse.RemovePropertiesOptions) => void;
|
|
13
|
+
removeProperties: (tree: traverse.Node, opts?: traverse.RemovePropertiesOptions) => traverse.Node;
|
|
14
|
+
hasType: (tree: traverse.Node, type: traverse.Node["type"], denylistTypes?: string[]) => boolean;
|
|
15
15
|
cache: typeof traverse.cache;
|
|
16
16
|
};
|
|
17
17
|
export { t };
|
package/dist/config/index.d.ts
CHANGED
|
@@ -3,5 +3,5 @@ import type { AstroInlineConfig, AstroUserConfig } from '../@types/astro.js';
|
|
|
3
3
|
export declare function defineConfig(config: AstroUserConfig): AstroUserConfig;
|
|
4
4
|
export declare function getViteConfig(userViteConfig: ViteUserConfig, inlineAstroConfig?: AstroInlineConfig): ({ mode, command }: {
|
|
5
5
|
mode: string;
|
|
6
|
-
command:
|
|
6
|
+
command: "serve" | "build";
|
|
7
7
|
}) => Promise<Record<string, any>>;
|
|
@@ -8,5 +8,4 @@ export declare class ContainerPipeline extends Pipeline {
|
|
|
8
8
|
tryRewrite(payload: RewritePayload, request: Request): Promise<[RouteData, ComponentInstance, URL]>;
|
|
9
9
|
insertRoute(route: RouteData, componentInstance: ComponentInstance): void;
|
|
10
10
|
getComponentByRoute(_routeData: RouteData): Promise<ComponentInstance>;
|
|
11
|
-
rewriteKnownRoute(pathname: string, _sourceRoute: RouteData): ComponentInstance;
|
|
12
11
|
}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { Pipeline } from "../core/base-pipeline.js";
|
|
2
|
-
import {
|
|
2
|
+
import { RouteNotFound } from "../core/errors/errors-data.js";
|
|
3
3
|
import { AstroError } from "../core/errors/index.js";
|
|
4
4
|
import {
|
|
5
5
|
createModuleScriptElement,
|
|
6
6
|
createStylesheetElementSet
|
|
7
7
|
} from "../core/render/ssr-element.js";
|
|
8
|
-
import { DEFAULT_404_ROUTE
|
|
8
|
+
import { DEFAULT_404_ROUTE } from "../core/routing/astro-designed-error-pages.js";
|
|
9
|
+
import { findRouteToRewrite } from "../core/routing/rewrite.js";
|
|
9
10
|
class ContainerPipeline extends Pipeline {
|
|
10
11
|
/**
|
|
11
12
|
* Internal cache to store components instances by `RouteData`.
|
|
@@ -52,30 +53,16 @@ class ContainerPipeline extends Pipeline {
|
|
|
52
53
|
return { links, styles, scripts };
|
|
53
54
|
}
|
|
54
55
|
async tryRewrite(payload, request) {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
if (route.routeData.pattern.test(decodeURI(finalUrl.pathname))) {
|
|
66
|
-
foundRoute = route.routeData;
|
|
67
|
-
break;
|
|
68
|
-
} else if (finalUrl.pathname === "/404") {
|
|
69
|
-
foundRoute = DEFAULT_404_ROUTE;
|
|
70
|
-
break;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
if (foundRoute && finalUrl) {
|
|
74
|
-
const componentInstance = await this.getComponentByRoute(foundRoute);
|
|
75
|
-
return [foundRoute, componentInstance, finalUrl];
|
|
76
|
-
} else {
|
|
77
|
-
throw new AstroError(RouteNotFound);
|
|
78
|
-
}
|
|
56
|
+
const [foundRoute, finalUrl] = findRouteToRewrite({
|
|
57
|
+
payload,
|
|
58
|
+
request,
|
|
59
|
+
routes: this.manifest?.routes.map((r) => r.routeData),
|
|
60
|
+
trailingSlash: this.manifest.trailingSlash,
|
|
61
|
+
buildFormat: this.manifest.buildFormat,
|
|
62
|
+
base: this.manifest.base
|
|
63
|
+
});
|
|
64
|
+
const componentInstance = await this.getComponentByRoute(foundRoute);
|
|
65
|
+
return [foundRoute, componentInstance, finalUrl];
|
|
79
66
|
}
|
|
80
67
|
insertRoute(route, componentInstance) {
|
|
81
68
|
this.#componentsInterner.set(route, {
|
|
@@ -90,12 +77,6 @@ class ContainerPipeline extends Pipeline {
|
|
|
90
77
|
// @ts-expect-error It needs to be implemented.
|
|
91
78
|
async getComponentByRoute(_routeData) {
|
|
92
79
|
}
|
|
93
|
-
rewriteKnownRoute(pathname, _sourceRoute) {
|
|
94
|
-
if (pathname === "/404") {
|
|
95
|
-
return { default: default404Page };
|
|
96
|
-
}
|
|
97
|
-
throw new AstroError(InvalidRewrite404);
|
|
98
|
-
}
|
|
99
80
|
}
|
|
100
81
|
export {
|
|
101
82
|
ContainerPipeline
|
|
@@ -2,10 +2,10 @@ import type { PluginContext } from 'rollup';
|
|
|
2
2
|
import { z } from 'zod';
|
|
3
3
|
export declare function createImage(pluginContext: PluginContext, shouldEmitFile: boolean, entryFilePath: string): () => z.ZodEffects<z.ZodString, z.ZodNever | {
|
|
4
4
|
ASTRO_ASSET: string;
|
|
5
|
-
|
|
5
|
+
format: import("../assets/types.js").ImageInputFormat;
|
|
6
6
|
width: number;
|
|
7
7
|
height: number;
|
|
8
|
-
|
|
9
|
-
orientation?: number | undefined;
|
|
8
|
+
src: string;
|
|
10
9
|
fsPath: string;
|
|
10
|
+
orientation?: number;
|
|
11
11
|
}, string>;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="node" resolution-mode="require"/>
|
|
2
1
|
import type fsMod from 'node:fs';
|
|
3
2
|
import { type ViteDevServer } from 'vite';
|
|
4
3
|
import type { AstroSettings } from '../@types/astro.js';
|
|
@@ -22,7 +21,7 @@ export declare function createContentTypesGenerator({ contentConfigObserver, fs,
|
|
|
22
21
|
typesGenerated: true;
|
|
23
22
|
} | {
|
|
24
23
|
typesGenerated: false;
|
|
25
|
-
reason:
|
|
24
|
+
reason: "no-content-dir";
|
|
26
25
|
}>;
|
|
27
26
|
queueEvent: (rawEvent: RawContentEvent) => void;
|
|
28
27
|
}>;
|
|
@@ -318,13 +318,26 @@ async function writeContentFiles({
|
|
|
318
318
|
// This ensures `getCollection('empty-collection')` doesn't raise a type error
|
|
319
319
|
collectionConfig?.type ?? "data"
|
|
320
320
|
) : collection.type;
|
|
321
|
+
const collectionEntryKeys = Object.keys(collection.entries).sort();
|
|
322
|
+
const dataType = collectionConfig?.schema ? `InferEntrySchema<${collectionKey}>` : "any";
|
|
321
323
|
switch (resolvedType) {
|
|
322
324
|
case "content":
|
|
325
|
+
if (collectionEntryKeys.length === 0) {
|
|
326
|
+
contentTypesStr += `${collectionKey}: Record<string, {
|
|
327
|
+
id: string;
|
|
328
|
+
slug: string;
|
|
329
|
+
body: string;
|
|
330
|
+
collection: ${collectionKey};
|
|
331
|
+
data: ${dataType};
|
|
332
|
+
render(): Render[".md"];
|
|
333
|
+
}>;
|
|
334
|
+
`;
|
|
335
|
+
break;
|
|
336
|
+
}
|
|
323
337
|
contentTypesStr += `${collectionKey}: {
|
|
324
338
|
`;
|
|
325
|
-
for (const entryKey of
|
|
339
|
+
for (const entryKey of collectionEntryKeys) {
|
|
326
340
|
const entryMetadata = collection.entries[entryKey];
|
|
327
|
-
const dataType = collectionConfig?.schema ? `InferEntrySchema<${collectionKey}>` : "any";
|
|
328
341
|
const renderType = `{ render(): Render[${JSON.stringify(
|
|
329
342
|
path.extname(JSON.parse(entryKey))
|
|
330
343
|
)}] }`;
|
|
@@ -342,16 +355,24 @@ async function writeContentFiles({
|
|
|
342
355
|
`;
|
|
343
356
|
break;
|
|
344
357
|
case "data":
|
|
345
|
-
|
|
358
|
+
if (collectionEntryKeys.length === 0) {
|
|
359
|
+
dataTypesStr += `${collectionKey}: Record<string, {
|
|
360
|
+
id: string;
|
|
361
|
+
collection: ${collectionKey};
|
|
362
|
+
data: ${dataType};
|
|
363
|
+
}>;
|
|
346
364
|
`;
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
365
|
+
} else {
|
|
366
|
+
dataTypesStr += `${collectionKey}: {
|
|
367
|
+
`;
|
|
368
|
+
for (const entryKey of collectionEntryKeys) {
|
|
369
|
+
dataTypesStr += `${entryKey}: {
|
|
350
370
|
id: ${entryKey};
|
|
351
371
|
collection: ${collectionKey};
|
|
352
372
|
data: ${dataType}
|
|
353
373
|
};
|
|
354
374
|
`;
|
|
375
|
+
}
|
|
355
376
|
dataTypesStr += `};
|
|
356
377
|
`;
|
|
357
378
|
}
|
package/dist/content/utils.d.ts
CHANGED
package/dist/core/app/index.d.ts
CHANGED
|
@@ -39,6 +39,10 @@ export interface RenderErrorOptions {
|
|
|
39
39
|
* Whether to skip middleware while rendering the error page. Defaults to false.
|
|
40
40
|
*/
|
|
41
41
|
skipMiddleware?: boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Allows passing an error to 500.astro. It will be available through `Astro.props.error`.
|
|
44
|
+
*/
|
|
45
|
+
error?: unknown;
|
|
42
46
|
}
|
|
43
47
|
export declare class App {
|
|
44
48
|
#private;
|
package/dist/core/app/index.js
CHANGED
|
@@ -195,8 +195,9 @@ class App {
|
|
|
195
195
|
}
|
|
196
196
|
if (locals) {
|
|
197
197
|
if (typeof locals !== "object") {
|
|
198
|
-
|
|
199
|
-
|
|
198
|
+
const error = new AstroError(AstroErrorData.LocalsNotAnObject);
|
|
199
|
+
this.#logger.error(null, error.stack);
|
|
200
|
+
return this.#renderError(request, { status: 500, error });
|
|
200
201
|
}
|
|
201
202
|
Reflect.set(request, clientLocalsSymbol, locals);
|
|
202
203
|
}
|
|
@@ -229,13 +230,16 @@ class App {
|
|
|
229
230
|
response = await renderContext.render(await mod.page());
|
|
230
231
|
} catch (err) {
|
|
231
232
|
this.#logger.error(null, err.stack || err.message || String(err));
|
|
232
|
-
return this.#renderError(request, { locals, status: 500 });
|
|
233
|
+
return this.#renderError(request, { locals, status: 500, error: err });
|
|
233
234
|
}
|
|
234
235
|
if (REROUTABLE_STATUS_CODES.includes(response.status) && response.headers.get(REROUTE_DIRECTIVE_HEADER) !== "no") {
|
|
235
236
|
return this.#renderError(request, {
|
|
236
237
|
locals,
|
|
237
238
|
response,
|
|
238
|
-
status: response.status
|
|
239
|
+
status: response.status,
|
|
240
|
+
// We don't have an error to report here. Passing null means we pass nothing intentionally
|
|
241
|
+
// while undefined means there's no error
|
|
242
|
+
error: response.status === 500 ? null : void 0
|
|
239
243
|
});
|
|
240
244
|
}
|
|
241
245
|
if (response.headers.has(REROUTE_DIRECTIVE_HEADER)) {
|
|
@@ -276,7 +280,13 @@ class App {
|
|
|
276
280
|
* If it is a known error code, try sending the according page (e.g. 404.astro / 500.astro).
|
|
277
281
|
* This also handles pre-rendered /404 or /500 routes
|
|
278
282
|
*/
|
|
279
|
-
async #renderError(request, {
|
|
283
|
+
async #renderError(request, {
|
|
284
|
+
locals,
|
|
285
|
+
status,
|
|
286
|
+
response: originalResponse,
|
|
287
|
+
skipMiddleware = false,
|
|
288
|
+
error
|
|
289
|
+
}) {
|
|
280
290
|
const errorRoutePath = `/${status}${this.#manifest.trailingSlash === "always" ? "/" : ""}`;
|
|
281
291
|
const errorRouteData = matchRoute(errorRoutePath, this.#manifestData);
|
|
282
292
|
const url = new URL(request.url);
|
|
@@ -300,7 +310,8 @@ class App {
|
|
|
300
310
|
pathname: this.#getPathnameFromRequest(request),
|
|
301
311
|
request,
|
|
302
312
|
routeData: errorRouteData,
|
|
303
|
-
status
|
|
313
|
+
status,
|
|
314
|
+
props: { error }
|
|
304
315
|
});
|
|
305
316
|
const response2 = await renderContext.render(await mod.page());
|
|
306
317
|
return this.#mergeResponses(response2, originalResponse);
|
package/dist/core/app/node.d.ts
CHANGED
|
@@ -7,7 +7,6 @@ export declare class AppPipeline extends Pipeline {
|
|
|
7
7
|
headElements(routeData: RouteData): Pick<SSRResult, 'scripts' | 'styles' | 'links'>;
|
|
8
8
|
componentMetadata(): void;
|
|
9
9
|
getComponentByRoute(routeData: RouteData): Promise<ComponentInstance>;
|
|
10
|
-
tryRewrite(payload: RewritePayload, request: Request,
|
|
10
|
+
tryRewrite(payload: RewritePayload, request: Request, _sourceRoute: RouteData): Promise<[RouteData, ComponentInstance, URL]>;
|
|
11
11
|
getModuleForRoute(route: RouteData): Promise<SinglePageBuiltModule>;
|
|
12
|
-
rewriteKnownRoute(pathname: string, _sourceRoute: RouteData): ComponentInstance;
|
|
13
12
|
}
|
|
@@ -5,6 +5,7 @@ import { AstroError } from "../errors/index.js";
|
|
|
5
5
|
import { RedirectSinglePageBuiltModule } from "../redirects/component.js";
|
|
6
6
|
import { createModuleScriptElement, createStylesheetElementSet } from "../render/ssr-element.js";
|
|
7
7
|
import { DEFAULT_404_ROUTE } from "../routing/astro-designed-error-pages.js";
|
|
8
|
+
import { findRouteToRewrite } from "../routing/rewrite.js";
|
|
8
9
|
class AppPipeline extends Pipeline {
|
|
9
10
|
#manifestData;
|
|
10
11
|
static create(manifestData, {
|
|
@@ -62,38 +63,17 @@ class AppPipeline extends Pipeline {
|
|
|
62
63
|
const module = await this.getModuleForRoute(routeData);
|
|
63
64
|
return module.page();
|
|
64
65
|
}
|
|
65
|
-
async tryRewrite(payload, request,
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
} else {
|
|
74
|
-
finalUrl = new URL(payload, new URL(request.url).origin);
|
|
75
|
-
}
|
|
76
|
-
if (route.pattern.test(decodeURI(finalUrl.pathname))) {
|
|
77
|
-
foundRoute = route;
|
|
78
|
-
break;
|
|
79
|
-
} else if (finalUrl.pathname === "/404") {
|
|
80
|
-
foundRoute = DEFAULT_404_ROUTE;
|
|
81
|
-
break;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
if (foundRoute && finalUrl) {
|
|
85
|
-
if (foundRoute.pathname === "/404") {
|
|
86
|
-
const componentInstance = this.rewriteKnownRoute(foundRoute.pathname, sourceRoute);
|
|
87
|
-
return [foundRoute, componentInstance, finalUrl];
|
|
88
|
-
} else {
|
|
89
|
-
const componentInstance = await this.getComponentByRoute(foundRoute);
|
|
90
|
-
return [foundRoute, componentInstance, finalUrl];
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
throw new AstroError({
|
|
94
|
-
...RewriteEncounteredAnError,
|
|
95
|
-
message: RewriteEncounteredAnError.message(payload.toString())
|
|
66
|
+
async tryRewrite(payload, request, _sourceRoute) {
|
|
67
|
+
const [foundRoute, finalUrl] = findRouteToRewrite({
|
|
68
|
+
payload,
|
|
69
|
+
request,
|
|
70
|
+
routes: this.manifest?.routes.map((r) => r.routeData),
|
|
71
|
+
trailingSlash: this.manifest.trailingSlash,
|
|
72
|
+
buildFormat: this.manifest.buildFormat,
|
|
73
|
+
base: this.manifest.base
|
|
96
74
|
});
|
|
75
|
+
const componentInstance = await this.getComponentByRoute(foundRoute);
|
|
76
|
+
return [foundRoute, componentInstance, finalUrl];
|
|
97
77
|
}
|
|
98
78
|
async getModuleForRoute(route) {
|
|
99
79
|
if (route.component === DEFAULT_404_COMPONENT) {
|
|
@@ -121,14 +101,6 @@ class AppPipeline extends Pipeline {
|
|
|
121
101
|
);
|
|
122
102
|
}
|
|
123
103
|
}
|
|
124
|
-
// We don't need to check the source route, we already are in SSR
|
|
125
|
-
rewriteKnownRoute(pathname, _sourceRoute) {
|
|
126
|
-
if (pathname === "/404") {
|
|
127
|
-
return { default: () => new Response(null, { status: 404 }) };
|
|
128
|
-
} else {
|
|
129
|
-
return { default: () => new Response(null, { status: 500 }) };
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
104
|
}
|
|
133
105
|
export {
|
|
134
106
|
AppPipeline
|