@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,36 @@
1
+ import type { Meta, StoryObj } from '@storybook/react';
2
+ import { <%= componentName %> } from './<%= componentImportFileName %>';
3
+ <% if ( interactionTests ) { %>
4
+ import { within } from '@storybook/testing-library';
5
+ import { expect } from '@storybook/jest';
6
+ <% } %>
7
+
8
+ const meta: Meta<typeof <%= componentName %>> = {
9
+ component: <%= componentName %>,
10
+ title: '<%= componentName %>',<% if ( argTypes && argTypes.length > 0 ) { %>
11
+ argTypes: {<% for (let argType of argTypes) { %>
12
+ <%= argType.name %>: { <%- argType.type %> : "<%- argType.actionText %>" },<% } %>
13
+ }
14
+ <% } %>
15
+ };
16
+ export default meta;
17
+ type Story = StoryObj<typeof <%= componentName %>>;
18
+
19
+
20
+ export const Primary = {
21
+ args: {<% for (let prop of props) { %>
22
+ <%= prop.name %>: <%- prop.defaultValue %>,<% } %>
23
+ },
24
+ };
25
+
26
+ <% if ( interactionTests ) { %>
27
+ export const Heading: Story = {
28
+ args: {<% for (let prop of props) { %>
29
+ <%= prop.name %>: <%- prop.defaultValue %>,<% } %>
30
+ },
31
+ play: async ({ canvasElement }) => {
32
+ const canvas = within(canvasElement);
33
+ expect(canvas.getByText(/Welcome to <%=componentName%>!/gi)).toBeTruthy();
34
+ },
35
+ };
36
+ <% } %>
@@ -0,0 +1,42 @@
1
+ {
2
+ "$schema": "https://json-schema.org/schema",
3
+ "cli": "nx",
4
+ "$id": "NxReactComponentStory",
5
+ "title": "Create component story",
6
+ "description": "Generate storybook story for a react component.",
7
+ "type": "object",
8
+ "properties": {
9
+ "project": {
10
+ "type": "string",
11
+ "aliases": ["name", "projectName"],
12
+ "description": "The project where to add the components.",
13
+ "examples": ["shared-ui-component"],
14
+ "$default": {
15
+ "$source": "projectName",
16
+ "index": 0
17
+ },
18
+ "x-prompt": "What's name of the project where the component lives?",
19
+ "x-priority": "important"
20
+ },
21
+ "componentPath": {
22
+ "type": "string",
23
+ "description": "Relative path to the component file from the library root.",
24
+ "examples": ["lib/components"],
25
+ "x-prompt": "What's path of the component relative to the project's lib root?",
26
+ "x-priority": "important"
27
+ },
28
+ "skipFormat": {
29
+ "description": "Skip formatting files.",
30
+ "type": "boolean",
31
+ "default": false,
32
+ "x-priority": "internal"
33
+ },
34
+ "interactionTests": {
35
+ "type": "boolean",
36
+ "description": "Set up Storybook interaction tests.",
37
+ "default": true,
38
+ "x-priority": "important"
39
+ }
40
+ },
41
+ "required": ["project", "componentPath"]
42
+ }
@@ -0,0 +1,4 @@
1
+ import { Tree } from '@nx/devkit';
2
+ import { ComponentTestSchema } from './schema';
3
+ export declare function componentTestGenerator(tree: Tree, options: ComponentTestSchema): Promise<void>;
4
+ export default componentTestGenerator;
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.componentTestGenerator = void 0;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const path_1 = require("path");
6
+ const ast_utils_1 = require("../../utils/ast-utils");
7
+ const component_props_1 = require("../../utils/component-props");
8
+ const versions_1 = require("../../utils/versions");
9
+ const ensure_typescript_1 = require("@nx/js/src/utils/typescript/ensure-typescript");
10
+ let tsModule;
11
+ async function componentTestGenerator(tree, options) {
12
+ (0, devkit_1.ensurePackage)('@nx/cypress', versions_1.nxVersion);
13
+ const { assertMinimumCypressVersion } = await Promise.resolve().then(() => require('@nx/cypress/src/utils/cypress-version'));
14
+ assertMinimumCypressVersion(10);
15
+ // normalize any windows paths
16
+ options.componentPath = options.componentPath.replace(/\\/g, '/');
17
+ const projectConfig = (0, devkit_1.readProjectConfiguration)(tree, options.project);
18
+ const normalizedPath = options.componentPath.startsWith(projectConfig.sourceRoot)
19
+ ? (0, path_1.relative)(projectConfig.sourceRoot, options.componentPath)
20
+ : options.componentPath;
21
+ const componentPath = (0, devkit_1.joinPathFragments)(projectConfig.sourceRoot, normalizedPath);
22
+ if (tree.exists(componentPath)) {
23
+ generateSpecsForComponents(tree, componentPath);
24
+ }
25
+ }
26
+ exports.componentTestGenerator = componentTestGenerator;
27
+ function generateSpecsForComponents(tree, filePath) {
28
+ if (!tsModule) {
29
+ tsModule = (0, ensure_typescript_1.ensureTypescript)();
30
+ }
31
+ const sourceFile = tsModule.createSourceFile(filePath, tree.read(filePath, 'utf-8'), tsModule.ScriptTarget.Latest, true);
32
+ const cmpNodes = (0, ast_utils_1.findExportDeclarationsForJsx)(sourceFile);
33
+ const componentDir = (0, path_1.dirname)(filePath);
34
+ const ext = (0, path_1.extname)(filePath);
35
+ const fileName = (0, path_1.basename)(filePath, ext);
36
+ if (tree.exists((0, devkit_1.joinPathFragments)(componentDir, `${fileName}.cy${ext}`))) {
37
+ return;
38
+ }
39
+ const defaultExport = (0, ast_utils_1.getComponentNode)(sourceFile);
40
+ if (cmpNodes?.length) {
41
+ const components = cmpNodes.map((cmp) => {
42
+ const defaults = (0, component_props_1.getDefaultsForComponent)(sourceFile, cmp);
43
+ const isDefaultExport = defaultExport
44
+ ? defaultExport.name.text === cmp.name.text
45
+ : false;
46
+ return {
47
+ isDefaultExport,
48
+ props: [...defaults.props, ...defaults.argTypes],
49
+ name: cmp.name.text,
50
+ typeName: defaults.propsTypeName,
51
+ };
52
+ });
53
+ const namedImports = components
54
+ .reduce((imports, cmp) => {
55
+ if (cmp.typeName) {
56
+ imports.push(cmp.typeName);
57
+ }
58
+ if (cmp.isDefaultExport) {
59
+ return imports;
60
+ }
61
+ imports.push(cmp.name);
62
+ return imports;
63
+ }, [])
64
+ .join(', ');
65
+ const namedImportStatement = namedImports.length > 0 ? `, { ${namedImports} }` : '';
66
+ (0, devkit_1.generateFiles)(tree, (0, path_1.join)(__dirname, 'files'), componentDir, {
67
+ fileName,
68
+ components,
69
+ importStatement: defaultExport
70
+ ? `import ${defaultExport.name.text}${namedImportStatement} from './${fileName}'`
71
+ : `import { ${namedImports} } from './${fileName}'`,
72
+ ext,
73
+ });
74
+ }
75
+ }
76
+ exports.default = componentTestGenerator;
@@ -0,0 +1,21 @@
1
+ import * as React from 'react'
2
+ <%- importStatement %>
3
+
4
+ <% for (let cmp of components) { %>
5
+ describe(<%= cmp.name %>.name, () => {<% if (cmp.typeName) { %>
6
+ let props: <%= cmp.typeName%>;
7
+
8
+ beforeEach(() => {
9
+ props = {<% for (let prop of cmp.props) { %>
10
+ <%- prop.name %>: <% if(prop.type === 'action') { %>undefined<% } else { %><%- prop.defaultValue %>,<% } %><% }%>
11
+ }
12
+ })
13
+
14
+ it('renders', () => {
15
+ cy.mount(<<%= cmp.name %> {...props}/>)
16
+ })<% } else { %>
17
+ it('renders', () => {
18
+ cy.mount(<<%= cmp.name %> />)
19
+ })<% } %>
20
+ })
21
+ <% } %>
@@ -0,0 +1,4 @@
1
+ export interface ComponentTestSchema {
2
+ project: string;
3
+ componentPath: string;
4
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,31 @@
1
+ {
2
+ "$schema": "https://json-schema.org/schema",
3
+ "cli": "nx",
4
+ "$id": "NxReactCypressComponentTest",
5
+ "title": "Add Cypress component test",
6
+ "description": "Add a Cypress component test for a component.",
7
+ "type": "object",
8
+ "examples": [
9
+ {
10
+ "command": "nx g @nx/react:component-test --project=my-react-project --component-path=src/lib/fancy-component.tsx",
11
+ "description": "Create a cypress component test for FancyComponent"
12
+ }
13
+ ],
14
+ "properties": {
15
+ "project": {
16
+ "type": "string",
17
+ "description": "The name of the project the component is apart of",
18
+ "x-dropdown": "projects",
19
+ "x-prompt": "What project is this component apart of?",
20
+ "x-priority": "important"
21
+ },
22
+ "componentPath": {
23
+ "type": "string",
24
+ "description": "Path to component, from the project source root",
25
+ "x-prompt": "What is the path to the component?",
26
+ "x-priority": "important"
27
+ }
28
+ },
29
+ "required": ["project", "componentPath"],
30
+ "examplesFile": "../../../docs/component-test-examples.md"
31
+ }
@@ -0,0 +1,10 @@
1
+ import { Tree } from '@nx/devkit';
2
+ import { CypressComponentConfigurationSchema } from './schema.d';
3
+ export declare function cypressComponentConfigGenerator(tree: Tree, options: CypressComponentConfigurationSchema): Promise<import("@nx/devkit").GeneratorCallback>;
4
+ /**
5
+ * This is for using cypresses own Component testing, if you want to use test
6
+ * storybook components then use componentCypressGenerator instead.
7
+ *
8
+ */
9
+ export declare function cypressComponentConfigGeneratorInternal(tree: Tree, options: CypressComponentConfigurationSchema): Promise<import("@nx/devkit").GeneratorCallback>;
10
+ export default cypressComponentConfigGenerator;
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.cypressComponentConfigGeneratorInternal = exports.cypressComponentConfigGenerator = void 0;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const versions_1 = require("../../utils/versions");
6
+ const add_files_1 = require("./lib/add-files");
7
+ const ct_utils_1 = require("../../utils/ct-utils");
8
+ function cypressComponentConfigGenerator(tree, options) {
9
+ return cypressComponentConfigGeneratorInternal(tree, {
10
+ addPlugin: false,
11
+ ...options,
12
+ });
13
+ }
14
+ exports.cypressComponentConfigGenerator = cypressComponentConfigGenerator;
15
+ /**
16
+ * This is for using cypresses own Component testing, if you want to use test
17
+ * storybook components then use componentCypressGenerator instead.
18
+ *
19
+ */
20
+ async function cypressComponentConfigGeneratorInternal(tree, options) {
21
+ const { componentConfigurationGenerator: baseCyCtConfig } = (0, devkit_1.ensurePackage)('@nx/cypress', versions_1.nxVersion);
22
+ const nxJson = (0, devkit_1.readNxJson)(tree);
23
+ const addPlugin = process.env.NX_ADD_PLUGINS !== 'false' &&
24
+ nxJson.useInferencePlugins !== false;
25
+ options.addPlugin ??= addPlugin;
26
+ const projectConfig = (0, devkit_1.readProjectConfiguration)(tree, options.project);
27
+ const installTask = await baseCyCtConfig(tree, {
28
+ project: options.project,
29
+ skipFormat: true,
30
+ jsx: true,
31
+ addPlugin: options.addPlugin,
32
+ });
33
+ const found = await (0, ct_utils_1.configureCypressCT)(tree, {
34
+ project: options.project,
35
+ buildTarget: options.buildTarget,
36
+ bundler: options.bundler,
37
+ validExecutorNames: new Set([
38
+ '@nx/webpack:webpack',
39
+ '@nx/vite:build',
40
+ '@nrwl/webpack:webpack',
41
+ '@nrwl/vite:build',
42
+ ]),
43
+ });
44
+ await (0, add_files_1.addFiles)(tree, projectConfig, options, found);
45
+ if (!options.skipFormat) {
46
+ await (0, devkit_1.formatFiles)(tree);
47
+ }
48
+ return installTask;
49
+ }
50
+ exports.cypressComponentConfigGeneratorInternal = cypressComponentConfigGeneratorInternal;
51
+ exports.default = cypressComponentConfigGenerator;
@@ -0,0 +1,4 @@
1
+ import { ProjectConfiguration, Tree } from '@nx/devkit';
2
+ import type { CypressComponentConfigurationSchema } from '../schema';
3
+ import { FoundTarget } from '@nx/cypress/src/utils/find-target-options';
4
+ export declare function addFiles(tree: Tree, projectConfig: ProjectConfiguration, options: CypressComponentConfigurationSchema, found: FoundTarget): Promise<void>;
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.addFiles = void 0;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const versions_1 = require("nx/src/utils/versions");
6
+ const component_test_1 = require("../../component-test/component-test");
7
+ const ct_utils_1 = require("../../../utils/ct-utils");
8
+ async function addFiles(tree, projectConfig, options, found) {
9
+ // must dyanmicaly import to prevent packages not using cypress from erroring out
10
+ // when importing react
11
+ const { addMountDefinition, addDefaultCTConfig } = await Promise.resolve().then(() => require('@nx/cypress/src/utils/config'));
12
+ // Specifically undefined to allow Remix workaround of passing an empty string
13
+ const actualBundler = await (0, ct_utils_1.getActualBundler)(tree, options, found);
14
+ if (options.bundler && options.bundler !== actualBundler) {
15
+ devkit_1.logger.warn(`You have specified ${options.bundler} as the bundler but this project is configured to use ${actualBundler}.
16
+ This may cause errors. If you are seeing errors, try removing the --bundler option.`);
17
+ }
18
+ const bundlerToUse = options.bundler ?? actualBundler;
19
+ const commandFile = (0, devkit_1.joinPathFragments)(projectConfig.root, 'cypress', 'support', 'component.ts');
20
+ const updatedCommandFile = await addMountDefinition(tree.read(commandFile, 'utf-8'));
21
+ tree.write(commandFile, `import { mount } from 'cypress/react18';\n${updatedCommandFile}`);
22
+ if (options.bundler === 'webpack' ||
23
+ (!options.bundler && actualBundler === 'webpack')) {
24
+ (0, devkit_1.addDependenciesToPackageJson)(tree, {}, { '@nx/webpack': versions_1.nxVersion });
25
+ }
26
+ if (options.bundler === 'vite' ||
27
+ (!options.bundler && actualBundler === 'vite')) {
28
+ (0, devkit_1.addDependenciesToPackageJson)(tree, {}, { '@nx/vite': versions_1.nxVersion });
29
+ }
30
+ if (options.generateTests) {
31
+ const filePaths = [];
32
+ (0, devkit_1.visitNotIgnoredFiles)(tree, projectConfig.sourceRoot, (filePath) => {
33
+ if ((0, ct_utils_1.isComponent)(tree, filePath)) {
34
+ filePaths.push(filePath);
35
+ }
36
+ });
37
+ for (const filePath of filePaths) {
38
+ await (0, component_test_1.componentTestGenerator)(tree, {
39
+ project: options.project,
40
+ componentPath: filePath,
41
+ });
42
+ }
43
+ }
44
+ }
45
+ exports.addFiles = addFiles;
@@ -0,0 +1,8 @@
1
+ export interface CypressComponentConfigurationSchema {
2
+ project: string;
3
+ generateTests: boolean;
4
+ skipFormat?: boolean;
5
+ buildTarget?: string;
6
+ bundler?: 'webpack' | 'vite';
7
+ addPlugin?: boolean;
8
+ }
@@ -0,0 +1,54 @@
1
+ {
2
+ "$schema": "https://json-schema.org/schema",
3
+ "cli": "nx",
4
+ "$id": "NxReactCypressComponentTestConfiguration",
5
+ "title": "Add Cypress component testing",
6
+ "description": "Add a Cypress component testing configuration to an existing project.",
7
+ "type": "object",
8
+ "examples": [
9
+ {
10
+ "command": "nx g @nx/react:cypress-component-configuration --project=my-react-project",
11
+ "description": "Add component testing to your react project"
12
+ },
13
+ {
14
+ "command": "nx g @nx/react:cypress-component-configuration --project=my-react-project --generate-tests",
15
+ "description": "Add component testing to your react project and generate component tests for your existing components"
16
+ }
17
+ ],
18
+ "properties": {
19
+ "project": {
20
+ "type": "string",
21
+ "description": "The name of the project to add cypress component testing configuration to",
22
+ "x-dropdown": "projects",
23
+ "x-prompt": "What project should we add Cypress component testing to?",
24
+ "x-priority": "important"
25
+ },
26
+ "generateTests": {
27
+ "type": "boolean",
28
+ "description": "Generate default component tests for existing components in the project",
29
+ "x-prompt": "Automatically generate tests for components declared in this project?",
30
+ "default": false,
31
+ "x-priority": "important"
32
+ },
33
+ "buildTarget": {
34
+ "type": "string",
35
+ "description": "A build target used to configure Cypress component testing in the format of `project:target[:configuration]`. The build target should be from a React app. If not provided we will try to infer it from your projects usage.",
36
+ "pattern": "^[^:\\s]+:[^:\\s]+(:\\S+)?$"
37
+ },
38
+ "skipFormat": {
39
+ "type": "boolean",
40
+ "description": "Skip formatting files",
41
+ "default": false,
42
+ "x-priority": "internal"
43
+ },
44
+ "bundler": {
45
+ "description": "The bundler to use for Cypress Component Testing.",
46
+ "type": "string",
47
+ "enum": ["vite", "webpack"],
48
+ "hidden": true,
49
+ "x-priority": "internal"
50
+ }
51
+ },
52
+ "required": ["project"],
53
+ "examplesFile": "../../../docs/cypress-component-configuration-examples.md"
54
+ }
@@ -0,0 +1,4 @@
1
+ import { GeneratorCallback, Tree } from '@nx/devkit';
2
+ import { Schema } from './schema';
3
+ export declare function federateModuleGenerator(tree: Tree, schema: Schema): Promise<GeneratorCallback>;
4
+ export default federateModuleGenerator;
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.federateModuleGenerator = void 0;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const remote_1 = require("../remote/remote");
6
+ const utils_1 = require("./lib/utils");
7
+ const project_name_and_root_utils_1 = require("@nx/devkit/src/generators/project-name-and-root-utils");
8
+ const js_1 = require("@nx/js");
9
+ async function federateModuleGenerator(tree, schema) {
10
+ // Check if the file exists
11
+ if (!tree.exists(schema.path)) {
12
+ throw new Error((0, devkit_1.stripIndents) `The "path" provided does not exist. Please verify the path is correct and pointing to a file that exists in the workspace.
13
+
14
+ Path: ${schema.path}`);
15
+ }
16
+ const tasks = [];
17
+ // Check remote exists
18
+ const remote = (0, utils_1.checkRemoteExists)(tree, schema.remote);
19
+ let projectRoot, remoteName;
20
+ if (!remote) {
21
+ // create remote
22
+ const remoteGenerator = await (0, remote_1.remoteGeneratorInternal)(tree, {
23
+ name: schema.remote,
24
+ directory: schema.remoteDirectory,
25
+ e2eTestRunner: schema.e2eTestRunner,
26
+ skipFormat: schema.skipFormat,
27
+ linter: schema.linter,
28
+ style: schema.style,
29
+ unitTestRunner: schema.unitTestRunner,
30
+ host: schema.host,
31
+ projectNameAndRootFormat: schema.projectNameAndRootFormat ?? 'derived',
32
+ });
33
+ tasks.push(remoteGenerator);
34
+ const { projectName, projectRoot: remoteRoot } = await (0, project_name_and_root_utils_1.determineProjectNameAndRootOptions)(tree, {
35
+ name: schema.remote,
36
+ directory: schema.remoteDirectory,
37
+ projectType: 'application',
38
+ projectNameAndRootFormat: schema.projectNameAndRootFormat ?? 'derived',
39
+ callingGenerator: '@nx/react:federate-module',
40
+ });
41
+ projectRoot = remoteRoot;
42
+ remoteName = projectName;
43
+ }
44
+ else {
45
+ projectRoot = remote.root;
46
+ remoteName = remote.name;
47
+ }
48
+ // add path to exposes property
49
+ (0, utils_1.addPathToExposes)(tree, projectRoot, schema.name, schema.path);
50
+ // Add new path to tsconfig
51
+ const rootJSON = (0, devkit_1.readJson)(tree, (0, js_1.getRootTsConfigPathInTree)(tree));
52
+ if (!rootJSON?.compilerOptions?.paths[`${remoteName}/${schema.name}`]) {
53
+ (0, js_1.addTsConfigPath)(tree, `${remoteName}/${schema.name}`, [schema.path]);
54
+ }
55
+ if (!schema.skipFormat) {
56
+ await (0, devkit_1.formatFiles)(tree);
57
+ }
58
+ devkit_1.logger.info(`✅️ Updated module federation config.
59
+ Now you can use the module from your host app like this:
60
+
61
+ Static import:
62
+ import { MyComponent } from '${remoteName}/${schema.name}';
63
+
64
+ Dynamic import:
65
+ import('${remoteName}/${schema.name}').then((m) => m.${schema.name});
66
+ `);
67
+ return (0, devkit_1.runTasksInSerial)(...tasks);
68
+ }
69
+ exports.federateModuleGenerator = federateModuleGenerator;
70
+ exports.default = federateModuleGenerator;
@@ -0,0 +1,23 @@
1
+ import { Tree } from '@nx/devkit';
2
+ import type { SourceFile, ObjectLiteralExpression, PropertyAssignment } from 'typescript';
3
+ /**
4
+ * Adds a Module Federation path to the exposes property of the module federation config
5
+ * The assumption here is made the we will only update a TypeScript Module Federation file namely 'module-federation.config.js'
6
+ * @param tree Tree for the workspace
7
+ * @param projectPath Project path relative to the workspace
8
+ * @param moduleName The name of the module to expose
9
+ * @param modulePath The path to the module to expose (e.g. './src/my-lib/my-lib.ts')
10
+ */
11
+ export declare function addPathToExposes(tree: Tree, projectPath: string, moduleName: string, modulePath: string): void;
12
+ /**
13
+ * @param tree The workspace tree
14
+ * @param remoteName The name of the remote to check
15
+ * @returns Remote ProjectConfig if it exists, false otherwise
16
+ */
17
+ export declare function checkRemoteExists(tree: Tree, remoteName: string): false | import("@nx/devkit").ProjectConfiguration;
18
+ export declare function getRemote(tree: Tree, remoteName: string): import("@nx/devkit").ProjectConfiguration;
19
+ export declare function findExposes(sourceFile: SourceFile): ObjectLiteralExpression;
20
+ export declare function createObjectEntry(moduleName: string, modulePath: string): PropertyAssignment;
21
+ export declare function updateExposesPropertyinAST(source: SourceFile, exposesObject: ObjectLiteralExpression, newEntry: PropertyAssignment): SourceFile;
22
+ export declare function writeToConfig(tree: Tree, filename: string, source: SourceFile, updatedSourceFile: SourceFile): void;
23
+ export declare function updateExposesProperty(tree: Tree, filename: string, moduleName: string, modulePath: string): void;
@@ -0,0 +1,100 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.updateExposesProperty = exports.writeToConfig = exports.updateExposesPropertyinAST = exports.createObjectEntry = exports.findExposes = exports.getRemote = exports.checkRemoteExists = exports.addPathToExposes = void 0;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const ensure_typescript_1 = require("@nx/js/src/utils/typescript/ensure-typescript");
6
+ let tsModule;
7
+ if (!tsModule) {
8
+ tsModule = (0, ensure_typescript_1.ensureTypescript)();
9
+ }
10
+ /**
11
+ * Adds a Module Federation path to the exposes property of the module federation config
12
+ * The assumption here is made the we will only update a TypeScript Module Federation file namely 'module-federation.config.js'
13
+ * @param tree Tree for the workspace
14
+ * @param projectPath Project path relative to the workspace
15
+ * @param moduleName The name of the module to expose
16
+ * @param modulePath The path to the module to expose (e.g. './src/my-lib/my-lib.ts')
17
+ */
18
+ function addPathToExposes(tree, projectPath, moduleName, modulePath) {
19
+ const moduleFederationConfigPath = (0, devkit_1.joinPathFragments)(projectPath, tree.exists((0, devkit_1.joinPathFragments)(projectPath, 'module-federation.config.ts'))
20
+ ? 'module-federation.config.ts'
21
+ : 'module-federation.config.js');
22
+ updateExposesProperty(tree, moduleFederationConfigPath, moduleName, modulePath);
23
+ }
24
+ exports.addPathToExposes = addPathToExposes;
25
+ /**
26
+ * @param tree The workspace tree
27
+ * @param remoteName The name of the remote to check
28
+ * @returns Remote ProjectConfig if it exists, false otherwise
29
+ */
30
+ function checkRemoteExists(tree, remoteName) {
31
+ const remote = getRemote(tree, remoteName);
32
+ if (!remote)
33
+ return false;
34
+ const hasModuleFederationConfig = tree.exists((0, devkit_1.joinPathFragments)(remote.root, 'module-federation.config.js')) ||
35
+ tree.exists((0, devkit_1.joinPathFragments)(remote.root, 'module-federation.config.ts'));
36
+ return hasModuleFederationConfig ? remote : false;
37
+ }
38
+ exports.checkRemoteExists = checkRemoteExists;
39
+ function getRemote(tree, remoteName) {
40
+ const projects = (0, devkit_1.getProjects)(tree);
41
+ const remote = projects.get(remoteName);
42
+ return remote;
43
+ }
44
+ exports.getRemote = getRemote;
45
+ // Check if the exposes property exists in the AST
46
+ function findExposes(sourceFile) {
47
+ let exposesObject = null;
48
+ const visit = (node) => {
49
+ if (tsModule.isPropertyAssignment(node) &&
50
+ tsModule.isIdentifier(node.name) &&
51
+ node.name.text === 'exposes' &&
52
+ tsModule.isObjectLiteralExpression(node.initializer)) {
53
+ exposesObject = node.initializer;
54
+ }
55
+ else {
56
+ tsModule.forEachChild(node, visit);
57
+ }
58
+ };
59
+ tsModule.forEachChild(sourceFile, visit);
60
+ return exposesObject;
61
+ }
62
+ exports.findExposes = findExposes;
63
+ // Create a new property assignment
64
+ function createObjectEntry(moduleName, modulePath) {
65
+ return tsModule.factory.createPropertyAssignment(tsModule.factory.createStringLiteral(`./${moduleName}`, true), tsModule.factory.createStringLiteral(modulePath, true));
66
+ }
67
+ exports.createObjectEntry = createObjectEntry;
68
+ // Update the exposes property in the AST
69
+ function updateExposesPropertyinAST(source, exposesObject, newEntry) {
70
+ const updatedExposes = tsModule.factory.updateObjectLiteralExpression(exposesObject, [...exposesObject.properties, newEntry]);
71
+ const transform = (context) => {
72
+ const visit = (node) => {
73
+ // Comparing nodes indirectly to ensure type compatibility. You must ensure that the nodes are identical.
74
+ return tsModule.isObjectLiteralExpression(node) && node === exposesObject
75
+ ? updatedExposes
76
+ : tsModule.visitEachChild(node, visit, context);
77
+ };
78
+ return (node) => tsModule.visitNode(node, visit);
79
+ };
80
+ return tsModule.transform(source, [transform]).transformed[0];
81
+ }
82
+ exports.updateExposesPropertyinAST = updateExposesPropertyinAST;
83
+ // Write the updated AST to the file (module-federation.config.js)
84
+ function writeToConfig(tree, filename, source, updatedSourceFile) {
85
+ const printer = tsModule.createPrinter();
86
+ const update = printer.printNode(tsModule.EmitHint.Unspecified, updatedSourceFile, source);
87
+ tree.write(filename, update);
88
+ }
89
+ exports.writeToConfig = writeToConfig;
90
+ function updateExposesProperty(tree, filename, moduleName, modulePath) {
91
+ const fileContent = tree.read(filename).toString();
92
+ const source = tsModule.createSourceFile(filename, fileContent, tsModule.ScriptTarget.ES2015, true);
93
+ const exposesObject = findExposes(source);
94
+ if (!exposesObject)
95
+ return;
96
+ const newEntry = createObjectEntry(moduleName, modulePath);
97
+ const updatedSourceFile = updateExposesPropertyinAST(source, exposesObject, newEntry);
98
+ writeToConfig(tree, filename, source, updatedSourceFile);
99
+ }
100
+ exports.updateExposesProperty = updateExposesProperty;
@@ -0,0 +1,13 @@
1
+ export interface Schema {
2
+ name: string;
3
+ path: string;
4
+ remote: string;
5
+ remoteDirectory?: string;
6
+ projectNameAndRootFormat?: ProjectNameAndRootFormat;
7
+ e2eTestRunner?: 'cypress' | 'playwright' | 'none';
8
+ host?: string;
9
+ linter?: Linter;
10
+ skipFormat?: boolean;
11
+ style?: SupportedStyles;
12
+ unitTestRunner?: 'jest' | 'vitest' | 'none';
13
+ }