microsoft / tslib

Runtime library for TypeScript helpers.
BSD Zero Clause License
1.26k stars 127 forks source link

Use standard `exports` in `package.json` #183

Closed benmccann closed 2 years ago

benmccann commented 2 years ago

tslib has a module entry in the exports, which is non-standard. It's unclear to me why this has been added or would be needed. I couldn't find any code comments explaining it various entry points. At the very least, it would be nice to add comments explaining this setup. However, I have a very strong feeling it's setup improperly and should be fixed. Looking through the issue tracker, it seems there's quite a lot of packaging issues in this library.

Vite has added support for module to its codebase, but it's a rather messy thing I'd rather not keep around long-term.

weswigham commented 2 years ago

webpack and other bundlers use it - it's for scenarios where the bundler ensures esm and cjs are drop-in replacements for one another, so only loads one copy of a module (the module version), unlike node, which loads two (the require and import version), and we need to take steps to ensure only one copy of the code is loaded (but still presents the right named exports).

It's entirely "standard" in that regard.

weswigham commented 2 years ago

FYI, the node docs page for conditions here may not list module, but it 100% meets the bar for inclusion (it's well supported by a tool in the ecosystem already and a bunch of packages use it, not just tslib) - nobody's added it yet though because it's just an as-requested thing.

benmccann commented 2 years ago

Ok, thanks for the explanation