babel / babel

🐠 Babel is a compiler for writing next generation JavaScript.
https://babel.dev
MIT License
43.27k stars 5.65k forks source link

Warn about unused browsers from `browserslist` in `preset-env` #8545

Open ylemkimon opened 6 years ago

ylemkimon commented 6 years ago

Feature Request

Is your feature request related to a problem? Please describe. @babel/preset-env only uses Android, Chrome, Edge, Firefox, IE, iOS, Safari, Node versions for detecting which transforms to include:

https://github.com/babel/babel/blob/e875fc7bc11ffdb8d5176028ae2b336bf7455c6c/packages/babel-preset-env/src/targets-parser.js#L32-L42

and silently ignores other browsers:

https://github.com/babel/babel/blob/e875fc7bc11ffdb8d5176028ae2b336bf7455c6c/packages/babel-preset-env/src/targets-parser.js#L72-L76

However, there are local-popular or manufacturer-specific browsers such as Opera Mini, UC browser, QQ browser, Baidu browser, and Samsung Internet. Please see https://github.com/browserslist/browserslist/issues/250 for their importance.

In Browserslist default, fortunately, IE 11, Chrome 49 (usage 0.69%) and Android 4.x (4.4 usage 0.58%, 4.4.4 isn't strictly last 2 versions) acts as a stopgap preventing from excluding transform needed for old browsers. However, if user excludes them, they become dead, or their usage drops, preset-env will recognize as if it targets very modern browsers. Also, user may explicitly target them, using Browserslist config.

Describe the solution you'd like Warn users about unused (unsupported, those preset-env doesn't have data) browsers like:

Following browser(s) were selected by Browserslist,
but @babel/preset-env doesn't know about their features.
Please add plugins and built-ins manually, if needed:
{
  "baidu": "7.12",
  "samsung": "7",
}

at least on DEBUG mode.

Then, the user can add necessary plugins and built-ins manually, or update Browserslist to exclude them.

Describe alternatives you've considered For Chromium-based browsers (UC, QQ, Baidu, Samsung), we can use a mapping to Chromium versions, like electron-to-chromium. I've opened an issue at https://github.com/browserslist/browserslist/issues/290. ~I'll open an issue here, if it gets rejected.~ #8552.

Teachability, Documentation, Adoption, Migration Strategy See above

babel-bot commented 6 years ago

Hey @ylemkimon! We really appreciate you taking the time to report an issue. The collaborators on this project attempt to help as many people as possible, but we're a limited number of volunteers, so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack community that typically always has someone willing to help. You can sign-up here for an invite.