How can I access a project's babel-related deps from somewhere else?

Viewed 50

This is kind of a strange need, but I don't think it's an X/Y problem. I need to access a project's babel-related dependencies and config from my own tool. My tool might be a devDep, or installed globally, or run with npx; I have no way of knowing.

I know this can be done with babel-register because great tools like babel-tape-runner do it just fine. In my case, though, I can't just require('babel-register') and then require other files; I'm using module._compile under the hood. (Writing out a temp file, running it, and then unlinking isn't really a good option in this case, because it could potentially happen hundreds or thousands of times.)

Is there any way to babelify some code I've read in from somewhere using the user's projects local Babel config and presets and plugins, before passing that stuff to module._compile?

1 Answers
Related