@module-federation/modern-js 0.0.0-next-20250526074234 → 0.0.0-next-20250527065931

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.
Files changed (106) hide show
  1. package/package.json +23 -39
  2. package/dist/LICENSE +0 -21
  3. package/dist/cjs/cli/configPlugin.js +0 -379
  4. package/dist/cjs/cli/configPlugin.spec.js +0 -114
  5. package/dist/cjs/cli/index.js +0 -87
  6. package/dist/cjs/cli/manifest.js +0 -75
  7. package/dist/cjs/cli/mfRuntimePlugins/auto-fetch-data.js +0 -98
  8. package/dist/cjs/cli/mfRuntimePlugins/inject-node-fetch.js +0 -44
  9. package/dist/cjs/cli/mfRuntimePlugins/resolve-entry-ipv4.js +0 -82
  10. package/dist/cjs/cli/mfRuntimePlugins/shared-strategy.js +0 -43
  11. package/dist/cjs/cli/server/data-fetch-server-plugin.js +0 -192
  12. package/dist/cjs/cli/ssrPlugin.js +0 -236
  13. package/dist/cjs/cli/utils.js +0 -90
  14. package/dist/cjs/constant.js +0 -78
  15. package/dist/cjs/interfaces/bundler.js +0 -16
  16. package/dist/cjs/interfaces/global.js +0 -16
  17. package/dist/cjs/logger.js +0 -27
  18. package/dist/cjs/runtime/AwaitDataFetch.js +0 -144
  19. package/dist/cjs/runtime/createRemoteComponent.js +0 -327
  20. package/dist/cjs/runtime/index.js +0 -50
  21. package/dist/cjs/runtime/wrapNoSSR.js +0 -35
  22. package/dist/cjs/ssr-runtime/SSRLiveReload.js +0 -43
  23. package/dist/cjs/ssr-runtime/devPlugin.js +0 -71
  24. package/dist/cjs/ssr-runtime/downgrade.js +0 -114
  25. package/dist/cjs/ssr-runtime/injectDataFetchFunctionPlugin.js +0 -136
  26. package/dist/cjs/types/index.js +0 -16
  27. package/dist/cjs/utils/dataFetch.js +0 -211
  28. package/dist/cjs/utils/index.js +0 -54
  29. package/dist/esm/cli/configPlugin.js +0 -386
  30. package/dist/esm/cli/configPlugin.spec.js +0 -110
  31. package/dist/esm/cli/index.js +0 -81
  32. package/dist/esm/cli/manifest.js +0 -41
  33. package/dist/esm/cli/mfRuntimePlugins/auto-fetch-data.js +0 -74
  34. package/dist/esm/cli/mfRuntimePlugins/inject-node-fetch.js +0 -16
  35. package/dist/esm/cli/mfRuntimePlugins/resolve-entry-ipv4.js +0 -74
  36. package/dist/esm/cli/mfRuntimePlugins/shared-strategy.js +0 -25
  37. package/dist/esm/cli/server/data-fetch-server-plugin.js +0 -240
  38. package/dist/esm/cli/ssrPlugin.js +0 -219
  39. package/dist/esm/cli/utils.js +0 -53
  40. package/dist/esm/constant.js +0 -42
  41. package/dist/esm/interfaces/bundler.js +0 -0
  42. package/dist/esm/interfaces/global.js +0 -0
  43. package/dist/esm/logger.js +0 -7
  44. package/dist/esm/runtime/AwaitDataFetch.js +0 -131
  45. package/dist/esm/runtime/createRemoteComponent.js +0 -417
  46. package/dist/esm/runtime/index.js +0 -22
  47. package/dist/esm/runtime/wrapNoSSR.js +0 -12
  48. package/dist/esm/ssr-runtime/SSRLiveReload.js +0 -26
  49. package/dist/esm/ssr-runtime/devPlugin.js +0 -73
  50. package/dist/esm/ssr-runtime/downgrade.js +0 -150
  51. package/dist/esm/ssr-runtime/injectDataFetchFunctionPlugin.js +0 -177
  52. package/dist/esm/types/index.js +0 -0
  53. package/dist/esm/utils/dataFetch.js +0 -237
  54. package/dist/esm/utils/index.js +0 -28
  55. package/dist/esm-node/cli/configPlugin.js +0 -338
  56. package/dist/esm-node/cli/configPlugin.spec.js +0 -91
  57. package/dist/esm-node/cli/index.js +0 -62
  58. package/dist/esm-node/cli/manifest.js +0 -41
  59. package/dist/esm-node/cli/mfRuntimePlugins/auto-fetch-data.js +0 -68
  60. package/dist/esm-node/cli/mfRuntimePlugins/inject-node-fetch.js +0 -14
  61. package/dist/esm-node/cli/mfRuntimePlugins/resolve-entry-ipv4.js +0 -62
  62. package/dist/esm-node/cli/mfRuntimePlugins/shared-strategy.js +0 -23
  63. package/dist/esm-node/cli/server/data-fetch-server-plugin.js +0 -162
  64. package/dist/esm-node/cli/ssrPlugin.js +0 -200
  65. package/dist/esm-node/cli/utils.js +0 -53
  66. package/dist/esm-node/constant.js +0 -42
  67. package/dist/esm-node/interfaces/bundler.js +0 -0
  68. package/dist/esm-node/interfaces/global.js +0 -0
  69. package/dist/esm-node/logger.js +0 -7
  70. package/dist/esm-node/runtime/AwaitDataFetch.js +0 -109
  71. package/dist/esm-node/runtime/createRemoteComponent.js +0 -291
  72. package/dist/esm-node/runtime/index.js +0 -22
  73. package/dist/esm-node/runtime/wrapNoSSR.js +0 -11
  74. package/dist/esm-node/ssr-runtime/SSRLiveReload.js +0 -19
  75. package/dist/esm-node/ssr-runtime/devPlugin.js +0 -37
  76. package/dist/esm-node/ssr-runtime/downgrade.js +0 -88
  77. package/dist/esm-node/ssr-runtime/injectDataFetchFunctionPlugin.js +0 -101
  78. package/dist/esm-node/types/index.js +0 -0
  79. package/dist/esm-node/utils/dataFetch.js +0 -166
  80. package/dist/esm-node/utils/index.js +0 -27
  81. package/dist/types/cli/configPlugin.d.ts +0 -21
  82. package/dist/types/cli/configPlugin.spec.d.ts +0 -1
  83. package/dist/types/cli/index.d.ts +0 -6
  84. package/dist/types/cli/manifest.d.ts +0 -2
  85. package/dist/types/cli/mfRuntimePlugins/auto-fetch-data.d.ts +0 -3
  86. package/dist/types/cli/mfRuntimePlugins/inject-node-fetch.d.ts +0 -3
  87. package/dist/types/cli/mfRuntimePlugins/resolve-entry-ipv4.d.ts +0 -3
  88. package/dist/types/cli/mfRuntimePlugins/shared-strategy.d.ts +0 -3
  89. package/dist/types/cli/server/data-fetch-server-plugin.d.ts +0 -3
  90. package/dist/types/cli/ssrPlugin.d.ts +0 -6
  91. package/dist/types/cli/utils.d.ts +0 -6
  92. package/dist/types/constant.d.ts +0 -25
  93. package/dist/types/interfaces/bundler.d.ts +0 -18
  94. package/dist/types/interfaces/global.d.ts +0 -27
  95. package/dist/types/logger.d.ts +0 -2
  96. package/dist/types/runtime/AwaitDataFetch.d.ts +0 -19
  97. package/dist/types/runtime/createRemoteComponent.d.ts +0 -26
  98. package/dist/types/runtime/index.d.ts +0 -10
  99. package/dist/types/runtime/wrapNoSSR.d.ts +0 -9
  100. package/dist/types/ssr-runtime/SSRLiveReload.d.ts +0 -1
  101. package/dist/types/ssr-runtime/devPlugin.d.ts +0 -2
  102. package/dist/types/ssr-runtime/downgrade.d.ts +0 -4
  103. package/dist/types/ssr-runtime/injectDataFetchFunctionPlugin.d.ts +0 -7
  104. package/dist/types/types/index.d.ts +0 -24
  105. package/dist/types/utils/dataFetch.d.ts +0 -26
  106. package/dist/types/utils/index.d.ts +0 -15
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@module-federation/modern-js",
3
- "version": "0.0.0-next-20250526074234",
3
+ "version": "0.0.0-next-20250527065931",
4
4
  "files": [
5
5
  "dist/",
6
6
  "types.d.ts",
@@ -24,13 +24,9 @@
24
24
  "types": "./dist/types/runtime/index.d.ts",
25
25
  "default": "./dist/esm/runtime/index.js"
26
26
  },
27
- "./ssr-dev-plugin": {
28
- "types": "./dist/types/ssr-runtime/devPlugin.d.ts",
29
- "default": "./dist/esm/ssr-runtime/devPlugin.js"
30
- },
31
- "./ssr-inject-data-fetch-function-plugin": {
32
- "types": "./dist/types/ssr-runtime/injectDataFetchFunctionPlugin.d.ts",
33
- "default": "./dist/esm/ssr-runtime/injectDataFetchFunctionPlugin.js"
27
+ "./ssr-runtime": {
28
+ "types": "./dist/types/ssr-runtime/index.d.ts",
29
+ "default": "./dist/esm/ssr-runtime/index.js"
34
30
  },
35
31
  "./config-plugin": {
36
32
  "types": "./dist/types/cli/configPlugin.d.ts",
@@ -52,19 +48,14 @@
52
48
  "import": "./dist/esm/cli/mfRuntimePlugins/resolve-entry-ipv4.js",
53
49
  "require": "./dist/esm/cli/mfRuntimePlugins/resolve-entry-ipv4.js"
54
50
  },
55
- "./auto-fetch-data": {
56
- "types": "./dist/types/cli/mfRuntimePlugins/auto-fetch-data.d.ts",
57
- "import": "./dist/esm/cli/mfRuntimePlugins/auto-fetch-data.js",
58
- "require": "./dist/esm/cli/mfRuntimePlugins/auto-fetch-data.js"
59
- },
60
51
  "./inject-node-fetch": {
61
52
  "types": "./dist/types/cli/mfRuntimePlugins/inject-node-fetch.d.ts",
62
53
  "import": "./dist/esm/cli/mfRuntimePlugins/inject-node-fetch.js",
63
54
  "require": "./dist/esm/cli/mfRuntimePlugins/inject-node-fetch.js"
64
55
  },
65
- "./data-fetch-server-plugin": {
66
- "types": "./dist/types/cli/server/data-fetch-server-plugin.d.ts",
67
- "default": "./dist/cjs/cli/server/data-fetch-server-plugin.js"
56
+ "./server": {
57
+ "types": "./dist/types/server/index.d.ts",
58
+ "default": "./dist/cjs/server/index.js"
68
59
  }
69
60
  },
70
61
  "typesVersions": {
@@ -87,17 +78,11 @@
87
78
  "resolve-entry-ipv4": [
88
79
  "./dist/types/cli/mfRuntimePlugins/resolve-entry-ipv4.d.ts"
89
80
  ],
90
- "auto-fetch-data": [
91
- "./dist/types/cli/mfRuntimePlugins/auto-fetch-data.d.ts"
92
- ],
93
81
  "inject-node-fetch": [
94
82
  "./dist/types/cli/mfRuntimePlugins/inject-node-fetch.d.ts"
95
83
  ],
96
- "data-fetch-server-plugin": [
97
- "./dist/types/cli/server/data-fetch-server-plugin.d.ts"
98
- ],
99
- "ssr-inject-data-fetch-function-plugin": [
100
- "./dist/types/cli/server/data-fetch-server-plugin.d.ts"
84
+ "server": [
85
+ "./dist/types/server/index.d.ts"
101
86
  ]
102
87
  }
103
88
  },
@@ -106,27 +91,26 @@
106
91
  "author": "hanric <hanric.zhang@gmail.com>",
107
92
  "license": "MIT",
108
93
  "dependencies": {
109
- "@modern-js/node-bundle-require": "2.67.5",
110
- "@modern-js/utils": "2.67.5",
94
+ "@modern-js/node-bundle-require": "2.67.6",
95
+ "fs-extra": "11.3.0",
96
+ "lru-cache": "11.1.0",
111
97
  "@swc/helpers": "0.5.13",
112
98
  "node-fetch": "~3.3.0",
113
99
  "react-error-boundary": "4.1.2",
114
- "@module-federation/rsbuild-plugin": "0.0.0-next-20250526074234",
115
- "@module-federation/enhanced": "0.0.0-next-20250526074234",
116
- "@module-federation/runtime": "0.0.0-next-20250526074234",
117
- "@module-federation/node": "0.0.0-next-20250526074234",
118
- "@module-federation/sdk": "0.0.0-next-20250526074234",
119
- "@module-federation/cli": "0.0.0-next-20250526074234"
100
+ "@module-federation/rsbuild-plugin": "0.0.0-next-20250527065931",
101
+ "@module-federation/enhanced": "0.0.0-next-20250527065931",
102
+ "@module-federation/node": "0.0.0-next-20250527065931",
103
+ "@module-federation/sdk": "0.0.0-next-20250527065931",
104
+ "@module-federation/cli": "0.0.0-next-20250527065931"
120
105
  },
121
106
  "devDependencies": {
122
107
  "@rsbuild/core": "1.2.8",
123
- "@modern-js/app-tools": "2.67.5",
124
- "@modern-js/core": "2.67.5",
125
- "@modern-js/module-tools": "2.67.5",
126
- "@modern-js/runtime": "2.67.5",
127
- "@modern-js/tsconfig": "2.67.5",
128
- "@modern-js/server-runtime": "2.67.5",
129
- "@module-federation/manifest": "0.0.0-next-20250526074234"
108
+ "@modern-js/app-tools": "2.67.6",
109
+ "@modern-js/server-runtime": "2.67.6",
110
+ "@modern-js/module-tools": "2.67.6",
111
+ "@modern-js/runtime": "2.67.6",
112
+ "@modern-js/tsconfig": "2.67.6",
113
+ "@module-federation/manifest": "0.0.0-next-20250527065931"
130
114
  },
131
115
  "peerDependencies": {
132
116
  "react": ">=17",
package/dist/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2024-present zhanghang(2heal1)
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
@@ -1,379 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var configPlugin_exports = {};
30
- __export(configPlugin_exports, {
31
- addMyTypes2Ignored: () => addMyTypes2Ignored,
32
- default: () => configPlugin_default,
33
- getMFConfig: () => getMFConfig,
34
- isWebTarget: () => import_utils.isWebTarget,
35
- moduleFederationConfigPlugin: () => moduleFederationConfigPlugin,
36
- patchBundlerConfig: () => patchBundlerConfig,
37
- patchMFConfig: () => patchMFConfig,
38
- setEnv: () => setEnv,
39
- skipByTarget: () => import_utils.skipByTarget
40
- });
41
- module.exports = __toCommonJS(configPlugin_exports);
42
- var import_path = __toESM(require("path"));
43
- var import_utils = require("./utils");
44
- var import_sdk = require("@module-federation/sdk");
45
- var import_node_bundle_require = require("@modern-js/node-bundle-require");
46
- var import_constant = require("../constant");
47
- var import_utils2 = require("@module-federation/rsbuild-plugin/utils");
48
- var import_logger = __toESM(require("../logger"));
49
- var import_utils3 = require("./utils");
50
- const defaultPath = import_path.default.resolve(process.cwd(), "module-federation.config.ts");
51
- function setEnv(enableSSR) {
52
- if (enableSSR) {
53
- process.env["MF_DISABLE_EMIT_STATS"] = "true";
54
- process.env["MF_SSR_PRJ"] = "true";
55
- }
56
- }
57
- const getMFConfig = async (userConfig) => {
58
- const { config, configPath } = userConfig;
59
- if (config) {
60
- return config;
61
- }
62
- const mfConfigPath = configPath ? configPath : defaultPath;
63
- const preBundlePath = await (0, import_node_bundle_require.bundle)(mfConfigPath);
64
- const mfConfig = (await Promise.resolve().then(() => __toESM(require(preBundlePath)))).default;
65
- return mfConfig;
66
- };
67
- const injectRuntimePlugins = (runtimePlugin, runtimePlugins) => {
68
- if (!runtimePlugins.includes(runtimePlugin)) {
69
- runtimePlugins.push(runtimePlugin);
70
- }
71
- };
72
- const replaceRemoteUrl = (mfConfig, remoteIpStrategy) => {
73
- if (remoteIpStrategy && remoteIpStrategy === "inherit") {
74
- return;
75
- }
76
- if (!mfConfig.remotes) {
77
- return;
78
- }
79
- const ipv4 = (0, import_utils.getIPV4)();
80
- const handleRemoteObject = (remoteObject) => {
81
- Object.keys(remoteObject).forEach((remoteKey) => {
82
- const remote = remoteObject[remoteKey];
83
- if (Array.isArray(remote)) {
84
- return;
85
- }
86
- if (typeof remote === "string" && remote.includes(import_constant.LOCALHOST)) {
87
- remoteObject[remoteKey] = remote.replace(import_constant.LOCALHOST, ipv4);
88
- }
89
- if (typeof remote === "object" && !Array.isArray(remote.external) && remote.external.includes(import_constant.LOCALHOST)) {
90
- remote.external = remote.external.replace(import_constant.LOCALHOST, ipv4);
91
- }
92
- });
93
- };
94
- if (Array.isArray(mfConfig.remotes)) {
95
- mfConfig.remotes.forEach((remoteObject) => {
96
- if (typeof remoteObject === "string") {
97
- return;
98
- }
99
- handleRemoteObject(remoteObject);
100
- });
101
- } else if (typeof mfConfig.remotes !== "string") {
102
- handleRemoteObject(mfConfig.remotes);
103
- }
104
- };
105
- const patchDTSConfig = (mfConfig, isServer) => {
106
- if (isServer) {
107
- return;
108
- }
109
- const ModernJSRuntime = "@module-federation/modern-js/runtime";
110
- if (mfConfig.dts !== false) {
111
- var _mfConfig_dts, _mfConfig_dts1;
112
- if (typeof mfConfig.dts === "boolean" || mfConfig.dts === void 0) {
113
- mfConfig.dts = {
114
- consumeTypes: {
115
- runtimePkgs: [
116
- ModernJSRuntime
117
- ]
118
- }
119
- };
120
- } else if (((_mfConfig_dts = mfConfig.dts) === null || _mfConfig_dts === void 0 ? void 0 : _mfConfig_dts.consumeTypes) || ((_mfConfig_dts1 = mfConfig.dts) === null || _mfConfig_dts1 === void 0 ? void 0 : _mfConfig_dts1.consumeTypes) === void 0) {
121
- var _mfConfig_dts2;
122
- if (typeof mfConfig.dts.consumeTypes === "boolean" || ((_mfConfig_dts2 = mfConfig.dts) === null || _mfConfig_dts2 === void 0 ? void 0 : _mfConfig_dts2.consumeTypes) === void 0) {
123
- mfConfig.dts.consumeTypes = {
124
- runtimePkgs: [
125
- ModernJSRuntime
126
- ]
127
- };
128
- } else {
129
- mfConfig.dts.consumeTypes.runtimePkgs = mfConfig.dts.consumeTypes.runtimePkgs || [];
130
- if (!mfConfig.dts.consumeTypes.runtimePkgs.includes(ModernJSRuntime)) {
131
- mfConfig.dts.consumeTypes.runtimePkgs.push(ModernJSRuntime);
132
- }
133
- }
134
- }
135
- }
136
- };
137
- const patchMFConfig = (mfConfig, isServer, remoteIpStrategy) => {
138
- replaceRemoteUrl(mfConfig, remoteIpStrategy);
139
- (0, import_utils2.addDataFetchExposes)(mfConfig.exposes, isServer);
140
- if (mfConfig.remoteType === void 0) {
141
- mfConfig.remoteType = "script";
142
- }
143
- if (!mfConfig.name) {
144
- throw new Error(`${import_constant.PLUGIN_IDENTIFIER} mfConfig.name can not be empty!`);
145
- }
146
- const runtimePlugins = [
147
- ...mfConfig.runtimePlugins || []
148
- ];
149
- patchDTSConfig(mfConfig, isServer);
150
- injectRuntimePlugins(require.resolve("@module-federation/modern-js/shared-strategy"), runtimePlugins);
151
- injectRuntimePlugins(require.resolve("@module-federation/modern-js/auto-fetch-data"), runtimePlugins);
152
- if ((0, import_utils3.isDev)()) {
153
- injectRuntimePlugins(require.resolve("@module-federation/modern-js/resolve-entry-ipv4"), runtimePlugins);
154
- }
155
- if (isServer) {
156
- injectRuntimePlugins(require.resolve("@module-federation/node/runtimePlugin"), runtimePlugins);
157
- if ((0, import_utils3.isDev)()) {
158
- injectRuntimePlugins(require.resolve("@module-federation/node/record-dynamic-remote-entry-hash-plugin"), runtimePlugins);
159
- }
160
- injectRuntimePlugins(require.resolve("@module-federation/modern-js/inject-node-fetch"), runtimePlugins);
161
- if (!mfConfig.library) {
162
- mfConfig.library = {
163
- type: "commonjs-module",
164
- name: mfConfig.name
165
- };
166
- } else {
167
- if (!mfConfig.library.type) {
168
- mfConfig.library.type = "commonjs-module";
169
- }
170
- if (!mfConfig.library.name) {
171
- mfConfig.library.name = mfConfig.name;
172
- }
173
- }
174
- }
175
- mfConfig.runtimePlugins = runtimePlugins;
176
- if (!isServer) {
177
- var _mfConfig_library;
178
- if (((_mfConfig_library = mfConfig.library) === null || _mfConfig_library === void 0 ? void 0 : _mfConfig_library.type) === "commonjs-module") {
179
- mfConfig.library.type = "global";
180
- }
181
- return mfConfig;
182
- }
183
- mfConfig.dts = false;
184
- mfConfig.dev = false;
185
- return mfConfig;
186
- };
187
- function patchIgnoreWarning(chain) {
188
- const ignoreWarnings = chain.get("ignoreWarnings") || [];
189
- const ignoredMsgs = [
190
- "external script",
191
- "process.env.WS_NO_BUFFER_UTIL",
192
- `Can't resolve 'utf-8-validate`
193
- ];
194
- ignoreWarnings.push((warning) => {
195
- if (ignoredMsgs.some((msg) => warning.message.includes(msg))) {
196
- return true;
197
- }
198
- return false;
199
- });
200
- chain.ignoreWarnings(ignoreWarnings);
201
- }
202
- function addMyTypes2Ignored(chain, mfConfig) {
203
- const watchOptions = chain.get("watchOptions");
204
- if (!watchOptions || !watchOptions.ignored) {
205
- chain.watchOptions({
206
- ignored: /[\\/](?:\.git|node_modules|@mf-types)[\\/]/
207
- });
208
- return;
209
- }
210
- const ignored = watchOptions.ignored;
211
- const DEFAULT_IGNORED_GLOB = "**/@mf-types/**";
212
- if (Array.isArray(ignored)) {
213
- if (mfConfig.dts !== false && typeof mfConfig.dts === "object" && typeof mfConfig.dts.consumeTypes === "object" && mfConfig.dts.consumeTypes.remoteTypesFolder) {
214
- chain.watchOptions({
215
- ...watchOptions,
216
- ignored: ignored.concat(`**/${mfConfig.dts.consumeTypes.remoteTypesFolder}/**`)
217
- });
218
- } else {
219
- chain.watchOptions({
220
- ...watchOptions,
221
- ignored: ignored.concat(DEFAULT_IGNORED_GLOB)
222
- });
223
- }
224
- return;
225
- }
226
- if (typeof ignored !== "string") {
227
- chain.watchOptions({
228
- ...watchOptions,
229
- ignored: /[\\/](?:\.git|node_modules|@mf-types)[\\/]/
230
- });
231
- return;
232
- }
233
- chain.watchOptions({
234
- ...watchOptions,
235
- ignored: ignored.concat(DEFAULT_IGNORED_GLOB)
236
- });
237
- }
238
- function patchBundlerConfig(options) {
239
- var _modernjsConfig_deploy;
240
- const { chain, modernjsConfig, isServer, mfConfig, enableSSR } = options;
241
- chain.optimization.delete("runtimeChunk");
242
- patchIgnoreWarning(chain);
243
- if (!chain.output.get("chunkLoadingGlobal")) {
244
- chain.output.chunkLoadingGlobal(`chunk_${mfConfig.name}`);
245
- }
246
- if (!chain.output.get("uniqueName")) {
247
- chain.output.uniqueName(mfConfig.name);
248
- }
249
- const splitChunkConfig = chain.optimization.splitChunks.entries();
250
- if (!isServer) {
251
- (0, import_utils2.autoDeleteSplitChunkCacheGroups)(mfConfig, splitChunkConfig);
252
- }
253
- if (!isServer && enableSSR && splitChunkConfig && typeof splitChunkConfig === "object" && splitChunkConfig.cacheGroups) {
254
- splitChunkConfig.chunks = "async";
255
- import_logger.default.warn(`splitChunks.chunks = async is not allowed with stream SSR mode, it will auto changed to "async"`);
256
- }
257
- if ((0, import_utils3.isDev)() && chain.output.get("publicPath") === "auto") {
258
- var _modernjsConfig_dev, _modernjsConfig_server;
259
- const port = ((_modernjsConfig_dev = modernjsConfig.dev) === null || _modernjsConfig_dev === void 0 ? void 0 : _modernjsConfig_dev.port) || ((_modernjsConfig_server = modernjsConfig.server) === null || _modernjsConfig_server === void 0 ? void 0 : _modernjsConfig_server.port) || 8080;
260
- const publicPath = `http://localhost:${port}/`;
261
- chain.output.publicPath(publicPath);
262
- }
263
- if (isServer && enableSSR) {
264
- const uniqueName = mfConfig.name || chain.output.get("uniqueName");
265
- const chunkFileName = chain.output.get("chunkFilename");
266
- if (typeof chunkFileName === "string" && uniqueName && !chunkFileName.includes(uniqueName)) {
267
- const suffix = `${(0, import_sdk.encodeName)(uniqueName)}-[chunkhash].js`;
268
- chain.output.chunkFilename(chunkFileName.replace(".js", suffix));
269
- }
270
- }
271
- if ((0, import_utils3.isDev)() && enableSSR && !isServer) {
272
- chain.resolve.fallback.set("crypto", false).set("stream", false).set("vm", false);
273
- }
274
- if (((_modernjsConfig_deploy = modernjsConfig.deploy) === null || _modernjsConfig_deploy === void 0 ? void 0 : _modernjsConfig_deploy.microFrontend) && Object.keys(mfConfig.exposes || {}).length) {
275
- chain.optimization.usedExports(false);
276
- }
277
- }
278
- const moduleFederationConfigPlugin = (userConfig) => ({
279
- name: "@modern-js/plugin-module-federation-config",
280
- pre: [
281
- "@modern-js/plugin-initialize"
282
- ],
283
- post: [
284
- "@modern-js/plugin-module-federation"
285
- ],
286
- setup: async (api) => {
287
- var _userConfig_userConfig, _modernjsConfig_server;
288
- const modernjsConfig = api.getConfig();
289
- const mfConfig = await getMFConfig(userConfig.originPluginOptions);
290
- const csrConfig = userConfig.csrConfig || JSON.parse(JSON.stringify(mfConfig));
291
- const ssrConfig = userConfig.ssrConfig || JSON.parse(JSON.stringify(mfConfig));
292
- userConfig.ssrConfig = ssrConfig;
293
- userConfig.csrConfig = csrConfig;
294
- var _userConfig_userConfig_ssr;
295
- const enableSSR = Boolean((_userConfig_userConfig_ssr = (_userConfig_userConfig = userConfig.userConfig) === null || _userConfig_userConfig === void 0 ? void 0 : _userConfig_userConfig.ssr) !== null && _userConfig_userConfig_ssr !== void 0 ? _userConfig_userConfig_ssr : Boolean(modernjsConfig === null || modernjsConfig === void 0 ? void 0 : (_modernjsConfig_server = modernjsConfig.server) === null || _modernjsConfig_server === void 0 ? void 0 : _modernjsConfig_server.ssr));
296
- api.modifyBundlerChain((chain) => {
297
- const target = chain.get("target");
298
- if ((0, import_utils.skipByTarget)(target)) {
299
- return;
300
- }
301
- const isWeb = (0, import_utils.isWebTarget)(target);
302
- addMyTypes2Ignored(chain, !isWeb ? ssrConfig : csrConfig);
303
- const targetMFConfig = !isWeb ? ssrConfig : csrConfig;
304
- patchMFConfig(targetMFConfig, !isWeb, userConfig.remoteIpStrategy || "ipv4");
305
- patchBundlerConfig({
306
- // @ts-expect-error chain type is not correct
307
- chain,
308
- isServer: !isWeb,
309
- modernjsConfig,
310
- mfConfig,
311
- enableSSR
312
- });
313
- userConfig.distOutputDir = chain.output.get("path") || import_path.default.resolve(process.cwd(), "dist");
314
- });
315
- api.config(() => {
316
- var _modernjsConfig_tools, _userConfig_csrConfig, _modernjsConfig_source, _modernjsConfig_source1, _modernjsConfig_dev;
317
- const bundlerType = api.getAppContext().bundlerType === "rspack" ? "rspack" : "webpack";
318
- const ipv4 = (0, import_utils.getIPV4)();
319
- if (userConfig.remoteIpStrategy === void 0) {
320
- if (!enableSSR) {
321
- userConfig.remoteIpStrategy = "inherit";
322
- } else {
323
- userConfig.remoteIpStrategy = "ipv4";
324
- }
325
- }
326
- const devServerConfig = (_modernjsConfig_tools = modernjsConfig.tools) === null || _modernjsConfig_tools === void 0 ? void 0 : _modernjsConfig_tools.devServer;
327
- const corsWarnMsgs = [
328
- "View https://module-federation.io/guide/troubleshooting/other.html#cors-warn for more details."
329
- ];
330
- if (typeof devServerConfig !== "object" || !("headers" in devServerConfig)) {
331
- corsWarnMsgs.unshift('Detect devServer.headers is empty, mf modern plugin will add default cors header: devServer.headers["Access-Control-Allow-Headers"] = "*". It is recommended to specify an allowlist of trusted origins instead.');
332
- }
333
- const exposes = (_userConfig_csrConfig = userConfig.csrConfig) === null || _userConfig_csrConfig === void 0 ? void 0 : _userConfig_csrConfig.exposes;
334
- const hasExposes = exposes && Array.isArray(exposes) ? exposes.length : Object.keys(exposes !== null && exposes !== void 0 ? exposes : {}).length;
335
- if (corsWarnMsgs.length > 1 && hasExposes) {
336
- import_logger.default.warn(corsWarnMsgs.join("\n"));
337
- }
338
- const corsHeaders = hasExposes ? {
339
- "Access-Control-Allow-Origin": "*",
340
- "Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, PATCH, OPTIONS",
341
- "Access-Control-Allow-Headers": "*"
342
- } : void 0;
343
- var _modernjsConfig_source_enableAsyncEntry;
344
- return {
345
- tools: {
346
- devServer: {
347
- headers: corsHeaders
348
- }
349
- },
350
- source: {
351
- alias: {
352
- // TODO: deprecated
353
- "@modern-js/runtime/mf": require.resolve("@module-federation/modern-js/runtime")
354
- },
355
- define: {
356
- FEDERATION_IPV4: JSON.stringify(ipv4),
357
- REMOTE_IP_STRATEGY: JSON.stringify(userConfig.remoteIpStrategy)
358
- },
359
- enableAsyncEntry: bundlerType === "rspack" ? (_modernjsConfig_source_enableAsyncEntry = (_modernjsConfig_source = modernjsConfig.source) === null || _modernjsConfig_source === void 0 ? void 0 : _modernjsConfig_source.enableAsyncEntry) !== null && _modernjsConfig_source_enableAsyncEntry !== void 0 ? _modernjsConfig_source_enableAsyncEntry : true : (_modernjsConfig_source1 = modernjsConfig.source) === null || _modernjsConfig_source1 === void 0 ? void 0 : _modernjsConfig_source1.enableAsyncEntry
360
- },
361
- dev: {
362
- assetPrefix: (modernjsConfig === null || modernjsConfig === void 0 ? void 0 : (_modernjsConfig_dev = modernjsConfig.dev) === null || _modernjsConfig_dev === void 0 ? void 0 : _modernjsConfig_dev.assetPrefix) ? modernjsConfig.dev.assetPrefix : true
363
- }
364
- };
365
- });
366
- }
367
- });
368
- var configPlugin_default = moduleFederationConfigPlugin;
369
- // Annotate the CommonJS export names for ESM import in node:
370
- 0 && (module.exports = {
371
- addMyTypes2Ignored,
372
- getMFConfig,
373
- isWebTarget,
374
- moduleFederationConfigPlugin,
375
- patchBundlerConfig,
376
- patchMFConfig,
377
- setEnv,
378
- skipByTarget
379
- });
@@ -1,114 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __copyProps = (to, from, except, desc) => {
9
- if (from && typeof from === "object" || typeof from === "function") {
10
- for (let key of __getOwnPropNames(from))
11
- if (!__hasOwnProp.call(to, key) && key !== except)
12
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
13
- }
14
- return to;
15
- };
16
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
17
- // If the importer is in node compatibility mode or this is not an ESM
18
- // file that has been converted to a CommonJS file using a Babel-
19
- // compatible transform (i.e. "__esModule" has not been set), then set
20
- // "default" to the CommonJS "module.exports" for node compatibility.
21
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
22
- mod
23
- ));
24
- var import_vitest = require("vitest");
25
- var import_configPlugin = require("./configPlugin");
26
- var import_utils = require("./utils");
27
- const mfConfig = {
28
- name: "host",
29
- filename: "remoteEntry.js",
30
- remotes: {
31
- remote: "http://localhost:3000/remoteEntry.js"
32
- },
33
- shared: {
34
- react: {
35
- singleton: true,
36
- eager: true
37
- },
38
- "react-dom": {
39
- singleton: true,
40
- eager: true
41
- }
42
- }
43
- };
44
- (0, import_vitest.describe)("patchMFConfig", async () => {
45
- (0, import_vitest.it)("patchMFConfig: server", async () => {
46
- const patchedConfig = JSON.parse(JSON.stringify(mfConfig));
47
- (0, import_configPlugin.patchMFConfig)(patchedConfig, true);
48
- const ipv4 = (0, import_utils.getIPV4)();
49
- (0, import_vitest.expect)(patchedConfig).toStrictEqual({
50
- dev: false,
51
- dts: false,
52
- filename: "remoteEntry.js",
53
- library: {
54
- name: "host",
55
- type: "commonjs-module"
56
- },
57
- name: "host",
58
- remotes: {
59
- remote: `http://${ipv4}:3000/remoteEntry.js`
60
- },
61
- remoteType: "script",
62
- runtimePlugins: [
63
- require.resolve("@module-federation/modern-js/shared-strategy"),
64
- require.resolve("@module-federation/modern-js/auto-fetch-data"),
65
- require.resolve("@module-federation/node/runtimePlugin"),
66
- require.resolve("@module-federation/modern-js/inject-node-fetch")
67
- ],
68
- shared: {
69
- react: {
70
- eager: true,
71
- singleton: true
72
- },
73
- "react-dom": {
74
- eager: true,
75
- singleton: true
76
- }
77
- }
78
- });
79
- });
80
- (0, import_vitest.it)("patchMFConfig: client", async () => {
81
- const patchedConfig = JSON.parse(JSON.stringify(mfConfig));
82
- (0, import_configPlugin.patchMFConfig)(patchedConfig, false);
83
- const ipv4 = (0, import_utils.getIPV4)();
84
- (0, import_vitest.expect)(patchedConfig).toStrictEqual({
85
- filename: "remoteEntry.js",
86
- name: "host",
87
- remotes: {
88
- remote: `http://${ipv4}:3000/remoteEntry.js`
89
- },
90
- remoteType: "script",
91
- runtimePlugins: [
92
- require.resolve("@module-federation/modern-js/shared-strategy"),
93
- require.resolve("@module-federation/modern-js/auto-fetch-data")
94
- ],
95
- shared: {
96
- react: {
97
- eager: true,
98
- singleton: true
99
- },
100
- "react-dom": {
101
- eager: true,
102
- singleton: true
103
- }
104
- },
105
- dts: {
106
- consumeTypes: {
107
- runtimePkgs: [
108
- "@module-federation/modern-js/runtime"
109
- ]
110
- }
111
- }
112
- });
113
- });
114
- });