-
Notifications
You must be signed in to change notification settings - Fork 128
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
refactor!: remove ufo
dependency
#440
base: main
Are you sure you want to change the base?
Conversation
ufo
with native URL
utilsufo
dependency
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #440 +/- ##
===========================================
+ Coverage 56.86% 67.37% +10.50%
===========================================
Files 16 18 +2
Lines 728 610 -118
Branches 113 162 +49
===========================================
- Hits 414 411 -3
+ Misses 303 188 -115
Partials 11 11 ☔ View full report in Codecov by Sentry. |
src/path.ts
Outdated
const searchIndex = input.indexOf("?"); | ||
const base = searchIndex === -1 ? input : input.slice(0, searchIndex); | ||
const searchParams = new URLSearchParams( | ||
searchIndex === -1 ? "" : input.slice(searchIndex + 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.
fast-path: when there is no searchIndex we can avoid creating new URLSearchParams
(sorry for being strict this is kind of thing we forget later and it can be potentially bases to ufo/lite
trying to make sure optimizing it as much as we can)
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.
Sorry, I don't get it completely: Even if no search is in the input path, we still need to construct the encoded query string for the new output path, am I right?
How should we build the search params if not using URLSearchParams
? Port the stringifyQuery
function from ufo
?
P.S.: Of course, no need to justify optimization and future-proofness. 🙋♂️
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.
Sorry my wording was confusing. I meant that when there is no quesry in input string, we can have a fast path if block. So we don't need to iterate to for example remove undefined
values, etc (we already know query state is empty) so it can be something like return new URLSearchParams(query).toString
(I'm not sure if query object needs normalization but it could be simple map)
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.
Ahh, I get it now! Thanks for the clarification. Now:
- If the query is empty, we return early.
- If the input URL has no query, we only normalize the items of the input
query
object.
Is that what you intended?
We have to normalize the values for URLSearchParams
, otherwise it returns string like key=undefined
. I have again tested with the (slighty changed) ufo
tests. I will create a separate PR there to track the implementation of these lighter functions.
Note
This PR might be better off over at
ufo
. Feel free to close this PR if it should be handled otherwise. I just wanted to share the idea and get some feedback. 🙂Migrating
ufo
to use nativeURL
is already in discussion, which would be beneficial to reduce the bundle size in the whole UnJS ecosystem, I suppose.In @pi0 work on
h3
v2,ufo
is no longer used and path utilities have been internalized to the repo. This might be also an approach forofetch
, since it only uses the following exports:withBase
withQuery
Taking inspiration from the refactors in
h3
v2, both path utilities have been inlined to remove the dependency onofetch
. At the time of writing, one test still fails.