-
Notifications
You must be signed in to change notification settings - Fork 9
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
Fix broken tree shaking for legacy parse #15
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks
@dkozickis @kossnocorp @silvenon Could you do us a huge favour and review and merge this? It's a relatively low-risk change that has a big impact, without this change we're not able to move forward with our date-fns upgrade, unless we remove date-fns/upgrade as a dependnecy. |
Needed to fix tsconfig module resolution, wonder if that is why the old style import was used to begin with. We're now using this version in prod published as date-fns-upgrade-treeshaking@1.0.8, so should be good to go now |
Could you help reviewers understand what the problem is and how these changes fixes it? I think it would greatly increase the chances of merging. |
Imports the whole module and doesn't get tree-shaken by Webpack.
There is no more need to tree-shaken because we're now importing from a single dedicated file. The changes to the config were necessary to facilitate those changes as TS is a bit fickle in its module resolution logic. date-fns exports isDate on the |
Adding an ES build of this library seems like a more natural solution for this problem, that way people won't end up with two copies of |
@silvenon Not sure I understand? date-fns currently doesn't have an ESM build: https://unpkg.com/browse/date-fns@2.21.1/isDate/ You're right that if:
Was ESM, we would need to do this change, but the fact that date-fns didn't add an ESM build up until now, leads me to believe this is an intentional decision. Arguably, we'd still want to import by submodules as this is still more reliable than tree shaking. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know how to get to it with unpkg's browse feature, but date-fns/esm/isDate/index.js
appears to exist, but now I realized that date-fns/esm/isDate/package.json
points ESM-enabled tools to date-fns/esm/isDate/index.js
anyway, so there's no problem, my bad! 😃
Only now I realized I don't have merging rights. 🤦♂️ 🤦♂️ 🤦♂️ @dkozickis |
Ah it does have ESM, missed that... I just noticed that date-fns/upgrade didn't tree shake properly when bundle analysing, I'm not quite sure why it doesn't tree shake https://unpkg.com/date-fns@2.21.1/esm/index.js looks fine, but Webpack can be a bit fickle sometimes, it's better to just use the submodule import instead. |
Because |
Adding ESM sounds like a good follow-up task on this project, but has significantly bigger scope and as a result a higher risk profile. |
Fixes #14