Skip to content

feat: add transform for useMergerefs#531

Merged
adrienzheng-cb merged 5 commits intocds-v9from
adrien/migrate-use-merge-refs
Apr 1, 2026
Merged

feat: add transform for useMergerefs#531
adrienzheng-cb merged 5 commits intocds-v9from
adrien/migrate-use-merge-refs

Conversation

@adrienzheng-cb
Copy link
Copy Markdown
Contributor

@adrienzheng-cb adrienzheng-cb commented Mar 23, 2026

What changed? Why?

Summary

This PR extends the CDS migrator for the v8 → v9 workflow: a new useMergeRefsmergeRefs codemod, button-variant-values moved under transforms/v9/ with scope-agnostic import matching, and an optional npm package scope flag so consumers can limit rewrites without hard-coding internal registry names.

What changed

New: migrate-use-merge-refs (v9)

  • Rewrites deprecated useMergeRefs imports from @<scope>/cds-common/hooks/useMergeRefs to mergeRefs from @<scope>/cds-common/utils/mergeRefs (scope is preserved).
  • Handles imports, re-exports, aliases, Jest mocks, duplicate import consolidation, and safe identifier renames (skips object keys, member access, etc.).
  • Scope matching: recognizes @<any-scope>/cds-common/... so the open-source migrator does not depend on a specific org prefix.
  • Registered in the v8-to-v9 preset manifest; includes fixtures and Jest coverage.

button-variant-values (v9)

  • Lives under packages/migrator/src/transforms/v9/.
  • Import detection uses @<scope>/cds-web and @<scope>/cds-mobile (any scope), not a fixed list of scoped package names.

CLI: package scope (-ps / --package-scope)

  • --package-scope <scope> (shorthand -ps) limits scope-aware transforms to a single npm scope (e.g. coinbase or @coinbase).
  • Omitted → all scopes matching the transform rules are rewritten.
  • The runner forwards --packageScope=… to jscodeshift; transforms read options.packageScope.
  • packages/migrator/src/utils/package-scope.ts centralizes normalization (coinbase@coinbase) and reading options.

Docs & tooling

  • CLI_REFERENCE.md updated for package scope and shorthand.
  • Test helpers / Jest config / fixture layout aligned with the new v9 transforms.

Usage examples

# Preset (includes new transform when selected in manifest)
npx @coinbase/cds-migrator ./src -p v8-to-v9

# Direct transform
npx @coinbase/cds-migrator ./src -t migrate-use-merge-refs

# Only @coinbase/* CDS imports
npx @coinbase/cds-migrator ./src -t button-variant-values -ps coinbase

Root cause (required for bugfixes)

UI changes

iOS Old iOS New
old screenshot new screenshot
Android Old Android New
old screenshot new screenshot
Web Old Web New
old screenshot new screenshot

Testing

How has it been tested?

  • Unit tests
  • Interaction tests
  • Pseudo State tests
  • Manual - Web
  • Manual - Android (Emulator / Device)
  • Manual - iOS (Emulator / Device)

Testing instructions

Illustrations/Icons Checklist

Required if this PR changes files under packages/illustrations/** or packages/icons/**

  • verified visreg changes with Terran (include link to visreg run/approval)
  • all illustration/icons names have been reviewed by Dom and/or Terran

Change management

type=routine
risk=low
impact=sev5

automerge=false

@adrienzheng-cb adrienzheng-cb force-pushed the adrien/migrate-use-merge-refs branch from 210d818 to 1da79b2 Compare March 31, 2026 18:04
@adrienzheng-cb adrienzheng-cb force-pushed the adrien/migrate-use-merge-refs branch from 61b696b to ef54a48 Compare April 1, 2026 15:58
@adrienzheng-cb adrienzheng-cb merged commit 162aba4 into cds-v9 Apr 1, 2026
19 checks passed
@adrienzheng-cb adrienzheng-cb deleted the adrien/migrate-use-merge-refs branch April 1, 2026 16:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants