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
Split @babel/runtime into 2 modules via @babel/runtime-corejs2 #8266
Conversation
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/8756/ |
5fd6aec
to
b95564b
Compare
for (const dep of helpers.getDependencies(helperName)) { | ||
const id = (dependencies[dep] = t.identifier(t.toIdentifier(dep))); | ||
tree.body.push(template.statement.ast` | ||
var ${id} = require("${`./${dep}`}"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some helpers redefine the exported function. Does this work in that case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it's a bug, but it's existing and tracked in #8087
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh ok, I didn't realize you just moved around this code
regenerator, | ||
useBuiltIns, | ||
useESModules, | ||
corejsVersion = false, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this option should be named just corejs
? corejs: 2
looks as good as corejsVersion: 2
to me, but corejs: false
looks better than corejsVersion: false
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good. I was on the fence.
|
Do you have strong feelings about specific cases in this PR? The primary issue is that I think the extra dash makes things harder in some cases here, like
I think that's fine. I thought about making it just |
.gitignore
Outdated
!/packages/babel-runtime-corejs2/helpers/es6/iterableToArray.js | ||
!/packages/babel-runtime-corejs2/helpers/es6/temporalRef.js | ||
/packages/babel-runtime-corejs2/core-js/**/*.js | ||
!/packages/babel-runtime-corejs2/core-js/map.js |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For anyone else reviewing, the reason why I added these !
gitignore's earlier is so that we are able to view the changes in output for the runtime since we would change the build script and it had a bug before and we never viewed the diff. But maybe there is a better way to do this since it's hardcoded. Basically we want to catch issues with the script
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good, just will want to document these changes on the website docs for all these packages, and then add to the migration guide which I can help with as well.
@@ -0,0 +1,14 @@ | |||
var _Map = require("@babel/runtime-corejs2/core-js/map"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just a nit and maybe not worth looking into, but do we want to just make the path require("@babel/runtime-corejs2/map")
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I don't love having core-js
repeated twice, but I do think having the core-js stuff grouped into a folder is nice. Do you just want to make it shorter, or is the repetition the part you want to avoid? Thoughts on other names?
Was looking at https://github.com/loganfsmyth/babel/blob/runtime-refactor/packages/babel-runtime and I believe you can delete https://github.com/loganfsmyth/babel/blob/runtime-refactor/packages/babel-runtime/core-js.js? |
const helperFilename = path.join( | ||
pkgDirname, | ||
"helpers", | ||
esm ? "es6" : "", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if the option is named esm
then this directory should be IMHO named esm
too, es6
makes it more confusing because othen than module format those files wont be written using es6 syntax
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good to me. This was just copied over as it was from babel/runtime
@@ -0,0 +1,158 @@ | |||
"use strict"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
imho it's really confusing that this build script is inside of babel-plugin-transform-runtime
package
I understand that this script creates those files in more than 1 package, but as such I would see it being in a top-level scripts and not here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The transform and the build script share the same source of data, which was my motivation. If we split it out, the build script will still have to reach into the transform to get that data, and doing that felt equally awkward.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In that case - feel free to go with whatever u prefer, I would still prefer to have this top-level, but I'm not super attached to it now (because of the reasons u gave)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess we should explain somewhere about running this
Could u explain how |
@Andarist This is just moving the existing logic. We don't currently offer |
This gave me the conclusion that
Why?
Agreed. |
Oh shoot, that's left over from when I was experimenting with support for it. It shouldn't have been committed.
Mostly that the semantics of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good!
0e70926
to
cc8b65a
Compare
Alright I have:
@hzoo You had comments about the @zloirock Any thoughts on my responses to your thoughts above? |
LGTM
I'm ok if we don't change it, I understand it's nice to have it sorted by folder. Not sure I have a better suggestion |
@loganfsmyth sorry for delayed reply. My opinion about kebab-case for |
@zloirock Are there specific instances that you see in this PR that you disagree with? It would make discussions easier to have specific cases to discuss. |
nwb depended on this to have the transform-runtime plugin generate imports which pointed to the absolute path to babel-runtime in nwb's own dependencies, allowing it to serve and build stuff with all devDependencies managed in a global install - is there an alternative way to get Babel to resolve the runtime module when it's not going to be available in |
@insin The original intention of I'd be happy to have an option of some kind (for transform-runtime) to have Babel inject absolute paths. How would you feel about a
Thoughts? |
@loganfsmyth Those both look good to me 👍 Would that also support passing the absolute path, as in |
Hello awesome Babel devs, it'd be awesome to avoid in-range breaking changes, and it would be highly valued and appreciated (so it doesn't break all the stuffs and the things)! Luckily, I share a single build config with my projects, so fixing them was easy. 😃 Is there a way that during an That would be very useful. If that is already the case, then I missed it and it wasn't noticeable enough. |
… to gain in-range breaking changes (babel/babel#8266 (comment))
As disruptive as these changes might be, I think they're totally fair game for a beta release. Being more careful about breaking changes during beta just means it takes longer for Babel 7 to be officially released, which is the goal we're all aiming for. Once we drop the |
While I totally understand that it's frustrating, the entire reason for being in For instance https://semver.org/ calls out
If it were only ever possible to make breaking changes in exact major version bumps, prerelease versions wouldn't exist in the first place. Similarly, https://www.npmjs.com/package/semver#prerelease-tags
As @hzoo mentioned above, npm's behavior around prereleases isn't quite ideal right now, and we've filed npm/rfcs#14 to try to have that addressed in future versions. Once we drop the |
It would not, and I don't know that it's something I'd want to allow, because it should be the runtime transform itself deciding the actual name of the runtime, at least in my opinion. In the context of
to resolve the runtime relative to |
For the absolute-path discussion, I created #8435, so let's continue that over there. |
You're right. This is an interesting case: v7 has been in Beta so long that people are using it like it's not Beta. |
Is there any compatible writting for Renamed the I found some packages would throw an error like:
in which luma.gl@6.3.1 requires a different version of @babel/runtime with my project (the project itself requires an old version of @babel/runtime before v7.0.0-beta56). |
If you (or a dependency who uses directly uses Babel) require a beta version, all your babel packages and the packages used by your deps need to match that beta version. |
Thanks for your reminding, I tried upgraded @babel/runtime's version in my repo, however the same problem reproduced in some dependencies inside the dependencies of my repo, which has got out of my control (I guess those dependencies require an old version of @babel/runtime and use the grammar like I'll look and see if there's some method to solve it, thanks. |
* Split @babel/runtime into 2 modules via @babel/runtime-corejs2 babel/babel#8266 * Only add the `corejs` option when needed, display a warning if not sure * Tpo * Update upgradeConfig.js * Fix merge
In Babel 6, we had
@babel/runtime
which always usescore-js
in its helpers, meaning that anyone who wants to use our helpers in a centralized modular way had to also use core-js, which isn't always ideal.Early in the Babel 7 alpha, we added a
useBuiltins: true
option that would use separate copies of the helpers that would skip loadingcore-js
, but this still requires users to have an indirect npm dependency oncore-js
.This PR splits our setup into two separate runtimes:
npm install --save @babel/runtime
that just includes our helpers, and relies on users to globally polyfill any APIs they need.npm install --save @babel/runtime-corejs2
that includes everything@babel/runtime
does, but also includes a passthrough API forcorejs@2.x
and rewrites all of the helper modules to referencecore-js
.