astro 4.10.2 → 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/container/index.d.ts +32 -1
- package/dist/container/index.js +45 -0
- package/dist/container/vite-plugin-container.d.ts +2 -0
- package/dist/container/vite-plugin-container.js +15 -0
- package/dist/content/types-generator.js +28 -28
- 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/base-pipeline.js +1 -1
- package/dist/core/build/internal.d.ts +4 -0
- package/dist/core/build/internal.js +2 -1
- package/dist/core/build/page-data.js +2 -4
- package/dist/core/build/plugins/plugin-chunks.js +6 -0
- package/dist/core/build/plugins/plugin-prerender.js +55 -48
- package/dist/core/build/plugins/plugin-ssr.js +15 -12
- package/dist/core/build/static-build.js +36 -44
- package/dist/core/build/types.d.ts +0 -1
- package/dist/core/config/schema.d.ts +4 -156
- package/dist/core/constants.d.ts +4 -0
- package/dist/core/constants.js +3 -1
- package/dist/core/create-vite.js +4 -2
- package/dist/core/dev/dev.js +1 -1
- package/dist/core/errors/errors-data.d.ts +20 -0
- package/dist/core/errors/errors-data.js +6 -0
- package/dist/core/messages.js +2 -2
- package/dist/core/render-context.js +3 -0
- 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/util.js +5 -2
- package/dist/env/constants.d.ts +0 -1
- package/dist/env/constants.js +0 -2
- package/dist/env/runtime.d.ts +3 -1
- package/dist/env/runtime.js +8 -1
- package/dist/env/schema.d.ts +2 -78
- package/dist/env/schema.js +1 -17
- package/dist/env/vite-plugin-env.js +15 -15
- package/dist/jsx/server.d.ts +3 -5
- package/dist/jsx/server.js +3 -1
- package/dist/vite-plugin-astro/index.js +1 -1
- package/dist/vite-plugin-astro-server/route.js +18 -1
- package/package.json +8 -8
- 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 {
|
|
@@ -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
|
};
|
|
@@ -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
|
+
};
|
|
@@ -352,36 +352,36 @@ async function writeContentFiles({
|
|
|
352
352
|
data: ${dataType}
|
|
353
353
|
};
|
|
354
354
|
`;
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
)
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
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
|
+
);
|
|
381
383
|
}
|
|
382
384
|
}
|
|
383
|
-
dataTypesStr += `};
|
|
384
|
-
`;
|
|
385
385
|
break;
|
|
386
386
|
}
|
|
387
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[];
|
|
@@ -16,10 +16,12 @@ import {
|
|
|
16
16
|
getEntryConfigByExtMap,
|
|
17
17
|
getEntryData,
|
|
18
18
|
getEntryType,
|
|
19
|
+
getSymlinkedContentCollections,
|
|
19
20
|
globalContentConfigObserver,
|
|
20
21
|
hasContentFlag,
|
|
21
22
|
parseEntrySlug,
|
|
22
|
-
reloadContentConfigObserver
|
|
23
|
+
reloadContentConfigObserver,
|
|
24
|
+
reverseSymlink
|
|
23
25
|
} from "./utils.js";
|
|
24
26
|
function getContentRendererByViteId(viteId, settings) {
|
|
25
27
|
let ext = viteId.split(".").pop();
|
|
@@ -35,7 +37,8 @@ const CHOKIDAR_MODIFIED_EVENTS = ["add", "unlink", "change"];
|
|
|
35
37
|
const COLLECTION_TYPES_TO_INVALIDATE_ON = ["data", "content", "config"];
|
|
36
38
|
function astroContentImportPlugin({
|
|
37
39
|
fs,
|
|
38
|
-
settings
|
|
40
|
+
settings,
|
|
41
|
+
logger
|
|
39
42
|
}) {
|
|
40
43
|
const contentPaths = getContentPaths(settings.config, fs);
|
|
41
44
|
const contentEntryExts = getContentEntryExts(settings);
|
|
@@ -44,15 +47,23 @@ function astroContentImportPlugin({
|
|
|
44
47
|
const dataEntryConfigByExt = getEntryConfigByExtMap(settings.dataEntryTypes);
|
|
45
48
|
const { contentDir } = contentPaths;
|
|
46
49
|
let shouldEmitFile = false;
|
|
50
|
+
let symlinks;
|
|
47
51
|
const plugins = [
|
|
48
52
|
{
|
|
49
53
|
name: "astro:content-imports",
|
|
50
54
|
config(_config, env) {
|
|
51
55
|
shouldEmitFile = env.command === "build";
|
|
52
56
|
},
|
|
57
|
+
async buildStart() {
|
|
58
|
+
symlinks = await getSymlinkedContentCollections({ contentDir, logger, fs });
|
|
59
|
+
},
|
|
53
60
|
async transform(_, viteId) {
|
|
54
61
|
if (hasContentFlag(viteId, DATA_FLAG)) {
|
|
55
|
-
const fileId =
|
|
62
|
+
const fileId = reverseSymlink({
|
|
63
|
+
entry: viteId.split("?")[0] ?? viteId,
|
|
64
|
+
contentDir,
|
|
65
|
+
symlinks
|
|
66
|
+
});
|
|
56
67
|
const { id, data, collection, _internal } = await getDataEntryModule({
|
|
57
68
|
fileId,
|
|
58
69
|
entryConfigByExt: dataEntryConfigByExt,
|
|
@@ -74,7 +85,7 @@ export const _internal = {
|
|
|
74
85
|
`;
|
|
75
86
|
return code;
|
|
76
87
|
} else if (hasContentFlag(viteId, CONTENT_FLAG)) {
|
|
77
|
-
const fileId = viteId.split("?")[0];
|
|
88
|
+
const fileId = reverseSymlink({ entry: viteId.split("?")[0], contentDir, symlinks });
|
|
78
89
|
const { id, slug, collection, body, data, _internal } = await getContentEntryModule({
|
|
79
90
|
fileId,
|
|
80
91
|
entryConfigByExt: contentEntryConfigByExt,
|
|
@@ -89,6 +89,10 @@ export interface BuildInternals {
|
|
|
89
89
|
ssrSplitEntryChunks: Map<string, Rollup.OutputChunk>;
|
|
90
90
|
componentMetadata: SSRResult['componentMetadata'];
|
|
91
91
|
middlewareEntryPoint?: URL;
|
|
92
|
+
/**
|
|
93
|
+
* Chunks in the bundle that are only used in prerendering that we can delete later
|
|
94
|
+
*/
|
|
95
|
+
prerenderOnlyChunks: Rollup.OutputChunk[];
|
|
92
96
|
}
|
|
93
97
|
/**
|
|
94
98
|
* Creates internal maps used to coordinate the CSS and HTML plugins.
|
|
@@ -26,7 +26,8 @@ function createBuildInternals() {
|
|
|
26
26
|
componentMetadata: /* @__PURE__ */ new Map(),
|
|
27
27
|
ssrSplitEntryChunks: /* @__PURE__ */ new Map(),
|
|
28
28
|
entryPoints: /* @__PURE__ */ new Map(),
|
|
29
|
-
cacheManifestUsed: false
|
|
29
|
+
cacheManifestUsed: false,
|
|
30
|
+
prerenderOnlyChunks: []
|
|
30
31
|
};
|
|
31
32
|
}
|
|
32
33
|
function trackPageData(internals, component, pageData, componentModuleId, componentURL) {
|
|
@@ -29,8 +29,7 @@ async function collectPagesData(opts) {
|
|
|
29
29
|
route,
|
|
30
30
|
moduleSpecifier: "",
|
|
31
31
|
styles: [],
|
|
32
|
-
hoistedScript: void 0
|
|
33
|
-
hasSharedModules: false
|
|
32
|
+
hoistedScript: void 0
|
|
34
33
|
};
|
|
35
34
|
clearInterval(routeCollectionLogTimeout);
|
|
36
35
|
if (settings.config.output === "static") {
|
|
@@ -50,8 +49,7 @@ async function collectPagesData(opts) {
|
|
|
50
49
|
route,
|
|
51
50
|
moduleSpecifier: "",
|
|
52
51
|
styles: [],
|
|
53
|
-
hoistedScript: void 0
|
|
54
|
-
hasSharedModules: false
|
|
52
|
+
hoistedScript: void 0
|
|
55
53
|
};
|
|
56
54
|
}
|
|
57
55
|
clearInterval(dataCollectionLogTimeout);
|
|
@@ -8,6 +8,12 @@ function vitePluginChunks() {
|
|
|
8
8
|
if (id.includes("astro/dist/runtime/server/")) {
|
|
9
9
|
return "astro/server";
|
|
10
10
|
}
|
|
11
|
+
if (id.includes("astro/dist/runtime")) {
|
|
12
|
+
return "astro";
|
|
13
|
+
}
|
|
14
|
+
if (id.includes("astro/dist/env/setup")) {
|
|
15
|
+
return "astro/env-setup";
|
|
16
|
+
}
|
|
11
17
|
}
|
|
12
18
|
});
|
|
13
19
|
}
|