@nx/react 0.0.0-pr-22179-271588f

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 (347) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +68 -0
  3. package/ast-utils.d.ts +1 -0
  4. package/ast-utils.js +11 -0
  5. package/babel.d.ts +20 -0
  6. package/babel.js +50 -0
  7. package/executors.json +14 -0
  8. package/generators.json +112 -0
  9. package/index.d.ts +22 -0
  10. package/index.js +47 -0
  11. package/mf/dynamic-federation.d.ts +4 -0
  12. package/mf/dynamic-federation.js +75 -0
  13. package/mf/index.d.ts +1 -0
  14. package/mf/index.js +7 -0
  15. package/migrations.json +310 -0
  16. package/module-federation.d.ts +4 -0
  17. package/module-federation.js +12 -0
  18. package/package.json +49 -0
  19. package/plugins/bundle-rollup.d.ts +1 -0
  20. package/plugins/bundle-rollup.js +47 -0
  21. package/plugins/component-testing/index.d.ts +37 -0
  22. package/plugins/component-testing/index.js +222 -0
  23. package/plugins/component-testing/webpack-fallback.d.ts +5 -0
  24. package/plugins/component-testing/webpack-fallback.js +125 -0
  25. package/plugins/jest.d.ts +1 -0
  26. package/plugins/jest.js +59 -0
  27. package/plugins/nx-react-webpack-plugin/lib/apply-react-config.d.ts +4 -0
  28. package/plugins/nx-react-webpack-plugin/lib/apply-react-config.js +60 -0
  29. package/plugins/nx-react-webpack-plugin/nx-react-webpack-plugin.d.ts +8 -0
  30. package/plugins/nx-react-webpack-plugin/nx-react-webpack-plugin.js +13 -0
  31. package/plugins/storybook/index.d.ts +3 -0
  32. package/plugins/storybook/index.js +174 -0
  33. package/plugins/storybook/merge-plugins.d.ts +3 -0
  34. package/plugins/storybook/merge-plugins.js +17 -0
  35. package/plugins/webpack.d.ts +1 -0
  36. package/plugins/webpack.js +6 -0
  37. package/plugins/with-react.d.ts +10 -0
  38. package/plugins/with-react.js +22 -0
  39. package/src/executors/module-federation-dev-server/module-federation-dev-server.impl.d.ts +25 -0
  40. package/src/executors/module-federation-dev-server/module-federation-dev-server.impl.js +211 -0
  41. package/src/executors/module-federation-dev-server/schema.json +114 -0
  42. package/src/executors/module-federation-ssr-dev-server/module-federation-ssr-dev-server.impl.d.ts +9 -0
  43. package/src/executors/module-federation-ssr-dev-server/module-federation-ssr-dev-server.impl.js +106 -0
  44. package/src/executors/module-federation-ssr-dev-server/schema.json +48 -0
  45. package/src/generators/application/application.d.ts +5 -0
  46. package/src/generators/application/application.js +232 -0
  47. package/src/generators/application/files/base-rspack/src/app/__fileName__.spec.tsx__tmpl__ +10 -0
  48. package/src/generators/application/files/base-rspack/src/assets/.gitkeep +0 -0
  49. package/src/generators/application/files/base-rspack/src/favicon.ico +0 -0
  50. package/src/generators/application/files/base-rspack/src/index.html +14 -0
  51. package/src/generators/application/files/base-rspack/src/main.tsx__tmpl__ +10 -0
  52. package/src/generators/application/files/base-rspack/tsconfig.app.json__tmpl__ +14 -0
  53. package/src/generators/application/files/base-vite/index.html__tmpl__ +16 -0
  54. package/src/generators/application/files/base-vite/public/favicon.ico +0 -0
  55. package/src/generators/application/files/base-vite/src/app/__fileName__.spec.tsx__tmpl__ +10 -0
  56. package/src/generators/application/files/base-vite/src/assets/.gitkeep +0 -0
  57. package/src/generators/application/files/base-vite/src/environments/environment.prod.ts__tmpl__ +3 -0
  58. package/src/generators/application/files/base-vite/src/environments/environment.ts__tmpl__ +6 -0
  59. package/src/generators/application/files/base-vite/src/main.tsx__tmpl__ +10 -0
  60. package/src/generators/application/files/base-vite/tsconfig.app.json__tmpl__ +14 -0
  61. package/src/generators/application/files/base-webpack/src/app/__fileName__.spec.tsx__tmpl__ +10 -0
  62. package/src/generators/application/files/base-webpack/src/assets/.gitkeep +0 -0
  63. package/src/generators/application/files/base-webpack/src/favicon.ico +0 -0
  64. package/src/generators/application/files/base-webpack/src/index.html +12 -0
  65. package/src/generators/application/files/base-webpack/src/main.tsx__tmpl__ +10 -0
  66. package/src/generators/application/files/base-webpack/tsconfig.app.json__tmpl__ +14 -0
  67. package/src/generators/application/files/base-webpack/webpack.config.js__tmpl__ +50 -0
  68. package/src/generators/application/files/nx-welcome/src/app/nx-welcome.tsx +886 -0
  69. package/src/generators/application/files/style-css-module/src/app/__fileName__.module.__style__ +1 -0
  70. package/src/generators/application/files/style-css-module/src/app/__fileName__.tsx__tmpl__ +36 -0
  71. package/src/generators/application/files/style-css-module/src/styles.__style__ +1 -0
  72. package/src/generators/application/files/style-global-css/src/app/__fileName__.__style__ +1 -0
  73. package/src/generators/application/files/style-global-css/src/app/__fileName__.tsx__tmpl__ +35 -0
  74. package/src/generators/application/files/style-global-css/src/styles.__style__ +1 -0
  75. package/src/generators/application/files/style-none/src/app/__fileName__.tsx__tmpl__ +34 -0
  76. package/src/generators/application/files/style-styled-jsx/src/app/__fileName__.tsx__tmpl__ +37 -0
  77. package/src/generators/application/files/style-styled-module/src/app/__fileName__.tsx__tmpl__ +40 -0
  78. package/src/generators/application/files/style-tailwind/src/app/__fileName__.tsx__tmpl__ +33 -0
  79. package/src/generators/application/files/style-tailwind/src/styles.css +1 -0
  80. package/src/generators/application/lib/add-e2e.d.ts +3 -0
  81. package/src/generators/application/lib/add-e2e.js +79 -0
  82. package/src/generators/application/lib/add-jest.d.ts +3 -0
  83. package/src/generators/application/lib/add-jest.js +21 -0
  84. package/src/generators/application/lib/add-project.d.ts +3 -0
  85. package/src/generators/application/lib/add-project.js +96 -0
  86. package/src/generators/application/lib/add-routing.d.ts +3 -0
  87. package/src/generators/application/lib/add-routing.js +27 -0
  88. package/src/generators/application/lib/create-application-files.d.ts +3 -0
  89. package/src/generators/application/lib/create-application-files.js +143 -0
  90. package/src/generators/application/lib/find-free-port.d.ts +2 -0
  91. package/src/generators/application/lib/find-free-port.js +16 -0
  92. package/src/generators/application/lib/get-app-tests.d.ts +2 -0
  93. package/src/generators/application/lib/get-app-tests.js +21 -0
  94. package/src/generators/application/lib/install-common-dependencies.d.ts +3 -0
  95. package/src/generators/application/lib/install-common-dependencies.js +47 -0
  96. package/src/generators/application/lib/normalize-options.d.ts +5 -0
  97. package/src/generators/application/lib/normalize-options.js +72 -0
  98. package/src/generators/application/lib/set-defaults.d.ts +3 -0
  99. package/src/generators/application/lib/set-defaults.js +43 -0
  100. package/src/generators/application/lib/show-possible-warnings.d.ts +3 -0
  101. package/src/generators/application/lib/show-possible-warnings.js +11 -0
  102. package/src/generators/application/lib/update-jest-config.d.ts +3 -0
  103. package/src/generators/application/lib/update-jest-config.js +30 -0
  104. package/src/generators/application/schema.d.ts +45 -0
  105. package/src/generators/application/schema.json +201 -0
  106. package/src/generators/component/component.d.ts +5 -0
  107. package/src/generators/component/component.js +93 -0
  108. package/src/generators/component/files/__fileName__.__style__ +0 -0
  109. package/src/generators/component/files/__fileName__.module.__style__ +7 -0
  110. package/src/generators/component/files/__fileName__.spec.tsx__tmpl__ +7 -0
  111. package/src/generators/component/files/__fileName__.tsx__tmpl__ +88 -0
  112. package/src/generators/component/lib/get-component-tests.d.ts +2 -0
  113. package/src/generators/component/lib/get-component-tests.js +12 -0
  114. package/src/generators/component/lib/normalize-options.d.ts +3 -0
  115. package/src/generators/component/lib/normalize-options.js +50 -0
  116. package/src/generators/component/schema.d.ts +48 -0
  117. package/src/generators/component/schema.json +150 -0
  118. package/src/generators/component-cypress-spec/component-cypress-spec.d.ts +13 -0
  119. package/src/generators/component-cypress-spec/component-cypress-spec.js +100 -0
  120. package/src/generators/component-cypress-spec/files/__componentName__.__fileExt__ +13 -0
  121. package/src/generators/component-cypress-spec/schema.json +44 -0
  122. package/src/generators/component-story/component-story.d.ts +12 -0
  123. package/src/generators/component-story/component-story.js +72 -0
  124. package/src/generators/component-story/files/jsx/__componentFileName__.stories.jsx__tmpl__ +29 -0
  125. package/src/generators/component-story/files/tsx/__componentFileName__.stories.tsx__tmpl__ +36 -0
  126. package/src/generators/component-story/schema.json +42 -0
  127. package/src/generators/component-test/component-test.d.ts +4 -0
  128. package/src/generators/component-test/component-test.js +76 -0
  129. package/src/generators/component-test/files/__fileName__.cy__ext__ +21 -0
  130. package/src/generators/component-test/schema.d.ts +4 -0
  131. package/src/generators/component-test/schema.js +2 -0
  132. package/src/generators/component-test/schema.json +31 -0
  133. package/src/generators/cypress-component-configuration/cypress-component-configuration.d.ts +10 -0
  134. package/src/generators/cypress-component-configuration/cypress-component-configuration.js +51 -0
  135. package/src/generators/cypress-component-configuration/lib/add-files.d.ts +4 -0
  136. package/src/generators/cypress-component-configuration/lib/add-files.js +45 -0
  137. package/src/generators/cypress-component-configuration/schema.d.ts +8 -0
  138. package/src/generators/cypress-component-configuration/schema.json +54 -0
  139. package/src/generators/federate-module/federate-module.d.ts +4 -0
  140. package/src/generators/federate-module/federate-module.js +70 -0
  141. package/src/generators/federate-module/lib/utils.d.ts +23 -0
  142. package/src/generators/federate-module/lib/utils.js +100 -0
  143. package/src/generators/federate-module/schema.d.ts +13 -0
  144. package/src/generators/federate-module/schema.json +83 -0
  145. package/src/generators/hook/files/__fileName__.spec.tsx__tmpl__ +18 -0
  146. package/src/generators/hook/files/__fileName__.ts__tmpl__ +15 -0
  147. package/src/generators/hook/hook.d.ts +5 -0
  148. package/src/generators/hook/hook.js +131 -0
  149. package/src/generators/hook/schema.d.ts +24 -0
  150. package/src/generators/hook/schema.json +84 -0
  151. package/src/generators/host/files/common/src/app/__fileName__.js__tmpl__ +33 -0
  152. package/src/generators/host/files/common/src/main.js__tmpl__ +10 -0
  153. package/src/generators/host/files/common/tsconfig.lint.json__tmpl__ +19 -0
  154. package/src/generators/host/files/common-ts/src/app/__fileName__.tsx__tmpl__ +41 -0
  155. package/src/generators/host/files/common-ts/src/main.ts__tmpl__ +10 -0
  156. package/src/generators/host/files/module-federation/module-federation.config.js__tmpl__ +21 -0
  157. package/src/generators/host/files/module-federation/webpack.config.js__tmpl__ +12 -0
  158. package/src/generators/host/files/module-federation/webpack.config.prod.js__tmpl__ +32 -0
  159. package/src/generators/host/files/module-federation-ssr/module-federation.server.config.js__tmpl__ +16 -0
  160. package/src/generators/host/files/module-federation-ssr/server.ts__tmpl__ +28 -0
  161. package/src/generators/host/files/module-federation-ssr/tsconfig.server.json__tmpl__ +17 -0
  162. package/src/generators/host/files/module-federation-ssr/webpack.server.config.js__tmpl__ +12 -0
  163. package/src/generators/host/files/module-federation-ssr-ts/module-federation.server.config.ts__tmpl__ +13 -0
  164. package/src/generators/host/files/module-federation-ssr-ts/server.ts__tmpl__ +28 -0
  165. package/src/generators/host/files/module-federation-ssr-ts/tsconfig.server.json__tmpl__ +17 -0
  166. package/src/generators/host/files/module-federation-ssr-ts/webpack.server.config.ts__tmpl__ +12 -0
  167. package/src/generators/host/files/module-federation-ts/module-federation.config.ts__tmpl__ +25 -0
  168. package/src/generators/host/files/module-federation-ts/webpack.config.prod.ts__tmpl__ +33 -0
  169. package/src/generators/host/files/module-federation-ts/webpack.config.ts__tmpl__ +12 -0
  170. package/src/generators/host/host.d.ts +5 -0
  171. package/src/generators/host/host.js +95 -0
  172. package/src/generators/host/lib/add-module-federation-files.d.ts +6 -0
  173. package/src/generators/host/lib/add-module-federation-files.js +52 -0
  174. package/src/generators/host/lib/normalize-remote.d.ts +4 -0
  175. package/src/generators/host/lib/normalize-remote.js +28 -0
  176. package/src/generators/host/lib/setup-ssr-for-host.d.ts +6 -0
  177. package/src/generators/host/lib/setup-ssr-for-host.js +33 -0
  178. package/src/generators/host/lib/update-module-federation-e2e-project.d.ts +3 -0
  179. package/src/generators/host/lib/update-module-federation-e2e-project.js +20 -0
  180. package/src/generators/host/schema.d.ts +37 -0
  181. package/src/generators/host/schema.json +184 -0
  182. package/src/generators/init/init.d.ts +4 -0
  183. package/src/generators/init/init.js +23 -0
  184. package/src/generators/init/schema.d.ts +5 -0
  185. package/src/generators/init/schema.json +27 -0
  186. package/src/generators/library/files/common/README.md +7 -0
  187. package/src/generators/library/files/common/package.json__tmpl__ +4 -0
  188. package/src/generators/library/files/common/src/index.ts__tmpl__ +0 -0
  189. package/src/generators/library/files/common/tsconfig.lib.json__tmpl__ +14 -0
  190. package/src/generators/library/files/vite/README.md +7 -0
  191. package/src/generators/library/files/vite/package.json__tmpl__ +12 -0
  192. package/src/generators/library/files/vite/tsconfig.lib.json__tmpl__ +14 -0
  193. package/src/generators/library/lib/add-linting.d.ts +3 -0
  194. package/src/generators/library/lib/add-linting.js +36 -0
  195. package/src/generators/library/lib/add-rollup-build-target.d.ts +4 -0
  196. package/src/generators/library/lib/add-rollup-build-target.js +59 -0
  197. package/src/generators/library/lib/create-files.d.ts +3 -0
  198. package/src/generators/library/lib/create-files.js +53 -0
  199. package/src/generators/library/lib/install-common-dependencies.d.ts +3 -0
  200. package/src/generators/library/lib/install-common-dependencies.js +47 -0
  201. package/src/generators/library/lib/normalize-options.d.ts +3 -0
  202. package/src/generators/library/lib/normalize-options.js +92 -0
  203. package/src/generators/library/lib/set-defaults.d.ts +3 -0
  204. package/src/generators/library/lib/set-defaults.js +23 -0
  205. package/src/generators/library/lib/update-app-routes.d.ts +3 -0
  206. package/src/generators/library/lib/update-app-routes.js +62 -0
  207. package/src/generators/library/library.d.ts +5 -0
  208. package/src/generators/library/library.js +193 -0
  209. package/src/generators/library/schema.d.ts +45 -0
  210. package/src/generators/library/schema.json +198 -0
  211. package/src/generators/redux/files/__fileName__.slice.spec.ts__tmpl__ +56 -0
  212. package/src/generators/redux/files/__fileName__.slice.ts__tmpl__ +129 -0
  213. package/src/generators/redux/redux.d.ts +5 -0
  214. package/src/generators/redux/redux.js +143 -0
  215. package/src/generators/redux/schema.d.ts +23 -0
  216. package/src/generators/redux/schema.json +51 -0
  217. package/src/generators/remote/files/common/src/main.js__tmpl__ +1 -0
  218. package/src/generators/remote/files/common/src/remote-entry.js__tmpl__ +1 -0
  219. package/src/generators/remote/files/common-ts/src/main.ts__tmpl__ +1 -0
  220. package/src/generators/remote/files/common-ts/src/remote-entry.ts__tmpl__ +1 -0
  221. package/src/generators/remote/files/module-federation/module-federation.config.js__tmpl__ +9 -0
  222. package/src/generators/remote/files/module-federation/webpack.config.js__tmpl__ +12 -0
  223. package/src/generators/remote/files/module-federation/webpack.config.prod.js__tmpl__ +1 -0
  224. package/src/generators/remote/files/module-federation-ssr/module-federation.server.config.js__tmpl__ +6 -0
  225. package/src/generators/remote/files/module-federation-ssr/server.ts__tmpl__ +45 -0
  226. package/src/generators/remote/files/module-federation-ssr/webpack.server.config.js__tmpl__ +12 -0
  227. package/src/generators/remote/files/module-federation-ssr-ts/module-federation.server.config.ts__tmpl__ +10 -0
  228. package/src/generators/remote/files/module-federation-ssr-ts/server.ts__tmpl__ +45 -0
  229. package/src/generators/remote/files/module-federation-ssr-ts/tsconfig.lint.json__tmpl__ +19 -0
  230. package/src/generators/remote/files/module-federation-ssr-ts/webpack.server.config.ts__tmpl__ +12 -0
  231. package/src/generators/remote/files/module-federation-ts/module-federation.config.ts__tmpl__ +13 -0
  232. package/src/generators/remote/files/module-federation-ts/tsconfig.lint.json__tmpl__ +19 -0
  233. package/src/generators/remote/files/module-federation-ts/webpack.config.prod.ts__tmpl__ +1 -0
  234. package/src/generators/remote/files/module-federation-ts/webpack.config.ts__tmpl__ +12 -0
  235. package/src/generators/remote/lib/add-remote-to-dynamic-host.d.ts +2 -0
  236. package/src/generators/remote/lib/add-remote-to-dynamic-host.js +11 -0
  237. package/src/generators/remote/lib/setup-ssr-for-remote.d.ts +4 -0
  238. package/src/generators/remote/lib/setup-ssr-for-remote.js +40 -0
  239. package/src/generators/remote/lib/setup-tspath-for-remote.d.ts +3 -0
  240. package/src/generators/remote/lib/setup-tspath-for-remote.js +15 -0
  241. package/src/generators/remote/lib/update-host-with-remote.d.ts +2 -0
  242. package/src/generators/remote/lib/update-host-with-remote.js +64 -0
  243. package/src/generators/remote/remote.d.ts +7 -0
  244. package/src/generators/remote/remote.js +104 -0
  245. package/src/generators/remote/schema.d.ts +34 -0
  246. package/src/generators/remote/schema.json +183 -0
  247. package/src/generators/setup-ssr/files/server.ts__tmpl__ +28 -0
  248. package/src/generators/setup-ssr/files/src/main.server.tsx__tmpl__ +47 -0
  249. package/src/generators/setup-ssr/files/tsconfig.server.json__tmpl__ +17 -0
  250. package/src/generators/setup-ssr/schema.d.ts +7 -0
  251. package/src/generators/setup-ssr/schema.json +48 -0
  252. package/src/generators/setup-ssr/setup-ssr.d.ts +4 -0
  253. package/src/generators/setup-ssr/setup-ssr.js +183 -0
  254. package/src/generators/setup-tailwind/files/postcss.config.js__tmpl__ +15 -0
  255. package/src/generators/setup-tailwind/files/tailwind.config.js__tmpl__ +17 -0
  256. package/src/generators/setup-tailwind/lib/add-tailwind-style-imports.d.ts +3 -0
  257. package/src/generators/setup-tailwind/lib/add-tailwind-style-imports.js +36 -0
  258. package/src/generators/setup-tailwind/lib/update-project.d.ts +3 -0
  259. package/src/generators/setup-tailwind/lib/update-project.js +13 -0
  260. package/src/generators/setup-tailwind/schema.d.ts +6 -0
  261. package/src/generators/setup-tailwind/schema.js +2 -0
  262. package/src/generators/setup-tailwind/schema.json +47 -0
  263. package/src/generators/setup-tailwind/setup-tailwind.d.ts +4 -0
  264. package/src/generators/setup-tailwind/setup-tailwind.js +35 -0
  265. package/src/generators/stories/schema.json +67 -0
  266. package/src/generators/stories/stories.d.ts +15 -0
  267. package/src/generators/stories/stories.js +130 -0
  268. package/src/generators/storybook-configuration/configuration.d.ts +6 -0
  269. package/src/generators/storybook-configuration/configuration.js +74 -0
  270. package/src/generators/storybook-configuration/schema.d.ts +16 -0
  271. package/src/generators/storybook-configuration/schema.json +95 -0
  272. package/src/migrations/update-15-3-0/install-webpack-rollup-dependencies.d.ts +3 -0
  273. package/src/migrations/update-15-3-0/install-webpack-rollup-dependencies.js +37 -0
  274. package/src/migrations/update-15-3-0/update-rollup-executor.d.ts +3 -0
  275. package/src/migrations/update-15-3-0/update-rollup-executor.js +15 -0
  276. package/src/migrations/update-15-6-3/webpack-config-setup.d.ts +2 -0
  277. package/src/migrations/update-15-6-3/webpack-config-setup.js +103 -0
  278. package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.d.ts +2 -0
  279. package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.js +9 -0
  280. package/src/migrations/update-16-2-0-remove-package/update-16-2-0-remove-package.d.ts +2 -0
  281. package/src/migrations/update-16-2-0-remove-package/update-16-2-0-remove-package.js +8 -0
  282. package/src/migrations/update-16-3-0/remove-types-react-router-dom-package.d.ts +2 -0
  283. package/src/migrations/update-16-3-0/remove-types-react-router-dom-package.js +8 -0
  284. package/src/migrations/update-16-7-0/add-babel-core.d.ts +2 -0
  285. package/src/migrations/update-16-7-0/add-babel-core.js +14 -0
  286. package/src/migrations/update-16-7-0-add-typings/update-16-7-0-add-typings.d.ts +2 -0
  287. package/src/migrations/update-16-7-0-add-typings/update-16-7-0-add-typings.js +57 -0
  288. package/src/migrations/update-18-0-0/add-mf-env-var-to-target-defaults.d.ts +2 -0
  289. package/src/migrations/update-18-0-0/add-mf-env-var-to-target-defaults.js +26 -0
  290. package/src/module-federation/ast-utils.d.ts +8 -0
  291. package/src/module-federation/ast-utils.js +102 -0
  292. package/src/module-federation/load-config.d.ts +3 -0
  293. package/src/module-federation/load-config.js +16 -0
  294. package/src/module-federation/models.d.ts +24 -0
  295. package/src/module-federation/models.js +2 -0
  296. package/src/module-federation/package-json.d.ts +8 -0
  297. package/src/module-federation/package-json.js +13 -0
  298. package/src/module-federation/utils.d.ts +12 -0
  299. package/src/module-federation/utils.js +76 -0
  300. package/src/module-federation/with-module-federation-ssr.d.ts +2 -0
  301. package/src/module-federation/with-module-federation-ssr.js +34 -0
  302. package/src/module-federation/with-module-federation.d.ts +7 -0
  303. package/src/module-federation/with-module-federation.js +50 -0
  304. package/src/rules/add-styled-dependencies.d.ts +5 -0
  305. package/src/rules/add-styled-dependencies.js +17 -0
  306. package/src/rules/update-module-federation-project.d.ts +9 -0
  307. package/src/rules/update-module-federation-project.js +50 -0
  308. package/src/utils/add-mf-env-to-inputs.d.ts +2 -0
  309. package/src/utils/add-mf-env-to-inputs.js +24 -0
  310. package/src/utils/assertion.d.ts +1 -0
  311. package/src/utils/assertion.js +19 -0
  312. package/src/utils/ast-utils.d.ts +29 -0
  313. package/src/utils/ast-utils.js +522 -0
  314. package/src/utils/component-props.d.ts +15 -0
  315. package/src/utils/component-props.js +60 -0
  316. package/src/utils/create-ts-config.d.ts +9 -0
  317. package/src/utils/create-ts-config.js +65 -0
  318. package/src/utils/ct-utils.d.ts +14 -0
  319. package/src/utils/ct-utils.js +94 -0
  320. package/src/utils/dependencies.d.ts +7 -0
  321. package/src/utils/dependencies.js +2 -0
  322. package/src/utils/format-file.d.ts +1 -0
  323. package/src/utils/format-file.js +12 -0
  324. package/src/utils/get-in-source-vitest-tests-template.d.ts +1 -0
  325. package/src/utils/get-in-source-vitest-tests-template.js +21 -0
  326. package/src/utils/has-vite-plugin.d.ts +2 -0
  327. package/src/utils/has-vite-plugin.js +11 -0
  328. package/src/utils/has-webpack-plugin.d.ts +2 -0
  329. package/src/utils/has-webpack-plugin.js +11 -0
  330. package/src/utils/jest-utils.d.ts +1 -0
  331. package/src/utils/jest-utils.js +9 -0
  332. package/src/utils/lint.d.ts +36 -0
  333. package/src/utils/lint.js +24 -0
  334. package/src/utils/maybe-js.d.ts +3 -0
  335. package/src/utils/maybe-js.js +9 -0
  336. package/src/utils/styled.d.ts +3 -0
  337. package/src/utils/styled.js +62 -0
  338. package/src/utils/testing-generators.d.ts +3 -0
  339. package/src/utils/testing-generators.js +30 -0
  340. package/src/utils/versions.d.ts +46 -0
  341. package/src/utils/versions.js +54 -0
  342. package/tailwind.d.ts +6 -0
  343. package/tailwind.js +29 -0
  344. package/typings/cssmodule.d.ts +19 -0
  345. package/typings/image.d.ts +48 -0
  346. package/typings/style.d.ts +9 -0
  347. package/typings/styled-jsx.d.ts +8 -0
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.addStyledModuleDependencies = void 0;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const styled_1 = require("../utils/styled");
6
+ function addStyledModuleDependencies(host, options) {
7
+ const extraDependencies = options.compiler === 'swc'
8
+ ? styled_1.cssInJsDependenciesSwc[options.styledModule]
9
+ : styled_1.cssInJsDependenciesBabel[options.styledModule];
10
+ if (extraDependencies) {
11
+ return (0, devkit_1.addDependenciesToPackageJson)(host, extraDependencies.dependencies, extraDependencies.devDependencies);
12
+ }
13
+ else {
14
+ return () => { };
15
+ }
16
+ }
17
+ exports.addStyledModuleDependencies = addStyledModuleDependencies;
@@ -0,0 +1,9 @@
1
+ import { GeneratorCallback, Tree } from '@nx/devkit';
2
+ export declare function updateModuleFederationProject(host: Tree, options: {
3
+ js?: boolean;
4
+ projectName: string;
5
+ appProjectRoot: string;
6
+ devServerPort?: number;
7
+ typescriptConfiguration?: boolean;
8
+ dynamic?: boolean;
9
+ }): GeneratorCallback;
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.updateModuleFederationProject = void 0;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const versions_1 = require("../utils/versions");
6
+ const maybe_js_1 = require("../utils/maybe-js");
7
+ function updateModuleFederationProject(host, options) {
8
+ const projectConfig = (0, devkit_1.readProjectConfiguration)(host, options.projectName);
9
+ projectConfig.targets.build.options = {
10
+ ...projectConfig.targets.build.options,
11
+ main: (0, maybe_js_1.maybeJs)(options, `${options.appProjectRoot}/src/main.ts`),
12
+ webpackConfig: `${options.appProjectRoot}/webpack.config.${options.typescriptConfiguration && !options.js ? 'ts' : 'js'}`,
13
+ };
14
+ projectConfig.targets.build.configurations.production = {
15
+ ...projectConfig.targets.build.configurations.production,
16
+ webpackConfig: `${options.appProjectRoot}/webpack.config.prod.${options.typescriptConfiguration && !options.js ? 'ts' : 'js'}`,
17
+ };
18
+ // If host should be configured to use dynamic federation
19
+ if (options.dynamic) {
20
+ const pathToProdWebpackConfig = (0, devkit_1.joinPathFragments)(projectConfig.root, `webpack.prod.config.${options.typescriptConfiguration && !options.js ? 'ts' : 'js'}`);
21
+ if (host.exists(pathToProdWebpackConfig)) {
22
+ host.delete(pathToProdWebpackConfig);
23
+ }
24
+ delete projectConfig.targets.build.configurations.production?.webpackConfig;
25
+ }
26
+ projectConfig.targets.serve.executor =
27
+ '@nx/react:module-federation-dev-server';
28
+ projectConfig.targets.serve.options.port = options.devServerPort;
29
+ // `serve-static` for remotes that don't need to be in development mode
30
+ projectConfig.targets['serve-static'] = {
31
+ executor: '@nx/web:file-server',
32
+ defaultConfiguration: 'production',
33
+ options: {
34
+ buildTarget: `${options.projectName}:build`,
35
+ watch: false,
36
+ port: options.devServerPort,
37
+ },
38
+ configurations: {
39
+ development: {
40
+ buildTarget: `${options.projectName}:build:development`,
41
+ },
42
+ production: {
43
+ buildTarget: `${options.projectName}:build:production`,
44
+ },
45
+ },
46
+ };
47
+ (0, devkit_1.updateProjectConfiguration)(host, options.projectName, projectConfig);
48
+ return (0, devkit_1.addDependenciesToPackageJson)(host, {}, { '@nx/web': versions_1.nxVersion });
49
+ }
50
+ exports.updateModuleFederationProject = updateModuleFederationProject;
@@ -0,0 +1,2 @@
1
+ import { type Tree } from '@nx/devkit';
2
+ export declare function addMfEnvToTargetDefaultInputs(tree: Tree): void;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.addMfEnvToTargetDefaultInputs = void 0;
4
+ const devkit_1 = require("@nx/devkit");
5
+ function addMfEnvToTargetDefaultInputs(tree) {
6
+ const nxJson = (0, devkit_1.readNxJson)(tree);
7
+ const webpackExecutor = '@nx/webpack:webpack';
8
+ const mfEnvVar = 'NX_MF_DEV_SERVER_STATIC_REMOTES';
9
+ nxJson.targetDefaults ??= {};
10
+ nxJson.targetDefaults[webpackExecutor] ??= {};
11
+ nxJson.targetDefaults[webpackExecutor].inputs ??= [];
12
+ let mfEnvVarExists = false;
13
+ for (const input of nxJson.targetDefaults[webpackExecutor].inputs) {
14
+ if (typeof input === 'object' && input['env'] === mfEnvVar) {
15
+ mfEnvVarExists = true;
16
+ break;
17
+ }
18
+ }
19
+ if (!mfEnvVarExists) {
20
+ nxJson.targetDefaults[webpackExecutor].inputs.push({ env: mfEnvVar });
21
+ (0, devkit_1.updateNxJson)(tree, nxJson);
22
+ }
23
+ }
24
+ exports.addMfEnvToTargetDefaultInputs = addMfEnvToTargetDefaultInputs;
@@ -0,0 +1 @@
1
+ export declare function assertValidStyle(style: string): void;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.assertValidStyle = void 0;
4
+ const VALID_STYLES = [
5
+ 'css',
6
+ 'scss',
7
+ 'less',
8
+ 'tailwind',
9
+ 'styled-components',
10
+ '@emotion/styled',
11
+ 'styled-jsx',
12
+ 'none',
13
+ ];
14
+ function assertValidStyle(style) {
15
+ if (VALID_STYLES.indexOf(style) === -1) {
16
+ throw new Error(`Unsupported style option found: ${style}. Valid values are: "${VALID_STYLES.join('", "')}"`);
17
+ }
18
+ }
19
+ exports.assertValidStyle = assertValidStyle;
@@ -0,0 +1,29 @@
1
+ import type * as ts from 'typescript';
2
+ import { StringChange } from '@nx/devkit';
3
+ export declare function addImport(source: ts.SourceFile, statement: string): StringChange[];
4
+ export declare function findMainRenderStatement(source: ts.SourceFile): ts.CallExpression | null;
5
+ export declare function findDefaultExport(source: ts.SourceFile): ts.VariableDeclaration | ts.FunctionDeclaration | ts.ClassDeclaration | null;
6
+ export declare function findDefaultExportDeclaration(source: ts.SourceFile): ts.VariableDeclaration | ts.FunctionDeclaration | ts.ClassDeclaration | null;
7
+ export declare function findExportDeclarationsForJsx(source: ts.SourceFile): Array<ts.VariableDeclaration | ts.FunctionDeclaration | ts.ClassDeclaration> | null;
8
+ export declare function findDefaultExportIdentifier(source: ts.SourceFile): ts.Identifier | null;
9
+ export declare function findDefaultClassOrFunction(source: ts.SourceFile | null): ts.FunctionDeclaration | ts.ClassDeclaration | null;
10
+ export declare function findComponentImportPath(componentName: string, source: ts.SourceFile): string;
11
+ export declare function findElements(source: ts.SourceFile, tagName: string): ts.Node[];
12
+ export declare function findClosestOpening(tagName: string, node: ts.Node): ts.Node;
13
+ export declare function isTag(tagName: string, node: ts.Node): boolean;
14
+ export declare function addInitialRoutes(sourcePath: string, source: ts.SourceFile): StringChange[];
15
+ export declare function addRoute(sourcePath: string, source: ts.SourceFile, options: {
16
+ routePath: string;
17
+ componentName: string;
18
+ moduleName: string;
19
+ }): StringChange[];
20
+ export declare function addBrowserRouter(sourcePath: string, source: ts.SourceFile): StringChange[];
21
+ export declare function addStaticRouter(sourcePath: string, source: ts.SourceFile): StringChange[];
22
+ export declare function addReduxStoreToMain(sourcePath: string, source: ts.SourceFile): StringChange[];
23
+ export declare function updateReduxStore(sourcePath: string, source: ts.SourceFile, feature: {
24
+ keyName: string;
25
+ reducerName: string;
26
+ modulePath: string;
27
+ }): StringChange[];
28
+ export declare function getComponentNode(sourceFile: ts.SourceFile): ts.Node | null;
29
+ export declare function getComponentPropsInterface(sourceFile: ts.SourceFile, cmpDeclaration: ts.Node): ts.InterfaceDeclaration | null;
@@ -0,0 +1,522 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getComponentPropsInterface = exports.getComponentNode = exports.updateReduxStore = exports.addReduxStoreToMain = exports.addStaticRouter = exports.addBrowserRouter = exports.addRoute = exports.addInitialRoutes = exports.isTag = exports.findClosestOpening = exports.findElements = exports.findComponentImportPath = exports.findDefaultClassOrFunction = exports.findDefaultExportIdentifier = exports.findExportDeclarationsForJsx = exports.findDefaultExportDeclaration = exports.findDefaultExport = exports.findMainRenderStatement = exports.addImport = void 0;
4
+ const js_1 = require("@nx/js");
5
+ const devkit_1 = require("@nx/devkit");
6
+ const ensure_typescript_1 = require("@nx/js/src/utils/typescript/ensure-typescript");
7
+ let tsModule;
8
+ function addImport(source, statement) {
9
+ if (!tsModule) {
10
+ tsModule = (0, ensure_typescript_1.ensureTypescript)();
11
+ }
12
+ const allImports = (0, js_1.findNodes)(source, tsModule.SyntaxKind.ImportDeclaration);
13
+ if (allImports.length > 0) {
14
+ const lastImport = allImports[allImports.length - 1];
15
+ return [
16
+ {
17
+ type: devkit_1.ChangeType.Insert,
18
+ index: lastImport.end + 1,
19
+ text: `\n${statement}\n`,
20
+ },
21
+ ];
22
+ }
23
+ else {
24
+ return [
25
+ {
26
+ type: devkit_1.ChangeType.Insert,
27
+ index: 0,
28
+ text: `\n${statement}\n`,
29
+ },
30
+ ];
31
+ }
32
+ }
33
+ exports.addImport = addImport;
34
+ function findMainRenderStatement(source) {
35
+ if (!tsModule) {
36
+ tsModule = (0, ensure_typescript_1.ensureTypescript)();
37
+ }
38
+ // 1. Try to find ReactDOM.render.
39
+ const calls = (0, js_1.findNodes)(source, tsModule.SyntaxKind.CallExpression);
40
+ for (const expr of calls) {
41
+ const inner = expr.expression;
42
+ // React 17 and below
43
+ if (tsModule.isPropertyAccessExpression(inner) &&
44
+ /ReactDOM/i.test(inner.expression.getText()) &&
45
+ inner.name.getText() === 'render') {
46
+ return expr;
47
+ }
48
+ // React 18
49
+ if (tsModule.isPropertyAccessExpression(inner) &&
50
+ /root/.test(inner.expression.getText()) &&
51
+ inner.name.getText() === 'render') {
52
+ return expr;
53
+ }
54
+ }
55
+ // 2. Try to find render from 'react-dom'.
56
+ const imports = (0, js_1.findNodes)(source, tsModule.SyntaxKind.ImportDeclaration);
57
+ const hasRenderImport = imports.some((i) => i.moduleSpecifier.getText().includes('react-dom') &&
58
+ /\brender\b/.test(i.importClause.namedBindings.getText()));
59
+ if (hasRenderImport) {
60
+ const calls = (0, js_1.findNodes)(source, tsModule.SyntaxKind.CallExpression);
61
+ for (const expr of calls) {
62
+ if (expr.expression.getText() === 'render') {
63
+ return expr;
64
+ }
65
+ }
66
+ }
67
+ return null;
68
+ }
69
+ exports.findMainRenderStatement = findMainRenderStatement;
70
+ function findDefaultExport(source) {
71
+ return (findDefaultExportDeclaration(source) || findDefaultClassOrFunction(source));
72
+ }
73
+ exports.findDefaultExport = findDefaultExport;
74
+ function findDefaultExportDeclaration(source) {
75
+ if (!tsModule) {
76
+ tsModule = (0, ensure_typescript_1.ensureTypescript)();
77
+ }
78
+ const identifier = findDefaultExportIdentifier(source);
79
+ if (identifier) {
80
+ const variables = (0, js_1.findNodes)(source, tsModule.SyntaxKind.VariableDeclaration);
81
+ const fns = (0, js_1.findNodes)(source, tsModule.SyntaxKind.FunctionDeclaration);
82
+ const cls = (0, js_1.findNodes)(source, tsModule.SyntaxKind.ClassDeclaration);
83
+ const all = [...variables, ...fns, ...cls];
84
+ const exported = all
85
+ .filter((x) => x.name.kind === tsModule.SyntaxKind.Identifier)
86
+ .find((x) => x.name.text === identifier.text);
87
+ return exported || null;
88
+ }
89
+ else {
90
+ return null;
91
+ }
92
+ }
93
+ exports.findDefaultExportDeclaration = findDefaultExportDeclaration;
94
+ function findExportDeclarationsForJsx(source) {
95
+ if (!tsModule) {
96
+ tsModule = (0, ensure_typescript_1.ensureTypescript)();
97
+ }
98
+ const variables = (0, js_1.findNodes)(source, tsModule.SyntaxKind.VariableDeclaration);
99
+ const variableStatements = (0, js_1.findNodes)(source, tsModule.SyntaxKind.VariableStatement);
100
+ const fns = (0, js_1.findNodes)(source, tsModule.SyntaxKind.FunctionDeclaration);
101
+ const cls = (0, js_1.findNodes)(source, tsModule.SyntaxKind.ClassDeclaration);
102
+ const exportDeclarations = (0, js_1.findNodes)(source, tsModule.SyntaxKind.ExportDeclaration);
103
+ let componentNamesNodes = [];
104
+ exportDeclarations.forEach((node) => {
105
+ componentNamesNodes = [
106
+ ...componentNamesNodes,
107
+ ...(0, js_1.findNodes)(node, tsModule.SyntaxKind.ExportSpecifier),
108
+ ];
109
+ });
110
+ const componentNames = componentNamesNodes?.map((node) => node.getText());
111
+ const all = [...variables, ...variableStatements, ...fns, ...cls];
112
+ let foundExport;
113
+ let foundJSX;
114
+ const nodesContainingJSX = all.filter((x) => {
115
+ foundJSX = (0, js_1.findNodes)(x, [
116
+ tsModule.SyntaxKind.JsxSelfClosingElement,
117
+ tsModule.SyntaxKind.JsxOpeningElement,
118
+ ]);
119
+ return foundJSX?.length;
120
+ });
121
+ const exported = nodesContainingJSX.filter((x) => {
122
+ foundExport = (0, js_1.findNodes)(x, tsModule.SyntaxKind.ExportKeyword);
123
+ if (x.kind === tsModule.SyntaxKind.VariableStatement) {
124
+ const nameNode = (0, js_1.findNodes)(x, tsModule.SyntaxKind.VariableDeclaration)?.[0];
125
+ return (nameNode?.name?.kind === tsModule.SyntaxKind.Identifier ||
126
+ foundExport?.length ||
127
+ componentNames?.includes(nameNode?.name?.getText()));
128
+ }
129
+ else {
130
+ return ((x.name.kind === tsModule.SyntaxKind.Identifier &&
131
+ foundExport?.length) ||
132
+ componentNames?.includes(x.name.getText()));
133
+ }
134
+ });
135
+ const exportedDeclarations = exported.map((x) => {
136
+ if (x.kind === tsModule.SyntaxKind.VariableStatement) {
137
+ const nameNode = (0, js_1.findNodes)(x, tsModule.SyntaxKind.VariableDeclaration)?.[0];
138
+ return nameNode;
139
+ }
140
+ return x;
141
+ });
142
+ return exportedDeclarations || null;
143
+ }
144
+ exports.findExportDeclarationsForJsx = findExportDeclarationsForJsx;
145
+ function findDefaultExportIdentifier(source) {
146
+ if (!tsModule) {
147
+ tsModule = (0, ensure_typescript_1.ensureTypescript)();
148
+ }
149
+ const exports = (0, js_1.findNodes)(source, tsModule.SyntaxKind.ExportAssignment);
150
+ const identifier = exports
151
+ .map((x) => x.expression)
152
+ .find((x) => x.kind === tsModule.SyntaxKind.Identifier);
153
+ return identifier || null;
154
+ }
155
+ exports.findDefaultExportIdentifier = findDefaultExportIdentifier;
156
+ function findDefaultClassOrFunction(source) {
157
+ if (!tsModule) {
158
+ tsModule = (0, ensure_typescript_1.ensureTypescript)();
159
+ }
160
+ const fns = (0, js_1.findNodes)(source, tsModule.SyntaxKind.FunctionDeclaration);
161
+ const cls = (0, js_1.findNodes)(source, tsModule.SyntaxKind.ClassDeclaration);
162
+ return (fns.find(hasDefaultExportModifier) ||
163
+ cls.find(hasDefaultExportModifier) ||
164
+ null);
165
+ }
166
+ exports.findDefaultClassOrFunction = findDefaultClassOrFunction;
167
+ function hasDefaultExportModifier(x) {
168
+ if (!tsModule) {
169
+ tsModule = (0, ensure_typescript_1.ensureTypescript)();
170
+ }
171
+ return (x.modifiers &&
172
+ x.modifiers.some((m) => m.kind === tsModule.SyntaxKind.ExportKeyword) &&
173
+ x.modifiers.some((m) => m.kind === tsModule.SyntaxKind.DefaultKeyword));
174
+ }
175
+ function findComponentImportPath(componentName, source) {
176
+ if (!tsModule) {
177
+ tsModule = (0, ensure_typescript_1.ensureTypescript)();
178
+ }
179
+ const allImports = (0, js_1.findNodes)(source, tsModule.SyntaxKind.ImportDeclaration);
180
+ const matching = allImports.filter((i) => {
181
+ return (i.importClause &&
182
+ i.importClause.name &&
183
+ i.importClause.name.getText() === componentName);
184
+ });
185
+ if (matching.length === 0) {
186
+ return null;
187
+ }
188
+ const appImport = matching[0];
189
+ return appImport.moduleSpecifier.getText().replace(/['"]/g, '');
190
+ }
191
+ exports.findComponentImportPath = findComponentImportPath;
192
+ function findElements(source, tagName) {
193
+ if (!tsModule) {
194
+ tsModule = (0, ensure_typescript_1.ensureTypescript)();
195
+ }
196
+ const nodes = (0, js_1.findNodes)(source, [
197
+ tsModule.SyntaxKind.JsxSelfClosingElement,
198
+ tsModule.SyntaxKind.JsxOpeningElement,
199
+ ]);
200
+ return nodes.filter((node) => isTag(tagName, node));
201
+ }
202
+ exports.findElements = findElements;
203
+ function findClosestOpening(tagName, node) {
204
+ if (!node) {
205
+ return null;
206
+ }
207
+ if (isTag(tagName, node)) {
208
+ return node;
209
+ }
210
+ else {
211
+ return findClosestOpening(tagName, node.parent);
212
+ }
213
+ }
214
+ exports.findClosestOpening = findClosestOpening;
215
+ function isTag(tagName, node) {
216
+ if (!tsModule) {
217
+ tsModule = (0, ensure_typescript_1.ensureTypescript)();
218
+ }
219
+ if (tsModule.isJsxOpeningLikeElement(node)) {
220
+ return (node.tagName.kind === tsModule.SyntaxKind.Identifier &&
221
+ node.tagName.text === tagName);
222
+ }
223
+ if (tsModule.isJsxElement(node) && node.openingElement) {
224
+ return (node.openingElement.tagName.kind === tsModule.SyntaxKind.Identifier &&
225
+ node.openingElement.tagName.getText() === tagName);
226
+ }
227
+ return false;
228
+ }
229
+ exports.isTag = isTag;
230
+ function addInitialRoutes(sourcePath, source) {
231
+ if (!tsModule) {
232
+ tsModule = (0, ensure_typescript_1.ensureTypescript)();
233
+ }
234
+ const jsxClosingElements = (0, js_1.findNodes)(source, [
235
+ tsModule.SyntaxKind.JsxClosingElement,
236
+ tsModule.SyntaxKind.JsxClosingFragment,
237
+ ]);
238
+ const outerMostJsxClosing = jsxClosingElements[jsxClosingElements.length - 1];
239
+ if (!outerMostJsxClosing) {
240
+ devkit_1.logger.warn(`Could not find JSX elements in ${sourcePath}; Skipping insert routes`);
241
+ return [];
242
+ }
243
+ const insertRoutes = {
244
+ type: devkit_1.ChangeType.Insert,
245
+ index: outerMostJsxClosing.getStart(),
246
+ text: `
247
+ {/* START: routes */}
248
+ {/* These routes and navigation have been generated for you */}
249
+ {/* Feel free to move and update them to fit your needs */}
250
+ <br/>
251
+ <hr/>
252
+ <br/>
253
+ <div role="navigation">
254
+ <ul>
255
+ <li><Link to="/">Home</Link></li>
256
+ <li><Link to="/page-2">Page 2</Link></li>
257
+ </ul>
258
+ </div>
259
+ <Routes>
260
+ <Route
261
+ path="/"
262
+ element={
263
+ <div>This is the generated root route. <Link to="/page-2">Click here for page 2.</Link></div>
264
+ }
265
+ />
266
+ <Route
267
+ path="/page-2"
268
+ element={
269
+ <div><Link to="/">Click here to go back to root page.</Link></div>
270
+ }
271
+ />
272
+ </Routes>
273
+ {/* END: routes */}
274
+ `,
275
+ };
276
+ return [
277
+ ...addImport(source, `import { Route, Routes, Link } from 'react-router-dom';`),
278
+ insertRoutes,
279
+ ];
280
+ }
281
+ exports.addInitialRoutes = addInitialRoutes;
282
+ function addRoute(sourcePath, source, options) {
283
+ const routes = findElements(source, 'Route');
284
+ const links = findElements(source, 'Link');
285
+ if (routes.length === 0) {
286
+ devkit_1.logger.warn(`Could not find <Route/> components in ${sourcePath}; Skipping add route`);
287
+ return [];
288
+ }
289
+ else {
290
+ const changes = [];
291
+ const firstRoute = routes[0];
292
+ const firstLink = links[0];
293
+ changes.push(...addImport(source, `import { ${options.componentName} } from '${options.moduleName}';`));
294
+ changes.push({
295
+ type: devkit_1.ChangeType.Insert,
296
+ index: firstRoute.getEnd(),
297
+ text: `<Route path="${options.routePath}" element={<${options.componentName}/>} />`,
298
+ });
299
+ if (firstLink) {
300
+ const parentLi = findClosestOpening('li', firstLink);
301
+ if (parentLi) {
302
+ changes.push({
303
+ type: devkit_1.ChangeType.Insert,
304
+ index: parentLi.getEnd(),
305
+ text: `<li><Link to="${options.routePath}">${options.componentName}</Link></li>`,
306
+ });
307
+ }
308
+ else {
309
+ changes.push({
310
+ type: devkit_1.ChangeType.Insert,
311
+ index: firstLink.parent.getEnd(),
312
+ text: `<Link to="${options.routePath}">${options.componentName}</Link>`,
313
+ });
314
+ }
315
+ }
316
+ return changes;
317
+ }
318
+ }
319
+ exports.addRoute = addRoute;
320
+ function addBrowserRouter(sourcePath, source) {
321
+ const app = findElements(source, 'App')[0];
322
+ if (app) {
323
+ return [
324
+ ...addImport(source, `import { BrowserRouter } from 'react-router-dom';`),
325
+ {
326
+ type: devkit_1.ChangeType.Insert,
327
+ index: app.getStart(),
328
+ text: `<BrowserRouter>`,
329
+ },
330
+ {
331
+ type: devkit_1.ChangeType.Insert,
332
+ index: app.getEnd(),
333
+ text: `</BrowserRouter>`,
334
+ },
335
+ ];
336
+ }
337
+ else {
338
+ devkit_1.logger.warn(`Could not find App component in ${sourcePath}; Skipping add <BrowserRouter>`);
339
+ return [];
340
+ }
341
+ }
342
+ exports.addBrowserRouter = addBrowserRouter;
343
+ function addStaticRouter(sourcePath, source) {
344
+ const app = findElements(source, 'App')[0];
345
+ if (app) {
346
+ return [
347
+ ...addImport(source, `import { StaticRouter } from 'react-router-dom/server';`),
348
+ {
349
+ type: devkit_1.ChangeType.Insert,
350
+ index: app.getStart(),
351
+ text: `<StaticRouter location={req.originalUrl}>`,
352
+ },
353
+ {
354
+ type: devkit_1.ChangeType.Insert,
355
+ index: app.getEnd(),
356
+ text: `</StaticRouter>`,
357
+ },
358
+ ];
359
+ }
360
+ else {
361
+ devkit_1.logger.warn(`Could not find App component in ${sourcePath}; Skipping add <StaticRouter>`);
362
+ return [];
363
+ }
364
+ }
365
+ exports.addStaticRouter = addStaticRouter;
366
+ function addReduxStoreToMain(sourcePath, source) {
367
+ const renderStmt = findMainRenderStatement(source);
368
+ if (!renderStmt) {
369
+ devkit_1.logger.warn(`Could not find render(...) in ${sourcePath}`);
370
+ return [];
371
+ }
372
+ const jsx = renderStmt.arguments[0];
373
+ return [
374
+ ...addImport(source, `import { configureStore } from '@reduxjs/toolkit';
375
+ import { Provider } from 'react-redux';`),
376
+ {
377
+ type: devkit_1.ChangeType.Insert,
378
+ index: renderStmt.getStart(),
379
+ text: `
380
+ const store = configureStore({
381
+ reducer: {},
382
+ // Additional middleware can be passed to this array
383
+ middleware: getDefaultMiddleware => getDefaultMiddleware(),
384
+ devTools: process.env.NODE_ENV !== 'production',
385
+ // Optional Redux store enhancers
386
+ enhancers: [],
387
+ });
388
+
389
+ `,
390
+ },
391
+ {
392
+ type: devkit_1.ChangeType.Insert,
393
+ index: jsx.getStart(),
394
+ text: `<Provider store={store}>`,
395
+ },
396
+ {
397
+ type: devkit_1.ChangeType.Insert,
398
+ index: jsx.getEnd(),
399
+ text: `</Provider>`,
400
+ },
401
+ ];
402
+ }
403
+ exports.addReduxStoreToMain = addReduxStoreToMain;
404
+ function updateReduxStore(sourcePath, source, feature) {
405
+ if (!tsModule) {
406
+ tsModule = (0, ensure_typescript_1.ensureTypescript)();
407
+ }
408
+ const calls = (0, js_1.findNodes)(source, tsModule.SyntaxKind.CallExpression);
409
+ let reducerDescriptor;
410
+ // Look for configureStore call
411
+ for (const expr of calls) {
412
+ if (!expr.expression.getText().includes('configureStore')) {
413
+ continue;
414
+ }
415
+ const arg = expr.arguments[0];
416
+ if (tsModule.isObjectLiteralExpression(arg)) {
417
+ let found;
418
+ for (const prop of arg.properties) {
419
+ if (tsModule.isPropertyAssignment(prop) &&
420
+ prop.name.getText() === 'reducer' &&
421
+ tsModule.isObjectLiteralExpression(prop.initializer)) {
422
+ found = prop.initializer;
423
+ break;
424
+ }
425
+ }
426
+ if (found) {
427
+ reducerDescriptor = found;
428
+ break;
429
+ }
430
+ }
431
+ }
432
+ // Look for combineReducer call
433
+ if (!reducerDescriptor) {
434
+ for (const expr of calls) {
435
+ if (!expr.expression.getText().includes('combineReducer')) {
436
+ continue;
437
+ }
438
+ const arg = expr.arguments[0];
439
+ if (tsModule.isObjectLiteralExpression(arg)) {
440
+ reducerDescriptor = arg;
441
+ break;
442
+ }
443
+ }
444
+ }
445
+ if (!reducerDescriptor) {
446
+ devkit_1.logger.warn(`Could not find configureStore/combineReducer call in ${sourcePath}`);
447
+ return [];
448
+ }
449
+ return [
450
+ ...addImport(source, `import { ${feature.keyName}, ${feature.reducerName} } from '${feature.modulePath}';`),
451
+ {
452
+ type: devkit_1.ChangeType.Insert,
453
+ index: reducerDescriptor.getStart() + 1,
454
+ text: `[${feature.keyName}]: ${feature.reducerName}${reducerDescriptor.properties.length > 0 ? ',' : ''}`,
455
+ },
456
+ ];
457
+ }
458
+ exports.updateReduxStore = updateReduxStore;
459
+ function getComponentNode(sourceFile) {
460
+ if (!tsModule) {
461
+ tsModule = (0, ensure_typescript_1.ensureTypescript)();
462
+ }
463
+ const defaultExport = findDefaultExport(sourceFile);
464
+ if (!(defaultExport &&
465
+ ((0, js_1.findNodes)(defaultExport, tsModule.SyntaxKind.JsxElement).length > 0 ||
466
+ (0, js_1.findNodes)(defaultExport, tsModule.SyntaxKind.JsxSelfClosingElement)
467
+ .length > 0))) {
468
+ return null;
469
+ }
470
+ return defaultExport;
471
+ }
472
+ exports.getComponentNode = getComponentNode;
473
+ function getComponentPropsInterface(sourceFile, cmpDeclaration) {
474
+ if (!tsModule) {
475
+ tsModule = (0, ensure_typescript_1.ensureTypescript)();
476
+ }
477
+ let propsTypeName = null;
478
+ if (tsModule.isFunctionDeclaration(cmpDeclaration)) {
479
+ const propsParam = cmpDeclaration.parameters.find((x) => tsModule.isParameter(x) && x.name.text === 'props');
480
+ if (propsParam?.type?.['typeName']) {
481
+ propsTypeName = propsParam.type.typeName.text;
482
+ }
483
+ }
484
+ else if (cmpDeclaration.initializer &&
485
+ tsModule.isArrowFunction(cmpDeclaration.initializer)) {
486
+ const arrowFn = cmpDeclaration
487
+ .initializer;
488
+ const propsParam = arrowFn.parameters.find((x) => tsModule.isParameter(x) && x.name.text === 'props');
489
+ if (propsParam?.type?.['typeName']) {
490
+ propsTypeName = propsParam.type.typeName.text;
491
+ }
492
+ }
493
+ else if (
494
+ // do we have a class component extending from React.Component
495
+ tsModule.isClassDeclaration(cmpDeclaration) &&
496
+ cmpDeclaration.heritageClauses &&
497
+ cmpDeclaration.heritageClauses.length > 0) {
498
+ const heritageClause = cmpDeclaration.heritageClauses[0];
499
+ if (heritageClause) {
500
+ const propsTypeExpression = heritageClause.types.find((x) => {
501
+ const name = x.expression.escapedText ||
502
+ x.expression.name.text;
503
+ return name === 'Component' || name === 'PureComponent';
504
+ });
505
+ if (propsTypeExpression?.typeArguments?.[0]?.['typeName']) {
506
+ propsTypeName = propsTypeExpression.typeArguments[0].typeName.getText();
507
+ }
508
+ }
509
+ }
510
+ else {
511
+ return null;
512
+ }
513
+ if (propsTypeName) {
514
+ return (0, js_1.findNodes)(sourceFile, tsModule.SyntaxKind.InterfaceDeclaration).find((x) => {
515
+ return x.name.getText() === propsTypeName;
516
+ });
517
+ }
518
+ else {
519
+ return null;
520
+ }
521
+ }
522
+ exports.getComponentPropsInterface = getComponentPropsInterface;