-
-
Notifications
You must be signed in to change notification settings - Fork 110
feat: custom param name #774
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?
Conversation
WalkthroughAdds an optional Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: Organization UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
commit: |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #774 +/- ##
==========================================
- Coverage 73.06% 73.04% -0.02%
==========================================
Files 30 30
Lines 2421 2423 +2
Branches 847 849 +2
==========================================
+ Hits 1769 1770 +1
- Misses 545 546 +1
Partials 107 107 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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: 0
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/core/context.ts (1)
220-238: Critical: Watcher must use customgetNamefunction.The watcher doesn't use the custom
getNamefunction, only the initial scan does. This creates inconsistent naming:
- Initial scan uses custom
getName(lines 136-139)- Watcher 'add' uses default
parsePathe(file).name(line 224)- Watcher 'unlink' uses default
parsePathe(file).name(line 235)This breaks the feature when files are added/removed after startup.
🔎 Proposed fix
function setupParamParserWatcher(watcher: FSWatcher, cwd: string) { logger.log(`🤖 Scanning param parsers in ${cwd}`) + const getName = + options.experimental.paramParsers?.getName || + ((file: string) => parsePathe(file).name) return watcher .on('add', (file) => { - const name = parsePathe(file).name + const name = getName(file) const absolutePath = resolve(cwd, file) paramParsersMap.set(name, { name, typeName: `Param_${name}`, absolutePath, relativePath: './' + relative(options.root, absolutePath), }) writeConfigFiles() }) .on('unlink', (file) => { - paramParsersMap.delete(parsePathe(file).name) + paramParsersMap.delete(getName(file)) writeConfigFiles() }) }
🧹 Nitpick comments (1)
src/options.ts (1)
246-251: Minor documentation inconsistency.The JSDoc references
path.parse(file).namebut the actual implementation usesparsePathe(file).name. Consider updating the documentation for consistency.🔎 Proposed documentation fix
/** * Method to generate the name of the param matcher. * - * @default `(file) => path.parse(file).name` + * @default `(file) => parsePathe(file).name` */ getName?: (file: string) => string
📜 Review details
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
src/core/context.tssrc/options.ts
🧰 Additional context used
🧠 Learnings (4)
📚 Learning: 2025-08-23T12:54:44.918Z
Learnt from: posva
Repo: posva/unplugin-vue-router PR: 700
File: src/core/context.ts:109-150
Timestamp: 2025-08-23T12:54:44.918Z
Learning: In src/core/context.ts, when paramParsers is defined in resolved options, the dir property is guaranteed to be an array, so optional chaining on options.experimental.paramParsers?.dir.map() is sufficient protection against undefined values.
Applied to files:
src/core/context.tssrc/options.ts
📚 Learning: 2025-08-23T12:50:36.614Z
Learnt from: posva
Repo: posva/unplugin-vue-router PR: 700
File: src/core/context.ts:137-142
Timestamp: 2025-08-23T12:50:36.614Z
Learning: In src/core/context.ts, param parser relative paths must be computed relative to options.root (not relative to DTS file location) and the './' prefix is required for proper path resolution in the generated code.
Applied to files:
src/core/context.tssrc/options.ts
📚 Learning: 2025-08-16T13:00:51.271Z
Learnt from: posva
Repo: posva/unplugin-vue-router PR: 700
File: src/core/context.ts:109-147
Timestamp: 2025-08-16T13:00:51.271Z
Learning: In src/core/context.ts, the options parameter is already resolved, meaning options.experimental.paramMatchers is either an object with a dir property or undefined - never a boolean. The boolean normalization happens earlier in the options resolution phase.
Applied to files:
src/core/context.tssrc/options.ts
📚 Learning: 2025-08-16T13:01:42.709Z
Learnt from: posva
Repo: posva/unplugin-vue-router PR: 700
File: src/codegen/generateParamParsers.ts:91-94
Timestamp: 2025-08-16T13:01:42.709Z
Learning: In the unplugin-vue-router codebase, path normalization for import specifiers is handled elsewhere in the system (not at individual call sites like generateParamParsers.ts). Individual functions should not normalize paths themselves as it violates separation of concerns.
Applied to files:
src/core/context.ts
🧬 Code graph analysis (1)
src/core/context.ts (2)
src/core/tree.ts (1)
name(269-276)src/core/extendRoutes.ts (2)
name(90-92)name(97-99)
🔇 Additional comments (2)
src/options.ts (1)
254-257: LGTM!The default value correctly reflects the optional nature of the
getNameproperty, with the fallback implementation properly handled in context.ts.src/core/context.ts (1)
136-139: LGTM!The implementation correctly uses the custom
getNamefunction with proper fallback toparsePathe(file).name.
I've been giving the param matchers a try and they're absolutely great!
Context for this change: I use kebab case to define my param matchers, but that breaks the types since there can be no dashes in type names. Personally I'd like to use this to convert the name to camel case.
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.