-
-
Notifications
You must be signed in to change notification settings - Fork 360
Opt-in ES6 support via babel-register #388
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
Conversation
Hey @benjie, I thought about babel already once, especially to also give es7 capabilities. But, if we're going to support es6/7, then probably someone else wants typescript. Also it is questionable if typescript would have any value in a migration, but this shouldn't be a matter in this dicussion. What I have had in mind the last days was that I wanted to introduce a bit more extensibility of db-migrate, by adding a plugin system. This would solve also some of the other issues, that want things, that won't be included in db-migrate. For example I have been asked once to introduce yaml support for configurations, while I definitely do not want to support this, as I don't want huge bloated project just to support some fancy edge cases, and creating a module that is so awkwardy slow like Let me review this later again and give you a more detailed answer this evening. |
@wzrdtales Cheers for giving this a look. Another option, potentially, is to give Of course if you do that you'd need to re-think the filenames regexp, though you could make that a command line flag such as: Anyway, This PR is so simple you could potentially add |
@benjie I wont merge this, but we talked about the plugins already, those are about to be introduced. In fact basic plugin support does exist already on the master branch (not yet published), so you will be able to publish this as a plugin instead. I will keep this item open and let you know how to publish this as a plugin as soon as this is official. Basically those plugins will be really simple, just see https://github.com/db-migrate/plugin-yaml/blob/master/index.js |
Cool 👍 |
Hook for registering a precompiler together with adding a file extension to be included is now added. See this for an example: In your case, you can also just return null instead as you don't register any new file extensions. |
To help developers there is now also a module called |
Okay; finally got around to creating it: https://github.com/benjie/db-migrate-plugin-babel You're welcome to take ownership of it if you want. |
Cool, @benjie. Thanks for your contribution! You are also free to keep maintaining it, but I am open to take ownership if you want to transfer it, as this plugin is really small I wouldn't mind it though. Just one thing, why didn't you follow the standard and used loadPlugin like it is intended? Was there any reason why? Just asking no offense, in this case it wouldn't make that big of a difference though. Maybe I explain the thoughts behind this method: The Also to note, every plugin removes the loadPlugin method after being called. In your case at this hook, this does not gets called multiple times, but for many other hooks, that would mean that every call would spend the CPU Cycles for the function call of loadPlugin again, if it was not removed. So what is suggested is actually: Either completely omit |
Hi Tobias, At first I was a little confused, you seemed to be advocating for efficiency whilst also suggesting that the plugin should be implemented less efficiently (more object allocations, more CPU cycles, more memory usage). However, I guess what you're saying is that it'd be wise to add the slightly less efficient boilerplate just in case others use this plugin as a template for their own (less efficient) plugins - that seems like a fair trade-off so I've made those changes. I've also removed the unnecessary overwriting of Cheers, Benjie. |
Thanks again for your effort @benjie . |
You're still welcome to take ownership of this plugin; I'm still using it but have never needed to change it 👍 |
Could you guys add a minimal tutorial on how to "install" this plugin? I'm having a hard time figuring out how to actually get it to run |
Ok so i figured out that it is enough to just install the corresponding npm package if its name begins with |
I think you can |
Wow, I never realized you can just install repos as npm packages. It works that way, thank you! Edit: |
I've pushed it to npm now too 👍 |
Fixes #289
Possibly removes the need for #340?
I was trying to find the easiest way to support the new import/export syntax via Babel from within the migrations so that they would pass my ESLint rules and be consistent with the rest of my app. I remembered that you've had coffee-script support for ages, so I figured it might be possible to add Babel support the same way; and it worked!
To use it, the user would opt-in by doing
npm install babel-register
- that's all.I don't think this breaks backwards compatibility since babel runs vanilla ES3/ES5 javascript code just fine; so whether or not the project has
babel-register
installed already I don't see any negative consequences (except an almost negligible performance cost?)I couldn't add tests for this because that would require modifying the package.json to require
babel-register
and thus all tests would then use babel's parser.If you think this is a good idea I'd be happy to update the relevant docs with a couple sentences about it - just point me to the relevant places.