Add ESM module using conditional exports#11
Conversation
There was a problem hiding this comment.
Thanks for your contribution!
In #8 I favored using "option 2" for higher compatibility. I'd like to avoid for users of this library having to set the experimental flag experimental-conditional-exports.
What's the reason that you've favored option 1 over option 2 that promises further compatibility?
|
@TimDaub When the issue mentioned 'option 2' I thought it meant 2.x. I didn't notice the caveat.😅 A reason for implementing option 2.1 was that 2.2 seemed hacky with more than one package.json. I tested things after implementation and didn't have to add the experimental flag. Otherwise I wouldn't have missed the caveat. After some digging, I found that the flag has been removed for node 12.x+. (nodejs/node#31001) Currently I have tested on node v12.22.6 and node v14.17.6. Everything works fine without any warnings. I say we stick with option 2.1. If you think otherwise then I can make changes to this PR. |
|
Thanks for digging. Supporting node >= 12 is sufficient. |
This PR adds support for both CommonJS and ES Modules. Resolves #8
Implementation reference -
https://2ality.com/2019/10/hybrid-npm-packages.html#option-1-(experimental%2C-needs-conditional-exports)%3A-esm-and-commonjs-are-both-bare-imports