microsoft / tslib

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

chore: Support Node.js ES Modules via conditional exports #87

Closed ExE-Boss closed 4 years ago

ExE-Boss commented 4 years ago

I’ve also added exports mappings for tslib/tslib.js → tslib/tslib.cjs.


Supersedes and closes #44

Resolves #81; closes #84

dasa commented 4 years ago

ping 😄

vikerman commented 4 years ago

Symbolic links don't work since the final resolved path is considered. Also you can't publish symbolic links on npm.

A solution might be to add a prepare step that copies tslib.es6.js to tslib.mjs and the have the conditional export for import point to the .mjs file. I can create a PR if that's acceptable.

ExE-Boss commented 4 years ago

A better option is to just do a ./tslib.js → ./tslib.cjs and ./tslib → ./tslib.cjs exports path mapping: https://github.com/microsoft/tslib/blob/71887cc57cb4c775f60ebbb25720724189f04766/package.json#L35-L36

vikerman commented 4 years ago

Changing the file extension from .js to .cjs is still a breaking change since conditional exports are used only by node and not other tools(and older node).

ExE-Boss commented 4 years ago

That’s why I wanted to get this into v2.0.

vikerman commented 4 years ago

Ok - I shouldn't say breaking change. This change could break the usage of tslib with bundlers and other tools because of the .cjs file extension. Using .mjs for the conditional export would be a safer change.

guybedford commented 4 years ago

Changing file names etc might be considered a breaking change? https://github.com/microsoft/tslib/pull/121 would be fully backwards compatible I believe.

orta commented 4 years ago

Thanks - ES Module support was shipped with #126