-
Notifications
You must be signed in to change notification settings - Fork 515
fix(@clayui/date-picker): remove moment.js #3306
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
Conversation
|
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 0252a2d:
|
|
Only issue with date-fns is the lack of localization support, but that only really effects our helper function |
|
Going off of size-limit builds, with all dependencies, minified and gzipped
|
Glad you mention this as a possibility. If it could be made to work, that would clearly be a win in terms of size, isolation from the vagaries of third party stuff, and extracting maximum value from the platform. |
I would much rather prefer this. If not possible, I would also prefer to see If, after all, we think |
d067315 to
9eb294b
Compare
|
Alright so I don't think we can get away with strictly native APIs since we allow for the custom date formatting... However, I was able to use just the format and parse functions from Total size with Knowing that we only need parse and format, I stumbled across Total size with Since we really don't rely on heavy date manipulation, I think going with Both libraries score well on ClearlyDefined(licensing) and both seem to be highly supported and popular in the community. Overall, this would take clays total size from 120KB to 56KB. 😱 |
I would then stick with |
|
Removed dayjs and going with Any final issues before merging other than docs? |
|
I haven't checked code-wise, but I agree on principle! ;) |
| import formatDate from 'date-fns/format'; | ||
| import parseDate from 'date-fns/parse'; | ||
|
|
||
| export {formatDate, parseDate}; |
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.
If you write it like this, it becomes obvious that these are just re-exports and not used in this file:
export {default as formatDate} from 'date-fns/format';
export {default as parseDate} from 'date-fns/parse';| export const addMonths = (date: number | Date, months: number) => { | ||
| date = clone(date); | ||
|
|
||
| date.setMonth(date.getMonth() + months); | ||
|
|
||
| return date; | ||
| }; |
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 think we should always export functions in the same way. You have both:
export function a() {
// ...
};and:
export const b = () => {
// ...
};(FWIW, I prefer the former because of hosting.)
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.
Edit (sigh): of course I meant "I do think"...
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 created https://github.com/liferay/eslint-config-liferay/issues/184 to track enforcing this, with the recommendation that we go with export function — but feel free to comment there if you want to advocate the opposite (either way, we should enforce it).
| integrity sha512-xV2bxeN6F7oYjZWTe/YPAy6MN2M+sL4u/Rlm2AHCIVGfo2p1yGmBHQ6vHehl4bRTZBdHu3TSkWdYgkwpYzAGSw== | ||
|
|
||
| moment@^2.21.0, moment@^2.22.2, moment@^2.5.1: | ||
| moment@^2.21.0, moment@^2.5.1: |
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.
So moment is still in here; is it coming in transitively? What does yarn why moment say?
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.
It comes from gatsby.
- "_project_#clayui.com#gatsby" depends on it
- Hoisted from "_project_#clayui.com#gatsby#moment"
- Hoisted from "_project_#@clayui#css#metalsmith-permalinks#moment"
|
@wincent for some reason when I update the syntax to be |
Might be a Babel thing? If you look at the distributed source of "use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = format;
// ... etcMaybe something that will magically start working in the future at some point when some dep gets updated. |
|
@wincent I was hoping it wouldve resolved after the babel dependency updates but seems to still break. I'm just gonna import and then export separately for now and then look more into how our dependencies might be causing this. |
I went with a POC in removing moment by replacing it with
luxondate-fns. We still have a dependency, but its about 50kb smaller than when we used moment.One caveat is that the "format" strings are different, so that would be a breaking change, although we could create some sort of map.
Additionally, I want to see if it'd be possible to just use native APIs, so I will continue on that and see what it requires.
Curious to hear any thoughts on this
1st commit is using luxon2nd commit is using date-fns