diff options
author | 2023-11-30 10:03:51 -0500 | |
---|---|---|
committer | 2023-11-30 10:03:51 -0500 | |
commit | fbf145af8a792ee7334be577fbdf0bba9782b4e7 (patch) | |
tree | a5212b8b8f12d734579db8a2bb90dd4c772cba44 /packages/integrations/mdx/src | |
parent | ff8eadb95d34833baaf3ec7575bf4f293eae97da (diff) | |
parent | 05628aaa3c9a3702b59cbf3d0e99abf66df651df (diff) | |
download | astro-fbf145af8a792ee7334be577fbdf0bba9782b4e7.tar.gz astro-fbf145af8a792ee7334be577fbdf0bba9782b4e7.tar.zst astro-fbf145af8a792ee7334be577fbdf0bba9782b4e7.zip |
Merge pull request #9247 from withastro/next
Merge the `next` branch into `main` for the 4.0 release
Diffstat (limited to 'packages/integrations/mdx/src')
-rw-r--r-- | packages/integrations/mdx/src/index.ts | 7 | ||||
-rw-r--r-- | packages/integrations/mdx/src/plugins.ts | 8 | ||||
-rw-r--r-- | packages/integrations/mdx/src/remark-images-to-component.ts | 2 | ||||
-rw-r--r-- | packages/integrations/mdx/src/utils.ts | 4 |
4 files changed, 10 insertions, 11 deletions
diff --git a/packages/integrations/mdx/src/index.ts b/packages/integrations/mdx/src/index.ts index fd330625e..3fc00a723 100644 --- a/packages/integrations/mdx/src/index.ts +++ b/packages/integrations/mdx/src/index.ts @@ -1,8 +1,8 @@ import { markdownConfigDefaults, setVfileFrontmatter } from '@astrojs/markdown-remark'; -import type { PluggableList } from '@mdx-js/mdx/lib/core.js'; import type { AstroIntegration, ContentEntryType, HookParameters, SSRError } from 'astro'; import astroJSXRenderer from 'astro/jsx/renderer.js'; import { parse as parseESM } from 'es-module-lexer'; +import type { PluggableList } from 'unified'; import fs from 'node:fs/promises'; import { fileURLToPath } from 'node:url'; import type { Options as RemarkRehypeOptions } from 'remark-rehype'; @@ -190,7 +190,10 @@ export default function mdx(partialMdxOptions: Partial<MdxOptions> = {}): AstroI componentsCode += ' }'; // Make `Content` the default export so we can wrap `MDXContent` and pass in `Fragment` - code = code.replace('export default MDXContent;', ''); + code = code.replace( + 'export default function MDXContent', + 'function MDXContent' + ); code += `\nexport const Content = (props = {}) => MDXContent({ ...props, components: ${componentsCode}, diff --git a/packages/integrations/mdx/src/plugins.ts b/packages/integrations/mdx/src/plugins.ts index 3286a9fd8..e6584aacf 100644 --- a/packages/integrations/mdx/src/plugins.ts +++ b/packages/integrations/mdx/src/plugins.ts @@ -5,12 +5,11 @@ import { remarkShiki, } from '@astrojs/markdown-remark'; import { createProcessor, nodeTypes } from '@mdx-js/mdx'; -import type { PluggableList } from '@mdx-js/mdx/lib/core.js'; import rehypeRaw from 'rehype-raw'; import remarkGfm from 'remark-gfm'; import remarkSmartypants from 'remark-smartypants'; import { SourceMapGenerator } from 'source-map'; -import type { Processor } from 'unified'; +import type { PluggableList } from 'unified'; import type { MdxOptions } from './index.js'; import { recmaInjectImportMetaEnv } from './recma-inject-import-meta-env.js'; import { rehypeApplyFrontmatterExport } from './rehype-apply-frontmatter-export.js'; @@ -27,10 +26,7 @@ interface MdxProcessorExtraOptions { importMetaEnv: Record<string, any>; } -export function createMdxProcessor( - mdxOptions: MdxOptions, - extraOptions: MdxProcessorExtraOptions -): Processor { +export function createMdxProcessor(mdxOptions: MdxOptions, extraOptions: MdxProcessorExtraOptions) { return createProcessor({ remarkPlugins: getRemarkPlugins(mdxOptions), rehypePlugins: getRehypePlugins(mdxOptions), diff --git a/packages/integrations/mdx/src/remark-images-to-component.ts b/packages/integrations/mdx/src/remark-images-to-component.ts index f83f5d76a..810056def 100644 --- a/packages/integrations/mdx/src/remark-images-to-component.ts +++ b/packages/integrations/mdx/src/remark-images-to-component.ts @@ -15,7 +15,7 @@ export function remarkImageToComponent() { const importsStatements: MdxjsEsm[] = []; const importedImages = new Map<string, string>(); - visit(tree, 'image', (node: Image, index: number | null, parent: Parent | null) => { + visit(tree, 'image', (node: Image, index: number | undefined, parent: Parent | null) => { // Use the imagePaths set from the remark-collect-images so we don't have to duplicate the logic for // checking if an image should be imported or not if (file.data.imagePaths?.has(node.url)) { diff --git a/packages/integrations/mdx/src/utils.ts b/packages/integrations/mdx/src/utils.ts index 3425c50e3..a5b198116 100644 --- a/packages/integrations/mdx/src/utils.ts +++ b/packages/integrations/mdx/src/utils.ts @@ -1,10 +1,10 @@ -import type { PluggableList } from '@mdx-js/mdx/lib/core.js'; import type { Options as AcornOpts } from 'acorn'; import { parse } from 'acorn'; import type { AstroConfig, SSRError } from 'astro'; import matter from 'gray-matter'; import { bold, yellow } from 'kleur/colors'; import type { MdxjsEsm } from 'mdast-util-mdx'; +import type { PluggableList } from 'unified'; function appendForwardSlash(path: string) { return path.endsWith('/') ? path : path + '/'; @@ -75,8 +75,8 @@ export function jsToTreeNode( type: 'mdxjsEsm', value: '', data: { + // @ts-expect-error `parse` return types is incompatible but it should work in runtime estree: { - body: [], ...parse(jsString, acornOpts), type: 'Program', sourceType: 'module', |