-
-
Notifications
You must be signed in to change notification settings - Fork 233
refactor: add proper route segments for package code #1301
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
base: main
Are you sure you want to change the base?
refactor: add proper route segments for package code #1301
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
2 Skipped Deployments
|
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughThis PR replaces the array-based Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 1✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches🧪 Generate unit tests (beta)
Comment |
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.
Actionable comments posted: 2
🧹 Nitpick comments (1)
app/pages/package/[[org]]/[name].vue (1)
519-533: Avoid non‑null assertions when splitting package names.The split array indices are asserted with
!. Prefer explicit guards to keep index access type‑safe and avoid unexpected runtime issues when the name is malformed.
As per coding guidelines, "Ensure you write strictly type-safe code, for example by ensuring you always check when accessing an array value by index".♻️ Suggested refactor
-const linkCode = computed((): Parameters<typeof navigateTo>[0] | null => { - if (pkg.value == null || resolvedVersion.value == null) { - return null - } - const split = pkg.value.name.split('/') - return { - name: 'code', - params: { - org: split.length === 2 ? split[0]?.replace(/^@/, '') : undefined, - packageName: split.length === 2 ? split[1]! : split[0]!, - version: resolvedVersion.value, - filePath: '', - }, - } -}) +const linkCode = computed((): Parameters<typeof navigateTo>[0] | null => { + if (pkg.value == null || resolvedVersion.value == null) return null + + const [first, second] = pkg.value.name.split('/') + const isScoped = pkg.value.name.startsWith('@') && !!second + const packageName = isScoped ? second : first + if (!packageName) return null + + return { + name: 'code', + params: { + org: isScoped ? first.replace(/^@/, '') : undefined, + packageName, + version: resolvedVersion.value, + filePath: '', + }, + } +})
app/pages/package-code/[[org]]/[packageName]/v/[version]/[...filePath].vue
Show resolved
Hide resolved
c7a2dab to
b08b19d
Compare
|
this is absolutely something we should be doing - would you check the failing CI? |
28eda99 to
7648ef9
Compare
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
|
Ok, so unfortunately there is no elegant way to enforce the @danielroe should be fine now. |
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.
Actionable comments posted: 3
app/pages/package-code/[[org]]/[packageName]/v/[version]/[...filePath].vue
Show resolved
Hide resolved
|
seems like a couple of good comments from @coderabbitai 🙏 |
|
Tip For best results, initiate chat on the files or code changes.
|
|
Tip For best results, initiate chat on the files or code changes.
(ノ◕ヮ◕)ノ*:・゚✧ 🐰 |
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.
Actionable comments posted: 1
app/pages/package-code/[[org]]/[packageName]/v/[version]/[...filePath].vue
Outdated
Show resolved
Hide resolved
|
there may be some patterns here: #158 (comment) |
|
@danielroe should I try to make this work before? Behavior and types are working fine now. We just lack the enforcement of the |
|
@danielroe should all be fine now. My suggestion would be to merge this and I'll create an issue for the |
This is the first step to get rid of the catch all segments in routing.
If this looks good and we want to continue like this, I would like to change all routes to be properly described. Once they are all converted, a lot of the manual path splitting and build code can disappear and we can just pass around the route objects which should remove a lot of boiler plate code. It also will improve typing.
This also "fixes" the escaping of the slash in package names with an org.