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

Try to resolve browserslist config when targets are not specified #10897

Closed
wants to merge 2 commits into from

Conversation

JLHwung
Copy link
Contributor

@JLHwung JLHwung commented Dec 19, 2019

Q                       A
Fixed Issues? Resolves #9962
Major: Breaking Change? Yes
Tests Added + Pass? Yes
Documentation PR Link
License MIT

This PR changes the targets parsing logic when targets are empty. It will now try to resolve any browserslists external configuration and fallback to forceAllTransforms: true when neither targets is specified nor browserslists configuration is resolved.

This PR also generally improves integrations with browserslists: the browserslists.default is never changed during targets parsing. Surprisingly, by doing so we can remove a bunch of dead code.

@JLHwung JLHwung added PR: Breaking Change 💥 A type of pull request used for our changelog categories for next major release pkg: preset-env labels Dec 19, 2019
@JLHwung JLHwung added this to the Babel 8.x milestone Dec 19, 2019
// Note, if browserslist resolves the config (ex. package.json), then usage
// of `defaults` in queries will be different since we don't want to break
// the behavior of "no targets is the same as preset-latest".
if (!hasTargets) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

When hasTargets is false, objectToBrowserslist(targets) always return [].

const browsers = browserslist(browsersquery, {
path: options.configPath,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because browsersquery is never undefined here, browserslists will never loadConfig and therefore we don't need to pass path option here.


if (shouldParseBrowsers || shouldSearchForConfig) {
const browsers = browserslist(browsersquery, {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

When browsersquery is [], it will precede browserslists.default, therefore we don't need to overwrite browserslists.default.

@nicolo-ribaudo nicolo-ribaudo mentioned this pull request Dec 19, 2019
34 tasks
Copy link
Member

@nicolo-ribaudo nicolo-ribaudo left a comment

Choose a reason for hiding this comment

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

I like the change from "down to es3" to browserslist's defaults, but we should put a big warning in the docs that defaults is not a static compilation target.

@JLHwung
Copy link
Contributor Author

JLHwung commented Apr 22, 2020

@nicolo-ribaudo Note that although technically defaults is not static, it is almost invisible for our users as long as IE 11 is still included in defaults, which is accounted for most es6 transformers.

@babel-bot
Copy link
Collaborator

babel-bot commented Jun 23, 2020

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

@codesandbox-ci
Copy link

codesandbox-ci bot commented Jun 23, 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 8a77cda:

Sandbox Source
bold-sid-evzos Configuration
magical-dan-vx7md Configuration

@nicolo-ribaudo
Copy link
Member

Superseded by #12989

@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 Jul 3, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 3, 2021
@JLHwung JLHwung removed this from the v8.0.0 milestone Aug 9, 2023
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: Breaking Change 💥 A type of pull request used for our changelog categories for next major release PR: Ready For Review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Only change browserslist defaults if no config file exists
3 participants