manuelmhtr / countries-and-timezones

Minimalistic library to work with countries and timezones data
MIT License
224 stars 67 forks source link

Fix ESM packaging #36

Closed kherock closed 3 years ago

kherock commented 3 years ago

Since v3.0, the build distributed on NPM are a bit broken:

  1. The esm folder imports from ../src, which is excluded from the package
    • this prevents bundlers and ESM-native runtimes from being able to resolve anything
  2. the ESM is just re-exporting properties from a monolithic object, which prevents tree shaking for most bundlers

To fix this, I've converted the source code to ESM and modified the rollup config, adding an ES modules target. I've also made the default builds unminified for debugging purposes.

kherock commented 3 years ago

This is finally ready again. I hadn't realized that the unit tests using proxyquire weren't working, but I think I came up with a pretty effective workaround.

I also will be using the types that were recently added and had some tweaks for them. Let me know if they don't seem right. My main criticism is that they're too tolerant of nullish values. The actual implementations aren't null safe because the following are type errors:

countries[undefined]; // Type 'undefined' cannot be used as an index type
countries[null]; // Type 'undefined' cannot be used as an index type

Therefore argument values used to index dictionaries shouldn't be nullable.

manuelmhtr commented 3 years ago

Amazing, @kherock. Changes are now available in v3.2.1. Thanks a lot!