Closed Methuselah96 closed 1 year ago
This PR seems good but I remember avoiding the .mjs
file extension for a reason - I'll have to look into why before merging.
I think I made this change to avoid errors when directly importing something like fflate/esm/browser
without an extension in some environments. That was probably more necessary a few years ago than today, but I'd still like to support that behavior for backwards compat. Also, .mjs
gives a bad MIME type in some static file servers, which could be an issue for people who serve fflate
manually.
I think it's possible to fix the types here without switching the file extensions; I'll try to modify this PR to do so.
"Are the types wrong?" reveals that the ESM modules in this package are masquerading as CJS from a type perspective (https://arethetypeswrong.github.io/?p=fflate%400.8.0):
This PR fixes the situation by creating a separate declaration file per module as recommended in the TypeScript documentation:
Creating a declaration file per module fixes the type module resolution and fixes the "Are the types wrong?" tests:
The resulting built files now all specify whether they are CJS or MJS with the corresponding file extension and each module now has a corresponding declaration file which absolves the need to explicitly list them in
package.json#exports
: