Skip to content

Conversation

@CompuIves
Copy link
Contributor

@CompuIves CompuIves commented Sep 3, 2018

For a rehype plugin I'm working on I need the path of the current file being transpiled, I use it to resolve imports. This adds the filename info to the process function which allows plugins to access it.

@vercel
Copy link

vercel bot commented Sep 3, 2018

This pull request is automatically deployed with Now.

To access deployments, click Details below or on the icon next to each push.

Copy link
Member

@wooorm wooorm left a comment

Choose a reason for hiding this comment

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

Looks good, I have a few questions/tips though. Let me know what you think!

if (opts.filename) {
fileOpts.path = opts.filename;
}
const file = vfile(fileOpts);
Copy link
Member

Choose a reason for hiding this comment

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

On thing that may make this cleaner, and remove the vfile dependency, is that you pass fileOpts directly into .process / .processSync, no need to wrap yourself!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmmmmm that's true, that would make the API not backward compatible though because it would need to be wrapped in {content}. It feels a bit less straightforward, but I can change it!

Copy link
Member

Choose a reason for hiding this comment

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

would it not? .process and .processSync accept both, and create a vfile from either? Maybe I’m missing something!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Whoops, you're right!

@CompuIves
Copy link
Contributor Author

Bedankt voor de review!

I'll process the comments this evening 😄

@CompuIves CompuIves force-pushed the add/filename-info branch 2 times, most recently from 7afca58 to 18644ff Compare September 6, 2018 20:05
@CompuIves
Copy link
Contributor Author

CompuIves commented Sep 6, 2018

Hey! I processed the parameter to filepath, but when I changed the fileOpts to not use vfile the test seemed to fail. I'm not sure if it takes the path info if it's not a vfile. I put the vfile constructor back and it seemed to work.

Never mind! That was my mistake, I processed all feedback now!

@CompuIves CompuIves force-pushed the add/filename-info branch 2 times, most recently from 1b95128 to 9c4d7b8 Compare September 6, 2018 20:10
const compiler = createCompiler(opts)

const { contents } = compiler.processSync(mdx)
const fileOpts = { contents: mdx };
Copy link
Member

Choose a reason for hiding this comment

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

This looks amazing! You could pass {contents: mdx, path: opts.filepath}, but that's just nitpicking.

Looks great, lekker bezig!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm yes, I didn't do it in this case since the mdx transpiler didn't work for me when path: undefined. I can still change it since that's probably something that won't often happen, but this one is more correct methinks.

Also, dankjewel :D! Leuk om zoveel Nederlanders hier te zien!

Copy link
Member

Choose a reason for hiding this comment

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

Weird! Well then it’s fine! En ja, klopt! 👍

@johno
Copy link
Member

johno commented Sep 7, 2018

Thanks, this looks great!

@johno johno merged commit 13977e4 into mdx-js:master Sep 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants