Merge branch 'main' into main

This commit is contained in:
Chris 2023-09-05 14:23:39 +02:00 committed by GitHub
commit 45c522fcae
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 42 additions and 31 deletions

View file

@ -0,0 +1,5 @@
---
'@astrojs/mdx': patch
---
Add location data to MDX compile errors

View file

@ -642,7 +642,7 @@ export interface AstroUserConfig {
* import netlify from '@astrojs/netlify/functions'; * import netlify from '@astrojs/netlify/functions';
* { * {
* // Example: Build for Netlify serverless deployment * // Example: Build for Netlify serverless deployment
* adapter: netlify(), * adapter: netlify(),
* } * }
* ``` * ```
*/ */
@ -658,9 +658,9 @@ export interface AstroUserConfig {
* *
* Specifies the output target for builds. * Specifies the output target for builds.
* *
* - 'static' - Building a static site to be deploy to any static host. * - `'static'` - Building a static site to be deploy to any static host.
* - 'server' - Building an app to be deployed to a host supporting SSR (server-side rendering). * - `'server'` - Building an app to be deployed to a host supporting SSR (server-side rendering).
* - 'hybrid' - Building a static site with a few server-side rendered pages. * - `'hybrid'` - Building a static site with a few server-side rendered pages.
* *
* ```js * ```js
* import { defineConfig } from 'astro/config'; * import { defineConfig } from 'astro/config';
@ -685,8 +685,8 @@ export interface AstroUserConfig {
* @default `'directory'` * @default `'directory'`
* @description * @description
* Control the output file format of each page. * Control the output file format of each page.
* - If 'file', Astro will generate an HTML file (ex: "/foo.html") for each page. * - If `'file'`, Astro will generate an HTML file (ex: "/foo.html") for each page.
* - If 'directory', Astro will generate a directory with a nested `index.html` file (ex: "/foo/index.html") for each page. * - If `'directory'`, Astro will generate a directory with a nested `index.html` file (ex: "/foo/index.html") for each page.
* *
* ```js * ```js
* { * {
@ -970,7 +970,7 @@ export interface AstroUserConfig {
/** /**
* @docs * @docs
* @kind heading * @kind heading
* @name Image options * @name Image Options
*/ */
image?: { image?: {
/** /**
@ -980,7 +980,7 @@ export interface AstroUserConfig {
* @default `{entrypoint: 'astro/assets/services/sharp', config?: {}}` * @default `{entrypoint: 'astro/assets/services/sharp', config?: {}}`
* @version 2.1.0 * @version 2.1.0
* @description * @description
* Set which image service is used for Astros experimental assets support. * Set which image service is used for Astros assets support.
* *
* The value should be an object with an entrypoint for the image service to use and optionally, a config object to pass to the service. * The value should be an object with an entrypoint for the image service to use and optionally, a config object to pass to the service.
* *
@ -1004,7 +1004,7 @@ export interface AstroUserConfig {
* @default `{domains: []}` * @default `{domains: []}`
* @version 2.10.10 * @version 2.10.10
* @description * @description
* Defines a list of permitted image source domains for local image optimization. No other remote images will be optimized by Astro. * Defines a list of permitted image source domains for remote image optimization. No other remote images will be optimized by Astro.
* *
* This option requires an array of individual domain names as strings. Wildcards are not permitted. Instead, use [`image.remotePatterns`](#imageremotepatterns) to define a list of allowed source URL patterns. * This option requires an array of individual domain names as strings. Wildcards are not permitted. Instead, use [`image.remotePatterns`](#imageremotepatterns) to define a list of allowed source URL patterns.
* *
@ -1027,7 +1027,7 @@ export interface AstroUserConfig {
* @default `{remotePatterns: []}` * @default `{remotePatterns: []}`
* @version 2.10.10 * @version 2.10.10
* @description * @description
* Defines a list of permitted image source URL patterns for local image optimization. * Defines a list of permitted image source URL patterns for remote image optimization.
* *
* `remotePatterns` can be configured with four properties: * `remotePatterns` can be configured with four properties:
* 1. protocol * 1. protocol

View file

@ -2,7 +2,7 @@ import { markdownConfigDefaults } from '@astrojs/markdown-remark';
import { toRemarkInitializeAstroData } from '@astrojs/markdown-remark/dist/internal.js'; import { toRemarkInitializeAstroData } from '@astrojs/markdown-remark/dist/internal.js';
import { compile as mdxCompile, type CompileOptions } from '@mdx-js/mdx'; import { compile as mdxCompile, type CompileOptions } from '@mdx-js/mdx';
import type { PluggableList } from '@mdx-js/mdx/lib/core.js'; import type { PluggableList } from '@mdx-js/mdx/lib/core.js';
import type { AstroIntegration, ContentEntryType, HookParameters } from 'astro'; import type { AstroIntegration, ContentEntryType, HookParameters, SSRError } from 'astro';
import astroJSXRenderer from 'astro/jsx/renderer.js'; import astroJSXRenderer from 'astro/jsx/renderer.js';
import { parse as parseESM } from 'es-module-lexer'; import { parse as parseESM } from 'es-module-lexer';
import fs from 'node:fs/promises'; import fs from 'node:fs/promises';
@ -129,27 +129,33 @@ export default function mdx(partialMdxOptions: Partial<MdxOptions> = {}): AstroI
const code = await fs.readFile(fileId, 'utf-8'); const code = await fs.readFile(fileId, 'utf-8');
const { data: frontmatter, content: pageContent } = parseFrontmatter(code, id); const { data: frontmatter, content: pageContent } = parseFrontmatter(code, id);
const compiled = await mdxCompile(new VFile({ value: pageContent, path: id }), { try {
...mdxPluginOpts, const compiled = await mdxCompile(new VFile({ value: pageContent, path: id }), {
elementAttributeNameCase: 'html', ...mdxPluginOpts,
remarkPlugins: [ elementAttributeNameCase: 'html',
// Ensure `data.astro` is available to all remark plugins remarkPlugins: [
toRemarkInitializeAstroData({ userFrontmatter: frontmatter }), // Ensure `data.astro` is available to all remark plugins
...(mdxPluginOpts.remarkPlugins ?? []), toRemarkInitializeAstroData({ userFrontmatter: frontmatter }),
], ...(mdxPluginOpts.remarkPlugins ?? []),
recmaPlugins: [ ],
...(mdxPluginOpts.recmaPlugins ?? []), recmaPlugins: [
() => recmaInjectImportMetaEnvPlugin({ importMetaEnv }), ...(mdxPluginOpts.recmaPlugins ?? []),
], () => recmaInjectImportMetaEnvPlugin({ importMetaEnv }),
SourceMapGenerator: config.vite.build?.sourcemap ],
? SourceMapGenerator SourceMapGenerator: config.vite.build?.sourcemap
: undefined, ? SourceMapGenerator
}); : undefined,
});
return { return {
code: escapeViteEnvReferences(String(compiled.value)), code: escapeViteEnvReferences(String(compiled.value)),
map: compiled.map, map: compiled.map,
}; };
} catch (e: any) {
const err: SSRError = e;
err.loc = { file: fileId, line: e.line, column: e.column };
throw err;
}
}, },
}, },
{ {