feat(app/router): registerDownstreamRoutes extension hook (Fix B prerequisite for trawl#T15)#4242
Conversation
…nstream route injection Closes #4241. Add a `registerDownstreamRoutes(options)` named export that downstream Vue projects can call before `getRouter()` is invoked to inject their own routes without patching the shared devkit file. Three extension points: - `coreModules` — unconditionally mounted (spread into coreRoutes) - `adminChildModules` — added to adminChildModules before injectAdminChildren - `optionalModules` — added to optionalModules, gated by isModuleActive Route composition is moved inside `getRouter()` so that registry mutations made during module initialisation are always visible at composition time. Unit tests added (6 cases): no-registration baseline, coreModules/optionalModules injection, adminChildModules no-throw, ordering (stack-first), activation gating.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (2)
WalkthroughAdds extensibility to the Vue router by introducing a ChangesDownstream Route Registration Extension
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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 |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #4242 +/- ##
=======================================
Coverage 99.57% 99.57%
=======================================
Files 31 31
Lines 1172 1172
Branches 334 334
=======================================
Hits 1167 1167
Misses 5 5 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
Adds a supported extension hook to app.router so downstream projects can inject additional routes/modules without patching the shared devkit router, enabling stack byte-identity and reducing merge drift.
Changes:
- Introduces
registerDownstreamRoutes(options)as a named export to register downstreamcoreModules,adminChildModules, andoptionalModules. - Defers route composition into
getRouter()so downstream registry mutations are reflected at router creation time. - Adds unit tests covering baseline behavior, downstream injections, ordering, and
isModuleActivegating.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
src/modules/app/app.router.js |
Adds downstream route registries + registerDownstreamRoutes, and moves composition/injection into getRouter(). |
src/modules/app/tests/app.router.unit.tests.js |
Adds a dedicated registerDownstreamRoutes test suite verifying injection behavior and ordering/gating. |
| const adminChildModules = [..._downstreamAdminChildModules]; | ||
| injectAdminChildren(admin, adminChildModules, isModuleActive); | ||
|
|
||
| /** | ||
| * Organization-settings child modules — routes injected as children of the | ||
| * `/users/organizations/:organizationId` parent route via `injectModuleChildren`. | ||
| * Base devkit ships this empty; PR (c) and downstream projects populate it | ||
| * (e.g. a billing-settings tab rendered inside the org detail layout). | ||
| * | ||
| * Each module's router file should export routes with **relative** paths | ||
| * (e.g. `'billing'` rather than `'/users/organizations/:organizationId/billing'`) | ||
| * so they resolve under the org parent. | ||
| */ | ||
| const organizationChildModules = [ | ||
| { name: 'billing', routes: billingOrganizationRoutes }, | ||
| ]; | ||
| injectModuleChildren(organizations, organizationChildModules, isModuleActive, ORG_PARENT_PATH); |
| export function registerDownstreamRoutes(options = {}) { | ||
| if (options.coreModules) _downstreamCoreModules.push(...options.coreModules); | ||
| if (options.adminChildModules) _downstreamAdminChildModules.push(...options.adminChildModules); | ||
| if (options.optionalModules) _downstreamOptionalModules.push(...options.optionalModules); | ||
| } |
| /** | ||
| * Each test resets modules so it gets a fresh registry (arrays start empty). | ||
| * registerDownstreamRoutes is imported from the same fresh module instance | ||
| * as getRouter, so mutations are visible to the composition. | ||
| */ | ||
| async function setupFreshModule(registerFn) { |
Summary
registerDownstreamRoutes(options)as a named export ofsrc/modules/app/app.router.jsgetRouter()is invoked frommain.js) to injectcoreModules,adminChildModules, and/oroptionalModuleswithout patching the shared devkit filegetRouter()so registry mutations made at module-init time are always visible at composition timeContext
This is the Fix B prerequisite for trawl#T15 (extract trawl_vue downstream routes to
trawl.router.js, revertapp.router.jsto devkit byte-identity). Partially resolves infra#38 (no-ledger drift cleanup).Trawl currently injects 7 module route imports + 2 modified route arrays directly into the shared
app.router.js. This clean extension hook is the only path to revertingapp.router.jsto baseline without breaking trawl navigation.Test plan
npm run lint— ESLint: No issues foundnpm run test:unit— 2036 tests pass (123 test files)app.routertests pass unchangedregisterDownstreamRoutesdescribe block: 6/6 passCloses #4241. Partially resolves infra#38.
Summary by CodeRabbit
Refactor
Tests