@openrewrite/recipes-react 0.20.0 → 0.22.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 (276) hide show
  1. package/dist/i18n/translate-hard-coded-strings.d.ts +67 -0
  2. package/dist/i18n/translate-hard-coded-strings.d.ts.map +1 -0
  3. package/dist/i18n/translate-hard-coded-strings.js +439 -0
  4. package/dist/i18n/translate-hard-coded-strings.js.map +1 -0
  5. package/dist/index.d.ts +3 -0
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js +37 -1
  8. package/dist/index.js.map +1 -1
  9. package/dist/mui/adapt-v4-theme.d.ts +8 -0
  10. package/dist/mui/adapt-v4-theme.d.ts.map +1 -0
  11. package/dist/mui/adapt-v4-theme.js +65 -0
  12. package/dist/mui/adapt-v4-theme.js.map +1 -0
  13. package/dist/mui/add-component-prop.d.ts +18 -0
  14. package/dist/mui/add-component-prop.d.ts.map +1 -0
  15. package/dist/mui/add-component-prop.js +53 -0
  16. package/dist/mui/add-component-prop.js.map +1 -0
  17. package/dist/mui/add-emotion-prepend.d.ts +8 -0
  18. package/dist/mui/add-emotion-prepend.d.ts.map +1 -0
  19. package/dist/mui/add-emotion-prepend.js +71 -0
  20. package/dist/mui/add-emotion-prepend.js.map +1 -0
  21. package/dist/mui/change-module-specifier.d.ts +14 -0
  22. package/dist/mui/change-module-specifier.d.ts.map +1 -0
  23. package/dist/mui/change-module-specifier.js +95 -0
  24. package/dist/mui/change-module-specifier.js.map +1 -0
  25. package/dist/mui/convert-mui-imports.d.ts +14 -0
  26. package/dist/mui/convert-mui-imports.d.ts.map +1 -0
  27. package/dist/mui/convert-mui-imports.js +195 -0
  28. package/dist/mui/convert-mui-imports.js.map +1 -0
  29. package/dist/mui/convert-prop-to-sx.d.ts +22 -0
  30. package/dist/mui/convert-prop-to-sx.d.ts.map +1 -0
  31. package/dist/mui/convert-prop-to-sx.js +99 -0
  32. package/dist/mui/convert-prop-to-sx.js.map +1 -0
  33. package/dist/mui/index.d.ts +32 -0
  34. package/dist/mui/index.d.ts.map +1 -0
  35. package/dist/mui/index.js +67 -0
  36. package/dist/mui/index.js.map +1 -0
  37. package/dist/mui/jsx-attributes.d.ts +27 -0
  38. package/dist/mui/jsx-attributes.d.ts.map +1 -0
  39. package/dist/mui/jsx-attributes.js +140 -0
  40. package/dist/mui/jsx-attributes.js.map +1 -0
  41. package/dist/mui/mark-manual-migration.d.ts +16 -0
  42. package/dist/mui/mark-manual-migration.d.ts.map +1 -0
  43. package/dist/mui/mark-manual-migration.js +73 -0
  44. package/dist/mui/mark-manual-migration.js.map +1 -0
  45. package/dist/mui/mark-palette-mode-usage.d.ts +12 -0
  46. package/dist/mui/mark-palette-mode-usage.d.ts.map +1 -0
  47. package/dist/mui/mark-palette-mode-usage.js +50 -0
  48. package/dist/mui/mark-palette-mode-usage.js.map +1 -0
  49. package/dist/mui/move-component-prop-to-slot.d.ts +22 -0
  50. package/dist/mui/move-component-prop-to-slot.d.ts.map +1 -0
  51. package/dist/mui/move-component-prop-to-slot.js +87 -0
  52. package/dist/mui/move-component-prop-to-slot.js.map +1 -0
  53. package/dist/mui/move-primary-text-to-children.d.ts +12 -0
  54. package/dist/mui/move-primary-text-to-children.d.ts.map +1 -0
  55. package/dist/mui/move-primary-text-to-children.js +52 -0
  56. package/dist/mui/move-primary-text-to-children.js.map +1 -0
  57. package/dist/mui/move-system-props-to-sx.d.ts +16 -0
  58. package/dist/mui/move-system-props-to-sx.d.ts.map +1 -0
  59. package/dist/mui/move-system-props-to-sx.js +122 -0
  60. package/dist/mui/move-system-props-to-sx.js.map +1 -0
  61. package/dist/mui/mui-components.d.ts +8 -0
  62. package/dist/mui/mui-components.d.ts.map +1 -0
  63. package/dist/mui/mui-components.js +41 -0
  64. package/dist/mui/mui-components.js.map +1 -0
  65. package/dist/mui/mui-tag-visitor.d.ts +5 -0
  66. package/dist/mui/mui-tag-visitor.d.ts.map +1 -0
  67. package/dist/mui/mui-tag-visitor.js +54 -0
  68. package/dist/mui/mui-tag-visitor.js.map +1 -0
  69. package/dist/mui/pre-v5-recipe.d.ts +14 -0
  70. package/dist/mui/pre-v5-recipe.d.ts.map +1 -0
  71. package/dist/mui/pre-v5-recipe.js +88 -0
  72. package/dist/mui/pre-v5-recipe.js.map +1 -0
  73. package/dist/mui/remove-component-prop.d.ts +18 -0
  74. package/dist/mui/remove-component-prop.d.ts.map +1 -0
  75. package/dist/mui/remove-component-prop.js +55 -0
  76. package/dist/mui/remove-component-prop.js.map +1 -0
  77. package/dist/mui/remove-root-ref.d.ts +8 -0
  78. package/dist/mui/remove-root-ref.d.ts.map +1 -0
  79. package/dist/mui/remove-root-ref.js +61 -0
  80. package/dist/mui/remove-root-ref.js.map +1 -0
  81. package/dist/mui/remove-spacing-px-suffix.d.ts +8 -0
  82. package/dist/mui/remove-spacing-px-suffix.d.ts.map +1 -0
  83. package/dist/mui/remove-spacing-px-suffix.js +62 -0
  84. package/dist/mui/remove-spacing-px-suffix.js.map +1 -0
  85. package/dist/mui/rename-component-prop.d.ts +20 -0
  86. package/dist/mui/rename-component-prop.d.ts.map +1 -0
  87. package/dist/mui/rename-component-prop.js +66 -0
  88. package/dist/mui/rename-component-prop.js.map +1 -0
  89. package/dist/mui/rename-joy-css-variables.d.ts +8 -0
  90. package/dist/mui/rename-joy-css-variables.d.ts.map +1 -0
  91. package/dist/mui/rename-joy-css-variables.js +51 -0
  92. package/dist/mui/rename-joy-css-variables.js.map +1 -0
  93. package/dist/mui/rename-theme-palette-type.d.ts +8 -0
  94. package/dist/mui/rename-theme-palette-type.d.ts.map +1 -0
  95. package/dist/mui/rename-theme-palette-type.js +61 -0
  96. package/dist/mui/rename-theme-palette-type.js.map +1 -0
  97. package/dist/mui/replace-box-border-radius.d.ts +10 -0
  98. package/dist/mui/replace-box-border-radius.d.ts.map +1 -0
  99. package/dist/mui/replace-box-border-radius.js +50 -0
  100. package/dist/mui/replace-box-border-radius.js.map +1 -0
  101. package/dist/mui/replace-breakpoints-width.d.ts +8 -0
  102. package/dist/mui/replace-breakpoints-width.d.ts.map +1 -0
  103. package/dist/mui/replace-breakpoints-width.js +46 -0
  104. package/dist/mui/replace-breakpoints-width.js.map +1 -0
  105. package/dist/mui/replace-component-class.d.ts +18 -0
  106. package/dist/mui/replace-component-class.d.ts.map +1 -0
  107. package/dist/mui/replace-component-class.js +126 -0
  108. package/dist/mui/replace-component-class.js.map +1 -0
  109. package/dist/mui/replace-components-with-slots.d.ts +14 -0
  110. package/dist/mui/replace-components-with-slots.d.ts.map +1 -0
  111. package/dist/mui/replace-components-with-slots.js +69 -0
  112. package/dist/mui/replace-components-with-slots.js.map +1 -0
  113. package/dist/mui/replace-import-paths.d.ts +14 -0
  114. package/dist/mui/replace-import-paths.d.ts.map +1 -0
  115. package/dist/mui/replace-import-paths.js +101 -0
  116. package/dist/mui/replace-import-paths.js.map +1 -0
  117. package/dist/mui/replace-in-string-literals.d.ts +15 -0
  118. package/dist/mui/replace-in-string-literals.d.ts.map +1 -0
  119. package/dist/mui/replace-in-string-literals.js +62 -0
  120. package/dist/mui/replace-in-string-literals.js.map +1 -0
  121. package/dist/mui/replace-list-item-button-prop.d.ts +12 -0
  122. package/dist/mui/replace-list-item-button-prop.d.ts.map +1 -0
  123. package/dist/mui/replace-list-item-button-prop.js +80 -0
  124. package/dist/mui/replace-list-item-button-prop.js.map +1 -0
  125. package/dist/mui/replace-tabs-scroll-buttons.d.ts +8 -0
  126. package/dist/mui/replace-tabs-scroll-buttons.d.ts.map +1 -0
  127. package/dist/mui/replace-tabs-scroll-buttons.js +41 -0
  128. package/dist/mui/replace-tabs-scroll-buttons.js.map +1 -0
  129. package/dist/mui/replace-theme-color-functions.d.ts +8 -0
  130. package/dist/mui/replace-theme-color-functions.d.ts.map +1 -0
  131. package/dist/mui/replace-theme-color-functions.js +72 -0
  132. package/dist/mui/replace-theme-color-functions.js.map +1 -0
  133. package/dist/mui/replace-theme-spacing-unit.d.ts +8 -0
  134. package/dist/mui/replace-theme-spacing-unit.d.ts.map +1 -0
  135. package/dist/mui/replace-theme-spacing-unit.js +77 -0
  136. package/dist/mui/replace-theme-spacing-unit.js.map +1 -0
  137. package/dist/mui/replace-typography-round.d.ts +8 -0
  138. package/dist/mui/replace-typography-round.d.ts.map +1 -0
  139. package/dist/mui/replace-typography-round.js +44 -0
  140. package/dist/mui/replace-typography-round.js.map +1 -0
  141. package/dist/mui/shift-hidden-down-props.d.ts +10 -0
  142. package/dist/mui/shift-hidden-down-props.d.ts.map +1 -0
  143. package/dist/mui/shift-hidden-down-props.js +49 -0
  144. package/dist/mui/shift-hidden-down-props.js.map +1 -0
  145. package/dist/mui/theme-access.d.ts +5 -0
  146. package/dist/mui/theme-access.d.ts.map +1 -0
  147. package/dist/mui/theme-access.js +21 -0
  148. package/dist/mui/theme-access.js.map +1 -0
  149. package/dist/mui/update-theme-breakpoints.d.ts +10 -0
  150. package/dist/mui/update-theme-breakpoints.d.ts.map +1 -0
  151. package/dist/mui/update-theme-breakpoints.js +58 -0
  152. package/dist/mui/update-theme-breakpoints.js.map +1 -0
  153. package/dist/mui/upgrade-grid-props.d.ts +16 -0
  154. package/dist/mui/upgrade-grid-props.d.ts.map +1 -0
  155. package/dist/mui/upgrade-grid-props.js +90 -0
  156. package/dist/mui/upgrade-grid-props.js.map +1 -0
  157. package/dist/search/find-enzyme-usage.d.ts +8 -0
  158. package/dist/search/find-enzyme-usage.d.ts.map +1 -1
  159. package/dist/search/find-enzyme-usage.js +119 -8
  160. package/dist/search/find-enzyme-usage.js.map +1 -1
  161. package/dist/search/find-hard-coded-strings.d.ts +110 -0
  162. package/dist/search/find-hard-coded-strings.d.ts.map +1 -0
  163. package/dist/search/find-hard-coded-strings.js +987 -0
  164. package/dist/search/find-hard-coded-strings.js.map +1 -0
  165. package/dist/search/find-missing-use-client-directive.d.ts +2 -0
  166. package/dist/search/find-missing-use-client-directive.d.ts.map +1 -1
  167. package/dist/search/find-missing-use-client-directive.js +1 -0
  168. package/dist/search/find-missing-use-client-directive.js.map +1 -1
  169. package/dist/testing/enzyme-host-components.d.ts +12 -0
  170. package/dist/testing/enzyme-host-components.d.ts.map +1 -1
  171. package/dist/testing/enzyme-host-components.js +100 -0
  172. package/dist/testing/enzyme-host-components.js.map +1 -1
  173. package/dist/testing/enzyme-portals.d.ts +3 -5
  174. package/dist/testing/enzyme-portals.d.ts.map +1 -1
  175. package/dist/testing/enzyme-portals.js +8 -39
  176. package/dist/testing/enzyme-portals.js.map +1 -1
  177. package/dist/testing/enzyme-render-blockers.d.ts +19 -0
  178. package/dist/testing/enzyme-render-blockers.d.ts.map +1 -0
  179. package/dist/testing/enzyme-render-blockers.js +275 -0
  180. package/dist/testing/enzyme-render-blockers.js.map +1 -0
  181. package/dist/testing/enzyme-to-react-testing-library.d.ts +17 -3
  182. package/dist/testing/enzyme-to-react-testing-library.d.ts.map +1 -1
  183. package/dist/testing/enzyme-to-react-testing-library.js +237 -27
  184. package/dist/testing/enzyme-to-react-testing-library.js.map +1 -1
  185. package/dist/testing/enzyme-usage.d.ts +9 -0
  186. package/dist/testing/enzyme-usage.d.ts.map +1 -1
  187. package/dist/testing/enzyme-usage.js +36 -3
  188. package/dist/testing/enzyme-usage.js.map +1 -1
  189. package/dist/testing/enzyme-wrapper-scope.d.ts +8 -1
  190. package/dist/testing/enzyme-wrapper-scope.d.ts.map +1 -1
  191. package/dist/testing/enzyme-wrapper-scope.js +26 -5
  192. package/dist/testing/enzyme-wrapper-scope.js.map +1 -1
  193. package/dist/util/json-and-javascript.d.ts +4 -0
  194. package/dist/util/json-and-javascript.d.ts.map +1 -0
  195. package/dist/util/json-and-javascript.js +37 -0
  196. package/dist/util/json-and-javascript.js.map +1 -0
  197. package/dist/util/module-imports.d.ts +36 -0
  198. package/dist/util/module-imports.d.ts.map +1 -1
  199. package/dist/util/module-imports.js +216 -0
  200. package/dist/util/module-imports.js.map +1 -1
  201. package/dist/util/test-source.d.ts +2 -0
  202. package/dist/util/test-source.d.ts.map +1 -0
  203. package/dist/util/test-source.js +5 -0
  204. package/dist/util/test-source.js.map +1 -0
  205. package/dist/zustand/entry-store.d.ts +9 -0
  206. package/dist/zustand/entry-store.d.ts.map +1 -0
  207. package/dist/zustand/entry-store.js +136 -0
  208. package/dist/zustand/entry-store.js.map +1 -0
  209. package/dist/zustand/redux-stores.d.ts +7 -4
  210. package/dist/zustand/redux-stores.d.ts.map +1 -1
  211. package/dist/zustand/redux-stores.js +128 -11
  212. package/dist/zustand/redux-stores.js.map +1 -1
  213. package/dist/zustand/redux-to-zustand.d.ts +11 -2
  214. package/dist/zustand/redux-to-zustand.d.ts.map +1 -1
  215. package/dist/zustand/redux-to-zustand.js +147 -46
  216. package/dist/zustand/redux-to-zustand.js.map +1 -1
  217. package/dist/zustand/zustand-plan.d.ts +14 -5
  218. package/dist/zustand/zustand-plan.d.ts.map +1 -1
  219. package/dist/zustand/zustand-plan.js +226 -52
  220. package/dist/zustand/zustand-plan.js.map +1 -1
  221. package/package.json +1 -1
  222. package/src/i18n/translate-hard-coded-strings.ts +442 -0
  223. package/src/index.ts +17 -0
  224. package/src/mui/adapt-v4-theme.ts +43 -0
  225. package/src/mui/add-component-prop.ts +43 -0
  226. package/src/mui/add-emotion-prepend.ts +48 -0
  227. package/src/mui/change-module-specifier.ts +71 -0
  228. package/src/mui/convert-mui-imports.ts +184 -0
  229. package/src/mui/convert-prop-to-sx.ts +89 -0
  230. package/src/mui/index.ts +31 -0
  231. package/src/mui/jsx-attributes.ts +133 -0
  232. package/src/mui/mark-manual-migration.ts +53 -0
  233. package/src/mui/mark-palette-mode-usage.ts +36 -0
  234. package/src/mui/move-component-prop-to-slot.ts +84 -0
  235. package/src/mui/move-primary-text-to-children.ts +41 -0
  236. package/src/mui/move-system-props-to-sx.ts +118 -0
  237. package/src/mui/mui-components.ts +40 -0
  238. package/src/mui/mui-tag-visitor.ts +36 -0
  239. package/src/mui/pre-v5-recipe.ts +82 -0
  240. package/src/mui/remove-component-prop.ts +43 -0
  241. package/src/mui/remove-root-ref.ts +41 -0
  242. package/src/mui/remove-spacing-px-suffix.ts +43 -0
  243. package/src/mui/rename-component-prop.ts +55 -0
  244. package/src/mui/rename-joy-css-variables.ts +41 -0
  245. package/src/mui/rename-theme-palette-type.ts +42 -0
  246. package/src/mui/replace-box-border-radius.ts +42 -0
  247. package/src/mui/replace-breakpoints-width.ts +28 -0
  248. package/src/mui/replace-component-class.ts +97 -0
  249. package/src/mui/replace-components-with-slots.ts +61 -0
  250. package/src/mui/replace-import-paths.ts +100 -0
  251. package/src/mui/replace-in-string-literals.ts +44 -0
  252. package/src/mui/replace-list-item-button-prop.ts +59 -0
  253. package/src/mui/replace-tabs-scroll-buttons.ts +31 -0
  254. package/src/mui/replace-theme-color-functions.ts +55 -0
  255. package/src/mui/replace-theme-spacing-unit.ts +59 -0
  256. package/src/mui/replace-typography-round.ts +29 -0
  257. package/src/mui/shift-hidden-down-props.ts +44 -0
  258. package/src/mui/theme-access.ts +18 -0
  259. package/src/mui/update-theme-breakpoints.ts +47 -0
  260. package/src/mui/upgrade-grid-props.ts +82 -0
  261. package/src/search/find-enzyme-usage.ts +109 -12
  262. package/src/search/find-hard-coded-strings.ts +1006 -0
  263. package/src/search/find-missing-use-client-directive.ts +1 -1
  264. package/src/testing/enzyme-host-components.ts +110 -0
  265. package/src/testing/enzyme-portals.ts +4 -44
  266. package/src/testing/enzyme-render-blockers.ts +278 -0
  267. package/src/testing/enzyme-to-react-testing-library.ts +240 -34
  268. package/src/testing/enzyme-usage.ts +48 -2
  269. package/src/testing/enzyme-wrapper-scope.ts +35 -3
  270. package/src/util/json-and-javascript.ts +26 -0
  271. package/src/util/module-imports.ts +223 -0
  272. package/src/util/test-source.ts +2 -0
  273. package/src/zustand/entry-store.ts +131 -0
  274. package/src/zustand/redux-stores.ts +131 -12
  275. package/src/zustand/redux-to-zustand.ts +179 -52
  276. package/src/zustand/zustand-plan.ts +256 -49
@@ -1,7 +1,7 @@
1
- import {and, check, Cursor, DataTable, ExecutionContext, findMarker, not, Option, or, randomId, RecipeRef, ScanningRecipe, SourceFile, Tree, TreePrinters, TreeVisitor} from "@openrewrite/rewrite";
1
+ import {and, check, Cursor, DataTable, ExecutionContext, findMarker, MarkersKind, MarkupWarn, not, Option, or, randomId, RecipeRef, ScanningRecipe, SourceFile, Tree, TreePrinters, TreeVisitor} 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, raw, rewrite, scopeOf, StyleKind, Template, template, usesMethod} from "@openrewrite/rewrite/javascript";
4
- import {Expression, J} from "@openrewrite/rewrite/java";
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";
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";
7
7
  import {readFileSync} from "fs";
@@ -10,8 +10,9 @@ import {satisfies, valid, validRange} from "semver";
10
10
  import {FindEnzymeUsage} from "../search/find-enzyme-usage";
11
11
  import {JavaDependencyRecipe, treesOfType} from "../util/java-recipe-proxy";
12
12
  import {importBindings} from "../util/module-imports";
13
- import {ENZYME, ENZYME_USAGE_TABLE, enclosingScope, enzymeMethod, EnzymeUsageRow} from "./enzyme-usage";
14
- import {HostComponents, hostComponentExports, hostComponentsDeclared, ImportedExport, importedNames, propsRenderHostElements, relativeImports, rendersHostElements} from "./enzyme-host-components";
13
+ import {ENZYME, ENZYME_USAGE_TABLE, enclosingScope, enzymeMethod, EnzymeUsageRow, FILE_BLOCKER, RENDER_BLOCKERS, SELECTOR_VALUES, SelectorRead} from "./enzyme-usage";
14
+ import {blockedByFile, blockedByGate, blockedByShape, blockedByShared, blockedByPackage, blockedByShallow, blockedByUses, FileGate, NotAdded} from "./enzyme-render-blockers";
15
+ import {compositeFacts, Composites, HostComponents, hostComponentExports, shallowMiss, hostComponentsDeclared, ImportedExport, importedNames, propsRenderHostElements, relativeImports, rendersHostElements} from "./enzyme-host-components";
15
16
  import {moduleFacts, Modules, rendersPortal, resolver} from "./enzyme-portals";
16
17
  import {evaluate, stringParts} from "./enzyme-constant-strings";
17
18
  import {hostOnlyNames, selectorNames, SelectorNames} from "./enzyme-selector-names";
@@ -78,6 +79,12 @@ abstract class EnzymeTestDependency extends JavaDependencyRecipe {
78
79
  */
79
80
  readonly landed = new Set<string>();
80
81
 
82
+ /** The package roots whose edit `AddDependency` declined, such as for a lockfile it could not regenerate. Mutated in place too. */
83
+ readonly declined = new Set<string>();
84
+
85
+ /** Why the dependency didn't land in each package root declaring Enzyme that it didn't land in. Mutated in place too. */
86
+ readonly outcomes = new Map<string, NotAdded>();
87
+
81
88
  private readonly manifests: Json.Document[] = [];
82
89
 
83
90
  /** The manifests the step admits, which reach the Java recipe only in `generate`, once the forecast is known. */
@@ -89,6 +96,8 @@ abstract class EnzymeTestDependency extends JavaDependencyRecipe {
89
96
 
90
97
  override initialValue(): number {
91
98
  this.landed.clear();
99
+ this.declined.clear();
100
+ this.outcomes.clear();
92
101
  this.manifests.length = 0;
93
102
  this.held.length = 0;
94
103
  return super.initialValue();
@@ -121,10 +130,16 @@ abstract class EnzymeTestDependency extends JavaDependencyRecipe {
121
130
  // Without a forecast, as when the step runs alone, every admitted manifest goes on as before
122
131
  const converting = await this.forecast.converting?.();
123
132
  const scopes = lockfileScopes(this.held);
124
- const forwarded = new Set(this.held.filter(manifest => {
133
+ const withheld = (manifest: Json.Document): NotAdded | undefined => {
125
134
  const scope = scopes.get(manifest.sourcePath) ?? packageRoot(manifest.sourcePath);
126
- return !converting || [...converting].some(source => source.startsWith(scope));
127
- }));
135
+ if (converting && ![...converting].some(source => source.startsWith(scope))) return {kind: "withheld"};
136
+ return this.withholds(scope) ? {kind: "peer"} : undefined;
137
+ };
138
+ const forwarded = new Set(this.held.filter(manifest => !withheld(manifest)));
139
+ for (const manifest of this.manifests) {
140
+ const why = forwarded.has(manifest) ? undefined : withheld(manifest);
141
+ if (why) this.outcomes.set(packageRoot(manifest.sourcePath), why);
142
+ }
128
143
  const scanner = await this.java.scanner(acc);
129
144
  for (const manifest of forwarded) await scanner.visit(manifest, ctx);
130
145
  const kept = this.manifests.filter(manifest => forwarded.has(manifest));
@@ -134,10 +149,38 @@ abstract class EnzymeTestDependency extends JavaDependencyRecipe {
134
149
  const editor = await this.java.editorWithData(acc);
135
150
  for (const manifest of this.manifests) {
136
151
  const edited = await editor.visit<Json.Document>(manifest, ctx);
137
- if (edited && edited !== manifest && declares(edited, this.addition.packageName)) this.landed.add(manifest.sourcePath.slice(0, -"package.json".length));
152
+ const root = manifest.sourcePath.slice(0, -"package.json".length);
153
+ if (edited && edited !== manifest && declares(edited, this.addition.packageName)) this.landed.add(root);
154
+ else if (!declares(manifest, this.addition.packageName) && this.resolvesGate(manifest)) {
155
+ this.declined.add(root);
156
+ // NOTE: `AddDependency` leaves why it declined as a warning on the manifest it returns
157
+ const warning = (edited ?? manifest).markers.markers.find(marker => marker.kind === MarkersKind.MarkupWarn) as MarkupWarn | undefined;
158
+ this.outcomes.set(root, {kind: "declined", warning: warning && [warning.message, warning.detail].filter(Boolean).join("\n")});
159
+ } else if (!declares(manifest, this.addition.packageName)) this.outcomes.set(root, {kind: "gate"});
138
160
  }
139
161
  return generated;
140
162
  }
163
+
164
+ /** Whether the package resolves what `onlyIfResolving` asks, as `AddDependency` checks before it edits. */
165
+ private resolvesGate(manifest: Json.Document): boolean {
166
+ const resolved = findNodeResolutionResult(manifest)?.resolvedDependencies ?? [];
167
+ return (this.addition.onlyIfResolving ?? []).every(gate => {
168
+ const at = gate.lastIndexOf("@");
169
+ const name = gate.slice(0, at);
170
+ return resolved.some(dep => dep.name === name && valid(dep.version) !== null && satisfies(dep.version, gate.slice(at + 1)));
171
+ });
172
+ }
173
+
174
+ /** Whether to keep the manifests of a lockfile scope, such as `packages/ui/` or the root's `""`, from the Java recipe. */
175
+ protected withholds(_scope: string): boolean {
176
+ return false;
177
+ }
178
+ }
179
+
180
+ function dependencySteps(forecast: ConversionForecast) {
181
+ const rtl = new AddTestingLibraryReact(forecast);
182
+ const dom18 = new AddTestingLibraryDom18(forecast);
183
+ return {rtl, dom18, rtl18: new AddTestingLibraryReact18(forecast, dom18)};
141
184
  }
142
185
 
143
186
  /** Adds {@link RTL_ADDITION}. */
@@ -157,9 +200,15 @@ export class AddTestingLibraryReact18 extends EnzymeTestDependency {
157
200
  readonly displayName = "Add `@testing-library/react` 16 where Enzyme tests on React 18 are migrated";
158
201
  readonly description = "Adds `@testing-library/react` 16 as a dev dependency to packages that declare `enzyme` and resolve React and React DOM 18.";
159
202
 
160
- constructor(forecast: ConversionForecast = {}) {
203
+ constructor(forecast: ConversionForecast = {}, private readonly peer?: AddTestingLibraryDom18) {
161
204
  super(RTL_18_ADDITION, forecast);
162
205
  }
206
+
207
+ // NOTE: RTL 16 needs its peer `@testing-library/dom`, whose step runs first. Where that step's edit was declined,
208
+ // as when a registry timeout fails its lockfile, this step adds nothing in the same lockfile either.
209
+ protected override withholds(scope: string): boolean {
210
+ return !!this.peer && [...this.peer.declined].some(root => root.startsWith(scope));
211
+ }
163
212
  }
164
213
 
165
214
  /** Adds {@link DOM_18_ADDITION}, the peer of {@link RTL_18_ADDITION}. */
@@ -329,6 +378,8 @@ type Packages = Map<string, PackageDeclarations>;
329
378
  interface Scanned {
330
379
  packages: Packages;
331
380
  components: HostComponents;
381
+ /** What the components of each source render that `shallow` leaves out, for a review row's action. */
382
+ composites: Composites;
332
383
  modules: Modules;
333
384
  /** The words of each source's strings, for the selectors whose ancestor compounds name no tag. */
334
385
  names: Map<string, SelectorNames>;
@@ -379,6 +430,11 @@ export function reactMajor(packages: Packages, sourcePath: string, landed: Reado
379
430
  return compatibility(packages, sourcePath, landed).react;
380
431
  }
381
432
 
433
+ /** Why {@link reactMajor} is 0 for a source file, as far as its package's declarations say. */
434
+ export function incompatibility(packages: Packages, sourcePath: string, landed: ReadonlySet<string> = new Set()): FileGate | undefined {
435
+ return compatibility(packages, sourcePath, landed).why;
436
+ }
437
+
382
438
  /** The events `simulate` can dispatch as `fireEvent` in a source file, and whether its render must be attached to the document for them. */
383
439
  export interface SimulatedEvents {
384
440
  events: ReadonlySet<string>;
@@ -403,8 +459,17 @@ export function simulatesEvents(packages: Packages, sourcePath: string, landed:
403
459
  return {events: new Set(), attached: false};
404
460
  }
405
461
 
462
+ /**
463
+ * The package root a source's RTL goes to, that of the package declaring Enzyme, and whether its React is 18, which
464
+ * decides the dependency step that adds it. Undefined where no package of the source declares or provides Enzyme.
465
+ */
466
+ export function rtlTarget(packages: Packages, sourcePath: string): {root: string, react18: boolean} | undefined {
467
+ const {enzymeRoot, enzymeReact} = compatibility(packages, sourcePath, new Set());
468
+ return enzymeRoot === undefined ? undefined : {root: enzymeRoot, react18: enzymeReact === 18};
469
+ }
470
+
406
471
  /** The React major as {@link reactMajor} reads it, and the major of the RTL the tests run with. */
407
- function compatibility(packages: Packages, sourcePath: string, landed: ReadonlySet<string>): {react: number, rtl: number} {
472
+ function compatibility(packages: Packages, sourcePath: string, landed: ReadonlySet<string>): {react: number, rtl: number, why?: FileGate, enzymeRoot?: string, enzymeReact?: number} {
408
473
  const roots = [...packages.keys()].filter(root => sourcePath.startsWith(root)).sort((a, b) => b.length - a.length);
409
474
  const declared = (name: "react" | "reactDom" | "rtl", from = roots) =>
410
475
  from.map(root => packages.get(root)![name]).find(version => version !== undefined);
@@ -425,7 +490,11 @@ function compatibility(packages: Packages, sourcePath: string, landed: ReadonlyS
425
490
  const rtlMajor = added ? ((enzymeReact as DeclaredVersion).major >= 18 ? 16 : 12) : typeof rtl === "object" && rtl.major >= 10 && rtl.major <= 16 ? rtl.major : 0;
426
491
  const compatible = supportedReact(react) && supportedReact(reactDom) && react.major === reactDom.major &&
427
492
  rtlMajor > 0 && rtlSupports(rtlMajor, react.major);
428
- return {react: compatible ? react.major : 0, rtl: rtlMajor};
493
+ const target = {enzymeRoot: enzymeRoots[0], enzymeReact: supportedReact(enzymeReact) ? enzymeReact.major : undefined};
494
+ if (compatible) return {react: react.major, rtl: rtlMajor, ...target};
495
+ const why: FileGate = !supportedReact(react) || !supportedReact(reactDom) || react.major !== reactDom.major ? "react" :
496
+ rtl === undefined && !added ? "rtlMissing" : "rtl";
497
+ return {react: 0, rtl: rtlMajor, why, ...target};
429
498
  }
430
499
 
431
500
  /**
@@ -531,7 +600,7 @@ function withoutStatements(block: J.Block, removed: ReadonlySet<string>): J.Bloc
531
600
  export class EnzymeToReactTestingLibrary extends ScanningRecipe<Scanned> {
532
601
  readonly name: string = "org.openrewrite.react.migrate.enzyme-to-react-testing-library";
533
602
  readonly displayName: string = "Migrate Enzyme to React Testing Library";
534
- readonly description: string = "Migrates Enzyme `mount` wrappers whose every use is a supported DOM read or event (`find(selector).length`, `.exists()`, `.text()`, `.html()`, `.hasClass()`, positions through `.at(n)`, `.first()`, `.last()`, the wrapper's `text()` and `exists(selector)`, found nodes as a `toHaveLength` subject, `setProps` as a rerender of the cloned element, and `simulate` with common mouse, keyboard, focus, form, and touch events, including `nativeEvent` mocks, on React 17 and 18 and, without the hover events and in a render attached to the document, on React 15.5 and 16) and bare `mount` statements to React Testing Library container queries, `rerender`, and `fireEvent` in packages using React 16 or 17 with RTL 10 to 12, React 15.5+ with RTL 12, or React 18 with RTL 16, adding RTL 12, or RTL 16 with its peer `@testing-library/dom` 10, where it is missing. On React 15, whose markup differs, `html()` and DOM nodes are left for review. Converts `shallow` wrappers the same way, without `simulate` or `html()`, where the component is imported from a source in the repository that creates host elements only and runs no effects, so a full render produces the DOM the shallow render does. Selectors are limited to HTML or SVG tag, class, ID, and pass-through attribute compounds and their descendant combinations. Reports remaining Enzyme usages for manual review. Requires an existing DOM test environment; shared wrappers, props, snapshots, and shallow rendering of other components are left for review.";
603
+ readonly description: string = "Migrates Enzyme `mount` wrappers whose every use is a supported DOM read or event (`find(selector).length`, `.exists()`, `.text()`, `.html()`, `.hasClass()`, positions through `.at(n)`, `.first()`, `.last()`, the wrapper's `text()` and `exists(selector)`, found nodes as a `toHaveLength` subject, `setProps` as a rerender of the cloned element, and `simulate` with common mouse, keyboard, focus, form, and touch events, including `nativeEvent` mocks, on React 17 and 18 and, without the hover events and in a render attached to the document, on React 15.5 and 16) and bare `mount` statements to React Testing Library container queries, `rerender`, and `fireEvent` in packages using React 16 or 17 with RTL 10 to 12, React 15.5+ with RTL 12, or React 18 with RTL 16, adding RTL 12, or RTL 16 with its peer `@testing-library/dom` 10, where it is missing. This includes a shared `let` wrapper that each test assigns first, or that the last statement of a `beforeEach` assigns, where every test of it converts. On React 15, whose markup differs, `html()` and DOM nodes are left for review. Converts `shallow` wrappers the same way, without `simulate` or `html()`, where the component is imported from a source in the repository that creates host elements only and runs no effects, so a full render produces the DOM the shallow render does. Selectors are limited to HTML or SVG tag, class, ID, and pass-through attribute compounds and their descendant combinations. Reports remaining Enzyme usages for manual review. Requires an existing DOM test environment; props, snapshots, and shallow rendering of other components are left for review.";
535
604
 
536
605
  @Option({
537
606
  displayName: "Convert positions into untagged selector matches",
@@ -546,8 +615,9 @@ export class EnzymeToReactTestingLibrary extends ScanningRecipe<Scanned> {
546
615
  // PERF: the sources that import Enzyme, kept from the scan to the forecast in `generate`, as the dependency steps keep
547
616
  // their manifests. Not in the accumulator, which the host keeps until the cycle ends; cleared once the forecast is made.
548
617
  private readonly tests: JS.CompilationUnit[] = [];
549
- private readonly dependencySteps = ADDS_RTL ? {rtl: new AddTestingLibraryReact(this.forecast), rtl18: new AddTestingLibraryReact18(this.forecast),
550
- dom18: new AddTestingLibraryDom18(this.forecast)} : undefined;
618
+ // What kept each render on Enzyme in the forecast, where RTL is taken to land, for the sources of a package it withholds RTL from
619
+ private readonly forecastBlockers = new Map<string, ReadonlyMap<string, string>>();
620
+ private readonly dependencySteps = ADDS_RTL ? dependencySteps(this.forecast) : undefined;
551
621
 
552
622
  constructor(options?: {untaggedSelectorPositions?: boolean}) {
553
623
  super(options);
@@ -564,7 +634,8 @@ export class EnzymeToReactTestingLibrary extends ScanningRecipe<Scanned> {
564
634
 
565
635
  initialValue(): Scanned {
566
636
  this.tests.length = 0;
567
- return {packages: new Map(), components: new Map(), modules: new Map(), names: new Map(), nullSnapshots: new Set()};
637
+ this.forecastBlockers.clear();
638
+ return {packages: new Map(), components: new Map(), composites: new Map(), modules: new Map(), names: new Map(), nullSnapshots: new Set()};
568
639
  }
569
640
 
570
641
  // The host may prepare the visitors before there is an accumulator, so it is read only while visiting
@@ -577,6 +648,8 @@ export class EnzymeToReactTestingLibrary extends ScanningRecipe<Scanned> {
577
648
  const sources = new class extends JavaScriptVisitor<ExecutionContext> {
578
649
  override async visitJsCompilationUnit(cu: JS.CompilationUnit): Promise<J | undefined> {
579
650
  scanned.components.set(cu.sourcePath, hostComponentExports(cu));
651
+ const composite = compositeFacts(cu);
652
+ if (composite) scanned.composites.set(cu.sourcePath, composite);
580
653
  scanned.modules.set(cu.sourcePath, moduleFacts(cu));
581
654
  scanned.names.set(cu.sourcePath, selectorNames(cu));
582
655
  if (importBindings(cu).some(({module}) => module === ENZYME)) tests.push(cu);
@@ -699,6 +772,18 @@ export class EnzymeToReactTestingLibrary extends ScanningRecipe<Scanned> {
699
772
  };
700
773
  const usages = this.usages;
701
774
  const steps = this.dependencySteps;
775
+ const forecastBlockers = this.forecastBlockers;
776
+ // Why the run added no RTL for a source, from the step that adds the RTL its package's React takes. Where the
777
+ // forecast withheld it, what kept each render on Enzyme in the forecast is what to resolve first.
778
+ const notAdded = (sourcePath: string): ReadonlyMap<string, string> => {
779
+ const target = rtlTarget(scanned.packages, sourcePath);
780
+ if (!target) return new Map([[FILE_BLOCKER, blockedByFile("rtlMissing")]]);
781
+ const outcome = !steps ? undefined : target.react18 ?
782
+ steps.dom18.outcomes.get(target.root) ?? steps.rtl18.outcomes.get(target.root) : steps.rtl.outcomes.get(target.root);
783
+ const blockers = new Map([[FILE_BLOCKER, blockedByPackage(target.root, outcome)]]);
784
+ if (outcome?.kind === "withheld") forecastBlockers.get(sourcePath)?.forEach((why, id) => blockers.set(id, why));
785
+ return blockers;
786
+ };
702
787
  const untaggedPositions = this.untaggedSelectorPositions !== false;
703
788
  const snapshots = this.snapshots;
704
789
  return check(and(not(isVendoredOrBundled()), or(usesMethod("enzyme mount(..)"), usesMethod("enzyme shallow(..)"))), new class extends JavaScriptVisitor<ExecutionContext> {
@@ -713,12 +798,15 @@ export class EnzymeToReactTestingLibrary extends ScanningRecipe<Scanned> {
713
798
  private readonly mounts = new Map<string, ConvertedRender>();
714
799
  private imports: ReadonlyMap<string, ImportedExport> = new Map();
715
800
  private importedNames: ReadonlySet<string> = new Set();
801
+ private bindings: ReturnType<typeof importBindings> = [];
716
802
  private declaredHost: ReadonlySet<string> = new Set();
717
803
  private readonly uses = new Map<string, WrapperRead>();
718
804
  private readonly removedStatements = new Set<string>();
719
805
  private readonly unmounts = new Set<string>();
720
806
  private readonly declarations = new Set<string>();
721
807
  private readonly pending = new Set<string>();
808
+ // The renders of shared wrappers, whose shape the recipe converts, so blockShapes leaves them alone
809
+ private readonly sharedRenders = new Set<string>();
722
810
  private readonly reformat = new Set<string>();
723
811
  private readonly hoists = new Map<string, HoistedElement>();
724
812
  private readonly hoistedMounts = new Map<string, string>();
@@ -726,15 +814,20 @@ export class EnzymeToReactTestingLibrary extends ScanningRecipe<Scanned> {
726
814
  private cu?: JS.CompilationUnit;
727
815
  private readonly portals = new Set<string>();
728
816
  private readonly rows: EnzymeUsageRow[] = [];
817
+ // What kept each mount analyzed in this source on Enzyme
818
+ private readonly blockers = new Map<string, string>();
729
819
  private prettier = false;
730
820
  private printWidth = 80;
731
821
 
732
822
  override async visitJsCompilationUnit(cu: JS.CompilationUnit, ctx: ExecutionContext): Promise<J | undefined> {
733
823
  this.sourcePath = cu.sourcePath;
734
- [this.mounts, this.uses, this.removedStatements, this.unmounts, this.declarations, this.pending, this.reformat].forEach(ids => ids.clear());
824
+ [this.mounts, this.uses, this.removedStatements, this.unmounts, this.declarations, this.pending, this.reformat, this.sharedRenders].forEach(ids => ids.clear());
735
825
  this.hoists.clear();
736
826
  this.hoistedMounts.clear();
737
827
  this.rows.length = 0;
828
+ this.blockers.clear();
829
+ if (!dry) RENDER_BLOCKERS.delete(cu.sourcePath);
830
+ if (!dry) await this.readSelectors(cu);
738
831
  this.names = namesUsedIn(cu);
739
832
  const prettierStyle = findMarker<PrettierStyle>(cu, StyleKind.PrettierStyle);
740
833
  this.prettier = prettierStyle !== undefined && !prettierStyle.ignored && await formattedBy(cu, prettierStyle);
@@ -747,8 +840,15 @@ export class EnzymeToReactTestingLibrary extends ScanningRecipe<Scanned> {
747
840
  this.typescript = isTypeScript(cu);
748
841
  this.optionalChaining = parsesOptionalChaining(scanned.packages, cu.sourcePath, this.typescript);
749
842
  this.enabled = this.reactMajor > 0 && moduleBindings(this).moduleSystem === "esm";
750
- if (!this.enabled) return cu;
843
+ if (!this.enabled) {
844
+ // Every render of the file stays on Enzyme for the same reason
845
+ const why = this.reactMajor === 0 ? incompatibility(scanned.packages, cu.sourcePath, landed) : "commonjs";
846
+ if (dry && why && why !== "rtlMissing") forecastBlockers.set(cu.sourcePath, new Map([[FILE_BLOCKER, blockedByFile(why)]]));
847
+ if (!dry && why) RENDER_BLOCKERS.set(cu.sourcePath, why === "rtlMissing" ? notAdded(cu.sourcePath) : new Map([[FILE_BLOCKER, blockedByFile(why)]]));
848
+ return cu;
849
+ }
751
850
  this.imports = relativeImports(cu, scanned.components);
851
+ this.bindings = importBindings(cu);
752
852
  this.importedNames = importedNames(cu);
753
853
  this.declaredHost = hostComponentsDeclared(cu);
754
854
  // Templates lay out what they insert with the source's Prettier style, which a source its config does not lay out keeps out of
@@ -763,7 +863,12 @@ export class EnzymeToReactTestingLibrary extends ScanningRecipe<Scanned> {
763
863
  const visited = await super.visitJsCompilationUnit(visiting, ctx);
764
864
  if (dry) {
765
865
  if (this.rows.some(row => row.status === "CONVERTED")) dry.converted.add(cu.sourcePath);
766
- } else this.rows.forEach(row => usages.insertRow(ctx, row));
866
+ if (this.blockers.size > 0) forecastBlockers.set(cu.sourcePath, new Map(this.blockers));
867
+ } else {
868
+ this.rows.forEach(row => usages.insertRow(ctx, row));
869
+ await this.blockShapes(cu, ctx);
870
+ if (this.blockers.size > 0) RENDER_BLOCKERS.set(cu.sourcePath, new Map(this.blockers));
871
+ }
767
872
  if (!foreign || !visited) return visited;
768
873
  return visited === visiting ? cu : create(visited as JS.CompilationUnit, draft => {
769
874
  draft.markers.markers.push(prettierStyle as any);
@@ -781,9 +886,23 @@ export class EnzymeToReactTestingLibrary extends ScanningRecipe<Scanned> {
781
886
  const converted = await this.convertBlock(candidate, ctx);
782
887
  this.cursor = original;
783
888
  // Each test's wrapper converts, or the shared wrapper and every test keep Enzyme
784
- if (mounts.every(id => this.mounts.has(id) && !this.pending.has(id))) return this.renderedInHooks(converted as J.Block, block, shared, ctx);
889
+ if (mounts.every(({id}) => this.mounts.has(id) && !this.pending.has(id))) return this.renderedInHooks(converted as J.Block, block, shared, ctx);
890
+ // What kept each test's copy of the render on Enzyme is what keeps the shared render there
891
+ const kept = new Map<string, string>();
892
+ for (const {id, from} of mounts) {
893
+ const why = this.blockers.get(id);
894
+ if (why && !kept.has(from)) kept.set(from, why);
895
+ }
896
+ for (const {id, from, name} of mounts) {
897
+ if (!kept.has(from) && this.mounts.has(id) && !this.pending.has(id)) kept.set(from, blockedByShared(name));
898
+ }
785
899
  this.restoreState(saved);
786
- return this.convertBlock(block, ctx);
900
+ const plain = await this.convertBlock(block, ctx);
901
+ mounts.forEach(({from}) => this.sharedRenders.add(from));
902
+ kept.forEach((why, id) => {
903
+ if (!this.blockers.has(id)) this.blockers.set(id, why);
904
+ });
905
+ return plain;
787
906
  }
788
907
 
789
908
  /**
@@ -894,7 +1013,7 @@ export class EnzymeToReactTestingLibrary extends ScanningRecipe<Scanned> {
894
1013
  * cleanup in `afterEach`, or the tests clearing it. An unmount that `afterEach` does before other statements
895
1014
  * becomes RTL's `cleanup()`, which keeps the order, and one after them is dropped, as RTL unmounts after them too.
896
1015
  */
897
- private async mountedInEachTest(block: J.Block, shared: SharedWrapper[], ctx: ExecutionContext): Promise<{candidate: J.Block, mounts: string[]}> {
1016
+ private async mountedInEachTest(block: J.Block, shared: SharedWrapper[], ctx: ExecutionContext): Promise<{candidate: J.Block, mounts: {id: string, from: string, name: string}[]}> {
898
1017
  const names = new Map<string, string>();
899
1018
  shared.forEach(wrapper => wrapper.assignments.forEach(id => names.set(id, wrapper.name)));
900
1019
  const cleanup = new Set(shared.flatMap(wrapper => [...wrapper.cleanup]));
@@ -908,7 +1027,7 @@ export class EnzymeToReactTestingLibrary extends ScanningRecipe<Scanned> {
908
1027
  };
909
1028
  const removed = new Set(shared.flatMap(wrapper => [wrapper.declaration.id, ...wrapper.afterEach && whole(wrapper.afterEach) ? [wrapper.afterEach.id] : []]));
910
1029
  const trimmed = withoutStatements(block, removed);
911
- const mounts: string[] = [];
1030
+ const mounts: {id: string, from: string, name: string}[] = [];
912
1031
  const outer = this;
913
1032
  const candidate = await new class extends JavaScriptVisitor<ExecutionContext> {
914
1033
  override async visitBlock(inner: J.Block, p: ExecutionContext): Promise<J | undefined> {
@@ -950,7 +1069,7 @@ export class EnzymeToReactTestingLibrary extends ScanningRecipe<Scanned> {
950
1069
  const declare = Template.builder().code(`const ${name} = `).param(assignment.assignment.element).build();
951
1070
  const declared = await declare.apply(statement.element, cursor) as J.VariableDeclarations | undefined;
952
1071
  if (!declared) throw new Error(`Cannot declare ${name}`);
953
- mounts.push(declared.variables[0].element.initializer!.element.id);
1072
+ mounts.push({id: declared.variables[0].element.initializer!.element.id, from: assignment.assignment.element.id, name});
954
1073
  statements.push({...statement, element: {...declared, prefix: statement.element.prefix}});
955
1074
  }
956
1075
  return withoutStatements(create(visited, draft => {
@@ -968,7 +1087,7 @@ export class EnzymeToReactTestingLibrary extends ScanningRecipe<Scanned> {
968
1087
  const declare = Template.builder().code(`const ${hooked.name} = `).param(withNewIds(hooked.mount)).build();
969
1088
  const declared = await declare.apply(first.element, cursor) as J.VariableDeclarations | undefined;
970
1089
  if (!declared) throw new Error(`Cannot declare ${hooked.name}`);
971
- mounts.push(declared.variables[0].element.initializer!.element.id);
1090
+ mounts.push({id: declared.variables[0].element.initializer!.element.id, from: hooked.mount.id, name: hooked.name});
972
1091
  const semicolon = test.statements.some(padded => padded.markers.markers.some(marker => marker.kind === J.Markers.Semicolon));
973
1092
  const padded = {...first, element: {...declared, prefix: first.element.prefix},
974
1093
  markers: {...first.markers, markers: semicolon ? [{kind: J.Markers.Semicolon, id: randomId()}] : []}};
@@ -984,7 +1103,7 @@ export class EnzymeToReactTestingLibrary extends ScanningRecipe<Scanned> {
984
1103
  return {mounts: new Map(this.mounts), uses: new Map(this.uses), removedStatements: new Set(this.removedStatements),
985
1104
  unmounts: new Set(this.unmounts), declarations: new Set(this.declarations), pending: new Set(this.pending),
986
1105
  reformat: new Set(this.reformat), hoists: new Map(this.hoists), hoistedMounts: new Map(this.hoistedMounts),
987
- portals: new Set(this.portals), rows: this.rows.length, afterVisit: this.afterVisit.length};
1106
+ portals: new Set(this.portals), rows: this.rows.length, afterVisit: this.afterVisit.length, blockers: new Map(this.blockers)};
988
1107
  }
989
1108
 
990
1109
  private restoreState(saved: ReturnType<typeof this.saveState>): void {
@@ -1000,6 +1119,7 @@ export class EnzymeToReactTestingLibrary extends ScanningRecipe<Scanned> {
1000
1119
  remap(this.uses, saved.uses);
1001
1120
  remap(this.hoists, saved.hoists);
1002
1121
  remap(this.hoistedMounts, saved.hoistedMounts);
1122
+ remap(this.blockers, saved.blockers);
1003
1123
  [[this.removedStatements, saved.removedStatements], [this.unmounts, saved.unmounts], [this.declarations, saved.declarations],
1004
1124
  [this.pending, saved.pending], [this.reformat, saved.reformat], [this.portals, saved.portals]]
1005
1125
  .forEach(([target, from]) => refill(target, from));
@@ -1017,15 +1137,25 @@ export class EnzymeToReactTestingLibrary extends ScanningRecipe<Scanned> {
1017
1137
  const reads = READS[api];
1018
1138
  // React 15 marks its markup with `data-reactroot` and empty renders with comments, which Enzyme's html() leaves out
1019
1139
  const markup = this.reactMajor >= 16;
1020
- const scope = analyzeWrapperScope(this.cursor, candidate, {events: reads.simulate ? this.events.events : new Set(), html: reads.html && markup, untaggedPositions, hostNames, snapshots: snapshots && markup, optionalChaining: this.optionalChaining,
1021
- constant: node => this.constantString(node)});
1022
- if (!scope) continue;
1023
- if ([...scope.uses.values()].some(use => use.use === "setProps" && !reads.props(use.props!, this.importedNames))) continue;
1140
+ let blocking: Parameters<typeof blockedByUses>[0] | undefined;
1141
+ const scope = analyzeWrapperScope(this.cursor, candidate, {events: reads.simulate ? this.events.events : new Set(), html: reads.html && markup, untaggedPositions, hostNames, snapshots: snapshots && markup, optInSnapshots: !snapshots && markup, optionalChaining: this.optionalChaining,
1142
+ constant: node => this.constantString(node), blocked: references => blocking = references});
1143
+ if (!scope) {
1144
+ if (blocking) this.blockers.set(candidate.mount.id, await blockedByUses(blocking));
1145
+ continue;
1146
+ }
1147
+ if ([...scope.uses.values()].some(use => use.use === "setProps" && !reads.props(use.props!, this.importedNames))) {
1148
+ this.blockers.set(candidate.mount.id, blockedByGate("setProps"));
1149
+ continue;
1150
+ }
1024
1151
  const mount = new Cursor(candidate.mount, variableCursor(this.cursor, candidate.declaration));
1025
1152
  const document = documentAt(mount);
1026
1153
  if (!document || !await renderPatterns[api].render.match(candidate.mount, mount)) continue;
1027
1154
  const attached = this.events.attached && [...scope.uses.values()].some(use => use.use === "simulate");
1028
- if (!attached && this.rootStyles && [...scope.uses.values()].some(use => CONTAINER_READS.has(use.use))) continue;
1155
+ if (!attached && this.rootStyles && [...scope.uses.values()].some(use => CONTAINER_READS.has(use.use))) {
1156
+ this.blockers.set(candidate.mount.id, blockedByGate("rootStyles"));
1157
+ continue;
1158
+ }
1029
1159
  this.mounts.set(candidate.mount.id, {document, api, attached});
1030
1160
  apis.push(api);
1031
1161
  this.declarations.add(candidate.declaration.id);
@@ -1273,9 +1403,16 @@ export class EnzymeToReactTestingLibrary extends ScanningRecipe<Scanned> {
1273
1403
  if (node?.kind !== J.Kind.MethodInvocation) return undefined;
1274
1404
  const call = node as J.MethodInvocation;
1275
1405
  const api = enzymeMethod(call);
1276
- if (api === "mount") return read && this.rendersPortal(call) ? undefined : api;
1406
+ if (api === "mount") {
1407
+ if (!read || !this.rendersPortal(call)) return api;
1408
+ this.blockers.set(call.id, blockedByGate("portal"));
1409
+ return undefined;
1410
+ }
1411
+ if (api !== "shallow" || call.arguments.elements.length !== 1) return undefined;
1277
1412
  const element = call.arguments.elements[0]?.element;
1278
- return api === "shallow" && call.arguments.elements.length === 1 && rendersHostElements(element, this.imports, scanned.components, this.importedNames, this.declaredHost) ? api : undefined;
1413
+ if (rendersHostElements(element, this.imports, scanned.components, this.importedNames, this.declaredHost)) return api;
1414
+ this.blockers.set(call.id, blockedByShallow(shallowMiss(element, this.imports, scanned.components, scanned.composites, this.bindings)));
1415
+ return undefined;
1279
1416
  }
1280
1417
 
1281
1418
  /**
@@ -1309,6 +1446,74 @@ export class EnzymeToReactTestingLibrary extends ScanningRecipe<Scanned> {
1309
1446
  return {roots, declares, resolve: resolver(scanned.modules, [...new Set([...roots, ""])], declares)};
1310
1447
  }
1311
1448
 
1449
+ /** Records what each `find` selector of `cu` written as other than a literal holds, for its review row. */
1450
+ /** Names the shape that kept each render the conversion didn't analyze, where the shape says why. */
1451
+ private async blockShapes(cu: JS.CompilationUnit, ctx: ExecutionContext): Promise<void> {
1452
+ const blockers = this.blockers;
1453
+ const mounts = this.mounts;
1454
+ const sharedRenders = this.sharedRenders;
1455
+ await new class extends JavaScriptVisitor<ExecutionContext> {
1456
+ override async visitMethodInvocation(method: J.MethodInvocation, ctx: ExecutionContext): Promise<J | undefined> {
1457
+ const api = enzymeMethod(method);
1458
+ if ((api === "mount" || api === "shallow") && !blockers.has(method.id) && !mounts.has(method.id) && !sharedRenders.has(method.id)) {
1459
+ const why = blockedByShape(this.cursor);
1460
+ if (why) blockers.set(method.id, why);
1461
+ }
1462
+ return super.visitMethodInvocation(method, ctx);
1463
+ }
1464
+ }().visit(cu, ctx);
1465
+ }
1466
+
1467
+ private async readSelectors(cu: JS.CompilationUnit): Promise<void> {
1468
+ SELECTOR_VALUES.delete(cu.sourcePath);
1469
+ const finds: J.MethodInvocation[] = [];
1470
+ walk(cu, tree => {
1471
+ if (tree.kind === J.Kind.MethodInvocation && enzymeMethod(tree as J.MethodInvocation) === "find" &&
1472
+ (tree as J.MethodInvocation).arguments.elements.length === 1) finds.push(tree as J.MethodInvocation);
1473
+ return true;
1474
+ });
1475
+ const topLevel = new Set(cu.statements.map(({element}) =>
1476
+ element.kind === JS.Kind.ExportDeclaration ? (element as JS.ExportDeclaration).exportClause?.id : element.id));
1477
+ // The resolver reads only top-level constants, so a name a nested `const` declares may hold a string after all
1478
+ const nested = new Set<string>();
1479
+ walk(cu, tree => {
1480
+ if (tree.kind !== J.Kind.VariableDeclarations || topLevel.has(tree.id)) return true;
1481
+ const variables = tree as J.VariableDeclarations;
1482
+ if (!variables.modifiers.some(modifier => modifier.keyword === "const")) return true;
1483
+ for (const {element: variable} of variables.variables) {
1484
+ if (isIdentifier(variable.name) && variable.initializer && stringParts(variable.initializer.element)) nested.add(variable.name.simpleName);
1485
+ }
1486
+ return true;
1487
+ });
1488
+ const reads = new Map<string, SelectorRead>();
1489
+ for (const find of finds) {
1490
+ const read = await this.selectorRead(find.arguments.elements[0].element, nested);
1491
+ if (read) reads.set(find.id, read);
1492
+ }
1493
+ if (reads.size > 0) SELECTOR_VALUES.set(cu.sourcePath, reads);
1494
+ }
1495
+
1496
+ /** What a selector holds that is a template or a string-typed name, or the first part of it that isn't a constant string. */
1497
+ private async selectorRead(selector: J, nested: ReadonlySet<string>): Promise<SelectorRead | undefined> {
1498
+ const named = (name: string) => evaluate([{name}], this.sourcePath, scanned.modules, this.moduleResolution().resolve);
1499
+ const printed = async (node: J) => (await TreePrinters.printer(JS.Kind.CompilationUnit).print(node)).trim().replace(/\s+/g, " ");
1500
+ if (selector.kind === JS.Kind.TemplateExpression) {
1501
+ const value = this.constantString(selector);
1502
+ if (value !== undefined) return {value};
1503
+ for (const {element: span} of (selector as JS.TemplateExpression).spans) {
1504
+ const part = span.expression;
1505
+ if (isIdentifier(part) && nested.has(part.simpleName)) return undefined;
1506
+ if (!isIdentifier(part) || named(part.simpleName) === undefined) return {unread: await printed(part)};
1507
+ }
1508
+ return undefined;
1509
+ }
1510
+ const value = isIdentifier(selector) ? named(selector.simpleName) : undefined;
1511
+ if (value !== undefined) return {value};
1512
+ // A name that isn't a constant string may hold a component or props, which only its type tells apart
1513
+ if (TypedTree.getType(selector) !== Type.Primitive.String || isIdentifier(selector) && nested.has(selector.simpleName)) return undefined;
1514
+ return isIdentifier(selector) || selector.kind === J.Kind.FieldAccess ? {unread: await printed(selector)} : undefined;
1515
+ }
1516
+
1312
1517
  /** The string a template of `const` strings holds, from the test or the modules it imports them from. */
1313
1518
  private constantString(node: J): string | undefined {
1314
1519
  const parts = stringParts(node);
@@ -1330,7 +1535,8 @@ export class EnzymeToReactTestingLibrary extends ScanningRecipe<Scanned> {
1330
1535
 
1331
1536
  async recipeList() {
1332
1537
  const steps = this.dependencySteps;
1333
- return [...steps ? [steps.rtl, steps.rtl18, steps.dom18] : [], new FindEnzymeUsage()];
1538
+ // The peer `@testing-library/dom` goes first, so RTL 16 lands only where it did
1539
+ return [...steps ? [steps.rtl, steps.dom18, steps.rtl18] : [], new FindEnzymeUsage()];
1334
1540
  }
1335
1541
  }
1336
1542
 
@@ -26,6 +26,28 @@ export class EnzymeUsageRow {
26
26
  suggestedAction!: string;
27
27
  }
28
28
 
29
+ /**
30
+ * What kept each render the converter analyzed on Enzyme, by source and then mount, for the review row of the mount that
31
+ * `FindEnzymeUsage` writes after it. Both run in the same RPC worker, which edits a source with each recipe in turn.
32
+ */
33
+ export const RENDER_BLOCKERS = new Map<string, ReadonlyMap<string, string>>();
34
+
35
+ /** The key of {@link RENDER_BLOCKERS} for what keeps every render of a source on Enzyme. */
36
+ export const FILE_BLOCKER = "*";
37
+
38
+ /** What the converter read of a `find` selector written as other than a literal: the string it holds, or the part it can't read. */
39
+ export type SelectorRead = {value: string} | {unread: string};
40
+
41
+ /** Each {@link SelectorRead} of a source, by the `find` call, for the review row `FindEnzymeUsage` writes after the converter. */
42
+ export const SELECTOR_VALUES = new Map<string, ReadonlyMap<string, SelectorRead>>();
43
+
44
+ /** The suggested action for a `find` whose selector is a string the recipe can't read, built from `unread`. */
45
+ export function unreadSelector(unread: string): string {
46
+ return `The recipe can't read this selector as a string: \`${unread}\` isn't a \`const\` string, or a template of \`const\` strings, that the recipe finds in this test or in a module it imports by a relative path or \`baseUrl\`. ` +
47
+ "Where the selector is a tag, class, id or attribute selector, write `container.querySelectorAll` with the same expression by hand. " +
48
+ "Enzyme also counts components given that class, id or attribute, so compare the counts.";
49
+ }
50
+
29
51
  export function enzymeModule(value: unknown): value is string {
30
52
  return typeof value === "string" && (value === ENZYME || value.startsWith("enzyme/") ||
31
53
  (value === "enzyme-to-json" || value.startsWith("enzyme-to-json/")) || /^(?:@[^/]+\/)?enzyme-adapter-/.test(value));
@@ -50,7 +72,11 @@ export type SelectorKind = "component" | "dom" | "enzyme" | "props" | "predicate
50
72
  export type EventKind = "event" | "hover" | "change" | "mock" | "other";
51
73
 
52
74
  export function migrationReason(api: string, selector?: SelectorKind, event?: EventKind): {reason: string, suggestedAction: string} {
53
- if (api === "shallow" || api === "dive") {
75
+ if (api === "dive") {
76
+ return {reason: "SHALLOW_RENDERING", suggestedAction: "Remove the `dive()`: RTL's `render` renders every level, so query what the child component renders directly. " +
77
+ "Where the test relied on the levels below not rendering, `jest.mock` those components' modules with stubs."};
78
+ }
79
+ if (api === "shallow") {
54
80
  return {reason: "SHALLOW_RENDERING", suggestedAction: "Review child rendering and effects before replacing shallow rendering with RTL render."};
55
81
  }
56
82
  const internal = INTERNAL_STATE_ACTIONS[api];
@@ -114,7 +140,27 @@ const WRAPPER_API_ACTIONS: Readonly<Record<string, string>> = {
114
140
  hasClass: "Use `element.classList.contains`, or `toHaveClass` from `@testing-library/jest-dom`.",
115
141
  getDOMNode: "Query the element directly with `screen.getBy*` or `container.querySelector`; RTL already returns DOM nodes.",
116
142
  update: "Remove it: RTL renders the latest state on every query. Await `findBy*` or `waitFor` where the change is asynchronous.",
117
- unmount: "Call the `unmount` that RTL's `render` returns, or rely on RTL's automatic cleanup after each test."
143
+ unmount: "Call the `unmount` that RTL's `render` returns, or rely on RTL's automatic cleanup after each test.",
144
+ hostNodes: "Remove it: `querySelectorAll` and the `getBy*` queries return DOM elements only, which is what `hostNodes()` keeps.",
145
+ childAt: "Read the queried element's `children[index]`, or query the child with `within(element)`.",
146
+ get: "Index the `querySelectorAll` or `getAllBy*` result; it already holds DOM elements, which `get` returns a React element in place of.",
147
+ forEach: "Loop over `Array.from(container.querySelectorAll(selector))` or the `getAllBy*` result, reading each element's DOM properties.",
148
+ map: "Map over `Array.from(container.querySelectorAll(selector))` or the `getAllBy*` result, reading each element's DOM properties.",
149
+ reduce: "Reduce over `Array.from(container.querySelectorAll(selector))` or the `getAllBy*` result, reading each element's DOM properties.",
150
+ filter: "Filter `Array.from(container.querySelectorAll(selector))` by a DOM property, or narrow the selector so the query returns only those elements.",
151
+ contains: "Assert the element is in the DOM: `screen.getByText` or `getByRole` for what the React element renders, or `toContainElement` from `@testing-library/jest-dom`.",
152
+ containsMatchingElement: "Assert what the element renders is in the DOM, with `screen.getByText` or `getByRole`; RTL doesn't compare React elements.",
153
+ is: "Use `element.matches(selector)` on the queried element.",
154
+ type: "Read the element's `tagName` for a DOM element. A component's type has no DOM equivalent: assert on what it renders.",
155
+ name: "Read the element's `tagName` for a DOM element. A component's name has no DOM equivalent: assert on what it renders.",
156
+ parent: "Read the queried element's `parentElement`.",
157
+ closest: "Use `element.closest(selector)` on the queried element.",
158
+ isEmptyRender: "Assert `container` is empty, with `expect(container).toBeEmptyDOMElement()` from `@testing-library/jest-dom` or `container.innerHTML === ''`.",
159
+ debug: "Use `screen.debug()` or `prettyDOM(element)`, or remove it once the test passes.",
160
+ getElement: "Assert on what the element renders in the DOM; RTL has no React element tree to compare.",
161
+ renderProp: "Render what the render prop returns by rendering the component with that prop, and query the result in the DOM.",
162
+ detach: "Remove it: RTL unmounts and removes each render's container after each test.",
163
+ key: "A React key has no DOM equivalent: assert on the order or content of the rendered elements instead."
118
164
  };
119
165
 
120
166
  export function enclosingScope(start: Cursor): string {