astro 4.10.1 → 4.10.3
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 +43 -39
- package/dist/config/index.d.ts +2 -2
- package/dist/config/index.js +4 -4
- package/dist/container/index.d.ts +32 -1
- package/dist/container/index.js +45 -0
- package/dist/container/pipeline.d.ts +1 -1
- package/dist/container/pipeline.js +17 -18
- package/dist/container/vite-plugin-container.d.ts +2 -0
- package/dist/container/vite-plugin-container.js +15 -0
- package/dist/content/runtime.js +2 -2
- package/dist/content/types-generator.js +30 -32
- 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.js +0 -4
- package/dist/core/app/pipeline.d.ts +1 -1
- package/dist/core/app/pipeline.js +4 -4
- package/dist/core/base-pipeline.d.ts +1 -1
- package/dist/core/base-pipeline.js +1 -1
- package/dist/core/build/generate.js +2 -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 -1
- package/dist/core/build/pipeline.js +4 -4
- 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 +422 -78
- package/dist/core/constants.d.ts +4 -0
- package/dist/core/constants.js +3 -1
- package/dist/core/create-vite.js +4 -2
- package/dist/core/dev/dev.js +1 -1
- package/dist/core/errors/errors-data.d.ts +31 -0
- package/dist/core/errors/errors-data.js +12 -0
- package/dist/core/messages.js +2 -2
- package/dist/core/render-context.d.ts +1 -1
- package/dist/core/render-context.js +28 -22
- 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/params.js +1 -1
- package/dist/core/util.js +5 -2
- package/dist/env/config.d.ts +2 -1
- package/dist/env/config.js +4 -0
- 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 +198 -220
- package/dist/env/schema.js +47 -79
- package/dist/env/validators.js +73 -10
- package/dist/env/vite-plugin-env.js +15 -15
- package/dist/i18n/index.d.ts +1 -1
- package/dist/i18n/index.js +4 -11
- package/dist/jsx/server.d.ts +3 -5
- package/dist/jsx/server.js +3 -1
- package/dist/runtime/server/render/astro/render.js +8 -2
- package/dist/vite-plugin-astro/index.js +1 -1
- package/dist/vite-plugin-astro-server/pipeline.d.ts +1 -1
- package/dist/vite-plugin-astro-server/pipeline.js +4 -4
- package/dist/vite-plugin-astro-server/request.js +2 -2
- package/dist/vite-plugin-astro-server/route.js +18 -1
- package/package.json +16 -16
- package/templates/env/module.mjs +14 -5
- package/templates/env/types.d.ts +1 -12
package/dist/@types/astro.d.ts
CHANGED
|
@@ -211,7 +211,7 @@ export interface AstroGlobal<Props extends Record<string, any> = Record<string,
|
|
|
211
211
|
/**
|
|
212
212
|
* The <Astro.self /> element allows a component to reference itself recursively.
|
|
213
213
|
*
|
|
214
|
-
* [Astro reference](https://docs.astro.build/en/
|
|
214
|
+
* [Astro reference](https://docs.astro.build/en/reference/api-reference/#astroself)
|
|
215
215
|
*/
|
|
216
216
|
self: Self;
|
|
217
217
|
/** Utility functions for modifying an Astro component’s slotted children
|
|
@@ -1295,7 +1295,7 @@ export interface AstroUserConfig {
|
|
|
1295
1295
|
* import remarkToc from 'remark-toc';
|
|
1296
1296
|
* {
|
|
1297
1297
|
* markdown: {
|
|
1298
|
-
* remarkPlugins: [remarkToc]
|
|
1298
|
+
* remarkPlugins: [ [remarkToc, { heading: "contents"} ] ]
|
|
1299
1299
|
* }
|
|
1300
1300
|
* }
|
|
1301
1301
|
* ```
|
|
@@ -1931,17 +1931,17 @@ export interface AstroUserConfig {
|
|
|
1931
1931
|
*
|
|
1932
1932
|
* ```astro
|
|
1933
1933
|
* ---
|
|
1934
|
-
* import {
|
|
1935
|
-
* import {
|
|
1936
|
-
* const
|
|
1934
|
+
* import { APP_ID } from "astro:env/client"
|
|
1935
|
+
* import { API_URL, API_TOKEN, getSecret } from "astro:env/server"
|
|
1936
|
+
* const NODE_ENV = getSecret("NODE_ENV")
|
|
1937
1937
|
*
|
|
1938
|
-
* const data = await fetch(`${
|
|
1938
|
+
* const data = await fetch(`${API_URL}/users`, {
|
|
1939
1939
|
* method: "POST",
|
|
1940
1940
|
* headers: {
|
|
1941
1941
|
* "Content-Type": "application/json",
|
|
1942
1942
|
* "Authorization": `Bearer ${API_TOKEN}`
|
|
1943
1943
|
* },
|
|
1944
|
-
* body: JSON.stringify({ appId:
|
|
1944
|
+
* body: JSON.stringify({ appId: APP_ID, nodeEnv: NODE_ENV })
|
|
1945
1945
|
* })
|
|
1946
1946
|
* ---
|
|
1947
1947
|
* ```
|
|
@@ -1956,8 +1956,8 @@ export interface AstroUserConfig {
|
|
|
1956
1956
|
* experimental: {
|
|
1957
1957
|
* env: {
|
|
1958
1958
|
* schema: {
|
|
1959
|
-
*
|
|
1960
|
-
*
|
|
1959
|
+
* API_URL: envField.string({ context: "client", access: "public", optional: true }),
|
|
1960
|
+
* PORT: envField.number({ context: "server", access: "public", default: 4321 }),
|
|
1961
1961
|
* API_SECRET: envField.string({ context: "server", access: "secret" }),
|
|
1962
1962
|
* }
|
|
1963
1963
|
* }
|
|
@@ -1965,28 +1965,27 @@ export interface AstroUserConfig {
|
|
|
1965
1965
|
* })
|
|
1966
1966
|
* ```
|
|
1967
1967
|
*
|
|
1968
|
-
* There are currently
|
|
1968
|
+
* There are currently four data types supported: strings, numbers, booleans and enums.
|
|
1969
1969
|
*
|
|
1970
1970
|
* There are three kinds of environment variables, determined by the combination of `context` (client or server) and `access` (secret or public) settings defined in your [`env.schema`](#experimentalenvschema):
|
|
1971
1971
|
*
|
|
1972
1972
|
* - **Public client variables**: These variables end up in both your final client and server bundles, and can be accessed from both client and server through the `astro:env/client` module:
|
|
1973
1973
|
*
|
|
1974
1974
|
* ```js
|
|
1975
|
-
* import {
|
|
1975
|
+
* import { API_URL } from "astro:env/client"
|
|
1976
1976
|
* ```
|
|
1977
1977
|
*
|
|
1978
1978
|
* - **Public server variables**: These variables end up in your final server bundle and can be accessed on the server through the `astro:env/server` module:
|
|
1979
1979
|
*
|
|
1980
1980
|
* ```js
|
|
1981
|
-
* import {
|
|
1981
|
+
* import { PORT } from "astro:env/server"
|
|
1982
1982
|
* ```
|
|
1983
1983
|
*
|
|
1984
|
-
* - **Secret server variables**: These variables are not part of your final bundle and can be accessed on the server through the `getSecret()` helper function
|
|
1984
|
+
* - **Secret server variables**: These variables are not part of your final bundle and can be accessed on the server through the `astro:env/server` module. The `getSecret()` helper function can be used to retrieve secrets not specified in the schema:
|
|
1985
1985
|
*
|
|
1986
1986
|
* ```js
|
|
1987
|
-
* import { getSecret } from "astro:env/server"
|
|
1987
|
+
* import { API_SECRET, getSecret } from "astro:env/server"
|
|
1988
1988
|
*
|
|
1989
|
-
* const API_SECRET = getSecret("API_SECRET") // typed
|
|
1990
1989
|
* const SECRET_NOT_IN_SCHEMA = getSecret("SECRET_NOT_IN_SCHEMA") // string | undefined
|
|
1991
1990
|
* ```
|
|
1992
1991
|
*
|
|
@@ -2013,8 +2012,8 @@ export interface AstroUserConfig {
|
|
|
2013
2012
|
* experimental: {
|
|
2014
2013
|
* env: {
|
|
2015
2014
|
* schema: {
|
|
2016
|
-
*
|
|
2017
|
-
*
|
|
2015
|
+
* API_URL: envField.string({ context: "client", access: "public", optional: true }),
|
|
2016
|
+
* PORT: envField.number({ context: "server", access: "public", default: 4321 }),
|
|
2018
2017
|
* API_SECRET: envField.string({ context: "server", access: "secret" }),
|
|
2019
2018
|
* }
|
|
2020
2019
|
* }
|
|
@@ -2604,7 +2603,7 @@ export interface APIContext<Props extends Record<string, any> = Record<string, a
|
|
|
2604
2603
|
* }
|
|
2605
2604
|
* ```
|
|
2606
2605
|
*
|
|
2607
|
-
* [Reference](https://docs.astro.build/en/
|
|
2606
|
+
* [Reference](https://docs.astro.build/en/reference/api-reference/#contextprops)
|
|
2608
2607
|
*/
|
|
2609
2608
|
props: AstroSharedContext<Props, APIParams>['props'];
|
|
2610
2609
|
/**
|
|
@@ -2711,27 +2710,32 @@ export interface AstroRenderer {
|
|
|
2711
2710
|
/** @deprecated Vite plugins should transform the JSX instead */
|
|
2712
2711
|
jsxTransformOptions?: JSXTransformFn;
|
|
2713
2712
|
}
|
|
2714
|
-
export interface
|
|
2715
|
-
|
|
2716
|
-
|
|
2717
|
-
|
|
2718
|
-
|
|
2719
|
-
|
|
2720
|
-
|
|
2721
|
-
|
|
2722
|
-
|
|
2723
|
-
|
|
2724
|
-
|
|
2725
|
-
|
|
2726
|
-
|
|
2727
|
-
|
|
2728
|
-
|
|
2729
|
-
|
|
2730
|
-
|
|
2731
|
-
|
|
2732
|
-
|
|
2733
|
-
|
|
2734
|
-
|
|
2713
|
+
export interface NamedSSRLoadedRendererValue extends SSRLoadedRendererValue {
|
|
2714
|
+
name: string;
|
|
2715
|
+
}
|
|
2716
|
+
export interface SSRLoadedRendererValue {
|
|
2717
|
+
name?: string;
|
|
2718
|
+
check: AsyncRendererComponentFn<boolean>;
|
|
2719
|
+
renderToStaticMarkup: AsyncRendererComponentFn<{
|
|
2720
|
+
html: string;
|
|
2721
|
+
attrs?: Record<string, string>;
|
|
2722
|
+
}>;
|
|
2723
|
+
supportsAstroStaticSlot?: boolean;
|
|
2724
|
+
/**
|
|
2725
|
+
* If provided, Astro will call this function and inject the returned
|
|
2726
|
+
* script in the HTML before the first component handled by this renderer.
|
|
2727
|
+
*
|
|
2728
|
+
* This feature is needed by some renderers (in particular, by Solid). The
|
|
2729
|
+
* Solid official hydration script sets up a page-level data structure.
|
|
2730
|
+
* It is mainly used to transfer data between the server side render phase
|
|
2731
|
+
* and the browser application state. Solid Components rendered later in
|
|
2732
|
+
* the HTML may inject tiny scripts into the HTML that call into this
|
|
2733
|
+
* page-level data structure.
|
|
2734
|
+
*/
|
|
2735
|
+
renderHydrationScript?: () => string;
|
|
2736
|
+
}
|
|
2737
|
+
export interface SSRLoadedRenderer extends Pick<AstroRenderer, 'name' | 'clientEntrypoint'> {
|
|
2738
|
+
ssr: SSRLoadedRendererValue;
|
|
2735
2739
|
}
|
|
2736
2740
|
export type HookParameters<Hook extends keyof AstroIntegration['hooks'], Fn = AstroIntegration['hooks'][Hook]> = Fn extends (...args: any) => any ? Parameters<Fn>[0] : never;
|
|
2737
2741
|
export interface AstroIntegration {
|
package/dist/config/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { UserConfig } from 'vite';
|
|
1
|
+
import type { UserConfig as ViteUserConfig } from 'vite';
|
|
2
2
|
import type { AstroInlineConfig, AstroUserConfig } from '../@types/astro.js';
|
|
3
3
|
export declare function defineConfig(config: AstroUserConfig): AstroUserConfig;
|
|
4
|
-
export declare function getViteConfig(
|
|
4
|
+
export declare function getViteConfig(userViteConfig: ViteUserConfig, inlineAstroConfig?: AstroInlineConfig): ({ mode, command }: {
|
|
5
5
|
mode: string;
|
|
6
6
|
command: 'serve' | 'build';
|
|
7
7
|
}) => Promise<Record<string, any>>;
|
package/dist/config/index.js
CHANGED
|
@@ -2,7 +2,7 @@ import { Logger } from "../core/logger/core.js";
|
|
|
2
2
|
function defineConfig(config) {
|
|
3
3
|
return config;
|
|
4
4
|
}
|
|
5
|
-
function getViteConfig(
|
|
5
|
+
function getViteConfig(userViteConfig, inlineAstroConfig = {}) {
|
|
6
6
|
return async ({ mode, command }) => {
|
|
7
7
|
const cmd = command === "serve" ? "dev" : command;
|
|
8
8
|
const [
|
|
@@ -26,8 +26,8 @@ function getViteConfig(inlineConfig, inlineAstroConfig = {}) {
|
|
|
26
26
|
dest: nodeLogDestination,
|
|
27
27
|
level: "info"
|
|
28
28
|
});
|
|
29
|
-
const { astroConfig: config
|
|
30
|
-
let settings = await createSettings(config,
|
|
29
|
+
const { astroConfig: config } = await resolveConfig(inlineAstroConfig, cmd);
|
|
30
|
+
let settings = await createSettings(config, userViteConfig.root);
|
|
31
31
|
settings = await runHookConfigSetup({ settings, command: cmd, logger });
|
|
32
32
|
const viteConfig = await createVite(
|
|
33
33
|
{
|
|
@@ -40,7 +40,7 @@ function getViteConfig(inlineConfig, inlineAstroConfig = {}) {
|
|
|
40
40
|
{ settings, logger, mode }
|
|
41
41
|
);
|
|
42
42
|
await runHookConfigDone({ settings, logger });
|
|
43
|
-
return mergeConfig(viteConfig,
|
|
43
|
+
return mergeConfig(viteConfig, userViteConfig);
|
|
44
44
|
};
|
|
45
45
|
}
|
|
46
46
|
export {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AstroUserConfig, Props, RouteType, SSRLoadedRenderer, SSRManifest, SSRResult } from '../@types/astro.js';
|
|
1
|
+
import type { AstroUserConfig, NamedSSRLoadedRendererValue, Props, RouteType, SSRLoadedRenderer, SSRLoadedRendererValue, SSRManifest, SSRResult } from '../@types/astro.js';
|
|
2
2
|
import type { AstroComponentFactory } from '../runtime/server/index.js';
|
|
3
3
|
/**
|
|
4
4
|
* Options to be passed when rendering a route
|
|
@@ -59,6 +59,13 @@ export type ContainerRenderOptions = {
|
|
|
59
59
|
*/
|
|
60
60
|
props?: Props;
|
|
61
61
|
};
|
|
62
|
+
export type AddServerRenderer = {
|
|
63
|
+
renderer: NamedSSRLoadedRendererValue;
|
|
64
|
+
name: never;
|
|
65
|
+
} | {
|
|
66
|
+
renderer: SSRLoadedRendererValue;
|
|
67
|
+
name: string;
|
|
68
|
+
};
|
|
62
69
|
export type AstroContainerUserConfig = Omit<AstroUserConfig, 'integrations' | 'adapter'>;
|
|
63
70
|
/**
|
|
64
71
|
* Options that are used for the entire lifecycle of the current instance of the container.
|
|
@@ -122,6 +129,30 @@ export declare class experimental_AstroContainer {
|
|
|
122
129
|
* @param {AstroContainerOptions=} containerOptions
|
|
123
130
|
*/
|
|
124
131
|
static create(containerOptions?: AstroContainerOptions): Promise<experimental_AstroContainer>;
|
|
132
|
+
/**
|
|
133
|
+
* Use this function to manually add a renderer to the container.
|
|
134
|
+
*
|
|
135
|
+
* This function is preferred when you require to use the container with a renderer in environments such as on-demand pages.
|
|
136
|
+
*
|
|
137
|
+
* ## Example
|
|
138
|
+
*
|
|
139
|
+
* ```js
|
|
140
|
+
* import reactRenderer from "@astrojs/react/server.js";
|
|
141
|
+
* import vueRenderer from "@astrojs/vue/server.js";
|
|
142
|
+
* import customRenderer from "../renderer/customRenderer.js";
|
|
143
|
+
* import { experimental_AstroContainer as AstroContainer } from "astro/container"
|
|
144
|
+
*
|
|
145
|
+
* const container = await AstroContainer.create();
|
|
146
|
+
* container.addServerRenderer(reactRenderer);
|
|
147
|
+
* container.addServerRenderer(vueRenderer);
|
|
148
|
+
* container.addServerRenderer("customRenderer", customRenderer);
|
|
149
|
+
* ```
|
|
150
|
+
*
|
|
151
|
+
* @param options {object}
|
|
152
|
+
* @param options.name The name of the renderer. The name **isn't** arbitrary, and it should match the name of the package.
|
|
153
|
+
* @param options.renderer The server renderer exported by integration.
|
|
154
|
+
*/
|
|
155
|
+
addServerRenderer(options: AddServerRenderer): void;
|
|
125
156
|
private static createFromManifest;
|
|
126
157
|
/**
|
|
127
158
|
* @description
|
package/dist/container/index.js
CHANGED
|
@@ -93,6 +93,48 @@ class experimental_AstroContainer {
|
|
|
93
93
|
resolve
|
|
94
94
|
});
|
|
95
95
|
}
|
|
96
|
+
/**
|
|
97
|
+
* Use this function to manually add a renderer to the container.
|
|
98
|
+
*
|
|
99
|
+
* This function is preferred when you require to use the container with a renderer in environments such as on-demand pages.
|
|
100
|
+
*
|
|
101
|
+
* ## Example
|
|
102
|
+
*
|
|
103
|
+
* ```js
|
|
104
|
+
* import reactRenderer from "@astrojs/react/server.js";
|
|
105
|
+
* import vueRenderer from "@astrojs/vue/server.js";
|
|
106
|
+
* import customRenderer from "../renderer/customRenderer.js";
|
|
107
|
+
* import { experimental_AstroContainer as AstroContainer } from "astro/container"
|
|
108
|
+
*
|
|
109
|
+
* const container = await AstroContainer.create();
|
|
110
|
+
* container.addServerRenderer(reactRenderer);
|
|
111
|
+
* container.addServerRenderer(vueRenderer);
|
|
112
|
+
* container.addServerRenderer("customRenderer", customRenderer);
|
|
113
|
+
* ```
|
|
114
|
+
*
|
|
115
|
+
* @param options {object}
|
|
116
|
+
* @param options.name The name of the renderer. The name **isn't** arbitrary, and it should match the name of the package.
|
|
117
|
+
* @param options.renderer The server renderer exported by integration.
|
|
118
|
+
*/
|
|
119
|
+
addServerRenderer(options) {
|
|
120
|
+
const { renderer, name } = options;
|
|
121
|
+
if (!renderer.check || !renderer.renderToStaticMarkup) {
|
|
122
|
+
throw new Error(
|
|
123
|
+
"The renderer you passed isn't valid. A renderer is usually an object that exposes the `check` and `renderToStaticMarkup` functions.\nUsually, the renderer is exported by a /server.js entrypoint e.g. `import renderer from '@astrojs/react/server.js'`"
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
if (isNamedRenderer(renderer)) {
|
|
127
|
+
this.#pipeline.manifest.renderers.push({
|
|
128
|
+
name: renderer.name,
|
|
129
|
+
ssr: renderer
|
|
130
|
+
});
|
|
131
|
+
} else {
|
|
132
|
+
this.#pipeline.manifest.renderers.push({
|
|
133
|
+
name,
|
|
134
|
+
ssr: renderer
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
}
|
|
96
138
|
// NOTE: we keep this private via TS instead via `#` so it's still available on the surface, so we can play with it.
|
|
97
139
|
// @ematipico: I plan to use it for a possible integration that could help people
|
|
98
140
|
static async createFromManifest(manifest) {
|
|
@@ -234,6 +276,9 @@ class experimental_AstroContainer {
|
|
|
234
276
|
return { default: componentFactory };
|
|
235
277
|
}
|
|
236
278
|
}
|
|
279
|
+
function isNamedRenderer(renderer) {
|
|
280
|
+
return !!renderer?.name;
|
|
281
|
+
}
|
|
237
282
|
export {
|
|
238
283
|
experimental_AstroContainer
|
|
239
284
|
};
|
|
@@ -5,7 +5,7 @@ export declare class ContainerPipeline extends Pipeline {
|
|
|
5
5
|
static create({ logger, manifest, renderers, resolve, serverLike, streaming, }: Pick<ContainerPipeline, 'logger' | 'manifest' | 'renderers' | 'resolve' | 'serverLike' | 'streaming'>): ContainerPipeline;
|
|
6
6
|
componentMetadata(_routeData: RouteData): Promise<SSRResult['componentMetadata']> | void;
|
|
7
7
|
headElements(routeData: RouteData): Promise<HeadElements> | HeadElements;
|
|
8
|
-
tryRewrite(
|
|
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
11
|
rewriteKnownRoute(pathname: string, _sourceRoute: RouteData): ComponentInstance;
|
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
createModuleScriptElement,
|
|
6
6
|
createStylesheetElementSet
|
|
7
7
|
} from "../core/render/ssr-element.js";
|
|
8
|
-
import { default404Page } from "../core/routing/astro-designed-error-pages.js";
|
|
8
|
+
import { DEFAULT_404_ROUTE, default404Page } from "../core/routing/astro-designed-error-pages.js";
|
|
9
9
|
class ContainerPipeline extends Pipeline {
|
|
10
10
|
/**
|
|
11
11
|
* Internal cache to store components instances by `RouteData`.
|
|
@@ -51,29 +51,28 @@ class ContainerPipeline extends Pipeline {
|
|
|
51
51
|
}
|
|
52
52
|
return { links, styles, scripts };
|
|
53
53
|
}
|
|
54
|
-
async tryRewrite(
|
|
54
|
+
async tryRewrite(payload, request) {
|
|
55
55
|
let foundRoute;
|
|
56
|
+
let finalUrl = void 0;
|
|
56
57
|
for (const route of this.manifest.routes) {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
} else if (routeData.pattern.test(decodeURI(rewritePayload))) {
|
|
70
|
-
foundRoute = routeData;
|
|
58
|
+
if (payload instanceof URL) {
|
|
59
|
+
finalUrl = payload;
|
|
60
|
+
} else if (payload instanceof Request) {
|
|
61
|
+
finalUrl = new URL(payload.url);
|
|
62
|
+
} else {
|
|
63
|
+
finalUrl = new URL(payload, new URL(request.url).origin);
|
|
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;
|
|
71
70
|
break;
|
|
72
71
|
}
|
|
73
72
|
}
|
|
74
|
-
if (foundRoute) {
|
|
73
|
+
if (foundRoute && finalUrl) {
|
|
75
74
|
const componentInstance = await this.getComponentByRoute(foundRoute);
|
|
76
|
-
return [foundRoute, componentInstance];
|
|
75
|
+
return [foundRoute, componentInstance, finalUrl];
|
|
77
76
|
} else {
|
|
78
77
|
throw new AstroError(RouteNotFound);
|
|
79
78
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
const virtualModuleId = "astro:container";
|
|
2
|
+
function astroContainer() {
|
|
3
|
+
return {
|
|
4
|
+
name: "astro:container",
|
|
5
|
+
enforce: "pre",
|
|
6
|
+
resolveId(id) {
|
|
7
|
+
if (id === virtualModuleId) {
|
|
8
|
+
return this.resolve("astro/virtual-modules/container.js");
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
export {
|
|
14
|
+
astroContainer as default
|
|
15
|
+
};
|
package/dist/content/runtime.js
CHANGED
|
@@ -55,7 +55,7 @@ function createGetCollection({
|
|
|
55
55
|
);
|
|
56
56
|
let entries = [];
|
|
57
57
|
if (!import.meta.env?.DEV && cacheEntriesByCollection.has(collection)) {
|
|
58
|
-
entries =
|
|
58
|
+
entries = cacheEntriesByCollection.get(collection);
|
|
59
59
|
} else {
|
|
60
60
|
const limit = pLimit(10);
|
|
61
61
|
entries = await Promise.all(
|
|
@@ -88,7 +88,7 @@ function createGetCollection({
|
|
|
88
88
|
if (typeof filter === "function") {
|
|
89
89
|
return entries.filter(filter);
|
|
90
90
|
} else {
|
|
91
|
-
return entries;
|
|
91
|
+
return entries.slice();
|
|
92
92
|
}
|
|
93
93
|
};
|
|
94
94
|
}
|
|
@@ -72,16 +72,14 @@ async function createContentTypesGenerator({
|
|
|
72
72
|
if (!isCollectionEvent) return { shouldGenerateTypes: false };
|
|
73
73
|
switch (event.name) {
|
|
74
74
|
case "addDir":
|
|
75
|
-
collectionEntryMap[
|
|
75
|
+
collectionEntryMap[collectionKey2] = {
|
|
76
76
|
type: "unknown",
|
|
77
77
|
entries: {}
|
|
78
78
|
};
|
|
79
79
|
logger.debug("content", `${cyan(collection2)} collection added`);
|
|
80
80
|
break;
|
|
81
81
|
case "unlinkDir":
|
|
82
|
-
|
|
83
|
-
delete collectionEntryMap[JSON.stringify(collection2)];
|
|
84
|
-
}
|
|
82
|
+
delete collectionEntryMap[collectionKey2];
|
|
85
83
|
break;
|
|
86
84
|
}
|
|
87
85
|
return { shouldGenerateTypes: true };
|
|
@@ -354,36 +352,36 @@ async function writeContentFiles({
|
|
|
354
352
|
data: ${dataType}
|
|
355
353
|
};
|
|
356
354
|
`;
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
)
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
355
|
+
dataTypesStr += `};
|
|
356
|
+
`;
|
|
357
|
+
}
|
|
358
|
+
if (settings.config.experimental.contentCollectionJsonSchema && collectionConfig?.schema) {
|
|
359
|
+
let zodSchemaForJson = typeof collectionConfig.schema === "function" ? collectionConfig.schema({ image: () => z.string() }) : collectionConfig.schema;
|
|
360
|
+
if (zodSchemaForJson instanceof z.ZodObject) {
|
|
361
|
+
zodSchemaForJson = zodSchemaForJson.extend({
|
|
362
|
+
$schema: z.string().optional()
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
try {
|
|
366
|
+
await fs.promises.writeFile(
|
|
367
|
+
new URL(`./${collectionKey.replace(/"/g, "")}.schema.json`, collectionSchemasDir),
|
|
368
|
+
JSON.stringify(
|
|
369
|
+
zodToJsonSchema(zodSchemaForJson, {
|
|
370
|
+
name: collectionKey.replace(/"/g, ""),
|
|
371
|
+
markdownDescription: true,
|
|
372
|
+
errorMessages: true
|
|
373
|
+
}),
|
|
374
|
+
null,
|
|
375
|
+
2
|
|
376
|
+
)
|
|
377
|
+
);
|
|
378
|
+
} catch (err) {
|
|
379
|
+
logger.warn(
|
|
380
|
+
"content",
|
|
381
|
+
`An error was encountered while creating the JSON schema for the ${collectionKey} collection. Proceeding without it. Error: ${err}`
|
|
382
|
+
);
|
|
383
383
|
}
|
|
384
384
|
}
|
|
385
|
-
dataTypesStr += `};
|
|
386
|
-
`;
|
|
387
385
|
break;
|
|
388
386
|
}
|
|
389
387
|
}
|
package/dist/content/utils.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ import type { PluginContext } from 'rollup';
|
|
|
5
5
|
import { type ViteDevServer } from 'vite';
|
|
6
6
|
import { z } from 'zod';
|
|
7
7
|
import type { AstroConfig, AstroSettings, ContentEntryType, DataEntryType } from '../@types/astro.js';
|
|
8
|
+
import type { Logger } from '../core/logger/core.js';
|
|
8
9
|
import { CONTENT_FLAGS } from './consts.js';
|
|
9
10
|
/**
|
|
10
11
|
* Amap from a collection + slug to the local file path.
|
|
@@ -99,6 +100,16 @@ export declare function getEntryData(entry: {
|
|
|
99
100
|
export declare function getContentEntryExts(settings: Pick<AstroSettings, 'contentEntryTypes'>): string[];
|
|
100
101
|
export declare function getDataEntryExts(settings: Pick<AstroSettings, 'dataEntryTypes'>): string[];
|
|
101
102
|
export declare function getEntryConfigByExtMap<TEntryType extends ContentEntryType | DataEntryType>(entryTypes: TEntryType[]): Map<string, TEntryType>;
|
|
103
|
+
export declare function getSymlinkedContentCollections({ contentDir, logger, fs, }: {
|
|
104
|
+
contentDir: URL;
|
|
105
|
+
logger: Logger;
|
|
106
|
+
fs: typeof fsMod;
|
|
107
|
+
}): Promise<Map<string, string>>;
|
|
108
|
+
export declare function reverseSymlink({ entry, symlinks, contentDir, }: {
|
|
109
|
+
entry: string | URL;
|
|
110
|
+
contentDir: string | URL;
|
|
111
|
+
symlinks?: Map<string, string>;
|
|
112
|
+
}): string;
|
|
102
113
|
export declare function getEntryCollectionName({ contentDir, entry, }: Pick<ContentPaths, 'contentDir'> & {
|
|
103
114
|
entry: string | URL;
|
|
104
115
|
}): string | undefined;
|
package/dist/content/utils.js
CHANGED
|
@@ -108,6 +108,53 @@ function getEntryConfigByExtMap(entryTypes) {
|
|
|
108
108
|
}
|
|
109
109
|
return map;
|
|
110
110
|
}
|
|
111
|
+
async function getSymlinkedContentCollections({
|
|
112
|
+
contentDir,
|
|
113
|
+
logger,
|
|
114
|
+
fs
|
|
115
|
+
}) {
|
|
116
|
+
const contentPaths = /* @__PURE__ */ new Map();
|
|
117
|
+
const contentDirPath = fileURLToPath(contentDir);
|
|
118
|
+
try {
|
|
119
|
+
if (!fs.existsSync(contentDirPath) || !fs.lstatSync(contentDirPath).isDirectory()) {
|
|
120
|
+
return contentPaths;
|
|
121
|
+
}
|
|
122
|
+
} catch {
|
|
123
|
+
return contentPaths;
|
|
124
|
+
}
|
|
125
|
+
try {
|
|
126
|
+
const contentDirEntries = await fs.promises.readdir(contentDir, { withFileTypes: true });
|
|
127
|
+
for (const entry of contentDirEntries) {
|
|
128
|
+
if (entry.isSymbolicLink()) {
|
|
129
|
+
const entryPath = path.join(contentDirPath, entry.name);
|
|
130
|
+
const realPath = await fs.promises.realpath(entryPath);
|
|
131
|
+
contentPaths.set(normalizePath(realPath), entry.name);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
} catch (e) {
|
|
135
|
+
logger.warn("content", `Error when reading content directory "${contentDir}"`);
|
|
136
|
+
logger.debug("content", e);
|
|
137
|
+
return /* @__PURE__ */ new Map();
|
|
138
|
+
}
|
|
139
|
+
return contentPaths;
|
|
140
|
+
}
|
|
141
|
+
function reverseSymlink({
|
|
142
|
+
entry,
|
|
143
|
+
symlinks,
|
|
144
|
+
contentDir
|
|
145
|
+
}) {
|
|
146
|
+
const entryPath = normalizePath(typeof entry === "string" ? entry : fileURLToPath(entry));
|
|
147
|
+
const contentDirPath = typeof contentDir === "string" ? contentDir : fileURLToPath(contentDir);
|
|
148
|
+
if (!symlinks || symlinks.size === 0) {
|
|
149
|
+
return entryPath;
|
|
150
|
+
}
|
|
151
|
+
for (const [realPath, symlinkName] of symlinks) {
|
|
152
|
+
if (entryPath.startsWith(realPath)) {
|
|
153
|
+
return normalizePath(path.join(contentDirPath, symlinkName, entryPath.replace(realPath, "")));
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
return entryPath;
|
|
157
|
+
}
|
|
111
158
|
function getEntryCollectionName({
|
|
112
159
|
contentDir,
|
|
113
160
|
entry
|
|
@@ -354,6 +401,7 @@ export {
|
|
|
354
401
|
getEntrySlug,
|
|
355
402
|
getEntryType,
|
|
356
403
|
getExtGlob,
|
|
404
|
+
getSymlinkedContentCollections,
|
|
357
405
|
globalContentConfigObserver,
|
|
358
406
|
hasAnyContentFlag,
|
|
359
407
|
hasAssetPropagationFlag,
|
|
@@ -363,5 +411,6 @@ export {
|
|
|
363
411
|
msg,
|
|
364
412
|
parseEntrySlug,
|
|
365
413
|
reloadContentConfigObserver,
|
|
414
|
+
reverseSymlink,
|
|
366
415
|
safeParseFrontmatter
|
|
367
416
|
};
|
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
import type fsMod from 'node:fs';
|
|
3
3
|
import type { Plugin } from 'vite';
|
|
4
4
|
import type { AstroSettings } from '../@types/astro.js';
|
|
5
|
-
|
|
5
|
+
import type { Logger } from '../core/logger/core.js';
|
|
6
|
+
export declare function astroContentImportPlugin({ fs, settings, logger, }: {
|
|
6
7
|
fs: typeof fsMod;
|
|
7
8
|
settings: AstroSettings;
|
|
9
|
+
logger: Logger;
|
|
8
10
|
}): Plugin[];
|