@openrewrite/recipes-react 0.25.0 → 0.27.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (432) hide show
  1. package/dist/i18n/translate-hard-coded-strings.d.ts.map +1 -1
  2. package/dist/i18n/translate-hard-coded-strings.js +3 -2
  3. package/dist/i18n/translate-hard-coded-strings.js.map +1 -1
  4. package/dist/index.d.ts +1 -4
  5. package/dist/index.d.ts.map +1 -1
  6. package/dist/index.js +6 -18
  7. package/dist/index.js.map +1 -1
  8. package/dist/migration/change-component-prop-value.d.ts.map +1 -1
  9. package/dist/migration/change-component-prop-value.js.map +1 -1
  10. package/dist/migration/cra-to-vite/add-vite-config.d.ts.map +1 -1
  11. package/dist/migration/cra-to-vite/add-vite-config.js.map +1 -1
  12. package/dist/migration/cra-to-vite/cra-to-vite.d.ts.map +1 -1
  13. package/dist/migration/cra-to-vite/cra-to-vite.js.map +1 -1
  14. package/dist/migration/cra-to-vite/find-cra-config-blockers.d.ts.map +1 -1
  15. package/dist/migration/cra-to-vite/find-cra-config-blockers.js.map +1 -1
  16. package/dist/migration/cra-to-vite/find-cra-env-file-blockers.d.ts.map +1 -1
  17. package/dist/migration/cra-to-vite/find-cra-env-file-blockers.js.map +1 -1
  18. package/dist/migration/cra-to-vite/find-cra-source-blockers.d.ts.map +1 -1
  19. package/dist/migration/cra-to-vite/find-cra-source-blockers.js.map +1 -1
  20. package/dist/migration/cra-to-vite/find-cra-to-vite-blockers.d.ts.map +1 -1
  21. package/dist/migration/cra-to-vite/find-cra-to-vite-blockers.js.map +1 -1
  22. package/dist/migration/cra-to-vite/migrate-cra-package.d.ts.map +1 -1
  23. package/dist/migration/cra-to-vite/migrate-cra-package.js.map +1 -1
  24. package/dist/migration/cra-to-vite/migrate-cra-svg-imports.d.ts.map +1 -1
  25. package/dist/migration/cra-to-vite/migrate-cra-svg-imports.js +3 -3
  26. package/dist/migration/cra-to-vite/migrate-cra-svg-imports.js.map +1 -1
  27. package/dist/migration/cra-to-vite/migrate-cra-tests-to-vitest.d.ts.map +1 -1
  28. package/dist/migration/cra-to-vite/migrate-cra-tests-to-vitest.js.map +1 -1
  29. package/dist/migration/cra-to-vite/move-public-index-html.d.ts +1 -1
  30. package/dist/migration/cra-to-vite/move-public-index-html.d.ts.map +1 -1
  31. package/dist/migration/cra-to-vite/move-public-index-html.js +1 -1
  32. package/dist/migration/cra-to-vite/move-public-index-html.js.map +1 -1
  33. package/dist/migration/cra-to-vite/remove-cra-configuration.d.ts.map +1 -1
  34. package/dist/migration/cra-to-vite/remove-cra-configuration.js.map +1 -1
  35. package/dist/migration/cra-to-vite/rename-jsx-files.d.ts.map +1 -1
  36. package/dist/migration/cra-to-vite/rename-jsx-files.js.map +1 -1
  37. package/dist/migration/cra-to-vite/rename-process-env-react-app.d.ts +1 -1
  38. package/dist/migration/cra-to-vite/rename-process-env-react-app.d.ts.map +1 -1
  39. package/dist/migration/cra-to-vite/rename-process-env-react-app.js +1 -1
  40. package/dist/migration/cra-to-vite/rename-process-env-react-app.js.map +1 -1
  41. package/dist/migration/cra-to-vite/rename-react-app-env-vars-in-env-files.d.ts +1 -1
  42. package/dist/migration/cra-to-vite/rename-react-app-env-vars-in-env-files.d.ts.map +1 -1
  43. package/dist/migration/cra-to-vite/rename-react-app-env-vars-in-env-files.js +1 -1
  44. package/dist/migration/cra-to-vite/rename-react-app-env-vars-in-env-files.js.map +1 -1
  45. package/dist/migration/cra-to-vite/replace-react-scripts-dependency.d.ts +1 -1
  46. package/dist/migration/cra-to-vite/replace-react-scripts-dependency.d.ts.map +1 -1
  47. package/dist/migration/cra-to-vite/replace-react-scripts-dependency.js +1 -1
  48. package/dist/migration/cra-to-vite/replace-react-scripts-dependency.js.map +1 -1
  49. package/dist/migration/cra-to-vite/update-react-app-env-types.d.ts.map +1 -1
  50. package/dist/migration/cra-to-vite/update-react-app-env-types.js.map +1 -1
  51. package/dist/migration/cra-to-vite/update-react-scripts-scripts.d.ts.map +1 -1
  52. package/dist/migration/cra-to-vite/update-react-scripts-scripts.js.map +1 -1
  53. package/dist/migration/cra-to-vite/update-tsconfig-for-vite.d.ts.map +1 -1
  54. package/dist/migration/cra-to-vite/update-tsconfig-for-vite.js.map +1 -1
  55. package/dist/mui/adapt-v4-theme.d.ts.map +1 -1
  56. package/dist/mui/adapt-v4-theme.js +1 -1
  57. package/dist/mui/adapt-v4-theme.js.map +1 -1
  58. package/dist/mui/add-component-prop.d.ts.map +1 -1
  59. package/dist/mui/add-component-prop.js.map +1 -1
  60. package/dist/mui/add-emotion-prepend.d.ts.map +1 -1
  61. package/dist/mui/add-emotion-prepend.js +3 -16
  62. package/dist/mui/add-emotion-prepend.js.map +1 -1
  63. package/dist/mui/convert-mui-imports.d.ts.map +1 -1
  64. package/dist/mui/convert-mui-imports.js +1 -1
  65. package/dist/mui/convert-mui-imports.js.map +1 -1
  66. package/dist/mui/convert-prop-to-sx.d.ts.map +1 -1
  67. package/dist/mui/convert-prop-to-sx.js +1 -1
  68. package/dist/mui/convert-prop-to-sx.js.map +1 -1
  69. package/dist/mui/mark-manual-migration.d.ts.map +1 -1
  70. package/dist/mui/mark-manual-migration.js.map +1 -1
  71. package/dist/mui/mark-palette-mode-usage.d.ts.map +1 -1
  72. package/dist/mui/mark-palette-mode-usage.js.map +1 -1
  73. package/dist/mui/move-component-prop-to-slot.d.ts.map +1 -1
  74. package/dist/mui/move-component-prop-to-slot.js.map +1 -1
  75. package/dist/mui/move-primary-text-to-children.d.ts.map +1 -1
  76. package/dist/mui/move-primary-text-to-children.js.map +1 -1
  77. package/dist/mui/move-system-props-to-sx.d.ts.map +1 -1
  78. package/dist/mui/move-system-props-to-sx.js +1 -1
  79. package/dist/mui/move-system-props-to-sx.js.map +1 -1
  80. package/dist/mui/remove-component-prop.d.ts.map +1 -1
  81. package/dist/mui/remove-component-prop.js.map +1 -1
  82. package/dist/mui/remove-root-ref.d.ts.map +1 -1
  83. package/dist/mui/remove-root-ref.js +1 -1
  84. package/dist/mui/remove-root-ref.js.map +1 -1
  85. package/dist/mui/remove-spacing-px-suffix.d.ts.map +1 -1
  86. package/dist/mui/remove-spacing-px-suffix.js +7 -10
  87. package/dist/mui/remove-spacing-px-suffix.js.map +1 -1
  88. package/dist/mui/rename-component-prop.d.ts.map +1 -1
  89. package/dist/mui/rename-component-prop.js.map +1 -1
  90. package/dist/mui/rename-joy-css-variables.d.ts.map +1 -1
  91. package/dist/mui/rename-joy-css-variables.js.map +1 -1
  92. package/dist/mui/rename-theme-palette-type.d.ts.map +1 -1
  93. package/dist/mui/rename-theme-palette-type.js.map +1 -1
  94. package/dist/mui/replace-box-border-radius.d.ts.map +1 -1
  95. package/dist/mui/replace-box-border-radius.js.map +1 -1
  96. package/dist/mui/replace-breakpoints-width.d.ts.map +1 -1
  97. package/dist/mui/replace-breakpoints-width.js.map +1 -1
  98. package/dist/mui/replace-component-class.d.ts.map +1 -1
  99. package/dist/mui/replace-component-class.js.map +1 -1
  100. package/dist/mui/replace-components-with-slots.d.ts.map +1 -1
  101. package/dist/mui/replace-components-with-slots.js.map +1 -1
  102. package/dist/mui/replace-import-paths.d.ts.map +1 -1
  103. package/dist/mui/replace-import-paths.js.map +1 -1
  104. package/dist/mui/replace-in-string-literals.d.ts.map +1 -1
  105. package/dist/mui/replace-in-string-literals.js.map +1 -1
  106. package/dist/mui/replace-list-item-button-prop.d.ts.map +1 -1
  107. package/dist/mui/replace-list-item-button-prop.js +2 -2
  108. package/dist/mui/replace-list-item-button-prop.js.map +1 -1
  109. package/dist/mui/replace-tabs-scroll-buttons.d.ts.map +1 -1
  110. package/dist/mui/replace-tabs-scroll-buttons.js.map +1 -1
  111. package/dist/mui/replace-theme-color-functions.d.ts.map +1 -1
  112. package/dist/mui/replace-theme-color-functions.js +7 -21
  113. package/dist/mui/replace-theme-color-functions.js.map +1 -1
  114. package/dist/mui/replace-theme-spacing-unit.d.ts.map +1 -1
  115. package/dist/mui/replace-theme-spacing-unit.js.map +1 -1
  116. package/dist/mui/replace-typography-round.d.ts.map +1 -1
  117. package/dist/mui/replace-typography-round.js.map +1 -1
  118. package/dist/mui/shift-hidden-down-props.d.ts.map +1 -1
  119. package/dist/mui/shift-hidden-down-props.js +4 -5
  120. package/dist/mui/shift-hidden-down-props.js.map +1 -1
  121. package/dist/mui/update-theme-breakpoints.d.ts.map +1 -1
  122. package/dist/mui/update-theme-breakpoints.js.map +1 -1
  123. package/dist/mui/upgrade-grid-props.d.ts.map +1 -1
  124. package/dist/mui/upgrade-grid-props.js +1 -1
  125. package/dist/mui/upgrade-grid-props.js.map +1 -1
  126. package/dist/react-native/view-prop-types.d.ts.map +1 -1
  127. package/dist/react-native/view-prop-types.js +3 -9
  128. package/dist/react-native/view-prop-types.js.map +1 -1
  129. package/dist/react16/error-boundaries.d.ts.map +1 -1
  130. package/dist/react16/error-boundaries.js +1 -1
  131. package/dist/react16/error-boundaries.js.map +1 -1
  132. package/dist/react16/find-dom-node.d.ts.map +1 -1
  133. package/dist/react16/find-dom-node.js.map +1 -1
  134. package/dist/react16/react-dom-factories.d.ts.map +1 -1
  135. package/dist/react16/react-dom-factories.js.map +1 -1
  136. package/dist/react16/react-prop-types.d.ts.map +1 -1
  137. package/dist/react16/react-prop-types.js +3 -9
  138. package/dist/react16/react-prop-types.js.map +1 -1
  139. package/dist/react16/react-to-react-dom.d.ts.map +1 -1
  140. package/dist/react16/react-to-react-dom.js +2 -2
  141. package/dist/react16/react-to-react-dom.js.map +1 -1
  142. package/dist/react17/migrate-deprecated-lifecycles.d.ts +1 -1
  143. package/dist/react17/migrate-deprecated-lifecycles.d.ts.map +1 -1
  144. package/dist/react17/migrate-deprecated-lifecycles.js +5 -6
  145. package/dist/react17/migrate-deprecated-lifecycles.js.map +1 -1
  146. package/dist/react17/remove-event-persist.d.ts.map +1 -1
  147. package/dist/react17/remove-event-persist.js +128 -63
  148. package/dist/react17/remove-event-persist.js.map +1 -1
  149. package/dist/react17/rename-unsafe-lifecycles.d.ts.map +1 -1
  150. package/dist/react17/rename-unsafe-lifecycles.js +1 -1
  151. package/dist/react17/rename-unsafe-lifecycles.js.map +1 -1
  152. package/dist/react17/update-react-imports.d.ts.map +1 -1
  153. package/dist/react17/update-react-imports.js +1 -1
  154. package/dist/react17/update-react-imports.js.map +1 -1
  155. package/dist/react17/use-new-jsx-transform.d.ts +1 -1
  156. package/dist/react17/use-new-jsx-transform.d.ts.map +1 -1
  157. package/dist/react17/use-new-jsx-transform.js +2 -1
  158. package/dist/react17/use-new-jsx-transform.js.map +1 -1
  159. package/dist/react18/add-children-to-props.js +1 -1
  160. package/dist/react18/add-children-to-props.js.map +1 -1
  161. package/dist/react18/replace-reactdom-render.d.ts.map +1 -1
  162. package/dist/react18/replace-reactdom-render.js +1 -1
  163. package/dist/react18/replace-reactdom-render.js.map +1 -1
  164. package/dist/react18/replace-render-callback.d.ts.map +1 -1
  165. package/dist/react18/replace-render-callback.js +3 -12
  166. package/dist/react18/replace-render-callback.js.map +1 -1
  167. package/dist/react18/replace-unmount-component-at-node.d.ts.map +1 -1
  168. package/dist/react18/replace-unmount-component-at-node.js +1 -1
  169. package/dist/react18/replace-unmount-component-at-node.js.map +1 -1
  170. package/dist/react19/find-context-consumer.d.ts.map +1 -1
  171. package/dist/react19/find-context-consumer.js.map +1 -1
  172. package/dist/react19/find-deprecated-reactdom-apis.d.ts.map +1 -1
  173. package/dist/react19/find-deprecated-reactdom-apis.js +16 -61
  174. package/dist/react19/find-deprecated-reactdom-apis.js.map +1 -1
  175. package/dist/react19/find-element-ref.d.ts.map +1 -1
  176. package/dist/react19/find-element-ref.js.map +1 -1
  177. package/dist/react19/find-legacy-context-api.d.ts.map +1 -1
  178. package/dist/react19/find-legacy-context-api.js.map +1 -1
  179. package/dist/react19/no-implicit-ref-callback-return.d.ts.map +1 -1
  180. package/dist/react19/no-implicit-ref-callback-return.js +1 -1
  181. package/dist/react19/no-implicit-ref-callback-return.js.map +1 -1
  182. package/dist/react19/remove-context-provider.d.ts.map +1 -1
  183. package/dist/react19/remove-context-provider.js +1 -7
  184. package/dist/react19/remove-context-provider.js.map +1 -1
  185. package/dist/react19/remove-forward-ref.d.ts.map +1 -1
  186. package/dist/react19/remove-forward-ref.js +2 -2
  187. package/dist/react19/remove-forward-ref.js.map +1 -1
  188. package/dist/react19/remove-prop-types.d.ts.map +1 -1
  189. package/dist/react19/remove-prop-types.js.map +1 -1
  190. package/dist/react19/remove-react-fc.js +2 -2
  191. package/dist/react19/remove-react-fc.js.map +1 -1
  192. package/dist/react19/remove-unstable-batched-updates.d.ts +1 -1
  193. package/dist/react19/remove-unstable-batched-updates.d.ts.map +1 -1
  194. package/dist/react19/remove-unstable-batched-updates.js +9 -88
  195. package/dist/react19/remove-unstable-batched-updates.js.map +1 -1
  196. package/dist/{react16 → react19}/replace-create-factory.d.ts +1 -1
  197. package/dist/react19/replace-create-factory.d.ts.map +1 -0
  198. package/dist/{react16 → react19}/replace-create-factory.js +5 -5
  199. package/dist/react19/replace-create-factory.js.map +1 -0
  200. package/dist/react19/replace-reactdom-hydrate.d.ts.map +1 -1
  201. package/dist/react19/replace-reactdom-hydrate.js +1 -1
  202. package/dist/react19/replace-reactdom-hydrate.js.map +1 -1
  203. package/dist/react19/replace-string-ref.d.ts.map +1 -1
  204. package/dist/react19/replace-string-ref.js.map +1 -1
  205. package/dist/react19/scoped-jsx-namespace.d.ts.map +1 -1
  206. package/dist/react19/scoped-jsx-namespace.js +2 -6
  207. package/dist/react19/scoped-jsx-namespace.js.map +1 -1
  208. package/dist/react19/use-context-hook.d.ts.map +1 -1
  209. package/dist/react19/use-context-hook.js +1 -1
  210. package/dist/react19/use-context-hook.js.map +1 -1
  211. package/dist/react19/use-ref-required-initial.d.ts.map +1 -1
  212. package/dist/react19/use-ref-required-initial.js +3 -1
  213. package/dist/react19/use-ref-required-initial.js.map +1 -1
  214. package/dist/refactoring/class-to-functional.d.ts.map +1 -1
  215. package/dist/refactoring/class-to-functional.js +7 -3
  216. package/dist/refactoring/class-to-functional.js.map +1 -1
  217. package/dist/refactoring/create-class-to-es6.d.ts.map +1 -1
  218. package/dist/refactoring/create-class-to-es6.js +1 -1
  219. package/dist/refactoring/create-class-to-es6.js.map +1 -1
  220. package/dist/refactoring/create-element-to-jsx.d.ts.map +1 -1
  221. package/dist/refactoring/create-element-to-jsx.js +5 -7
  222. package/dist/refactoring/create-element-to-jsx.js.map +1 -1
  223. package/dist/refactoring/fix-async-effect.d.ts.map +1 -1
  224. package/dist/refactoring/fix-async-effect.js.map +1 -1
  225. package/dist/refactoring/manual-bind-to-arrow.d.ts.map +1 -1
  226. package/dist/refactoring/manual-bind-to-arrow.js.map +1 -1
  227. package/dist/refactoring/prop-types-to-typescript.d.ts +1 -1
  228. package/dist/refactoring/prop-types-to-typescript.d.ts.map +1 -1
  229. package/dist/refactoring/prop-types-to-typescript.js +2 -2
  230. package/dist/refactoring/prop-types-to-typescript.js.map +1 -1
  231. package/dist/refactoring/pure-render-mixin.d.ts.map +1 -1
  232. package/dist/refactoring/pure-render-mixin.js +2 -8
  233. package/dist/refactoring/pure-render-mixin.js.map +1 -1
  234. package/dist/refactoring/sort-comp.d.ts.map +1 -1
  235. package/dist/refactoring/sort-comp.js +1 -1
  236. package/dist/refactoring/sort-comp.js.map +1 -1
  237. package/dist/search/find-deprecated-lifecycles.d.ts +1 -1
  238. package/dist/search/find-deprecated-lifecycles.d.ts.map +1 -1
  239. package/dist/search/find-deprecated-lifecycles.js +2 -2
  240. package/dist/search/find-deprecated-lifecycles.js.map +1 -1
  241. package/dist/search/find-effects-without-cleanup.d.ts +1 -1
  242. package/dist/search/find-effects-without-cleanup.d.ts.map +1 -1
  243. package/dist/search/find-effects-without-cleanup.js +7 -9
  244. package/dist/search/find-effects-without-cleanup.js.map +1 -1
  245. package/dist/search/find-enzyme-usage.d.ts.map +1 -1
  246. package/dist/search/find-enzyme-usage.js.map +1 -1
  247. package/dist/search/find-function-component-default-props.d.ts +1 -1
  248. package/dist/search/find-function-component-default-props.d.ts.map +1 -1
  249. package/dist/search/find-function-component-default-props.js +2 -2
  250. package/dist/search/find-function-component-default-props.js.map +1 -1
  251. package/dist/search/find-hard-coded-strings.d.ts.map +1 -1
  252. package/dist/search/find-hard-coded-strings.js.map +1 -1
  253. package/dist/search/find-hook-usage.d.ts.map +1 -1
  254. package/dist/search/find-hook-usage.js.map +1 -1
  255. package/dist/search/find-legacy-react-apis.d.ts +1 -1
  256. package/dist/search/find-legacy-react-apis.d.ts.map +1 -1
  257. package/dist/search/find-legacy-react-apis.js +1 -1
  258. package/dist/search/find-legacy-react-apis.js.map +1 -1
  259. package/dist/search/find-missing-use-client-directive.d.ts.map +1 -1
  260. package/dist/search/find-missing-use-client-directive.js +11 -10
  261. package/dist/search/find-missing-use-client-directive.js.map +1 -1
  262. package/dist/search/find-prop-usage.d.ts.map +1 -1
  263. package/dist/search/find-prop-usage.js.map +1 -1
  264. package/dist/search/find-react-component.d.ts.map +1 -1
  265. package/dist/search/find-react-component.js.map +1 -1
  266. package/dist/search/find-reactdom-root-apis.d.ts.map +1 -1
  267. package/dist/search/find-reactdom-root-apis.js +2 -42
  268. package/dist/search/find-reactdom-root-apis.js.map +1 -1
  269. package/dist/search/find-redux-stores.d.ts +1 -1
  270. package/dist/search/find-redux-stores.d.ts.map +1 -1
  271. package/dist/search/find-redux-stores.js +1 -1
  272. package/dist/search/find-redux-stores.js.map +1 -1
  273. package/dist/search/find-server-rendering-usage.d.ts.map +1 -1
  274. package/dist/search/find-server-rendering-usage.js +13 -54
  275. package/dist/search/find-server-rendering-usage.js.map +1 -1
  276. package/dist/simplify-object-pattern-property.d.ts.map +1 -1
  277. package/dist/simplify-object-pattern-property.js.map +1 -1
  278. package/dist/simplify-react-imports.d.ts.map +1 -1
  279. package/dist/simplify-react-imports.js +1 -1
  280. package/dist/simplify-react-imports.js.map +1 -1
  281. package/dist/testing/enzyme-host-components.d.ts.map +1 -1
  282. package/dist/testing/enzyme-host-components.js +2 -2
  283. package/dist/testing/enzyme-host-components.js.map +1 -1
  284. package/dist/testing/enzyme-to-react-testing-library.d.ts.map +1 -1
  285. package/dist/testing/enzyme-to-react-testing-library.js +11 -19
  286. package/dist/testing/enzyme-to-react-testing-library.js.map +1 -1
  287. package/dist/testing/enzyme-usage.js +2 -2
  288. package/dist/testing/enzyme-usage.js.map +1 -1
  289. package/dist/testing/enzyme-wrapper-scope.d.ts.map +1 -1
  290. package/dist/testing/enzyme-wrapper-scope.js +5 -12
  291. package/dist/testing/enzyme-wrapper-scope.js.map +1 -1
  292. package/dist/util/react-class.d.ts +2 -0
  293. package/dist/util/react-class.d.ts.map +1 -1
  294. package/dist/util/react-class.js +14 -0
  295. package/dist/util/react-class.js.map +1 -1
  296. package/dist/util/react-matchers.d.ts +8 -0
  297. package/dist/util/react-matchers.d.ts.map +1 -0
  298. package/dist/util/react-matchers.js +25 -0
  299. package/dist/util/react-matchers.js.map +1 -0
  300. package/dist/zustand/redux-to-zustand.d.ts.map +1 -1
  301. package/dist/zustand/redux-to-zustand.js +20 -20
  302. package/dist/zustand/redux-to-zustand.js.map +1 -1
  303. package/package.json +2 -2
  304. package/src/i18n/translate-hard-coded-strings.ts +5 -12
  305. package/src/index.ts +3 -12
  306. package/src/migration/change-component-prop-value.ts +0 -40
  307. package/src/migration/cra-to-vite/add-vite-config.ts +0 -10
  308. package/src/migration/cra-to-vite/cra-to-vite.ts +0 -3
  309. package/src/migration/cra-to-vite/find-cra-config-blockers.ts +2 -7
  310. package/src/migration/cra-to-vite/find-cra-env-file-blockers.ts +0 -7
  311. package/src/migration/cra-to-vite/find-cra-source-blockers.ts +0 -9
  312. package/src/migration/cra-to-vite/find-cra-to-vite-blockers.ts +0 -4
  313. package/src/migration/cra-to-vite/migrate-cra-package.ts +0 -1
  314. package/src/migration/cra-to-vite/migrate-cra-svg-imports.ts +3 -4
  315. package/src/migration/cra-to-vite/migrate-cra-tests-to-vitest.ts +1 -3
  316. package/src/migration/cra-to-vite/move-public-index-html.ts +1 -13
  317. package/src/migration/cra-to-vite/remove-cra-configuration.ts +0 -1
  318. package/src/migration/cra-to-vite/rename-jsx-files.ts +0 -4
  319. package/src/migration/cra-to-vite/rename-process-env-react-app.ts +1 -17
  320. package/src/migration/cra-to-vite/rename-react-app-env-vars-in-env-files.ts +1 -11
  321. package/src/migration/cra-to-vite/replace-react-scripts-dependency.ts +1 -12
  322. package/src/migration/cra-to-vite/update-react-app-env-types.ts +0 -9
  323. package/src/migration/cra-to-vite/update-react-scripts-scripts.ts +0 -15
  324. package/src/migration/cra-to-vite/update-tsconfig-for-vite.ts +0 -11
  325. package/src/mui/adapt-v4-theme.ts +2 -7
  326. package/src/mui/add-component-prop.ts +0 -7
  327. package/src/mui/add-emotion-prepend.ts +5 -17
  328. package/src/mui/convert-mui-imports.ts +1 -12
  329. package/src/mui/convert-prop-to-sx.ts +1 -9
  330. package/src/mui/mark-manual-migration.ts +0 -6
  331. package/src/mui/mark-palette-mode-usage.ts +0 -6
  332. package/src/mui/move-component-prop-to-slot.ts +0 -9
  333. package/src/mui/move-primary-text-to-children.ts +0 -5
  334. package/src/mui/move-system-props-to-sx.ts +1 -11
  335. package/src/mui/remove-component-prop.ts +0 -5
  336. package/src/mui/remove-root-ref.ts +2 -8
  337. package/src/mui/remove-spacing-px-suffix.ts +3 -11
  338. package/src/mui/rename-component-prop.ts +0 -7
  339. package/src/mui/rename-joy-css-variables.ts +0 -6
  340. package/src/mui/rename-theme-palette-type.ts +0 -5
  341. package/src/mui/replace-box-border-radius.ts +0 -5
  342. package/src/mui/replace-breakpoints-width.ts +0 -2
  343. package/src/mui/replace-component-class.ts +0 -10
  344. package/src/mui/replace-components-with-slots.ts +0 -8
  345. package/src/mui/replace-import-paths.ts +0 -11
  346. package/src/mui/replace-in-string-literals.ts +0 -7
  347. package/src/mui/replace-list-item-button-prop.ts +3 -10
  348. package/src/mui/replace-tabs-scroll-buttons.ts +0 -5
  349. package/src/mui/replace-theme-color-functions.ts +9 -26
  350. package/src/mui/replace-theme-spacing-unit.ts +0 -6
  351. package/src/mui/replace-typography-round.ts +0 -5
  352. package/src/mui/shift-hidden-down-props.ts +3 -12
  353. package/src/mui/update-theme-breakpoints.ts +0 -8
  354. package/src/mui/upgrade-grid-props.ts +1 -9
  355. package/src/react-native/view-prop-types.ts +4 -26
  356. package/src/react16/error-boundaries.ts +1 -20
  357. package/src/react16/find-dom-node.ts +0 -17
  358. package/src/react16/react-dom-factories.ts +0 -14
  359. package/src/react16/react-prop-types.ts +4 -29
  360. package/src/react16/react-to-react-dom.ts +3 -20
  361. package/src/react17/migrate-deprecated-lifecycles.ts +6 -21
  362. package/src/react17/remove-event-persist.ts +157 -92
  363. package/src/react17/rename-unsafe-lifecycles.ts +1 -24
  364. package/src/react17/update-react-imports.ts +2 -27
  365. package/src/react17/use-new-jsx-transform.ts +2 -15
  366. package/src/react18/add-children-to-props.ts +2 -2
  367. package/src/react18/replace-reactdom-render.ts +2 -24
  368. package/src/react18/replace-render-callback.ts +5 -31
  369. package/src/react18/replace-unmount-component-at-node.ts +2 -22
  370. package/src/react19/find-context-consumer.ts +0 -23
  371. package/src/react19/find-deprecated-reactdom-apis.ts +20 -80
  372. package/src/react19/find-element-ref.ts +0 -15
  373. package/src/react19/find-legacy-context-api.ts +0 -12
  374. package/src/react19/no-implicit-ref-callback-return.ts +1 -19
  375. package/src/react19/remove-context-provider.ts +1 -25
  376. package/src/react19/remove-forward-ref.ts +3 -18
  377. package/src/react19/remove-prop-types.ts +0 -24
  378. package/src/react19/remove-react-fc.ts +3 -3
  379. package/src/react19/remove-unstable-batched-updates.ts +15 -129
  380. package/src/{react16 → react19}/replace-create-factory.ts +8 -21
  381. package/src/react19/replace-reactdom-hydrate.ts +2 -19
  382. package/src/react19/replace-string-ref.ts +0 -14
  383. package/src/react19/scoped-jsx-namespace.ts +3 -7
  384. package/src/react19/use-context-hook.ts +2 -20
  385. package/src/react19/use-ref-required-initial.ts +4 -17
  386. package/src/refactoring/class-to-functional.ts +9 -33
  387. package/src/refactoring/create-class-to-es6.ts +1 -15
  388. package/src/refactoring/create-element-to-jsx.ts +7 -31
  389. package/src/refactoring/fix-async-effect.ts +0 -28
  390. package/src/refactoring/manual-bind-to-arrow.ts +0 -23
  391. package/src/refactoring/prop-types-to-typescript.ts +3 -34
  392. package/src/refactoring/pure-render-mixin.ts +3 -30
  393. package/src/refactoring/sort-comp.ts +1 -11
  394. package/src/search/find-deprecated-lifecycles.ts +3 -6
  395. package/src/search/find-effects-without-cleanup.ts +5 -15
  396. package/src/search/find-enzyme-usage.ts +0 -3
  397. package/src/search/find-function-component-default-props.ts +3 -7
  398. package/src/search/find-hard-coded-strings.ts +0 -9
  399. package/src/search/find-hook-usage.ts +0 -10
  400. package/src/search/find-legacy-react-apis.ts +1 -18
  401. package/src/search/find-missing-use-client-directive.ts +13 -19
  402. package/src/search/find-prop-usage.ts +0 -11
  403. package/src/search/find-react-component.ts +0 -11
  404. package/src/search/find-reactdom-root-apis.ts +5 -44
  405. package/src/search/find-redux-stores.ts +1 -9
  406. package/src/search/find-server-rendering-usage.ts +15 -72
  407. package/src/simplify-object-pattern-property.ts +0 -8
  408. package/src/simplify-react-imports.ts +3 -23
  409. package/src/testing/enzyme-host-components.ts +3 -2
  410. package/src/testing/enzyme-to-react-testing-library.ts +10 -50
  411. package/src/testing/enzyme-usage.ts +2 -2
  412. package/src/testing/enzyme-wrapper-scope.ts +7 -15
  413. package/src/util/react-class.ts +17 -1
  414. package/src/util/react-matchers.ts +34 -0
  415. package/src/zustand/redux-to-zustand.ts +21 -75
  416. package/dist/react16/replace-create-factory.d.ts.map +0 -1
  417. package/dist/react16/replace-create-factory.js.map +0 -1
  418. package/dist/react19/replace-act-import.d.ts +0 -9
  419. package/dist/react19/replace-act-import.d.ts.map +0 -1
  420. package/dist/react19/replace-act-import.js +0 -34
  421. package/dist/react19/replace-act-import.js.map +0 -1
  422. package/dist/react19/replace-react-shallow-renderer.d.ts +0 -8
  423. package/dist/react19/replace-react-shallow-renderer.d.ts.map +0 -1
  424. package/dist/react19/replace-react-shallow-renderer.js +0 -49
  425. package/dist/react19/replace-react-shallow-renderer.js.map +0 -1
  426. package/dist/react19/replace-use-form-state.d.ts +0 -8
  427. package/dist/react19/replace-use-form-state.d.ts.map +0 -1
  428. package/dist/react19/replace-use-form-state.js +0 -57
  429. package/dist/react19/replace-use-form-state.js.map +0 -1
  430. package/src/react19/replace-act-import.ts +0 -36
  431. package/src/react19/replace-react-shallow-renderer.ts +0 -47
  432. package/src/react19/replace-use-form-state.ts +0 -69
@@ -6,27 +6,10 @@ import {FindReactDomRootApis} from "./find-reactdom-root-apis";
6
6
  import {FindDeprecatedLifecycles} from "./find-deprecated-lifecycles";
7
7
  import {FindFunctionComponentDefaultProps} from "./find-function-component-default-props";
8
8
 
9
- /**
10
- * Finds the legacy React APIs that block an upgrade to React 19, by running the finders that each cover one family
11
- * of them. Every finder keeps its own marker and data table, so a call is reported once, by the finder that owns it:
12
- *
13
- * - `FindDeprecatedReactDomAPIs`: `findDOMNode`, `unmountComponentAtNode`, `createFactory`, `renderToNodeStream`.
14
- * - `FindLegacyContextAPI`: `contextTypes`, `childContextTypes` and `getChildContext`.
15
- * - `FindServerRenderingUsage`: server rendering entry points.
16
- * - `FindReactDomRootApis`: `ReactDOM.render` and `ReactDOM.hydrate`, matched by import.
17
- * - `FindDeprecatedLifecycles`: `componentWillMount`, `componentWillReceiveProps`, `componentWillUpdate`.
18
- * - `FindFunctionComponentDefaultProps`: `defaultProps` on function components.
19
- *
20
- * It does not report string refs, `Context.Provider`, the `act` import, `unstable_batchedUpdates` or
21
- * `react-test-renderer/shallow`; the step recipes migrate those without a finder.
22
- *
23
- * To see which React version a repository is on, use the `DevCenterReactStarter` card in DevCenter, which reads
24
- * the resolved versions.
25
- */
26
9
  export class FindLegacyReactApis extends Recipe {
27
10
  readonly name = "org.openrewrite.react.search.find-legacy-react-apis";
28
11
  readonly displayName = "Find legacy React API usage";
29
- readonly description = "Finds the removed and deprecated React APIs that block an upgrade to React 19 (`ReactDOM.render` and `hydrate`, `findDOMNode`, legacy context, `componentWill*` lifecycles, function component `defaultProps` and more) by running one finder for each family, each with its own data table. For where a repository sits on the upgrade path by version, see the `DevCenterReactStarter` card in DevCenter.";
12
+ readonly description = "Finds the removed and deprecated React APIs that block an upgrade to React 19 (`ReactDOM.render` and `hydrate`, `findDOMNode`, legacy context, `componentWill*` lifecycles, function component `defaultProps` and more) by running one finder for each family, each with its own data table. String refs, `Context.Provider`, the `act` import, `unstable_batchedUpdates` and `react-test-renderer/shallow` are not reported, since the upgrade migrates them without a finder. For where a repository sits on the upgrade path by version, see the `DevCenterReactStarter` card in DevCenter.";
30
13
 
31
14
  async recipeList(): Promise<Recipe[]> {
32
15
  return [
@@ -1,7 +1,8 @@
1
1
  import {Column, DataTable, ExecutionContext, foundSearchResult, Recipe, TreeVisitor, check, not} from "@openrewrite/rewrite";
2
- import {JavaScriptVisitor, JS, isVendoredOrBundled} from "@openrewrite/rewrite/javascript";
2
+ import {JavaScriptVisitor, JS, MethodMatcher, isVendoredOrBundled} from "@openrewrite/rewrite/javascript";
3
3
  import {J} from "@openrewrite/rewrite/java";
4
- import {extendsReactComponentByName} from "../util/react-class";
4
+ import {extendsReactComponent} from "../util/react-class";
5
+ import {reactFunction} from "../util/react-matchers";
5
6
 
6
7
  class MissingDirectiveRow {
7
8
  @Column({displayName: "File path", description: "The component file with no `'use client'` directive"})
@@ -11,11 +12,14 @@ class MissingDirectiveRow {
11
12
  reasons!: string;
12
13
  }
13
14
 
14
- const CLIENT_HOOKS = new Set([
15
- 'useState', 'useEffect', 'useLayoutEffect', 'useReducer', 'useRef', 'useContext', 'useCallback', 'useMemo',
16
- 'useTransition', 'useDeferredValue', 'useImperativeHandle', 'useSyncExternalStore', 'useInsertionEffect',
17
- 'useActionState', 'useFormState', 'useOptimistic',
18
- ]);
15
+ const CLIENT_HOOKS = [
16
+ ...[
17
+ 'useState', 'useEffect', 'useLayoutEffect', 'useReducer', 'useRef', 'useContext', 'useCallback', 'useMemo',
18
+ 'useTransition', 'useDeferredValue', 'useImperativeHandle', 'useSyncExternalStore', 'useInsertionEffect',
19
+ 'useActionState', 'useOptimistic',
20
+ ].map(reactFunction),
21
+ new MethodMatcher("react-dom useFormState(..)"),
22
+ ];
19
23
  const BROWSER_GLOBALS = new Set(['window', 'document', 'localStorage', 'sessionStorage', 'navigator']);
20
24
 
21
25
  /** Directives are the string-literal statements at the top of a file. */
@@ -29,14 +33,6 @@ export function hasDirective(cu: JS.CompilationUnit, directive: string): boolean
29
33
  return false;
30
34
  }
31
35
 
32
- /**
33
- * Finds component files that use client-only features but have no `'use client'` directive.
34
- *
35
- * In the Next.js App Router and other React Server Components setups, a file that uses state,
36
- * effects, class components or browser globals fails unless it, or a file above it, is marked as a
37
- * client boundary. This is a find-only recipe: the right boundary is usually the component that
38
- * owns the interaction, which a recipe cannot tell. Only `.tsx` and `.jsx` files are considered.
39
- */
40
36
  export class FindMissingUseClientDirective extends Recipe {
41
37
  readonly name = "org.openrewrite.react.search.find-missing-use-client-directive";
42
38
  readonly displayName = "Find client components missing a `'use client'` directive";
@@ -78,14 +74,12 @@ export class FindMissingUseClientDirective extends Recipe {
78
74
 
79
75
  override async visitMethodInvocation(method: J.MethodInvocation, ctx: ExecutionContext): Promise<J | undefined> {
80
76
  const m = await super.visitMethodInvocation(method, ctx) as J.MethodInvocation;
81
- const select = m.select?.element;
82
- const reactReceiver = select?.kind === J.Kind.Identifier && (select as J.Identifier).simpleName === 'React';
83
- return CLIENT_HOOKS.has(m.name.simpleName) && (!select || reactReceiver) ? this.note(m, m.name.simpleName) : m;
77
+ return CLIENT_HOOKS.some(matcher => matcher.matches(m.methodType)) ? this.note(m, m.methodType!.name) : m;
84
78
  }
85
79
 
86
80
  override async visitClassDeclaration(decl: J.ClassDeclaration, ctx: ExecutionContext): Promise<J | undefined> {
87
81
  const c = await super.visitClassDeclaration(decl, ctx) as J.ClassDeclaration;
88
- return extendsReactComponentByName(c) ? this.note(c, 'class component') : c;
82
+ return extendsReactComponent(c) ? this.note(c, 'class component') : c;
89
83
  }
90
84
 
91
85
  override async visitFieldAccess(fieldAccess: J.FieldAccess, ctx: ExecutionContext): Promise<J | undefined> {
@@ -22,17 +22,6 @@ class FindPropUsageRow {
22
22
  isSpread!: boolean;
23
23
  }
24
24
 
25
- /**
26
- * Finds prop usages across React components.
27
- *
28
- * Detects:
29
- * - String literal props: `<Button variant="primary" />`
30
- * - Expression props: `<Button onClick={handler} />`
31
- * - Boolean shorthand props: `<Button disabled />`
32
- * - Spread props: `<Button {...props} />`
33
- *
34
- * Can optionally filter by component name and/or prop name.
35
- */
36
25
  export class FindPropUsage extends Recipe {
37
26
  readonly name = "org.openrewrite.react.search.find-prop-usage";
38
27
  readonly displayName: string = "Find React prop usage";
@@ -22,17 +22,6 @@ class FindReactComponentRow {
22
22
  aliasName!: string;
23
23
  }
24
24
 
25
- /**
26
- * Finds usages of a specific React component across source files.
27
- *
28
- * Detects:
29
- * - Named imports: `import { Button } from 'lib'`
30
- * - Default imports: `import Button from 'lib'`
31
- * - Aliased imports: `import { Button as Btn } from 'lib'`
32
- * - Namespace access: `<Lib.Button />`
33
- * - JSX elements: `<Button />` and `<Button>...</Button>`
34
- * - Re-exports: `export { Button } from 'lib'`
35
- */
36
25
  export class FindReactComponent extends Recipe {
37
26
  readonly name = "org.openrewrite.react.search.find-react-component";
38
27
  readonly displayName: string = "Find React component";
@@ -1,5 +1,5 @@
1
1
  import {Column, DataTable, ExecutionContext, foundSearchResult, Recipe, TreeVisitor, check, not} from "@openrewrite/rewrite";
2
- import {isVendoredOrBundled, JavaScriptVisitor, JS, moduleBindings, resolve} from "@openrewrite/rewrite/javascript";
2
+ import {isVendoredOrBundled, JavaScriptVisitor, JS, MethodMatcher} from "@openrewrite/rewrite/javascript";
3
3
  import {J} from "@openrewrite/rewrite/java";
4
4
 
5
5
  class ReactDomRootApiRow {
@@ -19,13 +19,10 @@ export const REACTDOM_ROOT_APIS = new Map<string, { api: string; upgradeStep: st
19
19
  ['hydrate', {api: 'ReactDOM.hydrate', upgradeStep: 'org.openrewrite.react.migrate.react-18-to-19', migratedBy: 'org.openrewrite.react.19.replace-reactdom-hydrate'}],
20
20
  ]);
21
21
 
22
+ const ROOT_API_CALLS = [...REACTDOM_ROOT_APIS.entries()].map(([member, found]) =>
23
+ ({matcher: new MethodMatcher(`react-dom ${member}(..)`), found}));
24
+
22
25
  /**
23
- * Finds calls of `ReactDOM.render` and `ReactDOM.hydrate`, which React 19 removed.
24
- *
25
- * A call is matched by where its callee was imported from, not by how it is spelled: `ReactDOM.render` through a
26
- * default, namespace or `require` binding of `react-dom` under any local name, and `render` or `hydrate` imported by
27
- * name, renamed or not. A local function that happens to be called `render` is not reported.
28
- *
29
26
  * @see https://react.dev/blog/2024/04/25/react-19-upgrade-guide#removed-reactdom-render
30
27
  */
31
28
  export class FindReactDomRootApis extends Recipe {
@@ -45,55 +42,19 @@ export class FindReactDomRootApis extends Recipe {
45
42
 
46
43
  return check(not(isVendoredOrBundled()), new class extends JavaScriptVisitor<ExecutionContext> {
47
44
  private filePath = "";
48
- /** Local name to the `react-dom` member it was imported by name, for `import {render as r} from 'react-dom'`. */
49
- private named = new Map<string, string>();
50
45
 
51
46
  override async visitJsCompilationUnit(cu: JS.CompilationUnit, ctx: ExecutionContext): Promise<J | undefined> {
52
47
  this.filePath = cu.sourcePath ?? "";
53
- this.named.clear();
54
48
  return super.visitJsCompilationUnit(cu, ctx);
55
49
  }
56
50
 
57
- protected override async visitImportSpecifier(spec: JS.ImportSpecifier, ctx: ExecutionContext): Promise<J | undefined> {
58
- const imp = this.cursor.firstEnclosing((n: any): n is JS.Import => n?.kind === JS.Kind.Import);
59
- const module = (imp?.moduleSpecifier?.element as J.Literal | undefined)?.value;
60
- if (module === 'react-dom') {
61
- const specifier = spec.specifier as J;
62
- if (specifier.kind === JS.Kind.Alias) {
63
- const alias = specifier as JS.Alias;
64
- const imported = alias.propertyName.element as J;
65
- if (imported.kind === J.Kind.Identifier && alias.alias.kind === J.Kind.Identifier) {
66
- this.named.set((alias.alias as J.Identifier).simpleName, (imported as J.Identifier).simpleName);
67
- }
68
- } else if (specifier.kind === J.Kind.Identifier) {
69
- this.named.set((specifier as J.Identifier).simpleName, (specifier as J.Identifier).simpleName);
70
- }
71
- }
72
- return super.visitImportSpecifier(spec, ctx);
73
- }
74
-
75
51
  override async visitMethodInvocation(method: J.MethodInvocation, ctx: ExecutionContext): Promise<J | undefined> {
76
52
  const m = await super.visitMethodInvocation(method, ctx) as J.MethodInvocation;
77
- const select = m.select?.element as J | undefined;
78
- let member: string | undefined;
79
- if (select) {
80
- if (select.kind === J.Kind.Identifier && moduleBindings(this).moduleOf((select as J.Identifier).simpleName) === 'react-dom') {
81
- member = m.name.simpleName;
82
- }
83
- } else if (this.named.has(m.name.simpleName) && this.boundByTheImport(m.name)) {
84
- member = this.named.get(m.name.simpleName);
85
- }
86
- const found = member ? REACTDOM_ROOT_APIS.get(member) : undefined;
53
+ const found = ROOT_API_CALLS.find(({matcher}) => matcher.matches(m.methodType))?.found;
87
54
  if (!found) return m;
88
55
  dataTable.insertRow(ctx, {filePath: this.filePath, api: found.api, upgradeStep: found.upgradeStep});
89
56
  return foundSearchResult(m, found.api) as J.MethodInvocation;
90
57
  }
91
-
92
- /** Whether the name still reads the import, rather than a parameter or local declaration that shadows it. */
93
- private boundByTheImport(name: J.Identifier): boolean {
94
- const owner = resolve(this.cursor, name);
95
- return owner === undefined || owner.kind === JS.Kind.CompilationUnit;
96
- }
97
58
  }());
98
59
  }
99
60
  }
@@ -6,20 +6,12 @@ import {
6
6
  } from "../zustand/redux-stores";
7
7
 
8
8
  /**
9
- * Inventories the Redux stores of a repository for a migration to zustand. A store is a candidate when it is a
10
- * `configureStore` call whose `reducer` is an object of `createSlice` reducers, in the same source or imported from
11
- * a relative module, and whose options are only `reducer`. Every other store gets a row for each reason it is not,
12
- * such as a legacy `createStore`, custom middleware or a hand-written reducer. Stores are attributed by what the
13
- * source imports from `redux` or `@reduxjs/toolkit`; namespace imports and `require` are not followed.
14
- *
15
- * Only the store's setup is checked; the components and modules that read or dispatch to it are not.
16
- *
17
9
  * @see https://zustand.docs.pmnd.rs/guides/migrating-to-zustand
18
10
  */
19
11
  export class FindReduxStores extends ScanningRecipe<Map<string, SliceModule>> {
20
12
  readonly name = "org.openrewrite.react.search.find-redux-stores";
21
13
  readonly displayName = "Find Redux stores";
22
- readonly description = "Finds the Redux stores created with `createStore` or Redux Toolkit's `configureStore` and records whether each one's setup can move to zustand: a `configureStore` call whose `reducer` is an object of `createSlice` reducers without `extraReducers`, and no other option, is a candidate. Every other store is recorded with the reasons it is not, such as a legacy `createStore`, custom middleware, enhancers, preloaded state or a hand-written reducer. The components and modules that use a store are not checked.";
14
+ readonly description = "Finds the Redux stores created with `createStore` or Redux Toolkit's `configureStore` and records whether each one's setup can move to zustand: a `configureStore` call whose `reducer` is an object of `createSlice` reducers without `extraReducers`, and no other option, is a candidate. Every other store is recorded with the reasons it is not, such as a legacy `createStore`, custom middleware, enhancers, preloaded state or a hand-written reducer. The components and modules that use a store are not checked. Stores are found through what a source imports from `redux` or `@reduxjs/toolkit`; namespace imports and `require` are not followed.";
23
15
 
24
16
  private readonly stores = new DataTable<ReduxStoreRow>(
25
17
  REDUX_STORES_TABLE, "Redux stores",
@@ -1,6 +1,7 @@
1
1
  import {Column, DataTable, ExecutionContext, foundSearchResult, Recipe, TreeVisitor, check, not} from "@openrewrite/rewrite";
2
2
  import {JavaScriptVisitor, JS, isVendoredOrBundled} from "@openrewrite/rewrite/javascript";
3
3
  import {isIdentifier, J} from "@openrewrite/rewrite/java";
4
+ import {anyOf, typedOrNamedCall} from "../util/react-matchers";
4
5
 
5
6
  class ServerRenderingRow {
6
7
  @Column({displayName: "File path", description: "The file path where the SSR API is used"})
@@ -20,17 +21,13 @@ const SSR_APIS = new Map<string, string>([
20
21
  ['renderToStaticNodeStream', 'Use renderToPipeableStream or renderToReadableStream instead (removed in React 19)'],
21
22
  ]);
22
23
 
23
- /**
24
- * Finds usage of React server-side rendering APIs from `react-dom/server`.
25
- *
26
- * Detects:
27
- * - `renderToString(element)` -- synchronous SSR, consider streaming alternatives
28
- * - `renderToStaticMarkup(element)` -- synchronous static markup, consider streaming
29
- * - `renderToNodeStream(element)` -- removed in React 19, use `renderToPipeableStream`
30
- * - `renderToStaticNodeStream(element)` -- removed in React 19, use streaming APIs
31
- *
32
- * Also detects named imports and namespace calls (ReactDOMServer.renderToString, ReactDOM.renderToString).
33
- */
24
+ const SSR_CALLS = [...SSR_APIS].map(([api, replacement]) => {
25
+ // A namespace or default import of `react-dom/server` is declared on `react-dom` (openrewrite/rewrite#9994)
26
+ const matcher = anyOf(`react-dom/server ${api}(..)`, `react-dom ${api}(..)`);
27
+ const calls = ['ReactDOMServer', 'ReactDOM'].map(receiver => typedOrNamedCall(matcher, receiver, api));
28
+ return {api, replacement, matches: (method: J.MethodInvocation) => calls.some(call => call(method))};
29
+ });
30
+
34
31
  export class FindServerRenderingUsage extends Recipe {
35
32
  readonly name = "org.openrewrite.react.search.find-server-rendering-usage";
36
33
  readonly displayName = "Find server-side rendering API usage";
@@ -48,74 +45,20 @@ export class FindServerRenderingUsage extends Recipe {
48
45
 
49
46
  return check(not(isVendoredOrBundled()), new class extends JavaScriptVisitor<ExecutionContext> {
50
47
  private filePath = "";
51
- private importedSsrApis = new Set<string>();
52
48
 
53
49
  override async visitJsCompilationUnit(cu: JS.CompilationUnit, ctx: ExecutionContext): Promise<J | undefined> {
54
50
  this.filePath = cu.sourcePath ?? "";
55
- this.importedSsrApis.clear();
56
51
  return super.visitJsCompilationUnit(cu, ctx);
57
52
  }
58
53
 
59
- // Detect imports of SSR APIs
60
- override async visitImportSpecifier(spec: JS.ImportSpecifier, ctx: ExecutionContext): Promise<J | undefined> {
61
- const specifier = spec.specifier;
62
-
63
- let importedName: string | undefined;
64
- if (specifier.kind === JS.Kind.Alias) {
65
- const alias = specifier as JS.Alias;
66
- const propName = alias.propertyName.element;
67
- if (isIdentifier(propName)) {
68
- importedName = propName.simpleName;
69
- }
70
- } else if (isIdentifier(specifier)) {
71
- importedName = specifier.simpleName;
72
- }
73
-
74
- const importReplacement = importedName ? SSR_APIS.get(importedName) : undefined;
75
- if (importedName && importReplacement) {
76
- this.importedSsrApis.add(importedName);
77
- dataTable.insertRow(ctx, {
78
- filePath: this.filePath,
79
- apiName: importedName,
80
- replacement: importReplacement
81
- });
82
- return foundSearchResult(spec, `SSR API: ${importedName}`);
83
- }
84
-
85
- return super.visitImportSpecifier(spec, ctx);
86
- }
87
-
88
- // Detect method calls: renderToString(...), ReactDOMServer.renderToString(...), etc.
89
54
  override async visitMethodInvocation(method: J.MethodInvocation, ctx: ExecutionContext): Promise<J | undefined> {
90
- let m = await super.visitMethodInvocation(method, ctx) as J.MethodInvocation;
91
-
92
- const methodName = m.name.simpleName;
93
-
94
- const replacement = SSR_APIS.get(methodName);
95
- if (!replacement) return m;
96
-
97
- // Direct call from named import: renderToString(...)
98
- if (!m.select && this.importedSsrApis.has(methodName)) {
99
- return foundSearchResult(m, `SSR API: ${methodName}`);
100
- }
101
-
102
- // Namespace call: ReactDOMServer.renderToString(...), ReactDOM.renderToString(...)
103
- if (m.select) {
104
- const select = (m.select as any).element ?? m.select;
105
- if (isIdentifier(select)) {
106
- const ns = select.simpleName;
107
- if (ns === 'ReactDOMServer' || ns === 'ReactDOM') {
108
- dataTable.insertRow(ctx, {
109
- filePath: this.filePath,
110
- apiName: `${ns}.${methodName}`,
111
- replacement
112
- });
113
- return foundSearchResult(m, `SSR API: ${ns}.${methodName}`);
114
- }
115
- }
116
- }
117
-
118
- return m;
55
+ const m = await super.visitMethodInvocation(method, ctx) as J.MethodInvocation;
56
+ const call = SSR_CALLS.find(c => c.matches(m));
57
+ if (!call) return m;
58
+ const select = m.select?.element;
59
+ const apiName = select && isIdentifier(select) ? `${select.simpleName}.${call.api}` : call.api;
60
+ dataTable.insertRow(ctx, {filePath: this.filePath, apiName, replacement: call.replacement});
61
+ return foundSearchResult(m, `SSR API: ${apiName}`);
119
62
  }
120
63
  }());
121
64
  }
@@ -2,14 +2,6 @@ import {ExecutionContext, Recipe, TreeVisitor, check, mapAsync, not, updateIfCha
2
2
  import {JavaScriptVisitor, JS, isVendoredOrBundled} from "@openrewrite/rewrite/javascript";
3
3
  import {J} from "@openrewrite/rewrite/java";
4
4
 
5
- /**
6
- * Simplifies object pattern properties where the key and value have the same name.
7
- *
8
- * Examples:
9
- * - `{ x: x }` → `{ x }`
10
- * - `{ ref: ref, ...props }` → `{ ref, ...props }`
11
- * - `{ foo: foo, bar: bar }` → `{ foo, bar }`
12
- */
13
5
  export class SimplifyObjectPatternProperty extends Recipe {
14
6
  readonly name = "org.openrewrite.javascript.cleanup.simplify-object-pattern-property";
15
7
  readonly displayName: string = "Simplify object pattern properties";
@@ -1,5 +1,5 @@
1
1
  import {ExecutionContext, Recipe, TreeVisitor, check, not} from "@openrewrite/rewrite";
2
- import {JavaScriptVisitor, JS, maybeAddImport, isVendoredOrBundled, namesDeclaredIn} from "@openrewrite/rewrite/javascript";
2
+ import {JavaScriptVisitor, JS, maybeBind, isVendoredOrBundled, namesDeclaredIn} from "@openrewrite/rewrite/javascript";
3
3
  import {J} from "@openrewrite/rewrite/java";
4
4
  import {importBindings} from "./util/module-imports";
5
5
 
@@ -73,26 +73,6 @@ function getReactMethodName(method: J.MethodInvocation): string | undefined {
73
73
  return methodName;
74
74
  }
75
75
 
76
- /**
77
- * Simplifies React namespace usage by converting `React.xxx` to direct imports.
78
- *
79
- * Instead of:
80
- * ```tsx
81
- * import React from 'react';
82
- * const [count, setCount] = React.useState(0);
83
- * ```
84
- *
85
- * This recipe produces:
86
- * ```tsx
87
- * import React, { useState } from 'react';
88
- * const [count, setCount] = useState(0);
89
- * ```
90
- *
91
- * This is a modern best practice that:
92
- * - Reduces bundle size when tree-shaking is applied
93
- * - Makes code more readable
94
- * - Aligns with React team recommendations
95
- */
96
76
  export class SimplifyReactImports extends Recipe {
97
77
  readonly name = "org.openrewrite.react.simplify-react-imports";
98
78
  readonly displayName: string = "Simplify `React.xxx` to direct imports";
@@ -105,7 +85,7 @@ export class SimplifyReactImports extends Recipe {
105
85
 
106
86
  override async visitJsCompilationUnit(cu: JS.CompilationUnit, ctx: ExecutionContext): Promise<J | undefined> {
107
87
  this.usedExports = new Set<string>();
108
- // File-wide rather than in scope, as `maybeAddImport` aliases the import when any binding of the name is declared
88
+ // File-wide rather than in scope, as `maybeBind` aliases the import when any binding of the name is declared
109
89
  this.declaredNames = new Set(namesDeclaredIn(cu));
110
90
  for (const {local, name, module} of importBindings(cu)) {
111
91
  if (module === 'react' && local === name) this.declaredNames.delete(local);
@@ -115,7 +95,7 @@ export class SimplifyReactImports extends Recipe {
115
95
 
116
96
  // Already known to be referenced, since they were just unqualified
117
97
  for (const exportName of this.usedExports) {
118
- maybeAddImport(this, {module: "react", member: exportName, onlyIfReferenced: false});
98
+ maybeBind(this, {module: "react", member: exportName, onlyIfReferenced: false});
119
99
  }
120
100
 
121
101
  return result;
@@ -1,6 +1,6 @@
1
1
  import {JS, JSX, namesReferencedWithin, walk} from "@openrewrite/rewrite/javascript";
2
2
  import {Expression, isIdentifier, J, Type} from "@openrewrite/rewrite/java";
3
- import {COMPONENT_BASES, unwrapBaseType} from "../util/react-class";
3
+ import {COMPONENT_BASES, reactComponentSupertype, unwrapBaseType} from "../util/react-class";
4
4
  import {importBindings, namespaceImports, resolveRelative} from "../util/module-imports";
5
5
 
6
6
  /**
@@ -152,7 +152,8 @@ function reactMember(node: J | undefined, names: ReadonlySet<string>): boolean {
152
152
  /** Whether a class extends `Component` or `PureComponent`, bare or as a member of `React`, so that its `render` is its own. */
153
153
  function reactBaseClass(declaration: J.ClassDeclaration): boolean {
154
154
  const base = unwrapBaseType(declaration.extends?.element);
155
- return base !== undefined && (isIdentifier(base) ? COMPONENT_BASES.has(base.simpleName) : reactMember(base, COMPONENT_BASES));
155
+ return reactComponentSupertype(declaration) ??
156
+ (base !== undefined && (isIdentifier(base) ? COMPONENT_BASES.has(base.simpleName) : reactMember(base, COMPONENT_BASES)));
156
157
  }
157
158
 
158
159
  /** A top-level declaration that can be a component, the export name it has, if any, and the body that renders it. */
@@ -1,6 +1,6 @@
1
- import {and, check, Cursor, DataTable, ExecutionContext, findMarker, MarkersKind, MarkupWarn, not, Option, or, randomId, RecipeRef, ScanningRecipe, SourceFile, Tree, TreePrinters, TreeVisitor} from "@openrewrite/rewrite";
1
+ import {and, check, Cursor, DataTable, ExecutionContext, findMarker, mapAsync, MarkersKind, MarkupWarn, not, Option, or, randomId, RecipeRef, ScanningRecipe, SourceFile, Tree, TreePrinters, TreeVisitor, updateIfChanged} from "@openrewrite/rewrite";
2
2
  import {isPlainText} from "@openrewrite/rewrite/text";
3
- import {AddDependencyOptions, autoFormat, Autodetect, capture, PrettierStyle, deconflict, findNodeResolutionResult, isTypeScript, isVendoredOrBundled, JavaScriptVisitor, JS, maybeAddImport, maybeRemoveImport, moduleBindings, namesUsedIn, pattern, walk, raw, rewrite, scopeOf, StyleKind, Template, template, usesMethod} from "@openrewrite/rewrite/javascript";
3
+ import {AddDependencyOptions, autoFormat, Autodetect, capture, PrettierStyle, deconflict, findNodeResolutionResult, isTypeScript, isVendoredOrBundled, JavaScriptVisitor, JS, maybeBind, maybeUnbind, moduleBindings, namesUsedIn, pattern, walk, raw, rewrite, scopeOf, StyleKind, Template, template, usesMethod} from "@openrewrite/rewrite/javascript";
4
4
  import {Expression, isIdentifier, J, Type, TypedTree} from "@openrewrite/rewrite/java";
5
5
  import {create} from "mutative";
6
6
  import {Json, JsonVisitor} from "@openrewrite/rewrite/json";
@@ -183,7 +183,6 @@ function dependencySteps(forecast: ConversionForecast) {
183
183
  return {rtl, dom18, rtl18: new AddTestingLibraryReact18(forecast, dom18)};
184
184
  }
185
185
 
186
- /** Adds {@link RTL_ADDITION}. */
187
186
  export class AddTestingLibraryReact extends EnzymeTestDependency {
188
187
  readonly name = "org.openrewrite.react.migrate.add-testing-library-react";
189
188
  readonly displayName = "Add `@testing-library/react` where Enzyme tests are migrated";
@@ -194,7 +193,6 @@ export class AddTestingLibraryReact extends EnzymeTestDependency {
194
193
  }
195
194
  }
196
195
 
197
- /** Adds {@link RTL_18_ADDITION}. */
198
196
  export class AddTestingLibraryReact18 extends EnzymeTestDependency {
199
197
  readonly name = "org.openrewrite.react.migrate.add-testing-library-react-18";
200
198
  readonly displayName = "Add `@testing-library/react` 16 where Enzyme tests on React 18 are migrated";
@@ -211,7 +209,6 @@ export class AddTestingLibraryReact18 extends EnzymeTestDependency {
211
209
  }
212
210
  }
213
211
 
214
- /** Adds {@link DOM_18_ADDITION}, the peer of {@link RTL_18_ADDITION}. */
215
212
  export class AddTestingLibraryDom18 extends EnzymeTestDependency {
216
213
  readonly name = "org.openrewrite.react.migrate.add-testing-library-dom-18";
217
214
  readonly displayName = "Add `@testing-library/dom` where Enzyme tests on React 18 are migrated";
@@ -572,31 +569,8 @@ function withoutStatements(block: J.Block, removed: ReadonlySet<string>): J.Bloc
572
569
  }
573
570
 
574
571
  /**
575
- * Converts an Enzyme `mount` wrapper only when all of its uses can be converted together, so no
576
- * partially migrated wrapper can escape. Inline expressions such as
577
- * `mount(<Button />).find('button').length` and `const wrapper = mount(<Button />)` declarations
578
- * whose every reference is a supported DOM read become RTL renders into a detached container.
579
- *
580
- * A `shallow` wrapper converts the same way where the full render cannot differ from the shallow
581
- * one: its component, scanned from the source it is imported from, creates host elements only and
582
- * runs no effects, and receives no component element from the test. `simulate` and `html()` stay
583
- * excluded there, since a shallow render calls a handler without bubbling and prints static markup.
584
- *
585
- * ```tsx
586
- * // before, where `Label` renders `<ul><li>{text}</li></ul>`
587
- * const wrapper = shallow(<Label text="a" />);
588
- * expect(wrapper.find('li').length).toBe(1);
589
- * // after
590
- * const wrapper = render(<Label text="a" />, {container: document.createElement('div')});
591
- * expect(wrapper.container.querySelectorAll('li').length).toBe(1);
592
- * ```
593
- *
594
- * Existing compatible RTL installation and DOM test setup are prerequisites. More complex
595
- * wrapper flows remain in the inventory rather than being guessed at.
596
- *
597
572
  * @see https://testing-library.com/docs/react-testing-library/migrate-from-enzyme/#how-to-migrate-from-enzyme-to-react-testing-library
598
573
  */
599
-
600
574
  export class EnzymeToReactTestingLibrary extends ScanningRecipe<Scanned> {
601
575
  readonly name: string = "org.openrewrite.react.migrate.enzyme-to-react-testing-library";
602
576
  readonly displayName: string = "Migrate Enzyme to React Testing Library";
@@ -1000,7 +974,7 @@ export class EnzymeToReactTestingLibrary extends ScanningRecipe<Scanned> {
1000
974
  /** The shared wrapper's declaration, typed as RTL's `RenderResult` where it had a type, which an Enzyme type was. */
1001
975
  private async renderResultDeclaration(declaration: J.VariableDeclarations, block: J.Block): Promise<J.VariableDeclarations> {
1002
976
  if (!declaration.typeExpression) return declaration;
1003
- const local = maybeAddImport(this, {module: RTL, member: "RenderResult", typeOnly: true, onlyIfReferenced: false}) ?? "RenderResult";
977
+ const local = maybeBind(this, {module: RTL, member: "RenderResult", typeOnly: true, onlyIfReferenced: false}) ?? "RenderResult";
1004
978
  const name = (declaration.variables[0].element.name as J.Identifier).simpleName;
1005
979
  const typed = await Template.builder().code(`let ${name}: ${local}`).build()
1006
980
  .apply(declaration, new Cursor(declaration, new Cursor(block, this.cursor.parent))) as J.VariableDeclarations | undefined;
@@ -1049,7 +1023,7 @@ export class EnzymeToReactTestingLibrary extends ScanningRecipe<Scanned> {
1049
1023
  continue;
1050
1024
  }
1051
1025
  if (cleanup.has(id)) {
1052
- const local = maybeAddImport(outer, {module: RTL, member: "cleanup", onlyIfReferenced: false}) ?? "cleanup";
1026
+ const local = maybeBind(outer, {module: RTL, member: "cleanup", onlyIfReferenced: false}) ?? "cleanup";
1053
1027
  const replaced = await Template.builder().code(`${local}()`).build().apply(statement.element, cursor) as J | undefined;
1054
1028
  if (!replaced) throw new Error("Cannot clean up the shared wrapper");
1055
1029
  cleaned = true;
@@ -1230,21 +1204,12 @@ export class EnzymeToReactTestingLibrary extends ScanningRecipe<Scanned> {
1230
1204
  private async withPrettierLayout(block: J.Block, ctx: ExecutionContext): Promise<J.Block> {
1231
1205
  if (this.reformat.size === 0) return block;
1232
1206
  const parent = new Cursor(block, this.cursor.parent);
1233
- const statements: J.Block["statements"][number][] = [];
1234
- let formatted = false;
1235
- for (const statement of block.statements) {
1207
+ return updateIfChanged(block, {statements: await mapAsync(block.statements, async statement => {
1236
1208
  const ids = idsWithin(statement.element, this.reformat);
1237
- if (ids.length === 0) {
1238
- statements.push(statement);
1239
- continue;
1240
- }
1209
+ if (ids.length === 0) return statement;
1241
1210
  ids.forEach(id => this.reformat.delete(id));
1242
- statements.push({...statement, element: await autoFormat(statement.element, ctx, undefined, new Cursor(statement, parent))});
1243
- formatted = true;
1244
- }
1245
- return formatted ? create(block, draft => {
1246
- draft.statements = statements as any;
1247
- }) : block;
1211
+ return {...statement, element: await autoFormat(statement.element, ctx, undefined, new Cursor(statement, parent))};
1212
+ })});
1248
1213
  }
1249
1214
 
1250
1215
  override async visitVariableDeclarations(declarations: J.VariableDeclarations, ctx: ExecutionContext): Promise<J | undefined> {
@@ -1525,8 +1490,8 @@ export class EnzymeToReactTestingLibrary extends ScanningRecipe<Scanned> {
1525
1490
  }
1526
1491
 
1527
1492
  private converted(api: string, scope: string, reason: string): void {
1528
- maybeRemoveImport(this, ENZYME);
1529
- if (snapshots) maybeRemoveImport(this, "enzyme-to-json");
1493
+ maybeUnbind(this, ENZYME);
1494
+ if (snapshots) maybeUnbind(this, "enzyme-to-json");
1530
1495
  this.rows.push({sourcePath: this.sourcePath, scope, api, status: "CONVERTED", reason,
1531
1496
  suggestedAction: "Run the migrated test and review whether an accessible RTL query would better express its intent."});
1532
1497
  }
@@ -1540,11 +1505,6 @@ export class EnzymeToReactTestingLibrary extends ScanningRecipe<Scanned> {
1540
1505
  }
1541
1506
  }
1542
1507
 
1543
- /**
1544
- * {@link EnzymeToReactTestingLibrary}, also converting snapshot assertions of the wrappers it converts. RTL
1545
- * snapshots the rendered DOM, which Enzyme's serializer records as a component tree, so every converted
1546
- * snapshot is written anew on the next run with `--updateSnapshot` and should be reviewed then.
1547
- */
1548
1508
  export class EnzymeSnapshotsToReactTestingLibrary extends EnzymeToReactTestingLibrary {
1549
1509
  override readonly name = "org.openrewrite.react.migrate.enzyme-snapshots-to-react-testing-library";
1550
1510
  override readonly displayName = "Migrate Enzyme to React Testing Library, snapshots included";
@@ -56,8 +56,8 @@ export function enzymeModule(value: unknown): value is string {
56
56
  export function enzymeMethod(method: J.MethodInvocation): string | undefined {
57
57
  const type = method.methodType;
58
58
  if (!type) return undefined;
59
- const owner = Type.FullyQualified.getFullyQualifiedName(type.declaringType);
60
- return owner === ENZYME || owner.startsWith(`${ENZYME}.`) ? type.name : undefined;
59
+ return Type.isOfTypeWithName(type.declaringType, false, owner => owner === ENZYME || owner.startsWith(`${ENZYME}.`))
60
+ ? type.name : undefined;
61
61
  }
62
62
 
63
63
  export function enzymeWrapper(type: Type | undefined): boolean {