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