* Cross-file finalization for `RouterModule.register([...])`. The per-file * extract() above only sees `@Controller(prefix) + @Get(path)` — it can't * learn about the route prefix supplied by a sibling `app.module.ts` like: * * RouterModule.register([ * { path: 'admin', module:
(context: ResolutionContext)
| 215 | * the same input regardless of how many times it has already prefixed). |
| 216 | */ |
| 217 | postExtract(context: ResolutionContext): Node[] { |
| 218 | const moduleToPrefix = new Map<string, string>(); |
| 219 | const controllerToModule = new Map<string, string>(); |
| 220 | |
| 221 | for (const filePath of context.getAllFiles()) { |
| 222 | if (!/\.module\.(m?[jt]s|cjs)$/.test(filePath)) continue; |
| 223 | const content = context.readFile(filePath); |
| 224 | if (!content) continue; |
| 225 | const safe = stripCommentsForRegex(content, detectLanguage(filePath)); |
| 226 | collectRouterModuleRegistrations(safe, moduleToPrefix); |
| 227 | collectModuleControllers(safe, controllerToModule); |
| 228 | } |
| 229 | |
| 230 | const controllerToPrefix = new Map<string, string>(); |
| 231 | for (const [controller, module] of controllerToModule) { |
| 232 | const prefix = moduleToPrefix.get(module); |
| 233 | // `''` and `'/'` are no-op prefixes; skip them so we don't run updates |
| 234 | // that would set name to the value it already has. |
| 235 | if (prefix && prefix !== '' && prefix !== '/') { |
| 236 | controllerToPrefix.set(controller, prefix); |
| 237 | } |
| 238 | } |
| 239 | |
| 240 | if (controllerToPrefix.size === 0) return []; |
| 241 | |
| 242 | const updates: Node[] = []; |
| 243 | for (const [controllerName, prefix] of controllerToPrefix) { |
| 244 | const classes = context |
| 245 | .getNodesByName(controllerName) |
| 246 | .filter((n) => n.kind === 'class'); |
| 247 | for (const cls of classes) { |
| 248 | const routes = context |
| 249 | .getNodesInFile(cls.filePath) |
| 250 | .filter((n) => n.kind === 'route'); |
| 251 | for (const route of routes) { |
| 252 | // Multiple controllers can live in one file (covered by the |
| 253 | // existing "attributes methods to the right controller" test); |
| 254 | // each route must be associated with the controller whose line |
| 255 | // range contains it. |
| 256 | if (route.startLine < cls.startLine || route.startLine > cls.endLine) { |
| 257 | continue; |
| 258 | } |
| 259 | const updated = applyModulePrefix(route, prefix); |
| 260 | if (updated && updated.name !== route.name) updates.push(updated); |
| 261 | } |
| 262 | } |
| 263 | } |
| 264 | |
| 265 | return updates; |
| 266 | }, |
| 267 | }; |
| 268 | |
| 269 | // --------------------------------------------------------------------------- |
nothing calls this directly
no test coverage detected