@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,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/schema",
|
|
3
|
+
"$id": "NxReactNgInit",
|
|
4
|
+
"title": "Init React Plugin",
|
|
5
|
+
"description": "Initialize a React Plugin.",
|
|
6
|
+
"cli": "nx",
|
|
7
|
+
"type": "object",
|
|
8
|
+
"properties": {
|
|
9
|
+
"skipFormat": {
|
|
10
|
+
"description": "Skip formatting files.",
|
|
11
|
+
"type": "boolean",
|
|
12
|
+
"default": false
|
|
13
|
+
},
|
|
14
|
+
"skipPackageJson": {
|
|
15
|
+
"description": "Do not add dependencies to `package.json`.",
|
|
16
|
+
"type": "boolean",
|
|
17
|
+
"default": false
|
|
18
|
+
},
|
|
19
|
+
"keepExistingVersions": {
|
|
20
|
+
"type": "boolean",
|
|
21
|
+
"x-priority": "internal",
|
|
22
|
+
"description": "Keep existing dependencies versions",
|
|
23
|
+
"default": false
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
"required": []
|
|
27
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "./tsconfig.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"outDir": "<%= offsetFromRoot %>dist/out-tsc",
|
|
5
|
+
"types": [
|
|
6
|
+
"node",
|
|
7
|
+
<% if (style === 'styled-jsx') { %>"@nx/react/typings/styled-jsx.d.ts",<% } %>
|
|
8
|
+
"@nx/react/typings/cssmodule.d.ts",
|
|
9
|
+
"@nx/react/typings/image.d.ts"
|
|
10
|
+
]
|
|
11
|
+
},
|
|
12
|
+
"exclude": ["jest.config.ts", "src/**/*.spec.ts", "src/**/*.test.ts", "src/**/*.spec.tsx", "src/**/*.test.tsx", "src/**/*.spec.js", "src/**/*.test.js", "src/**/*.spec.jsx", "src/**/*.test.jsx"],
|
|
13
|
+
"include": ["src/**/*.js", "src/**/*.jsx", "src/**/*.ts", "src/**/*.tsx"]
|
|
14
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "./tsconfig.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"outDir": "<%= offsetFromRoot %>dist/out-tsc",
|
|
5
|
+
"types": [
|
|
6
|
+
"node",
|
|
7
|
+
<% if (style === 'styled-jsx') { %>"@nx/react/typings/styled-jsx.d.ts",<% } %>
|
|
8
|
+
"@nx/react/typings/cssmodule.d.ts",
|
|
9
|
+
"@nx/react/typings/image.d.ts"
|
|
10
|
+
]
|
|
11
|
+
},
|
|
12
|
+
"exclude": ["**/*.spec.ts", "**/*.test.ts", "**/*.spec.tsx", "**/*.test.tsx", "**/*.spec.js", "**/*.test.js", "**/*.spec.jsx", "**/*.test.jsx"],
|
|
13
|
+
"include": ["src/**/*.js", "src/**/*.jsx", "src/**/*.ts", "src/**/*.tsx"]
|
|
14
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.addLinting = void 0;
|
|
4
|
+
const eslint_1 = require("@nx/eslint");
|
|
5
|
+
const path_1 = require("nx/src/utils/path");
|
|
6
|
+
const devkit_1 = require("@nx/devkit");
|
|
7
|
+
const lint_1 = require("../../../utils/lint");
|
|
8
|
+
const eslint_file_1 = require("@nx/eslint/src/generators/utils/eslint-file");
|
|
9
|
+
async function addLinting(host, options) {
|
|
10
|
+
if (options.linter === eslint_1.Linter.EsLint) {
|
|
11
|
+
const lintTask = await (0, eslint_1.lintProjectGenerator)(host, {
|
|
12
|
+
linter: options.linter,
|
|
13
|
+
project: options.name,
|
|
14
|
+
tsConfigPaths: [
|
|
15
|
+
(0, path_1.joinPathFragments)(options.projectRoot, 'tsconfig.lib.json'),
|
|
16
|
+
],
|
|
17
|
+
unitTestRunner: options.unitTestRunner,
|
|
18
|
+
skipFormat: true,
|
|
19
|
+
skipPackageJson: options.skipPackageJson,
|
|
20
|
+
setParserOptionsProject: options.setParserOptionsProject,
|
|
21
|
+
addPlugin: options.addPlugin,
|
|
22
|
+
});
|
|
23
|
+
if ((0, eslint_file_1.isEslintConfigSupported)(host)) {
|
|
24
|
+
(0, eslint_file_1.addExtendsToLintConfig)(host, options.projectRoot, 'plugin:@nx/react');
|
|
25
|
+
}
|
|
26
|
+
let installTask = () => { };
|
|
27
|
+
if (!options.skipPackageJson) {
|
|
28
|
+
installTask = (0, devkit_1.addDependenciesToPackageJson)(host, lint_1.extraEslintDependencies.dependencies, lint_1.extraEslintDependencies.devDependencies);
|
|
29
|
+
}
|
|
30
|
+
return (0, devkit_1.runTasksInSerial)(lintTask, installTask);
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
return () => { };
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
exports.addLinting = addLinting;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.addRollupBuildTarget = void 0;
|
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
const maybe_js_1 = require("../../../utils/maybe-js");
|
|
6
|
+
const versions_1 = require("../../../utils/versions");
|
|
7
|
+
async function addRollupBuildTarget(host, options) {
|
|
8
|
+
const tasks = [];
|
|
9
|
+
const { configurationGenerator } = (0, devkit_1.ensurePackage)('@nx/rollup', versions_1.nxVersion);
|
|
10
|
+
tasks.push(await configurationGenerator(host, {
|
|
11
|
+
...options,
|
|
12
|
+
project: options.name,
|
|
13
|
+
skipFormat: true,
|
|
14
|
+
}));
|
|
15
|
+
if (!options.skipPackageJson) {
|
|
16
|
+
// These are used in `@nx/react/plugins/bundle-rollup`
|
|
17
|
+
tasks.push((0, devkit_1.addDependenciesToPackageJson)(host, {}, {
|
|
18
|
+
'@rollup/plugin-url': versions_1.rollupPluginUrlVersion,
|
|
19
|
+
'@svgr/rollup': versions_1.svgrRollupVersion,
|
|
20
|
+
}));
|
|
21
|
+
}
|
|
22
|
+
const { targets } = (0, devkit_1.readProjectConfiguration)(host, options.name);
|
|
23
|
+
const external = ['react', 'react-dom'];
|
|
24
|
+
if (options.style === '@emotion/styled') {
|
|
25
|
+
external.push('@emotion/react/jsx-runtime');
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
external.push('react/jsx-runtime');
|
|
29
|
+
}
|
|
30
|
+
targets.build = {
|
|
31
|
+
executor: '@nx/rollup:rollup',
|
|
32
|
+
outputs: ['{options.outputPath}'],
|
|
33
|
+
options: {
|
|
34
|
+
outputPath: (0, devkit_1.joinPathFragments)('dist', options.projectRoot),
|
|
35
|
+
tsConfig: `${options.projectRoot}/tsconfig.lib.json`,
|
|
36
|
+
project: `${options.projectRoot}/package.json`,
|
|
37
|
+
entryFile: (0, maybe_js_1.maybeJs)(options, `${options.projectRoot}/src/index.ts`),
|
|
38
|
+
external,
|
|
39
|
+
rollupConfig: `@nx/react/plugins/bundle-rollup`,
|
|
40
|
+
compiler: options.compiler ?? 'babel',
|
|
41
|
+
assets: [
|
|
42
|
+
{
|
|
43
|
+
glob: `${options.projectRoot}/README.md`,
|
|
44
|
+
input: '.',
|
|
45
|
+
output: '.',
|
|
46
|
+
},
|
|
47
|
+
],
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
(0, devkit_1.updateProjectConfiguration)(host, options.name, {
|
|
51
|
+
root: options.projectRoot,
|
|
52
|
+
sourceRoot: (0, devkit_1.joinPathFragments)(options.projectRoot, 'src'),
|
|
53
|
+
projectType: 'library',
|
|
54
|
+
tags: options.parsedTags,
|
|
55
|
+
targets,
|
|
56
|
+
});
|
|
57
|
+
return (0, devkit_1.runTasksInSerial)(...tasks);
|
|
58
|
+
}
|
|
59
|
+
exports.addRollupBuildTarget = addRollupBuildTarget;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createFiles = void 0;
|
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
const js_1 = require("@nx/js");
|
|
6
|
+
const create_ts_config_1 = require("../../../utils/create-ts-config");
|
|
7
|
+
function createFiles(host, options) {
|
|
8
|
+
const relativePathToRootTsConfig = (0, js_1.getRelativePathToRootTsConfig)(host, options.projectRoot);
|
|
9
|
+
const substitutions = {
|
|
10
|
+
...options,
|
|
11
|
+
...(0, devkit_1.names)(options.name),
|
|
12
|
+
tmpl: '',
|
|
13
|
+
offsetFromRoot: (0, devkit_1.offsetFromRoot)(options.projectRoot),
|
|
14
|
+
fileName: options.fileName,
|
|
15
|
+
};
|
|
16
|
+
(0, devkit_1.generateFiles)(host, (0, devkit_1.joinPathFragments)(__dirname, '../files/common'), options.projectRoot, substitutions);
|
|
17
|
+
if (options.bundler === 'vite' || options.unitTestRunner === 'vitest') {
|
|
18
|
+
(0, devkit_1.generateFiles)(host, (0, devkit_1.joinPathFragments)(__dirname, '../files/vite'), options.projectRoot, substitutions);
|
|
19
|
+
}
|
|
20
|
+
if (options.compiler === 'babel') {
|
|
21
|
+
(0, devkit_1.writeJson)(host, (0, devkit_1.joinPathFragments)(options.projectRoot, '.babelrc'), {
|
|
22
|
+
presets: [
|
|
23
|
+
[
|
|
24
|
+
'@nx/react/babel',
|
|
25
|
+
{
|
|
26
|
+
runtime: 'automatic',
|
|
27
|
+
useBuiltIns: 'usage',
|
|
28
|
+
importSource: options.style === '@emotion/styled'
|
|
29
|
+
? '@emotion/react'
|
|
30
|
+
: undefined,
|
|
31
|
+
},
|
|
32
|
+
],
|
|
33
|
+
],
|
|
34
|
+
plugins: [
|
|
35
|
+
options.style === 'styled-components'
|
|
36
|
+
? ['styled-components', { pure: true, ssr: true }]
|
|
37
|
+
: undefined,
|
|
38
|
+
options.style === 'styled-jsx' ? 'styled-jsx/babel' : undefined,
|
|
39
|
+
options.style === '@emotion/styled'
|
|
40
|
+
? '@emotion/babel-plugin'
|
|
41
|
+
: undefined,
|
|
42
|
+
].filter(Boolean),
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
if (!options.publishable && !options.buildable) {
|
|
46
|
+
host.delete(`${options.projectRoot}/package.json`);
|
|
47
|
+
}
|
|
48
|
+
if (options.js) {
|
|
49
|
+
(0, devkit_1.toJS)(host);
|
|
50
|
+
}
|
|
51
|
+
(0, create_ts_config_1.createTsConfig)(host, options.projectRoot, 'lib', options, relativePathToRootTsConfig);
|
|
52
|
+
}
|
|
53
|
+
exports.createFiles = createFiles;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.installCommonDependencies = void 0;
|
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
const add_swc_dependencies_1 = require("@nx/js/src/utils/swc/add-swc-dependencies");
|
|
6
|
+
const versions_1 = require("../../../utils/versions");
|
|
7
|
+
function installCommonDependencies(host, options) {
|
|
8
|
+
const tasks = [];
|
|
9
|
+
const dependencies = {};
|
|
10
|
+
const devDependencies = {
|
|
11
|
+
'@types/node': versions_1.typesNodeVersion,
|
|
12
|
+
'@types/react': versions_1.typesReactVersion,
|
|
13
|
+
'@types/react-dom': versions_1.typesReactDomVersion,
|
|
14
|
+
};
|
|
15
|
+
if (options.bundler !== 'vite') {
|
|
16
|
+
dependencies['tslib'] = versions_1.tsLibVersion;
|
|
17
|
+
}
|
|
18
|
+
// Vite requires style preprocessors to be installed manually.
|
|
19
|
+
// `@nx/webpack` installs them automatically for now.
|
|
20
|
+
// TODO(jack): Once we clean up webpack we can remove this check
|
|
21
|
+
if (options.bundler === 'vite' || options.unitTestRunner === 'vitest') {
|
|
22
|
+
switch (options.style) {
|
|
23
|
+
case 'scss':
|
|
24
|
+
devDependencies['sass'] = versions_1.sassVersion;
|
|
25
|
+
break;
|
|
26
|
+
case 'less':
|
|
27
|
+
devDependencies['less'] = versions_1.lessVersion;
|
|
28
|
+
break;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
if (options.unitTestRunner && options.unitTestRunner !== 'none') {
|
|
32
|
+
devDependencies['@testing-library/react'] = versions_1.testingLibraryReactVersion;
|
|
33
|
+
}
|
|
34
|
+
const baseInstallTask = (0, devkit_1.addDependenciesToPackageJson)(host, dependencies, devDependencies);
|
|
35
|
+
tasks.push(baseInstallTask);
|
|
36
|
+
if (options.compiler === 'swc') {
|
|
37
|
+
tasks.push((0, add_swc_dependencies_1.addSwcDependencies)(host));
|
|
38
|
+
}
|
|
39
|
+
else if (options.compiler === 'babel') {
|
|
40
|
+
tasks.push((0, devkit_1.addDependenciesToPackageJson)(host, {}, {
|
|
41
|
+
'@babel/preset-react': versions_1.babelPresetReactVersion,
|
|
42
|
+
'@babel/core': versions_1.babelCoreVersion,
|
|
43
|
+
}));
|
|
44
|
+
}
|
|
45
|
+
return (0, devkit_1.runTasksInSerial)(...tasks);
|
|
46
|
+
}
|
|
47
|
+
exports.installCommonDependencies = installCommonDependencies;
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.normalizeOptions = void 0;
|
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
const project_name_and_root_utils_1 = require("@nx/devkit/src/generators/project-name-and-root-utils");
|
|
6
|
+
const assertion_1 = require("../../../utils/assertion");
|
|
7
|
+
async function normalizeOptions(host, options) {
|
|
8
|
+
const { projectName, names: projectNames, projectRoot, importPath, } = await (0, project_name_and_root_utils_1.determineProjectNameAndRootOptions)(host, {
|
|
9
|
+
name: options.name,
|
|
10
|
+
projectType: 'library',
|
|
11
|
+
directory: options.directory,
|
|
12
|
+
importPath: options.importPath,
|
|
13
|
+
projectNameAndRootFormat: options.projectNameAndRootFormat,
|
|
14
|
+
callingGenerator: '@nx/react:library',
|
|
15
|
+
});
|
|
16
|
+
const nxJson = (0, devkit_1.readNxJson)(host);
|
|
17
|
+
const addPlugin = process.env.NX_ADD_PLUGINS !== 'false' &&
|
|
18
|
+
nxJson.useInferencePlugins !== false;
|
|
19
|
+
options.addPlugin ??= addPlugin;
|
|
20
|
+
const fileName = options.simpleName
|
|
21
|
+
? projectNames.projectSimpleName
|
|
22
|
+
: projectNames.projectFileName;
|
|
23
|
+
const parsedTags = options.tags
|
|
24
|
+
? options.tags.split(',').map((s) => s.trim())
|
|
25
|
+
: [];
|
|
26
|
+
let bundler = options.bundler ?? 'none';
|
|
27
|
+
if (bundler === 'none') {
|
|
28
|
+
if (options.publishable) {
|
|
29
|
+
devkit_1.logger.warn(`Publishable libraries cannot be used with bundler: 'none'. Defaulting to 'rollup'.`);
|
|
30
|
+
bundler = 'rollup';
|
|
31
|
+
}
|
|
32
|
+
if (options.buildable) {
|
|
33
|
+
devkit_1.logger.warn(`Buildable libraries cannot be used with bundler: 'none'. Defaulting to 'rollup'.`);
|
|
34
|
+
bundler = 'rollup';
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
const normalized = {
|
|
38
|
+
...options,
|
|
39
|
+
compiler: options.compiler ?? 'babel',
|
|
40
|
+
bundler,
|
|
41
|
+
fileName,
|
|
42
|
+
routePath: `/${projectNames.projectSimpleName}`,
|
|
43
|
+
name: projectName,
|
|
44
|
+
projectRoot,
|
|
45
|
+
parsedTags,
|
|
46
|
+
importPath,
|
|
47
|
+
};
|
|
48
|
+
// Libraries with a bundler or is publishable must also be buildable.
|
|
49
|
+
normalized.buildable = Boolean(normalized.bundler !== 'none' || options.buildable || options.publishable);
|
|
50
|
+
normalized.inSourceTests === normalized.minimal || normalized.inSourceTests;
|
|
51
|
+
if (options.appProject) {
|
|
52
|
+
const appProjectConfig = (0, devkit_1.getProjects)(host).get(options.appProject);
|
|
53
|
+
if (appProjectConfig.projectType !== 'application') {
|
|
54
|
+
throw new Error(`appProject expected type of "application" but got "${appProjectConfig.projectType}"`);
|
|
55
|
+
}
|
|
56
|
+
normalized.appMain =
|
|
57
|
+
appProjectConfig.targets.build?.options?.main ??
|
|
58
|
+
findMainEntry(host, appProjectConfig.root);
|
|
59
|
+
normalized.appSourceRoot = (0, devkit_1.normalizePath)(appProjectConfig.sourceRoot);
|
|
60
|
+
// TODO(jack): We should use appEntryFile instead of appProject so users can directly set it rather than us inferring it.
|
|
61
|
+
if (!normalized.appMain) {
|
|
62
|
+
throw new Error(`Could not locate project main for ${options.appProject}`);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
(0, assertion_1.assertValidStyle)(normalized.style);
|
|
66
|
+
return normalized;
|
|
67
|
+
}
|
|
68
|
+
exports.normalizeOptions = normalizeOptions;
|
|
69
|
+
function findMainEntry(tree, projectRoot) {
|
|
70
|
+
const mainFiles = [
|
|
71
|
+
// These are the main files we generate with.
|
|
72
|
+
'src/main.ts',
|
|
73
|
+
'src/main.tsx',
|
|
74
|
+
'src/main.js',
|
|
75
|
+
'src/main.jsx',
|
|
76
|
+
// Other options just in case
|
|
77
|
+
'src/index.ts',
|
|
78
|
+
'src/index.tsx',
|
|
79
|
+
'src/index.js',
|
|
80
|
+
'src/index.jsx',
|
|
81
|
+
'main.ts',
|
|
82
|
+
'main.tsx',
|
|
83
|
+
'main.js',
|
|
84
|
+
'main.jsx',
|
|
85
|
+
'index.ts',
|
|
86
|
+
'index.tsx',
|
|
87
|
+
'index.js',
|
|
88
|
+
'index.jsx',
|
|
89
|
+
];
|
|
90
|
+
const mainEntry = mainFiles.find((file) => tree.exists((0, devkit_1.joinPathFragments)(projectRoot, file)));
|
|
91
|
+
return mainEntry ? (0, devkit_1.joinPathFragments)(projectRoot, mainEntry) : undefined;
|
|
92
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.setDefaults = void 0;
|
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
function setDefaults(host, options) {
|
|
6
|
+
const nxJson = (0, devkit_1.readNxJson)(host);
|
|
7
|
+
nxJson.generators = nxJson.generators || {};
|
|
8
|
+
nxJson.generators['@nx/react'] = nxJson.generators['@nx/react'] || {};
|
|
9
|
+
const prev = { ...nxJson.generators['@nx/react'] };
|
|
10
|
+
const libDefaults = {
|
|
11
|
+
...prev.library,
|
|
12
|
+
unitTestRunner: prev.library?.unitTestRunner ?? options.unitTestRunner,
|
|
13
|
+
};
|
|
14
|
+
nxJson.generators = {
|
|
15
|
+
...nxJson.generators,
|
|
16
|
+
'@nx/react': {
|
|
17
|
+
...prev,
|
|
18
|
+
library: libDefaults,
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
(0, devkit_1.updateNxJson)(host, nxJson);
|
|
22
|
+
}
|
|
23
|
+
exports.setDefaults = setDefaults;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.updateAppRoutes = void 0;
|
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
const ast_utils_1 = require("../../../utils/ast-utils");
|
|
6
|
+
const ast_utils_2 = require("../../../utils/ast-utils");
|
|
7
|
+
const maybe_js_1 = require("../../../utils/maybe-js");
|
|
8
|
+
const versions_1 = require("../../../utils/versions");
|
|
9
|
+
const ensure_typescript_1 = require("@nx/js/src/utils/typescript/ensure-typescript");
|
|
10
|
+
let tsModule;
|
|
11
|
+
function updateAppRoutes(host, options) {
|
|
12
|
+
if (!options.appMain || !options.appSourceRoot) {
|
|
13
|
+
return () => { };
|
|
14
|
+
}
|
|
15
|
+
const { content, source } = readComponent(host, options.appMain);
|
|
16
|
+
const componentImportPath = (0, ast_utils_1.findComponentImportPath)('App', source);
|
|
17
|
+
if (!componentImportPath) {
|
|
18
|
+
throw new Error(`Could not find App component in ${options.appMain} (Hint: you can omit --appProject, or make sure App exists)`);
|
|
19
|
+
}
|
|
20
|
+
const appComponentPath = (0, devkit_1.joinPathFragments)(options.appSourceRoot, (0, maybe_js_1.maybeJs)(options, `${componentImportPath}.tsx`));
|
|
21
|
+
const routerTask = (0, devkit_1.addDependenciesToPackageJson)(host, {
|
|
22
|
+
'react-router-dom': versions_1.reactRouterDomVersion,
|
|
23
|
+
}, {});
|
|
24
|
+
// addBrowserRouterToMain
|
|
25
|
+
const isRouterPresent = content.match(/react-router-dom/);
|
|
26
|
+
if (!isRouterPresent) {
|
|
27
|
+
const changes = (0, devkit_1.applyChangesToString)(content, (0, ast_utils_1.addBrowserRouter)(options.appMain, source));
|
|
28
|
+
host.write(options.appMain, changes);
|
|
29
|
+
}
|
|
30
|
+
// addInitialAppRoutes
|
|
31
|
+
{
|
|
32
|
+
const { content: componentContent, source: componentSource } = readComponent(host, appComponentPath);
|
|
33
|
+
const isComponentRouterPresent = componentContent.match(/react-router-dom/);
|
|
34
|
+
if (!isComponentRouterPresent) {
|
|
35
|
+
const changes = (0, devkit_1.applyChangesToString)(componentContent, (0, ast_utils_2.addInitialRoutes)(appComponentPath, componentSource));
|
|
36
|
+
host.write(appComponentPath, changes);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
// addNewAppRoute
|
|
40
|
+
{
|
|
41
|
+
const { content: componentContent, source: componentSource } = readComponent(host, appComponentPath);
|
|
42
|
+
const changes = (0, devkit_1.applyChangesToString)(componentContent, (0, ast_utils_1.addRoute)(appComponentPath, componentSource, {
|
|
43
|
+
routePath: options.routePath,
|
|
44
|
+
componentName: (0, devkit_1.names)(options.name).className,
|
|
45
|
+
moduleName: options.importPath,
|
|
46
|
+
}));
|
|
47
|
+
host.write(appComponentPath, changes);
|
|
48
|
+
}
|
|
49
|
+
return routerTask;
|
|
50
|
+
}
|
|
51
|
+
exports.updateAppRoutes = updateAppRoutes;
|
|
52
|
+
function readComponent(host, path) {
|
|
53
|
+
if (!host.exists(path)) {
|
|
54
|
+
throw new Error(`Cannot find ${path}`);
|
|
55
|
+
}
|
|
56
|
+
if (!tsModule) {
|
|
57
|
+
tsModule = (0, ensure_typescript_1.ensureTypescript)();
|
|
58
|
+
}
|
|
59
|
+
const content = host.read(path, 'utf-8');
|
|
60
|
+
const source = tsModule.createSourceFile(path, content, tsModule.ScriptTarget.Latest, true);
|
|
61
|
+
return { content, source };
|
|
62
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { GeneratorCallback, Tree } from '@nx/devkit';
|
|
2
|
+
import { Schema } from './schema';
|
|
3
|
+
export declare function libraryGenerator(host: Tree, schema: Schema): Promise<GeneratorCallback>;
|
|
4
|
+
export declare function libraryGeneratorInternal(host: Tree, schema: Schema): Promise<GeneratorCallback>;
|
|
5
|
+
export default libraryGenerator;
|