-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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 useBuiltIns and useESModules options to transform-runtime #5442
Conversation
useBuiltIns uses versions of the helpers that do not import even internal polyfills from core-js. useESModules uses versions of the helpers that do not go through transform-es2015-modules-commonjs. This allows for smaller builds in module systems like webpack, as it doesn't need to preserve commonjs semantics. This includes changes to the babel-runtime build-dist script, which will build the versions of the runtime helpers to be used by combinations of useBuiltIns and useESModules.
Hey @Kovensky! It looks like one or more of your builds have failed. I've copied the relevant info below to save you some time. |
Codecov Report
@@ Coverage Diff @@
## 7.0 #5442 +/- ##
==========================================
- Coverage 85.46% 85.42% -0.04%
==========================================
Files 203 203
Lines 9533 9537 +4
Branches 2703 2706 +3
==========================================
Hits 8147 8147
- Misses 899 900 +1
- Partials 487 490 +3
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## 7.0 #5442 +/- ##
==========================================
+ Coverage 85.41% 85.79% +0.37%
==========================================
Files 203 203
Lines 9525 9842 +317
Branches 2703 2832 +129
==========================================
+ Hits 8136 8444 +308
- Misses 902 909 +7
- Partials 487 489 +2
Continue to review full report at Codecov.
|
Maybe we should actually add the generated files to git so we can actually compare what's happening.. Don't know how we can write tests |
Yeah it would be nice if we could diff previous code or diff the options somehow |
Could we add it as a snapshot in the tests? |
0db9529
to
2521244
Compare
I tried committing the files to git, but it would end up creating a huge commit adding 300+ files, and at least 4 of them would need to be updated every single time a helper got changed 😢 I added fixtures for the transform-runtime output, but no idea how babel-runtime could be tested. Any exec test that would pass with transform-runtime would also pass without using transform-runtime at all, and it's not possible to exec-test the useESModules output. |
|
||
function buildRuntimeRewritePlugin(relativePath, helperName) { | ||
return { | ||
pre: function (file) { | ||
var original = file.get("helperGenerator"); | ||
file.set("helperGenerator", function(name) { | ||
// make sure that helpers won't insert circular references to themselves | ||
if (name === helperName) return; | ||
if (name === helperName) return 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.
Why false
?
? `export { default } from \"./${helperName}.js\";` | ||
: "module.exports = require(\"./" + helperName + ".js\");"; | ||
writeFile(`${dirname}_${helperAlias}.js`, content); | ||
if (helperAlias !== helperName) writeFile(`${dirname}${helperAlias}.js`, content); |
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.
We should really kill all these aliases in 7.x. If you're up for it, maybe a PR another this one? Let's keep this separate so if we want to backport it is easier.
This looks awesome to me. The only case that comes to mind is that it's unfortunate people using Let's land this as-is, but it might be good for us to think about if we want to explore making a separate module for "only helpers" and one for "helpers with polyfill" or something. In the long run I'd love to have the helpers currently living in |
preset-env's useBuiltIns option outputs core-js which isn't very intuitive so it would be nice for polyfill to just have the modules. Would the transform easier too cc @zloirock |
Yeah, I took the @loganfsmyth the point of EDIT: oh, you mean literally the npm dependency, rather than the runtime dependency. |
useBuiltIns uses versions of the helpers that do not import even
internal polyfills from core-js.
useESModules uses versions of the helpers that do not go through
transform-es2015-modules-commonjs. This allows for smaller builds in
module systems like webpack, as it doesn't need to preserve commonjs
semantics.
This includes changes to the babel-runtime build-dist script, which
will build the versions of the runtime helpers to be used by
combinations of useBuiltIns and useESModules.
This is untested other than by looking at the output and seeing if it makes sense >_<
{ polyfill: false, useBuiltIns: true, useESModules: true }
will be perfect for webpack/rollupusers that want to deduplicate helpers without accidentally bundling an extra
core-js when babel-polyfill is already in use, or when, say, targeting electron.