@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,6 +1,7 @@
1
1
  import { ExecutionContext, ScanningRecipe, SourceFile, TreeVisitor } from "@openrewrite/rewrite";
2
2
  import { AddDependencyOptions } from "@openrewrite/rewrite/javascript";
3
3
  import { JavaDependencyRecipe } from "../util/java-recipe-proxy";
4
+ import { PathsConfigs } from "../util/module-imports";
4
5
  import { SliceModule } from "./redux-stores";
5
6
  import { SliceSource, SourceFacts } from "./zustand-plan";
6
7
  export interface ZustandForecast {
@@ -18,12 +19,16 @@ interface PackageFacts {
18
19
  reactNative?: string;
19
20
  zustand?: string;
20
21
  immer?: string;
22
+ redux?: string;
23
+ toolkit?: string;
24
+ reactRedux?: string;
21
25
  }
22
26
  interface Scanned {
23
27
  sources: Map<string, SourceFacts>;
24
28
  modules: Map<string, SliceModule>;
25
29
  sliceSources: Map<string, SliceSource>;
26
30
  packages: Map<string, PackageFacts>;
31
+ configs: PathsConfigs;
27
32
  }
28
33
  declare abstract class ZustandDependency extends JavaDependencyRecipe {
29
34
  private readonly addition;
@@ -67,7 +72,7 @@ export declare class AddImmer extends ZustandDependency {
67
72
  export declare class ReduxToZustand extends ScanningRecipe<Scanned> {
68
73
  readonly name = "org.openrewrite.react.migrate.redux-to-zustand";
69
74
  readonly displayName = "Migrate Redux Toolkit slices to zustand";
70
- readonly description = "Moves a repository's one Redux Toolkit store to zustand when it is a `configureStore` of `createSlice` reducers with no other option, its sources are JavaScript, and every use of it converts: each slice becomes a zustand store whose action creators keep their names and run the slice's reducers through immer's `produce`, `useSelector` reads of one slice become the slice's zustand hook, `dispatch` and `store.dispatch` of the slices' action creators become calls of them, `store.getState()` reads become the slice store's `getState()`, and the react-redux `Provider`, replaced with its children, and the store's source are removed. A slice's own `createAsyncThunk`s, whose stages its `extraReducers` handles, keep running on Redux Toolkit and send their actions to the slice's zustand store. A store of its `reducer` alone whose slices can't move one by one, such as one with a reducer that is no slice's, thunks that reach the rest of the store or dispatches whose result is used, moves whole: its reducer runs on one zustand store whose `dispatch` runs thunks as Redux Toolkit's default middleware does, its selectors run on that store, through a hook of the store's source that keeps each selection per state where zustand 5 would run the selector on each read, and the store keeps its `getState` and `dispatch`, and its `subscribe`, whose listeners its `dispatch` calls after every action as Redux does, where a source subscribes to it. A legacy `createStore` of a reducer, and perhaps a preloaded state, moves whole too, its `dispatch` taking plain actions only, as Redux's does without middleware, or thunks as well where its enhancer is `applyMiddleware(thunk)`, perhaps inside `compose` or Redux DevTools, which is dropped. Components connected with `connect`, with no `mergeProps` and no option but `forwardRef`, move with a store that moves whole: its source declares a `connect` for the zustand store that passes the same props, copies the same statics and skips the same re-renders as react-redux's, and the store batches its updates as react-redux does. Adds `zustand`, and `immer` where slices move one by one, where they are missing. Stores with any other use, such as `connect` with `mergeProps`, other middleware or enhancers, other uses of the store object such as `persistStore(store)`, selectors with their own equality function or several stores, stay in Redux and are recorded for review.";
75
+ readonly description = "Moves a repository's one Redux Toolkit store to zustand when it is a `configureStore` of `createSlice` reducers with no other option, its sources are JavaScript, and every use of it converts: each slice becomes a zustand store whose action creators keep their names and run the slice's reducers through immer's `produce`, `useSelector` reads of one slice become the slice's zustand hook, `dispatch` and `store.dispatch` of the slices' action creators become calls of them, `store.getState()` reads become the slice store's `getState()`, and the react-redux `Provider`, replaced with its children, and the store's source are removed. A slice's own `createAsyncThunk`s, whose stages its `extraReducers` handles, keep running on Redux Toolkit and send their actions to the slice's zustand store. A store of its `reducer` alone whose slices can't move one by one, such as one with a reducer that is no slice's, thunks that reach the rest of the store or dispatches whose result is used, moves whole: its reducer runs on one zustand store whose `dispatch` runs thunks as Redux Toolkit's default middleware does, its selectors run on that store, through a hook of the store's source that keeps each selection per state where zustand 5 would run the selector on each read, and the store keeps its `getState` and `dispatch`, and its `subscribe`, whose listeners its `dispatch` calls after every action as Redux does, where a source subscribes to it. A legacy `createStore` of a reducer, and perhaps a preloaded state, moves whole too, its `dispatch` taking plain actions only, as Redux's does without middleware, or thunks as well where its enhancer is `applyMiddleware(thunk)`, perhaps inside `compose` or Redux DevTools, which is dropped. Components connected with `connect`, with no `mergeProps` and no option but `forwardRef`, move with a store that moves whole: its source declares a `connect` for the zustand store that passes the same props, copies the same statics and skips the same re-renders as react-redux's, and the store batches its updates as react-redux does. A store that moves whole but is created, and not exported, at the top level of an application's entry source, such as the one that renders the `Provider`, moves to an `appStore` module beside that source, with the imports and top-level `const`s and `let`s only it uses, and the source imports back what it still uses. A store's source may export it in its declaration, as its default export or in an export list such as `export {store}`, and other sources may import it, and its slices, by relative paths or by aliases such as `@/store` that the `paths` of the nearest `tsconfig.json` or `jsconfig.json` declare. Adds `zustand`, and `immer` where slices move one by one, where they are missing. Stores with any other use, such as `connect` with `mergeProps`, other middleware or enhancers, other uses of the store object such as `persistStore(store)`, selectors with their own equality function or several stores, stay in Redux and are recorded for review.";
71
76
  wholeStores?: boolean;
72
77
  constructor(options?: {
73
78
  wholeStores?: boolean;
@@ -79,13 +84,17 @@ export declare class ReduxToZustand extends ScanningRecipe<Scanned> {
79
84
  private readonly stores;
80
85
  initialValue(): Scanned;
81
86
  scanner(scanned: Scanned): Promise<TreeVisitor<any, ExecutionContext>>;
87
+ private reported;
88
+ private splits;
82
89
  private plans;
83
90
  private planned;
91
+ private split;
92
+ generate(scanned: Scanned, ctx: ExecutionContext): Promise<SourceFile[]>;
84
93
  private dependencies;
85
94
  editorWithData(scanned: Scanned): Promise<TreeVisitor<any, ExecutionContext>>;
86
95
  recipeList(): Promise<(AddZustand | AddZustand4 | AddImmer)[]>;
87
96
  }
88
97
  export declare const SELECTOR = "export function SELECTOR_HOOK(selector) {\n const last = useRef(undefined);\n const select = () => {\n const state = HOOK.getState();\n const kept = last.current;\n if (kept && kept.state === state && kept.selector === selector) return kept.selection;\n const selection = selector(state);\n last.current = {state, selector, selection};\n return selection;\n };\n return useSyncExternalStore(HOOK.subscribe, select, select);\n}";
89
- export declare const CONNECT = "export function connect(mapStateToProps, mapDispatchToProps, mergeProps, options) {\n const forwardsRef = Boolean(options && options.forwardRef);\n const selectState = mapStateToProps ? state => state : () => undefined;\n const dependsOnOwnProps = map => map.dependsOnOwnProps !== undefined && map.dependsOnOwnProps !== null ? Boolean(map.dependsOnOwnProps) : map.length !== 1;\n // A map that returns a function on its first call is a factory of the map to use\n const mapper = map => {\n let actual = map;\n let first = true;\n const run = (value, ownProps) => dependsOnOwnProps(actual) ? actual(value, ownProps) : actual(value);\n return {\n map(value, ownProps) {\n let props = run(value, ownProps);\n if (first) {\n first = false;\n if (typeof props === \"function\") {\n actual = props;\n props = run(value, ownProps);\n }\n }\n return props;\n },\n dependsOnOwnProps: () => dependsOnOwnProps(actual)\n };\n };\n const bound = actionCreators => {\n const props = {};\n for (const key of Object.keys(actionCreators)) {\n const actionCreator = actionCreators[key];\n if (typeof actionCreator === \"function\") props[key] = (...args) => HOOK.dispatch(actionCreator(...args));\n }\n return props;\n };\n const shallowEqual = (a, b) => {\n const keys = Object.keys(a);\n return keys.length === Object.keys(b).length && keys.every(key => Object.prototype.hasOwnProperty.call(b, key) && Object.is(a[key], b[key]));\n };\n const notHoisted = [\"$$typeof\", \"render\", \"compare\", \"type\", \"childContextTypes\", \"contextType\", \"contextTypes\", \"defaultProps\", \"displayName\",\n \"getDefaultProps\", \"getDerivedStateFromError\", \"getDerivedStateFromProps\", \"mixins\", \"propTypes\", \"name\", \"length\", \"prototype\", \"caller\",\n \"callee\", \"arguments\", \"arity\"];\n const hoistStatics = (target, source) => {\n for (let from = source; from && from !== Function.prototype && from !== Object.prototype; from = Object.getPrototypeOf(from)) {\n for (const key of [...Object.getOwnPropertyNames(from), ...Object.getOwnPropertySymbols(from)]) {\n if (!notHoisted.includes(key) && !Object.prototype.hasOwnProperty.call(target, key)) Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(from, key));\n }\n }\n return target;\n };\n return WrappedComponent => {\n const displayName = `Connect(${WrappedComponent.displayName || WrappedComponent.name || \"Component\"})`;\n function ConnectFunction(props) {\n const cache = useRef({}).current;\n const state = HOOK(selectState);\n if (!cache.mappers) cache.mappers = {state: mapStateToProps ? mapper(mapStateToProps) : undefined, dispatch: typeof mapDispatchToProps === \"function\" ? mapper(mapDispatchToProps) : undefined};\n const {state: mapState, dispatch: mapDispatch} = cache.mappers;\n if (cache.props !== props) {\n cache.props = props;\n cache.ownProps = props;\n if (forwardsRef) {\n cache.ownProps = {};\n for (const key of Object.keys(props)) if (key !== \"reactReduxForwardedRef\") cache.ownProps[key] = props[key];\n }\n }\n const ownProps = cache.ownProps;\n if (!cache.stateProps || (mapState && (cache.state !== state || (mapState.dependsOnOwnProps() && cache.stateOwnProps !== ownProps)))) {\n cache.stateProps = mapState ? mapState.map(state, ownProps) : {};\n cache.state = state;\n cache.stateOwnProps = ownProps;\n }\n if (!cache.dispatchProps || (mapDispatch && mapDispatch.dependsOnOwnProps() && cache.dispatchOwnProps !== ownProps)) {\n cache.dispatchProps = mapDispatch ? mapDispatch.map(HOOK.dispatch, ownProps) : mapDispatchToProps ? bound(mapDispatchToProps) : {dispatch: HOOK.dispatch};\n cache.dispatchOwnProps = ownProps;\n }\n const merged = {...ownProps, ...cache.stateProps, ...cache.dispatchProps};\n if (!cache.merged || !shallowEqual(cache.merged, merged)) cache.merged = merged;\n if (!cache.element || cache.rendered !== cache.merged || cache.ref !== props.reactReduxForwardedRef) {\n cache.rendered = cache.merged;\n cache.ref = props.reactReduxForwardedRef;\n cache.element = createElement(WrappedComponent, forwardsRef ? {...cache.merged, ref: cache.ref} : cache.merged);\n }\n return cache.element;\n }\n ConnectFunction.displayName = displayName;\n const Connect = memo(ConnectFunction);\n Connect.displayName = displayName;\n Connect.WrappedComponent = WrappedComponent;\n if (!forwardsRef) return hoistStatics(Connect, WrappedComponent);\n const Forwarded = forwardRef((props, ref) => createElement(Connect, {...props, reactReduxForwardedRef: ref}));\n Forwarded.displayName = displayName;\n Forwarded.WrappedComponent = WrappedComponent;\n return hoistStatics(Forwarded, WrappedComponent);\n };\n}";
98
+ export declare function connectSource(hook: string, reactRedux: string | undefined): string;
90
99
  export {};
91
100
  //# sourceMappingURL=redux-to-zustand.d.ts.map
@@ -1 +1 @@
1
- {"version":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B;AA8aD,eAAO,MAAM,QAAQ,qcAWnB,CAAC;AAYH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,CAElF"}
@@ -15,7 +15,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
15
15
  });
16
16
  };
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.CONNECT = exports.SELECTOR = exports.ReduxToZustand = exports.AddImmer = exports.AddZustand4 = exports.AddZustand = void 0;
18
+ exports.SELECTOR = exports.ReduxToZustand = exports.AddImmer = exports.AddZustand4 = exports.AddZustand = void 0;
19
+ exports.connectSource = connectSource;
19
20
  const rewrite_1 = require("@openrewrite/rewrite");
20
21
  const javascript_1 = require("@openrewrite/rewrite/javascript");
21
22
  const java_1 = require("@openrewrite/rewrite/java");
@@ -26,6 +27,7 @@ const rewrite_2 = require("@openrewrite/rewrite");
26
27
  const java_recipe_proxy_1 = require("../util/java-recipe-proxy");
27
28
  const module_imports_1 = require("../util/module-imports");
28
29
  const enzyme_to_react_testing_library_1 = require("../testing/enzyme-to-react-testing-library");
30
+ const entry_store_1 = require("./entry-store");
29
31
  const redux_stores_1 = require("./redux-stores");
30
32
  const zustand_plan_1 = require("./zustand-plan");
31
33
  const ZUSTAND = "zustand";
@@ -36,6 +38,12 @@ const ZUSTAND_5 = {
36
38
  const ZUSTAND_4 = Object.assign(Object.assign({}, ZUSTAND_5), { version: "^4.5.7", onlyIfResolving: ["react@>=16.8.0 <18"] });
37
39
  const IMMER_10 = Object.assign(Object.assign({}, ZUSTAND_5), { packageName: IMMER, version: "^10.1.3", onlyIfResolving: ["react@>=16.8.0"] });
38
40
  const LOCKFILE = /(^|\/)(package-lock\.json|npm-shrinkwrap\.json|yarn\.lock|pnpm-lock\.yaml|bun\.lock)$/;
41
+ function resolverOf(scanned) {
42
+ return (from, specifier) => (0, module_imports_1.resolveModule)(from, specifier, scanned.sources, scanned.configs);
43
+ }
44
+ function followsImport(module) {
45
+ return module === zustand_plan_1.REACT_REDUX || module.startsWith(".") || (0, module_imports_1.isAliasSpecifier)(module);
46
+ }
39
47
  class ZustandDependency extends java_recipe_proxy_1.JavaDependencyRecipe {
40
48
  constructor(addition, forecast) {
41
49
  super("org.openrewrite.javascript.AddDependency", addition);
@@ -215,17 +223,19 @@ class ReduxToZustand extends rewrite_1.ScanningRecipe {
215
223
  super(options);
216
224
  this.name = "org.openrewrite.react.migrate.redux-to-zustand";
217
225
  this.displayName = "Migrate Redux Toolkit slices to zustand";
218
- this.description = "Moves a repository's one Redux Toolkit store to zustand when it is a `configureStore` of `createSlice` reducers with no other option, its sources are JavaScript, and every use of it converts: each slice becomes a zustand store whose action creators keep their names and run the slice's reducers through immer's `produce`, `useSelector` reads of one slice become the slice's zustand hook, `dispatch` and `store.dispatch` of the slices' action creators become calls of them, `store.getState()` reads become the slice store's `getState()`, and the react-redux `Provider`, replaced with its children, and the store's source are removed. A slice's own `createAsyncThunk`s, whose stages its `extraReducers` handles, keep running on Redux Toolkit and send their actions to the slice's zustand store. A store of its `reducer` alone whose slices can't move one by one, such as one with a reducer that is no slice's, thunks that reach the rest of the store or dispatches whose result is used, moves whole: its reducer runs on one zustand store whose `dispatch` runs thunks as Redux Toolkit's default middleware does, its selectors run on that store, through a hook of the store's source that keeps each selection per state where zustand 5 would run the selector on each read, and the store keeps its `getState` and `dispatch`, and its `subscribe`, whose listeners its `dispatch` calls after every action as Redux does, where a source subscribes to it. A legacy `createStore` of a reducer, and perhaps a preloaded state, moves whole too, its `dispatch` taking plain actions only, as Redux's does without middleware, or thunks as well where its enhancer is `applyMiddleware(thunk)`, perhaps inside `compose` or Redux DevTools, which is dropped. Components connected with `connect`, with no `mergeProps` and no option but `forwardRef`, move with a store that moves whole: its source declares a `connect` for the zustand store that passes the same props, copies the same statics and skips the same re-renders as react-redux's, and the store batches its updates as react-redux does. Adds `zustand`, and `immer` where slices move one by one, where they are missing. Stores with any other use, such as `connect` with `mergeProps`, other middleware or enhancers, other uses of the store object such as `persistStore(store)`, selectors with their own equality function or several stores, stay in Redux and are recorded for review.";
226
+ this.description = "Moves a repository's one Redux Toolkit store to zustand when it is a `configureStore` of `createSlice` reducers with no other option, its sources are JavaScript, and every use of it converts: each slice becomes a zustand store whose action creators keep their names and run the slice's reducers through immer's `produce`, `useSelector` reads of one slice become the slice's zustand hook, `dispatch` and `store.dispatch` of the slices' action creators become calls of them, `store.getState()` reads become the slice store's `getState()`, and the react-redux `Provider`, replaced with its children, and the store's source are removed. A slice's own `createAsyncThunk`s, whose stages its `extraReducers` handles, keep running on Redux Toolkit and send their actions to the slice's zustand store. A store of its `reducer` alone whose slices can't move one by one, such as one with a reducer that is no slice's, thunks that reach the rest of the store or dispatches whose result is used, moves whole: its reducer runs on one zustand store whose `dispatch` runs thunks as Redux Toolkit's default middleware does, its selectors run on that store, through a hook of the store's source that keeps each selection per state where zustand 5 would run the selector on each read, and the store keeps its `getState` and `dispatch`, and its `subscribe`, whose listeners its `dispatch` calls after every action as Redux does, where a source subscribes to it. A legacy `createStore` of a reducer, and perhaps a preloaded state, moves whole too, its `dispatch` taking plain actions only, as Redux's does without middleware, or thunks as well where its enhancer is `applyMiddleware(thunk)`, perhaps inside `compose` or Redux DevTools, which is dropped. Components connected with `connect`, with no `mergeProps` and no option but `forwardRef`, move with a store that moves whole: its source declares a `connect` for the zustand store that passes the same props, copies the same statics and skips the same re-renders as react-redux's, and the store batches its updates as react-redux does. A store that moves whole but is created, and not exported, at the top level of an application's entry source, such as the one that renders the `Provider`, moves to an `appStore` module beside that source, with the imports and top-level `const`s and `let`s only it uses, and the source imports back what it still uses. A store's source may export it in its declaration, as its default export or in an export list such as `export {store}`, and other sources may import it, and its slices, by relative paths or by aliases such as `@/store` that the `paths` of the nearest `tsconfig.json` or `jsconfig.json` declare. Adds `zustand`, and `immer` where slices move one by one, where they are missing. Stores with any other use, such as `connect` with `mergeProps`, other middleware or enhancers, other uses of the store object such as `persistStore(store)`, selectors with their own equality function or several stores, stay in Redux and are recorded for review.";
219
227
  this.forecast = { refused: new Map(), withoutImmer: new Set() };
220
228
  this.storeSources = [];
221
229
  this.steps = ADDS_DEPENDENCIES ? { zustand: new AddZustand(this.forecast), zustand4: new AddZustand4(this.forecast), immer: new AddImmer(this.forecast) } : undefined;
222
230
  this.stores = new rewrite_1.DataTable(redux_stores_1.REDUX_STORES_TABLE, "Redux stores", "The Redux stores of the repository and whether each one's setup can move to zustand, with one row for each reason it can't.", redux_stores_1.ReduxStoreRow);
231
+ this.reported = new WeakMap();
232
+ this.splits = new WeakMap();
223
233
  this.plans = new WeakMap();
224
234
  (_a = this.wholeStores) !== null && _a !== void 0 ? _a : (this.wholeStores = true);
225
235
  }
226
236
  initialValue() {
227
237
  this.storeSources.length = 0;
228
- return { sources: new Map(), modules: new Map(), sliceSources: new Map(), packages: new Map() };
238
+ return { sources: new Map(), modules: new Map(), sliceSources: new Map(), packages: new Map(), configs: new Map() };
229
239
  }
230
240
  scanner(scanned) {
231
241
  return __awaiter(this, void 0, void 0, function* () {
@@ -261,8 +271,9 @@ class ReduxToZustand extends rewrite_1.ScanningRecipe {
261
271
  if (/(^|\/)package\.json$/.test(doc.sourcePath)) {
262
272
  const declared = (0, javascript_1.findNodeResolutionResult)(doc) ? undefined : yield declaredDependencies(doc);
263
273
  const get = (name) => declared ? declared[name] : version(doc, name);
264
- scanned.packages.set(packageRoot(doc.sourcePath), { react: get("react"), reactDom: get("react-dom"), reactNative: get("react-native"), zustand: get(ZUSTAND), immer: get(IMMER) });
274
+ scanned.packages.set(packageRoot(doc.sourcePath), { react: get("react"), reactDom: get("react-dom"), reactNative: get("react-native"), zustand: get(ZUSTAND), immer: get(IMMER), redux: get("redux"), toolkit: get(redux_stores_1.RTK), reactRedux: get("react-redux") });
265
275
  }
276
+ yield (0, module_imports_1.addPathsConfig)(scanned.configs, doc);
266
277
  return doc;
267
278
  });
268
279
  }
@@ -292,10 +303,13 @@ class ReduxToZustand extends rewrite_1.ScanningRecipe {
292
303
  return cached;
293
304
  }
294
305
  const result = (() => __awaiter(this, void 0, void 0, function* () {
306
+ var _a, _b;
307
+ const splits = yield this.split(scanned);
295
308
  for (const cu of this.storeSources) {
296
- const facts = scanned.sources.get(cu.sourcePath);
309
+ const source = (_b = (_a = splits.get(cu.sourcePath)) === null || _a === void 0 ? void 0 : _a.module) !== null && _b !== void 0 ? _b : cu;
310
+ const facts = scanned.sources.get(source.sourcePath);
297
311
  if (facts)
298
- facts.stores = yield (0, zustand_plan_1.storeFacts)(cu, scanned.modules);
312
+ facts.stores = yield (0, zustand_plan_1.storeFacts)(source, scanned.modules, resolverOf(scanned));
299
313
  }
300
314
  return (0, zustand_plan_1.planPackages)(scanned.sources, scanned.sliceSources, path => packageOf(scanned.packages, path), (storePath, immer) => this.dependencies(scanned, storePath, forecast, immer), this.wholeStores !== false, storePath => {
301
315
  var _a;
@@ -305,13 +319,59 @@ class ReduxToZustand extends rewrite_1.ScanningRecipe {
305
319
  var _a, _b, _c;
306
320
  const facts = scanned.packages.get((_a = packageOf(scanned.packages, storePath)) !== null && _a !== void 0 ? _a : "");
307
321
  return (facts === null || facts === void 0 ? void 0 : facts.zustand) !== undefined ? ((_b = major(facts.zustand)) !== null && _b !== void 0 ? _b : 0) >= 5 : ((_c = major(facts === null || facts === void 0 ? void 0 : facts.react)) !== null && _c !== void 0 ? _c : 0) >= 18;
308
- });
322
+ }, resolverOf(scanned));
309
323
  }))();
310
324
  if (!forecast)
311
325
  this.plans.set(scanned, result);
312
326
  return result;
313
327
  });
314
328
  }
329
+ split(scanned) {
330
+ return __awaiter(this, void 0, void 0, function* () {
331
+ const known = this.splits.get(scanned);
332
+ if (known)
333
+ return known;
334
+ const splits = new Map();
335
+ this.splits.set(scanned, splits);
336
+ const paths = [...scanned.sources.keys()];
337
+ const created = new Map();
338
+ for (const cu of this.storeSources)
339
+ created.set(cu, yield (0, zustand_plan_1.storeFacts)(cu, scanned.modules, resolverOf(scanned)));
340
+ const storesIn = (root) => [...created].filter(([cu]) => packageOf(scanned.packages, cu.sourcePath) === root).reduce((n, [, stores]) => n + stores.length, 0);
341
+ for (const [cu, stores] of created) {
342
+ if (/\.(?:ts|tsx|mts|cts)$/.test(cu.sourcePath) || redux_stores_1.TEST_SOURCE.test(cu.sourcePath))
343
+ continue;
344
+ if (stores.length !== 1 || stores[0].exportedAs || storesIn(packageOf(scanned.packages, cu.sourcePath)) !== 1)
345
+ continue;
346
+ const directory = cu.sourcePath.includes("/") ? cu.sourcePath.slice(0, cu.sourcePath.lastIndexOf("/") + 1) : "";
347
+ const base = directory + entry_store_1.ENTRY_STORE_MODULE;
348
+ if (paths.some(path => path.startsWith(base + ".") || path.startsWith(base + "/")))
349
+ continue;
350
+ const split = yield (0, entry_store_1.splitEntryStore)(cu, stores[0].store, base + ".js", new rewrite_1.ExecutionContext());
351
+ if (!split)
352
+ continue;
353
+ splits.set(cu.sourcePath, Object.assign(Object.assign({}, split), { modulePath: base + ".js" }));
354
+ paths.push(base + ".js");
355
+ for (const source of [split.entry, split.module]) {
356
+ const { reducers, slices } = (0, redux_stores_1.localSlices)(source);
357
+ scanned.modules.set(source.sourcePath, { reducers, slices });
358
+ scanned.sources.set(source.sourcePath, yield (0, zustand_plan_1.sourceFacts)(source));
359
+ const slice = (0, zustand_plan_1.sliceSource)(source);
360
+ if (slice)
361
+ scanned.sliceSources.set(source.sourcePath, slice);
362
+ else
363
+ scanned.sliceSources.delete(source.sourcePath);
364
+ }
365
+ }
366
+ return splits;
367
+ });
368
+ }
369
+ generate(scanned, ctx) {
370
+ return __awaiter(this, void 0, void 0, function* () {
371
+ const plans = yield this.planned(scanned, true);
372
+ return [...(yield this.split(scanned)).values()].filter(split => plans.some(p => { var _a; return ((_a = p.store) === null || _a === void 0 ? void 0 : _a.path) === split.modulePath && p.reducerStore; })).map(split => split.module);
373
+ });
374
+ }
315
375
  dependencies(scanned, storePath, forecast, needsImmer = true) {
316
376
  var _a, _b, _c, _d, _e, _f, _g, _h, _j;
317
377
  const root = packageOf(scanned.packages, storePath);
@@ -323,7 +383,8 @@ class ReduxToZustand extends rewrite_1.ScanningRecipe {
323
383
  return { reason: "REACT_VERSION", detail: (_c = facts.react) !== null && _c !== void 0 ? _c : "react not declared" };
324
384
  const refusal = !forecast ? (_d = this.forecast.refused) === null || _d === void 0 ? void 0 : _d.get(root) : undefined;
325
385
  if (refusal)
326
- return { reason: "DEPENDENCY", detail: `zustand isn't added: ${refusal.message}` };
386
+ return { reason: "DEPENDENCY", detail: `zustand isn't added: ${refusal.message}`,
387
+ action: `The recipe adds \`zustand\` and \`immer\` only where it can write the lockfile the package manager would, which the detail says it can't here: add \`zustand\` ${(react >= 18 ? ZUSTAND_5 : ZUSTAND_4).version} and \`immer\` ${IMMER_10.version} to the package yourself, with its own package manager, and run the recipe again.` };
327
388
  const landed = (step) => { var _a; return forecast || !((_a = this.asked) === null || _a === void 0 ? void 0 : _a.has(root)) && this.asked !== undefined ? !!this.steps : !!(step === null || step === void 0 ? void 0 : step.landed.has(root)); };
328
389
  const zustand = facts.zustand !== undefined ? ((_e = major(facts.zustand)) !== null && _e !== void 0 ? _e : 0) >= (react >= 18 ? 4 : 4) && (react >= 18 || major(facts.zustand) === 4)
329
390
  : landed(react >= 18 ? (_f = this.steps) === null || _f === void 0 ? void 0 : _f.zustand : (_g = this.steps) === null || _g === void 0 ? void 0 : _g.zustand4);
@@ -338,38 +399,45 @@ class ReduxToZustand extends rewrite_1.ScanningRecipe {
338
399
  return __awaiter(this, void 0, void 0, function* () {
339
400
  const recipe = this;
340
401
  const stores = this.stores;
341
- const reported = new Set();
402
+ let reported = this.reported.get(scanned);
403
+ if (!reported)
404
+ this.reported.set(scanned, reported = new Set());
342
405
  return (0, rewrite_2.check)((0, rewrite_2.not)((0, javascript_1.isVendoredOrBundled)()), new class extends javascript_1.JavaScriptVisitor {
343
406
  visitJsCompilationUnit(cu, ctx) {
344
407
  return __awaiter(this, void 0, void 0, function* () {
345
- var _a, _b, _c, _d, _e;
408
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
346
409
  const plans = yield recipe.planned(scanned);
347
410
  const facts = scanned.sources.get(cu.sourcePath);
348
- for (const store of (_a = facts === null || facts === void 0 ? void 0 : facts.stores) !== null && _a !== void 0 ? _a : []) {
411
+ const splits = yield recipe.split(scanned);
412
+ const split = splits.get(cu.sourcePath);
413
+ const entryOf = (path) => { var _a, _b; return (_b = (_a = [...splits].find(([, s]) => s.modulePath === path)) === null || _a === void 0 ? void 0 : _a[0]) !== null && _b !== void 0 ? _b : path; };
414
+ for (const store of [...(_a = facts === null || facts === void 0 ? void 0 : facts.stores) !== null && _a !== void 0 ? _a : [], ...split ? (_c = (_b = scanned.sources.get(split.modulePath)) === null || _b === void 0 ? void 0 : _b.stores) !== null && _c !== void 0 ? _c : [] : []]) {
349
415
  const key = `${store.path}\0${store.store}\0${store.api}`;
350
416
  if (reported.has(key))
351
417
  continue;
352
418
  reported.add(key);
353
- const p = (_b = plans.find(candidate => candidate.store === store)) !== null && _b !== void 0 ? _b : plans.find(candidate => candidate.blocked.has(store));
354
- const findings = (p === null || p === void 0 ? void 0 : p.store) === store ? [] : (_c = p === null || p === void 0 ? void 0 : p.blocked.get(store)) !== null && _c !== void 0 ? _c : store.findings;
419
+ const p = (_d = plans.find(candidate => candidate.store === store)) !== null && _d !== void 0 ? _d : plans.find(candidate => candidate.blocked.has(store));
420
+ const findings = (p === null || p === void 0 ? void 0 : p.store) === store ? [] : (_e = p === null || p === void 0 ? void 0 : p.blocked.get(store)) !== null && _e !== void 0 ? _e : store.findings;
355
421
  const rows = findings.length === 0 ? [{ reason: (p === null || p === void 0 ? void 0 : p.reducerStore) ? "REDUCER_STORE" : "SLICE_STORE", detail: "" }] : findings;
356
- for (const { reason, detail } of rows) {
422
+ for (const { reason, detail, action } of rows) {
357
423
  stores.insertRow(ctx, {
358
- sourcePath: store.path, store: store.store, api: store.api,
424
+ sourcePath: entryOf(store.path), store: store.store, api: store.api,
359
425
  status: (p === null || p === void 0 ? void 0 : p.store) === store ? "CONVERTED" : "REVIEW", reason, detail,
360
- testSource: redux_stores_1.TEST_SOURCE.test(store.path), suggestedAction: (_e = (_d = redux_stores_1.SUGGESTED_ACTIONS[reason]) !== null && _d !== void 0 ? _d : CONVERSION_ACTIONS[reason]) !== null && _e !== void 0 ? _e : ""
426
+ testSource: redux_stores_1.TEST_SOURCE.test(entryOf(store.path)), suggestedAction: (_g = (_f = action !== null && action !== void 0 ? action : redux_stores_1.SUGGESTED_ACTIONS[reason]) !== null && _f !== void 0 ? _f : CONVERSION_ACTIONS[reason]) !== null && _g !== void 0 ? _g : ""
361
427
  });
362
428
  }
363
429
  }
364
430
  const p = plans.find(candidate => candidate.store && candidate.sources.has(cu.sourcePath));
431
+ const generated = [...splits.values()].some(s => s.modulePath === cu.sourcePath);
365
432
  if (!(p === null || p === void 0 ? void 0 : p.store))
366
- return cu;
433
+ return generated ? undefined : cu;
367
434
  if (p.reducerStore)
368
- return cu.sourcePath === p.store.path ? convertReducerStore(cu, p, ctx) : convertReducerConsumer(cu, p, scanned, ctx);
435
+ return cu.sourcePath === p.store.path ? convertReducerStore(cu, p, scanned.packages.get((_h = packageOf(scanned.packages, cu.sourcePath)) !== null && _h !== void 0 ? _h : ""), ctx) : convertReducerConsumer((_j = split === null || split === void 0 ? void 0 : split.entry) !== null && _j !== void 0 ? _j : cu, p, scanned, ctx);
369
436
  if (cu.sourcePath === p.store.path)
370
437
  return undefined;
371
438
  const slice = [...p.slices.values()].find(s => s.path === cu.sourcePath);
372
- const converted = slice ? yield convertSlice(this, cu, slice, scanned, ctx) : cu;
439
+ const source = (_k = split === null || split === void 0 ? void 0 : split.entry) !== null && _k !== void 0 ? _k : cu;
440
+ const converted = slice ? yield convertSlice(this, source, slice, scanned, ctx) : source;
373
441
  return convertConsumer(converted, p, scanned, ctx);
374
442
  });
375
443
  }
@@ -394,7 +462,7 @@ __decorate([
394
462
  ], ReduxToZustand.prototype, "wholeStores", void 0);
395
463
  const CONVERSION_ACTIONS = {
396
464
  MULTIPLE_STORES: "Convert by hand, or one store at a time: the uses of react-redux can't be told apart by store.",
397
- STORE_NOT_MODULE_LEVEL: "Create the store once at the top level of its module; a zustand store is a module-level singleton.",
465
+ STORE_NOT_MODULE_LEVEL: "Create the store once at the top level of its module, and export it; a zustand store is a module-level singleton. A store its source creates at the top level moves to a module of its own where only imports and top-level `const`s and `let`s it uses move with it, nothing that stays uses them, and no `appStore` module is beside the source already.",
398
466
  STORE_SOURCE: "Move what else the store's source declares, such as types or helpers, to another module.",
399
467
  SLICE_SOURCE: "Declare each slice in a source of its own, held in a `const` of its own.",
400
468
  SLICE_KEY: "Use a reducer key that is a JavaScript identifier, which names the zustand hook.",
@@ -607,10 +675,10 @@ function withPrefix(node, prefix) {
607
675
  function convertConsumer(cu, p, scanned, ctx) {
608
676
  return __awaiter(this, void 0, void 0, function* () {
609
677
  const bindings = (0, module_imports_1.importBindings)(cu);
610
- const followed = new Map(bindings.filter(b => b.module === zustand_plan_1.REACT_REDUX || b.module.startsWith(".")).map(b => [b.local, b]));
678
+ const followed = new Map(bindings.filter(b => followsImport(b.module)).map(b => [b.local, b]));
611
679
  const isStore = (name) => {
612
680
  const binding = followed.get(name);
613
- return !!binding && binding.module !== zustand_plan_1.REACT_REDUX && (0, module_imports_1.resolveRelative)(cu.sourcePath, binding.module, scanned.sources) === p.store.path &&
681
+ return !!binding && binding.module !== zustand_plan_1.REACT_REDUX && resolverOf(scanned)(cu.sourcePath, binding.module) === p.store.path &&
614
682
  binding.name === p.store.exportedAs;
615
683
  };
616
684
  const reactRedux = (name, member) => { var _a, _b; return ((_a = followed.get(name)) === null || _a === void 0 ? void 0 : _a.module) === zustand_plan_1.REACT_REDUX && ((_b = followed.get(name)) === null || _b === void 0 ? void 0 : _b.name) === member; };
@@ -773,7 +841,7 @@ function replaceTree(root, target, replacement) {
773
841
  });
774
842
  }
775
843
  function storeStatement(cu, store) {
776
- var _a, _b;
844
+ var _a;
777
845
  const legacy = store.reducerStore === "legacy" || store.reducerStore === "legacyThunk";
778
846
  const functions = (0, redux_stores_1.storeFunctions)(cu);
779
847
  const names = legacy ? functions.legacy : functions.configure;
@@ -794,8 +862,13 @@ function storeStatement(cu, store) {
794
862
  const enhancer = args.length === 3 || args.length === 2 && !preloaded ? (0, redux_stores_1.legacyEnhancer)(args[args.length - 1], cu) : undefined;
795
863
  return { index, call, reducer: Object.assign(Object.assign({}, args[0]), { prefix: java_1.emptySpace }), preloaded: preloaded && Object.assign(Object.assign({}, preloaded), { prefix: java_1.emptySpace }), consts: enhancer && !("unsupported" in enhancer) ? enhancer.consts : new Set() };
796
864
  }
797
- const reducer = (_b = (0, redux_stores_1.objectProperties)((0, zustand_plan_1.argumentsOf)(call)[0])) === null || _b === void 0 ? void 0 : _b.get("reducer");
798
- return reducer ? { index, call, reducer } : undefined;
865
+ const options = (0, redux_stores_1.objectProperties)((0, zustand_plan_1.argumentsOf)(call)[0]);
866
+ const reducer = options === null || options === void 0 ? void 0 : options.get("reducer");
867
+ const effectful = new Set(cu.statements.map(padded => padded.element).filter(s => s.kind === java_1.J.Kind.VariableDeclarations)
868
+ .flatMap(s => s.variables.map(v => v.element))
869
+ .filter(v => (0, java_1.isIdentifier)(v.name) && v.initializer && !(0, redux_stores_1.withoutEffects)(v.initializer.element)).map(v => v.name.simpleName));
870
+ const consts = new Set([...options !== null && options !== void 0 ? options : []].filter(([key]) => key !== "reducer").flatMap(([, value]) => [...(0, javascript_1.namesReferencedWithin)(value)]).filter(name => !effectful.has(name)));
871
+ return reducer ? { index, call, reducer, consts } : undefined;
799
872
  }
800
873
  return undefined;
801
874
  }
@@ -840,7 +913,16 @@ exports.SELECTOR = `export function SELECTOR_HOOK(selector) {
840
913
  };
841
914
  return useSyncExternalStore(HOOK.subscribe, select, select);
842
915
  }`;
843
- exports.CONNECT = `export function connect(mapStateToProps, mapDispatchToProps, mergeProps, options) {
916
+ const STORE_UPDATE_ERROR = {
917
+ swallowed: `if (!update) throw error;`,
918
+ rethrown: `if (update) cache.error = error;
919
+ throw error;`
920
+ };
921
+ function connectSource(hook, reactRedux) {
922
+ var _a;
923
+ return CONNECT.split("HOOK").join(hook).replace("STORE_UPDATE_ERROR", STORE_UPDATE_ERROR[((_a = major(reactRedux)) !== null && _a !== void 0 ? _a : 8) >= 8 ? "swallowed" : "rethrown"]);
924
+ }
925
+ const CONNECT = `export function connect(mapStateToProps, mapDispatchToProps, mergeProps, options) {
844
926
  const forwardsRef = Boolean(options && options.forwardRef);
845
927
  const selectState = mapStateToProps ? state => state : () => undefined;
846
928
  const dependsOnOwnProps = map => map.dependsOnOwnProps !== undefined && map.dependsOnOwnProps !== null ? Boolean(map.dependsOnOwnProps) : map.length !== 1;
@@ -903,17 +985,34 @@ exports.CONNECT = `export function connect(mapStateToProps, mapDispatchToProps,
903
985
  }
904
986
  }
905
987
  const ownProps = cache.ownProps;
906
- if (!cache.stateProps || (mapState && (cache.state !== state || (mapState.dependsOnOwnProps() && cache.stateOwnProps !== ownProps)))) {
907
- cache.stateProps = mapState ? mapState.map(state, ownProps) : {};
988
+ // Own props compare shallowly with those of the last render, whether that render finished or not
989
+ const ownPropsChanged = !cache.seenOwnProps || !shallowEqual(cache.seenOwnProps, ownProps);
990
+ cache.seenOwnProps = ownProps;
991
+ const propsChanged = Boolean(mapState) && mapState.dependsOnOwnProps() && !(cache.stateOwnProps && shallowEqual(cache.stateOwnProps, ownProps));
992
+ if (!cache.stateProps || (mapState && (cache.state !== state || propsChanged))) {
993
+ // The state and props count as mapped before the map runs, so a render React retries after the map
994
+ // throws keeps the props from before
995
+ const update = cache.stateProps !== undefined && cache.state !== state && !propsChanged;
908
996
  cache.state = state;
909
997
  cache.stateOwnProps = ownProps;
998
+ cache.error = undefined;
999
+ try {
1000
+ cache.stateProps = mapState ? mapState.map(state, ownProps) : {};
1001
+ cache.kept = false;
1002
+ } catch (error) {
1003
+ // The props passed last stay, own props too, until the map returns again
1004
+ cache.kept = true;
1005
+ STORE_UPDATE_ERROR
1006
+ }
1007
+ } else if (cache.error) {
1008
+ throw cache.error;
910
1009
  }
911
1010
  if (!cache.dispatchProps || (mapDispatch && mapDispatch.dependsOnOwnProps() && cache.dispatchOwnProps !== ownProps)) {
912
1011
  cache.dispatchProps = mapDispatch ? mapDispatch.map(HOOK.dispatch, ownProps) : mapDispatchToProps ? bound(mapDispatchToProps) : {dispatch: HOOK.dispatch};
913
1012
  cache.dispatchOwnProps = ownProps;
914
1013
  }
915
1014
  const merged = {...ownProps, ...cache.stateProps, ...cache.dispatchProps};
916
- if (!cache.merged || !shallowEqual(cache.merged, merged)) cache.merged = merged;
1015
+ if (!cache.merged || (!cache.kept || ownPropsChanged) && !shallowEqual(cache.merged, merged)) cache.merged = merged;
917
1016
  if (!cache.element || cache.rendered !== cache.merged || cache.ref !== props.reactReduxForwardedRef) {
918
1017
  cache.rendered = cache.merged;
919
1018
  cache.ref = props.reactReduxForwardedRef;
@@ -932,7 +1031,14 @@ exports.CONNECT = `export function connect(mapStateToProps, mapDispatchToProps,
932
1031
  return hoistStatics(Forwarded, WrappedComponent);
933
1032
  };
934
1033
  }`;
935
- function convertReducerStore(cu, p, ctx) {
1034
+ function typedByString(facts, fromToolkit) {
1035
+ var _a;
1036
+ const redux = fromToolkit ? undefined : major(facts === null || facts === void 0 ? void 0 : facts.redux);
1037
+ if (redux !== undefined)
1038
+ return redux >= 5;
1039
+ return ((_a = major(facts === null || facts === void 0 ? void 0 : facts.toolkit)) !== null && _a !== void 0 ? _a : 0) >= 2;
1040
+ }
1041
+ function convertReducerStore(cu, p, facts, ctx) {
936
1042
  return __awaiter(this, void 0, void 0, function* () {
937
1043
  var _a;
938
1044
  const store = p.store;
@@ -946,6 +1052,9 @@ function convertReducerStore(cu, p, ctx) {
946
1052
  const combined = store.reducerStore === "combined";
947
1053
  const legacy = store.reducerStore === "legacy" || store.reducerStore === "legacyThunk";
948
1054
  const thunk = store.reducerStore === "legacyThunk";
1055
+ const checks = `if (typeof action !== "object" || action === null || ![Object.prototype, null].includes(Object.getPrototypeOf(action))) throw new Error("Actions must be plain objects.");
1056
+ if (action.type === undefined) throw new Error("Actions may not have an undefined 'type' property.");` +
1057
+ (typedByString(facts, (0, redux_stores_1.importedAs)(cu, redux_stores_1.RTK, "configureStore", "createStore", "legacy_createStore").has(store.api)) ? `\n if (typeof action.type !== "string") throw new Error("Action 'type' property must be a string.");` : "");
949
1058
  const update = `${hook}.setState(${reducer}(${hook}.getState(), action), true);`;
950
1059
  const notified = listeners ? `${update}\n for (const listener of [...${listeners}.values()]) listener();` : update;
951
1060
  const setState = renderer ? listeners ? `unstable_batchedUpdates(() => {\n ${notified}\n });` : `unstable_batchedUpdates(() => ${update.slice(0, -1)});` : notified;
@@ -964,23 +1073,15 @@ function convertReducerStore(cu, p, ctx) {
964
1073
  yield (0, javascript_1.template) `export const ${(0, javascript_1.raw)(hook)} = create(() => ${(0, javascript_1.raw)(reducer)}(${found.preloaded}, {type: "@@redux/INIT"}));`.apply(statement, cursor) :
965
1074
  yield (0, javascript_1.template) `export const ${(0, javascript_1.raw)(hook)} = create(() => ${(0, javascript_1.raw)(reducer)}(undefined, {type: "@@redux/INIT"}));`.apply(statement, cursor),
966
1075
  ...listeners ? [yield (0, javascript_1.template) `const ${(0, javascript_1.raw)(listeners)} = new Map();`.apply(statement, cursor)] : [],
967
- thunk ?
1076
+ legacy && !thunk ?
968
1077
  yield (0, javascript_1.template) `${(0, javascript_1.raw)(hook)}.dispatch = action => {
969
- if (typeof action === "function") return action(${(0, javascript_1.raw)(hook)}.dispatch, ${(0, javascript_1.raw)(hook)}.getState, undefined);
970
- if (typeof action !== "object" || action === null || ![Object.prototype, null].includes(Object.getPrototypeOf(action))) throw new Error("Actions must be plain objects.");
971
- if (action.type === undefined) throw new Error("Actions may not have an undefined 'type' property.");
1078
+ ${(0, javascript_1.raw)(checks)}
972
1079
  ${(0, javascript_1.raw)(setState)}
973
1080
  return action;
974
1081
  };`.apply(statement, cursor) :
975
- legacy ?
976
- yield (0, javascript_1.template) `${(0, javascript_1.raw)(hook)}.dispatch = action => {
977
- if (typeof action !== "object" || action === null || ![Object.prototype, null].includes(Object.getPrototypeOf(action))) throw new Error("Actions must be plain objects.");
978
- if (action.type === undefined) throw new Error("Actions may not have an undefined 'type' property.");
979
- ${(0, javascript_1.raw)(setState)}
980
- return action;
981
- };`.apply(statement, cursor) :
982
- yield (0, javascript_1.template) `${(0, javascript_1.raw)(hook)}.dispatch = action => {
1082
+ yield (0, javascript_1.template) `${(0, javascript_1.raw)(hook)}.dispatch = action => {
983
1083
  if (typeof action === "function") return action(${(0, javascript_1.raw)(hook)}.dispatch, ${(0, javascript_1.raw)(hook)}.getState, undefined);
1084
+ ${(0, javascript_1.raw)(checks)}
984
1085
  ${(0, javascript_1.raw)(setState)}
985
1086
  return action;
986
1087
  };`.apply(statement, cursor),
@@ -988,7 +1089,7 @@ function convertReducerStore(cu, p, ctx) {
988
1089
  yield (0, javascript_1.template) `export default {${(0, javascript_1.raw)(members)}};`.apply(statement, cursor) :
989
1090
  yield (0, javascript_1.template) `${(0, javascript_1.raw)(statement.modifiers.some(m => m.keyword === "export") ? "export " : "")}const ${(0, javascript_1.raw)(store.store)} = {${(0, javascript_1.raw)(members)}};`.apply(statement, cursor),
990
1091
  ...selectorHook ? [yield (0, javascript_1.template) `${(0, javascript_1.raw)(exports.SELECTOR.split("SELECTOR_HOOK").join(selectorHook).split("HOOK").join(hook))}`.apply(statement, cursor)] : [],
991
- ...renderer ? [yield (0, javascript_1.template) `${(0, javascript_1.raw)(exports.CONNECT.split("HOOK").join(hook))}`.apply(statement, cursor)] : []
1092
+ ...renderer ? [yield (0, javascript_1.template) `${(0, javascript_1.raw)(connectSource(hook, facts === null || facts === void 0 ? void 0 : facts.reactRedux))}`.apply(statement, cursor)] : []
992
1093
  ];
993
1094
  const statements = [...cu.statements.slice(0, found.index)];
994
1095
  for (let i = 0; i < generated.length; i++) {
@@ -1051,9 +1152,9 @@ function convertReducerConsumer(cu, p, scanned, ctx) {
1051
1152
  const { hook, selectorHook } = p.reducerStore;
1052
1153
  const source = scanned.sources.get(cu.sourcePath);
1053
1154
  const reads = (selector) => !!(0, zustand_plan_1.selectorRead)(selector) ||
1054
- (0, java_1.isIdentifier)(selector) && !!source && (0, zustand_plan_1.readSelector)(source, selector.simpleName, scanned.sources);
1155
+ (0, java_1.isIdentifier)(selector) && !!source && (0, zustand_plan_1.readSelector)(source, selector.simpleName, scanned.sources, resolverOf(scanned));
1055
1156
  const bindings = (0, module_imports_1.importBindings)(cu);
1056
- const followed = new Map(bindings.filter(b => b.module === zustand_plan_1.REACT_REDUX || b.module.startsWith(".")).map(b => [b.local, b]));
1157
+ const followed = new Map(bindings.filter(b => followsImport(b.module)).map(b => [b.local, b]));
1057
1158
  const reactRedux = (name, member) => { var _a, _b; return ((_a = followed.get(name)) === null || _a === void 0 ? void 0 : _a.module) === zustand_plan_1.REACT_REDUX && ((_b = followed.get(name)) === null || _b === void 0 ? void 0 : _b.name) === member; };
1058
1159
  const removed = new Set();
1059
1160
  const uses = new Set();
@@ -1129,7 +1230,7 @@ function convertReducerConsumer(cu, p, scanned, ctx) {
1129
1230
  }
1130
1231
  if (removed.has("Provider")) {
1131
1232
  for (const binding of bindings) {
1132
- if (binding.module !== zustand_plan_1.REACT_REDUX && (0, module_imports_1.resolveRelative)(cu.sourcePath, binding.module, scanned.sources) === p.store.path)
1233
+ if (binding.module !== zustand_plan_1.REACT_REDUX && resolverOf(scanned)(cu.sourcePath, binding.module) === p.store.path)
1133
1234
  (0, javascript_1.maybeRemoveImport)(this, binding.module, binding.name);
1134
1235
  }
1135
1236
  }