add-entity-ref-to-location
Backstage 1.50.0 codemod: Adds the required entityRef field to Location object literals from @backstage/catalog-client.
Background
In Backstage 1.50.0, the Location type in @backstage/catalog-client now includes a required entityRef: string field. Any code constructing or mocking Location objects (tests, fixtures, mock implementations) must include this field.
Production code consuming Location from API responses is unaffected -- the backend already populates entityRef.
What it does
- Detects
Locationobject literals with explicit type annotations (: Location,satisfies Location,as Location) - Detects nested
Locationobjects insideAddLocationResponse-typed variables - Adds
entityRef: 'location:default/example'with aTODO(backstage-codemod)comment for manual follow-up - Skips objects that use spread (
{ ...existingLocation }) since they inherit the field - Skips objects that already have an
entityRefproperty
Usage
bash
Before / After
ts
ts
Notes
- The real
entityRefformat islocation:default/generated-<sha1hex>. The codemod uses a placeholder since the actual value cannot be computed statically. - After running the codemod, search for
TODO(backstage-codemod)to find all locations that need manual attention. - The optional AI fixup step (
--param aiFixup=true) can handle edge cases like inferred types, dynamic mock setups, and test assertion objects.