hashicorp / next-mdx-remote

Load MDX content from anywhere
Mozilla Public License 2.0
2.67k stars 140 forks source link

v4: Cannot provide filepath to plugins #309

Closed nwalters512 closed 1 year ago

nwalters512 commented 1 year ago

I have a plugin that relies on knowing the path to the file being compiled. In next-mdx-remote v3, I was able to provide filepath via mdxOptions, e.g.:

serialize('# Hello', { mdxOptions: { filepath: '/path/to/file.mdx' } });

As of MDX v2, however, filepath isn't an option anymore, and that's been replaced by passing a VFile object (https://mdxjs.com/migrating/v2/):

filepath is replaced by accepting a VFile or compatible object as the first argument file

I would like to be able to provide a filepath, either by passing a VFile object directly to serialize, or by adding support for a filepath key in the second argument to serialize.

BRKalow commented 1 year ago

So, we do actually construct a VFile instance internally. Maybe we can update serialize() to accept a string or a VFile instance, like MDX's compile() does. Happy to take a look at a PR if you're up to take a crack at it!

nwalters512 commented 1 year ago

@BRKalow great! I opened a PR adding this: #311.