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

browserslist returns default config for unrecognised environments #559

Open
sgomes opened this issue Nov 25, 2020 · 4 comments · May be fixed by #560
Open

browserslist returns default config for unrecognised environments #559

sgomes opened this issue Nov 25, 2020 · 4 comments · May be fixed by #560
Milestone

Comments

@sgomes
Copy link

sgomes commented Nov 25, 2020

Background

browserslist conveniently allows for keeping different lists, through different environments. These can be defined in any one of the locations that browserslist searches, such as package.json.

They can then be used by doing e.g.:

browserslist(undefined, {env:'my-env'});

Description of the issue

If the provided environment (my-env, in the example above) isn't defined everywhere, browserslist will return the default list of browsers, rather than providing any sort of indication that the list is missing. This can lead to hard-to-find bugs in client code if for some reason the browserslist configuration isn't present, such as not having been copied to a production environment.

How to reproduce

  • Run browserslist(undefined, {env:'missing-env'}); without having missing-env defined anywhere
  • Observe the response

Expected result

An error or an empty list.

Observed result

The default browserslist configuration. In my particular version:

[
  'and_chr 84',        'chrome 87',
  'chrome 86',         'chrome 85',
  'chrome 84',         'chrome 83',
  'edge 84',           'edge 83',
  'firefox 81',        'firefox 80',
  'firefox 79',        'firefox 78',
  'ios_saf 13.4-13.5', 'ios_saf 13.3',
  'opera 69',          'opera 68',
  'safari 13.1',       'safari 13'
]

Next steps

I'm more than happy to work on a PR to fix this issue, but it would likely be best to reach a consensus first on what the correct behaviour should be:

  • The current behaviour
  • Throwing an error
  • Returning an empty list

Thank you!

@ai
Copy link
Member

ai commented Nov 25, 2020

Yeap. Let’s throw an error in the next major release.

@ai ai added this to the 5.0 milestone Nov 25, 2020
@ai ai added the enhancement label Nov 25, 2020
@sgomes
Copy link
Author

sgomes commented Nov 25, 2020

Thank you for the super quick reply, @ai! 👍

Shall I prepare a PR, or is this something you'd prefer to handle yourself?

@ai
Copy link
Member

ai commented Nov 25, 2020

Yeap, PR will be very helpful.

But be ready, that it could take a few months before the next major update.

It is hard to make major releases of Browserslist, since we need to force all tools to switch to new versions (to avoid the case, when different tools parse Browserslist config differently because of different Browserslist version).

@sgomes
Copy link
Author

sgomes commented Nov 25, 2020

No worries at all, I'm happy to prepare the PR and have it sit in limbo until it's time for the next major release 🙂

Thanks again, @ai!

@sgomes sgomes linked a pull request Nov 25, 2020 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants