-
Notifications
You must be signed in to change notification settings - Fork 18
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
Add hint to add babel-register prior to using it #25
Conversation
Thanks for your PR. I rebased it to fix the build error. If the instructions you added work, we should add it to the ~ yarn global add babel-register
yarn global v0.24.4
warning No license field
[1/4] 🔍 Resolving packages...
[2/4] 🚚 Fetching packages...
[3/4] 🔗 Linking dependencies...
[4/4] 📃 Building fresh packages...
warning "[email protected]" has no binaries
warning No license field
✨ Done in 2.76s.
~ touch foo.js
~ codemod -r babel-register foo.js
Error: Cannot find module 'babel-register' from '/Users/donovan'
at Function.module.exports [as sync] (/Users/donovan/.config/yarn/global/node_modules/resolve/lib/sync.js:40:15)
at getRequirableModulePath (/Users/donovan/.config/yarn/global/node_modules/babel-codemod/src/Options.js:188:26)
at Function.parse (/Users/donovan/.config/yarn/global/node_modules/babel-codemod/src/Options.js:141:35)
at /Users/donovan/.config/yarn/global/node_modules/babel-codemod/src/index.js:60:41
at Generator.next (<anonymous>)
at /Users/donovan/.config/yarn/global/node_modules/babel-codemod/src/index.js:7:71
at __awaiter (/Users/donovan/.config/yarn/global/node_modules/babel-codemod/src/index.js:3:12)
at run (/Users/donovan/.config/yarn/global/node_modules/babel-codemod/src/index.js:59:12)
at Object.<anonymous> (/Users/donovan/.config/yarn/global/node_modules/babel-codemod/bin/codemod:5:1)
at Module._compile (module.js:571:32) If we did want this to work I suppose we could use something like |
yeah you're prob right. Backstory: However, I think we still need to do something here, because if you pull from my plugin repo, install ~/babel-plugin-add-name-to-plugin/src/index.js:18
export default function ({ types: t }) {
^^^^^^ ... which is not what we want. I haven't had a chance to dig in more in detail on how to resolve it, but maybe you'd have tips for me? (and I can update this PR accordingly with the appropriate thing once we have the right way) thanks btw for the cool project! |
@sarupbanskota if you run your |
@mcMickJuice nope, same error :( I did the following:
|
Do you have a .babelrc that has the appropriate plugins/presets to transpile your code? babel-register looks for this file and appropriate plugins to modify your code. |
@mcMickJuice That was it :-) I still feel we should make the following clearer. In my case I had to do:
{
"presets": ["env"]
} |
It seems like that's too much to expect people to do. Maybe having an option that specifically tries to just make it work would be good? Something like |
so eschew babel-register in favor of directly referencing a babel plugin(s)? Would it be reasonable to just look for a .babelrc file and apply those presets/plugins if it exists? My impression (and how I use babel-register with this library) is I have a separate project where I write my codemods. I then am then modding files that are in an adjacent project. My codemod script is run via npm scripts in this codemod project and all dependencies are installed locally and there are no globals. Is the point of this PR/thread to include documentation around how to use babel-codemod in this way? |
In my opinion, that's the right way to do this. Your codemods should be in a separate project from the code being modified. This However, a different setup – or a one-off codemod – makes this more annoying. What I was suggesting is having this project understand that you may want to load plugins written with future JS syntax and that it will just figure out how to make that happen, presumably using babel-register and babel-preset-env internally. |
I think that'd work great. So to clarify, in this situation the
This feature would then be that switch, essentially and it wouldn't be necessary for users to have a project setup with those plugins installed and a . Is that what you're after? |
Yep! Sounds right to me. I'm not sure what the right way to do that is, but I'd love to hear suggestions. |
Cool. Should we create a feature issue and move the discussion over there? Sorry to hijack your PR thread @sarupbanskota :smiley |
Yep, just created #29. I'll close this since there isn't really a clear way forward. |
haha, no worries folks. thanks for taking this forward! i'll try to contribute code towards this if I can manage time this week and if isn't already taken care of! |
Since #31 was just merged and babel-register is used internally, this issue is now moot. Hopefully you find it easier to develop codemods with auto transpilation of plugins! |
No description provided.