Bbackstage

backstage/add-entity-ref-to-location

Backstage 1.50.0: Add required entityRef field to Location object literals from @backstage/catalog-client

backstagemigrationcatalog-clientlocationentityRef1.50.0
Public
6 executions

Run locally

npx codemod @backstage/add-entity-ref-to-location

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 Location object literals with explicit type annotations (: Location, satisfies Location, as Location)
  • Detects nested Location objects inside AddLocationResponse-typed variables
  • Adds entityRef: 'location:default/example' with a TODO(backstage-codemod) comment for manual follow-up
  • Skips objects that use spread ({ ...existingLocation }) since they inherit the field
  • Skips objects that already have an entityRef property

Usage

bash

Before / After

ts
ts

Notes

  • The real entityRef format is location: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.

Ready to contribute?

Build your own codemod and share it with the community.