Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to MDX 2 #7922

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/core/integration-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"@babel/preset-env": "^7.12.11",
"@babel/preset-typescript": "^7.14.5",
"@jetbrains/kotlinc-js-api": "^1.2.12",
"@mdx-js/react": "^1.5.3",
"@mdx-js/react": "^2",
"autoprefixer": "^10.4.0",
"chalk": "^4.1.0",
"codecov": "^3.0.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/transformers/mdx/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
"parcel": "^2.4.1"
},
"dependencies": {
"@mdx-js/mdx": "^1.6.22",
"@mdx-js/mdx": "^2",
"@parcel/plugin": "2.4.1"
},
"peerDependencies": {
"@mdx-js/react": "^1.6.22"
"@mdx-js/react": "^2"
}
}
17 changes: 8 additions & 9 deletions packages/transformers/mdx/src/MDXTransformer.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
// @flow
import {Transformer} from '@parcel/plugin';
import mdx from '@mdx-js/mdx';

export default (new Transformer({
async transform({asset}) {
let { compile } = await import('@mdx-js/mdx');
let code = await asset.getCode();
let compiled = await mdx(code);

asset.type = 'js';
asset.setCode(`/* @jsxRuntime classic */
/* @jsx mdx */
import React from 'react';
import { mdx } from '@mdx-js/react'
${compiled}
`);
try {
let compiled = await compile(code);
Copy link

@Ayc0 Ayc0 Jul 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feature request:
This plugin should have the possibility to have a 2nd argument options, like the webpack loader: https://mdxjs.com/packages/loader/#options (so that if people want to add custom remarkPlugins or other options, they'll have the possibility to)

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as similar system as done in the Stylus plugin could be used: https://github.com/parcel-bundler/parcel/blob/a6765b2/packages/transformers/stylus/src/StylusTransformer.js#L18-L26

We try to load a .mdxrc.js or .mdxrc.cjs or .mdxrc.mjs file and if found, we disable the config on load with config.invalidateOnStartup(); and this config is then passed to the mdx compiler as a 2nd argument.

asset.type = 'js';
asset.setCode(compiled.value);
} catch (e) {
throw e.toString(); // Adds the line and column number of errors
}

return [asset];
},
Expand Down