diff options
Diffstat (limited to 'packages/integrations/mdx')
8 files changed, 34 insertions, 38 deletions
diff --git a/packages/integrations/mdx/package.json b/packages/integrations/mdx/package.json index f9e22d58c..8a2ff0b3f 100644 --- a/packages/integrations/mdx/package.json +++ b/packages/integrations/mdx/package.json @@ -35,47 +35,47 @@ }, "dependencies": { "@astrojs/markdown-remark": "workspace:*", - "@mdx-js/mdx": "^2.3.0", - "acorn": "^8.10.0", - "es-module-lexer": "^1.3.0", - "estree-util-visit": "^1.2.1", + "@mdx-js/mdx": "^3.0.0", + "acorn": "^8.11.2", + "es-module-lexer": "^1.4.1", + "estree-util-visit": "^2.0.0", "github-slugger": "^2.0.0", "gray-matter": "^4.0.3", - "hast-util-to-html": "^8.0.4", + "hast-util-to-html": "^9.0.0", "kleur": "^4.1.4", - "rehype-raw": "^6.1.1", - "remark-gfm": "^3.0.1", + "rehype-raw": "^7.0.0", + "remark-gfm": "^4.0.0", "remark-smartypants": "^2.0.0", "source-map": "^0.7.4", - "unist-util-visit": "^4.1.2", - "vfile": "^5.3.7" + "unist-util-visit": "^5.0.0", + "vfile": "^6.0.1" }, "peerDependencies": { "astro": "^3.0.0" }, "devDependencies": { - "@types/chai": "^4.3.5", - "@types/estree": "^1.0.1", - "@types/mdast": "^3.0.12", - "@types/mocha": "^10.0.1", - "@types/yargs-parser": "^21.0.0", + "@types/chai": "^4.3.10", + "@types/estree": "^1.0.5", + "@types/mdast": "^4.0.3", + "@types/mocha": "^10.0.4", + "@types/yargs-parser": "^21.0.3", "astro": "workspace:*", "astro-scripts": "workspace:*", "chai": "^4.3.7", "cheerio": "1.0.0-rc.12", - "linkedom": "^0.15.1", - "mdast-util-mdx": "^2.0.1", - "mdast-util-to-string": "^3.2.0", + "linkedom": "^0.16.4", + "mdast-util-mdx": "^3.0.0", + "mdast-util-to-string": "^4.0.0", "mocha": "^10.2.0", "reading-time": "^1.5.0", - "rehype-mathjax": "^4.0.3", - "rehype-pretty-code": "^0.10.0", - "remark-math": "^5.1.1", - "remark-rehype": "^10.1.0", + "rehype-mathjax": "^5.0.0", + "rehype-pretty-code": "^0.10.2", + "remark-math": "^6.0.0", + "remark-rehype": "^11.0.0", "remark-shiki-twoslash": "^3.1.3", - "remark-toc": "^8.0.1", - "unified": "^10.1.2", - "vite": "^4.4.9" + "remark-toc": "^9.0.0", + "unified": "^11.0.4", + "vite": "^5.0.0" }, "engines": { "node": ">=18.14.1" diff --git a/packages/integrations/mdx/src/index.ts b/packages/integrations/mdx/src/index.ts index fd330625e..f44e19e92 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,7 @@ 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', diff --git a/packages/integrations/mdx/test/fixtures/mdx-infinite-loop/package.json b/packages/integrations/mdx/test/fixtures/mdx-infinite-loop/package.json index d2fb7a75d..a00e19d5b 100644 --- a/packages/integrations/mdx/test/fixtures/mdx-infinite-loop/package.json +++ b/packages/integrations/mdx/test/fixtures/mdx-infinite-loop/package.json @@ -6,6 +6,6 @@ "@astrojs/mdx": "workspace:*", "@astrojs/preact": "workspace:*", "astro": "workspace:*", - "preact": "^10.17.1" + "preact": "^10.19.2" } } diff --git a/packages/integrations/mdx/test/mdx-astro-markdown-remarkRehype.test.js b/packages/integrations/mdx/test/mdx-astro-markdown-remarkRehype.test.js index ddcce4ba5..eab2c61b0 100644 --- a/packages/integrations/mdx/test/mdx-astro-markdown-remarkRehype.test.js +++ b/packages/integrations/mdx/test/mdx-astro-markdown-remarkRehype.test.js @@ -79,7 +79,7 @@ describe('MDX with Astro Markdown remark-rehype config', () => { expect(document.querySelector('#footnote-label').textContent).to.equal('Catatan kaki'); expect(document.querySelector('.data-footnote-backref').getAttribute('aria-label')).to.equal( - 'Back to content' + 'Back to reference 1' ); }); }); diff --git a/packages/integrations/mdx/test/mdx-math.test.js b/packages/integrations/mdx/test/mdx-math.test.js index f39ea42c8..52ee94a46 100644 --- a/packages/integrations/mdx/test/mdx-math.test.js +++ b/packages/integrations/mdx/test/mdx-math.test.js @@ -4,7 +4,7 @@ import { parseHTML } from 'linkedom'; import { loadFixture } from '../../../astro/test/test-utils.js'; import remarkMath from 'remark-math'; import rehypeMathjaxSvg from 'rehype-mathjax'; -import rehypeMathjaxChtml from 'rehype-mathjax/chtml.js'; +import rehypeMathjaxChtml from 'rehype-mathjax/chtml'; const FIXTURE_ROOT = new URL('./fixtures/mdx-math/', import.meta.url); |