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

Add js extension to preset-env generated polyfill imports #10862

Merged

Conversation

JLHwung
Copy link
Contributor

@JLHwung JLHwung commented Dec 11, 2019

Q                       A
Fixed Issues? preset-env generated esm polyfill imports will throw on Node.js 13, fixes #12378
Patch: Bug Fix? Yes
Tests Added + Pass? Yes
License MIT

In this PR we add .js extension to the injected polyfill imports by @babel/preset-env. The new import specifier path/to/polyfill.js could cause trouble for AMD module compatibility (see #10832 ) but practically it is okay in this scenario because both our upstream polyfills: core-js and regenerator do not support amd.

Note that this PR is different than #10549 which handles transform-runtime instead.

/cc @rwjblue

@JLHwung JLHwung added PR: Bug Fix 🐛 A type of pull request used for our changelog categories pkg: preset-env labels Dec 11, 2019
nicolo-ribaudo added a commit to babel/babel-polyfills that referenced this pull request Mar 20, 2020
nicolo-ribaudo added a commit to babel/babel-polyfills that referenced this pull request Apr 17, 2020
nicolo-ribaudo added a commit to babel/babel-polyfills that referenced this pull request Apr 17, 2020
@@ -152,11 +152,11 @@ export function isPolyfillSource(source: ?string): boolean {
}

const modulePathMap = {
"regenerator-runtime": "regenerator-runtime/runtime",
"regenerator-runtime": "regenerator-runtime/runtime.js",
Copy link
Member

Choose a reason for hiding this comment

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

regenerator-runtime works in browsers, so it currently works with AMD I think.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

regenerator-runtime/runtime.js does not use define to declare its name and dependencies, if any. So I guess it is likely that no one consume it as an AMD module.

@JLHwung JLHwung changed the base branch from master to main November 20, 2020 15:14
@JLHwung JLHwung force-pushed the add-js-extension-to-polyfill-imports branch from 2515fce to 4f7bb76 Compare November 20, 2020 15:16
@babel-bot
Copy link
Collaborator

babel-bot commented Nov 20, 2020

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

@codesandbox-ci
Copy link

codesandbox-ci bot commented Nov 20, 2020

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 f8afd66:

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

@nicolo-ribaudo
Copy link
Member

nicolo-ribaudo commented Dec 2, 2020

You need to patch the vue e2e test similarly to what we did in e2e-create-react-app.sh, since this PR is making those tests failing.

@sodatea This PR will make vue-cli tests fail (https://app.circleci.com/pipelines/github/babel/babel/4604/workflows/bae839be-16f9-4ea1-975b-2477fb57eaff/jobs/33616/parallel-runs/0/steps/0-103), since they test that the code produced by Babel contains an exact substring changed by this PR.
Note that this isn't a breaking change, since we never give any guarantee about the exact output.

@sodatea
Copy link
Contributor

sodatea commented Dec 4, 2020

@nicolo-ribaudo Thanks for the caution! I've fixed the tests.

@existentialism
Copy link
Member

existentialism commented Dec 10, 2020

@JLHwung mind fixing the conflicts?

EDIT: @nicolo-ribaudo i dunno what you're talking about ;)

@nicolo-ribaudo
Copy link
Member

@existentialism I think you pinged the wrong person 😛

Btw, fixing the conflicts probably also fixes the e2e tests, since they are failing exactly in those two files.

@JLHwung JLHwung force-pushed the add-js-extension-to-polyfill-imports branch from 4f7bb76 to f8afd66 Compare December 10, 2020 16:51
@nicolo-ribaudo
Copy link
Member

Spammish, but tomorrow it's the birthday of this PR 🥳

@nicolo-ribaudo nicolo-ribaudo merged commit 1382437 into babel:main Dec 10, 2020
@nicolo-ribaudo nicolo-ribaudo deleted the add-js-extension-to-polyfill-imports branch December 10, 2020 19:16
@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 Mar 12, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 12, 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: Bug Fix 🐛 A type of pull request used for our changelog categories
Projects
None yet
Development

Successfully merging this pull request may close these issues.

core-js 3 missing .js extension when 'type': 'module'
5 participants