robatwilliams / es-compat

Check JavaScript code compatibility with target runtime environments
MIT License
64 stars 13 forks source link

Add browserslist options to the rule options #83

Closed lukeapage closed 8 months ago

lukeapage commented 9 months ago

We have a number of browserslist environments and would like some files to be scanned using one environment and some with another.

I can only achieve this by clearing the node cache and re-importing the rule.. Most browserslist tools allow you to pass the environment through.

I added the full API options to the eslint rule options for full flexibility.

I've also added a warning if the browsers list comes back empty - we had missed that when we introduced environments, the tool no longer did anything...

One gotcha with the es2022 test was that the rule tester seems to be async but returns void - so initially it didn't work because the environment variable is changed synchronously which works when re-importing the rule, but not when the testing is done async.. but the new options provide a neater way to test different configurations anyway.

lukeapage commented 9 months ago

I've been trying it out - One problem is that the console logs now happen once per file.

I could memoize getting the target rules, but then it still might flip-flop depending on the size of the memoize cache.

any suggestions?

lukeapage commented 8 months ago

@robatwilliams I've made the changes now. I resolve the comments, wasn't sure if I should do that or you. Let me know if there is anything else.

robatwilliams commented 8 months ago

Released in https://github.com/robatwilliams/es-compat/releases/tag/v3.1.0