@module-federation/modern-js-v3 2.7.0 → 2.8.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.
@@ -59,6 +59,7 @@ var __webpack_exports__ = {};
59
59
  moduleFederationConfigPlugin: ()=>moduleFederationConfigPlugin,
60
60
  patchBundlerConfig: ()=>patchBundlerConfig,
61
61
  patchMFConfig: ()=>patchMFConfig,
62
+ setDefaultOptimizationTarget: ()=>setDefaultOptimizationTarget,
62
63
  setEnv: ()=>setEnv,
63
64
  skipByTarget: ()=>external_utils_js_namespaceObject.skipByTarget
64
65
  });
@@ -167,6 +168,13 @@ var __webpack_exports__ = {};
167
168
  mfConfig.dev = false;
168
169
  return mfConfig;
169
170
  };
171
+ const setDefaultOptimizationTarget = (mfConfig, enableSSR, isServer, autoOptimization = true)=>{
172
+ var _mfConfig, _mfConfig_experiments, _mfConfig_experiments_optimization;
173
+ if (!autoOptimization) return;
174
+ (_mfConfig = mfConfig).experiments || (_mfConfig.experiments = {});
175
+ (_mfConfig_experiments = mfConfig.experiments).optimization || (_mfConfig_experiments.optimization = {});
176
+ null != (_mfConfig_experiments_optimization = mfConfig.experiments.optimization).target || (_mfConfig_experiments_optimization.target = enableSSR && isServer ? 'node' : 'web');
177
+ };
170
178
  function patchIgnoreWarning(chain) {
171
179
  const ignoreWarnings = chain.get('ignoreWarnings') || [];
172
180
  const ignoredMsgs = [
@@ -235,7 +243,10 @@ var __webpack_exports__ = {};
235
243
  }
236
244
  }
237
245
  if ((0, external_utils_js_namespaceObject.isDev)() && enableSSR && !isServer) chain.resolve.fallback.set('crypto', false).set('stream', false).set('vm', false);
238
- if ((null == (_modernjsConfig_deploy = modernjsConfig.deploy) ? void 0 : _modernjsConfig_deploy.microFrontend) && Object.keys(mfConfig.exposes || {}).length) chain.optimization.usedExports(false);
246
+ if ((null == (_modernjsConfig_deploy = modernjsConfig.deploy) ? void 0 : _modernjsConfig_deploy.microFrontend) && Object.keys(mfConfig.exposes || {}).length) {
247
+ external_logger_js_default().info('optimization.usedExports is set to "global" to avoid tree shaking issues in micro frontend mode.');
248
+ chain.optimization.usedExports('global');
249
+ }
239
250
  }
240
251
  const moduleFederationConfigPlugin = (userConfig)=>({
241
252
  name: '@modern-js/plugin-module-federation-config',
@@ -262,6 +273,7 @@ var __webpack_exports__ = {};
262
273
  const isWeb = (0, external_utils_js_namespaceObject.isWebTarget)(target);
263
274
  addMyTypes2Ignored(chain, isWeb ? csrConfig : ssrConfig);
264
275
  const targetMFConfig = isWeb ? csrConfig : ssrConfig;
276
+ setDefaultOptimizationTarget(targetMFConfig, enableSSR, !isWeb, userConfig.originPluginOptions.autoOptimization);
265
277
  patchMFConfig(targetMFConfig, !isWeb);
266
278
  if ((null == (_modernjsConfig_source = modernjsConfig.source) ? void 0 : _modernjsConfig_source.enableAsyncEntry) !== true && (null == (_targetMFConfig_experiments = targetMFConfig.experiments) ? void 0 : _targetMFConfig_experiments.asyncStartup) !== false) {
267
279
  var _targetMFConfig;
@@ -333,6 +345,7 @@ exports.isWebTarget = __webpack_exports__.isWebTarget;
333
345
  exports.moduleFederationConfigPlugin = __webpack_exports__.moduleFederationConfigPlugin;
334
346
  exports.patchBundlerConfig = __webpack_exports__.patchBundlerConfig;
335
347
  exports.patchMFConfig = __webpack_exports__.patchMFConfig;
348
+ exports.setDefaultOptimizationTarget = __webpack_exports__.setDefaultOptimizationTarget;
336
349
  exports.setEnv = __webpack_exports__.setEnv;
337
350
  exports.skipByTarget = __webpack_exports__.skipByTarget;
338
351
  for(var __rspack_i in __webpack_exports__)if (-1 === [
@@ -343,6 +356,7 @@ for(var __rspack_i in __webpack_exports__)if (-1 === [
343
356
  "moduleFederationConfigPlugin",
344
357
  "patchBundlerConfig",
345
358
  "patchMFConfig",
359
+ "setDefaultOptimizationTarget",
346
360
  "setEnv",
347
361
  "skipByTarget"
348
362
  ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
@@ -1,14 +1,5 @@
1
1
  "use strict";
2
2
  var __webpack_require__ = {};
3
- (()=>{
4
- __webpack_require__.n = (module)=>{
5
- var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
6
- __webpack_require__.d(getter, {
7
- a: getter
8
- });
9
- return getter;
10
- };
11
- })();
12
3
  (()=>{
13
4
  __webpack_require__.d = (exports1, getters, values)=>{
14
5
  var define = (defs, kind)=>{
@@ -36,19 +27,17 @@ var __webpack_require__ = {};
36
27
  })();
37
28
  var __webpack_exports__ = {};
38
29
  __webpack_require__.r(__webpack_exports__);
39
- __webpack_require__.d(__webpack_exports__, {
40
- default: ()=>inject_node_fetch
41
- });
42
- const external_node_fetch_namespaceObject = require("node-fetch");
43
- var external_node_fetch_default = /*#__PURE__*/ __webpack_require__.n(external_node_fetch_namespaceObject);
44
30
  const injectNodeFetchPlugin = ()=>({
45
31
  name: 'inject-node-fetch-plugin',
46
32
  beforeInit (args) {
47
- if (!globalThis.fetch) globalThis.fetch = external_node_fetch_default();
33
+ if (!globalThis.fetch) throw new Error('@module-federation/modern-js-v3 requires Node.js 18 or later.');
48
34
  return args;
49
35
  }
50
36
  });
51
- const inject_node_fetch = injectNodeFetchPlugin;
37
+ const __rspack_default_export = injectNodeFetchPlugin;
38
+ __webpack_require__.d(__webpack_exports__, {}, {
39
+ default: __rspack_default_export
40
+ });
52
41
  exports["default"] = __webpack_exports__["default"];
53
42
  for(var __rspack_i in __webpack_exports__)if (-1 === [
54
43
  "default"
@@ -32,7 +32,7 @@ __webpack_require__.d(__webpack_exports__, {
32
32
  fileCache: ()=>fileCache
33
33
  });
34
34
  const promises_namespaceObject = require("fs/promises");
35
- const external_lru_cache_namespaceObject = require("lru-cache");
35
+ const size_limited_cache_namespaceObject = require("@module-federation/bridge-react/size-limited-cache");
36
36
  const pathExists = async (filepath)=>{
37
37
  try {
38
38
  await (0, promises_namespaceObject.access)(filepath);
@@ -68,9 +68,9 @@ class FileCache {
68
68
  return null;
69
69
  }
70
70
  }
71
- constructor(){
72
- this.cache = new external_lru_cache_namespaceObject.LRUCache({
73
- maxSize: 209715200
71
+ constructor(maxSize = 209715200){
72
+ this.cache = new size_limited_cache_namespaceObject.SizeLimitedCache({
73
+ maxSize
74
74
  });
75
75
  }
76
76
  }
@@ -138,6 +138,14 @@ var configPlugin_patchMFConfig = function(mfConfig, isServer) {
138
138
  mfConfig.dev = false;
139
139
  return mfConfig;
140
140
  };
141
+ var configPlugin_setDefaultOptimizationTarget = function(mfConfig, enableSSR, isServer) {
142
+ var autoOptimization = arguments.length > 3 && void 0 !== arguments[3] ? arguments[3] : true;
143
+ var _mfConfig, _mfConfig_experiments, _mfConfig_experiments_optimization;
144
+ if (!autoOptimization) return;
145
+ (_mfConfig = mfConfig).experiments || (_mfConfig.experiments = {});
146
+ (_mfConfig_experiments = mfConfig.experiments).optimization || (_mfConfig_experiments.optimization = {});
147
+ null != (_mfConfig_experiments_optimization = mfConfig.experiments.optimization).target || (_mfConfig_experiments_optimization.target = enableSSR && isServer ? 'node' : 'web');
148
+ };
141
149
  function patchIgnoreWarning(chain) {
142
150
  var ignoreWarnings = chain.get('ignoreWarnings') || [];
143
151
  var ignoredMsgs = [
@@ -204,7 +212,10 @@ function patchBundlerConfig(options) {
204
212
  }
205
213
  }
206
214
  if (isDev() && enableSSR && !isServer) chain.resolve.fallback.set('crypto', false).set('stream', false).set('vm', false);
207
- if ((null == (_modernjsConfig_deploy = modernjsConfig.deploy) ? void 0 : _modernjsConfig_deploy.microFrontend) && Object.keys(mfConfig.exposes || {}).length) chain.optimization.usedExports(false);
215
+ if ((null == (_modernjsConfig_deploy = modernjsConfig.deploy) ? void 0 : _modernjsConfig_deploy.microFrontend) && Object.keys(mfConfig.exposes || {}).length) {
216
+ logger.info('optimization.usedExports is set to "global" to avoid tree shaking issues in micro frontend mode.');
217
+ chain.optimization.usedExports('global');
218
+ }
208
219
  }
209
220
  var configPlugin_moduleFederationConfigPlugin = function(userConfig) {
210
221
  return {
@@ -240,6 +251,7 @@ var configPlugin_moduleFederationConfigPlugin = function(userConfig) {
240
251
  var isWeb = isWebTarget(target);
241
252
  addMyTypes2Ignored(chain, isWeb ? csrConfig : ssrConfig);
242
253
  var targetMFConfig = isWeb ? csrConfig : ssrConfig;
254
+ configPlugin_setDefaultOptimizationTarget(targetMFConfig, enableSSR, !isWeb, userConfig.originPluginOptions.autoOptimization);
243
255
  configPlugin_patchMFConfig(targetMFConfig, !isWeb);
244
256
  if ((null == (_modernjsConfig_source = modernjsConfig.source) ? void 0 : _modernjsConfig_source.enableAsyncEntry) !== true && (null == (_targetMFConfig_experiments = targetMFConfig.experiments) ? void 0 : _targetMFConfig_experiments.asyncStartup) !== false) {
245
257
  var _targetMFConfig;
@@ -311,4 +323,4 @@ var configPlugin_moduleFederationConfigPlugin = function(userConfig) {
311
323
  };
312
324
  var configPlugin = configPlugin_moduleFederationConfigPlugin;
313
325
  export default configPlugin;
314
- export { addMyTypes2Ignored, configPlugin_getMFConfig as getMFConfig, configPlugin_moduleFederationConfigPlugin as moduleFederationConfigPlugin, configPlugin_patchMFConfig as patchMFConfig, isWebTarget, patchBundlerConfig, setEnv, skipByTarget };
326
+ export { addMyTypes2Ignored, configPlugin_getMFConfig as getMFConfig, configPlugin_moduleFederationConfigPlugin as moduleFederationConfigPlugin, configPlugin_patchMFConfig as patchMFConfig, configPlugin_setDefaultOptimizationTarget as setDefaultOptimizationTarget, isWebTarget, patchBundlerConfig, setEnv, skipByTarget };
@@ -1,9 +1,8 @@
1
- import node_fetch from "node-fetch";
2
1
  var inject_node_fetch_injectNodeFetchPlugin = function() {
3
2
  return {
4
3
  name: 'inject-node-fetch-plugin',
5
4
  beforeInit: function(args) {
6
- if (!globalThis.fetch) globalThis.fetch = node_fetch;
5
+ if (!globalThis.fetch) throw new Error('@module-federation/modern-js-v3 requires Node.js 18 or later.');
7
6
  return args;
8
7
  }
9
8
  };
@@ -2,7 +2,7 @@ import { _ } from "@swc/helpers/_/_async_to_generator";
2
2
  import { _ as _class_call_check__ } from "@swc/helpers/_/_class_call_check";
3
3
  import { _ as _ts_generator__ } from "@swc/helpers/_/_ts_generator";
4
4
  import { access, lstat, readFile } from "fs/promises";
5
- import { LRUCache } from "lru-cache";
5
+ import { SizeLimitedCache } from "@module-federation/bridge-react/size-limited-cache";
6
6
  var fileCache_pathExists = function(filepath) {
7
7
  return _(function() {
8
8
  return _ts_generator__(this, function(_state) {
@@ -41,9 +41,10 @@ var fileCache_pathExists = function(filepath) {
41
41
  var fileCache_FileCache = /*#__PURE__*/ function() {
42
42
  "use strict";
43
43
  function FileCache() {
44
+ var maxSize = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : 209715200;
44
45
  _class_call_check__(this, FileCache);
45
- this.cache = new LRUCache({
46
- maxSize: 209715200
46
+ this.cache = new SizeLimitedCache({
47
+ maxSize: maxSize
47
48
  });
48
49
  }
49
50
  var _proto = FileCache.prototype;
@@ -107,6 +107,13 @@ const patchMFConfig = (mfConfig, isServer)=>{
107
107
  mfConfig.dev = false;
108
108
  return mfConfig;
109
109
  };
110
+ const setDefaultOptimizationTarget = (mfConfig, enableSSR, isServer, autoOptimization = true)=>{
111
+ var _mfConfig, _mfConfig_experiments, _mfConfig_experiments_optimization;
112
+ if (!autoOptimization) return;
113
+ (_mfConfig = mfConfig).experiments || (_mfConfig.experiments = {});
114
+ (_mfConfig_experiments = mfConfig.experiments).optimization || (_mfConfig_experiments.optimization = {});
115
+ null != (_mfConfig_experiments_optimization = mfConfig.experiments.optimization).target || (_mfConfig_experiments_optimization.target = enableSSR && isServer ? 'node' : 'web');
116
+ };
110
117
  function patchIgnoreWarning(chain) {
111
118
  const ignoreWarnings = chain.get('ignoreWarnings') || [];
112
119
  const ignoredMsgs = [
@@ -175,7 +182,10 @@ function patchBundlerConfig(options) {
175
182
  }
176
183
  }
177
184
  if (isDev() && enableSSR && !isServer) chain.resolve.fallback.set('crypto', false).set('stream', false).set('vm', false);
178
- if ((null == (_modernjsConfig_deploy = modernjsConfig.deploy) ? void 0 : _modernjsConfig_deploy.microFrontend) && Object.keys(mfConfig.exposes || {}).length) chain.optimization.usedExports(false);
185
+ if ((null == (_modernjsConfig_deploy = modernjsConfig.deploy) ? void 0 : _modernjsConfig_deploy.microFrontend) && Object.keys(mfConfig.exposes || {}).length) {
186
+ logger.info('optimization.usedExports is set to "global" to avoid tree shaking issues in micro frontend mode.');
187
+ chain.optimization.usedExports('global');
188
+ }
179
189
  }
180
190
  const moduleFederationConfigPlugin = (userConfig)=>({
181
191
  name: '@modern-js/plugin-module-federation-config',
@@ -202,6 +212,7 @@ const moduleFederationConfigPlugin = (userConfig)=>({
202
212
  const isWeb = isWebTarget(target);
203
213
  addMyTypes2Ignored(chain, isWeb ? csrConfig : ssrConfig);
204
214
  const targetMFConfig = isWeb ? csrConfig : ssrConfig;
215
+ setDefaultOptimizationTarget(targetMFConfig, enableSSR, !isWeb, userConfig.originPluginOptions.autoOptimization);
205
216
  patchMFConfig(targetMFConfig, !isWeb);
206
217
  if ((null == (_modernjsConfig_source = modernjsConfig.source) ? void 0 : _modernjsConfig_source.enableAsyncEntry) !== true && (null == (_targetMFConfig_experiments = targetMFConfig.experiments) ? void 0 : _targetMFConfig_experiments.asyncStartup) !== false) {
207
218
  var _targetMFConfig;
@@ -266,4 +277,4 @@ const moduleFederationConfigPlugin = (userConfig)=>({
266
277
  });
267
278
  const configPlugin = moduleFederationConfigPlugin;
268
279
  export default configPlugin;
269
- export { addMyTypes2Ignored, getMFConfig, isWebTarget, moduleFederationConfigPlugin, patchBundlerConfig, patchMFConfig, setEnv, skipByTarget };
280
+ export { addMyTypes2Ignored, getMFConfig, isWebTarget, moduleFederationConfigPlugin, patchBundlerConfig, patchMFConfig, setDefaultOptimizationTarget, setEnv, skipByTarget };
@@ -1,8 +1,7 @@
1
- import node_fetch from "node-fetch";
2
1
  const injectNodeFetchPlugin = ()=>({
3
2
  name: 'inject-node-fetch-plugin',
4
3
  beforeInit (args) {
5
- if (!globalThis.fetch) globalThis.fetch = node_fetch;
4
+ if (!globalThis.fetch) throw new Error('@module-federation/modern-js-v3 requires Node.js 18 or later.');
6
5
  return args;
7
6
  }
8
7
  });
@@ -1,5 +1,5 @@
1
1
  import { access, lstat, readFile } from "fs/promises";
2
- import { LRUCache } from "lru-cache";
2
+ import { SizeLimitedCache } from "@module-federation/bridge-react/size-limited-cache";
3
3
  const pathExists = async (filepath)=>{
4
4
  try {
5
5
  await access(filepath);
@@ -35,9 +35,9 @@ class FileCache {
35
35
  return null;
36
36
  }
37
37
  }
38
- constructor(){
39
- this.cache = new LRUCache({
40
- maxSize: 209715200
38
+ constructor(maxSize = 209715200){
39
+ this.cache = new SizeLimitedCache({
40
+ maxSize
41
41
  });
42
42
  }
43
43
  }
@@ -8,6 +8,7 @@ export type ConfigType = Rspack.Configuration;
8
8
  export declare function setEnv(enableSSR: boolean): void;
9
9
  export declare const getMFConfig: (userConfig: PluginOptions) => Promise<moduleFederationPlugin.ModuleFederationPluginOptions>;
10
10
  export declare const patchMFConfig: (mfConfig: moduleFederationPlugin.ModuleFederationPluginOptions, isServer: boolean) => moduleFederationPlugin.ModuleFederationPluginOptions;
11
+ export declare const setDefaultOptimizationTarget: (mfConfig: moduleFederationPlugin.ModuleFederationPluginOptions, enableSSR: boolean, isServer: boolean, autoOptimization?: boolean) => void;
11
12
  export declare function addMyTypes2Ignored(chain: BundlerChainConfig, mfConfig: moduleFederationPlugin.ModuleFederationPluginOptions): void;
12
13
  export declare function patchBundlerConfig(options: {
13
14
  chain: BundlerChainConfig;
@@ -4,6 +4,7 @@ export interface FileResult {
4
4
  }
5
5
  export declare class FileCache {
6
6
  private cache;
7
+ constructor(maxSize?: number);
7
8
  /**
8
9
  * Check if file exists and return file info
9
10
  * @param filepath Path to the file
@@ -3,6 +3,12 @@ import type { StatsAssetResource } from '@module-federation/rsbuild-plugin/utils
3
3
  export interface PluginOptions {
4
4
  config?: moduleFederationPlugin.ModuleFederationPluginOptions;
5
5
  configPath?: string;
6
+ /**
7
+ * Automatically set the federation optimization target from the Modern.js
8
+ * SSR and bundler target configuration.
9
+ * @default true
10
+ */
11
+ autoOptimization?: boolean;
6
12
  ssr?: {
7
13
  distOutputDir?: string;
8
14
  } | boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@module-federation/modern-js-v3",
3
- "version": "2.7.0",
3
+ "version": "2.8.1",
4
4
  "files": [
5
5
  "dist/",
6
6
  "types.d.ts",
@@ -131,19 +131,19 @@
131
131
  "types": "./dist/types/cli/index.d.ts",
132
132
  "author": "hanric <hanric.zhang@gmail.com>",
133
133
  "license": "MIT",
134
+ "engines": {
135
+ "node": ">=18.0.0"
136
+ },
134
137
  "dependencies": {
135
- "lru-cache": "10.4.3",
136
138
  "@swc/helpers": "0.5.17",
137
- "node-fetch": "3.3.0",
138
139
  "jiti": "2.4.2",
139
- "react-error-boundary": "4.1.2",
140
- "@module-federation/rsbuild-plugin": "2.7.0",
141
- "@module-federation/enhanced": "2.7.0",
142
- "@module-federation/bridge-react": "2.7.0",
143
- "@module-federation/runtime": "2.7.0",
144
- "@module-federation/node": "2.7.46",
145
- "@module-federation/cli": "2.7.0",
146
- "@module-federation/sdk": "2.7.0"
140
+ "@module-federation/rsbuild-plugin": "2.8.1",
141
+ "@module-federation/bridge-react": "2.8.1",
142
+ "@module-federation/enhanced": "2.8.1",
143
+ "@module-federation/node": "2.7.48",
144
+ "@module-federation/runtime": "2.8.1",
145
+ "@module-federation/cli": "2.8.1",
146
+ "@module-federation/sdk": "2.8.1"
147
147
  },
148
148
  "devDependencies": {
149
149
  "@rsbuild/plugin-react": "1.4.5",
@@ -155,18 +155,17 @@
155
155
  "@modern-js/server-runtime": "3.5.0",
156
156
  "@modern-js/module-tools": "2.70.5",
157
157
  "@modern-js/runtime": "3.5.0",
158
- "@modern-js/tsconfig": "3.5.0",
159
158
  "@types/react": "^18.3.11",
160
159
  "@types/react-dom": "^18.3.0",
161
160
  "react": "~18.3.1",
162
161
  "react-dom": "~18.3.1",
163
- "typescript": "6.0.3",
164
- "@module-federation/manifest": "2.7.0"
162
+ "typescript": "7.0.2",
163
+ "@module-federation/manifest": "2.8.1"
165
164
  },
166
165
  "peerDependencies": {
167
166
  "react": ">=17",
168
167
  "react-dom": ">=17",
169
- "typescript": "^4.9.0 || ^5.0.0 || ^6.0.0",
168
+ "typescript": "^4.9.0 || ^5.0.0 || ^6.0.0 || ^7.0.0",
170
169
  "vue-tsc": "^1.0.24",
171
170
  "react-router-dom": "^4 || ^5 || ^6 || ^7",
172
171
  "react-router": "^7"
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};