@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
@@ -10,6 +10,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.hookName = exports.REDUCER_STORE_HOOK = exports.STORE_LISTENERS = exports.SELECTOR_HOOK = exports.STORE_MEMBERS = exports.REACT_REDUX = void 0;
13
+ exports.storeValueAction = storeValueAction;
14
+ exports.connectAction = connectAction;
13
15
  exports.parentTree = parentTree;
14
16
  exports.isStatement = isStatement;
15
17
  exports.isReactDependencies = isReactDependencies;
@@ -39,6 +41,108 @@ const path_1 = require("path");
39
41
  const module_imports_1 = require("../util/module-imports");
40
42
  const redux_stores_1 = require("./redux-stores");
41
43
  exports.REACT_REDUX = "react-redux";
44
+ function storeValueUse(identifier, cursor, persistStore) {
45
+ var _a, _b;
46
+ const trees = ancestors(cursor);
47
+ if (trees.some(tree => tree.kind === javascript_1.JS.Kind.TypeQuery))
48
+ return { kind: "type" };
49
+ const parent = parentTree(cursor);
50
+ if ((parent === null || parent === void 0 ? void 0 : parent.kind) === java_1.J.Kind.MethodInvocation) {
51
+ const call = parent;
52
+ if (((_a = call.select) === null || _a === void 0 ? void 0 : _a.element) === identifier)
53
+ return { kind: "method", name: call.name.simpleName };
54
+ if (argumentsOf(call).includes(identifier)) {
55
+ if (!call.select && persistStore.has(call.name.simpleName))
56
+ return { kind: "persist" };
57
+ const select = call.select && (0, java_1.isIdentifier)(call.select.element) ? `${call.select.element.simpleName}.` : "";
58
+ return { kind: "passed", name: select + call.name.simpleName };
59
+ }
60
+ }
61
+ if ((parent === null || parent === void 0 ? void 0 : parent.kind) === java_1.J.Kind.FieldAccess && parent.target === identifier && exports.STORE_MEMBERS.has(parent.name.element.simpleName)) {
62
+ return { kind: "member", name: parent.name.element.simpleName };
63
+ }
64
+ if ((parent === null || parent === void 0 ? void 0 : parent.kind) === javascript_1.JS.Kind.JsxEmbeddedExpression && ((_b = trees[2]) === null || _b === void 0 ? void 0 : _b.kind) === javascript_1.JS.Kind.JsxAttribute && (0, java_1.isIdentifier)(trees[2].key) &&
65
+ trees[2].key.simpleName === "store")
66
+ return { kind: "provider" };
67
+ return { kind: "other" };
68
+ }
69
+ const MEMBER_CALLS = { getState: "() => STORE.getState()", dispatch: "action => STORE.dispatch(action)", subscribe: "listener => STORE.subscribe(listener)" };
70
+ function storeValueAction(store, uses) {
71
+ if (uses.some(use => use.kind === "persist"))
72
+ return `\`${store}\` is passed to redux-persist's \`persistStore\`, and redux-persist persists a Redux store: convert the store by hand, with zustand's \`persist\` middleware in place of redux-persist.`;
73
+ const first = (kind) => uses.find(use => use.kind === kind);
74
+ const actions = [];
75
+ if (first("type"))
76
+ actions.push(`\`typeof ${store}\` types, such as \`ReturnType<typeof ${store}.getState>\`, go with the TypeScript sources, which aren't converted yet.`);
77
+ const passed = first("passed");
78
+ if (passed && /(^|\.)spyOn$/.test(passed.name))
79
+ actions.push(`\`${passed.name}(${store}, ...)\` spies on a member of the Redux store, which the conversion replaces: check what the test spies for another way, such as by the state after the dispatch, or convert the test by hand.`);
80
+ else if (passed)
81
+ actions.push(`\`${store}\` is passed to \`${passed.name}\`, which the recipe doesn't follow: pass the calls it makes instead, such as \`() => ${store}.getState()\` and \`action => ${store}.dispatch(action)\`, so that the recipe checks each call, or convert by hand.`);
82
+ const member = first("member");
83
+ if (member)
84
+ actions.push(`Call \`${store}.${member.name}\` rather than pass it, as \`${MEMBER_CALLS[member.name].replace("STORE", store)}\`, so that the recipe checks each call.`);
85
+ const method = first("method");
86
+ if (method)
87
+ actions.push(`The zustand store has no \`${method.name}\`: remove \`${store}.${method.name}(...)\`, or convert by hand.`);
88
+ if (first("provider"))
89
+ actions.push(`Render \`<Provider store={${store}}>\` in a module that imports the store, not in the store's own source.`);
90
+ return actions.length > 0 ? actions.join(" ") : undefined;
91
+ }
92
+ const REACT_REDUX_VALUE_ACTIONS = {
93
+ shallowEqual: "zustand's hooks take no equality function. Where `shallowEqual` is `useSelector`'s second argument, select one value in each `useSelector` and drop it, or write the selector with zustand's `useShallow` by hand.",
94
+ TypedUseSelectorHook: "A react-redux type goes with the TypeScript sources, which aren't converted yet.",
95
+ ConnectedProps: "A react-redux type goes with the TypeScript sources, which aren't converted yet.",
96
+ ResolveThunks: "A react-redux type goes with the TypeScript sources, which aren't converted yet."
97
+ };
98
+ const REACT_REDUX_CALL_ACTIONS = {
99
+ batch: "zustand has no `batch`: on React 18, which batches updates itself, call the callback directly; before React 18, wrap it in `unstable_batchedUpdates` of react-dom.",
100
+ useStore: "Read the state with `useSelector` and dispatch with `useDispatch` instead of `useStore()`, or convert by hand."
101
+ };
102
+ function selectorAction(args, typed) {
103
+ if (typed)
104
+ return "A `useSelector` with type arguments goes with the TypeScript sources, which aren't converted yet.";
105
+ if (args !== 1)
106
+ return "Pass `useSelector` the selector alone: zustand's hooks take no equality function. Select one value in each `useSelector`, so that none needs one, or convert by hand.";
107
+ return "Read one slice's state in each selector, such as `state => state.counter.value`, or a top-level `const` selector that does, so that the slice's zustand hook can take it.";
108
+ }
109
+ const UNREAD_SLICES = "The store's slices aren't read while its own rows, such as MIDDLEWARE or ROOT_REDUCER, hold it back, so this use is recorded without being checked: remove what those rows name, and run the recipe again.";
110
+ function sliceDispatchAction(binding, fromSlice) {
111
+ return fromSlice ?
112
+ `\`${binding.name}\` of ${binding.module} is neither one of its slice's action creators nor a \`createAsyncThunk\` the recipe reads, such as a thunk written as \`() => async dispatch => ...\`: declare it with \`createAsyncThunk\` in that source, or export it from \`slice.actions\`, or convert by hand.` :
113
+ `\`${binding.name}\` comes from ${binding.module}, which declares none of the store's slices, such as a module of hand-written action creators or thunks: write it as a reducer of a \`createSlice\`, or as a \`createAsyncThunk\` in a slice's source, and import it from there, or convert by hand.`;
114
+ }
115
+ function connectAction(wholeStores) {
116
+ return wholeStores ?
117
+ "`connect` converts only where the store moves whole, which takes a `configureStore` of `reducer` alone, or a `createStore` of a reducer with at most a preloaded state, `applyMiddleware(thunk)` and Redux DevTools. Remove what the store's other rows name so it moves whole, or replace `connect` with `useSelector` and `useDispatch`." :
118
+ "`connect` converts only where the store moves whole, which `wholeStores` turns off: run with it on, or replace `connect` with `useSelector` and `useDispatch`.";
119
+ }
120
+ function storeExportAction(binding, source, store, storeModule, wholeStores) {
121
+ const name = binding.name === "default" ? binding.local : binding.name;
122
+ if (/^use[A-Z]/.test(name))
123
+ return `\`${name}\` comes from the store's source, which the conversion removes; most often it is a typed alias of a react-redux hook, such as \`useSelector.withTypes<RootState>()\`: call the hook itself where \`${name}\` is called and remove the alias, or convert by hand.`;
124
+ if (/^[A-Z]/.test(name) && source.typescript)
125
+ return `\`${name}\` comes from the store's source, which the conversion removes; most often it is a type of the store, such as \`ReturnType<typeof store.getState>\`, which goes with the TypeScript sources, which aren't converted yet.`;
126
+ if (/persist/i.test(name) && (storeModule === null || storeModule === void 0 ? void 0 : storeModule.bindings.some(b => b.module === "redux-persist")))
127
+ return `\`${name}\` comes from the store's source, and redux-persist persists a Redux store: convert the store by hand, with zustand's \`persist\` middleware in place of redux-persist.`;
128
+ if (!store.exportedAs && (name === store.store || /store/i.test(name)))
129
+ return `The store isn't created at its module's top level, so \`${name}\` is no store the recipe follows: create one store with \`export const store = configureStore(...)\`, and import that in place of \`${name}\`, or convert by hand.`;
130
+ return `\`${name}\` comes from the store's source, ${store.path}, which the conversion removes: move \`${name}\` to a module of its own and import it from there, or convert by hand.` +
131
+ (wholeStores && store.exportedAs ? ` Or remove what the store's other rows name, so that it moves whole and its source keeps \`${name}\`.` : "");
132
+ }
133
+ function multipleStoresAction(store, stores, facts) {
134
+ const app = stores.filter(s => { var _a; return !((_a = facts.get(s.path)) === null || _a === void 0 ? void 0 : _a.test); });
135
+ const why = "the recipe converts a package of one store, as react-redux's hooks don't say which store they read";
136
+ if (app.length === 0)
137
+ return `All ${stores.length} of the package's stores are created in test, mock or story sources: ${why}. Convert by hand.`;
138
+ if (app.length === 1) {
139
+ const one = app[0] === store ? "this store" : `its one other store, \`${app[0].store}\` of ${app[0].path}`;
140
+ return `${stores.length - 1} of the package's ${stores.length} stores ${stores.length === 2 ? "is" : "are"} created in test, mock or story sources, which hold back ${one}: ${why}. Convert by hand.`;
141
+ }
142
+ const paths = [...new Set(app.map(s => s.path))];
143
+ const named = paths.length > 3 ? `${paths.slice(0, 3).join(", ")} and ${paths.length - 3} more` : paths.join(", ");
144
+ return `The package creates ${app.length} stores outside tests, in ${named}: ${why}. Move each store, with the sources that use it, to a package of its own, or convert by hand.`;
145
+ }
42
146
  function parentTree(cursor) {
43
147
  for (let c = cursor.parent; c; c = c.parent) {
44
148
  const value = c.value;
@@ -214,8 +318,9 @@ function sourceFacts(cu) {
214
318
  path: cu.sourcePath, typescript: /\.(?:ts|tsx|mts|cts)$/.test(cu.sourcePath), test: redux_stores_1.TEST_SOURCE.test(cu.sourcePath),
215
319
  bindings, declared: new Set(declared.keys()), uses: [], unfollowed: [], stores: [], readSelectors: readSelectors(cu, declared)
216
320
  };
217
- const followed = new Map(bindings.filter(binding => binding.module === exports.REACT_REDUX || (0, module_imports_1.isRelativeSpecifier)(binding.module))
321
+ const followed = new Map(bindings.filter(binding => binding.module === exports.REACT_REDUX || (0, module_imports_1.isRelativeSpecifier)(binding.module) || (0, module_imports_1.isAliasSpecifier)(binding.module))
218
322
  .map(binding => [binding.local, binding]));
323
+ const persistStore = new Set(bindings.filter(b => b.module === "redux-persist" && b.name === "persistStore").map(b => b.local));
219
324
  for (const { element } of cu.statements) {
220
325
  if (element.kind === javascript_1.JS.Kind.Import) {
221
326
  const imp = element;
@@ -257,7 +362,7 @@ function sourceFacts(cu) {
257
362
  facts.uses.push(use);
258
363
  }
259
364
  if (binding) {
260
- const use = classify(identifier, binding, this.cursor, followed, dispatchers, declared);
365
+ const use = classify(identifier, binding, this.cursor, followed, dispatchers, declared, persistStore);
261
366
  if (use)
262
367
  facts.uses.push(use);
263
368
  }
@@ -278,7 +383,7 @@ function sourceFacts(cu) {
278
383
  return facts;
279
384
  });
280
385
  }
281
- function storeFacts(cu, modules) {
386
+ function storeFacts(cu, modules, resolve) {
282
387
  return __awaiter(this, void 0, void 0, function* () {
283
388
  const stores = [];
284
389
  const functions = (0, redux_stores_1.storeFunctions)(cu);
@@ -290,12 +395,12 @@ function storeFacts(cu, modules) {
290
395
  visitMethodInvocation: { get: () => super.visitMethodInvocation }
291
396
  });
292
397
  return __awaiter(this, void 0, void 0, function* () {
293
- const store = (0, redux_stores_1.storeFindings)(call, cu, modules, functions);
398
+ const store = (0, redux_stores_1.storeFindings)(call, cu, modules, functions, resolve);
294
399
  if (store) {
295
400
  const name = storeNameAt(this.cursor);
296
401
  const own = yield usesInSource(cu, name, call);
297
402
  stores.push({ path: cu.sourcePath, api: store.api, store: name, findings: store.findings,
298
- slices: store.slices, exportedAs: exportedStore(cu, this.cursor), reducerStore: store.reducerStore, usedInSource: own.other, calledInSource: own.called });
403
+ slices: store.slices, exportedAs: exportedStore(cu, this.cursor), reducerStore: store.reducerStore, usedInSource: own.other, usesInSource: own.uses, calledInSource: own.called });
299
404
  }
300
405
  return _super.visitMethodInvocation.call(this, call, ctx);
301
406
  });
@@ -335,14 +440,14 @@ function dispatcherCount(cu, followed, name) {
335
440
  });
336
441
  return count;
337
442
  }
338
- function classify(identifier, binding, cursor, followed, dispatchers, declared) {
339
- var _a, _b, _c;
443
+ function classify(identifier, binding, cursor, followed, dispatchers, declared, persistStore) {
444
+ var _a, _b, _c, _d, _e;
340
445
  const trees = ancestors(cursor);
341
446
  if (trees.some(tree => tree.kind === javascript_1.JS.Kind.Import))
342
447
  return undefined;
343
448
  const parent = parentTree(cursor);
344
449
  const local = identifier.simpleName;
345
- const other = (detail) => ({ local, kind: "other", detail });
450
+ const other = (detail, action) => (Object.assign({ local, kind: "other", detail }, action ? { action } : {}));
346
451
  if ((parent === null || parent === void 0 ? void 0 : parent.kind) === java_1.J.Kind.FieldAccess && parent.name.element === identifier)
347
452
  return undefined;
348
453
  if ((parent === null || parent === void 0 ? void 0 : parent.kind) === java_1.J.Kind.MethodInvocation && parent.name === identifier && parent.select)
@@ -366,24 +471,26 @@ function classify(identifier, binding, cursor, followed, dispatchers, declared)
366
471
  }
367
472
  if (binding.module === exports.REACT_REDUX) {
368
473
  if ((parent === null || parent === void 0 ? void 0 : parent.kind) !== java_1.J.Kind.MethodInvocation || parent.name !== identifier)
369
- return other(`\`${binding.name}\` from react-redux`);
474
+ return other(`\`${binding.name}\` from react-redux`, (_b = REACT_REDUX_VALUE_ACTIONS[binding.name]) !== null && _b !== void 0 ? _b : (binding.name.startsWith("use") ?
475
+ `\`${binding.name}\` is used other than called, most often in a typed alias such as \`const useApp${binding.name.slice(3)} = ${binding.name}\` or \`${binding.name}.withTypes<RootState>()\`, which the recipe doesn't follow: call \`${binding.name}\` itself where the alias is called and remove the alias, or convert by hand.` :
476
+ `\`${binding.name}\` is used other than called, such as passed or re-exported: call it where it's used, so the recipe follows each call, or convert by hand.`));
370
477
  const call = parent;
371
478
  if (binding.name === "connect")
372
- return (_b = connectUse(call, other)) !== null && _b !== void 0 ? _b : { local, kind: "connect" };
479
+ return (_c = connectUse(call, other)) !== null && _c !== void 0 ? _c : { local, kind: "connect" };
373
480
  if (binding.name === "useSelector") {
374
481
  const args = argumentsOf(call);
375
482
  const read = args.length === 1 && !call.typeParameters ? selectorRead(args[0]) : undefined;
376
483
  if (read)
377
484
  return { local, kind: "selector", key: read.key };
378
485
  const selector = args.length === 1 && !call.typeParameters && (0, java_1.isIdentifier)(args[0]) ? args[0].simpleName : undefined;
379
- return Object.assign(Object.assign({}, other("a selector that isn't a read of one slice's state")), { reason: "SELECTOR", selector, anySelector: args.length === 1 && !call.typeParameters });
486
+ return Object.assign(Object.assign({}, other("a selector that isn't a read of one slice's state", selectorAction(args.length, Boolean(call.typeParameters)))), { reason: "SELECTOR", selector, anySelector: args.length === 1 && !call.typeParameters });
380
487
  }
381
488
  if (binding.name === "useDispatch") {
382
489
  const variable = parentTree(cursorOf(cursor, call));
383
490
  return (variable === null || variable === void 0 ? void 0 : variable.kind) === java_1.J.Kind.NamedVariable && dispatchers.has(variable.name.simpleName)
384
- ? { local, kind: "dispatcher" } : other("`useDispatch` not held in a variable of its own");
491
+ ? { local, kind: "dispatcher" } : other("`useDispatch` not held in a variable of its own", "Hold the dispatcher in a `const` of its own, such as `const dispatch = useDispatch()`, and dispatch through it.");
385
492
  }
386
- return other(`\`${binding.name}\` from react-redux`);
493
+ return other(`\`${binding.name}\` from react-redux`, (_d = REACT_REDUX_CALL_ACTIONS[binding.name]) !== null && _d !== void 0 ? _d : `The recipe converts only \`connect\`, \`useSelector\`, \`useDispatch\` and \`<Provider>\` of react-redux: replace \`${binding.name}(...)\` by hand.`);
387
494
  }
388
495
  if ((parent === null || parent === void 0 ? void 0 : parent.kind) === java_1.J.Kind.MethodInvocation && parent.name === identifier) {
389
496
  const action = parent;
@@ -399,7 +506,7 @@ function classify(identifier, binding, cursor, followed, dispatchers, declared)
399
506
  return Object.assign(Object.assign({}, other("the dispatch's result is used")), { reason: "DISPATCH" });
400
507
  return { local, kind: "dispatched", via };
401
508
  }
402
- if ((parent === null || parent === void 0 ? void 0 : parent.kind) === java_1.J.Kind.MethodInvocation && ((_c = parent.select) === null || _c === void 0 ? void 0 : _c.element) === identifier) {
509
+ if ((parent === null || parent === void 0 ? void 0 : parent.kind) === java_1.J.Kind.MethodInvocation && ((_e = parent.select) === null || _e === void 0 ? void 0 : _e.element) === identifier) {
403
510
  const call = parent;
404
511
  const outer = parentTree(cursorOf(cursor, call));
405
512
  const read = getStateRead(call, outer);
@@ -409,7 +516,10 @@ function classify(identifier, binding, cursor, followed, dispatchers, declared)
409
516
  if (member === "dispatch" && dispatchedAction(call)) {
410
517
  return isStatement(call, outer) ? { local, kind: "storeDispatch", member } : Object.assign(Object.assign({}, other("the dispatch's result is used")), { reason: "DISPATCH", member });
411
518
  }
412
- return Object.assign(Object.assign({}, other(`\`${local}.${member}\``)), { member });
519
+ const action = member === "getState" ? `Read one slice's state in each call, such as \`${local}.getState().counter\`, rather than the whole state, or convert by hand.` :
520
+ member === "dispatch" ? unimportedDispatchAction(call, undefined, `${local}.dispatch`) :
521
+ member === "subscribe" ? `\`${local}.subscribe\` converts only where the store moves whole: remove what the store's other rows name, or convert by hand.` : undefined;
522
+ return Object.assign(Object.assign({}, other(`\`${local}.${member}\``, action)), { member });
413
523
  }
414
524
  if ((parent === null || parent === void 0 ? void 0 : parent.kind) === javascript_1.JS.Kind.JsxEmbeddedExpression) {
415
525
  const attribute = trees[2];
@@ -422,7 +532,8 @@ function classify(identifier, binding, cursor, followed, dispatchers, declared)
422
532
  return { local, kind: "provider" };
423
533
  }
424
534
  }
425
- return other("referenced");
535
+ const valueUse = storeValueUse(identifier, cursor, persistStore);
536
+ return Object.assign(Object.assign({}, other("referenced")), { valueUse: valueUse.kind === "provider" ? { kind: "other" } : valueUse });
426
537
  }
427
538
  function connectUse(call, other) {
428
539
  const args = argumentsOf(call);
@@ -430,16 +541,30 @@ function connectUse(call, other) {
430
541
  node.kind === java_1.J.Kind.Literal && node.valueSource === "null" ||
431
542
  (0, java_1.isIdentifier)(node) && node.simpleName === "undefined";
432
543
  if (args.length > 4 || !absent(args[2]))
433
- return other("`connect` with `mergeProps`");
544
+ return other("`connect` with `mergeProps`", "Merge the props in the wrapped component rather than with `mergeProps`, or convert by hand.");
434
545
  if (args.length === 4 && !absent(args[3])) {
435
546
  const options = (0, redux_stores_1.objectProperties)(args[3]);
436
547
  const forwardRef = options === null || options === void 0 ? void 0 : options.get("forwardRef");
437
548
  if (!options || options.size !== 1 || (forwardRef === null || forwardRef === void 0 ? void 0 : forwardRef.kind) !== java_1.J.Kind.Literal || typeof forwardRef.value !== "boolean") {
438
- return other("`connect` with options other than `forwardRef`");
549
+ return other("`connect` with options other than `forwardRef`", "Pass `connect` no options, or only `{forwardRef: true}` or `{forwardRef: false}`; others, such as `context`, `areStatesEqual` or `pure`, are converted by hand.");
439
550
  }
440
551
  }
441
552
  return undefined;
442
553
  }
554
+ function unimportedDispatchAction(dispatch, action, name = dispatch.name.simpleName) {
555
+ const [arg] = argumentsOf(dispatch);
556
+ if (action) {
557
+ return `\`${action.name.simpleName}\` isn't imported: import the action creator from the slice's source that declares it, and dispatch \`${name}(${action.name.simpleName}(...))\`, or convert by hand.`;
558
+ }
559
+ if ((arg === null || arg === void 0 ? void 0 : arg.kind) === java_1.J.Kind.MethodInvocation && arg.select) {
560
+ const member = arg.name.simpleName;
561
+ return `Import \`${member}\` by name from the slice's source, as \`export const {${member}} = slice.actions\` exports it, and dispatch \`${name}(${member}(...))\` rather than a member call such as \`actions.${member}(...)\`, or convert by hand.`;
562
+ }
563
+ if ((0, redux_stores_1.objectProperties)(arg)) {
564
+ return `An action object such as \`${name}({type: ...})\` has no zustand equivalent: dispatch a call of a slice's action creator for the same type, \`${name}(x(...))\`, or convert by hand.`;
565
+ }
566
+ return `Dispatch a call of an imported action creator in place, \`${name}(x(...))\`, rather than an action held in a variable or chosen by a condition, or convert by hand.`;
567
+ }
443
568
  function dispatcherUse(identifier, cursor, followed, bindings) {
444
569
  const parent = parentTree(cursor);
445
570
  const local = identifier.simpleName;
@@ -455,23 +580,27 @@ function dispatcherUse(identifier, cursor, followed, bindings) {
455
580
  const binding = action && followed.get(action.name.simpleName);
456
581
  if (binding && binding.module !== exports.REACT_REDUX)
457
582
  return undefined;
458
- return { local, kind: "other", detail: "dispatches what isn't an imported action creator", reason: "DISPATCH" };
583
+ return { local, kind: "other", detail: "dispatches what isn't an imported action creator", reason: "DISPATCH", action: unimportedDispatchAction(call, action) };
459
584
  }
460
585
  return { local, kind: "other", detail: "the dispatcher is used other than to dispatch", reason: "DISPATCH" };
461
586
  }
587
+ const PROVIDER_OTHER_STORE = "`Provider` gets something other than the store this package creates: pass it that store, under the name its source exports, or convert by hand.";
588
+ const PROVIDER_NOT_IMPORTED = "`Provider` gets a store that isn't imported, such as one made in this source, passed in, or held in a ref or `this`. " +
589
+ "A zustand store is one per module: pass `Provider` the store imported from the module that creates it at its top level, or convert by hand.";
462
590
  function providerUse(tag, followed, local) {
463
591
  var _a;
464
- const other = (detail) => ({ local, kind: "other", detail });
592
+ const other = (detail, action) => (Object.assign({ local, kind: "other", detail }, action ? { action } : {}));
465
593
  const attributes = tag.attributes.map(a => a.element);
466
- if (attributes.length !== 1 || attributes[0].kind !== javascript_1.JS.Kind.JsxAttribute)
467
- return other("`Provider` with props other than `store`");
594
+ if (attributes.length !== 1 || attributes[0].kind !== javascript_1.JS.Kind.JsxAttribute) {
595
+ return other("`Provider` with props other than `store`", "`Provider`'s props other than `store`, such as `context` or `serverState`, have no zustand equivalent: convert by hand.");
596
+ }
468
597
  const value = (_a = attributes[0].value) === null || _a === void 0 ? void 0 : _a.element;
469
598
  const expression = (value === null || value === void 0 ? void 0 : value.kind) === javascript_1.JS.Kind.JsxEmbeddedExpression ? value.expression.element : undefined;
470
599
  if (!(0, java_1.isIdentifier)(expression) || !followed.has(expression.simpleName))
471
- return other("`Provider` of a store that isn't imported");
600
+ return other("`Provider` of a store that isn't imported", PROVIDER_NOT_IMPORTED);
472
601
  if (!providerChild(tag) && !providerChildren(tag))
473
602
  return other("`Provider` without children");
474
- return { local, kind: "providerTag" };
603
+ return { local, kind: "providerTag", via: expression.simpleName };
475
604
  }
476
605
  function providerChildren(tag) {
477
606
  var _a;
@@ -499,10 +628,13 @@ function cursorOf(cursor, node) {
499
628
  exports.STORE_MEMBERS = new Set(["getState", "dispatch", "subscribe"]);
500
629
  function usesInSource(cu, name, call) {
501
630
  return __awaiter(this, void 0, void 0, function* () {
502
- const result = { other: false, called: new Set() };
631
+ const result = { other: false, uses: [], called: new Set() };
632
+ const persistStore = (0, redux_stores_1.importedAs)(cu, "redux-persist", "persistStore");
503
633
  const statements = cu.statements.map(s => s.element).flatMap(statement => {
504
634
  if (statement.kind === javascript_1.JS.Kind.Import)
505
635
  return [];
636
+ if (exportList(statement).some(entry => entry.local === name))
637
+ return [];
506
638
  if (statement.kind === javascript_1.JS.Kind.ExportAssignment && (0, java_1.isIdentifier)(statement.expression.element) &&
507
639
  statement.expression.element.simpleName === name)
508
640
  return [];
@@ -536,6 +668,7 @@ function usesInSource(cu, name, call) {
536
668
  parent.initializer)
537
669
  return identifier;
538
670
  result.other = true;
671
+ result.uses.push(storeValueUse(identifier, this.cursor, persistStore));
539
672
  return identifier;
540
673
  });
541
674
  }
@@ -574,14 +707,36 @@ function exportedStore(cu, cursor) {
574
707
  return name;
575
708
  const exported = cu.statements.map(s => s.element).find(s => s.kind === javascript_1.JS.Kind.ExportAssignment &&
576
709
  (0, java_1.isIdentifier)(s.expression.element) && s.expression.element.simpleName === name);
577
- return exported ? "default" : undefined;
710
+ if (exported)
711
+ return "default";
712
+ const listed = cu.statements.flatMap(s => exportList(s.element)).filter(entry => entry.local === name);
713
+ return listed.length === 1 ? listed[0].exported : undefined;
714
+ }
715
+ function exportList(statement) {
716
+ var _a;
717
+ if (statement.kind !== javascript_1.JS.Kind.ExportDeclaration)
718
+ return [];
719
+ const declaration = statement;
720
+ if (declaration.moduleSpecifier || declaration.typeOnly.element || ((_a = declaration.exportClause) === null || _a === void 0 ? void 0 : _a.kind) !== javascript_1.JS.Kind.NamedExports)
721
+ return [];
722
+ return declaration.exportClause.elements.elements.flatMap(({ element }) => {
723
+ if (element.kind !== javascript_1.JS.Kind.ExportSpecifier || element.typeOnly.element)
724
+ return [];
725
+ const specifier = element.specifier;
726
+ if ((0, java_1.isIdentifier)(specifier))
727
+ return [{ local: specifier.simpleName, exported: specifier.simpleName }];
728
+ if (specifier.kind !== javascript_1.JS.Kind.Alias)
729
+ return [];
730
+ const local = specifier.propertyName.element, alias = specifier.alias;
731
+ return (0, java_1.isIdentifier)(local) && (0, java_1.isIdentifier)(alias) ? [{ local: local.simpleName, exported: alias.simpleName }] : [];
732
+ });
578
733
  }
579
734
  exports.SELECTOR_HOOK = "useAppStoreSelector";
580
735
  exports.STORE_LISTENERS = "storeListeners";
581
736
  exports.REDUCER_STORE_HOOK = "useAppStore";
582
737
  const hookName = (key) => `use${key.charAt(0).toUpperCase()}${key.slice(1)}Store`;
583
738
  exports.hookName = hookName;
584
- function plan(facts, sliceSources, dependencies, scope = () => true, wholeStores = true, renderer = () => "react-dom", selectsOnEachRead = () => false) {
739
+ function plan(facts, sliceSources, dependencies, scope = () => true, wholeStores = true, renderer = () => "react-dom", selectsOnEachRead = () => false, resolveFrom = (from, specifier) => (0, module_imports_1.resolveRelative)(from, specifier, facts)) {
585
740
  var _a;
586
741
  const stores = [...facts.values()].filter(source => scope(source.path)).flatMap(source => source.stores);
587
742
  const result = { slices: new Map(), sources: new Set(), blocked: new Map() };
@@ -589,14 +744,15 @@ function plan(facts, sliceSources, dependencies, scope = () => true, wholeStores
589
744
  return result;
590
745
  if (stores.length > 1) {
591
746
  for (const store of stores)
592
- result.blocked.set(store, [...store.findings, { reason: "MULTIPLE_STORES", detail: `${stores.length} stores` }]);
747
+ result.blocked.set(store, [...store.findings, { reason: "MULTIPLE_STORES", detail: `${stores.length} stores`, action: multipleStoresAction(store, stores, facts) }]);
593
748
  return result;
594
749
  }
595
750
  const store = stores[0];
596
751
  const findings = [...store.findings];
597
- const block = (reason, detail) => findings.push({ reason, detail });
752
+ const block = (reason, detail, action) => findings.push(Object.assign({ reason, detail }, action ? { action } : {}));
598
753
  const held = new Map();
599
754
  const handled = new Map();
755
+ const slicesRead = findings.length === 0;
600
756
  if (findings.length === 0) {
601
757
  if (!store.exportedAs)
602
758
  block("STORE_NOT_MODULE_LEVEL", store.store);
@@ -643,9 +799,10 @@ function plan(facts, sliceSources, dependencies, scope = () => true, wholeStores
643
799
  }
644
800
  }
645
801
  const slicePaths = new Map([...result.slices.values()].map(slice => [slice.path, slice]));
802
+ const storeModule = facts.get(store.path);
646
803
  const sources = new Set([store.path, ...slicePaths.keys()]);
647
804
  for (const source of facts.values()) {
648
- const resolve = (module) => (0, module_imports_1.resolveRelative)(source.path, module, facts);
805
+ const resolve = (module) => resolveFrom(source.path, module);
649
806
  const touches = (module) => {
650
807
  const path = resolve(module);
651
808
  return path === store.path || (path !== undefined && slicePaths.has(path));
@@ -689,22 +846,33 @@ function plan(facts, sliceSources, dependencies, scope = () => true, wholeStores
689
846
  continue;
690
847
  changes = true;
691
848
  const where = `${use.local} in ${source.path}`;
849
+ if (use.kind === "providerTag" && !provides(source, use, store, resolve))
850
+ block("REACT_REDUX_USE", `${where}: \`Provider\` of \`${use.via}\`, which isn't the store`, PROVIDER_OTHER_STORE);
692
851
  if (use.kind === "other") {
693
- block((_a = use.reason) !== null && _a !== void 0 ? _a : (isStore ? "STORE_USE" : slice ? "SLICE_USE" : !binding ? "DISPATCH" : isReactRedux ? "REACT_REDUX_USE" : "STORE_USE"), `${where}: ${use.detail}`);
852
+ const whole = !wholeStores ? "" : use.anySelector ? " Or remove what the store's other rows name, so that it moves whole and runs the selector as it is." :
853
+ use.reason === "DISPATCH" ? " Or remove what the store's other rows name, so that it moves whole and dispatches it as Redux does." : "";
854
+ const reason = (_a = use.reason) !== null && _a !== void 0 ? _a : (isStore ? "STORE_USE" : slice ? "SLICE_USE" : !binding ? "DISPATCH" : isReactRedux ? "REACT_REDUX_USE" : "STORE_USE");
855
+ const member = isStore && (use.member === "getState" || use.member === "dispatch") && wholeStores ?
856
+ ` Or remove what the store's other rows name, so that it moves whole and calls \`${use.member}\` as Redux does.` : "";
857
+ const action = binding && path === store.path && !isStore && reason === "STORE_USE" ? storeExportAction(binding, source, store, storeModule, wholeStores) :
858
+ isStore && use.valueUse ? storeValueAction(use.local, [use.valueUse]) : use.action && use.action + whole + member;
859
+ block(reason, `${where}: ${use.detail}`, action);
694
860
  }
695
861
  else if (use.kind === "selector" || use.kind === "getState") {
696
- if (!result.slices.has(use.key))
697
- block("SELECTOR", `${where} reads \`${use.key}\`, which is no slice of the store`);
862
+ if (!result.slices.has(use.key)) {
863
+ block("SELECTOR", `${where} reads \`${use.key}\`, which is no slice of the store`, !slicesRead ? UNREAD_SLICES : `\`${use.key}\` isn't a key of the store's \`reducer\`, whose slices are ${[...result.slices.keys()].map(k => `\`${k}\``).join(", ") || "none that convert"}: read one of those, or, where \`${use.key}\` is a reducer of the store that isn't a slice, rewrite it with \`createSlice\`.`);
864
+ }
698
865
  }
699
866
  else if (use.kind === "dispatched") {
700
- if (!slice || !binding || !slice.actions.has(binding.name) && !slice.unknown.has(binding.name) && !slice.thunkVariables.has(binding.name))
701
- block("DISPATCH", `${where} dispatches what isn't an action creator of a slice`);
867
+ if (!slice || !binding || !slice.actions.has(binding.name) && !slice.unknown.has(binding.name) && !slice.thunkVariables.has(binding.name)) {
868
+ block("DISPATCH", `${where} dispatches what isn't an action creator of a slice`, slicesRead ? binding && sliceDispatchAction(binding, slice !== undefined) : UNREAD_SLICES);
869
+ }
702
870
  const via = source.bindings.find(b => b.local === use.via);
703
871
  if (via && !(resolve(via.module) === store.path && via.name === store.exportedAs))
704
872
  block("DISPATCH", `${where} is dispatched through \`${use.via}\``);
705
873
  }
706
874
  else if (use.kind === "connect") {
707
- block("REACT_REDUX_USE", `${where}: \`connect\` from react-redux`);
875
+ block("REACT_REDUX_USE", `${where}: \`connect\` from react-redux`, connectAction(wholeStores));
708
876
  }
709
877
  else if ((use.kind === "provider" || use.kind === "storeDispatch") && !isStore) {
710
878
  block("STORE_USE", `${where} isn't the store`);
@@ -712,14 +880,14 @@ function plan(facts, sliceSources, dependencies, scope = () => true, wholeStores
712
880
  if (slice && use.kind !== "dispatched" && use.kind !== "other")
713
881
  block("SLICE_USE", `${where}: ${use.kind}`);
714
882
  if (path === store.path && !isStore && source.path !== store.path)
715
- block("STORE_USE", `${where} imports more of the store's source`);
883
+ block("STORE_USE", `${where} imports more of the store's source`, binding && storeExportAction(binding, source, store, storeModule, wholeStores));
716
884
  }
717
885
  for (const binding of source.bindings) {
718
886
  if (source.path === store.path || binding.module === exports.REACT_REDUX || resolve(binding.module) !== store.path)
719
887
  continue;
720
888
  changes = true;
721
889
  if (binding.name !== store.exportedAs)
722
- block("STORE_USE", `${binding.local} in ${source.path} imports more of the store's source`);
890
+ block("STORE_USE", `${binding.local} in ${source.path} imports more of the store's source`, storeExportAction(binding, source, store, storeModule, wholeStores));
723
891
  }
724
892
  if (changes && source.path !== store.path) {
725
893
  if (source.typescript)
@@ -735,7 +903,7 @@ function plan(facts, sliceSources, dependencies, scope = () => true, wholeStores
735
903
  if ([store.path, ...slicePaths.keys()].some(path => /\.(?:ts|tsx|mts|cts)$/.test(path)))
736
904
  block("TYPESCRIPT", store.path);
737
905
  if (findings.length > 0 && store.reducerStore && wholeStores)
738
- return reducerPlan(facts, sliceSources, store, dependencies, scope, renderer, selectsOnEachRead);
906
+ return reducerPlan(facts, sliceSources, store, dependencies, scope, renderer, selectsOnEachRead, resolveFrom);
739
907
  if (findings.length > 0) {
740
908
  result.blocked.set(store, dedupe(findings));
741
909
  result.slices.clear();
@@ -745,10 +913,10 @@ function plan(facts, sliceSources, dependencies, scope = () => true, wholeStores
745
913
  result.sources = sources;
746
914
  return result;
747
915
  }
748
- function reducerPlan(facts, sliceSources, store, dependencies, scope, renderer, selectsOnEachRead) {
749
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
916
+ function reducerPlan(facts, sliceSources, store, dependencies, scope, renderer, selectsOnEachRead, resolveFrom) {
917
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
750
918
  const findings = [];
751
- const block = (reason, detail) => findings.push({ reason, detail });
919
+ const block = (reason, detail, action) => findings.push(Object.assign({ reason, detail }, action ? { action } : {}));
752
920
  const hook = exports.REDUCER_STORE_HOOK;
753
921
  const source = facts.get(store.path);
754
922
  const names = new Set([...(_b = (_a = sliceSources.get(store.path)) === null || _a === void 0 ? void 0 : _a.names) !== null && _b !== void 0 ? _b : [], ...(_c = source === null || source === void 0 ? void 0 : source.declared) !== null && _c !== void 0 ? _c : [], ...(_d = source === null || source === void 0 ? void 0 : source.bindings.map(b => b.local)) !== null && _d !== void 0 ? _d : []]);
@@ -756,7 +924,7 @@ function reducerPlan(facts, sliceSources, store, dependencies, scope, renderer,
756
924
  if (!store.exportedAs)
757
925
  block("STORE_NOT_MODULE_LEVEL", store.store);
758
926
  if (store.usedInSource)
759
- block("STORE_USE", `\`${store.store}\` is used in its own source`);
927
+ block("STORE_USE", `\`${store.store}\` is used in its own source`, (_g = storeValueAction(store.store, (_f = store.usesInSource) !== null && _f !== void 0 ? _f : [])) !== null && _g !== void 0 ? _g : `Move what uses \`${store.store}\` in its own source, other than calls of its \`getState\`, \`dispatch\` and \`subscribe\`, to a module that imports the store, or convert by hand.`);
760
928
  const dependency = dependencies(store.path, false);
761
929
  if (dependency)
762
930
  findings.push(dependency);
@@ -770,9 +938,9 @@ function reducerPlan(facts, sliceSources, store, dependencies, scope, renderer,
770
938
  const sources = new Set([store.path]);
771
939
  let connects = false;
772
940
  let selects = false;
773
- let subscribes = (_g = (_f = store.calledInSource) === null || _f === void 0 ? void 0 : _f.has("subscribe")) !== null && _g !== void 0 ? _g : false;
941
+ let subscribes = (_j = (_h = store.calledInSource) === null || _h === void 0 ? void 0 : _h.has("subscribe")) !== null && _j !== void 0 ? _j : false;
774
942
  for (const source of facts.values()) {
775
- const resolve = (module) => (0, module_imports_1.resolveRelative)(source.path, module, facts);
943
+ const resolve = (module) => resolveFrom(source.path, module);
776
944
  if (!scope(source.path)) {
777
945
  for (const binding of source.bindings) {
778
946
  if (binding.module !== exports.REACT_REDUX && resolve(binding.module) === store.path)
@@ -798,7 +966,9 @@ function reducerPlan(facts, sliceSources, store, dependencies, scope, renderer,
798
966
  changes = true;
799
967
  if (use.kind === "connect")
800
968
  connects = true;
801
- if (use.kind === "other" && use.selector && readSelector(source, use.selector, facts))
969
+ if (use.kind === "providerTag" && !provides(source, use, store, resolve))
970
+ block("REACT_REDUX_USE", `${where}: \`Provider\` of \`${use.via}\`, which isn't the store`, PROVIDER_OTHER_STORE);
971
+ if (use.kind === "other" && use.selector && readSelector(source, use.selector, facts, resolveFrom))
802
972
  continue;
803
973
  if (use.kind === "other" && use.anySelector) {
804
974
  if (selectsOnEachRead(store.path))
@@ -806,7 +976,7 @@ function reducerPlan(facts, sliceSources, store, dependencies, scope, renderer,
806
976
  continue;
807
977
  }
808
978
  if (use.kind === "other")
809
- block((_h = use.reason) !== null && _h !== void 0 ? _h : "REACT_REDUX_USE", `${where}: ${use.detail}`);
979
+ block((_k = use.reason) !== null && _k !== void 0 ? _k : "REACT_REDUX_USE", `${where}: ${use.detail}`, use.action);
810
980
  continue;
811
981
  }
812
982
  const path = resolve(binding.module);
@@ -817,7 +987,7 @@ function reducerPlan(facts, sliceSources, store, dependencies, scope, renderer,
817
987
  else if (use.kind === "other" && use.member === "subscribe")
818
988
  subscribes = true;
819
989
  else if (use.kind === "other" && use.member !== "getState" && use.member !== "dispatch")
820
- block(use.reason === "DISPATCH" ? "STORE_USE" : (_j = use.reason) !== null && _j !== void 0 ? _j : "STORE_USE", `${where}: ${use.detail}`);
990
+ block(use.reason === "DISPATCH" ? "STORE_USE" : (_l = use.reason) !== null && _l !== void 0 ? _l : "STORE_USE", `${where}: ${use.detail}`, use.valueUse && storeValueAction(use.local, [use.valueUse]));
821
991
  }
822
992
  if (changes && source.path !== store.path) {
823
993
  if (source.typescript)
@@ -862,18 +1032,22 @@ function reducerPlan(facts, sliceSources, store, dependencies, scope, renderer,
862
1032
  }
863
1033
  return Object.assign(Object.assign({}, result), { store, sources, reducerStore: Object.assign(Object.assign(Object.assign({ hook, reducer }, module ? { renderer: module } : {}), selects ? { selectorHook: exports.SELECTOR_HOOK } : {}), subscribes ? { listeners: exports.STORE_LISTENERS } : {}) });
864
1034
  }
865
- function readSelector(source, name, facts) {
1035
+ function provides(source, use, store, resolve) {
1036
+ const binding = source.bindings.find(b => b.local === use.via);
1037
+ return !!binding && binding.module !== exports.REACT_REDUX && resolve(binding.module) === store.path && binding.name === store.exportedAs;
1038
+ }
1039
+ function readSelector(source, name, facts, resolve = (from, specifier) => (0, module_imports_1.resolveRelative)(from, specifier, facts)) {
866
1040
  var _a, _b;
867
1041
  const binding = source.bindings.find(b => b.local === name);
868
1042
  if (!binding)
869
1043
  return source.readSelectors.local.has(name);
870
- const path = (0, module_imports_1.resolveRelative)(source.path, binding.module, facts);
1044
+ const path = resolve(source.path, binding.module);
871
1045
  return path !== undefined && ((_b = (_a = facts.get(path)) === null || _a === void 0 ? void 0 : _a.readSelectors.exported.has(binding.name)) !== null && _b !== void 0 ? _b : false);
872
1046
  }
873
- function planPackages(facts, sliceSources, packageOf, dependencies, wholeStores = true, renderer, selectsOnEachRead) {
1047
+ function planPackages(facts, sliceSources, packageOf, dependencies, wholeStores = true, renderer, selectsOnEachRead, resolve) {
874
1048
  const root = (path) => { var _a; return (_a = packageOf(path)) !== null && _a !== void 0 ? _a : ""; };
875
1049
  const roots = new Set([...facts.values()].filter(source => source.stores.length > 0).map(source => root(source.path)));
876
- return [...roots].map(packageRoot => plan(facts, sliceSources, dependencies, path => root(path) === packageRoot, wholeStores, renderer, selectsOnEachRead));
1050
+ return [...roots].map(packageRoot => plan(facts, sliceSources, dependencies, path => root(path) === packageRoot, wholeStores, renderer, selectsOnEachRead, resolve));
877
1051
  }
878
1052
  function dedupe(findings) {
879
1053
  const seen = new Set();