-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Upgrade to MDX 2 #7922
Conversation
Hey thanks for working on this. I think the big question is how we release it since MDX v2 has breaking syntax changes. We would also prefer not to bump a major version of all of Parcel just for this though. Two options:
|
From a user perspective, that would preferred. Having two separate packages will introduce confusion and people ending up with MDX 1 in 2023 |
${compiled} | ||
`); | ||
try { | ||
let compiled = await compile(code); |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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.
What about:
The issue with just introducing |
Maybe for Parcel 3? I saw Vite release major version quite often (less than a year). Maybe Parcel can take similar approach. In this way, new projects always get new features and old projects are not affected. Nobody needs to manually configure anything to opt-in or opt-out. Having |
With Parcel 2.9's local plugins, I found it easy enough to have my own little plugin that does exactly want I need it to do: .parcelrc {
"transformers": {
"*.mdx": ["./parcel-transformer-mdx2.mjs"],
},
} parcel-transformer-mdx2.mjs import { default as ThrowableDiagnostic } from "@parcel/diagnostic";
import { Transformer } from "@parcel/plugin";
import { compile } from "@mdx-js/mdx";
export default new Transformer({
async transform({ asset }) {
let source = await asset.getCode();
let codeVFile;
try {
codeVFile = await compile(source, {
development: true,
jsx: true,
providerImportSource: "@mdx-js/react",
});
} catch (e) {
const { start, end } = e.position;
const highlight = {
message: e.reason,
start,
end,
};
if (!(end.line && end.column)) {
highlight.end = { ...start };
}
// Adjust for parser and reporter differences
highlight.start.column -= 1;
highlight.end.column -= 1;
throw new ThrowableDiagnostic({
diagnostic: {
message: "Unable to compile MDX",
codeFrames: [
{
filePath: asset.filePath,
code: source,
codeHighlights: [highlight],
},
],
},
});
}
let code = String(codeVFile);
asset.type = "jsx";
asset.setCode(code);
return [asset];
},
}); It would be great if Parcel supported this out of the box, sure, but I'm no longer blocked on upgrading my dependencies now. |
I publish a MDX 3 transformer plugin, which may be help: https://github.com/EasyWebApp/Parcel-transformer-MDX |
↪️ Pull Request
This upgrades the dependency on MDX to version 2.
💻 Examples
Previous MDX examples should still be applicable.
🚨 Test instructions
Previous MDX tests should still be applicable.
✔️ PR Todo