astro 4.13.3 → 4.14.0
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 +251 -2
- package/dist/actions/consts.d.ts +1 -1
- package/dist/actions/consts.js +1 -1
- package/dist/actions/index.js +12 -21
- package/dist/actions/runtime/virtual/server.js +9 -3
- package/dist/actions/runtime/virtual/shared.js +25 -3
- package/dist/assets/utils/resolveImports.d.ts +9 -0
- package/dist/assets/utils/resolveImports.js +22 -0
- package/dist/cli/add/index.d.ts +2 -2
- package/dist/cli/add/index.js +2 -2
- package/dist/cli/build/index.d.ts +2 -2
- package/dist/cli/build/index.js +5 -1
- package/dist/cli/check/index.d.ts +2 -2
- package/dist/cli/check/index.js +5 -2
- package/dist/cli/db/index.d.ts +4 -3
- package/dist/cli/db/index.js +10 -3
- package/dist/cli/dev/index.d.ts +2 -2
- package/dist/cli/dev/index.js +1 -0
- package/dist/cli/docs/index.d.ts +2 -2
- package/dist/cli/flags.d.ts +3 -1
- package/dist/cli/flags.js +2 -1
- package/dist/cli/index.d.ts +1 -1
- package/dist/cli/index.js +26 -13
- package/dist/cli/info/index.d.ts +2 -2
- package/dist/cli/preferences/index.d.ts +2 -2
- package/dist/cli/preferences/index.js +1 -1
- package/dist/cli/preview/index.d.ts +2 -2
- package/dist/cli/sync/index.d.ts +2 -2
- package/dist/cli/sync/index.js +5 -2
- package/dist/cli/telemetry/index.d.ts +2 -2
- package/dist/container/index.js +3 -1
- package/dist/content/consts.d.ts +16 -2
- package/dist/content/consts.js +32 -2
- package/dist/content/content-layer.d.ts +40 -0
- package/dist/content/content-layer.js +253 -0
- package/dist/content/data-store.d.ts +114 -0
- package/dist/content/data-store.js +323 -0
- package/dist/content/loaders/file.d.ts +7 -0
- package/dist/content/loaders/file.js +72 -0
- package/dist/content/loaders/glob.d.ts +25 -0
- package/dist/content/loaders/glob.js +218 -0
- package/dist/content/loaders/index.d.ts +3 -0
- package/dist/content/loaders/index.js +7 -0
- package/dist/content/loaders/types.d.ts +36 -0
- package/dist/content/loaders/types.js +0 -0
- package/dist/content/runtime.d.ts +46 -8
- package/dist/content/runtime.js +225 -31
- package/dist/content/types-generator.js +125 -35
- package/dist/content/utils.d.ts +306 -2
- package/dist/content/utils.js +93 -7
- package/dist/content/vite-plugin-content-assets.js +9 -1
- package/dist/content/vite-plugin-content-virtual-mod.js +94 -2
- package/dist/core/app/common.js +4 -1
- package/dist/core/app/index.js +5 -3
- package/dist/core/app/types.d.ts +3 -1
- package/dist/core/build/generate.js +4 -2
- package/dist/core/build/index.js +17 -8
- package/dist/core/build/plugins/plugin-manifest.js +5 -2
- package/dist/core/build/plugins/plugin-ssr.js +35 -3
- package/dist/core/build/static-build.js +2 -0
- package/dist/core/build/types.d.ts +1 -0
- package/dist/core/config/config.d.ts +2 -5
- package/dist/core/config/config.js +0 -12
- package/dist/core/config/index.d.ts +1 -1
- package/dist/core/config/index.js +0 -2
- package/dist/core/config/schema.d.ts +34 -0
- package/dist/core/config/schema.js +6 -2
- package/dist/core/config/settings.js +5 -3
- package/dist/core/constants.js +1 -1
- package/dist/core/create-vite.js +1 -1
- package/dist/core/dev/container.js +2 -1
- package/dist/core/dev/dev.js +34 -2
- package/dist/core/dev/restart.js +25 -10
- package/dist/core/encryption.d.ts +24 -0
- package/dist/core/encryption.js +64 -0
- package/dist/core/errors/errors-data.d.ts +21 -0
- package/dist/core/errors/errors-data.js +13 -0
- package/dist/core/index.js +1 -1
- package/dist/core/messages.js +2 -2
- package/dist/core/render-context.js +1 -0
- package/dist/core/server-islands/endpoint.js +5 -1
- package/dist/core/sync/constants.d.ts +1 -0
- package/dist/core/sync/constants.js +4 -0
- package/dist/core/sync/index.d.ts +12 -4
- package/dist/core/sync/index.js +56 -25
- package/dist/core/sync/write-files.d.ts +4 -0
- package/dist/core/sync/write-files.js +69 -0
- package/dist/core/util.js +1 -1
- package/dist/env/sync.js +6 -4
- package/dist/integrations/hooks.d.ts +7 -1
- package/dist/integrations/hooks.js +54 -0
- package/dist/preferences/index.d.ts +1 -1
- package/dist/preferences/index.js +2 -2
- package/dist/runtime/server/render/server-islands.js +9 -5
- package/dist/vite-plugin-astro-server/plugin.js +2 -0
- package/dist/vite-plugin-env/index.d.ts +3 -1
- package/dist/vite-plugin-env/index.js +11 -1
- package/dist/vite-plugin-markdown/content-entry-type.js +25 -2
- package/dist/vite-plugin-scanner/index.js +15 -5
- package/dist/vite-plugin-scanner/scan.js +1 -1
- package/package.json +15 -9
- package/templates/content/module.mjs +6 -1
- package/templates/content/types.d.ts +18 -5
- package/types/content.d.ts +34 -1
- package/dist/core/sync/setup-env-ts.d.ts +0 -8
- package/dist/core/sync/setup-env-ts.js +0 -79
package/components/Code.astro
CHANGED
|
@@ -23,6 +23,13 @@ interface Props extends Omit<HTMLAttributes<'pre'>, 'lang'> {
|
|
|
23
23
|
* @default "plaintext"
|
|
24
24
|
*/
|
|
25
25
|
lang?: BuiltinLanguage | SpecialLanguage | LanguageRegistration;
|
|
26
|
+
/**
|
|
27
|
+
* A metastring to pass to the highlighter.
|
|
28
|
+
* Allows passing information to transformers: https://shiki.style/guide/transformers#meta
|
|
29
|
+
*
|
|
30
|
+
* @default undefined
|
|
31
|
+
*/
|
|
32
|
+
meta?: string;
|
|
26
33
|
/**
|
|
27
34
|
* The styling theme.
|
|
28
35
|
* Supports all themes listed here: https://shiki.style/themes
|
|
@@ -72,6 +79,7 @@ interface Props extends Omit<HTMLAttributes<'pre'>, 'lang'> {
|
|
|
72
79
|
const {
|
|
73
80
|
code,
|
|
74
81
|
lang = 'plaintext',
|
|
82
|
+
meta,
|
|
75
83
|
theme = 'github-dark',
|
|
76
84
|
themes = {},
|
|
77
85
|
defaultColor = 'light',
|
|
@@ -110,6 +118,7 @@ const highlighter = await getCachedHighlighter({
|
|
|
110
118
|
|
|
111
119
|
const html = await highlighter.highlight(code, typeof lang === 'string' ? lang : lang.name, {
|
|
112
120
|
inline,
|
|
121
|
+
meta,
|
|
113
122
|
attributes: rest as any,
|
|
114
123
|
});
|
|
115
124
|
---
|
package/dist/@types/astro.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ import type * as rollup from 'rollup';
|
|
|
6
6
|
import type * as vite from 'vite';
|
|
7
7
|
import type { ActionAccept, ActionClient, ActionInputSchema, ActionReturnType } from '../actions/runtime/virtual/server.js';
|
|
8
8
|
import type { RemotePattern } from '../assets/utils/remotePattern.js';
|
|
9
|
+
import type { DataEntry, RenderedContent } from '../content/data-store.js';
|
|
9
10
|
import type { AssetsPrefix, SSRManifest, SerializedSSRManifest } from '../core/app/types.js';
|
|
10
11
|
import type { PageBuildData } from '../core/build/types.js';
|
|
11
12
|
import type { AstroConfigType } from '../core/config/index.js';
|
|
@@ -29,7 +30,7 @@ export type { MarkdownHeading, RehypePlugins, RemarkPlugins, ShikiConfig, } from
|
|
|
29
30
|
export type { ExternalImageService, ImageService, LocalImageService, } from '../assets/services/service.js';
|
|
30
31
|
export type { GetImageResult, ImageInputFormat, ImageMetadata, ImageOutputFormat, ImageQuality, ImageQualityPreset, ImageTransform, UnresolvedImageTransform, } from '../assets/types.js';
|
|
31
32
|
export type { RemotePattern } from '../assets/utils/remotePattern.js';
|
|
32
|
-
export type {
|
|
33
|
+
export type { AssetsPrefix, SSRManifest } from '../core/app/types.js';
|
|
33
34
|
export type { AstroCookieGetOptions, AstroCookieSetOptions, AstroCookies, } from '../core/cookies/index.js';
|
|
34
35
|
export interface AstroBuiltinProps {
|
|
35
36
|
'client:load'?: boolean;
|
|
@@ -2038,6 +2039,223 @@ export interface AstroUserConfig {
|
|
|
2038
2039
|
* For a complete overview, and to give feedback on this experimental API, see the [Server Islands RFC](https://github.com/withastro/roadmap/pull/963).
|
|
2039
2040
|
*/
|
|
2040
2041
|
serverIslands?: boolean;
|
|
2042
|
+
/**
|
|
2043
|
+
* @docs
|
|
2044
|
+
* @name experimental.contentIntellisense
|
|
2045
|
+
* @type {boolean}
|
|
2046
|
+
* @default `false`
|
|
2047
|
+
* @version 4.14.0
|
|
2048
|
+
* @description
|
|
2049
|
+
*
|
|
2050
|
+
* Enables Intellisense features (e.g. code completion, quick hints) for your content collection entries in compatible editors.
|
|
2051
|
+
*
|
|
2052
|
+
* When enabled, this feature will generate and add JSON schemas to the `.astro` directory in your project. These files can be used by the Astro language server to provide Intellisense inside content files (`.md`, `.mdx`, `.mdoc`).
|
|
2053
|
+
*
|
|
2054
|
+
* ```js
|
|
2055
|
+
* {
|
|
2056
|
+
* experimental: {
|
|
2057
|
+
* contentIntellisense: true,
|
|
2058
|
+
* },
|
|
2059
|
+
* }
|
|
2060
|
+
* ```
|
|
2061
|
+
*
|
|
2062
|
+
* To use this feature with the Astro VS Code extension, you must also enable the `astro.content-intellisense` option in your VS Code settings. For editors using the Astro language server directly, pass the `contentIntellisense: true` initialization parameter to enable this feature.
|
|
2063
|
+
*/
|
|
2064
|
+
contentIntellisense?: boolean;
|
|
2065
|
+
/**
|
|
2066
|
+
* @docs
|
|
2067
|
+
* @name experimental.contentLayer
|
|
2068
|
+
* @type {boolean}
|
|
2069
|
+
* @default `false`
|
|
2070
|
+
* @version 4.14.0
|
|
2071
|
+
* @description
|
|
2072
|
+
*
|
|
2073
|
+
* The Content Layer API is a new way to handle content and data in Astro. It is similar to and builds upon [content collections](/en/guides/content-collections/), taking them beyond local files in `src/content/` and allowing you to fetch content from anywhere, including remote APIs, by adding a `loader` to your collection.
|
|
2074
|
+
*
|
|
2075
|
+
* Your existing content collections can be [migrated to the Content Layer API](#migrating-an-existing-content-collection-to-use-the-content-layer-api) with a few small changes. However, it is not necessary to update all your collections at once to add a new collection powered by the Content Layer API. You may have collections using both the existing and new APIs defined in `src/content/config.ts` at the same time.
|
|
2076
|
+
*
|
|
2077
|
+
* The Content Layer API is designed to be more powerful and more performant, helping sites scale to thousands of pages. Data is cached between builds and updated incrementally. Markdown parsing is also 5-10 times faster, with similar scale reductions in memory, and MDX is 2-3 times faster.
|
|
2078
|
+
*
|
|
2079
|
+
* To enable, add the `contentLayer` flag to the `experimental` object in your Astro config:
|
|
2080
|
+
*
|
|
2081
|
+
* ```js
|
|
2082
|
+
* // astro.config.mjs
|
|
2083
|
+
* {
|
|
2084
|
+
* experimental: {
|
|
2085
|
+
* contentLayer: true,
|
|
2086
|
+
* }
|
|
2087
|
+
* }
|
|
2088
|
+
* ```
|
|
2089
|
+
*
|
|
2090
|
+
* #### Fetching data with a `loader`
|
|
2091
|
+
*
|
|
2092
|
+
* The Content Layer API allows you to fetch your content from outside of the `src/content/` folder (whether stored locally in your project or remotely) and uses a `loader` property to retrieve your data.
|
|
2093
|
+
*
|
|
2094
|
+
* The `loader` is defined in the collection's schema and returns an array of entries. Astro provides two built-in loader functions (`glob()` and `file()`) for fetching your local content, as well as access to the API to [construct your own loader and fetch remote data](#creating-a-loader).
|
|
2095
|
+
*
|
|
2096
|
+
* The `glob()` loader creates entries from directories of Markdown, MDX, Markdoc, or JSON files from anywhere on the filesystem. It accepts a `pattern` of entry files to match, and a `base` file path of where your files are located. Use this when you have one file per entry.
|
|
2097
|
+
*
|
|
2098
|
+
* The `file()` loader creates multiple entries from a single local file. Use this when all your entries are stored in an array of objects.
|
|
2099
|
+
*
|
|
2100
|
+
* ```ts {3,8,19}
|
|
2101
|
+
* // src/content/config.ts
|
|
2102
|
+
* import { defineCollection, z } from 'astro:content';
|
|
2103
|
+
* import { glob, file } from 'astro/loaders';
|
|
2104
|
+
*
|
|
2105
|
+
* const blog = defineCollection({
|
|
2106
|
+
* // By default the ID is a slug generated from
|
|
2107
|
+
* // the path of the file relative to `base`
|
|
2108
|
+
* loader: glob({ pattern: "**\/*.md", base: "./src/data/blog" }),
|
|
2109
|
+
* schema: z.object({
|
|
2110
|
+
* title: z.string(),
|
|
2111
|
+
* description: z.string(),
|
|
2112
|
+
* pubDate: z.coerce.date(),
|
|
2113
|
+
* updatedDate: z.coerce.date().optional(),
|
|
2114
|
+
* })
|
|
2115
|
+
* });
|
|
2116
|
+
*
|
|
2117
|
+
* const dogs = defineCollection({
|
|
2118
|
+
* // The path is relative to the project root, or an absolute path.
|
|
2119
|
+
* loader: file("src/data/dogs.json"),
|
|
2120
|
+
* schema: z.object({
|
|
2121
|
+
* id: z.string(),
|
|
2122
|
+
* breed: z.string(),
|
|
2123
|
+
* temperament: z.array(z.string()),
|
|
2124
|
+
* }),
|
|
2125
|
+
* });
|
|
2126
|
+
*
|
|
2127
|
+
* export const collections = { blog, dogs };
|
|
2128
|
+
* ```
|
|
2129
|
+
*
|
|
2130
|
+
* #### Querying and rendering with the Content Layer API
|
|
2131
|
+
*
|
|
2132
|
+
* The collection can be [queried in the same way as content collections](/en/guides/content-collections/#querying-collections):
|
|
2133
|
+
*
|
|
2134
|
+
* ```ts
|
|
2135
|
+
* // src/pages/index.astro
|
|
2136
|
+
* import { getCollection, getEntry } from 'astro:content';
|
|
2137
|
+
*
|
|
2138
|
+
* // Get all entries from a collection.
|
|
2139
|
+
* // Requires the name of the collection as an argument.
|
|
2140
|
+
* const allBlogPosts = await getCollection('blog');
|
|
2141
|
+
*
|
|
2142
|
+
* // Get a single entry from a collection.
|
|
2143
|
+
* // Requires the name of the collection and ID
|
|
2144
|
+
* const labradorData = await getEntry('dogs', 'labrador-retriever');
|
|
2145
|
+
* ```
|
|
2146
|
+
*
|
|
2147
|
+
* Entries generated from Markdown, MDX, or Markdoc can be rendered directly to a page using the `render()` function.
|
|
2148
|
+
*
|
|
2149
|
+
* :::note
|
|
2150
|
+
* The syntax for rendering collection entries is different from the current content collections syntax.
|
|
2151
|
+
* :::
|
|
2152
|
+
*
|
|
2153
|
+
* ```astro title="src/pages/[slug].astro"
|
|
2154
|
+
* ---
|
|
2155
|
+
* import { getEntry, render } from 'astro:content';
|
|
2156
|
+
*
|
|
2157
|
+
* const post = await getEntry('blog', Astro.params.slug);
|
|
2158
|
+
*
|
|
2159
|
+
* const { Content, headings } = await render(entry);
|
|
2160
|
+
* ---
|
|
2161
|
+
*
|
|
2162
|
+
* <Content />
|
|
2163
|
+
* ```
|
|
2164
|
+
*
|
|
2165
|
+
* #### Creating a loader
|
|
2166
|
+
*
|
|
2167
|
+
* With the Content Layer API, you can build loaders to load or generate content from anywhere.
|
|
2168
|
+
*
|
|
2169
|
+
* For example, you can create a loader that fetches collection entries from a remote API.
|
|
2170
|
+
*
|
|
2171
|
+
* ```ts
|
|
2172
|
+
* // src/content/config.ts
|
|
2173
|
+
* const countries = defineCollection({
|
|
2174
|
+
* loader: async () => {
|
|
2175
|
+
* const response = await fetch("https://restcountries.com/v3.1/all");
|
|
2176
|
+
* const data = await response.json();
|
|
2177
|
+
* // Must return an array of entries with an id property,
|
|
2178
|
+
* // or an object with IDs as keys and entries as values
|
|
2179
|
+
* return data.map((country) => ({
|
|
2180
|
+
* id: country.cca3,
|
|
2181
|
+
* ...country,
|
|
2182
|
+
* }));
|
|
2183
|
+
* },
|
|
2184
|
+
* // optionally add a schema
|
|
2185
|
+
* // schema: z.object...
|
|
2186
|
+
* });
|
|
2187
|
+
*
|
|
2188
|
+
* export const collections = { countries };
|
|
2189
|
+
* ```
|
|
2190
|
+
*
|
|
2191
|
+
* For more advanced loading logic, you can define an object loader. This allows incremental updates and conditional loading while also giving full access to the data store. See the API in [the Content Layer API RFC](https://github.com/withastro/roadmap/blob/content-layer/proposals/0047-content-layer.md#loaders).
|
|
2192
|
+
*
|
|
2193
|
+
* #### Migrating an existing content collection to use the Content Layer API
|
|
2194
|
+
*
|
|
2195
|
+
* You can convert an existing content collection with Markdown, MDX, Markdoc, or JSON entries to use the Content Layer API.
|
|
2196
|
+
*
|
|
2197
|
+
* 1. **Move the collection folder out of `src/content/`** (e.g. to `src/data/`). All collections located in the `src/content/` folder will use the existing Content Collections API.
|
|
2198
|
+
*
|
|
2199
|
+
* **Do not move the existing `src/content/config.ts` file**. This file will define all collections, using either API.
|
|
2200
|
+
*
|
|
2201
|
+
* 2. **Edit the collection definition**. Your updated collection requires a `loader`, and the option to select a collection `type` is no longer available.
|
|
2202
|
+
*
|
|
2203
|
+
* ```diff
|
|
2204
|
+
* // src/content/config.ts
|
|
2205
|
+
* import { defineCollection, z } from 'astro:content';
|
|
2206
|
+
* + import { glob } from 'astro/loaders';
|
|
2207
|
+
*
|
|
2208
|
+
* const blog = defineCollection({
|
|
2209
|
+
* // For content layer you no longer define a `type`
|
|
2210
|
+
* - type: 'content',
|
|
2211
|
+
* + loader: glob({ pattern: "**\/*.md", base: "./src/data/blog" }),
|
|
2212
|
+
* schema: z.object({
|
|
2213
|
+
* title: z.string(),
|
|
2214
|
+
* description: z.string(),
|
|
2215
|
+
* pubDate: z.coerce.date(),
|
|
2216
|
+
* updatedDate: z.coerce.date().optional(),
|
|
2217
|
+
* }),
|
|
2218
|
+
* });
|
|
2219
|
+
* ```
|
|
2220
|
+
*
|
|
2221
|
+
* 3. **Change references from `slug` to `id`**. Content layer collections do not have a `slug` field. Instead, all updated collections will have an `id`.
|
|
2222
|
+
*
|
|
2223
|
+
* ```diff
|
|
2224
|
+
* // src/pages/index.astro
|
|
2225
|
+
* ---
|
|
2226
|
+
* export async function getStaticPaths() {
|
|
2227
|
+
* const posts = await getCollection('blog');
|
|
2228
|
+
* return posts.map((post) => ({
|
|
2229
|
+
* - params: { slug: post.slug },
|
|
2230
|
+
* + params: { slug: post.id },
|
|
2231
|
+
* props: post,
|
|
2232
|
+
* }));
|
|
2233
|
+
* }
|
|
2234
|
+
* ---
|
|
2235
|
+
* ```
|
|
2236
|
+
*
|
|
2237
|
+
* 4. **Switch to the new `render()` function**. Entries no longer have a `render()` method, as they are now serializable plain objects. Instead, import the `render()` function from `astro:content`.
|
|
2238
|
+
*
|
|
2239
|
+
* ```diff
|
|
2240
|
+
* // src/pages/index.astro
|
|
2241
|
+
* ---
|
|
2242
|
+
* - import { getEntry } from 'astro:content';
|
|
2243
|
+
* + import { getEntry, render } from 'astro:content';
|
|
2244
|
+
*
|
|
2245
|
+
* const post = await getEntry('blog', params.slug);
|
|
2246
|
+
*
|
|
2247
|
+
* - const { Content, headings } = await post.render();
|
|
2248
|
+
* + const { Content, headings } = await render(post);
|
|
2249
|
+
* ---
|
|
2250
|
+
*
|
|
2251
|
+
* <Content />
|
|
2252
|
+
* ```
|
|
2253
|
+
*
|
|
2254
|
+
* #### Learn more
|
|
2255
|
+
*
|
|
2256
|
+
* For a complete overview and the full API reference, see [the Content Layer API RFC](https://github.com/withastro/roadmap/blob/content-layer/proposals/0047-content-layer.md) and [share your feedback](https://github.com/withastro/roadmap/pull/982).
|
|
2257
|
+
*/
|
|
2258
|
+
contentLayer?: boolean;
|
|
2041
2259
|
};
|
|
2042
2260
|
}
|
|
2043
2261
|
/**
|
|
@@ -2064,6 +2282,20 @@ export interface InjectedRoute {
|
|
|
2064
2282
|
export interface ResolvedInjectedRoute extends InjectedRoute {
|
|
2065
2283
|
resolvedEntryPoint?: URL;
|
|
2066
2284
|
}
|
|
2285
|
+
export interface RouteOptions {
|
|
2286
|
+
/**
|
|
2287
|
+
* The path to this route relative to the project root. The slash is normalized as forward slash
|
|
2288
|
+
* across all OS.
|
|
2289
|
+
* @example "src/pages/blog/[...slug].astro"
|
|
2290
|
+
*/
|
|
2291
|
+
readonly component: string;
|
|
2292
|
+
/**
|
|
2293
|
+
* Whether this route should be prerendered. If the route has an explicit `prerender` export,
|
|
2294
|
+
* the value will be passed here. Otherwise, it's undefined and will fallback to a prerender
|
|
2295
|
+
* default depending on the `output` option.
|
|
2296
|
+
*/
|
|
2297
|
+
prerender?: boolean;
|
|
2298
|
+
}
|
|
2067
2299
|
/**
|
|
2068
2300
|
* Resolved Astro Config
|
|
2069
2301
|
* Config with user settings along with all defaults filled in.
|
|
@@ -2103,6 +2335,10 @@ export interface AstroInlineOnlyConfig {
|
|
|
2103
2335
|
* @default "info"
|
|
2104
2336
|
*/
|
|
2105
2337
|
logLevel?: LoggerLevel;
|
|
2338
|
+
/**
|
|
2339
|
+
* Clear the content layer cache, forcing a rebuild of all content entries.
|
|
2340
|
+
*/
|
|
2341
|
+
force?: boolean;
|
|
2106
2342
|
}
|
|
2107
2343
|
export type ContentEntryModule = {
|
|
2108
2344
|
id: string;
|
|
@@ -2124,6 +2360,7 @@ export type DataEntryModule = {
|
|
|
2124
2360
|
filePath: string;
|
|
2125
2361
|
};
|
|
2126
2362
|
};
|
|
2363
|
+
export type ContentEntryRenderFuction = (entry: DataEntry) => Promise<RenderedContent>;
|
|
2127
2364
|
export interface ContentEntryType {
|
|
2128
2365
|
extensions: string[];
|
|
2129
2366
|
getEntryInfo(params: {
|
|
@@ -2136,6 +2373,7 @@ export interface ContentEntryType {
|
|
|
2136
2373
|
viteId: string;
|
|
2137
2374
|
}): rollup.LoadResult | Promise<rollup.LoadResult>;
|
|
2138
2375
|
contentModuleTypes?: string;
|
|
2376
|
+
getRenderFunction?(settings: AstroSettings): Promise<ContentEntryRenderFuction>;
|
|
2139
2377
|
/**
|
|
2140
2378
|
* Handle asset propagation for rendered content to avoid bleed.
|
|
2141
2379
|
* Ex. MDX content can import styles and scripts, so `handlePropagation` should be true.
|
|
@@ -2167,7 +2405,7 @@ export type GetDataEntryInfoReturnType = {
|
|
|
2167
2405
|
};
|
|
2168
2406
|
export interface AstroAdapterFeatures {
|
|
2169
2407
|
/**
|
|
2170
|
-
* Creates
|
|
2408
|
+
* Creates an edge function that will communiate with the Astro middleware
|
|
2171
2409
|
*/
|
|
2172
2410
|
edgeMiddleware: boolean;
|
|
2173
2411
|
/**
|
|
@@ -2175,6 +2413,10 @@ export interface AstroAdapterFeatures {
|
|
|
2175
2413
|
*/
|
|
2176
2414
|
functionPerRoute: boolean;
|
|
2177
2415
|
}
|
|
2416
|
+
export interface InjectedType {
|
|
2417
|
+
filename: string;
|
|
2418
|
+
content: string;
|
|
2419
|
+
}
|
|
2178
2420
|
export interface AstroSettings {
|
|
2179
2421
|
config: AstroConfig;
|
|
2180
2422
|
adapter: AstroAdapter | undefined;
|
|
@@ -2213,6 +2455,7 @@ export interface AstroSettings {
|
|
|
2213
2455
|
latestAstroVersion: string | undefined;
|
|
2214
2456
|
serverIslandMap: NonNullable<SSRManifest['serverIslandMap']>;
|
|
2215
2457
|
serverIslandNameMap: NonNullable<SSRManifest['serverIslandNameMap']>;
|
|
2458
|
+
injectedTypes: Array<InjectedType>;
|
|
2216
2459
|
}
|
|
2217
2460
|
export type AsyncRendererComponentFn<U> = (Component: any, props: any, slots: Record<string, string>, metadata?: AstroComponentMetadata) => Promise<U>;
|
|
2218
2461
|
/** Generic interface for a component (Astro, Svelte, React, etc.) */
|
|
@@ -2788,6 +3031,7 @@ declare global {
|
|
|
2788
3031
|
'astro:config:done': (options: {
|
|
2789
3032
|
config: AstroConfig;
|
|
2790
3033
|
setAdapter: (adapter: AstroAdapter) => void;
|
|
3034
|
+
injectTypes: (injectedType: InjectedType) => URL;
|
|
2791
3035
|
logger: AstroIntegrationLogger;
|
|
2792
3036
|
}) => void | Promise<void>;
|
|
2793
3037
|
'astro:server:setup': (options: {
|
|
@@ -2838,6 +3082,10 @@ declare global {
|
|
|
2838
3082
|
logger: AstroIntegrationLogger;
|
|
2839
3083
|
cacheManifest: boolean;
|
|
2840
3084
|
}) => void | Promise<void>;
|
|
3085
|
+
'astro:route:setup': (options: {
|
|
3086
|
+
route: RouteOptions;
|
|
3087
|
+
logger: AstroIntegrationLogger;
|
|
3088
|
+
}) => void | Promise<void>;
|
|
2841
3089
|
}
|
|
2842
3090
|
}
|
|
2843
3091
|
}
|
|
@@ -2960,6 +3208,7 @@ export interface SSRResult {
|
|
|
2960
3208
|
cookies: AstroCookies | undefined;
|
|
2961
3209
|
serverIslandNameMap: Map<string, string>;
|
|
2962
3210
|
trailingSlash: AstroConfig['trailingSlash'];
|
|
3211
|
+
key: Promise<CryptoKey>;
|
|
2963
3212
|
_metadata: SSRMetadata;
|
|
2964
3213
|
}
|
|
2965
3214
|
/**
|
package/dist/actions/consts.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export declare const VIRTUAL_MODULE_ID = "astro:actions";
|
|
2
2
|
export declare const RESOLVED_VIRTUAL_MODULE_ID: string;
|
|
3
|
-
export declare const ACTIONS_TYPES_FILE = "actions.d.ts";
|
|
3
|
+
export declare const ACTIONS_TYPES_FILE = "astro/actions.d.ts";
|
|
4
4
|
export declare const VIRTUAL_INTERNAL_MODULE_ID = "astro:internal-actions";
|
|
5
5
|
export declare const RESOLVED_VIRTUAL_INTERNAL_MODULE_ID = "\0astro:internal-actions";
|
|
6
6
|
export declare const NOOP_ACTIONS = "\0noop-actions";
|
package/dist/actions/consts.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const VIRTUAL_MODULE_ID = "astro:actions";
|
|
2
2
|
const RESOLVED_VIRTUAL_MODULE_ID = "\0" + VIRTUAL_MODULE_ID;
|
|
3
|
-
const ACTIONS_TYPES_FILE = "actions.d.ts";
|
|
3
|
+
const ACTIONS_TYPES_FILE = "astro/actions.d.ts";
|
|
4
4
|
const VIRTUAL_INTERNAL_MODULE_ID = "astro:internal-actions";
|
|
5
5
|
const RESOLVED_VIRTUAL_INTERNAL_MODULE_ID = "\0astro:internal-actions";
|
|
6
6
|
const NOOP_ACTIONS = "\0noop-actions";
|
package/dist/actions/index.js
CHANGED
|
@@ -23,9 +23,6 @@ function astroActions({
|
|
|
23
23
|
error.stack = void 0;
|
|
24
24
|
throw error;
|
|
25
25
|
}
|
|
26
|
-
const stringifiedActionsImport = JSON.stringify(
|
|
27
|
-
viteID(new URL("./actions", params.config.srcDir))
|
|
28
|
-
);
|
|
29
26
|
params.updateConfig({
|
|
30
27
|
vite: {
|
|
31
28
|
plugins: [vitePluginUserActions({ settings }), vitePluginActions(fs)]
|
|
@@ -40,10 +37,18 @@ function astroActions({
|
|
|
40
37
|
entrypoint: "astro/actions/runtime/middleware.js",
|
|
41
38
|
order: "post"
|
|
42
39
|
});
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
40
|
+
},
|
|
41
|
+
"astro:config:done": (params) => {
|
|
42
|
+
const stringifiedActionsImport = JSON.stringify(
|
|
43
|
+
viteID(new URL("./actions", params.config.srcDir))
|
|
44
|
+
);
|
|
45
|
+
settings.injectedTypes.push({
|
|
46
|
+
filename: ACTIONS_TYPES_FILE,
|
|
47
|
+
content: `declare module "astro:actions" {
|
|
48
|
+
type Actions = typeof import(${stringifiedActionsImport})["server"];
|
|
49
|
+
|
|
50
|
+
export const actions: Actions;
|
|
51
|
+
}`
|
|
47
52
|
});
|
|
48
53
|
}
|
|
49
54
|
}
|
|
@@ -101,20 +106,6 @@ export * from 'astro/actions/runtime/virtual/client.js';`;
|
|
|
101
106
|
return code;
|
|
102
107
|
}
|
|
103
108
|
});
|
|
104
|
-
async function typegen({
|
|
105
|
-
stringifiedActionsImport,
|
|
106
|
-
root,
|
|
107
|
-
fs
|
|
108
|
-
}) {
|
|
109
|
-
const content = `declare module "astro:actions" {
|
|
110
|
-
type Actions = typeof import(${stringifiedActionsImport})["server"];
|
|
111
|
-
|
|
112
|
-
export const actions: Actions;
|
|
113
|
-
}`;
|
|
114
|
-
const dotAstroDir = new URL(".astro/", root);
|
|
115
|
-
await fs.promises.mkdir(dotAstroDir, { recursive: true });
|
|
116
|
-
await fs.promises.writeFile(new URL(ACTIONS_TYPES_FILE, dotAstroDir), content);
|
|
117
|
-
}
|
|
118
109
|
export {
|
|
119
110
|
astroActions as default,
|
|
120
111
|
vitePluginUserActions
|
|
@@ -62,11 +62,17 @@ function formDataToObject(formData, schema) {
|
|
|
62
62
|
const obj = {};
|
|
63
63
|
for (const [key, baseValidator] of Object.entries(schema.shape)) {
|
|
64
64
|
let validator = baseValidator;
|
|
65
|
-
while (validator instanceof z.ZodOptional || validator instanceof z.ZodNullable) {
|
|
65
|
+
while (validator instanceof z.ZodOptional || validator instanceof z.ZodNullable || validator instanceof z.ZodDefault) {
|
|
66
|
+
if (validator instanceof z.ZodDefault && !formData.has(key)) {
|
|
67
|
+
obj[key] = validator._def.defaultValue();
|
|
68
|
+
}
|
|
66
69
|
validator = validator._def.innerType;
|
|
67
70
|
}
|
|
68
|
-
if (
|
|
69
|
-
|
|
71
|
+
if (!formData.has(key) && key in obj) {
|
|
72
|
+
continue;
|
|
73
|
+
} else if (validator instanceof z.ZodBoolean) {
|
|
74
|
+
const val = formData.get(key);
|
|
75
|
+
obj[key] = val === "true" ? true : val === "false" ? false : formData.has(key);
|
|
70
76
|
} else if (validator instanceof z.ZodArray) {
|
|
71
77
|
obj[key] = handleFormDataGetAll(key, formData, validator);
|
|
72
78
|
} else {
|
|
@@ -132,14 +132,16 @@ function getActionProps(action) {
|
|
|
132
132
|
}
|
|
133
133
|
function serializeActionResult(res) {
|
|
134
134
|
if (res.error) {
|
|
135
|
+
if (import.meta.env?.DEV) {
|
|
136
|
+
actionResultErrorStack.set(res.error.stack);
|
|
137
|
+
}
|
|
135
138
|
return {
|
|
136
139
|
type: "error",
|
|
137
140
|
status: res.error.status,
|
|
138
141
|
contentType: "application/json",
|
|
139
142
|
body: JSON.stringify({
|
|
140
143
|
...res.error,
|
|
141
|
-
message: res.error.message
|
|
142
|
-
stack: import.meta.env.PROD ? void 0 : res.error.stack
|
|
144
|
+
message: res.error.message
|
|
143
145
|
})
|
|
144
146
|
};
|
|
145
147
|
}
|
|
@@ -161,7 +163,16 @@ function serializeActionResult(res) {
|
|
|
161
163
|
}
|
|
162
164
|
function deserializeActionResult(res) {
|
|
163
165
|
if (res.type === "error") {
|
|
164
|
-
|
|
166
|
+
if (import.meta.env?.PROD) {
|
|
167
|
+
return { error: ActionError.fromJson(JSON.parse(res.body)), data: void 0 };
|
|
168
|
+
} else {
|
|
169
|
+
const error = ActionError.fromJson(JSON.parse(res.body));
|
|
170
|
+
error.stack = actionResultErrorStack.get();
|
|
171
|
+
return {
|
|
172
|
+
error,
|
|
173
|
+
data: void 0
|
|
174
|
+
};
|
|
175
|
+
}
|
|
165
176
|
}
|
|
166
177
|
if (res.type === "empty") {
|
|
167
178
|
return { data: void 0, error: void 0 };
|
|
@@ -173,6 +184,17 @@ function deserializeActionResult(res) {
|
|
|
173
184
|
error: void 0
|
|
174
185
|
};
|
|
175
186
|
}
|
|
187
|
+
const actionResultErrorStack = /* @__PURE__ */ function actionResultErrorStackFn() {
|
|
188
|
+
let errorStack;
|
|
189
|
+
return {
|
|
190
|
+
set(stack) {
|
|
191
|
+
errorStack = stack;
|
|
192
|
+
},
|
|
193
|
+
get() {
|
|
194
|
+
return errorStack;
|
|
195
|
+
}
|
|
196
|
+
};
|
|
197
|
+
}();
|
|
176
198
|
export {
|
|
177
199
|
ACTION_ERROR_CODES,
|
|
178
200
|
ACTION_QUERY_PARAMS,
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resolves an image src from a content file (such as markdown) to a module ID or import that can be resolved by Vite.
|
|
3
|
+
*
|
|
4
|
+
* @param imageSrc The src attribute of an image tag
|
|
5
|
+
* @param filePath The path to the file that contains the imagem relative to the site root
|
|
6
|
+
* @returns A module id of the image that can be rsolved by Vite, or undefined if it is not a local image
|
|
7
|
+
*/
|
|
8
|
+
export declare function imageSrcToImportId(imageSrc: string, filePath: string): string | undefined;
|
|
9
|
+
export declare const importIdToSymbolName: (importId: string) => string;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { isRemotePath, removeBase } from "@astrojs/internal-helpers/path";
|
|
2
|
+
import { CONTENT_IMAGE_FLAG, IMAGE_IMPORT_PREFIX } from "../../content/consts.js";
|
|
3
|
+
import { shorthash } from "../../runtime/server/shorthash.js";
|
|
4
|
+
import { VALID_INPUT_FORMATS } from "../consts.js";
|
|
5
|
+
function imageSrcToImportId(imageSrc, filePath) {
|
|
6
|
+
imageSrc = removeBase(imageSrc, IMAGE_IMPORT_PREFIX);
|
|
7
|
+
if (isRemotePath(imageSrc) || imageSrc.startsWith("/")) {
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
const ext = imageSrc.split(".").at(-1);
|
|
11
|
+
if (!ext || !VALID_INPUT_FORMATS.includes(ext)) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
const params = new URLSearchParams(CONTENT_IMAGE_FLAG);
|
|
15
|
+
params.set("importer", filePath);
|
|
16
|
+
return `${imageSrc}?${params.toString()}`;
|
|
17
|
+
}
|
|
18
|
+
const importIdToSymbolName = (importId) => `__ASTRO_IMAGE_IMPORT_${shorthash(importId)}`;
|
|
19
|
+
export {
|
|
20
|
+
imageSrcToImportId,
|
|
21
|
+
importIdToSymbolName
|
|
22
|
+
};
|
package/dist/cli/add/index.d.ts
CHANGED
package/dist/cli/add/index.js
CHANGED
|
@@ -123,7 +123,7 @@ async function add(names, { flags }) {
|
|
|
123
123
|
});
|
|
124
124
|
return;
|
|
125
125
|
}
|
|
126
|
-
const cwd =
|
|
126
|
+
const cwd = inlineConfig.root;
|
|
127
127
|
const logger = createLoggerFromFlags(flags);
|
|
128
128
|
const integrationNames = names.map((name) => ALIASES.has(name) ? ALIASES.get(name) : name);
|
|
129
129
|
const integrations = await validateIntegrations(integrationNames);
|
|
@@ -222,7 +222,7 @@ async function add(names, { flags }) {
|
|
|
222
222
|
}
|
|
223
223
|
const rawConfigPath = await resolveConfigPath({
|
|
224
224
|
root: rootPath,
|
|
225
|
-
configFile:
|
|
225
|
+
configFile: inlineConfig.configFile,
|
|
226
226
|
fs: fsMod
|
|
227
227
|
});
|
|
228
228
|
let configURL = rawConfigPath ? pathToFileURL(rawConfigPath) : void 0;
|
package/dist/cli/build/index.js
CHANGED
|
@@ -9,6 +9,10 @@ async function build({ flags }) {
|
|
|
9
9
|
tables: {
|
|
10
10
|
Flags: [
|
|
11
11
|
["--outDir <directory>", `Specify the output directory for the build.`],
|
|
12
|
+
[
|
|
13
|
+
"--force",
|
|
14
|
+
"Clear the content layer and content collection cache, forcing a full rebuild."
|
|
15
|
+
],
|
|
12
16
|
["--help (-h)", "See all available flags."]
|
|
13
17
|
]
|
|
14
18
|
},
|
|
@@ -17,7 +21,7 @@ async function build({ flags }) {
|
|
|
17
21
|
return;
|
|
18
22
|
}
|
|
19
23
|
const inlineConfig = flagsToAstroInlineConfig(flags);
|
|
20
|
-
await _build(inlineConfig
|
|
24
|
+
await _build(inlineConfig);
|
|
21
25
|
}
|
|
22
26
|
export {
|
|
23
27
|
build
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type
|
|
2
|
-
export declare function check(flags:
|
|
1
|
+
import { type Flags } from '../flags.js';
|
|
2
|
+
export declare function check(flags: Flags): Promise<boolean | void>;
|
package/dist/cli/check/index.js
CHANGED
|
@@ -5,7 +5,10 @@ import { getPackage } from "../install-package.js";
|
|
|
5
5
|
async function check(flags) {
|
|
6
6
|
ensureProcessNodeEnv("production");
|
|
7
7
|
const logger = createLoggerFromFlags(flags);
|
|
8
|
-
const getPackageOpts = {
|
|
8
|
+
const getPackageOpts = {
|
|
9
|
+
skipAsk: !!flags.yes || !!flags.y,
|
|
10
|
+
cwd: typeof flags.root == "string" ? flags.root : void 0
|
|
11
|
+
};
|
|
9
12
|
const checkPackage = await getPackage(
|
|
10
13
|
"@astrojs/check",
|
|
11
14
|
logger,
|
|
@@ -23,7 +26,7 @@ async function check(flags) {
|
|
|
23
26
|
if (!flags.noSync && !flags.help) {
|
|
24
27
|
const { default: sync } = await import("../../core/sync/index.js");
|
|
25
28
|
try {
|
|
26
|
-
await sync(
|
|
29
|
+
await sync(flagsToAstroInlineConfig(flags));
|
|
27
30
|
} catch (_) {
|
|
28
31
|
return process.exit(1);
|
|
29
32
|
}
|
package/dist/cli/db/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type
|
|
2
|
-
export declare function db({ flags }: {
|
|
3
|
-
|
|
1
|
+
import { type Flags } from '../flags.js';
|
|
2
|
+
export declare function db({ positionals, flags }: {
|
|
3
|
+
positionals: string[];
|
|
4
|
+
flags: Flags;
|
|
4
5
|
}): Promise<void>;
|