Skip to content
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

Use the babel-plugin-polyfill-* packages in preset-env #12583

Merged
merged 4 commits into from Feb 21, 2021

Conversation

nicolo-ribaudo
Copy link
Member

@nicolo-ribaudo nicolo-ribaudo commented Jan 3, 2021

Q                       A
Fixed Issues? Closes #11823
Patch: Bug Fix?
Major: Breaking Change?
Minor: New Feature?
Tests Added + Pass? Yes
Documentation PR Link
Any Dependency Changes?
License MIT

This PR is now targeting main without any feature flags because now the polyfill packages are transpiled to be compatible with Node.js 6, so they don't introduce breaking changes.

We will still need to update transform-runtime, but that is harder because the babel-plugin-polyfill-* packages don't inject imports to @babel/runtime.

This PR depends on babel/babel-polyfills#50, babel/babel-polyfills#51 and babel/babel-polyfills#52, so I expect CI to fail for now. (EDIT: These PRs have been merged and published)

@nicolo-ribaudo nicolo-ribaudo added PR: Internal 🏠 A type of pull request used for our changelog categories pkg: preset-env labels Jan 3, 2021
@babel-bot
Copy link
Collaborator

babel-bot commented Jan 3, 2021

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/41469/

"opera": "48",
"safari": "10.1",
"samsung": "8.2"
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The targets are now printed multiple times: once by preset-env (for the transform) and one by the polyfill plugin. I could inject a secret parameter used only by preset-env to avoid printing them in the polyfill provider, but I don't think that it's worth the complexity.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, I do think it's worth the complexity :)

import "core-js/modules/es7.object.values.js";
import "core-js/modules/es6.array.map.js";
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure why the old code included these polyfills, but the new one seems correct to me.

@@ -27,7 +27,7 @@
"devDependencies": {
"@babel/core": "workspace:*",
"@babel/helper-plugin-test-runner": "workspace:*",
"babel-plugin-polyfill-corejs3": "0.0.10",
"babel-plugin-polyfill-corejs3": "0.0.11",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@merceyz If I don't update this to 0.0.11, I get this error:

➤ YN0001: │ Error: Assertion failed: /home/nicolo/Documenti/dev/babel/babel/packages/babel-plugin-proposal-async-generator-functions/node_modules/@babel/types cannot merge nodes with different link types

Is it a Yarn bug?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nicolo-ribaudo Yes, looks like a Yarn bug, I will take a look and report back

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the ping, I forwarded it to @larixer as he has a better grip on this part of the codebase


Apparently I didn't send this comment earlier

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nicolo-ribaudo Is this line really needed:
https://github.com/nicolo-ribaudo/babel/blob/polyfill-providers/package.json#L82
I'm afraid with this line you have atypical dependency graph, when there are workspace nodes not only at the beginning of the graph, but deep inside graph and that might make the graph unrepresentable in node_modules layout. I'm still investigating and I'm not fully understand what is happening yet, but the graph you have seems very difficult with this line.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's needed because:

  • @babel/parser doesn't have a dependency on @babel/types, which is used for TS typings (before adding it we need to add/fix different TS types across the monorepo)
  • To avoid failures, yarn uses packageExtensions to add a @babel/types dependency
  • It pulls in @babel/types from npm, causing problems due to nominal types

If the problem is that line, we will fix it at some point and for now we'll make sure to have the same babel-plugin-polyfill-corejs3 in all the packages to help yarn deduping (it's working with this exact setup).

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nicolo-ribaudo Thanks, for now I think its a Yarn bug which should be fixed, I'll let you know when I have more information.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nicolo-ribaudo Looks like the bug happens due to hoisting result is not terminal, if another pass of hoisting is done for this repo the conflict on @babel/types version is gone. I have implemented multi-pass hoisting which finishes when the result is the same on two consecutive hoisting passes here:
yarnpkg/berry#2394
For this repo 3 passes are needed, on the 1st and 2nd pass the hoisting layout changes and on 3rd pass nothing is changed, but it is still needed for algorithm to understand that we have a terminal result.
The downside of this approach is that it is obviously slower, in master hoisting takes 380ms for me, and multi-pass hoisting takes 1.28s. I'm still looking into ways to optimise multi-pass hoisting speed.

@codesandbox-ci
Copy link

codesandbox-ci bot commented Jan 7, 2021

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 735bb3d:

Sandbox Source
babel-repl-custom-plugin Configuration
babel-plugin-multi-config Configuration

@nicolo-ribaudo
Copy link
Member Author

This PR is marked as Internal, but I'd like to land it in a minor release because I'm not really sure that it doesn't include improvements.

@nicolo-ribaudo nicolo-ribaudo added the PR: Ready to be Merged A pull request with already two approvals, but waiting for the next minor release label Feb 1, 2021
This was referenced Mar 11, 2021
@github-actions github-actions bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label May 27, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 27, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated A closed issue/PR that is archived due to age. Recommended to make a new issue pkg: preset-env PR: Internal 🏠 A type of pull request used for our changelog categories PR: Ready to be Merged A pull request with already two approvals, but waiting for the next minor release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants