Multiple dependencies share Locale.default variable
Closed this issue · 1 comments
If we've got an app where we've got a library that depends on jed/locale and we use jed/locale in our library, when the dependency sets Locale.default and then our app sets it, our app takes priority (shared state).
Take this example:
Start app. Require dependency
Setup jed/locale
I noticed this when I need to return 'unknown' as the default locale in my library. When I imported that into my app, my app set it to 'en-US'. This was a tough one to pin down because of the way Node handles caching require() calls. If you test this with npm link
then you will get 2 different instances. I only noticed this when I cleared my package cache and started having tests fail.
A possible solution is to pass a second parameter to new Locales(supportedLocales)
that would have a per-instance based default.
Released version 0.1.0 that includes the fix for this.