Aalexbit-codemod

angularjs-shared-service-fanout

Mine high-fanout AngularJS services used across components/routes; read-only metrics

miningmetricsangularjscode-miningmigration-assessmentservice_fanout
PRO
0 executions

Run locally

npx codemod angularjs-shared-service-fanout

This is a Pro codemod. Preview changes and insights for free, no login or code sharing required. Applying changes and accessing insights requires a paid plan and sign in.Learn more

angularjs-shared-service-fanout

Read-only mining codemod that finds AngularJS .service() / .factory() / .provider()
registrations and estimates how many places in the same file inject each one. High-fanout
services are the ones most likely to block or gate a migration phase, since every consumer
needs to keep working while the service itself moves to Angular. No files are written to the
target repo.

What it detects

For every service/factory/provider registration, the codemod looks for injections via any of
the three classic AngularJS DI styles:

DI styleExample
Array annotation['$scope', 'DataService', function ($scope, DataService) {}]
$inject propertyCtrl.$inject = ['$scope', 'DataService']
Implicit parameter namingfunction Ctrl($scope, DataService) {}

Each registration is emitted once (finding_type: "registration"), plus one row per injection
site found (finding_type: "injection"), so you can see both the aggregate fanout count and
where each injection lives.

Metrics

MetricCardinalities
service_fanoutfinding_type, service_name, registration_type, injection_sites_in_file, injection_kind, consumer, file, line, snippet, migration_category, risk, automation, effort_points, recommended_phase

risk/effort_points/recommended_phase are derived from injection_sites_in_file:

Injection sitesRiskEffortPhase
0–1low1phase-3 (leaf features)
2–4medium3phase-2 (shared services)
5+high8phase-2 (shared services)

Limitations

  • File-local only. This codemod analyzes one file at a time (the JSSG execution model), so
    it cannot see a service injected from a different file. A service that looks "low fanout"
    here may actually be widely used across the whole app. Combine results with
    angularjs-service-inventory and cross-file usage search for an accurate picture, or run this
    as a stepping stone toward workspace-level analysis.
  • Detection is heuristic: implicit-parameter matching assumes a function parameter named exactly
    like a known registered service is really that service being injected (true in the vast
    majority of real AngularJS code, but not guaranteed).
  • Only .service(), .factory(), and .provider() registrations are tracked; .value() and
    .constant() are intentionally excluded since they are rarely gating dependencies.

Run

bash

Testing

bash

Development

bash

License

MIT

Ready to contribute?

Build your own codemod and share it with the community.