-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
feat: add resolvePath
export
#9949
Conversation
…o a relative path
🦋 Changeset detectedLatest commit: 110d716 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
* @param {Record<string, string>} params | ||
* @returns {string} | ||
*/ | ||
export function resolvePath(id, params) { |
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.
Since we call it route id in other places I think it would make sense to reuse that nomenclature here
export function resolvePath(id, params) { | |
export function resolveRoute(id, params) { |
Alternatively even resolveRouteId
.
Thoughts?
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 think resolvePath
is correct — we're resolving a path from a route ID + some parameters.
That said, resolvePath
sounds like path.resolve
, i.e. you might expect to see resolvePath(base, relative)
. I don't know if there's a good name for this that doesn't sound clunky and un-SvelteKit-like.
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.
Yeah, that was my reasoning as well, Rich -- I think the current name is a good mix of what it does and brevity, and the example is pretty darn clear
packages/kit/src/exports/index.js
Outdated
* @returns {string} | ||
*/ | ||
export function resolvePath(id, params) { | ||
return resolve_entry(id, params); |
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.
rather than calling the function indirectly like this, we should either a) re-export it or b) put the implementation here, and use that internally instead of resolve_entry
(probably better, though a more significant change)
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.
Agreed, let's put the implementation here. Makes it more clear that changing the implementation affects the public API.
Co-authored-by: Rich Harris <[email protected]>
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.
ugh i just realised that this doesn't show up in the docs, because we also need to update ambient.d.ts
this fuels my desire to build the missing library for generating .d.ts
bundles with declare module
from source #9895 (comment)
ah i tell a lie, it's not |
Why is the second argument optional? |
The second argument isn't optional, but the values of that record are because because optional route params are optional, so if you wanted to |
ohhh i read it as |
Woohoo! That was fast. |
Closes #9934.
Adds a
resolvePath
export for building relative paths from route IDs and params:Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
Tests
pnpm test
and lint the project withpnpm lint
andpnpm check
Changesets
pnpm changeset
and following the prompts. Changesets that add features should beminor
and those that fix bugs should bepatch
. Please prefix changeset messages withfeat:
,fix:
, orchore:
.