@nx/react 0.0.0-pr-31222-862e973 → 0.0.0-pr-31313-387cdca
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +1 -1
- package/generators.json +9 -13
- package/index.d.ts +1 -2
- package/index.js +2 -5
- package/mf/dynamic-federation.d.ts +64 -0
- package/mf/dynamic-federation.js +64 -0
- package/migrations.json +80 -148
- package/module-federation.d.ts +6 -4
- package/module-federation.js +16 -7
- package/package.json +11 -11
- package/plugins/bundle-rollup.js +4 -1
- package/plugins/component-testing/index.js +1 -1
- package/plugins/jest.js +6 -11
- package/plugins/nx-react-webpack-plugin/lib/apply-react-config.js +6 -22
- package/plugins/storybook/index.js +1 -2
- package/plugins/with-react.d.ts +4 -0
- package/router-plugin.d.ts +1 -0
- package/router-plugin.js +5 -0
- package/src/executors/module-federation-dev-server/lib/index.d.ts +2 -0
- package/src/executors/module-federation-dev-server/lib/index.js +5 -0
- package/src/executors/module-federation-dev-server/lib/normalize-options.d.ts +4 -0
- package/src/executors/module-federation-dev-server/lib/normalize-options.js +19 -0
- package/src/executors/module-federation-dev-server/lib/start-remotes.d.ts +5 -0
- package/src/executors/module-federation-dev-server/lib/start-remotes.js +33 -0
- package/src/executors/module-federation-dev-server/module-federation-dev-server.impl.d.ts +1 -1
- package/src/executors/module-federation-dev-server/module-federation-dev-server.impl.js +6 -110
- package/src/executors/module-federation-dev-server/schema.d.ts +9 -7
- package/src/executors/module-federation-dev-server/schema.json +15 -10
- package/src/executors/module-federation-ssr-dev-server/lib/index.d.ts +2 -0
- package/src/executors/module-federation-ssr-dev-server/lib/index.js +5 -0
- package/src/executors/module-federation-ssr-dev-server/lib/normalize-options.d.ts +4 -0
- package/src/executors/module-federation-ssr-dev-server/lib/normalize-options.js +23 -0
- package/src/executors/module-federation-ssr-dev-server/lib/start-remotes.d.ts +5 -0
- package/src/executors/module-federation-ssr-dev-server/lib/start-remotes.js +34 -0
- package/src/executors/module-federation-ssr-dev-server/module-federation-ssr-dev-server.impl.d.ts +1 -17
- package/src/executors/module-federation-ssr-dev-server/module-federation-ssr-dev-server.impl.js +5 -153
- package/src/executors/module-federation-ssr-dev-server/schema.d.ts +29 -0
- package/src/executors/module-federation-ssr-dev-server/schema.json +14 -9
- package/src/executors/module-federation-static-server/module-federation-static-server.impl.d.ts +2 -2
- package/src/executors/module-federation-static-server/module-federation-static-server.impl.js +11 -12
- package/src/executors/module-federation-static-server/schema.json +2 -1
- package/src/generators/application/application.d.ts +3 -3
- package/src/generators/application/application.js +108 -186
- package/src/generators/application/files/base-rsbuild/src/app/__fileName__.spec.tsx__tmpl__ +10 -0
- package/src/generators/application/files/base-rsbuild/src/assets/.gitkeep +0 -0
- package/src/generators/application/files/base-rsbuild/src/favicon.ico +0 -0
- package/src/generators/application/files/base-rsbuild/src/index.html +14 -0
- package/src/generators/application/files/base-rsbuild/src/main.tsx__tmpl__ +32 -0
- package/src/generators/application/files/base-rsbuild/tsconfig.app.json__tmpl__ +31 -0
- package/src/generators/application/files/base-rspack/rspack.config.js__tmpl__ +53 -0
- package/src/generators/application/files/base-rspack/src/app/__fileName__.spec.tsx__tmpl__ +3 -3
- package/src/generators/application/files/base-rspack/src/main.tsx__tmpl__ +27 -5
- package/src/generators/application/files/base-rspack/tsconfig.app.json__tmpl__ +21 -4
- package/src/generators/application/files/base-vite/src/app/__fileName__.spec.tsx__tmpl__ +3 -3
- package/src/generators/application/files/base-vite/src/main.tsx__tmpl__ +31 -6
- package/src/generators/application/files/base-vite/tsconfig.app.json__tmpl__ +20 -3
- package/src/generators/application/files/base-webpack/src/app/__fileName__.spec.tsx__tmpl__ +3 -3
- package/src/generators/application/files/base-webpack/src/main.tsx__tmpl__ +22 -2
- package/src/generators/application/files/base-webpack/tsconfig.app.json__tmpl__ +21 -4
- package/src/generators/application/files/base-webpack/webpack.config.js__tmpl__ +4 -4
- package/src/generators/application/files/react-router-ssr/common/app/app-nav.tsx__tmpl__ +14 -0
- package/src/generators/application/files/react-router-ssr/common/app/entry.client.tsx__tmpl__ +18 -0
- package/src/generators/application/files/react-router-ssr/common/app/entry.server.tsx__tmpl__ +74 -0
- package/src/generators/application/files/react-router-ssr/common/app/root.tsx__tmpl__ +51 -0
- package/src/generators/application/files/react-router-ssr/common/app/routes/about.tsx__tmpl__ +7 -0
- package/src/generators/application/files/react-router-ssr/common/app/routes.tsx__tmpl__ +6 -0
- package/src/generators/application/files/react-router-ssr/common/public/favicon.ico +0 -0
- package/src/generators/application/files/react-router-ssr/common/react-router.config.ts__tmpl__ +5 -0
- package/src/generators/application/files/react-router-ssr/common/tests/routes/_index.spec.tsx__tmpl__ +16 -0
- package/src/generators/application/files/react-router-ssr/common/tsconfig.app.json__tmpl__ +23 -0
- package/src/generators/application/files/react-router-ssr/common/tsconfig.json__tmpl__ +27 -0
- package/src/generators/application/files/react-router-ssr/non-root/.gitignore__tmpl__ +5 -0
- package/src/generators/application/files/react-router-ssr/non-root/package.json__tmpl__ +21 -0
- package/src/generators/application/files/react-router-ssr/nx-welcome/claimed/app/nx-welcome.tsx__tmpl__ +866 -0
- package/src/generators/application/files/react-router-ssr/nx-welcome/not-configured/app/nx-welcome.tsx__tmpl__ +866 -0
- package/src/generators/application/files/react-router-ssr/nx-welcome/unclaimed/app/nx-welcome.tsx__tmpl__ +864 -0
- package/src/generators/application/files/react-router-ssr/ts-solution/package.json__tmpl__ +21 -0
- package/src/generators/application/files/react-router-ssr/ts-solution/tsconfig.app.json__tmpl__ +39 -0
- package/src/generators/application/files/style-css-module/src/app/__fileName__.tsx__tmpl__ +28 -18
- package/src/generators/application/files/style-global-css/src/app/__fileName__.tsx__tmpl__ +29 -20
- package/src/generators/application/files/style-none/src/app/__fileName__.tsx__tmpl__ +26 -16
- package/src/generators/application/files/style-styled-jsx/src/app/__fileName__.tsx__tmpl__ +31 -22
- package/src/generators/application/files/style-styled-module/src/app/__fileName__.tsx__tmpl__ +30 -21
- package/src/generators/application/files/style-tailwind/src/app/__fileName__.tsx__tmpl__ +29 -19
- package/src/generators/application/lib/add-e2e.d.ts +1 -1
- package/src/generators/application/lib/add-e2e.js +74 -65
- package/src/generators/application/lib/add-jest.js +27 -2
- package/src/generators/application/lib/add-linting.d.ts +4 -0
- package/src/generators/application/lib/add-linting.js +86 -0
- package/src/generators/application/lib/add-project.js +112 -6
- package/src/generators/application/lib/add-routing.js +1 -1
- package/src/generators/application/lib/bundlers/add-rsbuild.d.ts +4 -0
- package/src/generators/application/lib/bundlers/add-rsbuild.js +63 -0
- package/src/generators/application/lib/bundlers/add-rspack.d.ts +4 -0
- package/src/generators/application/lib/bundlers/add-rspack.js +37 -0
- package/src/generators/application/lib/bundlers/add-vite.d.ts +4 -0
- package/src/generators/application/lib/bundlers/add-vite.js +76 -0
- package/src/generators/application/lib/bundlers/add-webpack.d.ts +3 -0
- package/src/generators/application/lib/bundlers/add-webpack.js +18 -0
- package/src/generators/application/lib/create-application-files.d.ts +61 -0
- package/src/generators/application/lib/create-application-files.js +102 -19
- package/src/generators/application/lib/get-app-tests.js +10 -11
- package/src/generators/application/lib/install-common-dependencies.d.ts +1 -1
- package/src/generators/application/lib/install-common-dependencies.js +18 -4
- package/src/generators/application/lib/normalize-options.d.ts +1 -3
- package/src/generators/application/lib/normalize-options.js +17 -19
- package/src/generators/application/lib/update-jest-config.js +5 -0
- package/src/generators/application/schema.d.ts +12 -6
- package/src/generators/application/schema.json +44 -42
- package/src/generators/component/component.d.ts +0 -1
- package/src/generators/component/component.js +19 -37
- package/src/generators/component/files/__fileName__.__ext__ +83 -0
- package/src/generators/component/lib/normalize-options.js +13 -15
- package/src/generators/component/schema.d.ts +13 -25
- package/src/generators/component/schema.json +13 -49
- package/src/generators/component-story/component-story.js +1 -2
- package/src/generators/component-story/files/jsx/__componentFileName__.stories.jsx__tmpl__ +5 -5
- package/src/generators/component-story/files/tsx/__componentFileName__.stories.tsx__tmpl__ +3 -4
- package/src/generators/component-test/component-test.js +1 -1
- package/src/generators/cypress-component-configuration/cypress-component-configuration.js +0 -2
- package/src/generators/cypress-component-configuration/lib/add-files.d.ts +1 -1
- package/src/generators/cypress-component-configuration/lib/add-files.js +7 -4
- package/src/generators/federate-module/federate-module.js +12 -22
- package/src/generators/federate-module/schema.d.ts +0 -1
- package/src/generators/federate-module/schema.json +13 -12
- package/src/generators/hook/files/{__fileName__.ts__tmpl__ → __fileName__.__ext__} +3 -1
- package/src/generators/hook/hook.d.ts +0 -1
- package/src/generators/hook/hook.js +35 -83
- package/src/generators/hook/schema.d.ts +4 -17
- package/src/generators/hook/schema.json +19 -46
- package/src/generators/host/files/common/src/app/__fileName__.js__tmpl__ +28 -21
- package/src/generators/host/files/common/src/main.js__tmpl__ +12 -9
- package/src/generators/host/files/common-ts/src/app/__fileName__.tsx__tmpl__ +28 -28
- package/src/generators/host/files/common-ts/src/main.ts__tmpl__ +12 -9
- package/src/generators/host/files/rspack-common/src/app/__fileName__.jsx__tmpl__ +22 -13
- package/src/generators/host/files/rspack-common/src/main.jsx__tmpl__ +12 -9
- package/src/generators/host/files/rspack-module-federation/module-federation.config.js__tmpl__ +8 -5
- package/src/generators/host/files/rspack-module-federation/rspack.config.js__tmpl__ +37 -13
- package/src/generators/host/files/rspack-module-federation/rspack.config.prod.js__tmpl__ +60 -30
- package/src/generators/host/files/rspack-module-federation-ssr/module-federation.server.config.js__tmpl__ +16 -5
- package/src/generators/host/files/rspack-module-federation-ssr/rspack.config.js__tmpl__ +66 -0
- package/src/generators/host/files/rspack-module-federation-ssr/server.ts__tmpl__ +1 -1
- package/src/generators/host/files/rspack-module-federation-ssr/src/main.server.tsx__tmpl__ +49 -0
- package/src/generators/host/files/rspack-module-federation-ssr-ts/module-federation.server.config.ts__tmpl__ +16 -7
- package/src/generators/host/files/rspack-module-federation-ssr-ts/rspack.config.ts__tmpl__ +66 -0
- package/src/generators/host/files/rspack-module-federation-ssr-ts/server.ts__tmpl__ +1 -1
- package/src/generators/host/files/rspack-module-federation-ssr-ts/src/main.server.tsx__tmpl__ +49 -0
- package/src/generators/host/files/rspack-module-federation-ts/module-federation.config.ts__tmpl__ +22 -19
- package/src/generators/host/files/rspack-module-federation-ts/rspack.config.prod.ts__tmpl__ +61 -30
- package/src/generators/host/files/rspack-module-federation-ts/rspack.config.ts__tmpl__ +37 -13
- package/src/generators/host/files/webpack-module-federation/module-federation.config.js__tmpl__ +8 -5
- package/src/generators/host/files/webpack-module-federation/webpack.config.js__tmpl__ +1 -1
- package/src/generators/host/files/webpack-module-federation/webpack.config.prod.js__tmpl__ +24 -22
- package/src/generators/host/files/webpack-module-federation-ssr/module-federation.server.config.js__tmpl__ +10 -7
- package/src/generators/host/files/webpack-module-federation-ssr/webpack.server.config.js__tmpl__ +2 -2
- package/src/generators/host/files/webpack-module-federation-ssr-ts/module-federation.server.config.ts__tmpl__ +10 -7
- package/src/generators/host/files/webpack-module-federation-ssr-ts/webpack.server.config.ts__tmpl__ +2 -2
- package/src/generators/host/files/webpack-module-federation-ts/module-federation.config.ts__tmpl__ +22 -19
- package/src/generators/host/files/webpack-module-federation-ts/webpack.config.prod.ts__tmpl__ +25 -23
- package/src/generators/host/files/webpack-module-federation-ts/webpack.config.ts__tmpl__ +4 -3
- package/src/generators/host/host.d.ts +0 -1
- package/src/generators/host/host.js +31 -27
- package/src/generators/host/lib/add-module-federation-files.js +29 -13
- package/src/generators/host/lib/normalize-host-name.d.ts +2 -0
- package/src/generators/host/lib/normalize-host-name.js +12 -0
- package/src/generators/host/lib/normalize-remote.js +10 -6
- package/src/generators/host/lib/setup-ssr-for-host.d.ts +3 -3
- package/src/generators/host/lib/setup-ssr-for-host.js +46 -22
- package/src/generators/host/lib/update-module-federation-tsconfig.d.ts +3 -0
- package/src/generators/host/lib/update-module-federation-tsconfig.js +39 -0
- package/src/generators/host/schema.d.ts +2 -5
- package/src/generators/host/schema.json +16 -27
- package/src/generators/init/init.d.ts +1 -1
- package/src/generators/init/init.js +31 -6
- package/src/generators/init/schema.d.ts +2 -0
- package/src/generators/library/files/common/tsconfig.lib.json__tmpl__ +1 -1
- package/src/generators/library/files/vite/tsconfig.lib.json__tmpl__ +1 -1
- package/src/generators/library/lib/add-linting.js +1 -1
- package/src/generators/library/lib/add-rollup-build-target.d.ts +3 -1
- package/src/generators/library/lib/add-rollup-build-target.js +34 -32
- package/src/generators/library/lib/create-files.d.ts +1 -1
- package/src/generators/library/lib/create-files.js +23 -2
- package/src/generators/library/lib/determine-entry-fields.d.ts +3 -0
- package/src/generators/library/lib/determine-entry-fields.js +22 -0
- package/src/generators/library/lib/install-common-dependencies.d.ts +1 -1
- package/src/generators/library/lib/install-common-dependencies.js +5 -3
- package/src/generators/library/lib/normalize-options.js +11 -6
- package/src/generators/library/library.js +80 -35
- package/src/generators/library/schema.d.ts +5 -5
- package/src/generators/library/schema.json +38 -36
- package/src/generators/redux/files/js/__fileName__.__ext__ +114 -0
- package/src/generators/redux/files/{__fileName__.slice.spec.ts__tmpl__ → js/__fileName__.spec.__ext__} +1 -1
- package/src/generators/redux/files/ts/__fileName__.spec.__ext__ +56 -0
- package/src/generators/redux/redux.d.ts +0 -1
- package/src/generators/redux/redux.js +27 -36
- package/src/generators/redux/schema.d.ts +12 -8
- package/src/generators/redux/schema.json +21 -23
- package/src/generators/remote/files/rspack-module-federation/module-federation.config.js__tmpl__ +10 -7
- package/src/generators/remote/files/rspack-module-federation/rspack.config.js__tmpl__ +40 -13
- package/src/generators/remote/files/rspack-module-federation-ssr/module-federation.server.config.js__tmpl__ +13 -4
- package/src/generators/remote/files/rspack-module-federation-ssr/rspack.config.js__tmpl__ +69 -0
- package/src/generators/remote/files/rspack-module-federation-ssr/server.ts__tmpl__ +2 -2
- package/src/generators/remote/files/rspack-module-federation-ssr/src/main.server.tsx__tmpl__ +45 -0
- package/src/generators/remote/files/rspack-module-federation-ssr-ts/module-federation.server.config.ts__tmpl__ +13 -4
- package/src/generators/remote/files/rspack-module-federation-ssr-ts/rspack.config.ts__tmpl__ +69 -0
- package/src/generators/remote/files/rspack-module-federation-ssr-ts/server.ts__tmpl__ +2 -2
- package/src/generators/remote/files/rspack-module-federation-ssr-ts/src/main.server.tsx__tmpl__ +45 -0
- package/src/generators/remote/files/rspack-module-federation-ts/module-federation.config.ts__tmpl__ +11 -8
- package/src/generators/remote/files/rspack-module-federation-ts/rspack.config.ts__tmpl__ +40 -13
- package/src/generators/remote/files/webpack-module-federation/module-federation.config.js__tmpl__ +10 -7
- package/src/generators/remote/files/webpack-module-federation/webpack.config.js__tmpl__ +1 -1
- package/src/generators/remote/files/webpack-module-federation-ssr/module-federation.server.config.js__tmpl__ +7 -4
- package/src/generators/remote/files/webpack-module-federation-ssr/webpack.server.config.js__tmpl__ +2 -2
- package/src/generators/remote/files/webpack-module-federation-ssr-ts/module-federation.server.config.ts__tmpl__ +8 -5
- package/src/generators/remote/files/webpack-module-federation-ssr-ts/webpack.server.config.ts__tmpl__ +2 -2
- package/src/generators/remote/files/webpack-module-federation-ts/module-federation.config.ts__tmpl__ +11 -8
- package/src/generators/remote/files/webpack-module-federation-ts/webpack.config.ts__tmpl__ +2 -2
- package/src/generators/remote/lib/setup-ssr-for-remote.d.ts +1 -1
- package/src/generators/remote/lib/setup-ssr-for-remote.js +37 -15
- package/src/generators/remote/lib/setup-tspath-for-remote.js +1 -3
- package/src/generators/remote/lib/update-host-with-remote.js +2 -2
- package/src/generators/remote/remote.d.ts +0 -1
- package/src/generators/remote/remote.js +57 -33
- package/src/generators/remote/schema.d.ts +2 -5
- package/src/generators/remote/schema.json +16 -27
- package/src/generators/setup-tailwind/lib/update-project.js +1 -2
- package/src/generators/stories/schema.json +0 -10
- package/src/generators/stories/stories.d.ts +1 -3
- package/src/generators/stories/stories.js +9 -20
- package/src/generators/storybook-configuration/configuration.js +2 -11
- package/src/generators/storybook-configuration/schema.d.ts +0 -3
- package/src/generators/storybook-configuration/schema.json +0 -15
- package/src/migrations/update-18-0-0/add-mf-env-var-to-target-defaults.js +11 -6
- package/src/migrations/update-20-2-0/migrate-mf-imports-to-new-package.d.ts +2 -0
- package/src/migrations/update-20-2-0/migrate-mf-imports-to-new-package.js +66 -0
- package/src/migrations/update-20-2-0/migrate-with-mf-import-to-new-package.d.ts +2 -0
- package/src/migrations/update-20-2-0/migrate-with-mf-import-to-new-package.js +41 -0
- package/src/migrations/update-20-3-0/ensure-nx-module-federation-package.d.ts +2 -0
- package/src/migrations/update-20-3-0/ensure-nx-module-federation-package.js +18 -0
- package/src/migrations/update-21-0-0/update-babel-loose.d.ts +2 -0
- package/src/migrations/update-21-0-0/update-babel-loose.js +30 -0
- package/src/plugins/router-plugin.d.ts +10 -0
- package/src/plugins/router-plugin.js +221 -0
- package/src/rules/update-module-federation-project.d.ts +2 -1
- package/src/rules/update-module-federation-project.js +37 -48
- package/src/utils/add-mf-env-to-inputs.d.ts +1 -1
- package/src/utils/add-mf-env-to-inputs.js +8 -11
- package/src/utils/assertion.d.ts +2 -0
- package/src/utils/assertion.js +6 -0
- package/src/utils/ast-utils.d.ts +1 -1
- package/src/utils/ast-utils.js +2 -2
- package/src/utils/create-ts-config.js +57 -7
- package/src/utils/ct-utils.d.ts +1 -1
- package/src/utils/ct-utils.js +2 -7
- package/src/utils/has-rsbuild-plugin.d.ts +2 -0
- package/src/utils/has-rsbuild-plugin.js +10 -0
- package/src/utils/has-rspack-plugin.d.ts +2 -0
- package/src/utils/has-rspack-plugin.js +10 -0
- package/src/utils/testing-generators.js +2 -4
- package/src/utils/version-utils.d.ts +14 -0
- package/src/utils/version-utils.js +56 -0
- package/src/utils/versions.d.ts +25 -17
- package/src/utils/versions.js +28 -19
- package/src/generators/component/files/__fileName__.tsx__tmpl__ +0 -84
- package/src/generators/component-cypress-spec/component-cypress-spec.d.ts +0 -13
- package/src/generators/component-cypress-spec/component-cypress-spec.js +0 -104
- package/src/generators/component-cypress-spec/files/__componentName__.__fileExt__ +0 -13
- package/src/generators/component-cypress-spec/schema.json +0 -45
- package/src/generators/host/files/rspack-module-federation-ssr/rspack.server.config.js__tmpl__ +0 -16
- package/src/generators/host/files/rspack-module-federation-ssr-ts/rspack.server.config.ts__tmpl__ +0 -16
- package/src/generators/library/files/common/package.json__tmpl__ +0 -4
- package/src/generators/library/files/vite/package.json__tmpl__ +0 -12
- package/src/generators/remote/files/rspack-module-federation-ssr/rspack.server.config.js__tmpl__ +0 -16
- package/src/generators/remote/files/rspack-module-federation-ssr-ts/rspack.server.config.ts__tmpl__ +0 -16
- package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.d.ts +0 -2
- package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.js +0 -9
- package/src/migrations/update-16-2-0-remove-package/update-16-2-0-remove-package.d.ts +0 -2
- package/src/migrations/update-16-2-0-remove-package/update-16-2-0-remove-package.js +0 -8
- package/src/migrations/update-16-3-0/remove-types-react-router-dom-package.d.ts +0 -2
- package/src/migrations/update-16-3-0/remove-types-react-router-dom-package.js +0 -8
- package/src/migrations/update-16-7-0/add-babel-core.d.ts +0 -2
- package/src/migrations/update-16-7-0/add-babel-core.js +0 -14
- package/src/migrations/update-16-7-0-add-typings/update-16-7-0-add-typings.d.ts +0 -2
- package/src/migrations/update-16-7-0-add-typings/update-16-7-0-add-typings.js +0 -57
- package/src/migrations/update-18-1-1/fix-target-defaults-inputs.d.ts +0 -2
- package/src/migrations/update-18-1-1/fix-target-defaults-inputs.js +0 -53
- package/src/module-federation/load-config.d.ts +0 -3
- package/src/module-federation/load-config.js +0 -15
- package/src/module-federation/models.d.ts +0 -24
- package/src/module-federation/models.js +0 -2
- package/src/module-federation/package-json.d.ts +0 -8
- package/src/module-federation/package-json.js +0 -12
- package/src/module-federation/utils.d.ts +0 -12
- package/src/module-federation/utils.js +0 -75
- package/src/module-federation/with-module-federation-ssr.d.ts +0 -2
- package/src/module-federation/with-module-federation-ssr.js +0 -50
- package/src/module-federation/with-module-federation.d.ts +0 -7
- package/src/module-federation/with-module-federation.js +0 -63
- package/src/utils/build-static.remotes.d.ts +0 -4
- package/src/utils/build-static.remotes.js +0 -65
- package/src/utils/format-file.d.ts +0 -1
- package/src/utils/format-file.js +0 -11
- /package/src/generators/component/files/{__fileName__.spec.tsx__tmpl__ → __fileName__.spec.__ext__} +0 -0
- /package/src/generators/hook/files/{__fileName__.spec.tsx__tmpl__ → __fileName__.spec.__specExt__} +0 -0
- /package/src/generators/redux/files/{__fileName__.slice.ts__tmpl__ → ts/__fileName__.__ext__} +0 -0
|
@@ -2,60 +2,90 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.libraryGenerator = libraryGenerator;
|
|
4
4
|
exports.libraryGeneratorInternal = libraryGeneratorInternal;
|
|
5
|
-
const path_1 = require("path");
|
|
6
5
|
const devkit_1 = require("@nx/devkit");
|
|
7
6
|
const artifact_name_and_directory_utils_1 = require("@nx/devkit/src/generators/artifact-name-and-directory-utils");
|
|
8
7
|
const log_show_project_command_1 = require("@nx/devkit/src/utils/log-show-project-command");
|
|
9
8
|
const js_1 = require("@nx/js");
|
|
10
|
-
const
|
|
9
|
+
const path_1 = require("path");
|
|
10
|
+
const add_release_config_1 = require("@nx/js/src/generators/library/utils/add-release-config");
|
|
11
|
+
const sort_fields_1 = require("@nx/js/src/utils/package-json/sort-fields");
|
|
12
|
+
const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
|
|
13
|
+
const use_legacy_versioning_1 = require("nx/src/command-line/release/config/use-legacy-versioning");
|
|
14
|
+
const create_ts_config_1 = require("../../utils/create-ts-config");
|
|
15
|
+
const jest_utils_1 = require("../../utils/jest-utils");
|
|
11
16
|
const maybe_js_1 = require("../../utils/maybe-js");
|
|
17
|
+
const versions_1 = require("../../utils/versions");
|
|
12
18
|
const component_1 = require("../component/component");
|
|
13
19
|
const init_1 = require("../init/init");
|
|
14
|
-
const jest_utils_1 = require("../../utils/jest-utils");
|
|
15
|
-
const normalize_options_1 = require("./lib/normalize-options");
|
|
16
|
-
const add_rollup_build_target_1 = require("./lib/add-rollup-build-target");
|
|
17
20
|
const add_linting_1 = require("./lib/add-linting");
|
|
18
|
-
const
|
|
21
|
+
const add_rollup_build_target_1 = require("./lib/add-rollup-build-target");
|
|
19
22
|
const create_files_1 = require("./lib/create-files");
|
|
20
|
-
const
|
|
23
|
+
const determine_entry_fields_1 = require("./lib/determine-entry-fields");
|
|
21
24
|
const install_common_dependencies_1 = require("./lib/install-common-dependencies");
|
|
25
|
+
const normalize_options_1 = require("./lib/normalize-options");
|
|
22
26
|
const set_defaults_1 = require("./lib/set-defaults");
|
|
27
|
+
const update_app_routes_1 = require("./lib/update-app-routes");
|
|
23
28
|
async function libraryGenerator(host, schema) {
|
|
24
29
|
return await libraryGeneratorInternal(host, {
|
|
25
30
|
addPlugin: false,
|
|
26
|
-
|
|
31
|
+
useProjectJson: true,
|
|
27
32
|
...schema,
|
|
28
33
|
});
|
|
29
34
|
}
|
|
30
35
|
async function libraryGeneratorInternal(host, schema) {
|
|
31
36
|
const tasks = [];
|
|
37
|
+
const jsInitTask = await (0, js_1.initGenerator)(host, {
|
|
38
|
+
...schema,
|
|
39
|
+
skipFormat: true,
|
|
40
|
+
});
|
|
41
|
+
tasks.push(jsInitTask);
|
|
32
42
|
const options = await (0, normalize_options_1.normalizeOptions)(host, schema);
|
|
33
|
-
if (options.publishable === true &&
|
|
43
|
+
if (options.publishable === true &&
|
|
44
|
+
!options.isUsingTsSolutionConfig &&
|
|
45
|
+
!schema.importPath) {
|
|
34
46
|
throw new Error(`For publishable libs you have to provide a proper "--importPath" which needs to be a valid npm package name (e.g. my-awesome-lib or @myorg/my-lib)`);
|
|
35
47
|
}
|
|
36
48
|
if (!options.component) {
|
|
37
49
|
options.style = 'none';
|
|
38
50
|
}
|
|
39
|
-
const jsInitTask = await (0, js_1.initGenerator)(host, {
|
|
40
|
-
...schema,
|
|
41
|
-
skipFormat: true,
|
|
42
|
-
});
|
|
43
|
-
tasks.push(jsInitTask);
|
|
44
51
|
const initTask = await (0, init_1.default)(host, {
|
|
45
52
|
...options,
|
|
46
53
|
skipFormat: true,
|
|
47
54
|
});
|
|
48
55
|
tasks.push(initTask);
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
+
const packageJson = {
|
|
57
|
+
name: options.importPath,
|
|
58
|
+
version: '0.0.1',
|
|
59
|
+
...(0, determine_entry_fields_1.determineEntryFields)(options),
|
|
60
|
+
files: options.publishable ? ['dist', '!**/*.tsbuildinfo'] : undefined,
|
|
61
|
+
};
|
|
62
|
+
if (!options.useProjectJson) {
|
|
63
|
+
if (options.name !== options.importPath) {
|
|
64
|
+
packageJson.nx = { name: options.name };
|
|
65
|
+
}
|
|
66
|
+
if (options.parsedTags?.length) {
|
|
67
|
+
packageJson.nx ??= {};
|
|
68
|
+
packageJson.nx.tags = options.parsedTags;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
(0, devkit_1.addProjectConfiguration)(host, options.name, {
|
|
73
|
+
root: options.projectRoot,
|
|
74
|
+
sourceRoot: (0, devkit_1.joinPathFragments)(options.projectRoot, 'src'),
|
|
75
|
+
projectType: 'library',
|
|
76
|
+
tags: options.parsedTags,
|
|
77
|
+
targets: {},
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
if (!options.useProjectJson || options.isUsingTsSolutionConfig) {
|
|
81
|
+
(0, devkit_1.writeJson)(host, `${options.projectRoot}/package.json`, packageJson);
|
|
82
|
+
}
|
|
83
|
+
(0, create_files_1.createFiles)(host, options);
|
|
84
|
+
if (options.isUsingTsSolutionConfig) {
|
|
85
|
+
await (0, ts_solution_setup_1.addProjectToTsSolutionWorkspace)(host, options.projectRoot);
|
|
86
|
+
}
|
|
56
87
|
const lintTask = await (0, add_linting_1.addLinting)(host, options);
|
|
57
88
|
tasks.push(lintTask);
|
|
58
|
-
(0, create_files_1.createFiles)(host, options);
|
|
59
89
|
// Set up build target
|
|
60
90
|
if (options.buildable && options.bundler === 'vite') {
|
|
61
91
|
const { viteConfigurationGenerator, createOrEditViteConfig } = (0, devkit_1.ensurePackage)('@nx/vite', versions_1.nxVersion);
|
|
@@ -125,6 +155,7 @@ async function libraryGeneratorInternal(host, schema) {
|
|
|
125
155
|
skipFormat: true,
|
|
126
156
|
testEnvironment: 'jsdom',
|
|
127
157
|
addPlugin: options.addPlugin,
|
|
158
|
+
compiler: options.compiler,
|
|
128
159
|
});
|
|
129
160
|
tasks.push(vitestTask);
|
|
130
161
|
createOrEditViteConfig(host, {
|
|
@@ -147,47 +178,61 @@ async function libraryGeneratorInternal(host, schema) {
|
|
|
147
178
|
}
|
|
148
179
|
if (options.component) {
|
|
149
180
|
const relativeCwd = (0, artifact_name_and_directory_utils_1.getRelativeCwd)();
|
|
150
|
-
const
|
|
181
|
+
const path = (0, devkit_1.joinPathFragments)(options.projectRoot, 'src/lib', options.fileName);
|
|
151
182
|
const componentTask = await (0, component_1.default)(host, {
|
|
152
|
-
|
|
153
|
-
name: relativeCwd ? (0, path_1.relative)(relativeCwd, name) : name,
|
|
154
|
-
project: options.name,
|
|
155
|
-
flat: true,
|
|
183
|
+
path: relativeCwd ? (0, path_1.relative)(relativeCwd, path) : path,
|
|
156
184
|
style: options.style,
|
|
157
185
|
skipTests: options.unitTestRunner === 'none' ||
|
|
158
186
|
(options.unitTestRunner === 'vitest' && options.inSourceTests == true),
|
|
159
187
|
export: true,
|
|
160
188
|
routing: options.routing,
|
|
161
189
|
js: options.js,
|
|
162
|
-
pascalCaseFiles: options.pascalCaseFiles,
|
|
163
190
|
inSourceTests: options.inSourceTests,
|
|
164
191
|
skipFormat: true,
|
|
165
192
|
globalCss: options.globalCss,
|
|
166
193
|
});
|
|
167
194
|
tasks.push(componentTask);
|
|
168
195
|
}
|
|
169
|
-
if (options.publishable
|
|
170
|
-
(0, devkit_1.
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
}
|
|
196
|
+
if (options.publishable) {
|
|
197
|
+
const projectConfiguration = (0, devkit_1.readProjectConfiguration)(host, options.name);
|
|
198
|
+
if (options.isUsingTsSolutionConfig) {
|
|
199
|
+
await (0, add_release_config_1.addReleaseConfigForTsSolution)(host, options.name, projectConfiguration);
|
|
200
|
+
}
|
|
201
|
+
else {
|
|
202
|
+
const nxJson = (0, devkit_1.readNxJson)(host);
|
|
203
|
+
await (0, add_release_config_1.addReleaseConfigForNonTsSolution)((0, use_legacy_versioning_1.shouldUseLegacyVersioning)(nxJson.release), host, options.name, projectConfiguration);
|
|
204
|
+
}
|
|
205
|
+
(0, devkit_1.updateProjectConfiguration)(host, options.name, projectConfiguration);
|
|
206
|
+
tasks.push(await (0, add_release_config_1.releaseTasks)(host));
|
|
174
207
|
}
|
|
175
208
|
if (!options.skipPackageJson) {
|
|
176
|
-
const installReactTask = (0, install_common_dependencies_1.installCommonDependencies)(host, options);
|
|
209
|
+
const installReactTask = await (0, install_common_dependencies_1.installCommonDependencies)(host, options);
|
|
177
210
|
tasks.push(installReactTask);
|
|
178
211
|
}
|
|
179
212
|
const routeTask = (0, update_app_routes_1.updateAppRoutes)(host, options);
|
|
180
213
|
tasks.push(routeTask);
|
|
181
214
|
(0, set_defaults_1.setDefaults)(host, options);
|
|
182
215
|
(0, create_ts_config_1.extractTsConfigBase)(host);
|
|
183
|
-
if (!options.skipTsConfig) {
|
|
216
|
+
if (!options.skipTsConfig && !options.isUsingTsSolutionConfig) {
|
|
184
217
|
(0, js_1.addTsConfigPath)(host, options.importPath, [
|
|
185
218
|
(0, maybe_js_1.maybeJs)(options, (0, devkit_1.joinPathFragments)(options.projectRoot, './src/index.ts')),
|
|
186
219
|
]);
|
|
187
220
|
}
|
|
221
|
+
(0, ts_solution_setup_1.updateTsconfigFiles)(host, options.projectRoot, 'tsconfig.lib.json', {
|
|
222
|
+
jsx: 'react-jsx',
|
|
223
|
+
module: 'esnext',
|
|
224
|
+
moduleResolution: 'bundler',
|
|
225
|
+
}, options.linter === 'eslint'
|
|
226
|
+
? ['eslint.config.js', 'eslint.config.cjs', 'eslint.config.mjs']
|
|
227
|
+
: undefined);
|
|
228
|
+
(0, sort_fields_1.sortPackageJsonFields)(host, options.projectRoot);
|
|
188
229
|
if (!options.skipFormat) {
|
|
189
230
|
await (0, devkit_1.formatFiles)(host);
|
|
190
231
|
}
|
|
232
|
+
// Always run install to link packages.
|
|
233
|
+
if (options.isUsingTsSolutionConfig) {
|
|
234
|
+
tasks.push(() => (0, devkit_1.installPackagesTask)(host, true));
|
|
235
|
+
}
|
|
191
236
|
tasks.push(() => {
|
|
192
237
|
(0, log_show_project_command_1.logShowProjectCommand)(options.name);
|
|
193
238
|
});
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { ProjectNameAndRootFormat } from '@nx/devkit/src/generators/project-name-and-root-utils';
|
|
2
1
|
import type { Linter, LinterType } from '@nx/eslint';
|
|
3
2
|
import type { SupportedStyles } from '../../../typings/style';
|
|
4
3
|
|
|
@@ -8,15 +7,13 @@ export interface Schema {
|
|
|
8
7
|
bundler?: 'none' | 'rollup' | 'vite';
|
|
9
8
|
compiler?: 'babel' | 'swc';
|
|
10
9
|
component?: boolean;
|
|
11
|
-
directory
|
|
12
|
-
projectNameAndRootFormat?: ProjectNameAndRootFormat;
|
|
10
|
+
directory: string;
|
|
13
11
|
globalCss?: boolean;
|
|
14
12
|
importPath?: string;
|
|
15
13
|
inSourceTests?: boolean;
|
|
16
14
|
js?: boolean;
|
|
17
15
|
linter: Linter | LinterType;
|
|
18
|
-
name
|
|
19
|
-
pascalCaseFiles?: boolean;
|
|
16
|
+
name?: string;
|
|
20
17
|
publishable?: boolean;
|
|
21
18
|
routing?: boolean;
|
|
22
19
|
setParserOptionsProject?: boolean;
|
|
@@ -30,6 +27,7 @@ export interface Schema {
|
|
|
30
27
|
minimal?: boolean;
|
|
31
28
|
simpleName?: boolean;
|
|
32
29
|
addPlugin?: boolean;
|
|
30
|
+
useProjectJson?: boolean;
|
|
33
31
|
}
|
|
34
32
|
|
|
35
33
|
export interface NormalizedSchema extends Schema {
|
|
@@ -39,7 +37,9 @@ export interface NormalizedSchema extends Schema {
|
|
|
39
37
|
projectRoot: string;
|
|
40
38
|
routePath: string;
|
|
41
39
|
parsedTags: string[];
|
|
40
|
+
importPath: string;
|
|
42
41
|
appMain?: string;
|
|
43
42
|
appSourceRoot?: string;
|
|
44
43
|
unitTestRunner: 'jest' | 'vitest' | 'none';
|
|
44
|
+
isUsingTsSolutionConfig?: boolean;
|
|
45
45
|
}
|
|
@@ -7,37 +7,30 @@
|
|
|
7
7
|
"type": "object",
|
|
8
8
|
"examples": [
|
|
9
9
|
{
|
|
10
|
-
"command": "nx g lib mylib
|
|
11
|
-
"description": "Generate `libs/
|
|
10
|
+
"command": "nx g @nx/react:lib libs/mylib",
|
|
11
|
+
"description": "Generate a library under `libs/mylib`"
|
|
12
12
|
},
|
|
13
13
|
{
|
|
14
|
-
"command": "nx g lib mylib --appProject=myapp",
|
|
15
|
-
"description": "Generate a library with routes and add them to `myapp`"
|
|
14
|
+
"command": "nx g @nx/react:lib mylib --appProject=myapp",
|
|
15
|
+
"description": "Generate a library under mylib with routes and add them to `myapp`"
|
|
16
16
|
}
|
|
17
17
|
],
|
|
18
18
|
"properties": {
|
|
19
|
-
"
|
|
19
|
+
"directory": {
|
|
20
20
|
"type": "string",
|
|
21
|
-
"description": "
|
|
21
|
+
"description": "A directory where the lib is placed.",
|
|
22
|
+
"alias": "dir",
|
|
22
23
|
"$default": {
|
|
23
24
|
"$source": "argv",
|
|
24
25
|
"index": 0
|
|
25
26
|
},
|
|
26
|
-
"x-prompt": "
|
|
27
|
-
"pattern": "(?:^@[a-zA-Z0-9-*~][a-zA-Z0-9-*._~]*\\/[a-zA-Z0-9-~][a-zA-Z0-9-._~]*|^[a-zA-Z][^:]*)$",
|
|
28
|
-
"x-priority": "important"
|
|
27
|
+
"x-prompt": "Which directory do you want to create the library in?"
|
|
29
28
|
},
|
|
30
|
-
"
|
|
29
|
+
"name": {
|
|
31
30
|
"type": "string",
|
|
32
|
-
"description": "
|
|
33
|
-
"alias": "dir",
|
|
31
|
+
"description": "Library name",
|
|
34
32
|
"x-priority": "important"
|
|
35
33
|
},
|
|
36
|
-
"projectNameAndRootFormat": {
|
|
37
|
-
"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`).",
|
|
38
|
-
"type": "string",
|
|
39
|
-
"enum": ["as-provided", "derived"]
|
|
40
|
-
},
|
|
41
34
|
"style": {
|
|
42
35
|
"description": "The file extension to be used for style files.",
|
|
43
36
|
"type": "string",
|
|
@@ -47,7 +40,10 @@
|
|
|
47
40
|
"message": "Which stylesheet format would you like to use?",
|
|
48
41
|
"type": "list",
|
|
49
42
|
"items": [
|
|
50
|
-
{
|
|
43
|
+
{
|
|
44
|
+
"value": "css",
|
|
45
|
+
"label": "CSS"
|
|
46
|
+
},
|
|
51
47
|
{
|
|
52
48
|
"value": "scss",
|
|
53
49
|
"label": "SASS(.scss) [ https://sass-lang.com ]"
|
|
@@ -56,6 +52,10 @@
|
|
|
56
52
|
"value": "less",
|
|
57
53
|
"label": "LESS [ https://lesscss.org ]"
|
|
58
54
|
},
|
|
55
|
+
{
|
|
56
|
+
"value": "tailwind",
|
|
57
|
+
"label": "tailwind [ https://tailwindcss.com/ ]"
|
|
58
|
+
},
|
|
59
59
|
{
|
|
60
60
|
"value": "styled-components",
|
|
61
61
|
"label": "styled-components [ https://styled-components.com ]"
|
|
@@ -75,17 +75,29 @@
|
|
|
75
75
|
]
|
|
76
76
|
}
|
|
77
77
|
},
|
|
78
|
+
"bundler": {
|
|
79
|
+
"type": "string",
|
|
80
|
+
"description": "The bundler to use. Choosing 'none' means this library is not buildable.",
|
|
81
|
+
"enum": ["none", "vite", "rollup"],
|
|
82
|
+
"default": "none",
|
|
83
|
+
"x-prompt": "Which bundler would you like to use to build the library? Choose 'none' to skip build setup.",
|
|
84
|
+
"x-priority": "important"
|
|
85
|
+
},
|
|
78
86
|
"linter": {
|
|
79
87
|
"description": "The tool to use for running lint checks.",
|
|
80
88
|
"type": "string",
|
|
81
89
|
"enum": ["eslint", "none"],
|
|
82
|
-
"default": "
|
|
90
|
+
"default": "none",
|
|
91
|
+
"x-prompt": "Which linter would you like to use?",
|
|
92
|
+
"x-priority": "important"
|
|
83
93
|
},
|
|
84
94
|
"unitTestRunner": {
|
|
85
95
|
"type": "string",
|
|
86
|
-
"enum": ["
|
|
96
|
+
"enum": ["vitest", "jest", "none"],
|
|
97
|
+
"default": "none",
|
|
87
98
|
"description": "Test runner to use for unit tests.",
|
|
88
|
-
"x-prompt": "What unit test runner should be used?"
|
|
99
|
+
"x-prompt": "What unit test runner should be used?",
|
|
100
|
+
"x-priority": "important"
|
|
89
101
|
},
|
|
90
102
|
"inSourceTests": {
|
|
91
103
|
"type": "boolean",
|
|
@@ -109,12 +121,6 @@
|
|
|
109
121
|
"description": "Do not update `tsconfig.json` for development experience.",
|
|
110
122
|
"x-priority": "internal"
|
|
111
123
|
},
|
|
112
|
-
"pascalCaseFiles": {
|
|
113
|
-
"type": "boolean",
|
|
114
|
-
"description": "Use pascal case component file name (e.g. `App.tsx`).",
|
|
115
|
-
"alias": "P",
|
|
116
|
-
"default": false
|
|
117
|
-
},
|
|
118
124
|
"routing": {
|
|
119
125
|
"type": "boolean",
|
|
120
126
|
"description": "Generate library with routes."
|
|
@@ -163,14 +169,6 @@
|
|
|
163
169
|
"description": "Whether or not to configure the ESLint `parserOptions.project` option. We do not do this by default for lint performance reasons.",
|
|
164
170
|
"default": false
|
|
165
171
|
},
|
|
166
|
-
"bundler": {
|
|
167
|
-
"type": "string",
|
|
168
|
-
"description": "The bundler to use. Choosing 'none' means this library is not buildable.",
|
|
169
|
-
"enum": ["none", "vite", "rollup"],
|
|
170
|
-
"default": "none",
|
|
171
|
-
"x-prompt": "Which bundler would you like to use to build the library? Choose 'none' to skip build setup.",
|
|
172
|
-
"x-priority": "important"
|
|
173
|
-
},
|
|
174
172
|
"compiler": {
|
|
175
173
|
"type": "string",
|
|
176
174
|
"enum": ["babel", "swc"],
|
|
@@ -192,7 +190,11 @@
|
|
|
192
190
|
"description": "Don't include the directory in the name of the module of the library.",
|
|
193
191
|
"type": "boolean",
|
|
194
192
|
"default": false
|
|
193
|
+
},
|
|
194
|
+
"useProjectJson": {
|
|
195
|
+
"type": "boolean",
|
|
196
|
+
"description": "Use a `project.json` configuration file instead of inlining the Nx configuration in the `package.json` file."
|
|
195
197
|
}
|
|
196
198
|
},
|
|
197
|
-
"required": ["
|
|
199
|
+
"required": ["directory"]
|
|
198
200
|
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createAsyncThunk,
|
|
3
|
+
createEntityAdapter,
|
|
4
|
+
createSelector,
|
|
5
|
+
createSlice,
|
|
6
|
+
} from '@reduxjs/toolkit';
|
|
7
|
+
|
|
8
|
+
export const <%= constantName %>_FEATURE_KEY = '<%= propertyName %>';
|
|
9
|
+
export const <%= propertyName %>Adapter = createEntityAdapter();
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Export an effect using createAsyncThunk from
|
|
13
|
+
* the Redux Toolkit: https://redux-toolkit.js.org/api/createAsyncThunk
|
|
14
|
+
*
|
|
15
|
+
* e.g.
|
|
16
|
+
* ```
|
|
17
|
+
* import React, { useEffect } from 'react';
|
|
18
|
+
* import { useDispatch } from 'react-redux';
|
|
19
|
+
*
|
|
20
|
+
* // ...
|
|
21
|
+
*
|
|
22
|
+
* const dispatch = useDispatch();
|
|
23
|
+
* useEffect(() => {
|
|
24
|
+
* dispatch(fetch<%= className %>())
|
|
25
|
+
* }, [dispatch]);
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export const fetch<%= className %> = createAsyncThunk(
|
|
29
|
+
'<%= propertyName %>/fetchStatus',
|
|
30
|
+
async (_, thunkAPI) => {
|
|
31
|
+
/**
|
|
32
|
+
* Replace this with your custom fetch call.
|
|
33
|
+
* For example, `return myApi.get<%= className %>s()`;
|
|
34
|
+
* Right now we just return an empty array.
|
|
35
|
+
*/
|
|
36
|
+
return Promise.resolve([]);
|
|
37
|
+
}
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
export const initial<%= className %>State = <%= propertyName %>Adapter.getInitialState({
|
|
41
|
+
loadingStatus: 'not loaded',
|
|
42
|
+
error: null
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
export const <%= propertyName %>Slice = createSlice({
|
|
46
|
+
name: <%= constantName %>_FEATURE_KEY,
|
|
47
|
+
initialState: initial<%= className %>State,
|
|
48
|
+
reducers: {
|
|
49
|
+
add: <%= propertyName %>Adapter.addOne,
|
|
50
|
+
remove: <%= propertyName %>Adapter.removeOne
|
|
51
|
+
// ...
|
|
52
|
+
},
|
|
53
|
+
extraReducers: builder => {
|
|
54
|
+
builder
|
|
55
|
+
.addCase(fetch<%= className %>.pending, (state) => {
|
|
56
|
+
state.loadingStatus = 'loading';
|
|
57
|
+
})
|
|
58
|
+
.addCase(fetch<%= className %>.fulfilled, (state, action) => {
|
|
59
|
+
<%= propertyName %>Adapter.setAll(state, action.payload);
|
|
60
|
+
state.loadingStatus = 'loaded';
|
|
61
|
+
})
|
|
62
|
+
.addCase(fetch<%= className %>.rejected, (state, action) => {
|
|
63
|
+
state.loadingStatus = 'error';
|
|
64
|
+
state.error = action.error.message;
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
/*
|
|
70
|
+
* Export reducer for store configuration.
|
|
71
|
+
*/
|
|
72
|
+
export const <%= propertyName %>Reducer = <%= propertyName %>Slice.reducer;
|
|
73
|
+
|
|
74
|
+
/*
|
|
75
|
+
* Export action creators to be dispatched. For use with the `useDispatch` hook.
|
|
76
|
+
*
|
|
77
|
+
* e.g.
|
|
78
|
+
* ```
|
|
79
|
+
* import React, { useEffect } from 'react';
|
|
80
|
+
* import { useDispatch } from 'react-redux';
|
|
81
|
+
*
|
|
82
|
+
* // ...
|
|
83
|
+
*
|
|
84
|
+
* const dispatch = useDispatch();
|
|
85
|
+
* useEffect(() => {
|
|
86
|
+
* dispatch(<%= propertyName %>Actions.add({ id: 1 }))
|
|
87
|
+
* }, [dispatch]);
|
|
88
|
+
* ```
|
|
89
|
+
*
|
|
90
|
+
* See: https://react-redux.js.org/next/api/hooks#usedispatch
|
|
91
|
+
*/
|
|
92
|
+
export const <%= propertyName %>Actions = <%= propertyName %>Slice.actions;
|
|
93
|
+
|
|
94
|
+
/*
|
|
95
|
+
* Export selectors to query state. For use with the `useSelector` hook.
|
|
96
|
+
*
|
|
97
|
+
* e.g.
|
|
98
|
+
* ```
|
|
99
|
+
* import { useSelector } from 'react-redux';
|
|
100
|
+
*
|
|
101
|
+
* // ...
|
|
102
|
+
*
|
|
103
|
+
* const entities = useSelector(selectAll<%= className %>);
|
|
104
|
+
* ```
|
|
105
|
+
*
|
|
106
|
+
* See: https://react-redux.js.org/next/api/hooks#useselector
|
|
107
|
+
*/
|
|
108
|
+
const { selectAll, selectEntities } = <%= propertyName %>Adapter.getSelectors();
|
|
109
|
+
|
|
110
|
+
export const get<%= className %>State = (rootState) => rootState[<%= constantName %>_FEATURE_KEY];
|
|
111
|
+
|
|
112
|
+
export const selectAll<%= className %> = createSelector(get<%= className %>State, selectAll);
|
|
113
|
+
|
|
114
|
+
export const select<%= className %>Entities = createSelector(get<%= className %>State, selectEntities);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { fetch<%= className %>, <%= propertyName %>Adapter, <%= propertyName %>Reducer } from './<%= fileName
|
|
1
|
+
import { fetch<%= className %>, <%= propertyName %>Adapter, <%= propertyName %>Reducer } from './<%= fileName %>';
|
|
2
2
|
|
|
3
3
|
describe('<%= propertyName %> reducer', () => {
|
|
4
4
|
it('should handle initial state', () => {
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { fetch<%= className %>, <%= propertyName %>Adapter, <%= propertyName %>Reducer } from './<%= fileName %>';
|
|
2
|
+
|
|
3
|
+
describe('<%= propertyName %> reducer', () => {
|
|
4
|
+
it('should handle initial state', () => {
|
|
5
|
+
const expected = <%= propertyName %>Adapter.getInitialState({
|
|
6
|
+
loadingStatus: 'not loaded',
|
|
7
|
+
error: null
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
expect(<%= propertyName %>Reducer(undefined, { type: '' })).toEqual(expected);
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it('should handle fetch<%= className %>', () => {
|
|
14
|
+
let state = <%= propertyName %>Reducer(
|
|
15
|
+
undefined,
|
|
16
|
+
fetch<%= className %>.pending('')
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
expect(state).toEqual(
|
|
20
|
+
expect.objectContaining({
|
|
21
|
+
loadingStatus: 'loading',
|
|
22
|
+
error: null,
|
|
23
|
+
entities: {},
|
|
24
|
+
ids: []
|
|
25
|
+
})
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
state = <%= propertyName %>Reducer(
|
|
29
|
+
state,
|
|
30
|
+
fetch<%= className %>.fulfilled([{ id: 1 }], '')
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
expect(state).toEqual(
|
|
34
|
+
expect.objectContaining({
|
|
35
|
+
loadingStatus: 'loaded',
|
|
36
|
+
error: null,
|
|
37
|
+
entities: { 1: { id: 1 } },
|
|
38
|
+
ids: [1]
|
|
39
|
+
})
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
state = <%= propertyName %>Reducer(
|
|
43
|
+
state,
|
|
44
|
+
fetch<%= className %>.rejected(new Error('Uh oh'), '')
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
expect(state).toEqual(
|
|
48
|
+
expect.objectContaining({
|
|
49
|
+
loadingStatus: 'error',
|
|
50
|
+
error: 'Uh oh',
|
|
51
|
+
entities: { 1: { id: 1 } },
|
|
52
|
+
ids: [1]
|
|
53
|
+
})
|
|
54
|
+
);
|
|
55
|
+
});
|
|
56
|
+
});
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Schema } from './schema';
|
|
2
2
|
import { Tree } from '@nx/devkit';
|
|
3
3
|
export declare function reduxGenerator(host: Tree, schema: Schema): Promise<import("@nx/devkit").GeneratorCallback>;
|
|
4
|
-
export declare function reduxGeneratorInternal(host: Tree, schema: Schema): Promise<import("@nx/devkit").GeneratorCallback>;
|
|
5
4
|
export default reduxGenerator;
|