Registry
Aalexbit-codemod avatar

feature-flag-mining

Read-only mining codemod for Backstage FeatureFlagsApi usage sites. Detects declarations, isActive checks, FeatureFlagged gates, extension $contains predicates, registerFlag calls, and UI-schema featureFlag fields. Emits backstage_feature_flag_usage metrics; leaves source unchanged.

alexbit-codemod0 executions

  • mining
  • metrics
  • backstage
  • feature-flags
  • FeatureFlagsApi
  • FeatureFlagged
  • tsx
  • typescript
Connect a repo
npx codemod feature-flag-mining

feature-flag-mining

Read-only mining codemod for Backstage FeatureFlagsApi usage sites.

No source edits are produced (return null). Each detection emits one
backstage_feature_flag_usage metric row so you can inventory declarations vs
consumers across a Backstage app or monorepo.

Detected patterns

usage_kindExample
declarationfeatureFlags: [{ name: 'show-example-feature' }]
api_refuseApi(featureFlagsApiRef) only (imports / re-exports skipped)
is_activeisActive('…') or dynamic isActive(stepFeatureFlag)
feature_flagged<FeatureFlagged with="…"> / without="…"
extension_predicateif: { featureFlags: { $contains: 'experimental-features' } }
register_flagfeatureFlagApi.registerFlag({ name: '…' })
ui_schema_flag'ui:backstage': { featureFlag: '…' } / featureFlag: '…'

is_active only fires when the file already signals Backstage feature flags
(featureFlagsApiRef, FeatureFlagged, a featureFlags property, or UI-schema
flag keys). Plain user.isActive() call sites are ignored.

Metric: backstage_feature_flag_usage

fielddescription
usage_kindOne of the kinds in the table above
flag_nameLiteral name, <expr:…> when dynamic, or <unknown> for bare api_ref
polaritydeclare / check / with / without / contains / ref / register
detailExtra context (useApi, receiver text, dynamic:…, schema path, …)
fileRelative path of the scanned file
line1-based line number
symbolEnclosing function/class name, or <file-scope>

What this does not report

  • Framework plumbing paths: FeatureFlagsApi definitions, FeatureFlagged.tsx impl,
    AppManager, apiFactories / predicates wiring, useElementFilter, mockApis,
    and plugins/app default FeatureFlagsApi factory
  • Bare import / re-export / createApiRef of featureFlagsApiRef (only useApi(...))
  • Markdown docs / changelogs (workflow only scans *.{ts,tsx})
  • Unrelated isActive helpers when the file has no Backstage feature-flag signals
  • $contains predicates that are not nested under a featureFlags key

Run locally

bash
cd codemods/backstage/feature-flag-mining
pnpm test

pnpm dlx codemod@latest workflow run \
  -w codemods/backstage/feature-flag-mining/workflow.yaml \
  --target /path/to/backstage-app

Development

bash
pnpm test
pnpm run check-types
pnpm dlx codemod@latest workflow validate -w workflow.yaml

License

MIT

Ready to evolve your codebase?

Build tailored, compiler-aware skills to assess, plan, and automate complex codebase changes.