@module-federation/modern-js 0.0.0-next-20240724103050 → 0.0.0-next-20240725035430

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.
@@ -51,6 +51,15 @@ function modifyBundlerConfig(options) {
51
51
  modernjsConfig,
52
52
  mfConfig
53
53
  });
54
+ if (bundlerType === "webpack") {
55
+ config.ignoreWarnings = config.ignoreWarnings || [];
56
+ config.ignoreWarnings.push((warning) => {
57
+ if (warning.message.includes("external script")) {
58
+ return true;
59
+ }
60
+ return false;
61
+ });
62
+ }
54
63
  }
55
64
  const moduleFederationConfigPlugin = (userConfig) => ({
56
65
  name: "@modern-js/plugin-module-federation-config",
@@ -36,10 +36,10 @@ module.exports = __toCommonJS(ssrPlugin_exports);
36
36
  var import_path = __toESM(require("path"));
37
37
  var import_utils = require("@modern-js/utils");
38
38
  var import_enhanced = require("@module-federation/enhanced");
39
- var import_rspack = require("@module-federation/enhanced/rspack");
40
39
  var import_node = require("@module-federation/node");
41
40
  var import_manifest = require("./manifest");
42
- var import_constant = require("./constant");
41
+ var import_constant = require("../constant");
42
+ var import_constant2 = require("./constant");
43
43
  function setEnv() {
44
44
  process.env["MF_DISABLE_EMIT_STATS"] = "true";
45
45
  process.env["MF_SSR_PRJ"] = "true";
@@ -50,7 +50,7 @@ const moduleFederationSSRPlugin = (userConfig) => ({
50
50
  "@modern-js/plugin-module-federation-config",
51
51
  "@modern-js/plugin-module-federation"
52
52
  ],
53
- setup: async ({ useConfigContext, useAppContext }) => {
53
+ setup: async ({ useConfigContext }) => {
54
54
  var _modernjsConfig_server;
55
55
  const modernjsConfig = useConfigContext();
56
56
  const enableSSR = Boolean(modernjsConfig === null || modernjsConfig === void 0 ? void 0 : (_modernjsConfig_server = modernjsConfig.server) === null || _modernjsConfig_server === void 0 ? void 0 : _modernjsConfig_server.ssr);
@@ -60,7 +60,7 @@ const moduleFederationSSRPlugin = (userConfig) => ({
60
60
  setEnv();
61
61
  return {
62
62
  _internalRuntimePlugins: ({ entrypoint, plugins }) => {
63
- if (!import_constant.isDev) {
63
+ if (!import_constant2.isDev) {
64
64
  return {
65
65
  entrypoint,
66
66
  plugins
@@ -77,36 +77,25 @@ const moduleFederationSSRPlugin = (userConfig) => ({
77
77
  };
78
78
  },
79
79
  config: async () => {
80
- var _modernjsConfig_source, _modernjsConfig_source1;
81
- const bundlerType = useAppContext().bundlerType === "rspack" ? "rspack" : "webpack";
82
- var _modernjsConfig_source_enableAsyncEntry;
83
80
  return {
84
- source: {
85
- 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
86
- },
87
81
  tools: {
88
82
  rspack(config, { isServer }) {
89
83
  if (isServer) {
90
- if (!userConfig.nodePlugin) {
91
- var _config_plugins;
92
- userConfig.nodePlugin = new import_rspack.ModuleFederationPlugin(userConfig.ssrConfig);
93
- (_config_plugins = config.plugins) === null || _config_plugins === void 0 ? void 0 : _config_plugins.push(userConfig.nodePlugin);
94
- }
95
- } else {
96
- var _config_output;
97
- userConfig.distOutputDir = userConfig.distOutputDir || ((_config_output = config.output) === null || _config_output === void 0 ? void 0 : _config_output.path) || import_path.default.resolve(process.cwd(), "dist");
84
+ throw new Error(`${import_constant.PLUGIN_IDENTIFIER} Not support rspack ssr mode yet !`);
98
85
  }
99
86
  },
100
87
  webpack(config, { isServer }) {
101
88
  if (isServer) {
89
+ var _config_plugins;
102
90
  if (!userConfig.nodePlugin) {
103
- var _config_plugins;
91
+ var _config_plugins1;
104
92
  userConfig.nodePlugin = new import_enhanced.ModuleFederationPlugin(userConfig.ssrConfig);
105
- (_config_plugins = config.plugins) === null || _config_plugins === void 0 ? void 0 : _config_plugins.push(userConfig.nodePlugin);
93
+ (_config_plugins1 = config.plugins) === null || _config_plugins1 === void 0 ? void 0 : _config_plugins1.push(userConfig.nodePlugin);
106
94
  }
107
- if (import_constant.isDev) {
108
- var _config_plugins1;
109
- (_config_plugins1 = config.plugins) === null || _config_plugins1 === void 0 ? void 0 : _config_plugins1.push(new import_node.EntryChunkTrackerPlugin());
95
+ (_config_plugins = config.plugins) === null || _config_plugins === void 0 ? void 0 : _config_plugins.push(new import_node.StreamingTargetPlugin(userConfig.nodePlugin));
96
+ if (import_constant2.isDev) {
97
+ var _config_plugins2;
98
+ (_config_plugins2 = config.plugins) === null || _config_plugins2 === void 0 ? void 0 : _config_plugins2.push(new import_node.EntryChunkTrackerPlugin());
110
99
  }
111
100
  } else {
112
101
  var _config_output;
@@ -142,10 +131,7 @@ const moduleFederationSSRPlugin = (userConfig) => ({
142
131
  ]
143
132
  },
144
133
  bundlerChain(chain, { isServer }) {
145
- if (isServer) {
146
- chain.target("async-node");
147
- }
148
- if (import_constant.isDev && !isServer) {
134
+ if (import_constant2.isDev && !isServer) {
149
135
  chain.externals({
150
136
  "@module-federation/node/utils": "NOT_USED_IN_BROWSER"
151
137
  });
@@ -31,7 +31,6 @@ __export(utils_exports, {
31
31
  getIPV4: () => getIPV4,
32
32
  getMFConfig: () => getMFConfig,
33
33
  patchBundlerConfig: () => patchBundlerConfig,
34
- patchIgnoreWarning: () => patchIgnoreWarning,
35
34
  patchMFConfig: () => patchMFConfig
36
35
  });
37
36
  module.exports = __toCommonJS(utils_exports);
@@ -139,7 +138,6 @@ const patchMFConfig = (mfConfig, isServer, remoteIpStrategy) => {
139
138
  injectRuntimePlugins(import_path.default.resolve(__dirname, "./mfRuntimePlugins/resolve-entry-ipv4.js"), runtimePlugins);
140
139
  }
141
140
  if (isServer) {
142
- injectRuntimePlugins(require.resolve("@module-federation/node/runtimePlugin"), runtimePlugins);
143
141
  if (isDev) {
144
142
  injectRuntimePlugins(require.resolve("@module-federation/node/record-dynamic-remote-entry-hash-plugin"), runtimePlugins);
145
143
  }
@@ -170,43 +168,11 @@ const patchMFConfig = (mfConfig, isServer, remoteIpStrategy) => {
170
168
  mfConfig.dev = false;
171
169
  return mfConfig;
172
170
  };
173
- function patchIgnoreWarning(bundlerConfig) {
174
- bundlerConfig.ignoreWarnings = bundlerConfig.ignoreWarnings || [];
175
- const ignoredMsgs = [
176
- "external script",
177
- "process.env.WS_NO_BUFFER_UTIL",
178
- `Can't resolve 'utf-8-validate`
179
- ];
180
- bundlerConfig.ignoreWarnings.push((warning) => {
181
- if (ignoredMsgs.some((msg) => warning.message.includes(msg))) {
182
- return true;
183
- }
184
- return false;
185
- });
186
- }
187
171
  function patchBundlerConfig(options) {
188
172
  var _modernjsConfig_server, _bundlerConfig_optimization, _bundlerConfig_optimization1, _bundlerConfig_output, _modernjsConfig_deploy;
189
173
  const { bundlerConfig, modernjsConfig, isServer, mfConfig } = options;
190
174
  const enableSSR = Boolean((_modernjsConfig_server = modernjsConfig.server) === null || _modernjsConfig_server === void 0 ? void 0 : _modernjsConfig_server.ssr);
191
175
  (_bundlerConfig_optimization = bundlerConfig.optimization) === null || _bundlerConfig_optimization === void 0 ? true : delete _bundlerConfig_optimization.runtimeChunk;
192
- patchIgnoreWarning(bundlerConfig);
193
- bundlerConfig.watchOptions = bundlerConfig.watchOptions || {};
194
- if (!Array.isArray(bundlerConfig.watchOptions.ignored)) {
195
- if (bundlerConfig.watchOptions.ignored) {
196
- bundlerConfig.watchOptions.ignored = [
197
- bundlerConfig.watchOptions.ignored
198
- ];
199
- } else {
200
- bundlerConfig.watchOptions.ignored = [];
201
- }
202
- }
203
- if (mfConfig.dts !== false) {
204
- if (typeof mfConfig.dts === "object" && typeof mfConfig.dts.consumeTypes === "object" && mfConfig.dts.consumeTypes.remoteTypesFolder) {
205
- bundlerConfig.watchOptions.ignored.push(mfConfig.dts.consumeTypes.remoteTypesFolder);
206
- } else {
207
- bundlerConfig.watchOptions.ignored.push("@mf-types");
208
- }
209
- }
210
176
  if (bundlerConfig.output) {
211
177
  var _bundlerConfig_output1, _bundlerConfig_output2;
212
178
  if (!((_bundlerConfig_output1 = bundlerConfig.output) === null || _bundlerConfig_output1 === void 0 ? void 0 : _bundlerConfig_output1.chunkLoadingGlobal)) {
@@ -324,6 +290,5 @@ function autoDeleteSplitChunkCacheGroups(mfConfig, bundlerConfig) {
324
290
  getIPV4,
325
291
  getMFConfig,
326
292
  patchBundlerConfig,
327
- patchIgnoreWarning,
328
293
  patchMFConfig
329
294
  });
@@ -61,7 +61,6 @@ const mfConfig = {
61
61
  remoteType: "script",
62
62
  runtimePlugins: [
63
63
  import_path.default.resolve(__dirname, "./mfRuntimePlugins/shared-strategy.js"),
64
- require.resolve("@module-federation/node/runtimePlugin"),
65
64
  import_path.default.resolve(__dirname, "./mfRuntimePlugins/inject-node-fetch.js")
66
65
  ],
67
66
  shared: {
@@ -129,20 +128,13 @@ const mfConfig = {
129
128
  },
130
129
  mfConfig
131
130
  });
132
- const expectedConfig = {
131
+ (0, import_vitest.expect)(bundlerConfig).toStrictEqual({
133
132
  output: {
134
133
  chunkLoadingGlobal: "chunk_host",
135
134
  publicPath: "auto",
136
135
  uniqueName: "host"
137
- },
138
- watchOptions: {
139
- ignored: [
140
- "@mf-types"
141
- ]
142
136
  }
143
- };
144
- bundlerConfig === null || bundlerConfig === void 0 ? true : delete bundlerConfig.ignoreWarnings;
145
- (0, import_vitest.expect)(bundlerConfig).toStrictEqual(expectedConfig);
137
+ });
146
138
  });
147
139
  (0, import_vitest.it)("patchBundlerConfig: client", async () => {
148
140
  const bundlerConfig = {
@@ -162,19 +154,12 @@ const mfConfig = {
162
154
  },
163
155
  mfConfig
164
156
  });
165
- const expectedConfig = {
157
+ (0, import_vitest.expect)(bundlerConfig).toStrictEqual({
166
158
  output: {
167
159
  chunkLoadingGlobal: "chunk_host",
168
160
  publicPath: "auto",
169
161
  uniqueName: "host"
170
- },
171
- watchOptions: {
172
- ignored: [
173
- "@mf-types"
174
- ]
175
162
  }
176
- };
177
- bundlerConfig === null || bundlerConfig === void 0 ? true : delete bundlerConfig.ignoreWarnings;
178
- (0, import_vitest.expect)(bundlerConfig).toStrictEqual(expectedConfig);
163
+ });
179
164
  });
180
165
  });
@@ -17,6 +17,15 @@ function modifyBundlerConfig(options) {
17
17
  modernjsConfig,
18
18
  mfConfig
19
19
  });
20
+ if (bundlerType === "webpack") {
21
+ config.ignoreWarnings = config.ignoreWarnings || [];
22
+ config.ignoreWarnings.push(function(warning) {
23
+ if (warning.message.includes("external script")) {
24
+ return true;
25
+ }
26
+ return false;
27
+ });
28
+ }
20
29
  }
21
30
  var moduleFederationConfigPlugin = function(userConfig) {
22
31
  return {
@@ -3,9 +3,9 @@ import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
3
3
  import path from "path";
4
4
  import { fs } from "@modern-js/utils";
5
5
  import { ModuleFederationPlugin } from "@module-federation/enhanced";
6
- import { ModuleFederationPlugin as RspackModuleFederationPlugin } from "@module-federation/enhanced/rspack";
7
- import { EntryChunkTrackerPlugin } from "@module-federation/node";
6
+ import { StreamingTargetPlugin, EntryChunkTrackerPlugin } from "@module-federation/node";
8
7
  import { updateStatsAndManifest } from "./manifest";
8
+ import { PLUGIN_IDENTIFIER } from "../constant";
9
9
  import { isDev } from "./constant";
10
10
  function setEnv() {
11
11
  process.env["MF_DISABLE_EMIT_STATS"] = "true";
@@ -20,9 +20,9 @@ var moduleFederationSSRPlugin = function(userConfig) {
20
20
  ],
21
21
  setup: function() {
22
22
  var _ref = _async_to_generator(function(param) {
23
- var useConfigContext, useAppContext, _modernjsConfig_server, modernjsConfig, enableSSR;
23
+ var useConfigContext, _modernjsConfig_server, modernjsConfig, enableSSR;
24
24
  return _ts_generator(this, function(_state) {
25
- useConfigContext = param.useConfigContext, useAppContext = param.useAppContext;
25
+ useConfigContext = param.useConfigContext;
26
26
  modernjsConfig = useConfigContext();
27
27
  enableSSR = Boolean(modernjsConfig === null || modernjsConfig === void 0 ? void 0 : (_modernjsConfig_server = modernjsConfig.server) === null || _modernjsConfig_server === void 0 ? void 0 : _modernjsConfig_server.ssr);
28
28
  if (!enableSSR) {
@@ -54,40 +54,30 @@ var moduleFederationSSRPlugin = function(userConfig) {
54
54
  };
55
55
  },
56
56
  config: /* @__PURE__ */ _async_to_generator(function() {
57
- var _modernjsConfig_source, _modernjsConfig_source1, bundlerType, _modernjsConfig_source_enableAsyncEntry;
58
57
  return _ts_generator(this, function(_state2) {
59
- bundlerType = useAppContext().bundlerType === "rspack" ? "rspack" : "webpack";
60
58
  return [
61
59
  2,
62
60
  {
63
- source: {
64
- 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
65
- },
66
61
  tools: {
67
62
  rspack: function rspack(config, param2) {
68
63
  var isServer = param2.isServer;
69
64
  if (isServer) {
70
- if (!userConfig.nodePlugin) {
71
- var _config_plugins;
72
- userConfig.nodePlugin = new RspackModuleFederationPlugin(userConfig.ssrConfig);
73
- (_config_plugins = config.plugins) === null || _config_plugins === void 0 ? void 0 : _config_plugins.push(userConfig.nodePlugin);
74
- }
75
- } else {
76
- var _config_output;
77
- userConfig.distOutputDir = userConfig.distOutputDir || ((_config_output = config.output) === null || _config_output === void 0 ? void 0 : _config_output.path) || path.resolve(process.cwd(), "dist");
65
+ throw new Error("".concat(PLUGIN_IDENTIFIER, " Not support rspack ssr mode yet !"));
78
66
  }
79
67
  },
80
68
  webpack: function webpack(config, param2) {
81
69
  var isServer = param2.isServer;
82
70
  if (isServer) {
71
+ var _config_plugins;
83
72
  if (!userConfig.nodePlugin) {
84
- var _config_plugins;
73
+ var _config_plugins1;
85
74
  userConfig.nodePlugin = new ModuleFederationPlugin(userConfig.ssrConfig);
86
- (_config_plugins = config.plugins) === null || _config_plugins === void 0 ? void 0 : _config_plugins.push(userConfig.nodePlugin);
75
+ (_config_plugins1 = config.plugins) === null || _config_plugins1 === void 0 ? void 0 : _config_plugins1.push(userConfig.nodePlugin);
87
76
  }
77
+ (_config_plugins = config.plugins) === null || _config_plugins === void 0 ? void 0 : _config_plugins.push(new StreamingTargetPlugin(userConfig.nodePlugin));
88
78
  if (isDev) {
89
- var _config_plugins1;
90
- (_config_plugins1 = config.plugins) === null || _config_plugins1 === void 0 ? void 0 : _config_plugins1.push(new EntryChunkTrackerPlugin());
79
+ var _config_plugins2;
80
+ (_config_plugins2 = config.plugins) === null || _config_plugins2 === void 0 ? void 0 : _config_plugins2.push(new EntryChunkTrackerPlugin());
91
81
  }
92
82
  } else {
93
83
  var _config_output;
@@ -124,9 +114,6 @@ var moduleFederationSSRPlugin = function(userConfig) {
124
114
  },
125
115
  bundlerChain: function bundlerChain(chain, param2) {
126
116
  var isServer = param2.isServer;
127
- if (isServer) {
128
- chain.target("async-node");
129
- }
130
117
  if (isDev && !isServer) {
131
118
  chain.externals({
132
119
  "@module-federation/node/utils": "NOT_USED_IN_BROWSER"
@@ -132,7 +132,6 @@ var patchMFConfig = function(mfConfig, isServer, remoteIpStrategy) {
132
132
  injectRuntimePlugins(path.resolve(__dirname, "./mfRuntimePlugins/resolve-entry-ipv4.js"), runtimePlugins);
133
133
  }
134
134
  if (isServer) {
135
- injectRuntimePlugins(require.resolve("@module-federation/node/runtimePlugin"), runtimePlugins);
136
135
  if (isDev) {
137
136
  injectRuntimePlugins(require.resolve("@module-federation/node/record-dynamic-remote-entry-hash-plugin"), runtimePlugins);
138
137
  }
@@ -163,45 +162,11 @@ var patchMFConfig = function(mfConfig, isServer, remoteIpStrategy) {
163
162
  mfConfig.dev = false;
164
163
  return mfConfig;
165
164
  };
166
- function patchIgnoreWarning(bundlerConfig) {
167
- bundlerConfig.ignoreWarnings = bundlerConfig.ignoreWarnings || [];
168
- var ignoredMsgs = [
169
- "external script",
170
- "process.env.WS_NO_BUFFER_UTIL",
171
- "Can't resolve 'utf-8-validate"
172
- ];
173
- bundlerConfig.ignoreWarnings.push(function(warning) {
174
- if (ignoredMsgs.some(function(msg) {
175
- return warning.message.includes(msg);
176
- })) {
177
- return true;
178
- }
179
- return false;
180
- });
181
- }
182
165
  function patchBundlerConfig(options) {
183
166
  var _modernjsConfig_server, _bundlerConfig_optimization, _bundlerConfig_optimization1, _bundlerConfig_output, _modernjsConfig_deploy;
184
167
  var bundlerConfig = options.bundlerConfig, modernjsConfig = options.modernjsConfig, isServer = options.isServer, mfConfig = options.mfConfig;
185
168
  var enableSSR = Boolean((_modernjsConfig_server = modernjsConfig.server) === null || _modernjsConfig_server === void 0 ? void 0 : _modernjsConfig_server.ssr);
186
169
  (_bundlerConfig_optimization = bundlerConfig.optimization) === null || _bundlerConfig_optimization === void 0 ? true : delete _bundlerConfig_optimization.runtimeChunk;
187
- patchIgnoreWarning(bundlerConfig);
188
- bundlerConfig.watchOptions = bundlerConfig.watchOptions || {};
189
- if (!Array.isArray(bundlerConfig.watchOptions.ignored)) {
190
- if (bundlerConfig.watchOptions.ignored) {
191
- bundlerConfig.watchOptions.ignored = [
192
- bundlerConfig.watchOptions.ignored
193
- ];
194
- } else {
195
- bundlerConfig.watchOptions.ignored = [];
196
- }
197
- }
198
- if (mfConfig.dts !== false) {
199
- if (typeof mfConfig.dts === "object" && typeof mfConfig.dts.consumeTypes === "object" && mfConfig.dts.consumeTypes.remoteTypesFolder) {
200
- bundlerConfig.watchOptions.ignored.push(mfConfig.dts.consumeTypes.remoteTypesFolder);
201
- } else {
202
- bundlerConfig.watchOptions.ignored.push("@mf-types");
203
- }
204
- }
205
170
  if (bundlerConfig.output) {
206
171
  var _bundlerConfig_output1, _bundlerConfig_output2;
207
172
  if (!((_bundlerConfig_output1 = bundlerConfig.output) === null || _bundlerConfig_output1 === void 0 ? void 0 : _bundlerConfig_output1.chunkLoadingGlobal)) {
@@ -334,6 +299,5 @@ export {
334
299
  getIPV4,
335
300
  getMFConfig,
336
301
  patchBundlerConfig,
337
- patchIgnoreWarning,
338
302
  patchMFConfig
339
303
  };
@@ -43,7 +43,6 @@ describe("patchMFConfig", /* @__PURE__ */ _async_to_generator(function() {
43
43
  remoteType: "script",
44
44
  runtimePlugins: [
45
45
  path.resolve(__dirname, "./mfRuntimePlugins/shared-strategy.js"),
46
- require.resolve("@module-federation/node/runtimePlugin"),
47
46
  path.resolve(__dirname, "./mfRuntimePlugins/inject-node-fetch.js")
48
47
  ],
49
48
  shared: {
@@ -109,7 +108,7 @@ describe("patchMFConfig", /* @__PURE__ */ _async_to_generator(function() {
109
108
  describe("patchBundlerConfig", /* @__PURE__ */ _async_to_generator(function() {
110
109
  return _ts_generator(this, function(_state) {
111
110
  it("patchBundlerConfig: server", /* @__PURE__ */ _async_to_generator(function() {
112
- var bundlerConfig, expectedConfig;
111
+ var bundlerConfig;
113
112
  return _ts_generator(this, function(_state2) {
114
113
  bundlerConfig = {
115
114
  output: {
@@ -128,27 +127,20 @@ describe("patchBundlerConfig", /* @__PURE__ */ _async_to_generator(function() {
128
127
  },
129
128
  mfConfig
130
129
  });
131
- expectedConfig = {
130
+ expect(bundlerConfig).toStrictEqual({
132
131
  output: {
133
132
  chunkLoadingGlobal: "chunk_host",
134
133
  publicPath: "auto",
135
134
  uniqueName: "host"
136
- },
137
- watchOptions: {
138
- ignored: [
139
- "@mf-types"
140
- ]
141
135
  }
142
- };
143
- bundlerConfig === null || bundlerConfig === void 0 ? true : delete bundlerConfig.ignoreWarnings;
144
- expect(bundlerConfig).toStrictEqual(expectedConfig);
136
+ });
145
137
  return [
146
138
  2
147
139
  ];
148
140
  });
149
141
  }));
150
142
  it("patchBundlerConfig: client", /* @__PURE__ */ _async_to_generator(function() {
151
- var bundlerConfig, expectedConfig;
143
+ var bundlerConfig;
152
144
  return _ts_generator(this, function(_state2) {
153
145
  bundlerConfig = {
154
146
  output: {
@@ -167,20 +159,13 @@ describe("patchBundlerConfig", /* @__PURE__ */ _async_to_generator(function() {
167
159
  },
168
160
  mfConfig
169
161
  });
170
- expectedConfig = {
162
+ expect(bundlerConfig).toStrictEqual({
171
163
  output: {
172
164
  chunkLoadingGlobal: "chunk_host",
173
165
  publicPath: "auto",
174
166
  uniqueName: "host"
175
- },
176
- watchOptions: {
177
- ignored: [
178
- "@mf-types"
179
- ]
180
167
  }
181
- };
182
- bundlerConfig === null || bundlerConfig === void 0 ? true : delete bundlerConfig.ignoreWarnings;
183
- expect(bundlerConfig).toStrictEqual(expectedConfig);
168
+ });
184
169
  return [
185
170
  2
186
171
  ];
@@ -15,6 +15,15 @@ function modifyBundlerConfig(options) {
15
15
  modernjsConfig,
16
16
  mfConfig
17
17
  });
18
+ if (bundlerType === "webpack") {
19
+ config.ignoreWarnings = config.ignoreWarnings || [];
20
+ config.ignoreWarnings.push((warning) => {
21
+ if (warning.message.includes("external script")) {
22
+ return true;
23
+ }
24
+ return false;
25
+ });
26
+ }
18
27
  }
19
28
  const moduleFederationConfigPlugin = (userConfig) => ({
20
29
  name: "@modern-js/plugin-module-federation-config",
@@ -1,9 +1,9 @@
1
1
  import path from "path";
2
2
  import { fs } from "@modern-js/utils";
3
3
  import { ModuleFederationPlugin } from "@module-federation/enhanced";
4
- import { ModuleFederationPlugin as RspackModuleFederationPlugin } from "@module-federation/enhanced/rspack";
5
- import { EntryChunkTrackerPlugin } from "@module-federation/node";
4
+ import { StreamingTargetPlugin, EntryChunkTrackerPlugin } from "@module-federation/node";
6
5
  import { updateStatsAndManifest } from "./manifest";
6
+ import { PLUGIN_IDENTIFIER } from "../constant";
7
7
  import { isDev } from "./constant";
8
8
  function setEnv() {
9
9
  process.env["MF_DISABLE_EMIT_STATS"] = "true";
@@ -15,7 +15,7 @@ const moduleFederationSSRPlugin = (userConfig) => ({
15
15
  "@modern-js/plugin-module-federation-config",
16
16
  "@modern-js/plugin-module-federation"
17
17
  ],
18
- setup: async ({ useConfigContext, useAppContext }) => {
18
+ setup: async ({ useConfigContext }) => {
19
19
  var _modernjsConfig_server;
20
20
  const modernjsConfig = useConfigContext();
21
21
  const enableSSR = Boolean(modernjsConfig === null || modernjsConfig === void 0 ? void 0 : (_modernjsConfig_server = modernjsConfig.server) === null || _modernjsConfig_server === void 0 ? void 0 : _modernjsConfig_server.ssr);
@@ -42,36 +42,25 @@ const moduleFederationSSRPlugin = (userConfig) => ({
42
42
  };
43
43
  },
44
44
  config: async () => {
45
- var _modernjsConfig_source, _modernjsConfig_source1;
46
- const bundlerType = useAppContext().bundlerType === "rspack" ? "rspack" : "webpack";
47
- var _modernjsConfig_source_enableAsyncEntry;
48
45
  return {
49
- source: {
50
- 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
51
- },
52
46
  tools: {
53
47
  rspack(config, { isServer }) {
54
48
  if (isServer) {
55
- if (!userConfig.nodePlugin) {
56
- var _config_plugins;
57
- userConfig.nodePlugin = new RspackModuleFederationPlugin(userConfig.ssrConfig);
58
- (_config_plugins = config.plugins) === null || _config_plugins === void 0 ? void 0 : _config_plugins.push(userConfig.nodePlugin);
59
- }
60
- } else {
61
- var _config_output;
62
- userConfig.distOutputDir = userConfig.distOutputDir || ((_config_output = config.output) === null || _config_output === void 0 ? void 0 : _config_output.path) || path.resolve(process.cwd(), "dist");
49
+ throw new Error(`${PLUGIN_IDENTIFIER} Not support rspack ssr mode yet !`);
63
50
  }
64
51
  },
65
52
  webpack(config, { isServer }) {
66
53
  if (isServer) {
54
+ var _config_plugins;
67
55
  if (!userConfig.nodePlugin) {
68
- var _config_plugins;
56
+ var _config_plugins1;
69
57
  userConfig.nodePlugin = new ModuleFederationPlugin(userConfig.ssrConfig);
70
- (_config_plugins = config.plugins) === null || _config_plugins === void 0 ? void 0 : _config_plugins.push(userConfig.nodePlugin);
58
+ (_config_plugins1 = config.plugins) === null || _config_plugins1 === void 0 ? void 0 : _config_plugins1.push(userConfig.nodePlugin);
71
59
  }
60
+ (_config_plugins = config.plugins) === null || _config_plugins === void 0 ? void 0 : _config_plugins.push(new StreamingTargetPlugin(userConfig.nodePlugin));
72
61
  if (isDev) {
73
- var _config_plugins1;
74
- (_config_plugins1 = config.plugins) === null || _config_plugins1 === void 0 ? void 0 : _config_plugins1.push(new EntryChunkTrackerPlugin());
62
+ var _config_plugins2;
63
+ (_config_plugins2 = config.plugins) === null || _config_plugins2 === void 0 ? void 0 : _config_plugins2.push(new EntryChunkTrackerPlugin());
75
64
  }
76
65
  } else {
77
66
  var _config_output;
@@ -107,9 +96,6 @@ const moduleFederationSSRPlugin = (userConfig) => ({
107
96
  ]
108
97
  },
109
98
  bundlerChain(chain, { isServer }) {
110
- if (isServer) {
111
- chain.target("async-node");
112
- }
113
99
  if (isDev && !isServer) {
114
100
  chain.externals({
115
101
  "@module-federation/node/utils": "NOT_USED_IN_BROWSER"
@@ -102,7 +102,6 @@ const patchMFConfig = (mfConfig, isServer, remoteIpStrategy) => {
102
102
  injectRuntimePlugins(path.resolve(__dirname, "./mfRuntimePlugins/resolve-entry-ipv4.js"), runtimePlugins);
103
103
  }
104
104
  if (isServer) {
105
- injectRuntimePlugins(require.resolve("@module-federation/node/runtimePlugin"), runtimePlugins);
106
105
  if (isDev) {
107
106
  injectRuntimePlugins(require.resolve("@module-federation/node/record-dynamic-remote-entry-hash-plugin"), runtimePlugins);
108
107
  }
@@ -133,43 +132,11 @@ const patchMFConfig = (mfConfig, isServer, remoteIpStrategy) => {
133
132
  mfConfig.dev = false;
134
133
  return mfConfig;
135
134
  };
136
- function patchIgnoreWarning(bundlerConfig) {
137
- bundlerConfig.ignoreWarnings = bundlerConfig.ignoreWarnings || [];
138
- const ignoredMsgs = [
139
- "external script",
140
- "process.env.WS_NO_BUFFER_UTIL",
141
- `Can't resolve 'utf-8-validate`
142
- ];
143
- bundlerConfig.ignoreWarnings.push((warning) => {
144
- if (ignoredMsgs.some((msg) => warning.message.includes(msg))) {
145
- return true;
146
- }
147
- return false;
148
- });
149
- }
150
135
  function patchBundlerConfig(options) {
151
136
  var _modernjsConfig_server, _bundlerConfig_optimization, _bundlerConfig_optimization1, _bundlerConfig_output, _modernjsConfig_deploy;
152
137
  const { bundlerConfig, modernjsConfig, isServer, mfConfig } = options;
153
138
  const enableSSR = Boolean((_modernjsConfig_server = modernjsConfig.server) === null || _modernjsConfig_server === void 0 ? void 0 : _modernjsConfig_server.ssr);
154
139
  (_bundlerConfig_optimization = bundlerConfig.optimization) === null || _bundlerConfig_optimization === void 0 ? true : delete _bundlerConfig_optimization.runtimeChunk;
155
- patchIgnoreWarning(bundlerConfig);
156
- bundlerConfig.watchOptions = bundlerConfig.watchOptions || {};
157
- if (!Array.isArray(bundlerConfig.watchOptions.ignored)) {
158
- if (bundlerConfig.watchOptions.ignored) {
159
- bundlerConfig.watchOptions.ignored = [
160
- bundlerConfig.watchOptions.ignored
161
- ];
162
- } else {
163
- bundlerConfig.watchOptions.ignored = [];
164
- }
165
- }
166
- if (mfConfig.dts !== false) {
167
- if (typeof mfConfig.dts === "object" && typeof mfConfig.dts.consumeTypes === "object" && mfConfig.dts.consumeTypes.remoteTypesFolder) {
168
- bundlerConfig.watchOptions.ignored.push(mfConfig.dts.consumeTypes.remoteTypesFolder);
169
- } else {
170
- bundlerConfig.watchOptions.ignored.push("@mf-types");
171
- }
172
- }
173
140
  if (bundlerConfig.output) {
174
141
  var _bundlerConfig_output1, _bundlerConfig_output2;
175
142
  if (!((_bundlerConfig_output1 = bundlerConfig.output) === null || _bundlerConfig_output1 === void 0 ? void 0 : _bundlerConfig_output1.chunkLoadingGlobal)) {
@@ -286,6 +253,5 @@ export {
286
253
  getIPV4,
287
254
  getMFConfig,
288
255
  patchBundlerConfig,
289
- patchIgnoreWarning,
290
256
  patchMFConfig
291
257
  };
@@ -38,7 +38,6 @@ describe("patchMFConfig", async () => {
38
38
  remoteType: "script",
39
39
  runtimePlugins: [
40
40
  path.resolve(__dirname, "./mfRuntimePlugins/shared-strategy.js"),
41
- require.resolve("@module-federation/node/runtimePlugin"),
42
41
  path.resolve(__dirname, "./mfRuntimePlugins/inject-node-fetch.js")
43
42
  ],
44
43
  shared: {
@@ -106,20 +105,13 @@ describe("patchBundlerConfig", async () => {
106
105
  },
107
106
  mfConfig
108
107
  });
109
- const expectedConfig = {
108
+ expect(bundlerConfig).toStrictEqual({
110
109
  output: {
111
110
  chunkLoadingGlobal: "chunk_host",
112
111
  publicPath: "auto",
113
112
  uniqueName: "host"
114
- },
115
- watchOptions: {
116
- ignored: [
117
- "@mf-types"
118
- ]
119
113
  }
120
- };
121
- bundlerConfig === null || bundlerConfig === void 0 ? true : delete bundlerConfig.ignoreWarnings;
122
- expect(bundlerConfig).toStrictEqual(expectedConfig);
114
+ });
123
115
  });
124
116
  it("patchBundlerConfig: client", async () => {
125
117
  const bundlerConfig = {
@@ -139,19 +131,12 @@ describe("patchBundlerConfig", async () => {
139
131
  },
140
132
  mfConfig
141
133
  });
142
- const expectedConfig = {
134
+ expect(bundlerConfig).toStrictEqual({
143
135
  output: {
144
136
  chunkLoadingGlobal: "chunk_host",
145
137
  publicPath: "auto",
146
138
  uniqueName: "host"
147
- },
148
- watchOptions: {
149
- ignored: [
150
- "@mf-types"
151
- ]
152
139
  }
153
- };
154
- bundlerConfig === null || bundlerConfig === void 0 ? true : delete bundlerConfig.ignoreWarnings;
155
- expect(bundlerConfig).toStrictEqual(expectedConfig);
140
+ });
156
141
  });
157
142
  });
@@ -5,7 +5,6 @@ import { BundlerConfig } from '../interfaces/bundler';
5
5
  export type ConfigType<T> = T extends 'webpack' ? webpack.Configuration : T extends 'rspack' ? Rspack.Configuration : never;
6
6
  export declare const getMFConfig: (userConfig: PluginOptions) => Promise<moduleFederationPlugin.ModuleFederationPluginOptions>;
7
7
  export declare const patchMFConfig: (mfConfig: moduleFederationPlugin.ModuleFederationPluginOptions, isServer: boolean, remoteIpStrategy?: "ipv4" | "inherit") => moduleFederationPlugin.ModuleFederationPluginOptions;
8
- export declare function patchIgnoreWarning<T extends Bundler>(bundlerConfig: BundlerConfig<T>): void;
9
8
  export declare function patchBundlerConfig<T extends Bundler>(options: {
10
9
  bundlerConfig: BundlerConfig<T>;
11
10
  isServer: boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@module-federation/modern-js",
3
- "version": "0.0.0-next-20240724103050",
3
+ "version": "0.0.0-next-20240725035430",
4
4
  "files": [
5
5
  "dist/",
6
6
  "types.d.ts",
@@ -61,9 +61,9 @@
61
61
  "node-fetch": "~3.3.0",
62
62
  "react-error-boundary": "4.0.13",
63
63
  "hoist-non-react-statics": "3.3.2",
64
- "@module-federation/sdk": "0.0.0-next-20240724103050",
65
- "@module-federation/enhanced": "0.0.0-next-20240724103050",
66
- "@module-federation/node": "0.0.0-next-20240724103050"
64
+ "@module-federation/sdk": "0.0.0-next-20240725035430",
65
+ "@module-federation/enhanced": "0.0.0-next-20240725035430",
66
+ "@module-federation/node": "0.0.0-next-20240725035430"
67
67
  },
68
68
  "devDependencies": {
69
69
  "@types/hoist-non-react-statics": "3.3.2",
@@ -72,7 +72,7 @@
72
72
  "@modern-js/runtime": "2.56.1",
73
73
  "@modern-js/module-tools": "2.56.1",
74
74
  "@modern-js/tsconfig": "2.56.1",
75
- "@module-federation/manifest": "0.0.0-next-20240724103050"
75
+ "@module-federation/manifest": "0.0.0-next-20240725035430"
76
76
  },
77
77
  "peerDependencies": {
78
78
  "react": ">=17",
@@ -1,46 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var RspackNodePlugin_exports = {};
20
- __export(RspackNodePlugin_exports, {
21
- default: () => RspackNodePlugin
22
- });
23
- module.exports = __toCommonJS(RspackNodePlugin_exports);
24
- class RspackNodePlugin {
25
- apply(compiler) {
26
- const { webpack } = compiler;
27
- compiler.options.output.chunkFormat = "commonjs";
28
- if (compiler.options.output.enabledLibraryTypes === void 0) {
29
- compiler.options.output.enabledLibraryTypes = [
30
- "commonjs-module"
31
- ];
32
- } else {
33
- compiler.options.output.enabledLibraryTypes.push("commonjs-module");
34
- }
35
- compiler.options.output.chunkLoading = "async-node";
36
- compiler.options.output.enabledChunkLoadingTypes = [];
37
- compiler.options.output.environment = {
38
- ...compiler.options.output.environment,
39
- dynamicImport: true
40
- };
41
- new webpack.node.NodeEnvironmentPlugin.apply(compiler);
42
- new webpack.node.NodeTargetPlugin().apply(compiler);
43
- }
44
- constructor() {
45
- }
46
- }
@@ -1,32 +0,0 @@
1
- import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check";
2
- import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
3
- import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
4
- var RspackNodePlugin = /* @__PURE__ */ function() {
5
- "use strict";
6
- function RspackNodePlugin2() {
7
- _class_call_check(this, RspackNodePlugin2);
8
- }
9
- var _proto = RspackNodePlugin2.prototype;
10
- _proto.apply = function apply(compiler) {
11
- var webpack = compiler.webpack;
12
- compiler.options.output.chunkFormat = "commonjs";
13
- if (compiler.options.output.enabledLibraryTypes === void 0) {
14
- compiler.options.output.enabledLibraryTypes = [
15
- "commonjs-module"
16
- ];
17
- } else {
18
- compiler.options.output.enabledLibraryTypes.push("commonjs-module");
19
- }
20
- compiler.options.output.chunkLoading = "async-node";
21
- compiler.options.output.enabledChunkLoadingTypes = [];
22
- compiler.options.output.environment = _object_spread_props(_object_spread({}, compiler.options.output.environment), {
23
- dynamicImport: true
24
- });
25
- new webpack.node.NodeEnvironmentPlugin.apply(compiler);
26
- new webpack.node.NodeTargetPlugin().apply(compiler);
27
- };
28
- return RspackNodePlugin2;
29
- }();
30
- export {
31
- RspackNodePlugin as default
32
- };
@@ -1,26 +0,0 @@
1
- class RspackNodePlugin {
2
- apply(compiler) {
3
- const { webpack } = compiler;
4
- compiler.options.output.chunkFormat = "commonjs";
5
- if (compiler.options.output.enabledLibraryTypes === void 0) {
6
- compiler.options.output.enabledLibraryTypes = [
7
- "commonjs-module"
8
- ];
9
- } else {
10
- compiler.options.output.enabledLibraryTypes.push("commonjs-module");
11
- }
12
- compiler.options.output.chunkLoading = "async-node";
13
- compiler.options.output.enabledChunkLoadingTypes = [];
14
- compiler.options.output.environment = {
15
- ...compiler.options.output.environment,
16
- dynamicImport: true
17
- };
18
- new webpack.node.NodeEnvironmentPlugin.apply(compiler);
19
- new webpack.node.NodeTargetPlugin().apply(compiler);
20
- }
21
- constructor() {
22
- }
23
- }
24
- export {
25
- RspackNodePlugin as default
26
- };
@@ -1,5 +0,0 @@
1
- import type { Rspack } from '@modern-js/app-tools';
2
- export default class RspackNodePlugin implements Rspack.RspackPluginInstance {
3
- constructor();
4
- apply(compiler: Rspack.Compiler): void;
5
- }