@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,104 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.remoteGeneratorInternal = exports.remoteGenerator = exports.addModuleFederationFiles = void 0;
|
|
4
|
+
const path_1 = require("path");
|
|
5
|
+
const devkit_1 = require("@nx/devkit");
|
|
6
|
+
const normalize_options_1 = require("../application/lib/normalize-options");
|
|
7
|
+
const application_1 = require("../application/application");
|
|
8
|
+
const update_host_with_remote_1 = require("./lib/update-host-with-remote");
|
|
9
|
+
const update_module_federation_project_1 = require("../../rules/update-module-federation-project");
|
|
10
|
+
const setup_ssr_1 = require("../setup-ssr/setup-ssr");
|
|
11
|
+
const setup_ssr_for_remote_1 = require("./lib/setup-ssr-for-remote");
|
|
12
|
+
const setup_tspath_for_remote_1 = require("./lib/setup-tspath-for-remote");
|
|
13
|
+
const add_remote_to_dynamic_host_1 = require("./lib/add-remote-to-dynamic-host");
|
|
14
|
+
const add_mf_env_to_inputs_1 = require("../../utils/add-mf-env-to-inputs");
|
|
15
|
+
const maybe_js_1 = require("../../utils/maybe-js");
|
|
16
|
+
function addModuleFederationFiles(host, options) {
|
|
17
|
+
const templateVariables = {
|
|
18
|
+
...(0, devkit_1.names)(options.name),
|
|
19
|
+
...options,
|
|
20
|
+
tmpl: '',
|
|
21
|
+
};
|
|
22
|
+
(0, devkit_1.generateFiles)(host, (0, path_1.join)(__dirname, `./files/${options.js ? 'common' : 'common-ts'}`), options.appProjectRoot, templateVariables);
|
|
23
|
+
const pathToModuleFederationFiles = options.typescriptConfiguration
|
|
24
|
+
? 'module-federation-ts'
|
|
25
|
+
: 'module-federation';
|
|
26
|
+
(0, devkit_1.generateFiles)(host, (0, path_1.join)(__dirname, `./files/${pathToModuleFederationFiles}`), options.appProjectRoot, templateVariables);
|
|
27
|
+
if (options.typescriptConfiguration) {
|
|
28
|
+
const pathToWebpackConfig = (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'webpack.config.js');
|
|
29
|
+
const pathToWebpackProdConfig = (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'webpack.config.prod.js');
|
|
30
|
+
if (host.exists(pathToWebpackConfig)) {
|
|
31
|
+
host.delete(pathToWebpackConfig);
|
|
32
|
+
}
|
|
33
|
+
if (host.exists(pathToWebpackProdConfig)) {
|
|
34
|
+
host.delete(pathToWebpackProdConfig);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
exports.addModuleFederationFiles = addModuleFederationFiles;
|
|
39
|
+
async function remoteGenerator(host, schema) {
|
|
40
|
+
return await remoteGeneratorInternal(host, {
|
|
41
|
+
projectNameAndRootFormat: 'derived',
|
|
42
|
+
...schema,
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
exports.remoteGenerator = remoteGenerator;
|
|
46
|
+
async function remoteGeneratorInternal(host, schema) {
|
|
47
|
+
const tasks = [];
|
|
48
|
+
const options = {
|
|
49
|
+
...(await (0, normalize_options_1.normalizeOptions)(host, schema, '@nx/react:remote')),
|
|
50
|
+
// when js is set to true, we want to use the js configuration
|
|
51
|
+
js: schema.js ?? false,
|
|
52
|
+
typescriptConfiguration: schema.js
|
|
53
|
+
? false
|
|
54
|
+
: schema.typescriptConfiguration ?? true,
|
|
55
|
+
dynamic: schema.dynamic ?? false,
|
|
56
|
+
// TODO(colum): remove when MF works with Crystal
|
|
57
|
+
addPlugin: false,
|
|
58
|
+
};
|
|
59
|
+
const initAppTask = await (0, application_1.default)(host, {
|
|
60
|
+
...options,
|
|
61
|
+
// Only webpack works with module federation for now.
|
|
62
|
+
bundler: 'webpack',
|
|
63
|
+
skipFormat: true,
|
|
64
|
+
});
|
|
65
|
+
tasks.push(initAppTask);
|
|
66
|
+
if (schema.host) {
|
|
67
|
+
(0, update_host_with_remote_1.updateHostWithRemote)(host, schema.host, options.projectName);
|
|
68
|
+
}
|
|
69
|
+
// Module federation requires bootstrap code to be dynamically imported.
|
|
70
|
+
// Renaming original entry file so we can use `import(./bootstrap)` in
|
|
71
|
+
// new entry file.
|
|
72
|
+
host.rename((0, path_1.join)(options.appProjectRoot, (0, maybe_js_1.maybeJs)(options, 'src/main.tsx')), (0, path_1.join)(options.appProjectRoot, (0, maybe_js_1.maybeJs)(options, 'src/bootstrap.tsx')));
|
|
73
|
+
addModuleFederationFiles(host, options);
|
|
74
|
+
(0, update_module_federation_project_1.updateModuleFederationProject)(host, options);
|
|
75
|
+
(0, setup_tspath_for_remote_1.setupTspathForRemote)(host, options);
|
|
76
|
+
if (options.ssr) {
|
|
77
|
+
const setupSsrTask = await (0, setup_ssr_1.default)(host, {
|
|
78
|
+
project: options.projectName,
|
|
79
|
+
serverPort: options.devServerPort,
|
|
80
|
+
skipFormat: true,
|
|
81
|
+
});
|
|
82
|
+
tasks.push(setupSsrTask);
|
|
83
|
+
const setupSsrForRemoteTask = await (0, setup_ssr_for_remote_1.setupSsrForRemote)(host, options, options.projectName);
|
|
84
|
+
tasks.push(setupSsrForRemoteTask);
|
|
85
|
+
const projectConfig = (0, devkit_1.readProjectConfiguration)(host, options.projectName);
|
|
86
|
+
projectConfig.targets.server.options.webpackConfig = (0, devkit_1.joinPathFragments)(projectConfig.root, `webpack.server.config.${options.typescriptConfiguration ? 'ts' : 'js'}`);
|
|
87
|
+
(0, devkit_1.updateProjectConfiguration)(host, options.projectName, projectConfig);
|
|
88
|
+
}
|
|
89
|
+
if (!options.setParserOptionsProject) {
|
|
90
|
+
host.delete((0, devkit_1.joinPathFragments)(options.appProjectRoot, 'tsconfig.lint.json'));
|
|
91
|
+
}
|
|
92
|
+
if (options.host && options.dynamic) {
|
|
93
|
+
const hostConfig = (0, devkit_1.readProjectConfiguration)(host, schema.host);
|
|
94
|
+
const pathToMFManifest = (0, devkit_1.joinPathFragments)(hostConfig.sourceRoot, 'assets/module-federation.manifest.json');
|
|
95
|
+
(0, add_remote_to_dynamic_host_1.addRemoteToDynamicHost)(host, options.name, options.devServerPort, pathToMFManifest);
|
|
96
|
+
}
|
|
97
|
+
(0, add_mf_env_to_inputs_1.addMfEnvToTargetDefaultInputs)(host);
|
|
98
|
+
if (!options.skipFormat) {
|
|
99
|
+
await (0, devkit_1.formatFiles)(host);
|
|
100
|
+
}
|
|
101
|
+
return (0, devkit_1.runTasksInSerial)(...tasks);
|
|
102
|
+
}
|
|
103
|
+
exports.remoteGeneratorInternal = remoteGeneratorInternal;
|
|
104
|
+
exports.default = remoteGenerator;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { ProjectNameAndRootFormat } from '@nx/devkit/src/generators/project-name-and-root-utils';
|
|
2
|
+
import type { Linter } from '@nx/eslint';
|
|
3
|
+
import type { SupportedStyles } from '../../../typings/style';
|
|
4
|
+
import type { NormalizedSchema as ApplicationNormalizedSchema } from '../application/schema';
|
|
5
|
+
|
|
6
|
+
export interface Schema {
|
|
7
|
+
classComponent?: boolean;
|
|
8
|
+
compiler?: 'babel' | 'swc';
|
|
9
|
+
devServerPort?: number;
|
|
10
|
+
directory?: string;
|
|
11
|
+
projectNameAndRootFormat?: ProjectNameAndRootFormat;
|
|
12
|
+
e2eTestRunner: 'cypress' | 'playwright' | 'none';
|
|
13
|
+
globalCss?: boolean;
|
|
14
|
+
host?: string;
|
|
15
|
+
js?: boolean;
|
|
16
|
+
linter: Linter;
|
|
17
|
+
name: string;
|
|
18
|
+
pascalCaseFiles?: boolean;
|
|
19
|
+
routing?: boolean;
|
|
20
|
+
setParserOptionsProject?: boolean;
|
|
21
|
+
skipFormat: boolean;
|
|
22
|
+
skipNxJson?: boolean;
|
|
23
|
+
ssr?: boolean;
|
|
24
|
+
strict?: boolean;
|
|
25
|
+
style: SupportedStyles;
|
|
26
|
+
tags?: string;
|
|
27
|
+
unitTestRunner: 'jest' | 'vitest' | 'none';
|
|
28
|
+
typescriptConfiguration?: boolean;
|
|
29
|
+
dynamic?: boolean;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface NormalizedSchema extends ApplicationNormalizedSchema {
|
|
33
|
+
typescriptConfiguration: boolean;
|
|
34
|
+
}
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/schema",
|
|
3
|
+
"$id": "GeneratorReactRemote",
|
|
4
|
+
"cli": "nx",
|
|
5
|
+
"title": "Generate Module Federation Setup for React Remote App",
|
|
6
|
+
"description": "Create Module Federation configuration files for given React Remote Application.",
|
|
7
|
+
"type": "object",
|
|
8
|
+
"properties": {
|
|
9
|
+
"name": {
|
|
10
|
+
"type": "string",
|
|
11
|
+
"description": "The name of the remote application to generate the Module Federation configuration",
|
|
12
|
+
"$default": {
|
|
13
|
+
"$source": "argv",
|
|
14
|
+
"index": 0
|
|
15
|
+
},
|
|
16
|
+
"x-prompt": "What name would you like to use as the remote application?",
|
|
17
|
+
"pattern": "^[a-zA-Z][^:]*$",
|
|
18
|
+
"x-priority": "important"
|
|
19
|
+
},
|
|
20
|
+
"directory": {
|
|
21
|
+
"description": "The directory of the new application.",
|
|
22
|
+
"type": "string",
|
|
23
|
+
"alias": "dir",
|
|
24
|
+
"x-priority": "important"
|
|
25
|
+
},
|
|
26
|
+
"projectNameAndRootFormat": {
|
|
27
|
+
"description": "Whether to generate the project name and root directory as provided (`as-provided`) or generate them composing their values and taking the configured layout into account (`derived`).",
|
|
28
|
+
"type": "string",
|
|
29
|
+
"enum": ["as-provided", "derived"]
|
|
30
|
+
},
|
|
31
|
+
"dynamic": {
|
|
32
|
+
"type": "boolean",
|
|
33
|
+
"description": "Should the host application use dynamic federation?",
|
|
34
|
+
"default": false,
|
|
35
|
+
"x-priority": "internal"
|
|
36
|
+
},
|
|
37
|
+
"style": {
|
|
38
|
+
"description": "The file extension to be used for style files.",
|
|
39
|
+
"type": "string",
|
|
40
|
+
"default": "css",
|
|
41
|
+
"alias": "s",
|
|
42
|
+
"x-prompt": {
|
|
43
|
+
"message": "Which stylesheet format would you like to use?",
|
|
44
|
+
"type": "list",
|
|
45
|
+
"items": [
|
|
46
|
+
{
|
|
47
|
+
"value": "css",
|
|
48
|
+
"label": "CSS"
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
"value": "scss",
|
|
52
|
+
"label": "SASS(.scss) [ https://sass-lang.com ]"
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
"value": "less",
|
|
56
|
+
"label": "LESS [ https://lesscss.org ]"
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
"value": "tailwind",
|
|
60
|
+
"label": "tailwind [ https://tailwindcss.com/ ]"
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
"value": "styled-components",
|
|
64
|
+
"label": "styled-components [ https://styled-components.com ]"
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
"value": "@emotion/styled",
|
|
68
|
+
"label": "emotion [ https://emotion.sh ]"
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
"value": "styled-jsx",
|
|
72
|
+
"label": "styled-jsx [ https://www.npmjs.com/package/styled-jsx ]"
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
"value": "none",
|
|
76
|
+
"label": "None"
|
|
77
|
+
}
|
|
78
|
+
]
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
"linter": {
|
|
82
|
+
"description": "The tool to use for running lint checks.",
|
|
83
|
+
"type": "string",
|
|
84
|
+
"enum": ["eslint"],
|
|
85
|
+
"default": "eslint"
|
|
86
|
+
},
|
|
87
|
+
"routing": {
|
|
88
|
+
"type": "boolean",
|
|
89
|
+
"description": "Generate application with routes.",
|
|
90
|
+
"default": false
|
|
91
|
+
},
|
|
92
|
+
"skipFormat": {
|
|
93
|
+
"description": "Skip formatting files.",
|
|
94
|
+
"type": "boolean",
|
|
95
|
+
"default": false,
|
|
96
|
+
"x-priority": "internal"
|
|
97
|
+
},
|
|
98
|
+
"skipNxJson": {
|
|
99
|
+
"description": "Skip updating workspace.json with default options based on values provided to this app (e.g. babel, style).",
|
|
100
|
+
"type": "boolean",
|
|
101
|
+
"default": false,
|
|
102
|
+
"x-priority": "internal"
|
|
103
|
+
},
|
|
104
|
+
"unitTestRunner": {
|
|
105
|
+
"type": "string",
|
|
106
|
+
"enum": ["jest", "none"],
|
|
107
|
+
"description": "Test runner to use for unit tests.",
|
|
108
|
+
"default": "jest"
|
|
109
|
+
},
|
|
110
|
+
"e2eTestRunner": {
|
|
111
|
+
"type": "string",
|
|
112
|
+
"enum": ["cypress", "playwright", "none"],
|
|
113
|
+
"description": "Test runner to use for end to end (E2E) tests.",
|
|
114
|
+
"x-prompt": "Which E2E test runner would you like to use?",
|
|
115
|
+
"default": "cypress"
|
|
116
|
+
},
|
|
117
|
+
"tags": {
|
|
118
|
+
"type": "string",
|
|
119
|
+
"description": "Add tags to the application (used for linting).",
|
|
120
|
+
"alias": "t"
|
|
121
|
+
},
|
|
122
|
+
"pascalCaseFiles": {
|
|
123
|
+
"type": "boolean",
|
|
124
|
+
"description": "Use pascal case component file name (e.g. App.tsx).",
|
|
125
|
+
"alias": "P",
|
|
126
|
+
"default": false
|
|
127
|
+
},
|
|
128
|
+
"classComponent": {
|
|
129
|
+
"type": "boolean",
|
|
130
|
+
"description": "Use class components instead of functional component.",
|
|
131
|
+
"alias": "C",
|
|
132
|
+
"default": false
|
|
133
|
+
},
|
|
134
|
+
"js": {
|
|
135
|
+
"type": "boolean",
|
|
136
|
+
"description": "Generate JavaScript files rather than TypeScript files.",
|
|
137
|
+
"default": false
|
|
138
|
+
},
|
|
139
|
+
"globalCss": {
|
|
140
|
+
"type": "boolean",
|
|
141
|
+
"description": "Default is false. When true, the component is generated with *.css/*.scss instead of *.module.css/*.module.scss.",
|
|
142
|
+
"default": false
|
|
143
|
+
},
|
|
144
|
+
"strict": {
|
|
145
|
+
"type": "boolean",
|
|
146
|
+
"description": "Creates an application with strict mode and strict type checking.",
|
|
147
|
+
"default": true
|
|
148
|
+
},
|
|
149
|
+
"setParserOptionsProject": {
|
|
150
|
+
"type": "boolean",
|
|
151
|
+
"description": "Whether or not to configure the ESLint \"parserOptions.project\" option. We do not do this by default for lint performance reasons.",
|
|
152
|
+
"default": false
|
|
153
|
+
},
|
|
154
|
+
"compiler": {
|
|
155
|
+
"type": "string",
|
|
156
|
+
"description": "The compiler to use.",
|
|
157
|
+
"enum": ["babel", "swc"],
|
|
158
|
+
"default": "babel"
|
|
159
|
+
},
|
|
160
|
+
"host": {
|
|
161
|
+
"type": "string",
|
|
162
|
+
"description": "The host / shell application for this remote.",
|
|
163
|
+
"x-priority": "important"
|
|
164
|
+
},
|
|
165
|
+
"devServerPort": {
|
|
166
|
+
"type": "number",
|
|
167
|
+
"description": "The port for the dev server of the remote app.",
|
|
168
|
+
"x-priority": "important"
|
|
169
|
+
},
|
|
170
|
+
"ssr": {
|
|
171
|
+
"description": "Whether to configure SSR for the host application",
|
|
172
|
+
"type": "boolean",
|
|
173
|
+
"default": false
|
|
174
|
+
},
|
|
175
|
+
"typescriptConfiguration": {
|
|
176
|
+
"type": "boolean",
|
|
177
|
+
"description": "Whether the module federation configuration and webpack configuration files should use TS. When --js is used, this flag is ignored.",
|
|
178
|
+
"default": true
|
|
179
|
+
}
|
|
180
|
+
},
|
|
181
|
+
"required": ["name"],
|
|
182
|
+
"additionalProperties": false
|
|
183
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import * as path from 'path';
|
|
2
|
+
import express from 'express';
|
|
3
|
+
import cors from 'cors';
|
|
4
|
+
|
|
5
|
+
import { handleRequest } from './src/main.server';
|
|
6
|
+
|
|
7
|
+
const port = process.env['PORT'] || 4200;
|
|
8
|
+
const app = express();
|
|
9
|
+
|
|
10
|
+
const browserDist = path.join(process.cwd(), '<%= browserBuildOutputPath %>');
|
|
11
|
+
const indexPath =path.join(browserDist, 'index.html');
|
|
12
|
+
|
|
13
|
+
app.use(cors());
|
|
14
|
+
|
|
15
|
+
app.get(
|
|
16
|
+
'*.*',
|
|
17
|
+
express.static(browserDist, {
|
|
18
|
+
maxAge: '1y',
|
|
19
|
+
})
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
app.use('*', handleRequest(indexPath));
|
|
23
|
+
|
|
24
|
+
const server = app.listen(port, () => {
|
|
25
|
+
// Server has started
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
server.on('error', console.error);
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { Request, Response } from 'express';
|
|
2
|
+
import * as fs from 'fs';
|
|
3
|
+
import * as ReactDOMServer from 'react-dom/server';
|
|
4
|
+
import isbot from 'isbot'
|
|
5
|
+
|
|
6
|
+
import App from './<%= appComponentImport %>';
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
let indexHtml: null | string = null;
|
|
10
|
+
|
|
11
|
+
export function handleRequest(indexPath: string) {
|
|
12
|
+
return function render(req: Request, res: Response) {
|
|
13
|
+
let didError = false;
|
|
14
|
+
|
|
15
|
+
if (!indexHtml) {
|
|
16
|
+
indexHtml = fs.readFileSync(indexPath).toString();
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const [htmlStart, htmlEnd] = indexHtml.split(`<div id="root"></div>`);
|
|
20
|
+
|
|
21
|
+
// For bots (e.g. search engines), the content will not be streamed but render all at once.
|
|
22
|
+
// For users, content should be streamed to the user as they are ready.
|
|
23
|
+
const callbackName = isbot(req.headers['user-agent']) ? 'onAllReady' : 'onShellReady';
|
|
24
|
+
|
|
25
|
+
const stream = ReactDOMServer.renderToPipeableStream(
|
|
26
|
+
<App />,
|
|
27
|
+
{
|
|
28
|
+
[callbackName]() {
|
|
29
|
+
res.statusCode = didError ? 500 : 200;
|
|
30
|
+
res.setHeader('Content-type', 'text/html; charset=utf-8');
|
|
31
|
+
res.write(`${htmlStart}<div id="root">`);
|
|
32
|
+
stream.pipe(res);
|
|
33
|
+
res.write(`</div>${htmlEnd}`);
|
|
34
|
+
},
|
|
35
|
+
onShellError(error) {
|
|
36
|
+
console.error(error);
|
|
37
|
+
res.statusCode = 500;
|
|
38
|
+
res.send('<!doctype html><h1>Server Error</h1>');
|
|
39
|
+
},
|
|
40
|
+
onError(error) {
|
|
41
|
+
didError = true;
|
|
42
|
+
console.error(error);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "./tsconfig.app.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"outDir": "../../out-tsc/server",
|
|
5
|
+
"target": "es2019",
|
|
6
|
+
"types": [
|
|
7
|
+
"node",
|
|
8
|
+
"@nx/react/typings/cssmodule.d.ts",
|
|
9
|
+
"@nx/react/typings/image.d.ts"
|
|
10
|
+
]
|
|
11
|
+
},
|
|
12
|
+
"include": [
|
|
13
|
+
<%- extraInclude %>
|
|
14
|
+
"src/main.server.tsx",
|
|
15
|
+
"server.ts"
|
|
16
|
+
]
|
|
17
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/schema",
|
|
3
|
+
"$id": "GeneratorReactSSRSetup",
|
|
4
|
+
"cli": "nx",
|
|
5
|
+
"title": "Generate SSR setup for a React app",
|
|
6
|
+
"description": "Create the additional configuration required to enable SSR via Express for a React application.",
|
|
7
|
+
"type": "object",
|
|
8
|
+
"properties": {
|
|
9
|
+
"project": {
|
|
10
|
+
"type": "string",
|
|
11
|
+
"description": "The name of the application to add SSR support to.",
|
|
12
|
+
"$default": {
|
|
13
|
+
"$source": "argv",
|
|
14
|
+
"index": 0
|
|
15
|
+
},
|
|
16
|
+
"x-prompt": "What app would you like to add SSR support to?",
|
|
17
|
+
"x-dropdown": "projects",
|
|
18
|
+
"x-priority": "important"
|
|
19
|
+
},
|
|
20
|
+
"appComponentImportPath": {
|
|
21
|
+
"type": "string",
|
|
22
|
+
"description": "The import path of the <App/ > component, relative to project sourceRoot.",
|
|
23
|
+
"default": "app/app"
|
|
24
|
+
},
|
|
25
|
+
"serverPort": {
|
|
26
|
+
"type": "number",
|
|
27
|
+
"default": 4200,
|
|
28
|
+
"description": "The port for the Express server.",
|
|
29
|
+
"x-priority": "important"
|
|
30
|
+
},
|
|
31
|
+
"skipFormat": {
|
|
32
|
+
"type": "boolean",
|
|
33
|
+
"description": "Skip formatting the workspace after the generator completes.",
|
|
34
|
+
"x-priority": "internal"
|
|
35
|
+
},
|
|
36
|
+
"extraInclude": {
|
|
37
|
+
"type": "array",
|
|
38
|
+
"items": {
|
|
39
|
+
"type": "string"
|
|
40
|
+
},
|
|
41
|
+
"hidden": true,
|
|
42
|
+
"description": "Extra include entries in tsconfig.",
|
|
43
|
+
"default": []
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
"required": ["project"],
|
|
47
|
+
"additionalProperties": false
|
|
48
|
+
}
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.setupSsrGenerator = void 0;
|
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
const versions_1 = require("../../utils/versions");
|
|
6
|
+
const ast_utils_1 = require("../../utils/ast-utils");
|
|
7
|
+
const ensure_typescript_1 = require("@nx/js/src/utils/typescript/ensure-typescript");
|
|
8
|
+
const path_1 = require("path");
|
|
9
|
+
let tsModule;
|
|
10
|
+
function readEntryFile(host, path) {
|
|
11
|
+
if (!tsModule) {
|
|
12
|
+
tsModule = (0, ensure_typescript_1.ensureTypescript)();
|
|
13
|
+
}
|
|
14
|
+
const content = host.read(path, 'utf-8');
|
|
15
|
+
return {
|
|
16
|
+
content,
|
|
17
|
+
source: tsModule.createSourceFile(path, content, tsModule.ScriptTarget.Latest, true),
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
async function getProjectConfig(tree, projectName) {
|
|
21
|
+
let maybeProjectConfig = (0, devkit_1.readProjectConfiguration)(tree, projectName);
|
|
22
|
+
if (!maybeProjectConfig.targets?.build) {
|
|
23
|
+
let projectGraph;
|
|
24
|
+
try {
|
|
25
|
+
projectGraph = (0, devkit_1.readCachedProjectGraph)();
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
projectGraph = await (0, devkit_1.createProjectGraphAsync)();
|
|
29
|
+
}
|
|
30
|
+
maybeProjectConfig = projectGraph.nodes[projectName].data;
|
|
31
|
+
}
|
|
32
|
+
return maybeProjectConfig;
|
|
33
|
+
}
|
|
34
|
+
async function setupSsrGenerator(tree, options) {
|
|
35
|
+
const projectConfig = await getProjectConfig(tree, options.project);
|
|
36
|
+
const projectRoot = projectConfig.root;
|
|
37
|
+
const appImportCandidates = [
|
|
38
|
+
options.appComponentImportPath ?? 'app/app',
|
|
39
|
+
'app',
|
|
40
|
+
'App',
|
|
41
|
+
'app/App',
|
|
42
|
+
'App/App',
|
|
43
|
+
].map((importPath) => {
|
|
44
|
+
return {
|
|
45
|
+
importPath,
|
|
46
|
+
filePath: (0, devkit_1.joinPathFragments)(projectConfig.sourceRoot || projectConfig.root, `${importPath}.tsx`),
|
|
47
|
+
};
|
|
48
|
+
});
|
|
49
|
+
const appComponentInfo = appImportCandidates.find((candidate) => tree.exists(candidate.filePath));
|
|
50
|
+
if (!appComponentInfo) {
|
|
51
|
+
throw new Error(`Cannot find an import path for <App/> component. Try passing setting --appComponentImportPath option.`);
|
|
52
|
+
}
|
|
53
|
+
if (!projectConfig.targets.build || !projectConfig.targets.serve) {
|
|
54
|
+
throw new Error(`Project ${options.project} does not have build and serve targets`);
|
|
55
|
+
}
|
|
56
|
+
if (projectConfig.targets.server) {
|
|
57
|
+
throw new Error(`Project ${options.project} already has a server target.`);
|
|
58
|
+
}
|
|
59
|
+
const originalOutputPath = projectConfig.targets.build?.options?.outputPath ??
|
|
60
|
+
projectConfig.targets.build?.outputs[0];
|
|
61
|
+
if (!originalOutputPath) {
|
|
62
|
+
throw new Error(`Project ${options.project} does not contain a outputPath for the build target.`);
|
|
63
|
+
}
|
|
64
|
+
// TODO(colum): We need to figure out how to handle this for Crystal
|
|
65
|
+
if (projectConfig.targets.build.options?.outputPath) {
|
|
66
|
+
projectConfig.targets.build.options.outputPath = (0, devkit_1.joinPathFragments)(originalOutputPath, 'browser');
|
|
67
|
+
}
|
|
68
|
+
projectConfig.targets = {
|
|
69
|
+
...projectConfig.targets,
|
|
70
|
+
server: {
|
|
71
|
+
dependsOn: ['build'],
|
|
72
|
+
executor: '@nx/webpack:webpack',
|
|
73
|
+
outputs: ['{options.outputPath}'],
|
|
74
|
+
defaultConfiguration: 'production',
|
|
75
|
+
options: {
|
|
76
|
+
target: 'node',
|
|
77
|
+
main: `${projectRoot}/server.ts`,
|
|
78
|
+
outputPath: (0, devkit_1.joinPathFragments)(originalOutputPath, 'server'),
|
|
79
|
+
outputFileName: 'server.js',
|
|
80
|
+
tsConfig: `${projectRoot}/tsconfig.server.json`,
|
|
81
|
+
compiler: 'babel',
|
|
82
|
+
externalDependencies: 'all',
|
|
83
|
+
outputHashing: 'none',
|
|
84
|
+
webpackConfig: (0, devkit_1.joinPathFragments)(projectRoot, 'webpack.config.js'),
|
|
85
|
+
},
|
|
86
|
+
configurations: {
|
|
87
|
+
development: {
|
|
88
|
+
optimization: false,
|
|
89
|
+
sourceMap: true,
|
|
90
|
+
},
|
|
91
|
+
production: {
|
|
92
|
+
fileReplacements: [
|
|
93
|
+
{
|
|
94
|
+
replace: `${projectRoot}/src/environments/environment.ts`,
|
|
95
|
+
with: `${projectRoot}/src/environments/environment.prod.ts`,
|
|
96
|
+
},
|
|
97
|
+
],
|
|
98
|
+
sourceMap: false,
|
|
99
|
+
},
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
'serve-browser': projectConfig.targets.serve,
|
|
103
|
+
'serve-server': {
|
|
104
|
+
executor: '@nx/js:node',
|
|
105
|
+
defaultConfiguration: 'development',
|
|
106
|
+
options: {
|
|
107
|
+
buildTarget: `${options.project}:server:development`,
|
|
108
|
+
buildTargetOptions: {
|
|
109
|
+
watch: true,
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
configurations: {
|
|
113
|
+
development: {},
|
|
114
|
+
production: {
|
|
115
|
+
buildTarget: `${options.project}:server:production`,
|
|
116
|
+
},
|
|
117
|
+
},
|
|
118
|
+
},
|
|
119
|
+
serve: {
|
|
120
|
+
executor: '@nx/webpack:ssr-dev-server',
|
|
121
|
+
defaultConfiguration: 'development',
|
|
122
|
+
options: {
|
|
123
|
+
browserTarget: `${options.project}:build:development`,
|
|
124
|
+
serverTarget: `${options.project}:serve-server:development`,
|
|
125
|
+
port: options.serverPort,
|
|
126
|
+
browserTargetOptions: {
|
|
127
|
+
watch: true,
|
|
128
|
+
},
|
|
129
|
+
},
|
|
130
|
+
configurations: {
|
|
131
|
+
development: {},
|
|
132
|
+
production: {
|
|
133
|
+
browserTarget: `${options.project}:build:production`,
|
|
134
|
+
serverTarget: `${options.project}:serve-server:production`,
|
|
135
|
+
},
|
|
136
|
+
},
|
|
137
|
+
},
|
|
138
|
+
};
|
|
139
|
+
(0, devkit_1.updateProjectConfiguration)(tree, options.project, projectConfig);
|
|
140
|
+
const nxJson = (0, devkit_1.readNxJson)(tree);
|
|
141
|
+
if (nxJson.tasksRunnerOptions?.default &&
|
|
142
|
+
!nxJson.tasksRunnerOptions?.default.options.cacheableOperations.includes('server')) {
|
|
143
|
+
nxJson.tasksRunnerOptions.default.options.cacheableOperations = [
|
|
144
|
+
...nxJson.tasksRunnerOptions.default.options.cacheableOperations,
|
|
145
|
+
'server',
|
|
146
|
+
];
|
|
147
|
+
}
|
|
148
|
+
nxJson.targetDefaults ??= {};
|
|
149
|
+
nxJson.targetDefaults['server'] ??= {};
|
|
150
|
+
nxJson.targetDefaults.server.cache = true;
|
|
151
|
+
(0, devkit_1.generateFiles)(tree, (0, path_1.join)(__dirname, 'files'), projectRoot, {
|
|
152
|
+
tmpl: '',
|
|
153
|
+
extraInclude: options.extraInclude?.length > 0
|
|
154
|
+
? `"${options.extraInclude.join('", "')}",`
|
|
155
|
+
: '',
|
|
156
|
+
appComponentImport: appComponentInfo.importPath,
|
|
157
|
+
browserBuildOutputPath: projectConfig.targets.build?.options?.outputPath ??
|
|
158
|
+
projectConfig.targets.build?.outputs[0],
|
|
159
|
+
});
|
|
160
|
+
// Add <StaticRouter> to server main if needed.
|
|
161
|
+
// TODO: need to read main.server.tsx not main.tsx.
|
|
162
|
+
const appContent = tree.read(appComponentInfo.filePath, 'utf-8');
|
|
163
|
+
const isRouterPresent = appContent.match(/react-router-dom/);
|
|
164
|
+
if (isRouterPresent) {
|
|
165
|
+
const serverEntry = (0, devkit_1.joinPathFragments)(projectRoot, 'src/main.server.tsx');
|
|
166
|
+
const { content, source } = readEntryFile(tree, serverEntry);
|
|
167
|
+
const changes = (0, devkit_1.applyChangesToString)(content, (0, ast_utils_1.addStaticRouter)(serverEntry, source));
|
|
168
|
+
tree.write(serverEntry, changes);
|
|
169
|
+
}
|
|
170
|
+
(0, devkit_1.updateNxJson)(tree, nxJson);
|
|
171
|
+
const installTask = (0, devkit_1.addDependenciesToPackageJson)(tree, {
|
|
172
|
+
express: versions_1.expressVersion,
|
|
173
|
+
isbot: versions_1.isbotVersion,
|
|
174
|
+
cors: versions_1.corsVersion,
|
|
175
|
+
}, {
|
|
176
|
+
'@types/express': versions_1.typesExpressVersion,
|
|
177
|
+
'@types/cors': versions_1.typesCorsVersion,
|
|
178
|
+
});
|
|
179
|
+
await (0, devkit_1.formatFiles)(tree);
|
|
180
|
+
return installTask;
|
|
181
|
+
}
|
|
182
|
+
exports.setupSsrGenerator = setupSsrGenerator;
|
|
183
|
+
exports.default = setupSsrGenerator;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
const { join } = require('path');
|
|
2
|
+
|
|
3
|
+
// Note: If you use library-specific PostCSS/Tailwind configuration then you should remove the `postcssConfig` build
|
|
4
|
+
// option from your application's configuration (i.e. project.json).
|
|
5
|
+
//
|
|
6
|
+
// See: https://nx.dev/guides/using-tailwind-css-in-react#step-4:-applying-configuration-to-libraries
|
|
7
|
+
|
|
8
|
+
module.exports = {
|
|
9
|
+
plugins: {
|
|
10
|
+
tailwindcss: {
|
|
11
|
+
config: join(__dirname, 'tailwind.config.js'),
|
|
12
|
+
},
|
|
13
|
+
autoprefixer: {},
|
|
14
|
+
},
|
|
15
|
+
}
|