Nearing the Babel 7.0 Release
babeljs.io
babeljs.io
Checkout the pipeline operator: https://github.com/babel/proposals/issues/29 (https://github.com/tc39/proposal-pipeline-operator)
That's some cutting-edge stuff. I wouldn't want to use it until it was official, but it's cool to have the opportunity to try TC39 (https://github.com/tc39) proposals via babel. In addition to the normal compiler usage for the latest standards.
> We received a $1k/month donation from Facebook Open Source!
> This the highest monthly donation we have gotten since the start (next highest is $100/month).
When I read this, I kind of mumbled to myself, "that's all?"
It goes to show how poorly funded open source projects are. We rely on these tools, file issues, and want them to work, yet there isn't enough to even pay someone to work on it full time.
https://twitter.com/ShiyaLuo/status/931230821976907776
> Engineer: There's a thing we need in babel, can I spent 2 days with a PR for it
> Company: lol no it's their job
Yep, the problem is cultural. The whole system of reciprocity is out of whack. The system would work more smoothly if more people took on responsibilities, QA'd, contributed patches. Give engineers a % of time to contribute back to the libraries they use.
And yea, contributing back upstream to libraries isn't always glorious as releasing your own stuff, but it's part of what open source is. These big companies (not naming names) would rather make totally new projects than pitch in maintaining current ones. I admit it, it's not fun to do, but it's necessary.
> TL;DR: use babel-preset-env
This is convenient.
I think this need not even be framed just as "the moral thing to do" - in an environment where attracting quality engineers is a continuous challenge, small "sacrifices" like this can be far more effective than spending the same amount of money on raising the potential wage. If a job lists "contribute to Babel maintenance one <time unit> every <time unit>" as one of the responsibilities, that'd make me far more interested.
It's more nuanced than that I'm afraid. I work on tooling for a living, and have in fact tried to contribute back to babel but unfortunately there's so much noise and traffic that there's just as good a chance that your PR is stuck in limbo forever than being merged or even reviewed. I understand why, there's only so much the maintainers can do with the limited time they have, but my point is that you can't just say that the problem is that people aren't contributing. It's a two-way street, and maintainers need to figure out how to actually accept (or reject) contributions as well.
There are other ways to contribute than opening PRs and issues of course, like sending money. But even sending money isn't without complexity -- plenty of companies have the ability to contribute financially, but they can't because they need a VAT receipt or invoice to make it happen. Accounting is a hard requirement for companies, you can't just send money willy-nilly like you can as a private person. It's surprisingly difficult for companies to contribute financially to most projects, and that's not even considering the hard ship of getting those expenses signed off which is often a battle and a half on its own. Babel has a decent set up, but still requires a credit card -- this alone makes it much harder since you'd probably have to personally expense it and then try to get it past accounting.
It's a problem, for sure, but I don't think it's as black and white as you make it seem.
I agree it's a two way street and not all maintainers want to be "purely" what people consider a maintainer role unlike me - but it's a lot of responsibility on their part to have to look at every PR in a certain amount of time. I think contributors could also do more to ask and get involved although it will take more energy on both sides parts: like doing a hangout/video call etc even though it feels like people either maintainer or contributor just think making a PR suffices to get something merged when a lot of times it is so much more.
I think what I'm saying is that if you do get the time to make a PR and if employers allowed it, they should also allow for the time it takes to get through the noise and traffic by helping out with maintenance, not just the bug fixes, or that we need a priority kind of thing so that maintainers/contributors see effort from one another to make it better. Yeah it's definetely not that simple but I think we need more people/companies trying it out to really see what the problems are then just talk about it.
Plenty of people try to contribute but either the receiving end is unreasonably difficult to work with – or, as is perhaps more often the case – simply aren’t responding at all. It’s hard to get on a call where the other end isn’t picking up, as it were.
I’ve seen this first hand several times. Despite numerous attempts to make things as easy as possible to merge, providing ample documentation for the changes, making yourself available etc., the receiving end simply isn’t picking up. At some point you just give up and let it be. Sometimes, I’ve seen my PRs get picked up months or even over a year after initially submitted, at which point even I as the author don’t know what the PR is all about anymore...
A database, for many many companies, is essentially the business. There's nothing more important. Babel, which again I love, at the end of the day lets you write more expressive code. Anyone who thinks fixing a bug that lets you write arrow functions instead of using `Function.prototype.bind` or whatever, is anywhere as important as a database... is just wrong.
Always remember your place. Your job is to make widgets for a company. Your productivity definitely has value, but don't overestimate how much value it has.
A better example would have been something like Resharper, which companies are willing to pay for, but they won't make its bugs an important part of their roadmap.
Understatement of the year. It's not just convenient, it's an absolute gamechanger.
JS gets a shit reputation for being mountains of config before you can do any work, but because of `babel-preset-env` I can start a new project, put `> 5%` in the babel config, and write in the latest and greatest version of JavaScript and have it just work.
But... that has nothing to do with JS and everything to do with the unnecessary complexity added by the ecosystem.
Are developers no longer aware that they can literally just open any text editor and write JS and it will work? That no one actually has to use NPM or Babel or anything?
But building an entire application like that would be insane!
There's websites, and there are web-applications, just like there are small scripts and there are full "applications". Yelling about how it's unnecessary complexity that someone made a python3 program with pip, tox, pyGTK and more when you could just open a text editor and write python 2.7 sounds silly doesn't it? Would you go to the maintainers of a large C project and tell them that CMake is unnecessary when they can just compile from the command line? Or just use make?
You can do that, but having these extra tools, this extra complexity pays off later when the application is larger, or when it needs to be maintained for many years.
Yes, I could just open a JS file and write JS, and I do for some websites, but for larger full applications, I want to use the newer language features, I want a compiler that will translate my code into something that all browsers can run, I want a compiler/linker that can do tree shaking and reduce the code size, I want a framework that makes it easier to architect a full application, I want a CSS module system to help manage the complexity of styling, I want a minifier that can optimize and reduce the size of my code, I want a unit testing framework that can help me prove my code is correct, I want to write in a dialect of javascript that can do type checking, I want a system to compress images to their smallest size for performance during the build process, I want to use packages that others have written, I want to have a cross platform task runner that makes it easy to develop, I want a "hot-reload" system which makes iterating through changes significantly faster, etc...
I want all of that, because the extra hour or 2 setting something up now will pay off when I need to maintain this application for the next decade or more.
A statement like "JS gets a shit reputation for being mountains of config before you can do any work" put my teeth on edge a bit because there's no good reason for that to be the case, given how simple the language is.
It's also completely unsurprising.
Relying on people's good will doesn't work sufficiently. It turns into a tragedy of the commons situation with everyone hoping to get the benefit of the work of others.
There are a few things we need to do like a upgrade tool and some other things that haven't been addressed like how library/module authors should publish to npm (do you include/exclude polyfills, do you compile down to ES5 or start introducing ES6+ code under a different folder or package.json string like "module" or "es2015" which will be out of date, etc)
Also didn't write much about the Typescript support yet but we want to help people use that too if that helps with their development
From what I understood, there is currently nothing to allow both ES5 and ES6 code to be published and let the bundler choose which one to include. Any ideas on how to change this?
Yeah it's mostly a conventional then we have to figure out.
Some people have different "dist" folders like say with redux_- https://unpkg.com/redux@3.7.2/ there is `src`, `lib`, `es`, `dist`.
In package.json, you can specify
"main": "lib/index.js",
"module": "es/index.js",
"jsnext:main": "es/index.js",
"typings": "./index.d.ts",
which a bundler like webpack will look at. The problem now mostly is that "module" assumes es modules but not a specific level of ES/polyfills and we want a way to do that instead. Making a yearly "es2015", "es2016" field seems weird and we want one that is up to date like preset-env?Not only did it slingshot the usable version of the language to the latest version at a time when standards were languishing for years, and it also provided some much needed documentation.
And I genuinely believe that babel had a large effect on the improvement of the language. The process for proposing new language features and getting them proposed was streamlined by babel, and after having looked into the process, it's honestly simple enough that anyone that knows Javascript well enough would be able to submit new proposals.
If yes, in retrospect, was the switch worth it? If no, it might be a way out of the configuration pains.
The issue to blame is https://github.com/facebook/react-native/issues/12590 which has been "iceboxed" and not fixed. In short, I have to patch metro each build, to increase the time it waits before killing babel, since the 5 minute timeout simply doesn't cut it.
Debug builds would take over 30m to transform with babel.
I guess in that case I would suggest not transforming files like ".json" which if it's a wrapper around Babel could do for you automatically? It's not intended to transform JSON since it would just have the same output, not sure how it's related to compiling JS specifically.
It's certainly possible that the babel team was never aware of it, but I'd imagine this has to do with the seemingly exponential growth of transformation time per source KB.
From quick glance, this seems more related to Metro, the packager that React Native uses. It was split out from the React Native repo and the team working on it is extremely receptive. I'd recommend opening a new issue on https://github.com/facebook/metro and linking to the issue in the RN repo.
Indeed, I think it's worth a shot to see if the metro team is more receptive. Thanks for the suggestion.
The "icebox" was automatic after a period of inactivity, if you are still having the problem, they give pretty explicit instructions on how to respond.
Also, that doesn't sound like a Babel issue, as I've compiled JS files that were several MB before without taking an unreasonable amount of time.
> Also, that doesn't sound like a Babel issue, as I've compiled JS files that were several MB before without taking an unreasonable amount of time.
The error is specifically that transformation of the JS times out, so it very much appears to be a babel issue. It might be something specific to the RN preset though.
I encourage everyone to switch to scoped packages if possible, it gives you much more freedom over your name, reduces the chances of typosquatting causing your users problems, and can even help get your name out there a bit more!
It's a no brainer, and I'm surprised more people don't use them.
I think before they were part of the paid npm plain or just not enough information about them, and the questions on what being an npm org meant, etc. Maybe Babel switching to them will help move that forward even?
Reasons to use Babel:
* Babel supports bleeding-edge proposed language features like the pipeline operator, throw expressions, optional chaining, etc.
* Babel lets you run custom transforms like babel-plugin-idx and babel-plugin-rewire.
* Babel gives you more control over exactly which transforms you want to run. In one case, I wanted to disable most transforms, but still had to enable the class transform for interop with CoffeeScript classes. TypeScript would need a custom option for any use case like that.
* Babel supports both Flow and TypeScript.
* Babel is a community project rather than being primarily developed by one company. Microsoft theoretically could make a business decision to stop TypeScript development, but nobody could do that for Flow.
Reasons to use TypeScript:
* From my measurements, TypeScript is quite a bit faster than Babel at compiling ES2017 to ES5. From a quick test, TypeScript took 35 seconds and Babel took 140 seconds when run on my codebase at work.
* TypeScript is probably easier to set up and configure. No individual plugins or presets to install, you just set your compilation target in the config. The TypeScript team has already made the decision about which proposed features (e.g. object rest/spread) are safe to use right now, so there's less decision-making to do in that regard.
* TypeScript is maintained by a full-time team at Microsoft, and there's less risk of the maintainers getting burnt out.
Hmm, I would of thought it would be the opposite but I guess it depends on the setup?
> * TypeScript is probably easier to set up and configure.
Yeah given it's more of a "language" TS can decide on those defaults although you can just make your own preset for your company/project as well. I think we can fix that too with a default/separate thing but not sure yet.
I've actually been hacking on a faster alternative to babel/tsc for simple use cases: https://github.com/alangpierce/sucrase . It has a built-in benchmark (`yarn run benchmark`) with at least one example of where typescript is about 3x faster. So you could look at that config if you want one example to compare the two.
Have you noticed any of the same?
https://github.com/mui-org/material-ui/pull/9453
https://github.com/mui-org/material-ui/issues/9312
https://github.com/mui-org/material-ui/issues/9109#issuecomm...
https://github.com/mui-org/material-ui/issues/9312#issuecomm...
Flow, and probably TypeScript, work best when you do things "the Flow(/TS)" way. MUI authors insist on writing code as they would without Flow, and then inserting Flow in after the fact.
Typed JavaScript does not work well when it's treated simply as vanilla JavaScript with annotations. To be successful, it should be treated as a different (yet similar) language, and written within the confines of what the typed language supports.
The frustrations from the linked attempts at upgrading Flow in MUI stemmed from an insistence on supporting defaultProps through HoCs. This works fine, but requires some slight hacks to get it typed properly. The authors were not willing to make the exchange of implementing these hacks in exchange for an easier upgrade path, as they would have changed the generated documentation.
The contributors of material-ui did not experience an issue with TS because their codebase does not use TS, it only provides external interfaces for it. I am confident they would have experienced similar issues with TS at some point, had it been used for the safety of the library itself instead of just its external API.
There is, at least, an ongoing effort to use TS internally in MUI: https://github.com/mui-org/material-ui/pull/9561