@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
1
  import {Column, Cursor} from "@openrewrite/rewrite";
2
- import {JS, walk} from "@openrewrite/rewrite/javascript";
2
+ import {JS, namesReferencedWithin, walk} from "@openrewrite/rewrite/javascript";
3
3
  import {isIdentifier, J} from "@openrewrite/rewrite/java";
4
- import {importBindings, resolveRelative} from "../util/module-imports";
4
+ import {importBindings, Resolve, resolveRelative} from "../util/module-imports";
5
5
 
6
6
  export const REDUX = "redux";
7
7
  export const RTK = "@reduxjs/toolkit";
@@ -342,12 +342,13 @@ export function localSlices(cu: JS.CompilationUnit): LocalSlices {
342
342
  }
343
343
 
344
344
  /** Resolves a reducer expression of a store to the slice it is the reducer of. */
345
- export function resolveSliceReducer(node: J, cu: JS.CompilationUnit, local: LocalSlices, modules: ReadonlyMap<string, SliceModule>): SliceFacts | undefined {
345
+ export function resolveSliceReducer(node: J, cu: JS.CompilationUnit, local: LocalSlices, modules: ReadonlyMap<string, SliceModule>,
346
+ resolve: Resolve = (from, specifier) => resolveRelative(from, specifier, modules)): SliceFacts | undefined {
346
347
  const inFile = reducerOf(node, local.localSlices) ?? (isIdentifier(node) ? local.localReducers.get(node.simpleName) : undefined);
347
348
  if (inFile) return inFile;
348
349
  const imported = (name: string) => {
349
350
  const binding = importBindings(cu).find(b => b.local === name);
350
- const path = binding && resolveRelative(cu.sourcePath, binding.module, modules);
351
+ const path = binding && resolve(cu.sourcePath, binding.module);
351
352
  return path ? {binding, module: modules.get(path)!} : undefined;
352
353
  };
353
354
  if (isIdentifier(node)) {
@@ -379,7 +380,7 @@ export const SUGGESTED_ACTIONS: Readonly<Record<string, string>> = {
379
380
  UNKNOWN_OPTION: "Review this `configureStore` option by hand."
380
381
  };
381
382
 
382
- export const TEST_SOURCE = /(^|\/)(__tests__|__mocks__|tests?|stories)\/|\.(test|spec|stories)\.[jt]sx?$/i;
383
+ export {TEST_SOURCE} from "../util/test-source";
383
384
 
384
385
  /** The options of `configureStore` that keep a store from converting, by the reason they are recorded under. */
385
386
  const BLOCKING_OPTIONS: Readonly<Record<string, string>> = {
@@ -389,6 +390,8 @@ const BLOCKING_OPTIONS: Readonly<Record<string, string>> = {
389
390
  export interface Finding {
390
391
  reason: string;
391
392
  detail: string;
393
+ /** What to do about this finding, where it says more than the reason's own action. */
394
+ action?: string;
392
395
  }
393
396
 
394
397
  /** The local names a source calls to create a Redux store: legacy `createStore` and Redux Toolkit's `configureStore`. */
@@ -466,6 +469,8 @@ export function legacyEnhancer(expression: J, cu: JS.CompilationUnit): LegacyEnh
466
469
  const name = ((node as JS.Spread).expression as J.Identifier).simpleName;
467
470
  const array = constant(name);
468
471
  if (array?.kind !== J.Kind.NewArray) return `middleware spread from \`${name}\``;
472
+ // An array that another statement refers to, such as one that pushes more middleware into it, may not hold only what it declares
473
+ if (cu.statements.filter(st => [...namesReferencedWithin(st.element)].includes(name)).length > 1) return `middleware spread from \`${name}\`, which is used elsewhere too`;
469
474
  for (const element of (array as J.NewArray).initializer?.elements.map(e => e.element).filter(e => e.kind !== J.Kind.Empty) ?? []) {
470
475
  const why = middleware(element);
471
476
  if (why) return why;
@@ -543,7 +548,7 @@ export function preloadedValue(expression: J, cu: JS.CompilationUnit): boolean {
543
548
  * `undefined` when `call` creates no store.
544
549
  */
545
550
  export function storeFindings(call: J.MethodInvocation, cu: JS.CompilationUnit, modules: ReadonlyMap<string, SliceModule>,
546
- functions = storeFunctions(cu)): {api: string, findings: Finding[], slices: Map<string, SliceFacts>, reducerStore?: ReducerStoreKind} | undefined {
551
+ functions = storeFunctions(cu), resolve?: Resolve): {api: string, findings: Finding[], slices: Map<string, SliceFacts>, reducerStore?: ReducerStoreKind} | undefined {
547
552
  if (call.select) return undefined;
548
553
  const api = call.name.simpleName;
549
554
  if (functions.legacy.has(api)) {
@@ -565,17 +570,23 @@ export function storeFindings(call: J.MethodInvocation, cu: JS.CompilationUnit,
565
570
  const options = objectProperties(call.arguments.elements[0]?.element);
566
571
  if (!options) return {api, findings: [{reason: "OPTIONS_NOT_LITERAL", detail: ""}], slices};
567
572
  const findings: Finding[] = [];
568
- for (const key of options.keys()) {
569
- if (key !== "reducer") findings.push({reason: BLOCKING_OPTIONS[key] ?? "UNKNOWN_OPTION", detail: key});
573
+ for (const [key, value] of options) {
574
+ if (key === "reducer") continue;
575
+ const action = optionAction(key, value, options.get("reducer"), cu);
576
+ findings.push({reason: BLOCKING_OPTIONS[key] ?? "UNKNOWN_OPTION", detail: key, ...action ? {action} : {}});
570
577
  }
571
- // A store of its `reducer` alone can also move to zustand whole, driven by that reducer
578
+ // A store of its `reducer` alone can also move to zustand whole, driven by that reducer, as can one whose other
579
+ // options only change what development builds check, which a plain `configureStore` checks and the move drops too
572
580
  const reducer = options.get("reducer");
573
- const reducerStore = options.size !== 1 || !reducer ? undefined : reducer.kind === J.Kind.NewClass && !(reducer as J.NewClass).class ? "combined" : "reducer";
581
+ const reducerStore = !reducer || [...options].some(([key, value]) => key !== "reducer" && !developmentOnly(key, value)) ? undefined : reducer.kind === J.Kind.NewClass && !(reducer as J.NewClass).class ? "combined" : "reducer";
574
582
  const reducers = objectProperties(options.get("reducer"));
575
- if (!reducers) return {api, findings: [...findings, {reason: "ROOT_REDUCER", detail: ""}], slices, reducerStore};
583
+ if (!reducers) {
584
+ const action = rootReducerAction(reducer, reducerStore !== undefined, cu);
585
+ return {api, findings: [...findings, {reason: "ROOT_REDUCER", detail: "", ...action ? {action} : {}}], slices, reducerStore};
586
+ }
576
587
  const local = localSlices(cu);
577
588
  for (const [key, value] of reducers) {
578
- const slice = resolveSliceReducer(value, cu, local, modules);
589
+ const slice = resolveSliceReducer(value, cu, local, modules, resolve);
579
590
  if (!slice) findings.push({reason: "NON_SLICE_REDUCER", detail: key});
580
591
  else if (slice.blocker) findings.push(slice.blocker);
581
592
  else slices.set(key, slice);
@@ -583,6 +594,114 @@ export function storeFindings(call: J.MethodInvocation, cu: JS.CompilationUnit,
583
594
  return {api, findings, slices, reducerStore};
584
595
  }
585
596
 
597
+ /** What to do about the `configureStore` option `key: value`, where it says more than the option's reason does. */
598
+ function optionAction(key: string, value: J, reducer: J | undefined, cu: JS.CompilationUnit): string | undefined {
599
+ if (developmentOnly(key, value)) return key === "devTools" ?
600
+ "`devTools` only connects the Redux DevTools extension, which a store that moves whole drops, as it drops a plain `configureStore`'s: remove what the store's other rows name, and it moves whole, where `wholeStores` is on." :
601
+ "`middleware` only sets the development checks of the default middleware, which a store that moves whole drops, as it drops a plain `configureStore`'s: remove what the store's other rows name, and it moves whole, where `wholeStores` is on.";
602
+ if (key !== "middleware") return undefined;
603
+ const actions: string[] = [];
604
+ // An RTK Query API adds its middleware and its reducer, the latter under `[api.reducerPath]`
605
+ const apis = new Set<string>();
606
+ walk(value, tree => {
607
+ const access = tree as J.FieldAccess;
608
+ if (tree.kind === J.Kind.FieldAccess && access.name.element.simpleName === "middleware" && isIdentifier(access.target)) apis.add(access.target.simpleName);
609
+ return true;
610
+ });
611
+ const reducedApis = new Set<string>();
612
+ if (reducer) walk(reducer, tree => {
613
+ const access = tree as J.FieldAccess;
614
+ if (tree.kind === J.Kind.FieldAccess && ["reducer", "reducerPath"].includes(access.name.element.simpleName) && isIdentifier(access.target) && apis.has(access.target.simpleName)) reducedApis.add(access.target.simpleName);
615
+ return true;
616
+ });
617
+ const made = madeBy(cu);
618
+ const read = namesReferencedWithin(value);
619
+ const by = (module: string, ...names: string[]) => {
620
+ const locals = importedAs(cu, module, ...names);
621
+ return [...read].some(name => locals.has(name) || locals.has(made.get(name)?.name.simpleName ?? ""));
622
+ };
623
+ if (reducedApis.size > 0) actions.push(`\`${[...reducedApis][0]}.middleware\` is RTK Query's, which has no zustand equivalent: keep this store in Redux, or move its queries to a data-fetching library, such as TanStack Query, by hand.`);
624
+ if (by("redux-saga", "default")) actions.push("redux-saga runs its sagas on the actions the store dispatches, which zustand has no middleware for: rewrite the sagas as functions that call the store, or keep this store in Redux.");
625
+ if ([...apis].some(api => importedAs(cu, RTK, "createListenerMiddleware").has(made.get(api)?.name.simpleName ?? ""))) actions.push("RTK's listener middleware runs its effects on the actions the store dispatches: rewrite them with the zustand store's `subscribe`, or keep this store in Redux.");
626
+ if (by("redux-logger", "default", "logger", "createLogger")) actions.push("redux-logger logs each action the store dispatches: remove it, or use zustand's `devtools` middleware to watch the store, and convert by hand.");
627
+ return actions.length > 0 ? actions.join(" ") : undefined;
628
+ }
629
+
630
+ /** The function each top-level `const` of `cu` is the result of calling, such as `createSagaMiddleware` for `const saga = createSagaMiddleware()`. */
631
+ function madeBy(cu: JS.CompilationUnit): Map<string, J.MethodInvocation> {
632
+ const made = new Map<string, J.MethodInvocation>();
633
+ for (const {element} of cu.statements) {
634
+ if (element.kind !== J.Kind.VariableDeclarations) continue;
635
+ for (const {element: variable} of (element as J.VariableDeclarations).variables) {
636
+ const initializer = variable.initializer?.element;
637
+ if (isIdentifier(variable.name) && initializer?.kind === J.Kind.MethodInvocation && !(initializer as J.MethodInvocation).select) {
638
+ made.set(variable.name.simpleName, initializer as J.MethodInvocation);
639
+ }
640
+ }
641
+ }
642
+ return made;
643
+ }
644
+
645
+ /**
646
+ * What to do about a `configureStore`'s `reducer` that isn't an object of reducers, where that is known: `whole` when
647
+ * nothing else in the call keeps the store from moving whole, driven by that reducer.
648
+ */
649
+ function rootReducerAction(reducer: J | undefined, whole: boolean, cu: JS.CompilationUnit): string | undefined {
650
+ if (!reducer) return undefined;
651
+ const call = reducer.kind === J.Kind.MethodInvocation && !(reducer as J.MethodInvocation).select ? reducer as J.MethodInvocation :
652
+ isIdentifier(reducer) ? madeBy(cu).get(reducer.simpleName) : undefined;
653
+ const by = (module: string, name: string) => call !== undefined && importedAs(cu, module, name).has(call.name.simpleName);
654
+ if (by("redux-persist", "persistReducer")) return "`reducer` is redux-persist's `persistReducer`, and redux-persist persists a Redux store: convert the store by hand, with zustand's `persist` middleware in place of redux-persist.";
655
+ if (whole) return "A store of a single root reducer moves whole, as one zustand store that the reducer drives: remove what the store's other rows name, and it moves whole, where `wholeStores` is on.";
656
+ if ((by(REDUX, "combineReducers") || by(RTK, "combineReducers")) && objectProperties(call!.arguments.elements[0]?.element)) {
657
+ const name = isIdentifier(reducer) ? `\`${reducer.simpleName}\`` : "`reducer`";
658
+ return `${name} is \`combineReducers\` of an object of reducers: pass that object as \`reducer\` instead, which \`configureStore\` combines the same way, and the store's slices are read.`;
659
+ }
660
+ return undefined;
661
+ }
662
+
663
+ /** The checks of Redux Toolkit's default middleware, which it runs only in development. */
664
+ const DEVELOPMENT_CHECKS = new Set(["serializableCheck", "immutableCheck", "actionCreatorCheck"]);
665
+
666
+ /**
667
+ * Whether the `configureStore` option `key: value` changes only what a development build checks or shows: `devTools`
668
+ * of any value without effects, or `middleware` of `getDefaultMiddleware => getDefaultMiddleware({...})` that sets
669
+ * only its checks, so that the store's middleware is still the default thunk.
670
+ */
671
+ export function developmentOnly(key: string, value: J): boolean {
672
+ if (key === "devTools") return withoutEffects(value);
673
+ if (key !== "middleware") return false;
674
+ const lambda = lambdaOf(value);
675
+ const parameters = lambda ? parametersOf(lambda) : [];
676
+ const name = parameters.length === 1 ? plainParameter(parameters[0]) : undefined;
677
+ if (!lambda || !name) return false;
678
+ let body: J | undefined = lambda.body;
679
+ if (body.kind === J.Kind.Block) {
680
+ const statements = (body as J.Block).statements;
681
+ body = statements.length === 1 && statements[0].element.kind === J.Kind.Return ? (statements[0].element as J.Return).expression : undefined;
682
+ }
683
+ if (body?.kind !== J.Kind.MethodInvocation) return false;
684
+ const call = body as J.MethodInvocation;
685
+ if (call.select || call.name.simpleName !== name) return false;
686
+ const args = call.arguments.elements.map(e => e.element).filter(e => e.kind !== J.Kind.Empty);
687
+ if (args.length === 0) return true;
688
+ const checks = args.length === 1 ? objectProperties(args[0]) : undefined;
689
+ // NOTE: `objectProperties` reads only `key: value` and shorthand properties, so a spread leaves it undefined
690
+ return checks !== undefined && [...checks].every(([check, setting]) => DEVELOPMENT_CHECKS.has(check) && withoutEffects(setting));
691
+ }
692
+
693
+ /** Whether evaluating `node` can do nothing but compute a value: it calls, constructs, assigns and awaits nothing. */
694
+ export function withoutEffects(node: J): boolean {
695
+ let effects = false;
696
+ walk(node, tree => {
697
+ // An object literal is a `NewClass` of no class
698
+ if (tree.kind === J.Kind.MethodInvocation || tree.kind === J.Kind.NewClass && (tree as J.NewClass).class || tree.kind === J.Kind.Assignment ||
699
+ tree.kind === J.Kind.AssignmentOperation || tree.kind === JS.Kind.Await || tree.kind === J.Kind.Lambda || tree.kind === JS.Kind.ArrowFunction) effects = true;
700
+ return !effects;
701
+ });
702
+ return !effects;
703
+ }
704
+
586
705
  /** The variable or function a store is created in, such as `store` in `export const store = configureStore(...)`. */
587
706
  export function storeName(cursor: Cursor): string {
588
707
  for (let c: Cursor | undefined = cursor.parent; c; c = c.parent) {