@nx/react 0.0.0-pr-31222-862e973 → 0.0.0-pr-31313-387cdca

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 (306) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +1 -1
  3. package/generators.json +9 -13
  4. package/index.d.ts +1 -2
  5. package/index.js +2 -5
  6. package/mf/dynamic-federation.d.ts +64 -0
  7. package/mf/dynamic-federation.js +64 -0
  8. package/migrations.json +80 -148
  9. package/module-federation.d.ts +6 -4
  10. package/module-federation.js +16 -7
  11. package/package.json +11 -11
  12. package/plugins/bundle-rollup.js +4 -1
  13. package/plugins/component-testing/index.js +1 -1
  14. package/plugins/jest.js +6 -11
  15. package/plugins/nx-react-webpack-plugin/lib/apply-react-config.js +6 -22
  16. package/plugins/storybook/index.js +1 -2
  17. package/plugins/with-react.d.ts +4 -0
  18. package/router-plugin.d.ts +1 -0
  19. package/router-plugin.js +5 -0
  20. package/src/executors/module-federation-dev-server/lib/index.d.ts +2 -0
  21. package/src/executors/module-federation-dev-server/lib/index.js +5 -0
  22. package/src/executors/module-federation-dev-server/lib/normalize-options.d.ts +4 -0
  23. package/src/executors/module-federation-dev-server/lib/normalize-options.js +19 -0
  24. package/src/executors/module-federation-dev-server/lib/start-remotes.d.ts +5 -0
  25. package/src/executors/module-federation-dev-server/lib/start-remotes.js +33 -0
  26. package/src/executors/module-federation-dev-server/module-federation-dev-server.impl.d.ts +1 -1
  27. package/src/executors/module-federation-dev-server/module-federation-dev-server.impl.js +6 -110
  28. package/src/executors/module-federation-dev-server/schema.d.ts +9 -7
  29. package/src/executors/module-federation-dev-server/schema.json +15 -10
  30. package/src/executors/module-federation-ssr-dev-server/lib/index.d.ts +2 -0
  31. package/src/executors/module-federation-ssr-dev-server/lib/index.js +5 -0
  32. package/src/executors/module-federation-ssr-dev-server/lib/normalize-options.d.ts +4 -0
  33. package/src/executors/module-federation-ssr-dev-server/lib/normalize-options.js +23 -0
  34. package/src/executors/module-federation-ssr-dev-server/lib/start-remotes.d.ts +5 -0
  35. package/src/executors/module-federation-ssr-dev-server/lib/start-remotes.js +34 -0
  36. package/src/executors/module-federation-ssr-dev-server/module-federation-ssr-dev-server.impl.d.ts +1 -17
  37. package/src/executors/module-federation-ssr-dev-server/module-federation-ssr-dev-server.impl.js +5 -153
  38. package/src/executors/module-federation-ssr-dev-server/schema.d.ts +29 -0
  39. package/src/executors/module-federation-ssr-dev-server/schema.json +14 -9
  40. package/src/executors/module-federation-static-server/module-federation-static-server.impl.d.ts +2 -2
  41. package/src/executors/module-federation-static-server/module-federation-static-server.impl.js +11 -12
  42. package/src/executors/module-federation-static-server/schema.json +2 -1
  43. package/src/generators/application/application.d.ts +3 -3
  44. package/src/generators/application/application.js +108 -186
  45. package/src/generators/application/files/base-rsbuild/src/app/__fileName__.spec.tsx__tmpl__ +10 -0
  46. package/src/generators/application/files/base-rsbuild/src/assets/.gitkeep +0 -0
  47. package/src/generators/application/files/base-rsbuild/src/favicon.ico +0 -0
  48. package/src/generators/application/files/base-rsbuild/src/index.html +14 -0
  49. package/src/generators/application/files/base-rsbuild/src/main.tsx__tmpl__ +32 -0
  50. package/src/generators/application/files/base-rsbuild/tsconfig.app.json__tmpl__ +31 -0
  51. package/src/generators/application/files/base-rspack/rspack.config.js__tmpl__ +53 -0
  52. package/src/generators/application/files/base-rspack/src/app/__fileName__.spec.tsx__tmpl__ +3 -3
  53. package/src/generators/application/files/base-rspack/src/main.tsx__tmpl__ +27 -5
  54. package/src/generators/application/files/base-rspack/tsconfig.app.json__tmpl__ +21 -4
  55. package/src/generators/application/files/base-vite/src/app/__fileName__.spec.tsx__tmpl__ +3 -3
  56. package/src/generators/application/files/base-vite/src/main.tsx__tmpl__ +31 -6
  57. package/src/generators/application/files/base-vite/tsconfig.app.json__tmpl__ +20 -3
  58. package/src/generators/application/files/base-webpack/src/app/__fileName__.spec.tsx__tmpl__ +3 -3
  59. package/src/generators/application/files/base-webpack/src/main.tsx__tmpl__ +22 -2
  60. package/src/generators/application/files/base-webpack/tsconfig.app.json__tmpl__ +21 -4
  61. package/src/generators/application/files/base-webpack/webpack.config.js__tmpl__ +4 -4
  62. package/src/generators/application/files/react-router-ssr/common/app/app-nav.tsx__tmpl__ +14 -0
  63. package/src/generators/application/files/react-router-ssr/common/app/entry.client.tsx__tmpl__ +18 -0
  64. package/src/generators/application/files/react-router-ssr/common/app/entry.server.tsx__tmpl__ +74 -0
  65. package/src/generators/application/files/react-router-ssr/common/app/root.tsx__tmpl__ +51 -0
  66. package/src/generators/application/files/react-router-ssr/common/app/routes/about.tsx__tmpl__ +7 -0
  67. package/src/generators/application/files/react-router-ssr/common/app/routes.tsx__tmpl__ +6 -0
  68. package/src/generators/application/files/react-router-ssr/common/public/favicon.ico +0 -0
  69. package/src/generators/application/files/react-router-ssr/common/react-router.config.ts__tmpl__ +5 -0
  70. package/src/generators/application/files/react-router-ssr/common/tests/routes/_index.spec.tsx__tmpl__ +16 -0
  71. package/src/generators/application/files/react-router-ssr/common/tsconfig.app.json__tmpl__ +23 -0
  72. package/src/generators/application/files/react-router-ssr/common/tsconfig.json__tmpl__ +27 -0
  73. package/src/generators/application/files/react-router-ssr/non-root/.gitignore__tmpl__ +5 -0
  74. package/src/generators/application/files/react-router-ssr/non-root/package.json__tmpl__ +21 -0
  75. package/src/generators/application/files/react-router-ssr/nx-welcome/claimed/app/nx-welcome.tsx__tmpl__ +866 -0
  76. package/src/generators/application/files/react-router-ssr/nx-welcome/not-configured/app/nx-welcome.tsx__tmpl__ +866 -0
  77. package/src/generators/application/files/react-router-ssr/nx-welcome/unclaimed/app/nx-welcome.tsx__tmpl__ +864 -0
  78. package/src/generators/application/files/react-router-ssr/ts-solution/package.json__tmpl__ +21 -0
  79. package/src/generators/application/files/react-router-ssr/ts-solution/tsconfig.app.json__tmpl__ +39 -0
  80. package/src/generators/application/files/style-css-module/src/app/__fileName__.tsx__tmpl__ +28 -18
  81. package/src/generators/application/files/style-global-css/src/app/__fileName__.tsx__tmpl__ +29 -20
  82. package/src/generators/application/files/style-none/src/app/__fileName__.tsx__tmpl__ +26 -16
  83. package/src/generators/application/files/style-styled-jsx/src/app/__fileName__.tsx__tmpl__ +31 -22
  84. package/src/generators/application/files/style-styled-module/src/app/__fileName__.tsx__tmpl__ +30 -21
  85. package/src/generators/application/files/style-tailwind/src/app/__fileName__.tsx__tmpl__ +29 -19
  86. package/src/generators/application/lib/add-e2e.d.ts +1 -1
  87. package/src/generators/application/lib/add-e2e.js +74 -65
  88. package/src/generators/application/lib/add-jest.js +27 -2
  89. package/src/generators/application/lib/add-linting.d.ts +4 -0
  90. package/src/generators/application/lib/add-linting.js +86 -0
  91. package/src/generators/application/lib/add-project.js +112 -6
  92. package/src/generators/application/lib/add-routing.js +1 -1
  93. package/src/generators/application/lib/bundlers/add-rsbuild.d.ts +4 -0
  94. package/src/generators/application/lib/bundlers/add-rsbuild.js +63 -0
  95. package/src/generators/application/lib/bundlers/add-rspack.d.ts +4 -0
  96. package/src/generators/application/lib/bundlers/add-rspack.js +37 -0
  97. package/src/generators/application/lib/bundlers/add-vite.d.ts +4 -0
  98. package/src/generators/application/lib/bundlers/add-vite.js +76 -0
  99. package/src/generators/application/lib/bundlers/add-webpack.d.ts +3 -0
  100. package/src/generators/application/lib/bundlers/add-webpack.js +18 -0
  101. package/src/generators/application/lib/create-application-files.d.ts +61 -0
  102. package/src/generators/application/lib/create-application-files.js +102 -19
  103. package/src/generators/application/lib/get-app-tests.js +10 -11
  104. package/src/generators/application/lib/install-common-dependencies.d.ts +1 -1
  105. package/src/generators/application/lib/install-common-dependencies.js +18 -4
  106. package/src/generators/application/lib/normalize-options.d.ts +1 -3
  107. package/src/generators/application/lib/normalize-options.js +17 -19
  108. package/src/generators/application/lib/update-jest-config.js +5 -0
  109. package/src/generators/application/schema.d.ts +12 -6
  110. package/src/generators/application/schema.json +44 -42
  111. package/src/generators/component/component.d.ts +0 -1
  112. package/src/generators/component/component.js +19 -37
  113. package/src/generators/component/files/__fileName__.__ext__ +83 -0
  114. package/src/generators/component/lib/normalize-options.js +13 -15
  115. package/src/generators/component/schema.d.ts +13 -25
  116. package/src/generators/component/schema.json +13 -49
  117. package/src/generators/component-story/component-story.js +1 -2
  118. package/src/generators/component-story/files/jsx/__componentFileName__.stories.jsx__tmpl__ +5 -5
  119. package/src/generators/component-story/files/tsx/__componentFileName__.stories.tsx__tmpl__ +3 -4
  120. package/src/generators/component-test/component-test.js +1 -1
  121. package/src/generators/cypress-component-configuration/cypress-component-configuration.js +0 -2
  122. package/src/generators/cypress-component-configuration/lib/add-files.d.ts +1 -1
  123. package/src/generators/cypress-component-configuration/lib/add-files.js +7 -4
  124. package/src/generators/federate-module/federate-module.js +12 -22
  125. package/src/generators/federate-module/schema.d.ts +0 -1
  126. package/src/generators/federate-module/schema.json +13 -12
  127. package/src/generators/hook/files/{__fileName__.ts__tmpl__ → __fileName__.__ext__} +3 -1
  128. package/src/generators/hook/hook.d.ts +0 -1
  129. package/src/generators/hook/hook.js +35 -83
  130. package/src/generators/hook/schema.d.ts +4 -17
  131. package/src/generators/hook/schema.json +19 -46
  132. package/src/generators/host/files/common/src/app/__fileName__.js__tmpl__ +28 -21
  133. package/src/generators/host/files/common/src/main.js__tmpl__ +12 -9
  134. package/src/generators/host/files/common-ts/src/app/__fileName__.tsx__tmpl__ +28 -28
  135. package/src/generators/host/files/common-ts/src/main.ts__tmpl__ +12 -9
  136. package/src/generators/host/files/rspack-common/src/app/__fileName__.jsx__tmpl__ +22 -13
  137. package/src/generators/host/files/rspack-common/src/main.jsx__tmpl__ +12 -9
  138. package/src/generators/host/files/rspack-module-federation/module-federation.config.js__tmpl__ +8 -5
  139. package/src/generators/host/files/rspack-module-federation/rspack.config.js__tmpl__ +37 -13
  140. package/src/generators/host/files/rspack-module-federation/rspack.config.prod.js__tmpl__ +60 -30
  141. package/src/generators/host/files/rspack-module-federation-ssr/module-federation.server.config.js__tmpl__ +16 -5
  142. package/src/generators/host/files/rspack-module-federation-ssr/rspack.config.js__tmpl__ +66 -0
  143. package/src/generators/host/files/rspack-module-federation-ssr/server.ts__tmpl__ +1 -1
  144. package/src/generators/host/files/rspack-module-federation-ssr/src/main.server.tsx__tmpl__ +49 -0
  145. package/src/generators/host/files/rspack-module-federation-ssr-ts/module-federation.server.config.ts__tmpl__ +16 -7
  146. package/src/generators/host/files/rspack-module-federation-ssr-ts/rspack.config.ts__tmpl__ +66 -0
  147. package/src/generators/host/files/rspack-module-federation-ssr-ts/server.ts__tmpl__ +1 -1
  148. package/src/generators/host/files/rspack-module-federation-ssr-ts/src/main.server.tsx__tmpl__ +49 -0
  149. package/src/generators/host/files/rspack-module-federation-ts/module-federation.config.ts__tmpl__ +22 -19
  150. package/src/generators/host/files/rspack-module-federation-ts/rspack.config.prod.ts__tmpl__ +61 -30
  151. package/src/generators/host/files/rspack-module-federation-ts/rspack.config.ts__tmpl__ +37 -13
  152. package/src/generators/host/files/webpack-module-federation/module-federation.config.js__tmpl__ +8 -5
  153. package/src/generators/host/files/webpack-module-federation/webpack.config.js__tmpl__ +1 -1
  154. package/src/generators/host/files/webpack-module-federation/webpack.config.prod.js__tmpl__ +24 -22
  155. package/src/generators/host/files/webpack-module-federation-ssr/module-federation.server.config.js__tmpl__ +10 -7
  156. package/src/generators/host/files/webpack-module-federation-ssr/webpack.server.config.js__tmpl__ +2 -2
  157. package/src/generators/host/files/webpack-module-federation-ssr-ts/module-federation.server.config.ts__tmpl__ +10 -7
  158. package/src/generators/host/files/webpack-module-federation-ssr-ts/webpack.server.config.ts__tmpl__ +2 -2
  159. package/src/generators/host/files/webpack-module-federation-ts/module-federation.config.ts__tmpl__ +22 -19
  160. package/src/generators/host/files/webpack-module-federation-ts/webpack.config.prod.ts__tmpl__ +25 -23
  161. package/src/generators/host/files/webpack-module-federation-ts/webpack.config.ts__tmpl__ +4 -3
  162. package/src/generators/host/host.d.ts +0 -1
  163. package/src/generators/host/host.js +31 -27
  164. package/src/generators/host/lib/add-module-federation-files.js +29 -13
  165. package/src/generators/host/lib/normalize-host-name.d.ts +2 -0
  166. package/src/generators/host/lib/normalize-host-name.js +12 -0
  167. package/src/generators/host/lib/normalize-remote.js +10 -6
  168. package/src/generators/host/lib/setup-ssr-for-host.d.ts +3 -3
  169. package/src/generators/host/lib/setup-ssr-for-host.js +46 -22
  170. package/src/generators/host/lib/update-module-federation-tsconfig.d.ts +3 -0
  171. package/src/generators/host/lib/update-module-federation-tsconfig.js +39 -0
  172. package/src/generators/host/schema.d.ts +2 -5
  173. package/src/generators/host/schema.json +16 -27
  174. package/src/generators/init/init.d.ts +1 -1
  175. package/src/generators/init/init.js +31 -6
  176. package/src/generators/init/schema.d.ts +2 -0
  177. package/src/generators/library/files/common/tsconfig.lib.json__tmpl__ +1 -1
  178. package/src/generators/library/files/vite/tsconfig.lib.json__tmpl__ +1 -1
  179. package/src/generators/library/lib/add-linting.js +1 -1
  180. package/src/generators/library/lib/add-rollup-build-target.d.ts +3 -1
  181. package/src/generators/library/lib/add-rollup-build-target.js +34 -32
  182. package/src/generators/library/lib/create-files.d.ts +1 -1
  183. package/src/generators/library/lib/create-files.js +23 -2
  184. package/src/generators/library/lib/determine-entry-fields.d.ts +3 -0
  185. package/src/generators/library/lib/determine-entry-fields.js +22 -0
  186. package/src/generators/library/lib/install-common-dependencies.d.ts +1 -1
  187. package/src/generators/library/lib/install-common-dependencies.js +5 -3
  188. package/src/generators/library/lib/normalize-options.js +11 -6
  189. package/src/generators/library/library.js +80 -35
  190. package/src/generators/library/schema.d.ts +5 -5
  191. package/src/generators/library/schema.json +38 -36
  192. package/src/generators/redux/files/js/__fileName__.__ext__ +114 -0
  193. package/src/generators/redux/files/{__fileName__.slice.spec.ts__tmpl__ → js/__fileName__.spec.__ext__} +1 -1
  194. package/src/generators/redux/files/ts/__fileName__.spec.__ext__ +56 -0
  195. package/src/generators/redux/redux.d.ts +0 -1
  196. package/src/generators/redux/redux.js +27 -36
  197. package/src/generators/redux/schema.d.ts +12 -8
  198. package/src/generators/redux/schema.json +21 -23
  199. package/src/generators/remote/files/rspack-module-federation/module-federation.config.js__tmpl__ +10 -7
  200. package/src/generators/remote/files/rspack-module-federation/rspack.config.js__tmpl__ +40 -13
  201. package/src/generators/remote/files/rspack-module-federation-ssr/module-federation.server.config.js__tmpl__ +13 -4
  202. package/src/generators/remote/files/rspack-module-federation-ssr/rspack.config.js__tmpl__ +69 -0
  203. package/src/generators/remote/files/rspack-module-federation-ssr/server.ts__tmpl__ +2 -2
  204. package/src/generators/remote/files/rspack-module-federation-ssr/src/main.server.tsx__tmpl__ +45 -0
  205. package/src/generators/remote/files/rspack-module-federation-ssr-ts/module-federation.server.config.ts__tmpl__ +13 -4
  206. package/src/generators/remote/files/rspack-module-federation-ssr-ts/rspack.config.ts__tmpl__ +69 -0
  207. package/src/generators/remote/files/rspack-module-federation-ssr-ts/server.ts__tmpl__ +2 -2
  208. package/src/generators/remote/files/rspack-module-federation-ssr-ts/src/main.server.tsx__tmpl__ +45 -0
  209. package/src/generators/remote/files/rspack-module-federation-ts/module-federation.config.ts__tmpl__ +11 -8
  210. package/src/generators/remote/files/rspack-module-federation-ts/rspack.config.ts__tmpl__ +40 -13
  211. package/src/generators/remote/files/webpack-module-federation/module-federation.config.js__tmpl__ +10 -7
  212. package/src/generators/remote/files/webpack-module-federation/webpack.config.js__tmpl__ +1 -1
  213. package/src/generators/remote/files/webpack-module-federation-ssr/module-federation.server.config.js__tmpl__ +7 -4
  214. package/src/generators/remote/files/webpack-module-federation-ssr/webpack.server.config.js__tmpl__ +2 -2
  215. package/src/generators/remote/files/webpack-module-federation-ssr-ts/module-federation.server.config.ts__tmpl__ +8 -5
  216. package/src/generators/remote/files/webpack-module-federation-ssr-ts/webpack.server.config.ts__tmpl__ +2 -2
  217. package/src/generators/remote/files/webpack-module-federation-ts/module-federation.config.ts__tmpl__ +11 -8
  218. package/src/generators/remote/files/webpack-module-federation-ts/webpack.config.ts__tmpl__ +2 -2
  219. package/src/generators/remote/lib/setup-ssr-for-remote.d.ts +1 -1
  220. package/src/generators/remote/lib/setup-ssr-for-remote.js +37 -15
  221. package/src/generators/remote/lib/setup-tspath-for-remote.js +1 -3
  222. package/src/generators/remote/lib/update-host-with-remote.js +2 -2
  223. package/src/generators/remote/remote.d.ts +0 -1
  224. package/src/generators/remote/remote.js +57 -33
  225. package/src/generators/remote/schema.d.ts +2 -5
  226. package/src/generators/remote/schema.json +16 -27
  227. package/src/generators/setup-tailwind/lib/update-project.js +1 -2
  228. package/src/generators/stories/schema.json +0 -10
  229. package/src/generators/stories/stories.d.ts +1 -3
  230. package/src/generators/stories/stories.js +9 -20
  231. package/src/generators/storybook-configuration/configuration.js +2 -11
  232. package/src/generators/storybook-configuration/schema.d.ts +0 -3
  233. package/src/generators/storybook-configuration/schema.json +0 -15
  234. package/src/migrations/update-18-0-0/add-mf-env-var-to-target-defaults.js +11 -6
  235. package/src/migrations/update-20-2-0/migrate-mf-imports-to-new-package.d.ts +2 -0
  236. package/src/migrations/update-20-2-0/migrate-mf-imports-to-new-package.js +66 -0
  237. package/src/migrations/update-20-2-0/migrate-with-mf-import-to-new-package.d.ts +2 -0
  238. package/src/migrations/update-20-2-0/migrate-with-mf-import-to-new-package.js +41 -0
  239. package/src/migrations/update-20-3-0/ensure-nx-module-federation-package.d.ts +2 -0
  240. package/src/migrations/update-20-3-0/ensure-nx-module-federation-package.js +18 -0
  241. package/src/migrations/update-21-0-0/update-babel-loose.d.ts +2 -0
  242. package/src/migrations/update-21-0-0/update-babel-loose.js +30 -0
  243. package/src/plugins/router-plugin.d.ts +10 -0
  244. package/src/plugins/router-plugin.js +221 -0
  245. package/src/rules/update-module-federation-project.d.ts +2 -1
  246. package/src/rules/update-module-federation-project.js +37 -48
  247. package/src/utils/add-mf-env-to-inputs.d.ts +1 -1
  248. package/src/utils/add-mf-env-to-inputs.js +8 -11
  249. package/src/utils/assertion.d.ts +2 -0
  250. package/src/utils/assertion.js +6 -0
  251. package/src/utils/ast-utils.d.ts +1 -1
  252. package/src/utils/ast-utils.js +2 -2
  253. package/src/utils/create-ts-config.js +57 -7
  254. package/src/utils/ct-utils.d.ts +1 -1
  255. package/src/utils/ct-utils.js +2 -7
  256. package/src/utils/has-rsbuild-plugin.d.ts +2 -0
  257. package/src/utils/has-rsbuild-plugin.js +10 -0
  258. package/src/utils/has-rspack-plugin.d.ts +2 -0
  259. package/src/utils/has-rspack-plugin.js +10 -0
  260. package/src/utils/testing-generators.js +2 -4
  261. package/src/utils/version-utils.d.ts +14 -0
  262. package/src/utils/version-utils.js +56 -0
  263. package/src/utils/versions.d.ts +25 -17
  264. package/src/utils/versions.js +28 -19
  265. package/src/generators/component/files/__fileName__.tsx__tmpl__ +0 -84
  266. package/src/generators/component-cypress-spec/component-cypress-spec.d.ts +0 -13
  267. package/src/generators/component-cypress-spec/component-cypress-spec.js +0 -104
  268. package/src/generators/component-cypress-spec/files/__componentName__.__fileExt__ +0 -13
  269. package/src/generators/component-cypress-spec/schema.json +0 -45
  270. package/src/generators/host/files/rspack-module-federation-ssr/rspack.server.config.js__tmpl__ +0 -16
  271. package/src/generators/host/files/rspack-module-federation-ssr-ts/rspack.server.config.ts__tmpl__ +0 -16
  272. package/src/generators/library/files/common/package.json__tmpl__ +0 -4
  273. package/src/generators/library/files/vite/package.json__tmpl__ +0 -12
  274. package/src/generators/remote/files/rspack-module-federation-ssr/rspack.server.config.js__tmpl__ +0 -16
  275. package/src/generators/remote/files/rspack-module-federation-ssr-ts/rspack.server.config.ts__tmpl__ +0 -16
  276. package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.d.ts +0 -2
  277. package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.js +0 -9
  278. package/src/migrations/update-16-2-0-remove-package/update-16-2-0-remove-package.d.ts +0 -2
  279. package/src/migrations/update-16-2-0-remove-package/update-16-2-0-remove-package.js +0 -8
  280. package/src/migrations/update-16-3-0/remove-types-react-router-dom-package.d.ts +0 -2
  281. package/src/migrations/update-16-3-0/remove-types-react-router-dom-package.js +0 -8
  282. package/src/migrations/update-16-7-0/add-babel-core.d.ts +0 -2
  283. package/src/migrations/update-16-7-0/add-babel-core.js +0 -14
  284. package/src/migrations/update-16-7-0-add-typings/update-16-7-0-add-typings.d.ts +0 -2
  285. package/src/migrations/update-16-7-0-add-typings/update-16-7-0-add-typings.js +0 -57
  286. package/src/migrations/update-18-1-1/fix-target-defaults-inputs.d.ts +0 -2
  287. package/src/migrations/update-18-1-1/fix-target-defaults-inputs.js +0 -53
  288. package/src/module-federation/load-config.d.ts +0 -3
  289. package/src/module-federation/load-config.js +0 -15
  290. package/src/module-federation/models.d.ts +0 -24
  291. package/src/module-federation/models.js +0 -2
  292. package/src/module-federation/package-json.d.ts +0 -8
  293. package/src/module-federation/package-json.js +0 -12
  294. package/src/module-federation/utils.d.ts +0 -12
  295. package/src/module-federation/utils.js +0 -75
  296. package/src/module-federation/with-module-federation-ssr.d.ts +0 -2
  297. package/src/module-federation/with-module-federation-ssr.js +0 -50
  298. package/src/module-federation/with-module-federation.d.ts +0 -7
  299. package/src/module-federation/with-module-federation.js +0 -63
  300. package/src/utils/build-static.remotes.d.ts +0 -4
  301. package/src/utils/build-static.remotes.js +0 -65
  302. package/src/utils/format-file.d.ts +0 -1
  303. package/src/utils/format-file.js +0 -11
  304. /package/src/generators/component/files/{__fileName__.spec.tsx__tmpl__ → __fileName__.spec.__ext__} +0 -0
  305. /package/src/generators/hook/files/{__fileName__.spec.tsx__tmpl__ → __fileName__.spec.__specExt__} +0 -0
  306. /package/src/generators/redux/files/{__fileName__.slice.ts__tmpl__ → ts/__fileName__.__ext__} +0 -0
@@ -1,12 +1,14 @@
1
1
  import { useState, useCallback } from 'react'
2
2
 
3
+ <%_ if (isTs) { _%>
3
4
  // eslint-disable-next-line @typescript-eslint/no-empty-interface
4
5
  export interface <%= hookTypeName %> {
5
6
  count: number;
6
7
  increment: () => void;
7
8
  }
9
+ <%_ } _%>
8
10
 
9
- export function <%= hookName %>(): <%= hookTypeName %> {
11
+ export function <%= hookName %>()<% if (isTs) { %>: <%= hookTypeName %><% } %> {
10
12
  const [count, setCount] = useState(0)
11
13
  const increment = useCallback(() => setCount((x) => x + 1), [])
12
14
  return { count, increment }
@@ -1,5 +1,4 @@
1
1
  import { Tree } from '@nx/devkit';
2
2
  import { Schema } from './schema';
3
3
  export declare function hookGenerator(host: Tree, schema: Schema): Promise<void>;
4
- export declare function hookGeneratorInternal(host: Tree, schema: Schema): Promise<void>;
5
4
  export default hookGenerator;
@@ -1,41 +1,29 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.hookGenerator = hookGenerator;
4
- exports.hookGeneratorInternal = hookGeneratorInternal;
5
4
  // TODO(jack): Remove inline renderHook function when RTL releases with its own version
6
5
  const devkit_1 = require("@nx/devkit");
7
- const ast_utils_1 = require("../../utils/ast-utils");
6
+ const artifact_name_and_directory_utils_1 = require("@nx/devkit/src/generators/artifact-name-and-directory-utils");
8
7
  const ensure_typescript_1 = require("@nx/js/src/utils/typescript/ensure-typescript");
9
8
  const path_1 = require("path");
10
- const artifact_name_and_directory_utils_1 = require("@nx/devkit/src/generators/artifact-name-and-directory-utils");
9
+ const ast_utils_1 = require("../../utils/ast-utils");
10
+ const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
11
11
  async function hookGenerator(host, schema) {
12
- return hookGeneratorInternal(host, {
13
- nameAndDirectoryFormat: 'derived',
14
- ...schema,
15
- });
16
- }
17
- async function hookGeneratorInternal(host, schema) {
18
12
  const options = await normalizeOptions(host, schema);
19
13
  createFiles(host, options);
20
14
  addExportsToBarrel(host, options);
21
15
  return await (0, devkit_1.formatFiles)(host);
22
16
  }
23
17
  function createFiles(host, options) {
18
+ const specExt = options.fileExtensionType === 'ts' ? 'tsx' : 'js';
24
19
  (0, devkit_1.generateFiles)(host, (0, path_1.join)(__dirname, './files'), options.directory, {
25
20
  ...options,
26
- tmpl: '',
21
+ ext: options.fileExtension,
22
+ specExt,
23
+ isTs: options.fileExtensionType === 'ts',
27
24
  });
28
- for (const c of host.listChanges()) {
29
- let deleteFile = false;
30
- if (options.skipTests && /.*spec.ts/.test(c.path)) {
31
- deleteFile = true;
32
- }
33
- if (deleteFile) {
34
- host.delete(c.path);
35
- }
36
- }
37
- if (options.js) {
38
- (0, devkit_1.toJS)(host);
25
+ if (options.skipTests) {
26
+ host.delete((0, devkit_1.joinPathFragments)(options.directory, `${options.fileName}.spec.${specExt}`));
39
27
  }
40
28
  }
41
29
  let tsModule;
@@ -46,85 +34,49 @@ function addExportsToBarrel(host, options) {
46
34
  const workspace = (0, devkit_1.getProjects)(host);
47
35
  const isApp = workspace.get(options.projectName).projectType === 'application';
48
36
  if (options.export && !isApp) {
49
- const indexFilePath = (0, devkit_1.joinPathFragments)(options.projectSourceRoot, options.js ? 'index.js' : 'index.ts');
50
- const indexSource = host.read(indexFilePath, 'utf-8');
51
- if (indexSource !== null) {
52
- const indexSourceFile = tsModule.createSourceFile(indexFilePath, indexSource, tsModule.ScriptTarget.Latest, true);
53
- const changes = (0, devkit_1.applyChangesToString)(indexSource, (0, ast_utils_1.addImport)(indexSourceFile, `export * from './${options.directory}/${options.fileName}';`));
54
- host.write(indexFilePath, changes);
37
+ const indexFilePath = (0, devkit_1.joinPathFragments)(options.projectSourceRoot, options.fileExtensionType === 'js' ? 'index.js' : 'index.ts');
38
+ if (!host.exists(indexFilePath)) {
39
+ return;
55
40
  }
41
+ const indexSource = host.read(indexFilePath, 'utf-8');
42
+ const indexSourceFile = tsModule.createSourceFile(indexFilePath, indexSource, tsModule.ScriptTarget.Latest, true);
43
+ const changes = (0, devkit_1.applyChangesToString)(indexSource, (0, ast_utils_1.addImport)(indexSourceFile, `export * from './${options.directory}/${options.fileName}';`));
44
+ host.write(indexFilePath, changes);
56
45
  }
57
46
  }
58
47
  async function normalizeOptions(host, options) {
59
- assertValidOptions(options);
60
- const { artifactName: name, directory: _directory, fileName: _fileName, nameAndDirectoryFormat, project: projectName, } = await (0, artifact_name_and_directory_utils_1.determineArtifactNameAndDirectoryOptions)(host, {
61
- artifactType: 'hook',
62
- callingGenerator: '@nx/react:hook',
48
+ const { artifactName, directory, fileName: hookFilename, fileExtension, fileExtensionType, project: projectName, } = await (0, artifact_name_and_directory_utils_1.determineArtifactNameAndDirectoryOptions)(host, {
49
+ path: options.path,
63
50
  name: options.name,
64
- directory: options.directory,
65
- derivedDirectory: options.directory,
66
- flat: options.flat,
67
- nameAndDirectoryFormat: options.nameAndDirectoryFormat,
68
- project: options.project,
69
- fileExtension: 'tsx',
70
- pascalCaseFile: options.pascalCaseFiles,
71
- pascalCaseDirectory: options.pascalCaseDirectory,
51
+ allowedFileExtensions: ['js', 'ts'],
52
+ fileExtension: options.js ? 'js' : 'ts',
53
+ js: options.js,
72
54
  });
73
- let base = _fileName;
74
- if (base.startsWith('use-')) {
75
- base = base.substring(4);
76
- }
77
- else if (base.startsWith('use')) {
78
- base = base.substring(3);
79
- }
80
- const { className, fileName } = (0, devkit_1.names)(base);
81
- // If using `as-provided` file and directory, then don't normalize.
82
- // Otherwise, support legacy behavior of prefixing filename with `use-`.
83
- const hookFilename = nameAndDirectoryFormat === 'as-provided'
84
- ? fileName
85
- : options.pascalCaseFiles
86
- ? 'use'.concat(className)
87
- : 'use-'.concat(fileName);
88
- const hookName = 'use'.concat(className);
89
- const hookTypeName = 'Use'.concat(className);
55
+ const { className } = (0, devkit_1.names)(hookFilename);
56
+ // if name is provided, use it as is for the hook name, otherwise prepend
57
+ // `use` to the pascal-cased file name if it doesn't already start with `use`
58
+ const hookName = options.name
59
+ ? artifactName
60
+ : className.toLocaleLowerCase().startsWith('use')
61
+ ? className
62
+ : `use${className}`;
63
+ const hookTypeName = (0, devkit_1.names)(hookName).className;
90
64
  const project = (0, devkit_1.getProjects)(host).get(projectName);
91
- const { sourceRoot: projectSourceRoot, projectType } = project;
92
- if (options.export && projectType === 'application') {
65
+ const { root, sourceRoot: projectSourceRoot, projectType } = project;
66
+ if (options.export &&
67
+ (0, ts_solution_setup_1.getProjectType)(host, root, projectType) === 'application') {
93
68
  devkit_1.logger.warn(`The "--export" option should not be used with applications and will do nothing.`);
94
69
  }
95
- // Support legacy behavior of derived directory to prefix with `use-`.
96
- let directory = _directory;
97
- if (nameAndDirectoryFormat === 'derived') {
98
- const parts = directory.split('/');
99
- parts.pop();
100
- if (!options.flat) {
101
- parts.push(options.pascalCaseDirectory
102
- ? 'use'.concat(className)
103
- : 'use-'.concat(fileName));
104
- }
105
- directory = parts.join('/');
106
- }
107
70
  return {
108
71
  ...options,
109
72
  directory,
110
73
  hookName,
111
74
  hookTypeName,
112
75
  fileName: hookFilename,
76
+ fileExtension,
77
+ fileExtensionType,
113
78
  projectSourceRoot,
114
79
  projectName,
115
80
  };
116
81
  }
117
- function assertValidOptions(options) {
118
- const slashes = ['/', '\\'];
119
- slashes.forEach((s) => {
120
- if (options.name.indexOf(s) !== -1) {
121
- const [name, ...rest] = options.name.split(s).reverse();
122
- let suggestion = rest.map((x) => x.toLowerCase()).join(s);
123
- if (options.directory) {
124
- suggestion = `${options.directory}${s}${suggestion}`;
125
- }
126
- throw new Error(`Found "${s}" in the hook name. Did you mean to use the --directory option (e.g. \`nx g c ${name} --directory ${suggestion}\`)?`);
127
- }
128
- });
129
- }
130
82
  exports.default = hookGenerator;
@@ -1,24 +1,11 @@
1
1
  export interface Schema {
2
- name: string;
3
- /**
4
- * @deprecated Provide the `directory` option instead and use the `as-provided` format. The project will be determined from the directory provided. It will be removed in Nx v20.
5
- */
6
- project: string;
2
+ path: string;
3
+ name?: string;
7
4
  skipTests?: boolean;
8
- directory?: string;
9
5
  export?: boolean;
6
+
10
7
  /**
11
- * @deprecated Provide the `name` option instead and use the `as-provided` format. This option will be removed in Nx v19.
12
- */
13
- pascalCaseFiles?: boolean;
14
- /**
15
- * @deprecated Provide the `directory` option instead and use the `as-provided` format. This option will be removed in Nx v19.
16
- */
17
- pascalCaseDirectory?: boolean;
18
- /**
19
- * @deprecated Provide the `directory` option instead and use the `as-provided` format. This option will be removed in Nx v19.
8
+ * @deprecated Provide the full file path including the file extension in the `path` option. This option will be removed in Nx v21.
20
9
  */
21
- flat?: boolean;
22
10
  js?: boolean;
23
- nameAndDirectoryFormat?: 'as-provided' | 'derived';
24
11
  }
@@ -7,34 +7,37 @@
7
7
  "type": "object",
8
8
  "examples": [
9
9
  {
10
- "command": "nx g hook my-hook --project=mylib",
11
- "description": "Generate a hook in the `mylib` library"
10
+ "description": "Generate a hook with the exported symbol matching the file name. It results in the hook `useFoo` at `mylib/src/lib/foo.ts`",
11
+ "command": "nx g @nx/react:hook mylib/src/lib/foo.ts"
12
+ },
13
+ {
14
+ "description": "Generate a hook with the exported symbol different from the file name. It results in the hook `useCustom` at `mylib/src/lib/foo.ts`",
15
+ "command": "nx g @nx/react:hook mylib/src/lib/foo.ts --name=useCustom"
16
+ },
17
+ {
18
+ "description": "Generate a hook without providing the file extension. It results in the hook `useFoo` at `mylib/src/lib/foo.ts`",
19
+ "command": "nx g @nx/react:hook mylib/src/lib/foo"
12
20
  }
13
21
  ],
14
22
  "properties": {
15
- "project": {
23
+ "path": {
16
24
  "type": "string",
17
- "description": "The name of the project.",
18
- "alias": "p",
19
- "$default": {
20
- "$source": "projectName"
21
- },
22
- "x-deprecated": "Provide the `directory` option instead and use the `as-provided` format. The project will be determined from the directory provided. It will be removed in Nx v20."
23
- },
24
- "name": {
25
- "type": "string",
26
- "description": "The name of the hook.",
25
+ "description": "The file path to the hook. Relative to the current working directory.",
27
26
  "$default": {
28
27
  "$source": "argv",
29
28
  "index": 0
30
29
  },
31
- "x-prompt": "What name would you like to use for the hook?",
30
+ "x-prompt": "What is the hook file path?",
32
31
  "x-priority": "important"
33
32
  },
33
+ "name": {
34
+ "type": "string",
35
+ "description": "The hook symbol name. Defaults to the last segment of the file path."
36
+ },
34
37
  "js": {
35
38
  "type": "boolean",
36
39
  "description": "Generate JavaScript files rather than TypeScript files.",
37
- "default": false
40
+ "x-deprecated": "Provide the full file path including the file extension in the `path` option. This option will be removed in Nx v21."
38
41
  },
39
42
  "skipTests": {
40
43
  "type": "boolean",
@@ -42,43 +45,13 @@
42
45
  "default": false,
43
46
  "x-priority": "internal"
44
47
  },
45
- "directory": {
46
- "type": "string",
47
- "description": "The directory at which to create the hook file. When `--nameAndDirectoryFormat=as-provided`, it will be relative to the current working directory. Otherwise, it will be relative to the project root.",
48
- "x-priority": "important"
49
- },
50
- "nameAndDirectoryFormat": {
51
- "description": "Whether to generate the component in the directory as provided, relative to the current working directory and ignoring the project (`as-provided`) or generate it using the project and directory relative to the workspace root (`derived`).",
52
- "type": "string",
53
- "enum": ["as-provided", "derived"]
54
- },
55
- "flat": {
56
- "type": "boolean",
57
- "description": "Create hook at the source root rather than its own directory.",
58
- "default": false,
59
- "x-deprecated": "Provide the `directory` option instead and use the `as-provided` format. It will be removed in Nx v20."
60
- },
61
48
  "export": {
62
49
  "type": "boolean",
63
50
  "description": "When true, the hook is exported from the project `index.ts` (if it exists).",
64
51
  "alias": "e",
65
52
  "default": false,
66
53
  "x-prompt": "Should this hook be exported in the project?"
67
- },
68
- "pascalCaseFiles": {
69
- "type": "boolean",
70
- "description": "Use pascal case hook file name (e.g. `useHook.ts`).",
71
- "alias": "P",
72
- "default": false,
73
- "x-deprecated": "Provide the `name` in pascal-case and use the `as-provided` format. This option will be removed in Nx v19."
74
- },
75
- "pascalCaseDirectory": {
76
- "type": "boolean",
77
- "description": "Use pascal case directory name (e.g. `useHook/useHook.ts`).",
78
- "alias": "R",
79
- "default": false,
80
- "x-deprecated": "Provide the `directory` in pascal-case and use the `as-provided` format. This option will be removed in Nx v19."
81
54
  }
82
55
  },
83
- "required": ["name"]
56
+ "required": ["path"]
84
57
  }
@@ -1,31 +1,38 @@
1
1
  import * as React from 'react';
2
- <% if (!minimal) { %>
2
+ <%_ if (!minimal) { _%>
3
3
  import NxWelcome from "./nx-welcome";
4
- <% } %>
4
+ <%_ } _%>
5
5
  import { Link, Route, Routes } from 'react-router-dom';
6
+ <%_ if (dynamic) { _%>
7
+ import { loadRemote } from '@module-federation/enhanced/runtime';
8
+ <%_ } _%>
6
9
 
7
- <% if (remotes.length > 0) { %>
8
- <% remotes.forEach(function(r) { %>
9
- const <%= r.className %> = React.lazy(() => import('<%= r.fileName %>/Module'));
10
- <% }); %>
11
- <% } %>
10
+ <%_ if (remotes.length > 0) {
11
+ remotes.forEach(function(r) { _%>
12
+ <%_ if (dynamic) { _%>
13
+ const <%= r.className %> = React.lazy(() => loadRemote('<%= r.fileName %>/Module') as any)
14
+ <%_ } else { _%>
15
+ const <%= r.className %> = React.lazy(() => import('<%= r.fileName %>/Module'));
16
+ <%_ } _%>
17
+ <%_ }); _%>
18
+ <%_ } _%>
12
19
  export function App() {
13
20
  return (
14
21
  <React.Suspense fallback={null}>
15
- <ul>
16
- <li><Link to="/">Home</Link></li>
17
- <% remotes.forEach(function(r) { %>
18
- <li><Link to="/<%=r.fileName%>"><%=r.className%></Link></li>
19
- <% }); %>
20
- </ul>
21
- <Routes>
22
- <% if (!minimal) { %>
23
- <Route path="/" element={<NxWelcome title="<%= projectName %>"/>} />
24
- <% } %>
25
- <% remotes.forEach(function(r) { %>
26
- <Route path="/<%=r.fileName%>" element={<<%= r.className %>/>} />
27
- <% }); %>
28
- </Routes>
22
+ <ul>
23
+ <li><Link to="/">Home</Link></li>
24
+ <%_ remotes.forEach(function(r) { _%>
25
+ <li><Link to="/<%=r.fileName%>"><%=r.className%></Link></li>
26
+ <%_ }); _%>
27
+ </ul>
28
+ <Routes>
29
+ <%_ if (!minimal) { _%>
30
+ <Route path="/" element={<NxWelcome title="<%= projectName %>"/>} />
31
+ <%_ } _%>
32
+ <%_ remotes.forEach(function(r) { _%>
33
+ <Route path="/<%=r.fileName%>" element={<<%= r.className %>/>} />
34
+ <%_ }); _%>
35
+ </Routes>
29
36
  </React.Suspense>
30
37
  );
31
38
  }
@@ -1,10 +1,13 @@
1
- <% if (dynamic) { %>
2
- import { setRemoteDefinitions } from '@nx/react/mf';
1
+ <%_ if (dynamic) { _%>
2
+ import { init } from '@module-federation/enhanced/runtime';
3
3
 
4
- fetch('/assets/module-federation.manifest.json')
5
- .then((res) => res.json())
6
- .then(definitions => setRemoteDefinitions(definitions))
7
- .then(() => import('./bootstrap').catch(err => console.error(err)));
8
- <% } else { %>
9
- import('./bootstrap').catch(err => console.error(err));
10
- <% } %>
4
+ fetch('/assets/module-federation.manifest.json')
5
+ .then((res) => res.json())
6
+ .then((remotes: Record<string, string>) =>
7
+ Object.entries(remotes).map(([name, entry]) => ({ name, entry }))
8
+ )
9
+ .then((remotes) => init({ name: '<%= projectName %>', remotes }))
10
+ .then(() => import('./bootstrap').catch(err => console.error(err)));
11
+ <%_ } else { _%>
12
+ import('./bootstrap').catch(err => console.error(err));
13
+ <%_ } _%>
@@ -1,39 +1,39 @@
1
1
  import * as React from 'react';
2
- <% if (!minimal) { %>
2
+ <%_ if (!minimal) { _%>
3
3
  import NxWelcome from "./nx-welcome";
4
- <% } %>
4
+ <%_ } _%>
5
5
  import { Link, Route, Routes } from 'react-router-dom';
6
- <% if (dynamic) { %>
7
- import { loadRemoteModule } from '@nx/react/mf';
8
- <% } %>
6
+ <%_ if (dynamic) { _%>
7
+ import { loadRemote } from '@module-federation/enhanced/runtime';
8
+ <%_ } _%>
9
9
 
10
- <% if (remotes.length > 0) { %>
11
- <% remotes.forEach(function(r) { %>
12
- <% if (dynamic) { %>
13
- const <%= r.className %> = React.lazy(() => loadRemoteModule('<%= r.fileName %>', './Module'))
14
- <% } else { %>
15
- const <%= r.className %> = React.lazy(() => import('<%= r.fileName %>/Module'));
16
- <% } %>
17
- <% }); %>
18
- <% } %>
10
+ <%_ if (remotes.length > 0) {
11
+ remotes.forEach(function(r) { _%>
12
+ <%_ if (dynamic) { _%>
13
+ const <%= r.className %> = React.lazy(() => loadRemote('<%= r.fileName %>/Module') as any)
14
+ <%_ } else { _%>
15
+ const <%= r.className %> = React.lazy(() => import('<%= r.fileName %>/Module'));
16
+ <%_ } _%>
17
+ <%_ }); _%>
18
+ <%_ } _%>
19
19
 
20
20
  export function App() {
21
21
  return (
22
22
  <React.Suspense fallback={null}>
23
- <ul>
24
- <li><Link to="/">Home</Link></li>
25
- <% remotes.forEach(function(r) { %>
26
- <li><Link to="/<%=r.fileName%>"><%=r.className%></Link></li>
27
- <% }); %>
28
- </ul>
29
- <Routes>
30
- <% if (!minimal) { %>
31
- <Route path="/" element={<NxWelcome title="<%= projectName %>"/>} />
32
- <% } %>
33
- <% remotes.forEach(function(r) { %>
34
- <Route path="/<%=r.fileName%>" element={<<%= r.className %>/>} />
35
- <% }); %>
36
- </Routes>
23
+ <ul>
24
+ <li><Link to="/">Home</Link></li>
25
+ <%_ remotes.forEach(function(r) { _%>
26
+ <li><Link to="/<%=r.fileName%>"><%=r.className%></Link></li>
27
+ <%_ }); _%>
28
+ </ul>
29
+ <Routes>
30
+ <%_ if (!minimal) { _%>
31
+ <Route path="/" element={<NxWelcome title="<%= projectName %>"/>} />
32
+ <%_ } _%>
33
+ <%_ remotes.forEach(function(r) { _%>
34
+ <Route path="/<%=r.fileName%>" element={<<%= r.className %>/>} />
35
+ <%_ }); _%>
36
+ </Routes>
37
37
  </React.Suspense>
38
38
  );
39
39
  }
@@ -1,10 +1,13 @@
1
- <% if (dynamic) { %>
2
- import { setRemoteDefinitions } from '@nx/react/mf';
1
+ <%_ if (dynamic) { _%>
2
+ import { init } from '@module-federation/enhanced/runtime';
3
3
 
4
- fetch('/assets/module-federation.manifest.json')
5
- .then((res) => res.json())
6
- .then(definitions => setRemoteDefinitions(definitions))
7
- .then(() => import('./bootstrap').catch(err => console.error(err)));
8
- <% } else { %>
9
- import('./bootstrap').catch(err => console.error(err));
10
- <% } %>
4
+ fetch('/assets/module-federation.manifest.json')
5
+ .then((res) => res.json())
6
+ .then((remotes: Record<string, string>) =>
7
+ Object.entries(remotes).map(([name, entry]) => ({ name, entry }))
8
+ )
9
+ .then((remotes) => init({ name: '<%= projectName %>', remotes }))
10
+ .then(() => import('./bootstrap').catch(err => console.error(err)));
11
+ <%_ } else { _%>
12
+ import('./bootstrap').catch(err => console.error(err));
13
+ <%_ } _%>
@@ -1,30 +1,39 @@
1
1
  import * as React from 'react';
2
- <% if (!minimal) { %>
2
+ <%_ if (!minimal) { _%>
3
3
  import NxWelcome from "./nx-welcome";
4
- <% } %>
4
+ <%_ } _%>
5
5
  import { Link, Route, Routes } from 'react-router-dom';
6
6
 
7
- <% if (remotes.length > 0) { %>
8
- <% remotes.forEach(function(r) { %>
9
- const <%= r.className %> = React.lazy(() => import('<%= r.fileName %>/Module'));
10
- <% }); %>
11
- <% } %>
7
+ <%_ if (dynamic) { _%>
8
+ import { loadRemote } from '@module-federation/enhanced/runtime';
9
+ <%_ } _%>
10
+
11
+ <%_ if (remotes.length > 0) {
12
+ remotes.forEach(function(r) { _%>
13
+ <%_ if (dynamic) { _%>
14
+ const <%= r.className %> = React.lazy(() => loadRemote('<%= r.fileName %>/Module') as any)
15
+ <%_ } else { _%>
16
+ const <%= r.className %> = React.lazy(() => import('<%= r.fileName %>/Module'));
17
+ <%_ } _%>
18
+ <%_ }); _%>
19
+ <%_ } _%>
20
+
12
21
  export function App() {
13
22
  return (
14
23
  <React.Suspense fallback={null}>
15
24
  <ul>
16
25
  <li><Link to="/">Home</Link></li>
17
- <% remotes.forEach(function(r) { %>
26
+ <%_ remotes.forEach(function(r) { _%>
18
27
  <li><Link to="/<%=r.fileName%>"><%=r.className%></Link></li>
19
- <% }); %>
28
+ <%_ }); _%>
20
29
  </ul>
21
30
  <Routes>
22
- <% if (!minimal) { %>
31
+ <%_ if (!minimal) { _%>
23
32
  <Route path="/" element={<NxWelcome title="<%= projectName %>"/>} />
24
- <% } %>
25
- <% remotes.forEach(function(r) { %>
33
+ <%_ } _%>
34
+ <%_ remotes.forEach(function(r) { _%>
26
35
  <Route path="/<%=r.fileName%>" element={<<%= r.className %>/>} />
27
- <% }); %>
36
+ <%_ }); _%>
28
37
  </Routes>
29
38
  </React.Suspense>
30
39
  );
@@ -1,10 +1,13 @@
1
- <% if (dynamic) { %>
2
- import { setRemoteDefinitions } from '@nx/react/mf';
1
+ <%_ if (dynamic) { _%>
2
+ import { init } from '@module-federation/enhanced/runtime';
3
3
 
4
- fetch('/assets/module-federation.manifest.json')
5
- .then((res) => res.json())
6
- .then(definitions => setRemoteDefinitions(definitions))
7
- .then(() => import('./bootstrap').catch(err => console.error(err)));
8
- <% } else { %>
9
- import('./bootstrap').catch(err => console.error(err));
10
- <% } %>
4
+ fetch('/assets/module-federation.manifest.json')
5
+ .then((res) => res.json())
6
+ .then((remotes: Record<string, string>) =>
7
+ Object.entries(remotes).map(([name, entry]) => ({ name, entry }))
8
+ )
9
+ .then((remotes) => init({ name: '<%= projectName %>', remotes }))
10
+ .then(() => import('./bootstrap').catch(err => console.error(err)));
11
+ <%_ } else { _%>
12
+ import('./bootstrap').catch(err => console.error(err));
13
+ <%_ } _%>
@@ -1,3 +1,6 @@
1
+ /**
2
+ * Nx requires a default export of the config to allow correct resolution of the module federation graph.
3
+ **/
1
4
  module.exports = {
2
5
  name: '<%= projectName %>',
3
6
  /**
@@ -13,9 +16,9 @@ module.exports = {
13
16
  *
14
17
  */
15
18
  remotes: [
16
- <% if (static) {
17
- remotes.forEach(function(r) { %> "<%= r.fileName %>", <% });
18
- }
19
- %>
19
+ <%_ if (static) {
20
+ remotes.forEach(function(r) { %>
21
+ "<%= r.fileName %>",
22
+ <%_ }); } _%>
20
23
  ],
21
- };
24
+ };
@@ -1,16 +1,40 @@
1
- const { composePlugins, withNx, withReact } = require('@nx/rspack');
2
- const { withModuleFederation } = require('@nx/rspack/module-federation');
1
+ const { NxAppRspackPlugin } = require('@nx/rspack/app-plugin');
2
+ const { NxReactRspackPlugin } = require('@nx/rspack/react-plugin');
3
+ const { NxModuleFederationPlugin, NxModuleFederationDevServerPlugin } = require('@nx/module-federation/rspack');
4
+ const { join } = require('path');
3
5
 
4
- const baseConfig = require('./module-federation.config');
6
+ const config = require('./module-federation.config');
5
7
 
6
- const config = {
7
- ...baseConfig,
8
+ module.exports = {
9
+ output: {
10
+ path: join(__dirname, '<%= rspackPluginOptions.outputPath %>'),
11
+ publicPath: 'auto'
12
+ },
13
+ devServer: {
14
+ port: <%= devServerPort %>,
15
+ historyApiFallback: {
16
+ index: '/index.html',
17
+ disableDotRule: true,
18
+ htmlAcceptHeaders: ['text/html', 'application/xhtml+xml'],
19
+ },
20
+ },
21
+ plugins: [
22
+ new NxAppRspackPlugin({
23
+ tsConfig: '<%= rspackPluginOptions.tsConfig %>',
24
+ main: '<%= rspackPluginOptions.main %>',
25
+ index: '<%= rspackPluginOptions.index %>',
26
+ baseHref: '<%= rspackPluginOptions.baseHref %>',
27
+ assets: <%- JSON.stringify(rspackPluginOptions.assets) %>,
28
+ styles: <%- JSON.stringify(rspackPluginOptions.styles) %>,
29
+ outputHashing: process.env['NODE_ENV'] === 'production' ? 'all' : 'none',
30
+ optimization: process.env['NODE_ENV'] === 'production',
31
+ }),
32
+ new NxReactRspackPlugin({
33
+ // Uncomment this line if you don't want to use SVGR
34
+ // See: https://react-svgr.com/
35
+ // svgr: false
36
+ }),
37
+ new NxModuleFederationPlugin({ config }, { dts: false }),
38
+ new NxModuleFederationDevServerPlugin({ config }),
39
+ ],
8
40
  };
9
-
10
- // Nx plugins for rspack to build config object from Nx options and context.
11
- /**
12
- * DTS Plugin is disabled in Nx Workspaces as Nx already provides Typing support for Module Federation
13
- * The DTS Plugin can be enabled by setting dts: true
14
- * Learn more about the DTS Plugin here: https://module-federation.io/configure/dts.html
15
- */
16
- module.exports = composePlugins(withNx(), withReact(), withModuleFederation(config, { dts: false }));