summaryrefslogtreecommitdiff
path: root/packages/integrations/mdx
diff options
context:
space:
mode:
Diffstat (limited to 'packages/integrations/mdx')
-rw-r--r--packages/integrations/mdx/CHANGELOG.md19
-rw-r--r--packages/integrations/mdx/package.json11
-rw-r--r--packages/integrations/mdx/src/index.ts20
-rw-r--r--packages/integrations/mdx/src/remark-images-to-component.ts2
-rw-r--r--packages/integrations/mdx/tsconfig.json2
5 files changed, 47 insertions, 7 deletions
diff --git a/packages/integrations/mdx/CHANGELOG.md b/packages/integrations/mdx/CHANGELOG.md
index 531e8809f..ac853011d 100644
--- a/packages/integrations/mdx/CHANGELOG.md
+++ b/packages/integrations/mdx/CHANGELOG.md
@@ -1,5 +1,24 @@
# @astrojs/mdx
+## 1.0.0-beta.0
+
+### Minor Changes
+
+- [`1eae2e3f7`](https://github.com/withastro/astro/commit/1eae2e3f7d693c9dfe91c8ccfbe606d32bf2fb81) Thanks [@Princesseuh](https://github.com/Princesseuh)! - Remove support for Node 16. The lowest supported version by Astro and all integrations is now v18.14.1. As a reminder, Node 16 will be deprecated on the 11th September 2023.
+
+- [`dfc2d93e3`](https://github.com/withastro/astro/commit/dfc2d93e3c645995379358fabbdfa9aab99f43d8) Thanks [@bluwy](https://github.com/bluwy)! - Add `astro` as peer dependency
+
+### Patch Changes
+
+- [`dfc2d93e3`](https://github.com/withastro/astro/commit/dfc2d93e3c645995379358fabbdfa9aab99f43d8) Thanks [@bluwy](https://github.com/bluwy)! - Re-orders the MDX plugin to run before Astro's JSX plugin
+
+- [`631b9c410`](https://github.com/withastro/astro/commit/631b9c410d5d66fa384674027ba95d69ebb5063f) Thanks [@bluwy](https://github.com/bluwy)! - Handle `components` exports handling itself
+
+- Updated dependencies [[`1eae2e3f7`](https://github.com/withastro/astro/commit/1eae2e3f7d693c9dfe91c8ccfbe606d32bf2fb81), [`76ddef19c`](https://github.com/withastro/astro/commit/76ddef19ccab6e5f7d3a5740cd41acf10e334b38), [`9b4f70a62`](https://github.com/withastro/astro/commit/9b4f70a629f55e461759ba46f68af7097a2e9215), [`3fdf509b2`](https://github.com/withastro/astro/commit/3fdf509b2731a9b2f972d89291e57cf78d62c769), [`2f951cd40`](https://github.com/withastro/astro/commit/2f951cd403dfcc2c3ca6aae618ae3e1409516e32), [`c022a4217`](https://github.com/withastro/astro/commit/c022a4217a805d223c1494e9eda4e48bbf810388), [`67becaa58`](https://github.com/withastro/astro/commit/67becaa580b8f787df58de66b7008b7098f1209c), [`bc37331d8`](https://github.com/withastro/astro/commit/bc37331d8154e3e95a8df9131e4e014e78a7a9e7), [`dfc2d93e3`](https://github.com/withastro/astro/commit/dfc2d93e3c645995379358fabbdfa9aab99f43d8), [`3dc1ca2fa`](https://github.com/withastro/astro/commit/3dc1ca2fac8d9965cc5085a5d09e72ed87b4281a), [`1be84dfee`](https://github.com/withastro/astro/commit/1be84dfee3ce8e6f5cc624f99aec4e980f6fde37), [`35f01df79`](https://github.com/withastro/astro/commit/35f01df797d23315f2bee2fc3fd795adb0559c58), [`3fdf509b2`](https://github.com/withastro/astro/commit/3fdf509b2731a9b2f972d89291e57cf78d62c769), [`78de801f2`](https://github.com/withastro/astro/commit/78de801f21fd4ca1653950027d953bf08614566b), [`59d6e569f`](https://github.com/withastro/astro/commit/59d6e569f63e175c97e82e94aa7974febfb76f7c), [`7723c4cc9`](https://github.com/withastro/astro/commit/7723c4cc93298c2e6530e55da7afda048f22cf81), [`fb5cd6b56`](https://github.com/withastro/astro/commit/fb5cd6b56dc27a71366ed5e1ab8bfe9b8f96bac5), [`631b9c410`](https://github.com/withastro/astro/commit/631b9c410d5d66fa384674027ba95d69ebb5063f)]:
+ - @astrojs/prism@3.0.0-beta.0
+ - astro@3.0.0-beta.0
+ - @astrojs/markdown-remark@3.0.0-beta.0
+
## 0.19.7
### Patch Changes
diff --git a/packages/integrations/mdx/package.json b/packages/integrations/mdx/package.json
index 7e38cb1b6..f5ed6fad8 100644
--- a/packages/integrations/mdx/package.json
+++ b/packages/integrations/mdx/package.json
@@ -1,7 +1,7 @@
{
"name": "@astrojs/mdx",
"description": "Add support for MDX pages in your Astro site",
- "version": "0.19.7",
+ "version": "1.0.0-beta.0",
"type": "module",
"types": "./dist/index.d.ts",
"author": "withastro",
@@ -34,8 +34,8 @@
"test:match": "mocha --timeout 20000 -g"
},
"dependencies": {
- "@astrojs/markdown-remark": "^2.2.1",
- "@astrojs/prism": "^2.1.2",
+ "@astrojs/markdown-remark": "workspace:*",
+ "@astrojs/prism": "workspace:*",
"@mdx-js/mdx": "^2.3.0",
"acorn": "^8.9.0",
"es-module-lexer": "^1.3.0",
@@ -53,6 +53,9 @@
"unist-util-visit": "^4.1.2",
"vfile": "^5.3.7"
},
+ "peerDependencies": {
+ "astro": "workspace:^3.0.0-beta.0"
+ },
"devDependencies": {
"@types/chai": "^4.3.5",
"@types/estree": "^1.0.1",
@@ -78,6 +81,6 @@
"vite": "^4.4.6"
},
"engines": {
- "node": ">=16.12.0"
+ "node": ">=18.14.1"
}
}
diff --git a/packages/integrations/mdx/src/index.ts b/packages/integrations/mdx/src/index.ts
index 1d0320213..ecf2a9a95 100644
--- a/packages/integrations/mdx/src/index.ts
+++ b/packages/integrations/mdx/src/index.ts
@@ -95,6 +95,21 @@ export default function mdx(partialMdxOptions: Partial<MdxOptions> = {}): AstroI
enforce: 'pre',
configResolved(resolved) {
importMetaEnv = { ...importMetaEnv, ...resolved.env };
+
+ // HACK: move ourselves before Astro's JSX plugin to transform things in the right order
+ const jsxPluginIndex = resolved.plugins.findIndex((p) => p.name === 'astro:jsx');
+ if (jsxPluginIndex !== -1) {
+ const myPluginIndex = resolved.plugins.findIndex(
+ (p) => p.name === '@mdx-js/rollup'
+ );
+ if (myPluginIndex !== -1) {
+ const myPlugin = resolved.plugins[myPluginIndex];
+ // @ts-ignore-error ignore readonly annotation
+ resolved.plugins.splice(myPluginIndex, 1);
+ // @ts-ignore-error ignore readonly annotation
+ resolved.plugins.splice(jsxPluginIndex, 0, myPlugin);
+ }
+ }
},
// Override transform to alter code before MDX compilation
// ex. inject layouts
@@ -156,11 +171,14 @@ export default function mdx(partialMdxOptions: Partial<MdxOptions> = {}): AstroI
code += `\nexport const file = ${JSON.stringify(fileId)};`;
}
if (!moduleExports.find(({ n }) => n === 'Content')) {
+ // If have `export const components`, pass that as props to `Content` as fallback
+ const hasComponents = moduleExports.find(({ n }) => n === 'components');
+
// Make `Content` the default export so we can wrap `MDXContent` and pass in `Fragment`
code = code.replace('export default MDXContent;', '');
code += `\nexport const Content = (props = {}) => MDXContent({
...props,
- components: { Fragment, ...props.components },
+ components: { Fragment${hasComponents ? ', ...components' : ''}, ...props.components },
});
export default Content;`;
}
diff --git a/packages/integrations/mdx/src/remark-images-to-component.ts b/packages/integrations/mdx/src/remark-images-to-component.ts
index 8a3166f49..bb9657f42 100644
--- a/packages/integrations/mdx/src/remark-images-to-component.ts
+++ b/packages/integrations/mdx/src/remark-images-to-component.ts
@@ -1,5 +1,5 @@
import type { MarkdownVFile } from '@astrojs/markdown-remark';
-import { type Image, type Parent } from 'mdast';
+import type { Image, Parent } from 'mdast';
import type { MdxJsxFlowElement, MdxjsEsm } from 'mdast-util-mdx';
import { visit } from 'unist-util-visit';
import { jsToTreeNode } from './utils.js';
diff --git a/packages/integrations/mdx/tsconfig.json b/packages/integrations/mdx/tsconfig.json
index 64d4ef454..af1b43564 100644
--- a/packages/integrations/mdx/tsconfig.json
+++ b/packages/integrations/mdx/tsconfig.json
@@ -5,6 +5,6 @@
"allowJs": true,
"module": "ES2022",
"outDir": "./dist",
- "target": "ES2021"
+ "target": "ES2022"
}
}