angularjs-routing-inventory
Mine AngularJS ui-router/ngRoute states, resolves, nested routes; read-only metrics
# angularjs-routing-inventory
Read-only **mining codemod** that inventories AngularJS routing configuration for migration assessment: ui-router `$stateProvider.state(...)` registrations (including nested, dot-separated state names, and `resolve` blocks) and ngRoute `$routeProvider.when(...)` / `.otherwise(...)` registrations. Each finding is classified with a risk level, an automation confidence, an effort-point estimate, and a recommended migration phase. No files are written to the target repo.
## What it does
| Pattern | Router | `has_resolve` | `is_nested` | Automation | Risk | Effort | Phase |
| ---------------------------------------------------- | --------- | ------------- | ----------- | ---------- | ------ | ------ | ------- |
| `.state('name', {...})` | ui-router | false | false | full | low | 2 | phase-3 |
| `.state('name', {...})` or `.when(path, {...})` | either | true or true | - | partial | medium | 5 | phase-3 |
| `.state('parent.child', {...})` (nested, no resolve) | ui-router | false | true | partial | medium | 5 | phase-3 |
| `.state('parent.child', {...})` (nested + resolve) | ui-router | true | true | partial | high | 8 | phase-4 |
| `.when(path, {...})` | ngRoute | false | false | full | low | 2 | phase-3 |
| `.otherwise(...)` | ngRoute | - | - | full | low | 1 | phase-3 |
Supports both `.state()` call shapes: `.state('name', config)` and the single-argument object-literal form `.state({ name: 'name', ... })`. For `.otherwise(...)`, the route is recorded as the `redirectTo` path when present (object-argument form), the literal string argument (string form), or the placeholder `(otherwise)` when neither can be resolved.
State/route names and paths are only recorded when they are string literals; dynamically computed names or paths (e.g. `.state(dynamicName, ...)`, `.when(path, ...)` where `path` is a variable) are skipped since they can't be resolved statically. Calls with no arguments are also skipped safely.
> **Heuristic limitation:** detection is name-based (matches any call whose callee property is `state`/`when`/`otherwise`), so it does not verify that the receiver is actually `$stateProvider`/`$routeProvider`. In practice this is rarely an issue for AngularJS codebases, but unrelated APIs that happen to share these method names could produce false positives.
## Metrics
| Metric | Cardinalities |
| ----------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `angularjs_route` | `file`, `line`, `snippet`, `route_name_or_path`, `router_type` (`ui-router`\|`ngRoute`), `has_resolve`, `is_nested`, `migration_category` (`routing`), `risk`, `automation`, `effort_points`, `recommended_phase` |
## Installation
```bash
# Install from registry
codemod run angularjs-routing-inventory
# Or run locally
codemod run -w workflow.yaml
```
## Usage
```bash
npx codemod@latest workflow run -w codemods/angularjs-to-angular/angularjs-routing-inventory \
-t /path/to/angularjs/repo \
--allow-dirty --no-interactive
```
## Development
```bash
# Test the transformation
pnpm test
# Check types
pnpm check-types
# Validate the workflow
codemod workflow validate -w workflow.yaml
# Publish to registry
codemod login
codemod publish
```
## License
MIT