|
| 1 | +# Codemod-first workflow |
| 2 | + |
| 3 | +## Inspect before editing |
| 4 | + |
| 5 | +- Search package manifests and source for `@adobe/react-spectrum`, `@react-spectrum/*`, and `@spectrum-icons/*`. |
| 6 | +- In monorepos or mixed-tooling repos, inspect the target package or app first instead of assuming the root manifest, Storybook config, or workspace tooling represents the runtime target being migrated. |
| 7 | +- Determine the package manager from the relevant lockfile or workspace setup, then choose the codemod runner that matches that repo or package. |
| 8 | +- Detect the bundler at the migration target level before touching setup files. Parcel v2.12.0+ already supports S2 style macros. Vite, webpack, Next.js, Rollup, ESBuild, and similar toolchains need explicit macro-plugin setup. |
| 9 | +- Find app entrypoints, standalone pages, alternate entrypoints, embedded sub-apps, utility apps, test-only render targets, root providers, shared test wrappers, toast setup, and any direct `defaultTheme` usage before the codemod changes imports. |
| 10 | +- Search for `ToastContainer`, `ToastQueue`, `DialogContainer`, `useDialogContainer`, `ClearSlots`, style props, and `UNSAFE_style`. These are common follow-up areas after the codemod. |
| 11 | + |
| 12 | +## Run the codemod first |
| 13 | + |
| 14 | +Prefer the repo-native non-interactive command so the upgrade stays deterministic: |
| 15 | + |
| 16 | +```bash |
| 17 | +npx @react-spectrum/codemods s1-to-s2 --agent |
| 18 | +yarn dlx @react-spectrum/codemods s1-to-s2 --agent |
| 19 | +pnpm dlx @react-spectrum/codemods s1-to-s2 --agent |
| 20 | +``` |
| 21 | + |
| 22 | +Use `npx` for npm and Yarn 1 repos, `yarn dlx` for Yarn Berry or Yarn PnP repos, and `pnpm dlx` for pnpm repos. Use the equivalent workspace-native runner if the repo uses another package manager. |
| 23 | +Use `--path <dir>` for monorepos or when only one package should migrate first. In a monorepo, run the codemod against the target subtree first instead of the whole workspace. |
| 24 | +Use `--components A,B` when the user explicitly wants an incremental rollout by component family. |
| 25 | +Use `--dry` when you need to preview scope before editing. |
| 26 | + |
| 27 | +## Resolve follow-up work in order |
| 28 | + |
| 29 | +1. Install or verify `@react-spectrum/s2` and clean up imports. |
| 30 | +2. Add S2 app setup such as `@react-spectrum/s2/page.css` or `Provider` changes. |
| 31 | +3. Search for `TODO(S2-upgrade)` and fix every remaining comment. |
| 32 | +4. Resolve style prop, layout, and dialog/collection follow-ups. |
| 33 | +5. Migrate icons, illustrations, and toast imports. |
| 34 | +6. Update tests, mocks, and validation commands. |
| 35 | + |
| 36 | +## Validate with repo-native commands |
| 37 | + |
| 38 | +Prefer the narrowest existing scripts from `package.json`: |
| 39 | + |
| 40 | +- dependency install if manifests changed |
| 41 | +- typecheck or compile |
| 42 | +- focused tests for touched areas |
| 43 | +- build |
| 44 | + |
| 45 | +For monorepos, validate the affected package or subtree first with its own scripts before escalating to workspace-wide checks. |
0 commit comments