-
Notifications
You must be signed in to change notification settings - Fork 377
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
use correct fields for entry points in package.json #326
Conversation
The fantasy-land keys are currently not importable when using esmodules available in node 12 and forward, these changes solve the problem. The module field has been removed since it serves no purpose and is not recognized by node. Exports field has been added accoding to the official node js documentation: https://nodejs.org/api/packages.html#packages_conditional_exports Main field is kept for legacy suppoert of node versions 12 and earlier. The types field has been removed since it is not needed. Typescript will find the definitions anyway when using both import and require. This should in theory not be breaking but it is difficult to know if any use case or build tool relies on the undocumented conventions that previoulsy existed in package.json.
The module field was used mainly by bundlers like Webpack, Rollup, etc. In my experience, these tools are slow to update, and their users even slower to install the updated versions. For that reason I chose the seemingly safer approach of just leaving the field in the manifests of the packages that I maintain, although I did no actual research to determine the real impact that makes. Are you sure it's safe to remove this field, @TheLudd ? The rest looks good to me. |
Wouldn't it break for users who are currently importing the cjs (auto compatibility in Node) version using |
That is right, that will not work, but does it today? |
I tried with rollup and that works without the module field. I have no experience of webpack so I could not test it to be sure. We can of course leave it to be on the safe side. But it is explicitly stated in the nodejs documentation that the module field is not supported. https://nodejs.org/api/packages.html#packages_dual_commonjs_es_module_packages
We can also release a new major version that "should not really cause any issues". |
I believe it does, thanks to Node's CJS interrop To make it non-breaking for these users, a default export like |
We could update (
awk '{ print "export const " $0 " = \047fantasy-land/" $0 "\047;" }' names
echo
echo 'export default {'
awk '{ print " " $0 "," }' names
echo '}'
) >index.mjs |
I think that is because today it will go through the main (umd) file. When using the esm file, you have never been able to do If I use rollup with the latest released version of fl and explicitly reuire the esm file I get this error: My code:
The error
|
Ok, so that means that my changes could be considered breaking. Now, I do not like exporting both So my vote is on a new major version. There is a lot of confusion out there about esm and I like packages who do it the right way. That said, if you are set on default export, I can fix that too. |
I agree. Adding the default export is messy overhead for what it's worth. I just wanted to make sure it's clear that this change is going to be breaking for a (probably tiny) subset of users. |
We seem to be discussing two changes that need not be made together. I suggest moving the breaking change to a separate pull request. We could then merge this pull request and release a new version of the package right away. What do you think? |
I don't see how. The change proposed in this pull request (specifying the correct entry points in package.json) is the breaking change. We have discussed a separate change that could be made on top of it, in order to preserve backwards compatibility. Both @TheLudd and I are however in agreement that going forward with the breaking change (made in this PR) without including the compatibility patch is the way to go. |
Thanks, Aldwin. It seems this pull request is ready to merge. :) Could one of you summarize this pull request in a sentence, for the release notes? |
Make fantasy-land compatible with native es modules. |
Thanks for merging. Is it possible to get a version 5 out? |
The fantasy-land keys are currently not importable when using esmodules
available in node 12 and forward, these changes solve the problem.
The module field has been removed since it serves no purpose and is not
recognized by node. Exports field has been added accoding to the
official node js documentation:
https://nodejs.org/api/packages.html#packages_conditional_exports
Main field is kept for legacy suppoert of node versions 12 and earlier.
The types field has been removed since it is not needed. Typescript will
find the definitions anyway when using both import and require.
This should in theory not be breaking but it is difficult to know if any
use case or build tool relies on the undocumented conventions that
previoulsy existed in package.json.