Skip to content

Conversation

paolostyle
Copy link
Contributor

@paolostyle paolostyle commented Jan 21, 2025

Description

Linked issue: #5177, #5128, #5326

Problem

This PR is a second attempt after #5326 to update date-fns to the latest version, v4.1.0. Dependabot update breaks the docs website (which is a separate topic in itself, the build system over there is extremely outdated - happy to help with that), my changes fix these issues so the website is still functional (this time for real, I triple checked).

Changes

  • bumped date-fns version in package.json
  • adjusted exports in package.json, namely removed browser field entirely and added more modern exports field
  • removed the logic in Rollup that marks date-fns exports as external
  • fixed UMD build so it actually works (it was probably broken for a very long time, though)
  • adjusted imports to use date-fns directly, also in tests for consistency

To reviewers

So it turns out that the main cause of the docs page failing after all was the browser field in package.json. It was pointing to the UMD build, which just wouldn't work with date-fns after the update. It points browser to an ESM file exporting all the other ESM files with individual functions. ESM and UMD are not compatible with each other (oh well), so there was just no way it would work.

What I did is I simply removed the browser field. I honestly think it was just used incorrectly until now. We could keep it (pointing to the ESM build) but if browser field is missing bundlers use module field anyway, and some (namely esbuild) have additional behavior where they can use main instead if imported with require. From what I've checked most frontend libraries nowadays tend to omit this field, but if you REALLY want to keep it, I can - just need to change it to the ESM build.

I kept the changes from previous PR, namely using only main date-fns export as an import source. This is part of the "fixing UMD bundle" effort which I decided to do as soon as I found out... it doesn't work at all. Or I guess it could work but it would require an enormous amount of effort. After extending the globals field in Rollup config it's now doable to use it with only CDN-imported dependencies.

I also added the exports field which I initially thought was relevant to this. It is not, however I think it's still valuable to keep it. If you'd prefer to do it in a separate PR (I will open one tomorrow re/ docs site), I can do that, too.

I think that's all.

Contribution checklist

  • I have followed the contributing guidelines.
  • I have added sufficient test coverage for my changes.
  • I have formatted my code with Prettier and checked for linting issues with ESLint for code readability.

Copy link

@pullrequest pullrequest bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ This pull request was sent to the PullRequest network for review. Expert reviewers are now being matched to your request based on the code's requirements. Stay tuned!

What to expect from this code review:
  • Comments posted to any areas of potential concern or improvement.
  • Detailed feedback or actions needed to resolve issues that are found.
  • Turnaround times vary, but we aim to be swift.

@paolostyle you can click here to see the review status or cancel the code review job.

Copy link

@pullrequest pullrequest bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PullRequest Breakdown

Reviewable lines of change

+ 111
- 105

69% TypeScript
13% JavaScript
7% JSON
6% TSX (tests)
5% TypeScript (tests)

Generated lines of change

+ 5
- 5

Type of change

Feature - These changes are adding a new feature or improvement to existing code.

@paolostyle paolostyle changed the title chore(deps): upgrade date-fns to v4.1.0 chore(deps): upgrade date-fns to v4.1.0 (attempt no. 2) Jan 21, 2025
Copy link

codecov bot commented Jan 21, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.87%. Comparing base (94e2931) to head (d707d7d).
Report is 9 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5332      +/-   ##
==========================================
- Coverage   96.92%   96.87%   -0.06%     
==========================================
  Files          30       30              
  Lines        3416     3358      -58     
  Branches     1427     1431       +4     
==========================================
- Hits         3311     3253      -58     
+ Misses        105      103       -2     
- Partials        0        2       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

@pullrequest pullrequest bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no concerns with this pull request.

Image of Jacob Jacob


Reviewed with ❤️ by PullRequest

Comment on lines +29 to +32
"react-dom": "ReactDOM",
clsx: "clsx",
"date-fns": "dateFns",
"@floating-ui/react": "FloatingUIReact",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These seem new, are these required?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They make the UMD build work in non-bundler environments. So not strictly necessary in the context of this PR but overall I think they should be kept

@martijnrusschen martijnrusschen merged commit d040c84 into Hacker0x01:main Jan 21, 2025
6 checks passed
@paolostyle paolostyle deleted the date-fns-v4 branch January 21, 2025 10:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants