@nx/react 23.0.0-beta.20 → 23.0.0-beta.22
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/generators.json +16 -3
- package/migrations.json +12 -6
- package/package.json +16 -16
- package/src/executors/module-federation-dev-server/module-federation-dev-server.impl.d.ts.map +1 -1
- package/src/executors/module-federation-dev-server/module-federation-dev-server.impl.js +2 -0
- package/src/executors/module-federation-dev-server/schema.json +1 -0
- package/src/executors/module-federation-ssr-dev-server/module-federation-ssr-dev-server.impl.d.ts.map +1 -1
- package/src/executors/module-federation-ssr-dev-server/module-federation-ssr-dev-server.impl.js +2 -0
- package/src/executors/module-federation-ssr-dev-server/schema.json +1 -0
- package/src/executors/module-federation-static-server/module-federation-static-server.impl.d.ts.map +1 -1
- package/src/executors/module-federation-static-server/module-federation-static-server.impl.js +2 -0
- package/src/executors/module-federation-static-server/schema.json +1 -0
- package/src/generators/_utils/mf-dependencies.d.ts +8 -0
- package/src/generators/_utils/mf-dependencies.d.ts.map +1 -0
- package/src/generators/_utils/mf-dependencies.js +84 -0
- package/src/generators/_utils/mf-versions.d.ts +12 -0
- package/src/generators/_utils/mf-versions.d.ts.map +1 -0
- package/src/generators/_utils/mf-versions.js +29 -0
- package/src/generators/_utils/normalize.d.ts +20 -0
- package/src/generators/_utils/normalize.d.ts.map +1 -0
- package/src/generators/_utils/normalize.js +48 -0
- package/src/generators/consumer/consumer.d.ts +5 -0
- package/src/generators/consumer/consumer.d.ts.map +1 -0
- package/src/generators/consumer/consumer.js +135 -0
- package/src/generators/consumer/files/_common/src/App.tsx__tmpl__ +53 -0
- package/src/generators/consumer/files/_common/src/bootstrap.tsx__tmpl__ +12 -0
- package/src/generators/consumer/files/_common/src/index.ts__tmpl__ +4 -0
- package/src/generators/consumer/files/_common/src/mf.ts__tmpl__ +35 -0
- package/src/generators/consumer/files/_common/tsconfig.json__tmpl__ +17 -0
- package/src/generators/consumer/files/rsbuild/index.html__tmpl__ +12 -0
- package/src/generators/consumer/files/rsbuild/package.json__tmpl__ +23 -0
- package/src/generators/consumer/files/rsbuild/rsbuild.config.ts__tmpl__ +25 -0
- package/src/generators/consumer/files/rspack/index.html__tmpl__ +12 -0
- package/src/generators/consumer/files/rspack/package.json__tmpl__ +23 -0
- package/src/generators/consumer/files/rspack/rspack.config.ts__tmpl__ +59 -0
- package/src/generators/consumer/files/vite/index.html__tmpl__ +12 -0
- package/src/generators/consumer/files/vite/package.json__tmpl__ +24 -0
- package/src/generators/consumer/files/vite/vite.config.ts__tmpl__ +27 -0
- package/src/generators/consumer/schema.d.ts +8 -0
- package/src/generators/consumer/schema.json +43 -0
- package/src/generators/federate-module/federate-module.d.ts.map +1 -1
- package/src/generators/federate-module/federate-module.js +2 -0
- package/src/generators/host/host.d.ts.map +1 -1
- package/src/generators/host/host.js +2 -0
- package/src/generators/provider/files/_common/src/__componentName__.tsx__tmpl__ +11 -0
- package/src/generators/provider/files/_common/src/bootstrap.tsx__tmpl__ +12 -0
- package/src/generators/provider/files/_common/src/index.ts__tmpl__ +5 -0
- package/src/generators/provider/files/_common/tsconfig.json__tmpl__ +17 -0
- package/src/generators/provider/files/rsbuild/index.html__tmpl__ +12 -0
- package/src/generators/provider/files/rsbuild/package.json__tmpl__ +22 -0
- package/src/generators/provider/files/rsbuild/rsbuild.config.ts__tmpl__ +31 -0
- package/src/generators/provider/files/rspack/index.html__tmpl__ +12 -0
- package/src/generators/provider/files/rspack/package.json__tmpl__ +22 -0
- package/src/generators/provider/files/rspack/rspack.config.ts__tmpl__ +69 -0
- package/src/generators/provider/files/vite/index.html__tmpl__ +12 -0
- package/src/generators/provider/files/vite/package.json__tmpl__ +23 -0
- package/src/generators/provider/files/vite/vite.config.ts__tmpl__ +37 -0
- package/src/generators/provider/provider.d.ts +5 -0
- package/src/generators/provider/provider.d.ts.map +1 -0
- package/src/generators/provider/provider.js +92 -0
- package/src/generators/provider/schema.d.ts +9 -0
- package/src/generators/provider/schema.json +46 -0
- package/src/generators/remote/remote.d.ts.map +1 -1
- package/src/generators/remote/remote.js +2 -0
- package/src/migrations/update-18-0-0/add-mf-env-var-to-target-defaults.md +36 -0
- package/src/migrations/update-20-2-0/migrate-mf-imports-to-new-package.md +27 -0
- package/src/migrations/update-20-2-0/migrate-with-mf-import-to-new-package.md +25 -0
- package/src/migrations/update-20-3-0/ensure-nx-module-federation-package.md +23 -0
- package/src/migrations/update-21-0-0/update-babel-loose.md +43 -0
- package/src/migrations/update-23-0-0/remove-nx-react-webpack-plugin-import.md +52 -0
- package/src/utils/module-federation-deprecation.d.ts +13 -0
- package/src/utils/module-federation-deprecation.d.ts.map +1 -0
- package/src/utils/module-federation-deprecation.js +46 -0
package/generators.json
CHANGED
|
@@ -65,14 +65,26 @@
|
|
|
65
65
|
"schema": "./src/generators/host/schema.json",
|
|
66
66
|
"x-type": "application",
|
|
67
67
|
"description": "Generate a host react application",
|
|
68
|
-
"
|
|
68
|
+
"x-deprecated": "Use `@nx/react:consumer` instead (dynamic federation, no static-serve orchestration). Removed in Nx v24."
|
|
69
69
|
},
|
|
70
70
|
"remote": {
|
|
71
71
|
"factory": "./src/generators/remote/remote",
|
|
72
72
|
"schema": "./src/generators/remote/schema.json",
|
|
73
73
|
"x-type": "application",
|
|
74
74
|
"description": "Generate a remote react application",
|
|
75
|
-
"
|
|
75
|
+
"x-deprecated": "Use `@nx/react:provider` instead. Removed in Nx v24."
|
|
76
|
+
},
|
|
77
|
+
"consumer": {
|
|
78
|
+
"factory": "./src/generators/consumer/consumer",
|
|
79
|
+
"schema": "./src/generators/consumer/schema.json",
|
|
80
|
+
"x-type": "application",
|
|
81
|
+
"description": "Create a React Module Federation consumer that loads federated components dynamically via an inline PROVIDERS list in src/mf.ts. Supports Vite (default), Rsbuild, and Rspack."
|
|
82
|
+
},
|
|
83
|
+
"provider": {
|
|
84
|
+
"factory": "./src/generators/provider/provider",
|
|
85
|
+
"schema": "./src/generators/provider/schema.json",
|
|
86
|
+
"x-type": "application",
|
|
87
|
+
"description": "Create a React Module Federation provider that exposes a federated component. Supports Vite (default), Rsbuild, and Rspack."
|
|
76
88
|
},
|
|
77
89
|
"cypress-component-configuration": {
|
|
78
90
|
"factory": "./src/generators/cypress-component-configuration/cypress-component-configuration#cypressComponentConfigGenerator",
|
|
@@ -96,7 +108,8 @@
|
|
|
96
108
|
"factory": "./src/generators/federate-module/federate-module#federateModuleGenerator",
|
|
97
109
|
"schema": "./src/generators/federate-module/schema.json",
|
|
98
110
|
"description": "Federate a module.",
|
|
99
|
-
"hidden": false
|
|
111
|
+
"hidden": false,
|
|
112
|
+
"x-deprecated": "The new `@nx/react:provider` generator exposes modules directly. Removed in Nx v24."
|
|
100
113
|
}
|
|
101
114
|
}
|
|
102
115
|
}
|
package/migrations.json
CHANGED
|
@@ -4,31 +4,36 @@
|
|
|
4
4
|
"cli": "nx",
|
|
5
5
|
"version": "20.2.0-beta.2",
|
|
6
6
|
"description": "Update the ModuleFederationConfig import use @nx/module-federation.",
|
|
7
|
-
"factory": "./src/migrations/update-20-2-0/migrate-mf-imports-to-new-package"
|
|
7
|
+
"factory": "./src/migrations/update-20-2-0/migrate-mf-imports-to-new-package",
|
|
8
|
+
"documentation": "./src/migrations/update-20-2-0/migrate-mf-imports-to-new-package.md"
|
|
8
9
|
},
|
|
9
10
|
"update-20-2-0-update-with-module-federation-import": {
|
|
10
11
|
"cli": "nx",
|
|
11
12
|
"version": "20.2.0-beta.2",
|
|
12
13
|
"description": "Update the withModuleFederation import use @nx/module-federation/webpack.",
|
|
13
|
-
"factory": "./src/migrations/update-20-2-0/migrate-with-mf-import-to-new-package"
|
|
14
|
+
"factory": "./src/migrations/update-20-2-0/migrate-with-mf-import-to-new-package",
|
|
15
|
+
"documentation": "./src/migrations/update-20-2-0/migrate-with-mf-import-to-new-package.md"
|
|
14
16
|
},
|
|
15
17
|
"ensure-nx-module-federation-package": {
|
|
16
18
|
"cli": "nx",
|
|
17
19
|
"version": "20.3.0-beta.2",
|
|
18
20
|
"description": "If workspace includes Module Federation projects, ensure the new @nx/module-federation package is installed.",
|
|
19
|
-
"factory": "./src/migrations/update-20-3-0/ensure-nx-module-federation-package"
|
|
21
|
+
"factory": "./src/migrations/update-20-3-0/ensure-nx-module-federation-package",
|
|
22
|
+
"documentation": "./src/migrations/update-20-3-0/ensure-nx-module-federation-package.md"
|
|
20
23
|
},
|
|
21
24
|
"add-mf-env-var-to-target-defaults": {
|
|
22
25
|
"cli": "nx",
|
|
23
26
|
"version": "20.4.0-beta.0",
|
|
24
27
|
"description": "Add NX_MF_DEV_REMOTES to inputs for task hashing when '@nx/webpack:webpack' or '@nx/rspack:rspack' is used for Module Federation.",
|
|
25
|
-
"factory": "./src/migrations/update-18-0-0/add-mf-env-var-to-target-defaults"
|
|
28
|
+
"factory": "./src/migrations/update-18-0-0/add-mf-env-var-to-target-defaults",
|
|
29
|
+
"documentation": "./src/migrations/update-18-0-0/add-mf-env-var-to-target-defaults.md"
|
|
26
30
|
},
|
|
27
31
|
"update-21-0-0-update-babel-loose": {
|
|
28
32
|
"cli": "nx",
|
|
29
33
|
"version": "21.0.0-beta.11",
|
|
30
34
|
"description": "Replaces `classProperties.loose` option with `loose`.",
|
|
31
|
-
"factory": "./src/migrations/update-21-0-0/update-babel-loose"
|
|
35
|
+
"factory": "./src/migrations/update-21-0-0/update-babel-loose",
|
|
36
|
+
"documentation": "./src/migrations/update-21-0-0/update-babel-loose.md"
|
|
32
37
|
},
|
|
33
38
|
"update-22-0-0-add-svgr-to-webpack-config": {
|
|
34
39
|
"cli": "nx",
|
|
@@ -40,7 +45,8 @@
|
|
|
40
45
|
"cli": "nx",
|
|
41
46
|
"version": "23.0.0-beta.10",
|
|
42
47
|
"description": "Rewrites imports of NxReactWebpackPlugin from '@nx/react' to the sub-path '@nx/react/webpack-plugin'.",
|
|
43
|
-
"factory": "./src/migrations/update-23-0-0/remove-nx-react-webpack-plugin-import"
|
|
48
|
+
"factory": "./src/migrations/update-23-0-0/remove-nx-react-webpack-plugin-import",
|
|
49
|
+
"documentation": "./src/migrations/update-23-0-0/remove-nx-react-webpack-plugin-import.md"
|
|
44
50
|
}
|
|
45
51
|
},
|
|
46
52
|
"packageJsonUpdates": {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/react",
|
|
3
|
-
"version": "23.0.0-beta.
|
|
3
|
+
"version": "23.0.0-beta.22",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "The React plugin for Nx contains executors and generators for managing React applications and libraries within an Nx workspace. It provides:\n\n\n- Integration with libraries such as Jest, Vitest, Playwright, Cypress, and Storybook.\n\n- Generators for applications, libraries, components, hooks, and more.\n\n- Library build support for publishing packages to npm or other registries.\n\n- Utilities for automatic workspace refactoring.",
|
|
6
6
|
"repository": {
|
|
@@ -37,28 +37,28 @@
|
|
|
37
37
|
"@svgr/webpack": "^8.0.1",
|
|
38
38
|
"minimatch": "10.2.5",
|
|
39
39
|
"tslib": "^2.3.0",
|
|
40
|
-
"@nx/devkit": "23.0.0-beta.
|
|
41
|
-
"@nx/js": "23.0.0-beta.
|
|
42
|
-
"@nx/eslint": "23.0.0-beta.
|
|
43
|
-
"@nx/web": "23.0.0-beta.
|
|
44
|
-
"@nx/module-federation": "23.0.0-beta.
|
|
45
|
-
"@nx/rollup": "23.0.0-beta.
|
|
40
|
+
"@nx/devkit": "23.0.0-beta.22",
|
|
41
|
+
"@nx/js": "23.0.0-beta.22",
|
|
42
|
+
"@nx/eslint": "23.0.0-beta.22",
|
|
43
|
+
"@nx/web": "23.0.0-beta.22",
|
|
44
|
+
"@nx/module-federation": "23.0.0-beta.22",
|
|
45
|
+
"@nx/rollup": "23.0.0-beta.22",
|
|
46
46
|
"express": "^4.21.2",
|
|
47
47
|
"http-proxy-middleware": "^3.0.5",
|
|
48
48
|
"semver": "^7.6.3"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
|
-
"@nx/cypress": "23.0.0-beta.
|
|
52
|
-
"@nx/playwright": "23.0.0-beta.
|
|
53
|
-
"@nx/rsbuild": "23.0.0-beta.
|
|
54
|
-
"@nx/vite": "23.0.0-beta.
|
|
55
|
-
"@nx/vitest": "23.0.0-beta.
|
|
56
|
-
"@nx/webpack": "23.0.0-beta.
|
|
57
|
-
"@nx/storybook": "23.0.0-beta.
|
|
58
|
-
"nx": "23.0.0-beta.
|
|
51
|
+
"@nx/cypress": "23.0.0-beta.22",
|
|
52
|
+
"@nx/playwright": "23.0.0-beta.22",
|
|
53
|
+
"@nx/rsbuild": "23.0.0-beta.22",
|
|
54
|
+
"@nx/vite": "23.0.0-beta.22",
|
|
55
|
+
"@nx/vitest": "23.0.0-beta.22",
|
|
56
|
+
"@nx/webpack": "23.0.0-beta.22",
|
|
57
|
+
"@nx/storybook": "23.0.0-beta.22",
|
|
58
|
+
"nx": "23.0.0-beta.22"
|
|
59
59
|
},
|
|
60
60
|
"optionalDependencies": {
|
|
61
|
-
"@nx/vite": "23.0.0-beta.
|
|
61
|
+
"@nx/vite": "23.0.0-beta.22"
|
|
62
62
|
},
|
|
63
63
|
"publishConfig": {
|
|
64
64
|
"access": "public"
|
package/src/executors/module-federation-dev-server/module-federation-dev-server.impl.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"module-federation-dev-server.impl.d.ts","sourceRoot":"","sources":["../../../../../../packages/react/src/executors/module-federation-dev-server/module-federation-dev-server.impl.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAU,MAAM,YAAY,CAAC;AAarD,OAAO,EAAE,gCAAgC,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"module-federation-dev-server.impl.d.ts","sourceRoot":"","sources":["../../../../../../packages/react/src/executors/module-federation-dev-server/module-federation-dev-server.impl.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAU,MAAM,YAAY,CAAC;AAarD,OAAO,EAAE,gCAAgC,EAAE,MAAM,UAAU,CAAC;AAG5D,wBAA+B,yBAAyB,CACtD,MAAM,EAAE,gCAAgC,EACxC,OAAO,EAAE,eAAe,GACvB,qBAAqB,CAAC;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,CAwG/D"}
|
|
@@ -12,7 +12,9 @@ const dev_server_impl_1 = tslib_1.__importDefault(require("@nx/webpack/src/execu
|
|
|
12
12
|
const fs_1 = require("fs");
|
|
13
13
|
const path_1 = require("path");
|
|
14
14
|
const lib_1 = require("./lib");
|
|
15
|
+
const module_federation_deprecation_1 = require("../../utils/module-federation-deprecation");
|
|
15
16
|
async function* moduleFederationDevServer(schema, context) {
|
|
17
|
+
(0, module_federation_deprecation_1.warnReactMfDevServerExecutorDeprecation)();
|
|
16
18
|
const options = (0, lib_1.normalizeOptions)(schema);
|
|
17
19
|
const currIter = options.static
|
|
18
20
|
? (0, file_server_impl_1.default)({
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
"continuous": true,
|
|
4
4
|
"outputCapture": "direct-nodejs",
|
|
5
5
|
"title": "Module Federation Dev Server",
|
|
6
|
+
"x-deprecated": "The `@nx/react:module-federation-dev-server` executor is deprecated. Dynamic federation in `@nx/react:consumer` removes the need for host-orchestrated remote serving. Removed in Nx v24.",
|
|
6
7
|
"description": "Serve a web application.",
|
|
7
8
|
"cli": "nx",
|
|
8
9
|
"type": "object",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"module-federation-ssr-dev-server.impl.d.ts","sourceRoot":"","sources":["../../../../../../packages/react/src/executors/module-federation-ssr-dev-server/module-federation-ssr-dev-server.impl.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAU,MAAM,YAAY,CAAC;AAYrD,OAAO,EAAE,mCAAmC,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"module-federation-ssr-dev-server.impl.d.ts","sourceRoot":"","sources":["../../../../../../packages/react/src/executors/module-federation-ssr-dev-server/module-federation-ssr-dev-server.impl.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAU,MAAM,YAAY,CAAC;AAYrD,OAAO,EAAE,mCAAmC,EAAE,MAAM,UAAU,CAAC;AAG/D,wBAA+B,4BAA4B,CACzD,mBAAmB,EAAE,mCAAmC,EACxD,OAAO,EAAE,eAAe,iCA6GzB"}
|
package/src/executors/module-federation-ssr-dev-server/module-federation-ssr-dev-server.impl.js
CHANGED
|
@@ -11,7 +11,9 @@ const ssr_dev_server_impl_1 = tslib_1.__importDefault(require("@nx/webpack/src/e
|
|
|
11
11
|
const fs_1 = require("fs");
|
|
12
12
|
const path_1 = require("path");
|
|
13
13
|
const lib_1 = require("./lib");
|
|
14
|
+
const module_federation_deprecation_1 = require("../../utils/module-federation-deprecation");
|
|
14
15
|
async function* moduleFederationSsrDevServer(ssrDevServerOptions, context) {
|
|
16
|
+
(0, module_federation_deprecation_1.warnReactMfSsrDevServerExecutorDeprecation)();
|
|
15
17
|
const options = (0, lib_1.normalizeOptions)(ssrDevServerOptions);
|
|
16
18
|
// TODO(JamesHenry): remove type assertion once the nx repo is updated to use https://github.com/nrwl/nx/pull/33095
|
|
17
19
|
let iter = (0, ssr_dev_server_impl_1.default)(options, context);
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
"continuous": true,
|
|
4
4
|
"outputCapture": "direct-nodejs",
|
|
5
5
|
"title": "Module Federation SSR Dev Server",
|
|
6
|
+
"x-deprecated": "The `@nx/react:module-federation-ssr-dev-server` executor is deprecated. SSR is not first-classed in the new `@nx/react:consumer`/`@nx/react:provider` generators. Removed in Nx v24.",
|
|
6
7
|
"description": "Serve a SSR Consumer (host) application along with its known Producers (remotes).",
|
|
7
8
|
"cli": "nx",
|
|
8
9
|
"type": "object",
|
package/src/executors/module-federation-static-server/module-federation-static-server.impl.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"module-federation-static-server.impl.d.ts","sourceRoot":"","sources":["../../../../../../packages/react/src/executors/module-federation-static-server/module-federation-static-server.impl.ts"],"names":[],"mappings":"AAaA,OAAO,EAIL,mBAAmB,EACpB,MAAM,iCAAiC,CAAC;
|
|
1
|
+
{"version":3,"file":"module-federation-static-server.impl.d.ts","sourceRoot":"","sources":["../../../../../../packages/react/src/executors/module-federation-static-server/module-federation-static-server.impl.ts"],"names":[],"mappings":"AAaA,OAAO,EAIL,mBAAmB,EACpB,MAAM,iCAAiC,CAAC;AAQzC,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAEhE,OAAO,EAAE,gCAAgC,EAAE,MAAM,wCAAwC,CAAC;AAC1F,OAAO,EAAE,kCAAkC,EAAE,MAAM,UAAU,CAAC;AAgJ9D,wBAAgB,YAAY,CAC1B,mBAAmB,EAAE,mBAAmB,EACxC,gBAAgB,EAAE,gCAAgC,EAClD,oBAAoB,EAAE,MAAM,EAC5B,wBAAwB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAChD,UAAU,CAAC,EAAE;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,QAgEvD;AAED,wBAA+B,4BAA4B,CACzD,MAAM,EAAE,kCAAkC,EAC1C,OAAO,EAAE,eAAe;;;aAkJzB"}
|
package/src/executors/module-federation-static-server/module-federation-static-server.impl.js
CHANGED
|
@@ -10,6 +10,7 @@ const utils_1 = require("@nx/module-federation/src/executors/utils");
|
|
|
10
10
|
const utils_2 = require("@nx/module-federation/src/utils");
|
|
11
11
|
const file_server_impl_1 = tslib_1.__importDefault(require("@nx/web/src/executors/file-server/file-server.impl"));
|
|
12
12
|
const wait_for_port_open_1 = require("@nx/web/src/utils/wait-for-port-open");
|
|
13
|
+
const module_federation_deprecation_1 = require("../../utils/module-federation-deprecation");
|
|
13
14
|
const child_process_1 = require("child_process");
|
|
14
15
|
const fs_1 = require("fs");
|
|
15
16
|
const path_1 = require("path");
|
|
@@ -159,6 +160,7 @@ function startProxies(staticRemotesConfig, hostServeOptions, mappedLocationOfHos
|
|
|
159
160
|
devkit_1.logger.info('NX Static Consumer (host) proxy started successfully');
|
|
160
161
|
}
|
|
161
162
|
async function* moduleFederationStaticServer(schema, context) {
|
|
163
|
+
(0, module_federation_deprecation_1.warnReactMfStaticServerExecutorDeprecation)();
|
|
162
164
|
// Force Node to resolve to look for the nx binary that is inside node_modules
|
|
163
165
|
const nxBin = require.resolve('nx/bin/nx');
|
|
164
166
|
// Get the remotes from the module federation config
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
"continuous": true,
|
|
4
4
|
"outputCapture": "direct-nodejs",
|
|
5
5
|
"title": "Module Federation Static Dev Server",
|
|
6
|
+
"x-deprecated": "The `@nx/react:module-federation-static-server` executor is deprecated. Use `vite preview` / `rsbuild preview` via `nx:run-commands` instead. Removed in Nx v24.",
|
|
6
7
|
"description": "Serve a Consumer (host) application statically along with its Producers (remotes).",
|
|
7
8
|
"cli": "nx",
|
|
8
9
|
"type": "object",
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { SupportedBundler } from './normalize';
|
|
2
|
+
export interface DepsBundle {
|
|
3
|
+
dependencies: Record<string, string>;
|
|
4
|
+
devDependencies: Record<string, string>;
|
|
5
|
+
}
|
|
6
|
+
export declare function getProviderDeps(bundler: SupportedBundler): DepsBundle;
|
|
7
|
+
export declare function getConsumerDeps(bundler: SupportedBundler): DepsBundle;
|
|
8
|
+
//# sourceMappingURL=mf-dependencies.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mf-dependencies.d.ts","sourceRoot":"","sources":["../../../../../../packages/react/src/generators/_utils/mf-dependencies.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAEpD,MAAM,WAAW,UAAU;IACzB,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACrC,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACzC;AAQD,wBAAgB,eAAe,CAAC,OAAO,EAAE,gBAAgB,GAAG,UAAU,CAarE;AAED,wBAAgB,eAAe,CAAC,OAAO,EAAE,gBAAgB,GAAG,UAAU,CAcrE"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getProviderDeps = getProviderDeps;
|
|
4
|
+
exports.getConsumerDeps = getConsumerDeps;
|
|
5
|
+
const tslib_1 = require("tslib");
|
|
6
|
+
const mfVersions = tslib_1.__importStar(require("./mf-versions"));
|
|
7
|
+
const versions_1 = require("@nx/js/src/utils/versions");
|
|
8
|
+
const versions_2 = require("../../utils/versions");
|
|
9
|
+
// Returned to both surfaces:
|
|
10
|
+
// - addDependenciesToPackageJson(tree, deps, devDeps) writes to root package.json
|
|
11
|
+
// so bare `vite` / `rsbuild` / `rspack` in the run-commands serve target resolve
|
|
12
|
+
// in integrated workspaces.
|
|
13
|
+
// - The per-project package.json template uses the same map so a pnpm-workspace
|
|
14
|
+
// setup (which installs per-project) gets the same versions without drift.
|
|
15
|
+
function getProviderDeps(bundler) {
|
|
16
|
+
const base = {
|
|
17
|
+
dependencies: {
|
|
18
|
+
react: versions_2.reactVersion,
|
|
19
|
+
'react-dom': versions_2.reactDomVersion,
|
|
20
|
+
},
|
|
21
|
+
devDependencies: {
|
|
22
|
+
'@types/react': versions_2.typesReactVersion,
|
|
23
|
+
'@types/react-dom': versions_2.typesReactDomVersion,
|
|
24
|
+
typescript: versions_1.typescriptVersion,
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
return mergeWith(base, bundlerDeps(bundler));
|
|
28
|
+
}
|
|
29
|
+
function getConsumerDeps(bundler) {
|
|
30
|
+
const base = {
|
|
31
|
+
dependencies: {
|
|
32
|
+
'@module-federation/runtime': mfVersions.moduleFederationRuntimeVersion,
|
|
33
|
+
react: versions_2.reactVersion,
|
|
34
|
+
'react-dom': versions_2.reactDomVersion,
|
|
35
|
+
},
|
|
36
|
+
devDependencies: {
|
|
37
|
+
'@types/react': versions_2.typesReactVersion,
|
|
38
|
+
'@types/react-dom': versions_2.typesReactDomVersion,
|
|
39
|
+
typescript: versions_1.typescriptVersion,
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
return mergeWith(base, bundlerDeps(bundler));
|
|
43
|
+
}
|
|
44
|
+
function bundlerDeps(bundler) {
|
|
45
|
+
switch (bundler) {
|
|
46
|
+
case 'vite':
|
|
47
|
+
return {
|
|
48
|
+
dependencies: {},
|
|
49
|
+
devDependencies: {
|
|
50
|
+
'@module-federation/vite': mfVersions.moduleFederationVitePluginVersion,
|
|
51
|
+
'@vitejs/plugin-react': mfVersions.vitejsPluginReactVersion,
|
|
52
|
+
vite: mfVersions.viteVersion,
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
case 'rsbuild':
|
|
56
|
+
return {
|
|
57
|
+
dependencies: {},
|
|
58
|
+
devDependencies: {
|
|
59
|
+
'@module-federation/rsbuild-plugin': mfVersions.moduleFederationRsbuildPluginVersion,
|
|
60
|
+
'@rsbuild/core': mfVersions.rsbuildCoreVersion,
|
|
61
|
+
'@rsbuild/plugin-react': mfVersions.rsbuildPluginReactVersion,
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
case 'rspack':
|
|
65
|
+
// Rspack provider/consumer both put @module-federation/enhanced in
|
|
66
|
+
// dependencies (it's imported at runtime by the federation plugin call).
|
|
67
|
+
return {
|
|
68
|
+
dependencies: {
|
|
69
|
+
'@module-federation/enhanced': mfVersions.moduleFederationEnhancedVersion,
|
|
70
|
+
},
|
|
71
|
+
devDependencies: {
|
|
72
|
+
'@rspack/cli': mfVersions.rspackCliVersion,
|
|
73
|
+
'@rspack/core': mfVersions.rspackCoreVersion,
|
|
74
|
+
'@rspack/dev-server': mfVersions.rspackDevServerVersion,
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
function mergeWith(a, b) {
|
|
80
|
+
return {
|
|
81
|
+
dependencies: { ...a.dependencies, ...b.dependencies },
|
|
82
|
+
devDependencies: { ...a.devDependencies, ...b.devDependencies },
|
|
83
|
+
};
|
|
84
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare const moduleFederationEnhancedVersion = "^2.4.0";
|
|
2
|
+
export declare const moduleFederationVitePluginVersion = "^1.15.5";
|
|
3
|
+
export declare const moduleFederationRuntimeVersion = "^2.4.0";
|
|
4
|
+
export declare const viteVersion = "^8.0.13";
|
|
5
|
+
export declare const vitejsPluginReactVersion = "^6.0.2";
|
|
6
|
+
export declare const rsbuildCoreVersion = "^1.4.0";
|
|
7
|
+
export declare const rsbuildPluginReactVersion = "^1.3.0";
|
|
8
|
+
export declare const moduleFederationRsbuildPluginVersion = "^2.5.0";
|
|
9
|
+
export declare const rspackCoreVersion = "^2.0.3";
|
|
10
|
+
export declare const rspackCliVersion = "^2.0.3";
|
|
11
|
+
export declare const rspackDevServerVersion = "2.0.1";
|
|
12
|
+
//# sourceMappingURL=mf-versions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mf-versions.d.ts","sourceRoot":"","sources":["../../../../../../packages/react/src/generators/_utils/mf-versions.ts"],"names":[],"mappings":"AAOA,eAAO,MAAM,+BAA+B,WAAW,CAAC;AACxD,eAAO,MAAM,iCAAiC,YAAY,CAAC;AAC3D,eAAO,MAAM,8BAA8B,WAAW,CAAC;AAGvD,eAAO,MAAM,WAAW,YAAY,CAAC;AACrC,eAAO,MAAM,wBAAwB,WAAW,CAAC;AAGjD,eAAO,MAAM,kBAAkB,WAAW,CAAC;AAC3C,eAAO,MAAM,yBAAyB,WAAW,CAAC;AAIlD,eAAO,MAAM,oCAAoC,WAAW,CAAC;AAG7D,eAAO,MAAM,iBAAiB,WAAW,CAAC;AAC1C,eAAO,MAAM,gBAAgB,WAAW,CAAC;AAIzC,eAAO,MAAM,sBAAsB,UAAU,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Module Federation runtime + bundler-specific deps live here. Framework
|
|
3
|
+
// versions (react, react-dom, @types/*, typescript) are owned by @nx/react
|
|
4
|
+
// (../../utils/versions) and @nx/js so each dep has a single source of truth.
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.rspackDevServerVersion = exports.rspackCliVersion = exports.rspackCoreVersion = exports.moduleFederationRsbuildPluginVersion = exports.rsbuildPluginReactVersion = exports.rsbuildCoreVersion = exports.vitejsPluginReactVersion = exports.viteVersion = exports.moduleFederationRuntimeVersion = exports.moduleFederationVitePluginVersion = exports.moduleFederationEnhancedVersion = void 0;
|
|
7
|
+
// Module Federation runtime packages. Keep `runtime` on the same major as
|
|
8
|
+
// `enhanced` / the `vite` plugin (both pull runtime 2.4.x). A 0.x runtime in
|
|
9
|
+
// the consumer would mismatch the 2.x runtime baked into the providers.
|
|
10
|
+
exports.moduleFederationEnhancedVersion = '^2.4.0';
|
|
11
|
+
exports.moduleFederationVitePluginVersion = '^1.15.5';
|
|
12
|
+
exports.moduleFederationRuntimeVersion = '^2.4.0';
|
|
13
|
+
// Vite stack.
|
|
14
|
+
exports.viteVersion = '^8.0.13';
|
|
15
|
+
exports.vitejsPluginReactVersion = '^6.0.2';
|
|
16
|
+
// Rsbuild stack.
|
|
17
|
+
exports.rsbuildCoreVersion = '^1.4.0';
|
|
18
|
+
exports.rsbuildPluginReactVersion = '^1.3.0';
|
|
19
|
+
// Official MF rsbuild integration. Peers @rsbuild/core ^1.3.21, so the pin
|
|
20
|
+
// above satisfies it. Used instead of @module-federation/enhanced/rspack so
|
|
21
|
+
// the federation config is a first-class rsbuild plugin, not a tools.rspack hack.
|
|
22
|
+
exports.moduleFederationRsbuildPluginVersion = '^2.5.0';
|
|
23
|
+
// Rspack stack.
|
|
24
|
+
exports.rspackCoreVersion = '^2.0.3';
|
|
25
|
+
exports.rspackCliVersion = '^2.0.3';
|
|
26
|
+
// Pinned (no ^) to dodge the broken 2.0.2 publish, which ships no dist/ so
|
|
27
|
+
// @rspack/cli can't load it for `rspack serve`. Re-float to ^ once upstream
|
|
28
|
+
// republishes a fixed 2.0.3+.
|
|
29
|
+
exports.rspackDevServerVersion = '2.0.1';
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Tree } from '@nx/devkit';
|
|
2
|
+
export type SupportedBundler = 'vite' | 'rsbuild' | 'rspack';
|
|
3
|
+
export type SupportedSurface = 'consumer' | 'provider';
|
|
4
|
+
export interface NormalizedScaffoldOptions {
|
|
5
|
+
projectName: string;
|
|
6
|
+
federationName: string;
|
|
7
|
+
bundler: SupportedBundler;
|
|
8
|
+
port: number;
|
|
9
|
+
projectRoot: string;
|
|
10
|
+
}
|
|
11
|
+
export interface RawScaffoldOptions {
|
|
12
|
+
directory: string;
|
|
13
|
+
surface: SupportedSurface;
|
|
14
|
+
bundler?: SupportedBundler;
|
|
15
|
+
port?: number;
|
|
16
|
+
}
|
|
17
|
+
export declare function getDefaultPort(bundler: SupportedBundler, surface: SupportedSurface): number;
|
|
18
|
+
export declare function toFederationName(projectName: string): string;
|
|
19
|
+
export declare function normalizeScaffoldOptions(tree: Tree, raw: RawScaffoldOptions): Promise<NormalizedScaffoldOptions>;
|
|
20
|
+
//# sourceMappingURL=normalize.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"normalize.d.ts","sourceRoot":"","sources":["../../../../../../packages/react/src/generators/_utils/normalize.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,IAAI,EAAE,MAAM,YAAY,CAAC;AAGzC,MAAM,MAAM,gBAAgB,GAAG,MAAM,GAAG,SAAS,GAAG,QAAQ,CAAC;AAC7D,MAAM,MAAM,gBAAgB,GAAG,UAAU,GAAG,UAAU,CAAC;AAevD,MAAM,WAAW,yBAAyB;IACxC,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,EAAE,MAAM,CAAC;IACvB,OAAO,EAAE,gBAAgB,CAAC;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,kBAAkB;IACjC,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,gBAAgB,CAAC;IAC1B,OAAO,CAAC,EAAE,gBAAgB,CAAC;IAC3B,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,wBAAgB,cAAc,CAC5B,OAAO,EAAE,gBAAgB,EACzB,OAAO,EAAE,gBAAgB,GACxB,MAAM,CAGR;AAKD,wBAAgB,gBAAgB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAe5D;AAED,wBAAsB,wBAAwB,CAC5C,IAAI,EAAE,IAAI,EACV,GAAG,EAAE,kBAAkB,GACtB,OAAO,CAAC,yBAAyB,CAAC,CAYpC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getDefaultPort = getDefaultPort;
|
|
4
|
+
exports.toFederationName = toFederationName;
|
|
5
|
+
exports.normalizeScaffoldOptions = normalizeScaffoldOptions;
|
|
6
|
+
const devkit_1 = require("@nx/devkit");
|
|
7
|
+
const internal_1 = require("@nx/devkit/internal");
|
|
8
|
+
// Default ports are split so a `consumer` + `provider` generated with no
|
|
9
|
+
// overrides don't collide. Consumer gets the round base (the user navigates
|
|
10
|
+
// to it); providers get base+1, base+2, etc., so a manifest pointing at
|
|
11
|
+
// `consumer-base + 1` lines up with the first generated provider.
|
|
12
|
+
//
|
|
13
|
+
// Vite base deliberately avoids 5000 (macOS AirTunes binds it on the IPv4
|
|
14
|
+
// wildcard, leading to silent EADDRINUSE on `127.0.0.1`).
|
|
15
|
+
const DEFAULT_BASE_PORTS = {
|
|
16
|
+
vite: 5100,
|
|
17
|
+
rsbuild: 3100,
|
|
18
|
+
rspack: 8100,
|
|
19
|
+
};
|
|
20
|
+
function getDefaultPort(bundler, surface) {
|
|
21
|
+
const base = DEFAULT_BASE_PORTS[bundler];
|
|
22
|
+
return surface === 'consumer' ? base : base + 1;
|
|
23
|
+
}
|
|
24
|
+
// Federation `name` must be a JS identifier so the bundler can use it as a
|
|
25
|
+
// global namespace. Hyphens are allowed in project names but invalid as an
|
|
26
|
+
// identifier, so we coerce to underscores.
|
|
27
|
+
function toFederationName(projectName) {
|
|
28
|
+
if (!/[A-Za-z0-9]/.test(projectName)) {
|
|
29
|
+
throw new Error(`Cannot derive a federation name from project name '${projectName}'. Use letters, digits, hyphens, or underscores.`);
|
|
30
|
+
}
|
|
31
|
+
const candidate = projectName
|
|
32
|
+
.replace(/-/g, '_')
|
|
33
|
+
.replace(/[^A-Za-z0-9_]/g, '');
|
|
34
|
+
if (/^[0-9]/.test(candidate)) {
|
|
35
|
+
throw new Error(`Federation name '${candidate}' (derived from project '${projectName}') cannot start with a digit. Rename the project.`);
|
|
36
|
+
}
|
|
37
|
+
return candidate;
|
|
38
|
+
}
|
|
39
|
+
async function normalizeScaffoldOptions(tree, raw) {
|
|
40
|
+
const bundler = raw.bundler ?? 'vite';
|
|
41
|
+
const { projectName, projectRoot } = await (0, internal_1.determineProjectNameAndRootOptions)(tree, {
|
|
42
|
+
projectType: 'application',
|
|
43
|
+
directory: raw.directory,
|
|
44
|
+
});
|
|
45
|
+
const federationName = toFederationName((0, devkit_1.names)(projectName).fileName);
|
|
46
|
+
const port = raw.port ?? getDefaultPort(bundler, raw.surface);
|
|
47
|
+
return { projectName, federationName, bundler, port, projectRoot };
|
|
48
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { GeneratorCallback, Tree } from '@nx/devkit';
|
|
2
|
+
import type { ConsumerGeneratorSchema } from './schema';
|
|
3
|
+
export declare function consumerGenerator(tree: Tree, schema: ConsumerGeneratorSchema): Promise<GeneratorCallback>;
|
|
4
|
+
export default consumerGenerator;
|
|
5
|
+
//# sourceMappingURL=consumer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"consumer.d.ts","sourceRoot":"","sources":["../../../../../../packages/react/src/generators/consumer/consumer.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,iBAAiB,EAIjB,IAAI,EACL,MAAM,YAAY,CAAC;AAgBpB,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,UAAU,CAAC;AAgBxD,wBAAsB,iBAAiB,CACrC,IAAI,EAAE,IAAI,EACV,MAAM,EAAE,uBAAuB,GAC9B,OAAO,CAAC,iBAAiB,CAAC,CAqI5B;AAED,eAAe,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.consumerGenerator = consumerGenerator;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const devkit_1 = require("@nx/devkit");
|
|
6
|
+
const versions_1 = require("@nx/js/src/utils/versions");
|
|
7
|
+
const versions_2 = require("../../utils/versions");
|
|
8
|
+
const mfVersions = tslib_1.__importStar(require("../_utils/mf-versions"));
|
|
9
|
+
const mf_dependencies_1 = require("../_utils/mf-dependencies");
|
|
10
|
+
const normalize_1 = require("../_utils/normalize");
|
|
11
|
+
const provider_1 = tslib_1.__importDefault(require("../provider/provider"));
|
|
12
|
+
// `--mode=...` is rspack's portable equivalent of `NODE_ENV=...` and works on
|
|
13
|
+
// Windows without a shell prefix.
|
|
14
|
+
const BUNDLER_DEV_COMMAND = {
|
|
15
|
+
vite: 'vite',
|
|
16
|
+
rsbuild: 'rsbuild dev',
|
|
17
|
+
rspack: 'rspack serve --mode=development',
|
|
18
|
+
};
|
|
19
|
+
const BUNDLER_BUILD_COMMAND = {
|
|
20
|
+
vite: 'vite build',
|
|
21
|
+
rsbuild: 'rsbuild build',
|
|
22
|
+
rspack: 'rspack build --mode=production',
|
|
23
|
+
};
|
|
24
|
+
async function consumerGenerator(tree, schema) {
|
|
25
|
+
const opts = await (0, normalize_1.normalizeScaffoldOptions)(tree, {
|
|
26
|
+
directory: schema.directory,
|
|
27
|
+
surface: 'consumer',
|
|
28
|
+
bundler: schema.bundler,
|
|
29
|
+
port: schema.port,
|
|
30
|
+
});
|
|
31
|
+
// When the user explicitly passes `--providerNames=p1,p2`, generate a
|
|
32
|
+
// sibling provider app per entry and wire them into the consumer's
|
|
33
|
+
// PROVIDERS list + App.tsx. When the flag is omitted, ship a placeholder
|
|
34
|
+
// `my-provider` entry pointing at the per-bundler provider-default port
|
|
35
|
+
// without generating an actual provider project.
|
|
36
|
+
const providerNames = schema.providerNames?.length
|
|
37
|
+
? schema.providerNames
|
|
38
|
+
: ['my-provider'];
|
|
39
|
+
const shouldGenerateProviders = !!schema.providerNames?.length;
|
|
40
|
+
const providerDefaultPort = (0, normalize_1.getDefaultPort)(opts.bundler, 'provider');
|
|
41
|
+
const providers = providerNames.map((name, i) => ({
|
|
42
|
+
name,
|
|
43
|
+
// The federation container name the provider build emits. Must match the
|
|
44
|
+
// provider's federation `name`, which is derived the same way (see
|
|
45
|
+
// provider.ts / normalize.ts) - it strips chars that aren't valid in a JS
|
|
46
|
+
// identifier, so a naive `alias.replace(/-/g, '_')` in the consumer would
|
|
47
|
+
// diverge for names with dots/slashes/@ and loadRemote() would resolve the
|
|
48
|
+
// URL but look up the wrong container.
|
|
49
|
+
federationName: (0, normalize_1.toFederationName)((0, devkit_1.names)(name).fileName),
|
|
50
|
+
componentName: `Provider${(0, devkit_1.names)(name).className}`,
|
|
51
|
+
directory: (0, devkit_1.joinPathFragments)(opts.projectRoot, '..', name),
|
|
52
|
+
port: providerDefaultPort + i,
|
|
53
|
+
}));
|
|
54
|
+
(0, devkit_1.addProjectConfiguration)(tree, opts.projectName, {
|
|
55
|
+
root: opts.projectRoot,
|
|
56
|
+
sourceRoot: (0, devkit_1.joinPathFragments)(opts.projectRoot, 'src'),
|
|
57
|
+
projectType: 'application',
|
|
58
|
+
targets: {
|
|
59
|
+
serve: {
|
|
60
|
+
executor: 'nx:run-commands',
|
|
61
|
+
continuous: true,
|
|
62
|
+
options: {
|
|
63
|
+
command: BUNDLER_DEV_COMMAND[opts.bundler],
|
|
64
|
+
cwd: opts.projectRoot,
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
build: {
|
|
68
|
+
executor: 'nx:run-commands',
|
|
69
|
+
options: {
|
|
70
|
+
command: BUNDLER_BUILD_COMMAND[opts.bundler],
|
|
71
|
+
cwd: opts.projectRoot,
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
});
|
|
76
|
+
const tasks = [];
|
|
77
|
+
if (shouldGenerateProviders) {
|
|
78
|
+
for (const p of providers) {
|
|
79
|
+
tasks.push(await (0, provider_1.default)(tree, {
|
|
80
|
+
directory: p.directory,
|
|
81
|
+
bundler: opts.bundler,
|
|
82
|
+
port: p.port,
|
|
83
|
+
// Wire `nx serve <provider>` to also spin up this consumer.
|
|
84
|
+
consumer: opts.projectName,
|
|
85
|
+
}));
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
// Point at `remoteEntry.js`, which every supported bundler emits at dev
|
|
89
|
+
// time. `mf-manifest.json` is richer (https://module-federation.io/configure/manifest-fields)
|
|
90
|
+
// but `@module-federation/vite` only emits it at build time, so a consumer
|
|
91
|
+
// serving against a dev-mode vite provider would get the SPA-fallback HTML
|
|
92
|
+
// and crash on JSON.parse. Swap to mf-manifest.json manually for prod if
|
|
93
|
+
// you want the extra metadata.
|
|
94
|
+
const remotes = providers.map((p) => ({
|
|
95
|
+
// `alias` is the key the consumer references (loadRemote/lazyProvider);
|
|
96
|
+
// `name` is the provider's federation container name; `entry` is its
|
|
97
|
+
// remoteEntry.js URL.
|
|
98
|
+
alias: p.name,
|
|
99
|
+
name: p.federationName,
|
|
100
|
+
entry: `http://localhost:${p.port}/remoteEntry.js`,
|
|
101
|
+
}));
|
|
102
|
+
// Vite emits ESM `remoteEntry.js`; rspack/rsbuild emit UMD. The federation
|
|
103
|
+
// runtime needs `type: 'module'` for ESM (else loads as a classic <script>
|
|
104
|
+
// and the browser throws #RUNTIME-001) and NO type for UMD (else
|
|
105
|
+
// #RUNTIME-002). We only generate same-bundler providers via --providerNames,
|
|
106
|
+
// so a single per-consumer setting is correct.
|
|
107
|
+
const remoteType = opts.bundler === 'vite' ? 'module' : null;
|
|
108
|
+
const templateSubstitutions = {
|
|
109
|
+
projectName: opts.projectName,
|
|
110
|
+
federationName: opts.federationName,
|
|
111
|
+
port: opts.port,
|
|
112
|
+
bundler: opts.bundler,
|
|
113
|
+
providers,
|
|
114
|
+
remotes,
|
|
115
|
+
remoteType,
|
|
116
|
+
versions: {
|
|
117
|
+
...mfVersions,
|
|
118
|
+
reactVersion: versions_2.reactVersion,
|
|
119
|
+
reactDomVersion: versions_2.reactDomVersion,
|
|
120
|
+
typesReactVersion: versions_2.typesReactVersion,
|
|
121
|
+
typesReactDomVersion: versions_2.typesReactDomVersion,
|
|
122
|
+
typescriptVersion: versions_1.typescriptVersion,
|
|
123
|
+
},
|
|
124
|
+
tmpl: '',
|
|
125
|
+
};
|
|
126
|
+
(0, devkit_1.generateFiles)(tree, (0, devkit_1.joinPathFragments)(__dirname, 'files', '_common'), opts.projectRoot, templateSubstitutions);
|
|
127
|
+
(0, devkit_1.generateFiles)(tree, (0, devkit_1.joinPathFragments)(__dirname, 'files', opts.bundler), opts.projectRoot, templateSubstitutions);
|
|
128
|
+
// Write deps into the workspace root package.json so bare bundler bins
|
|
129
|
+
// resolve when nx invokes the generated run-commands serve target.
|
|
130
|
+
const deps = (0, mf_dependencies_1.getConsumerDeps)(opts.bundler);
|
|
131
|
+
tasks.push((0, devkit_1.addDependenciesToPackageJson)(tree, deps.dependencies, deps.devDependencies));
|
|
132
|
+
await (0, devkit_1.formatFiles)(tree);
|
|
133
|
+
return (0, devkit_1.runTasksInSerial)(...tasks);
|
|
134
|
+
}
|
|
135
|
+
exports.default = consumerGenerator;
|