Skip to content

feat: Backstage 1.57.0 migration - add v1.57.0 migration recipe - #194

Draft
Sarabadu wants to merge 6 commits into
mainfrom
feat/v1.57.0-migration-recipe
Draft

Sarabadu wants to merge 6 commits into
mainfrom
feat/v1.57.0-migration-recipe

Conversation

@Sarabadu

@Sarabadu Sarabadu commented Nov 22, 2026 •

Copy link
Copy Markdown

Closes #193

Adds @backstage/v1-57-0-migration-recipe (codemods/v1.57.0/): one package and one workflow node running every Backstage 1.57.0 transform in the #193 step order (19 workflow entries for 16 steps). All transforms are deterministic js-ast-grep scripts, plus the host-run TechDocs shell step. There is no AI step.

Steps

# Script(s) Scope
1 scripts/migrate-frontend-plugin-api-imports.ts Rewrites removed @backstage/frontend-plugin-api/alpha imports; moves ExtensionFactoryMiddleware and AnalyticsImplementation*
2 scripts/replace-removed-frontend-plugin-api-types.ts Replaces removed type aliases (PageTab, PluginOptions, ExtensionAttachTo, ProgressProps) and deprecated AnyApiRef / AnyApiFactory; flags IconComponent
3 scripts/migrate-api-refs-to-core-apis.ts Replaces deprecated individual core API refs with coreApis.*
4 scripts/replace-create-specialized-app.ts createSpecializedApp(opts) → prepareSpecializedApp(opts).finalize()
5 scripts/replace-removed-mock-api-types.ts Replaces removed @backstage/frontend-test-utils mock API types with types derived from mockApis
6 scripts/add-timestamp-to-root-logger-json-format.ts Keeps timestamp in custom WinstonLogger JSON formats
7 scripts/add-logger-to-gitlab-token-validator.ts + scripts/flag-webhook-secret-config-yaml.ts Passes a logger to createGitlabTokenValidator; flags events.modules.{github,gitlab,azureDevOps} config without a webhook secret (TODO only)
8 scripts/migrate-ldap-search-attributes-yaml.ts Adds attributes: ['*', '+'] to LDAP user/group search options in app-config that don't set attributes (pre-1.57 behavior)
9 scripts/remove-dynamic-client-registration-config.ts Removes auth.experimentalDynamicClientRegistration from app-config
10 scripts/remove-alert-display-anchor-origin.ts Removes the ignored anchorOrigin from the alert display extension config
11 scripts/rename-techdocs-cli-serve-flags-package-json.ts + -ci-yaml.ts + -shell.ts (helper -command.ts) Renames deprecated TechDocs CLI --mkdocs-* serve flags in package.json scripts, GitHub Actions and shell scripts
12 scripts/update-react-peer-dependency-ranges.ts Drops React 16/17 alternatives from peerDependencies ranges that also allow React 18+, in every workspace package.json
13 scripts/wrap-icon-bundle-icons-in-elements.ts Wraps IconBundleBlueprint icon components in elements
14 scripts/migrate-router-blueprint-to-app-root-wrapper.ts RouterBlueprint → AppRootWrapperBlueprint (unwraps BrowserRouter); removes convertLegacyAppOptions components.Router; flags other routers and app/root router attachments
15 scripts/migrate-nav-content-items-to-nav-items.ts Custom nav components: items → navItems.rest()
16 scripts/flag-bui-standalone-routing.ts Flags javascript: / data: / vbscript: hrefs on Backstage UI elements (TODO only)

Step 7c (webhook secrets in app-config) and step 16 (executable-scheme BUI hrefs) only insert TODO(backstage-codemod) markers. The recipe takes no parameters.

Clarifications and deviations from #193

These were decided during implementation and review. #193 itself is unchanged.

  • Step 1: export * as ns from '…/alpha' is rewritten to the main entry; /alpha strings outside import/export declarations (jest.mock, import(), bare export * from) are left unchanged (README).
  • Step 2: extends/implements ProgressProps entries are dropped ({} can't appear there). Re-exports of only the deprecated AnyApiRef/AnyApiFactory get no TODO (still exported). Re-export TODOs (spec gives no text) name the replacement per symbol.
  • Step 3: re-exports get a TODO on that statement only; a locally re-exported imported ref keeps its import; everything else in the file is migrated. Re-export/shadow TODO texts are the implementer's (spec gives none).
  • Step 3: an emptied main-entry (or sole /alpha) import is rewritten in place to import coreApis.
  • Step 4: identifier options resolving to a same-file const object literal are inspected for advanced.apis; TODO only if present or unresolvable (spec Before/After shows no TODO for an identifier).
  • Step 4: no-argument calls get no TODO; satisfies/as wrappers are unwrapped before the object-literal check. Non-call references (typeof createSpecializedApp) are renamed without a TODO (TypeScript reports mismatches).
  • Step 5: re-export TODOs name the replacement type; emptied type-only imports become import type { mockApis } in place.
  • Step 6: the rule-3 skip is narrowed to the pipeline that produces the JSON: for each format.json() call, skip if any enclosing format.combine(...) (up to the format: value) has a format.timestamp() argument before the argument containing the json call; otherwise insert format.timestamp() as the first argument of the outermost enclosing combine, or wrap a bare format.json() as format.combine(format.timestamp(), format.json()). So prod ? format.json() : format.combine(format.timestamp(), …) gets a timestamp on the JSON branch, and format.combine(format.timestamp(), prod ? format.json() : …) is left alone. Quoted 'format' keys are matched.
  • Step 7a: X.config accepted for side-effect-free identifier / this / non-computed member chains (optional chaining preserved); imported logger bindings are not used.
  • Step 7b dropped (user decision): it flagged every webhook module added in backend code, even when the secret is configured, because TypeScript can't read config; step 7c checks app-config precisely.
  • Step 16 (user decision): only the executable-scheme href check remains. The BUIProvider-without-useNavigation TODO is dropped: inside a Backstage app navigation is inherited, so it flagged every app (all real hits were framework-internal).
  • Step 7c: dangerouslyAllowUnauthenticatedEvents only suppresses the TODO when it is true (a false opt-out still gets the TODO). Empty/null module values are flagged; flow-style modules: { … } maps are not handled (README).
  • Step 7c: a literal empty / null / ~ webhookSecret counts as not configured (module and integrations.github[].apps[]); env substitutions and $env/$file objects count as configured.
  • Step 8 (user decision, replaces [DRAFT]feat: Backstage 1.57.0 migration - add v1.57.0 migration recipe #193's TS TODO half and the ldapPreserveAllAttributes param): only the YAML half remains and it always adds attributes: ['*', '+'] to block-style LDAP user/group search options in app-config that don't set attributes, with # Preserves pre-1.57 behavior (all attributes). Narrow this list to the attributes your mappings and transformers use to benefit from attribute selection. The recipe runs right after the upgrade, so it keeps the pre-1.57 behavior instead of silently dropping attributes that custom transformers read; an explicit list replaces the defaults (1.57 docs), so ['*', '+'] is the only safe automatic value. With that in place the TypeScript transformer TODO was noise, so it was removed.
  • Step 9: enabled truthiness follows Backstage ConfigReader (yes/on/1/'true'; ${ENV} treated as possibly enabled → TODO). When auth only held the DCR key, auth is removed and the TODO is left at its former position. Flow-style auth: { … } is left unchanged (README).
  • Step 11: the shell step has if: state.targetDirEncoded so targets without any package.json skip it instead of failing; the package.json step sets the state on every package.json it visits. The shell step writes files even under --dry-run (host-run, as in v1.54).
  • Step 12 (lead decision): drops every alternative below React 18 (16 and 17), only when an alternative admitting React ≥18 remains; otherwise unchanged (e.g. ^16.13.1 || ^17.0.2). React-17-only and comparator ranges (>=17) are left for manual review (README).
  • Step 13: lowercase identifier icon values (e.g. myIcon) get the TODO instead of <myIcon /> (JSX would treat it as an intrinsic element).
  • Step 13: createElement(...) / React.createElement(...) icon values count as migrated; makeWithOverrides is handled via originalFactory({...}) (it has no params); namespace-qualified blueprint access is not handled (README).
  • Step 14: BrowserRouter with props (e.g. basename) is kept with a TODO; opaque params.component (imported, wrapped, unresolvable) is renamed with a "check this component no longer renders a router" TODO; unstable_HistoryRouter/HistoryRouter/Router/StaticRouter count as other routers. makeWithOverrides is handled through originalFactory({...}) (steps 13–15).
  • Step 14: a BrowserRouter-only wrapper becomes ({ children }) => <>{children}</> (not bare children, which doesn't satisfy JSX.Element | null) and keeps the delete TODO; an emptied components: {} in convertLegacyAppOptions is removed; exported/shorthand RouterBlueprint references get a rename-review TODO.
  • Step 16: for an href element inline with text, the TODO is placed on the same line right before the element so JSX whitespace/rendering is unchanged.
  • Not changed (as spec): step 6 only detects a named format import from winston (no winston.format.*); step 7a does not verify that X.logger exists (TypeScript reports it).
  • Known, not fixed: inside @backstage/frontend-app-api / @backstage/plugin-app-react themselves (framework repo only), step 1 would emit self-package imports; built-in packages are out of scope (spec Notes).

Notes for reviewers

  • Helpers shared across steps. Step 7a uses add-logger-to-gitlab-token-validator-todo.ts. Steps 1, 2, 4 and 5 share replace-removed-frontend-plugin-api-types-common.ts. Steps 9 and 10 share remove-dynamic-client-registration-config-helpers.ts. Steps 13 to 16 share migrate-router-blueprint-to-app-root-wrapper-helpers.ts. Step 11 uses rename-techdocs-cli-serve-flags-command.ts. These are listed in the README.
  • TechDocs shell step. As in v1.54, this step is host-run and writes .sh files even under --dry-run. It is skipped (if: state.targetDirEncoded) when the target has no package.json. Its rewrites don't appear in the metrics.
  • @jssg/utils. The scripts use listImports, importBindingOf, resolveDefinition, renameReferences, updateImport/addImport/removeImport and the style helpers where they fit. Some import-removal and offset code is bespoke because removeImport also matches CJS require and slices strings by UTF-8 byte offsets, which breaks after non-ASCII text. Tree-sitter columns are code points; the scripts convert them before slicing. An upstream issue is worth filing.
  • Formatting. The output keeps the surrounding layout but doesn't reflow long lines, so the README tells users to run their formatter afterwards.
  • Before running. Run v1.48 migrate-blueprints-to-plugin-app-react and v1.50 dialog-api-show-to-open first if those releases were skipped. Adding @backstage/frontend-app-api / @backstage/plugin-app-react dependencies is manual. Use coreApis.appHistory (appHistoryApiRef is not exported by @backstage/frontend-plugin-api@1.0.0). The README's "Known limitations" and "Manual-only migration work" sections mirror [DRAFT]feat: Backstage 1.57.0 migration - add v1.57.0 migration recipe #193's out-of-scope table.

QA

The full recipe ran on throwaway clones (the real repos were not modified) and on a synthetic adopter monorepo:

Target Changed files Idempotent (2nd run)
backstage/backstage @ 0b05c6c (pre-1.57) 154 yes
backstage/community-plugins @ bbb02b2 204 yes
Synthetic adopter app (all 16 steps) 10 yes

Size

After a simplification pass (consolidated fixtures, removed hardening for exotic shapes, rules beyond #193 and TODOs that fired on every app): 24 scripts (~4.4K lines, incl. 5 shared helpers) and 147 fixture cases / 420 test files. The full-recipe output on the backstage and community-plugins clones is unchanged apart from the intentionally removed TODOs (LDAP transformer, webhook modules in code, BUIProvider).

Tests

  • yarn test in codemods/v1.57.0: 18 JSSG suites (147 fixture cases, metrics snapshots on changing cases), tsc for every tests/**/tsconfig.json, node suites for the TechDocs command helper, shell walker and workflow state, and tests/workflow.test.ts (step order, selectors, shell run: line and if: guard, no params). The workflow also passes codemod workflow validate.
  • yarn lint, yarn format:check and yarn check:changed origin/main pass.

Changeset

.changeset/v1-57-0-migration-recipe.md: '@backstage/v1-57-0-migration-recipe': minor. The initial version is 0.1.0, as in v1.56. No versions were hand-edited, and the root README is untouched.

Steps 1-5 of #193: move removed @backstage/frontend-plugin-api/alpha and relocated exports, replace removed type aliases and AnyApiRef/AnyApiFactory, migrate deprecated core API refs to coreApis, replace createSpecializedApp with prepareSpecializedApp().finalize(), and replace removed frontend-test-utils mock API types.
Steps 6-7 of #193: keep timestamps in custom root logger JSON formats, pass a logger to createGitlabTokenValidator, and flag events.modules webhook config without a secret.
Steps 8-10 of #193: preserve pre-1.57 LDAP search attributes, remove auth.experimentalDynamicClientRegistration, and remove the ignored alert display anchorOrigin.
Steps 11-12 of #193: rename deprecated --mkdocs-* serve flags in package.json scripts, GitHub Actions and shell scripts, and drop React 16/17 alternatives from peerDependencies ranges.
Steps 13-16 of #193: wrap IconBundleBlueprint icons in elements, migrate RouterBlueprint to AppRootWrapperBlueprint, migrate custom nav items to navItems, and flag executable-scheme Backstage UI hrefs.
Wire every step into one workflow in #193 order, with the README (steps, limitations, manual-only work), workflow tests and a changeset.

Closes #193
@Sarabadu
Sarabadu force-pushed the feat/v1.57.0-migration-recipe branch from 7ae43e6 to d828886 Compare November 22, 2026 22:20
@Sarabadu

Copy link
Copy Markdown
Author

@schultzp2020, first codemod for me here, and this one look a bit massive, did some local test and look ok but not covering every single codemod in real project.

If you get some time I would appreciate to get some comments to see if i'm in the right direction here or if you spot anything evidently wrong

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[DRAFT]feat: Backstage 1.57.0 migration - add v1.57.0 migration recipe

1 participant