@module-federation/modern-js-v3 2.1.0 → 2.2.1

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.
@@ -58,6 +58,8 @@ var __webpack_exports__ = {};
58
58
  setEnv: ()=>setEnv,
59
59
  patchBundlerConfig: ()=>patchBundlerConfig
60
60
  });
61
+ const external_fs_namespaceObject = require("fs");
62
+ var external_fs_default = /*#__PURE__*/ __webpack_require__.n(external_fs_namespaceObject);
61
63
  const external_path_namespaceObject = require("path");
62
64
  var external_path_default = /*#__PURE__*/ __webpack_require__.n(external_path_namespaceObject);
63
65
  const external_utils_js_namespaceObject = require("./utils.js");
@@ -67,6 +69,20 @@ var __webpack_exports__ = {};
67
69
  const external_logger_js_namespaceObject = require("../logger.js");
68
70
  var external_logger_js_default = /*#__PURE__*/ __webpack_require__.n(external_logger_js_namespaceObject);
69
71
  const defaultPath = external_path_default().resolve(process.cwd(), 'module-federation.config.ts');
72
+ const resolvePackageFile = (packageName, esmRelativePath, cjsRelativePath)=>{
73
+ const packageEntry = require.resolve(packageName);
74
+ let packageRoot = external_path_default().dirname(packageEntry);
75
+ while(!external_fs_default().existsSync(external_path_default().join(packageRoot, 'package.json'))){
76
+ const parentDir = external_path_default().dirname(packageRoot);
77
+ if (parentDir === packageRoot) throw new Error(`Unable to resolve package root for ${packageName} from ${packageEntry}`);
78
+ packageRoot = parentDir;
79
+ }
80
+ return require.resolve(external_path_default().join(packageRoot, 'true' === process.env.IS_ESM_BUILD ? esmRelativePath : cjsRelativePath));
81
+ };
82
+ const resolveSharedStrategyPlugin = ()=>resolvePackageFile('@module-federation/modern-js-v3', 'dist/esm/cli/mfRuntimePlugins/shared-strategy.mjs', 'dist/cjs/cli/mfRuntimePlugins/shared-strategy.js');
83
+ const resolveInjectNodeFetchPlugin = ()=>resolvePackageFile('@module-federation/modern-js-v3', 'dist/esm/cli/mfRuntimePlugins/inject-node-fetch.mjs', 'dist/cjs/cli/mfRuntimePlugins/inject-node-fetch.js');
84
+ const resolveNodeRuntimePlugin = ()=>resolvePackageFile('@module-federation/node', 'dist/src/runtimePlugin.mjs', 'dist/src/runtimePlugin.js');
85
+ const resolveNodeRecordRemoteHashPlugin = ()=>resolvePackageFile('@module-federation/node', 'dist/src/recordDynamicRemoteEntryHashPlugin.mjs', 'dist/src/recordDynamicRemoteEntryHashPlugin.js');
70
86
  function setEnv(enableSSR) {
71
87
  if (enableSSR) process.env['MF_SSR_PRJ'] = 'true';
72
88
  }
@@ -76,8 +92,7 @@ var __webpack_exports__ = {};
76
92
  const mfConfigPath = configPath ? configPath : defaultPath;
77
93
  const { createJiti } = __webpack_require__("jiti");
78
94
  const jit = createJiti(__filename, {
79
- interopDefault: true,
80
- esmResolve: true
95
+ interopDefault: true
81
96
  });
82
97
  const configModule = await jit(mfConfigPath);
83
98
  const resolvedConfig = configModule && 'object' == typeof configModule && 'default' in configModule ? configModule.default : configModule;
@@ -125,11 +140,11 @@ var __webpack_exports__ = {};
125
140
  ...mfConfig.runtimePlugins || []
126
141
  ];
127
142
  patchDTSConfig(mfConfig, isServer);
128
- injectRuntimePlugins(require.resolve('@module-federation/modern-js-v3/shared-strategy'), runtimePlugins);
143
+ injectRuntimePlugins(resolveSharedStrategyPlugin(), runtimePlugins);
129
144
  if (isServer) {
130
- injectRuntimePlugins(require.resolve('@module-federation/node/runtimePlugin'), runtimePlugins);
131
- if ((0, external_utils_js_namespaceObject.isDev)()) injectRuntimePlugins(require.resolve('@module-federation/node/record-dynamic-remote-entry-hash-plugin'), runtimePlugins);
132
- injectRuntimePlugins(require.resolve('@module-federation/modern-js-v3/inject-node-fetch'), runtimePlugins);
145
+ injectRuntimePlugins(resolveNodeRuntimePlugin(), runtimePlugins);
146
+ if ((0, external_utils_js_namespaceObject.isDev)()) injectRuntimePlugins(resolveNodeRecordRemoteHashPlugin(), runtimePlugins);
147
+ injectRuntimePlugins(resolveInjectNodeFetchPlugin(), runtimePlugins);
133
148
  if (mfConfig.library) {
134
149
  if (!mfConfig.library.type) mfConfig.library.type = 'commonjs-module';
135
150
  if (!mfConfig.library.name) mfConfig.library.name = mfConfig.name;
@@ -237,12 +252,18 @@ var __webpack_exports__ = {};
237
252
  userConfig.csrConfig = csrConfig;
238
253
  const enableSSR = Boolean(null != (_ref = null == (_userConfig_userConfig = userConfig.userConfig) ? void 0 : _userConfig_userConfig.ssr) ? _ref : Boolean(null == modernjsConfig ? void 0 : null == (_modernjsConfig_server = modernjsConfig.server) ? void 0 : _modernjsConfig_server.ssr));
239
254
  api.modifyBundlerChain((chain)=>{
255
+ var _modernjsConfig_source, _targetMFConfig_experiments;
240
256
  const target = chain.get('target');
241
257
  if ((0, external_utils_js_namespaceObject.skipByTarget)(target)) return;
242
258
  const isWeb = (0, external_utils_js_namespaceObject.isWebTarget)(target);
243
259
  addMyTypes2Ignored(chain, isWeb ? csrConfig : ssrConfig);
244
260
  const targetMFConfig = isWeb ? csrConfig : ssrConfig;
245
261
  patchMFConfig(targetMFConfig, !isWeb);
262
+ if ((null == (_modernjsConfig_source = modernjsConfig.source) ? void 0 : _modernjsConfig_source.enableAsyncEntry) !== true && (null == (_targetMFConfig_experiments = targetMFConfig.experiments) ? void 0 : _targetMFConfig_experiments.asyncStartup) !== false) {
263
+ var _targetMFConfig;
264
+ (_targetMFConfig = targetMFConfig).experiments || (_targetMFConfig.experiments = {});
265
+ targetMFConfig.experiments.asyncStartup = true;
266
+ }
246
267
  patchBundlerConfig({
247
268
  chain,
248
269
  isServer: !isWeb,
@@ -5,6 +5,7 @@ import { _ as _object_spread_props__ } from "@swc/helpers/_/_object_spread_props
5
5
  import { _ as _to_consumable_array__ } from "@swc/helpers/_/_to_consumable_array";
6
6
  import { _ as _type_of__ } from "@swc/helpers/_/_type_of";
7
7
  import { _ as _ts_generator__ } from "@swc/helpers/_/_ts_generator";
8
+ import fs from "fs";
8
9
  import path from "path";
9
10
  import { isDev, isWebTarget, skipByTarget } from "./utils.mjs";
10
11
  import { encodeName } from "@module-federation/sdk";
@@ -27,6 +28,28 @@ function __webpack_require__(moduleId) {
27
28
  return module.exports;
28
29
  }
29
30
  var defaultPath = path.resolve(process.cwd(), 'module-federation.config.ts');
31
+ var resolvePackageFile = function(packageName, esmRelativePath, cjsRelativePath) {
32
+ var packageEntry = require.resolve(packageName);
33
+ var packageRoot = path.dirname(packageEntry);
34
+ while(!fs.existsSync(path.join(packageRoot, 'package.json'))){
35
+ var parentDir = path.dirname(packageRoot);
36
+ if (parentDir === packageRoot) throw new Error("Unable to resolve package root for ".concat(packageName, " from ").concat(packageEntry));
37
+ packageRoot = parentDir;
38
+ }
39
+ return require.resolve(path.join(packageRoot, 'true' === process.env.IS_ESM_BUILD ? esmRelativePath : cjsRelativePath));
40
+ };
41
+ var resolveSharedStrategyPlugin = function() {
42
+ return resolvePackageFile('@module-federation/modern-js-v3', 'dist/esm/cli/mfRuntimePlugins/shared-strategy.mjs', 'dist/cjs/cli/mfRuntimePlugins/shared-strategy.js');
43
+ };
44
+ var resolveInjectNodeFetchPlugin = function() {
45
+ return resolvePackageFile('@module-federation/modern-js-v3', 'dist/esm/cli/mfRuntimePlugins/inject-node-fetch.mjs', 'dist/cjs/cli/mfRuntimePlugins/inject-node-fetch.js');
46
+ };
47
+ var resolveNodeRuntimePlugin = function() {
48
+ return resolvePackageFile('@module-federation/node', 'dist/src/runtimePlugin.mjs', 'dist/src/runtimePlugin.js');
49
+ };
50
+ var resolveNodeRecordRemoteHashPlugin = function() {
51
+ return resolvePackageFile('@module-federation/node', 'dist/src/recordDynamicRemoteEntryHashPlugin.mjs', 'dist/src/recordDynamicRemoteEntryHashPlugin.js');
52
+ };
30
53
  function setEnv(enableSSR) {
31
54
  if (enableSSR) process.env['MF_SSR_PRJ'] = 'true';
32
55
  }
@@ -44,8 +67,7 @@ var getMFConfig = function(userConfig) {
44
67
  mfConfigPath = configPath ? configPath : defaultPath;
45
68
  createJiti = __webpack_require__("jiti").createJiti;
46
69
  jit = createJiti(__filename, {
47
- interopDefault: true,
48
- esmResolve: true
70
+ interopDefault: true
49
71
  });
50
72
  return [
51
73
  4,
@@ -102,11 +124,11 @@ var patchMFConfig = function(mfConfig, isServer) {
102
124
  if (!mfConfig.name) throw new Error("".concat(PLUGIN_IDENTIFIER, " mfConfig.name can not be empty!"));
103
125
  var runtimePlugins = _to_consumable_array__(mfConfig.runtimePlugins || []);
104
126
  patchDTSConfig(mfConfig, isServer);
105
- injectRuntimePlugins(require.resolve('@module-federation/modern-js-v3/shared-strategy'), runtimePlugins);
127
+ injectRuntimePlugins(resolveSharedStrategyPlugin(), runtimePlugins);
106
128
  if (isServer) {
107
- injectRuntimePlugins(require.resolve('@module-federation/node/runtimePlugin'), runtimePlugins);
108
- if (isDev()) injectRuntimePlugins(require.resolve('@module-federation/node/record-dynamic-remote-entry-hash-plugin'), runtimePlugins);
109
- injectRuntimePlugins(require.resolve('@module-federation/modern-js-v3/inject-node-fetch'), runtimePlugins);
129
+ injectRuntimePlugins(resolveNodeRuntimePlugin(), runtimePlugins);
130
+ if (isDev()) injectRuntimePlugins(resolveNodeRecordRemoteHashPlugin(), runtimePlugins);
131
+ injectRuntimePlugins(resolveInjectNodeFetchPlugin(), runtimePlugins);
110
132
  if (mfConfig.library) {
111
133
  if (!mfConfig.library.type) mfConfig.library.type = 'commonjs-module';
112
134
  if (!mfConfig.library.name) mfConfig.library.name = mfConfig.name;
@@ -221,12 +243,18 @@ var moduleFederationConfigPlugin = function(userConfig) {
221
243
  userConfig.csrConfig = csrConfig;
222
244
  enableSSR = Boolean(null != (_ref = null == (_userConfig_userConfig = userConfig.userConfig) ? void 0 : _userConfig_userConfig.ssr) ? _ref : Boolean(null == modernjsConfig ? void 0 : null == (_modernjsConfig_server = modernjsConfig.server) ? void 0 : _modernjsConfig_server.ssr));
223
245
  api.modifyBundlerChain(function(chain) {
246
+ var _modernjsConfig_source, _targetMFConfig_experiments;
224
247
  var target = chain.get('target');
225
248
  if (skipByTarget(target)) return;
226
249
  var isWeb = isWebTarget(target);
227
250
  addMyTypes2Ignored(chain, isWeb ? csrConfig : ssrConfig);
228
251
  var targetMFConfig = isWeb ? csrConfig : ssrConfig;
229
252
  patchMFConfig(targetMFConfig, !isWeb);
253
+ if ((null == (_modernjsConfig_source = modernjsConfig.source) ? void 0 : _modernjsConfig_source.enableAsyncEntry) !== true && (null == (_targetMFConfig_experiments = targetMFConfig.experiments) ? void 0 : _targetMFConfig_experiments.asyncStartup) !== false) {
254
+ var _targetMFConfig;
255
+ (_targetMFConfig = targetMFConfig).experiments || (_targetMFConfig.experiments = {});
256
+ targetMFConfig.experiments.asyncStartup = true;
257
+ }
230
258
  patchBundlerConfig({
231
259
  chain: chain,
232
260
  isServer: !isWeb,
@@ -1,4 +1,5 @@
1
1
  import * as __rspack_external_jiti from "jiti";
2
+ import fs from "fs";
2
3
  import path from "path";
3
4
  import { isDev, isWebTarget, skipByTarget } from "./utils.mjs";
4
5
  import { encodeName } from "@module-federation/sdk";
@@ -21,6 +22,20 @@ function __webpack_require__(moduleId) {
21
22
  return module.exports;
22
23
  }
23
24
  const defaultPath = path.resolve(process.cwd(), 'module-federation.config.ts');
25
+ const resolvePackageFile = (packageName, esmRelativePath, cjsRelativePath)=>{
26
+ const packageEntry = require.resolve(packageName);
27
+ let packageRoot = path.dirname(packageEntry);
28
+ while(!fs.existsSync(path.join(packageRoot, 'package.json'))){
29
+ const parentDir = path.dirname(packageRoot);
30
+ if (parentDir === packageRoot) throw new Error(`Unable to resolve package root for ${packageName} from ${packageEntry}`);
31
+ packageRoot = parentDir;
32
+ }
33
+ return require.resolve(path.join(packageRoot, 'true' === process.env.IS_ESM_BUILD ? esmRelativePath : cjsRelativePath));
34
+ };
35
+ const resolveSharedStrategyPlugin = ()=>resolvePackageFile('@module-federation/modern-js-v3', 'dist/esm/cli/mfRuntimePlugins/shared-strategy.mjs', 'dist/cjs/cli/mfRuntimePlugins/shared-strategy.js');
36
+ const resolveInjectNodeFetchPlugin = ()=>resolvePackageFile('@module-federation/modern-js-v3', 'dist/esm/cli/mfRuntimePlugins/inject-node-fetch.mjs', 'dist/cjs/cli/mfRuntimePlugins/inject-node-fetch.js');
37
+ const resolveNodeRuntimePlugin = ()=>resolvePackageFile('@module-federation/node', 'dist/src/runtimePlugin.mjs', 'dist/src/runtimePlugin.js');
38
+ const resolveNodeRecordRemoteHashPlugin = ()=>resolvePackageFile('@module-federation/node', 'dist/src/recordDynamicRemoteEntryHashPlugin.mjs', 'dist/src/recordDynamicRemoteEntryHashPlugin.js');
24
39
  function setEnv(enableSSR) {
25
40
  if (enableSSR) process.env['MF_SSR_PRJ'] = 'true';
26
41
  }
@@ -30,8 +45,7 @@ const getMFConfig = async (userConfig)=>{
30
45
  const mfConfigPath = configPath ? configPath : defaultPath;
31
46
  const { createJiti } = __webpack_require__("jiti");
32
47
  const jit = createJiti(__filename, {
33
- interopDefault: true,
34
- esmResolve: true
48
+ interopDefault: true
35
49
  });
36
50
  const configModule = await jit(mfConfigPath);
37
51
  const resolvedConfig = configModule && 'object' == typeof configModule && 'default' in configModule ? configModule.default : configModule;
@@ -79,11 +93,11 @@ const patchMFConfig = (mfConfig, isServer)=>{
79
93
  ...mfConfig.runtimePlugins || []
80
94
  ];
81
95
  patchDTSConfig(mfConfig, isServer);
82
- injectRuntimePlugins(require.resolve('@module-federation/modern-js-v3/shared-strategy'), runtimePlugins);
96
+ injectRuntimePlugins(resolveSharedStrategyPlugin(), runtimePlugins);
83
97
  if (isServer) {
84
- injectRuntimePlugins(require.resolve('@module-federation/node/runtimePlugin'), runtimePlugins);
85
- if (isDev()) injectRuntimePlugins(require.resolve('@module-federation/node/record-dynamic-remote-entry-hash-plugin'), runtimePlugins);
86
- injectRuntimePlugins(require.resolve('@module-federation/modern-js-v3/inject-node-fetch'), runtimePlugins);
98
+ injectRuntimePlugins(resolveNodeRuntimePlugin(), runtimePlugins);
99
+ if (isDev()) injectRuntimePlugins(resolveNodeRecordRemoteHashPlugin(), runtimePlugins);
100
+ injectRuntimePlugins(resolveInjectNodeFetchPlugin(), runtimePlugins);
87
101
  if (mfConfig.library) {
88
102
  if (!mfConfig.library.type) mfConfig.library.type = 'commonjs-module';
89
103
  if (!mfConfig.library.name) mfConfig.library.name = mfConfig.name;
@@ -191,12 +205,18 @@ const moduleFederationConfigPlugin = (userConfig)=>({
191
205
  userConfig.csrConfig = csrConfig;
192
206
  const enableSSR = Boolean(null != (_ref = null == (_userConfig_userConfig = userConfig.userConfig) ? void 0 : _userConfig_userConfig.ssr) ? _ref : Boolean(null == modernjsConfig ? void 0 : null == (_modernjsConfig_server = modernjsConfig.server) ? void 0 : _modernjsConfig_server.ssr));
193
207
  api.modifyBundlerChain((chain)=>{
208
+ var _modernjsConfig_source, _targetMFConfig_experiments;
194
209
  const target = chain.get('target');
195
210
  if (skipByTarget(target)) return;
196
211
  const isWeb = isWebTarget(target);
197
212
  addMyTypes2Ignored(chain, isWeb ? csrConfig : ssrConfig);
198
213
  const targetMFConfig = isWeb ? csrConfig : ssrConfig;
199
214
  patchMFConfig(targetMFConfig, !isWeb);
215
+ if ((null == (_modernjsConfig_source = modernjsConfig.source) ? void 0 : _modernjsConfig_source.enableAsyncEntry) !== true && (null == (_targetMFConfig_experiments = targetMFConfig.experiments) ? void 0 : _targetMFConfig_experiments.asyncStartup) !== false) {
216
+ var _targetMFConfig;
217
+ (_targetMFConfig = targetMFConfig).experiments || (_targetMFConfig.experiments = {});
218
+ targetMFConfig.experiments.asyncStartup = true;
219
+ }
200
220
  patchBundlerConfig({
201
221
  chain,
202
222
  isServer: !isWeb,
@@ -4,6 +4,13 @@ import { PluginOptions } from '../types';
4
4
  import type { InternalModernPluginOptions } from '../types';
5
5
  import type { AppTools, Rspack, AppUserConfig, CliPlugin } from '@modern-js/app-tools';
6
6
  import type { BundlerChainConfig } from '../interfaces/bundler';
7
+ declare global {
8
+ namespace NodeJS {
9
+ interface ProcessEnv {
10
+ IS_ESM_BUILD?: string;
11
+ }
12
+ }
13
+ }
7
14
  export type ConfigType = Rspack.Configuration;
8
15
  export declare function setEnv(enableSSR: boolean): void;
9
16
  export declare const getMFConfig: (userConfig: PluginOptions) => Promise<moduleFederationPlugin.ModuleFederationPluginOptions>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@module-federation/modern-js-v3",
3
- "version": "2.1.0",
3
+ "version": "2.2.1",
4
4
  "files": [
5
5
  "dist/",
6
6
  "types.d.ts",
@@ -131,13 +131,13 @@
131
131
  "node-fetch": "~3.3.0",
132
132
  "jiti": "2.4.2",
133
133
  "react-error-boundary": "4.1.2",
134
- "@module-federation/rsbuild-plugin": "2.1.0",
135
- "@module-federation/enhanced": "2.1.0",
136
- "@module-federation/bridge-react": "2.1.0",
137
- "@module-federation/node": "2.7.33",
138
- "@module-federation/sdk": "2.1.0",
139
- "@module-federation/cli": "2.1.0",
140
- "@module-federation/runtime": "2.1.0"
134
+ "@module-federation/rsbuild-plugin": "2.2.1",
135
+ "@module-federation/bridge-react": "2.2.1",
136
+ "@module-federation/enhanced": "2.2.1",
137
+ "@module-federation/node": "2.7.35",
138
+ "@module-federation/sdk": "2.2.1",
139
+ "@module-federation/runtime": "2.2.1",
140
+ "@module-federation/cli": "2.2.1"
141
141
  },
142
142
  "devDependencies": {
143
143
  "@rsbuild/plugin-react": "1.4.5",
@@ -150,7 +150,10 @@
150
150
  "@modern-js/tsconfig": "3.0.1",
151
151
  "@types/react": "^18.3.11",
152
152
  "@types/react-dom": "^18.3.0",
153
- "@module-federation/manifest": "2.1.0"
153
+ "react": "~18.3.1",
154
+ "react-dom": "~18.3.1",
155
+ "vitest": "1.6.0",
156
+ "@module-federation/manifest": "2.2.1"
154
157
  },
155
158
  "peerDependencies": {
156
159
  "react": ">=17",
@@ -175,6 +178,9 @@
175
178
  }
176
179
  },
177
180
  "scripts": {
178
- "build": "rslib build"
181
+ "build": "rslib build",
182
+ "lint": "ESLINT_USE_FLAT_CONFIG=false pnpm exec eslint --ignore-pattern node_modules \"**/*.ts\"",
183
+ "test": "pnpm exec vitest run --passWithNoTests --config vite.config.mts",
184
+ "pre-release": "pnpm run test && pnpm run build"
179
185
  }
180
186
  }
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.