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

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.
@@ -0,0 +1,46 @@
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
+ }
@@ -51,15 +51,6 @@ 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
- }
63
54
  }
64
55
  const moduleFederationConfigPlugin = (userConfig) => ({
65
56
  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");
39
40
  var import_node = require("@module-federation/node");
40
41
  var import_manifest = require("./manifest");
41
- var import_constant = require("../constant");
42
- var import_constant2 = require("./constant");
42
+ var import_constant = 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 }) => {
53
+ setup: async ({ useConfigContext, useAppContext }) => {
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_constant2.isDev) {
63
+ if (!import_constant.isDev) {
64
64
  return {
65
65
  entrypoint,
66
66
  plugins
@@ -77,25 +77,36 @@ 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;
80
83
  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
+ },
81
87
  tools: {
82
88
  rspack(config, { isServer }) {
83
89
  if (isServer) {
84
- throw new Error(`${import_constant.PLUGIN_IDENTIFIER} Not support rspack ssr mode yet !`);
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");
85
98
  }
86
99
  },
87
100
  webpack(config, { isServer }) {
88
101
  if (isServer) {
89
- var _config_plugins;
90
102
  if (!userConfig.nodePlugin) {
91
- var _config_plugins1;
103
+ var _config_plugins;
92
104
  userConfig.nodePlugin = new import_enhanced.ModuleFederationPlugin(userConfig.ssrConfig);
93
- (_config_plugins1 = config.plugins) === null || _config_plugins1 === void 0 ? void 0 : _config_plugins1.push(userConfig.nodePlugin);
105
+ (_config_plugins = config.plugins) === null || _config_plugins === void 0 ? void 0 : _config_plugins.push(userConfig.nodePlugin);
94
106
  }
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());
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());
99
110
  }
100
111
  } else {
101
112
  var _config_output;
@@ -110,9 +121,8 @@ const moduleFederationSSRPlugin = (userConfig) => ({
110
121
  return;
111
122
  }
112
123
  try {
113
- var _req_url, _req_url1, _req_url2;
114
- const SERVER_PREFIX = `/${import_constant.MODERN_JS_SERVER_DIR}`;
115
- if (((_req_url = req.url) === null || _req_url === void 0 ? void 0 : _req_url.startsWith(SERVER_PREFIX)) || ((_req_url1 = req.url) === null || _req_url1 === void 0 ? void 0 : _req_url1.includes(".json")) && !((_req_url2 = req.url) === null || _req_url2 === void 0 ? void 0 : _req_url2.includes("hot-update"))) {
124
+ var _req_url, _req_url1;
125
+ if (((_req_url = req.url) === null || _req_url === void 0 ? void 0 : _req_url.includes(".json")) && !((_req_url1 = req.url) === null || _req_url1 === void 0 ? void 0 : _req_url1.includes("hot-update"))) {
116
126
  const filepath = import_path.default.join(process.cwd(), `dist${req.url}`);
117
127
  import_utils.fs.statSync(filepath);
118
128
  res.setHeader("Access-Control-Allow-Origin", "*");
@@ -132,7 +142,10 @@ const moduleFederationSSRPlugin = (userConfig) => ({
132
142
  ]
133
143
  },
134
144
  bundlerChain(chain, { isServer }) {
135
- if (import_constant2.isDev && !isServer) {
145
+ if (isServer) {
146
+ chain.target("async-node");
147
+ }
148
+ if (import_constant.isDev && !isServer) {
136
149
  chain.externals({
137
150
  "@module-federation/node/utils": "NOT_USED_IN_BROWSER"
138
151
  });
@@ -31,6 +31,7 @@ __export(utils_exports, {
31
31
  getIPV4: () => getIPV4,
32
32
  getMFConfig: () => getMFConfig,
33
33
  patchBundlerConfig: () => patchBundlerConfig,
34
+ patchIgnoreWarning: () => patchIgnoreWarning,
34
35
  patchMFConfig: () => patchMFConfig
35
36
  });
36
37
  module.exports = __toCommonJS(utils_exports);
@@ -138,6 +139,7 @@ const patchMFConfig = (mfConfig, isServer, remoteIpStrategy) => {
138
139
  injectRuntimePlugins(import_path.default.resolve(__dirname, "./mfRuntimePlugins/resolve-entry-ipv4.js"), runtimePlugins);
139
140
  }
140
141
  if (isServer) {
142
+ injectRuntimePlugins(require.resolve("@module-federation/node/runtimePlugin"), runtimePlugins);
141
143
  if (isDev) {
142
144
  injectRuntimePlugins(require.resolve("@module-federation/node/record-dynamic-remote-entry-hash-plugin"), runtimePlugins);
143
145
  }
@@ -168,11 +170,43 @@ const patchMFConfig = (mfConfig, isServer, remoteIpStrategy) => {
168
170
  mfConfig.dev = false;
169
171
  return mfConfig;
170
172
  };
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
+ }
171
187
  function patchBundlerConfig(options) {
172
188
  var _modernjsConfig_server, _bundlerConfig_optimization, _bundlerConfig_optimization1, _bundlerConfig_output, _modernjsConfig_deploy;
173
189
  const { bundlerConfig, modernjsConfig, isServer, mfConfig } = options;
174
190
  const enableSSR = Boolean((_modernjsConfig_server = modernjsConfig.server) === null || _modernjsConfig_server === void 0 ? void 0 : _modernjsConfig_server.ssr);
175
191
  (_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
+ }
176
210
  if (bundlerConfig.output) {
177
211
  var _bundlerConfig_output1, _bundlerConfig_output2;
178
212
  if (!((_bundlerConfig_output1 = bundlerConfig.output) === null || _bundlerConfig_output1 === void 0 ? void 0 : _bundlerConfig_output1.chunkLoadingGlobal)) {
@@ -290,5 +324,6 @@ function autoDeleteSplitChunkCacheGroups(mfConfig, bundlerConfig) {
290
324
  getIPV4,
291
325
  getMFConfig,
292
326
  patchBundlerConfig,
327
+ patchIgnoreWarning,
293
328
  patchMFConfig
294
329
  });
@@ -61,6 +61,7 @@ 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"),
64
65
  import_path.default.resolve(__dirname, "./mfRuntimePlugins/inject-node-fetch.js")
65
66
  ],
66
67
  shared: {
@@ -128,13 +129,20 @@ const mfConfig = {
128
129
  },
129
130
  mfConfig
130
131
  });
131
- (0, import_vitest.expect)(bundlerConfig).toStrictEqual({
132
+ const expectedConfig = {
132
133
  output: {
133
134
  chunkLoadingGlobal: "chunk_host",
134
135
  publicPath: "auto",
135
136
  uniqueName: "host"
137
+ },
138
+ watchOptions: {
139
+ ignored: [
140
+ "@mf-types"
141
+ ]
136
142
  }
137
- });
143
+ };
144
+ bundlerConfig === null || bundlerConfig === void 0 ? true : delete bundlerConfig.ignoreWarnings;
145
+ (0, import_vitest.expect)(bundlerConfig).toStrictEqual(expectedConfig);
138
146
  });
139
147
  (0, import_vitest.it)("patchBundlerConfig: client", async () => {
140
148
  const bundlerConfig = {
@@ -154,12 +162,19 @@ const mfConfig = {
154
162
  },
155
163
  mfConfig
156
164
  });
157
- (0, import_vitest.expect)(bundlerConfig).toStrictEqual({
165
+ const expectedConfig = {
158
166
  output: {
159
167
  chunkLoadingGlobal: "chunk_host",
160
168
  publicPath: "auto",
161
169
  uniqueName: "host"
170
+ },
171
+ watchOptions: {
172
+ ignored: [
173
+ "@mf-types"
174
+ ]
162
175
  }
163
- });
176
+ };
177
+ bundlerConfig === null || bundlerConfig === void 0 ? true : delete bundlerConfig.ignoreWarnings;
178
+ (0, import_vitest.expect)(bundlerConfig).toStrictEqual(expectedConfig);
164
179
  });
165
180
  });
@@ -0,0 +1,32 @@
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
+ };
@@ -17,15 +17,6 @@ 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
- }
29
20
  }
30
21
  var moduleFederationConfigPlugin = function(userConfig) {
31
22
  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 { StreamingTargetPlugin, EntryChunkTrackerPlugin } from "@module-federation/node";
6
+ import { ModuleFederationPlugin as RspackModuleFederationPlugin } from "@module-federation/enhanced/rspack";
7
+ import { EntryChunkTrackerPlugin } from "@module-federation/node";
7
8
  import { updateStatsAndManifest } from "./manifest";
8
- import { MODERN_JS_SERVER_DIR, 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, _modernjsConfig_server, modernjsConfig, enableSSR;
23
+ var useConfigContext, useAppContext, _modernjsConfig_server, modernjsConfig, enableSSR;
24
24
  return _ts_generator(this, function(_state) {
25
- useConfigContext = param.useConfigContext;
25
+ useConfigContext = param.useConfigContext, useAppContext = param.useAppContext;
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,30 +54,40 @@ 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;
57
58
  return _ts_generator(this, function(_state2) {
59
+ bundlerType = useAppContext().bundlerType === "rspack" ? "rspack" : "webpack";
58
60
  return [
59
61
  2,
60
62
  {
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
+ },
61
66
  tools: {
62
67
  rspack: function rspack(config, param2) {
63
68
  var isServer = param2.isServer;
64
69
  if (isServer) {
65
- throw new Error("".concat(PLUGIN_IDENTIFIER, " Not support rspack ssr mode yet !"));
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");
66
78
  }
67
79
  },
68
80
  webpack: function webpack(config, param2) {
69
81
  var isServer = param2.isServer;
70
82
  if (isServer) {
71
- var _config_plugins;
72
83
  if (!userConfig.nodePlugin) {
73
- var _config_plugins1;
84
+ var _config_plugins;
74
85
  userConfig.nodePlugin = new ModuleFederationPlugin(userConfig.ssrConfig);
75
- (_config_plugins1 = config.plugins) === null || _config_plugins1 === void 0 ? void 0 : _config_plugins1.push(userConfig.nodePlugin);
86
+ (_config_plugins = config.plugins) === null || _config_plugins === void 0 ? void 0 : _config_plugins.push(userConfig.nodePlugin);
76
87
  }
77
- (_config_plugins = config.plugins) === null || _config_plugins === void 0 ? void 0 : _config_plugins.push(new StreamingTargetPlugin(userConfig.nodePlugin));
78
88
  if (isDev) {
79
- var _config_plugins2;
80
- (_config_plugins2 = config.plugins) === null || _config_plugins2 === void 0 ? void 0 : _config_plugins2.push(new EntryChunkTrackerPlugin());
89
+ var _config_plugins1;
90
+ (_config_plugins1 = config.plugins) === null || _config_plugins1 === void 0 ? void 0 : _config_plugins1.push(new EntryChunkTrackerPlugin());
81
91
  }
82
92
  } else {
83
93
  var _config_output;
@@ -92,9 +102,8 @@ var moduleFederationSSRPlugin = function(userConfig) {
92
102
  return;
93
103
  }
94
104
  try {
95
- var _req_url, _req_url1, _req_url2;
96
- var SERVER_PREFIX = "/".concat(MODERN_JS_SERVER_DIR);
97
- if (((_req_url = req.url) === null || _req_url === void 0 ? void 0 : _req_url.startsWith(SERVER_PREFIX)) || ((_req_url1 = req.url) === null || _req_url1 === void 0 ? void 0 : _req_url1.includes(".json")) && !((_req_url2 = req.url) === null || _req_url2 === void 0 ? void 0 : _req_url2.includes("hot-update"))) {
105
+ var _req_url, _req_url1;
106
+ if (((_req_url = req.url) === null || _req_url === void 0 ? void 0 : _req_url.includes(".json")) && !((_req_url1 = req.url) === null || _req_url1 === void 0 ? void 0 : _req_url1.includes("hot-update"))) {
98
107
  var filepath = path.join(process.cwd(), "dist".concat(req.url));
99
108
  fs.statSync(filepath);
100
109
  res.setHeader("Access-Control-Allow-Origin", "*");
@@ -115,6 +124,9 @@ var moduleFederationSSRPlugin = function(userConfig) {
115
124
  },
116
125
  bundlerChain: function bundlerChain(chain, param2) {
117
126
  var isServer = param2.isServer;
127
+ if (isServer) {
128
+ chain.target("async-node");
129
+ }
118
130
  if (isDev && !isServer) {
119
131
  chain.externals({
120
132
  "@module-federation/node/utils": "NOT_USED_IN_BROWSER"
@@ -132,6 +132,7 @@ 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);
135
136
  if (isDev) {
136
137
  injectRuntimePlugins(require.resolve("@module-federation/node/record-dynamic-remote-entry-hash-plugin"), runtimePlugins);
137
138
  }
@@ -162,11 +163,45 @@ var patchMFConfig = function(mfConfig, isServer, remoteIpStrategy) {
162
163
  mfConfig.dev = false;
163
164
  return mfConfig;
164
165
  };
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
+ }
165
182
  function patchBundlerConfig(options) {
166
183
  var _modernjsConfig_server, _bundlerConfig_optimization, _bundlerConfig_optimization1, _bundlerConfig_output, _modernjsConfig_deploy;
167
184
  var bundlerConfig = options.bundlerConfig, modernjsConfig = options.modernjsConfig, isServer = options.isServer, mfConfig = options.mfConfig;
168
185
  var enableSSR = Boolean((_modernjsConfig_server = modernjsConfig.server) === null || _modernjsConfig_server === void 0 ? void 0 : _modernjsConfig_server.ssr);
169
186
  (_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
+ }
170
205
  if (bundlerConfig.output) {
171
206
  var _bundlerConfig_output1, _bundlerConfig_output2;
172
207
  if (!((_bundlerConfig_output1 = bundlerConfig.output) === null || _bundlerConfig_output1 === void 0 ? void 0 : _bundlerConfig_output1.chunkLoadingGlobal)) {
@@ -299,5 +334,6 @@ export {
299
334
  getIPV4,
300
335
  getMFConfig,
301
336
  patchBundlerConfig,
337
+ patchIgnoreWarning,
302
338
  patchMFConfig
303
339
  };
@@ -43,6 +43,7 @@ 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"),
46
47
  path.resolve(__dirname, "./mfRuntimePlugins/inject-node-fetch.js")
47
48
  ],
48
49
  shared: {
@@ -108,7 +109,7 @@ describe("patchMFConfig", /* @__PURE__ */ _async_to_generator(function() {
108
109
  describe("patchBundlerConfig", /* @__PURE__ */ _async_to_generator(function() {
109
110
  return _ts_generator(this, function(_state) {
110
111
  it("patchBundlerConfig: server", /* @__PURE__ */ _async_to_generator(function() {
111
- var bundlerConfig;
112
+ var bundlerConfig, expectedConfig;
112
113
  return _ts_generator(this, function(_state2) {
113
114
  bundlerConfig = {
114
115
  output: {
@@ -127,20 +128,27 @@ describe("patchBundlerConfig", /* @__PURE__ */ _async_to_generator(function() {
127
128
  },
128
129
  mfConfig
129
130
  });
130
- expect(bundlerConfig).toStrictEqual({
131
+ expectedConfig = {
131
132
  output: {
132
133
  chunkLoadingGlobal: "chunk_host",
133
134
  publicPath: "auto",
134
135
  uniqueName: "host"
136
+ },
137
+ watchOptions: {
138
+ ignored: [
139
+ "@mf-types"
140
+ ]
135
141
  }
136
- });
142
+ };
143
+ bundlerConfig === null || bundlerConfig === void 0 ? true : delete bundlerConfig.ignoreWarnings;
144
+ expect(bundlerConfig).toStrictEqual(expectedConfig);
137
145
  return [
138
146
  2
139
147
  ];
140
148
  });
141
149
  }));
142
150
  it("patchBundlerConfig: client", /* @__PURE__ */ _async_to_generator(function() {
143
- var bundlerConfig;
151
+ var bundlerConfig, expectedConfig;
144
152
  return _ts_generator(this, function(_state2) {
145
153
  bundlerConfig = {
146
154
  output: {
@@ -159,13 +167,20 @@ describe("patchBundlerConfig", /* @__PURE__ */ _async_to_generator(function() {
159
167
  },
160
168
  mfConfig
161
169
  });
162
- expect(bundlerConfig).toStrictEqual({
170
+ expectedConfig = {
163
171
  output: {
164
172
  chunkLoadingGlobal: "chunk_host",
165
173
  publicPath: "auto",
166
174
  uniqueName: "host"
175
+ },
176
+ watchOptions: {
177
+ ignored: [
178
+ "@mf-types"
179
+ ]
167
180
  }
168
- });
181
+ };
182
+ bundlerConfig === null || bundlerConfig === void 0 ? true : delete bundlerConfig.ignoreWarnings;
183
+ expect(bundlerConfig).toStrictEqual(expectedConfig);
169
184
  return [
170
185
  2
171
186
  ];
@@ -0,0 +1,26 @@
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
+ };
@@ -15,15 +15,6 @@ 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
- }
27
18
  }
28
19
  const moduleFederationConfigPlugin = (userConfig) => ({
29
20
  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 { StreamingTargetPlugin, EntryChunkTrackerPlugin } from "@module-federation/node";
4
+ import { ModuleFederationPlugin as RspackModuleFederationPlugin } from "@module-federation/enhanced/rspack";
5
+ import { EntryChunkTrackerPlugin } from "@module-federation/node";
5
6
  import { updateStatsAndManifest } from "./manifest";
6
- import { MODERN_JS_SERVER_DIR, 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 }) => {
18
+ setup: async ({ useConfigContext, useAppContext }) => {
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,25 +42,36 @@ 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;
45
48
  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
+ },
46
52
  tools: {
47
53
  rspack(config, { isServer }) {
48
54
  if (isServer) {
49
- throw new Error(`${PLUGIN_IDENTIFIER} Not support rspack ssr mode yet !`);
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");
50
63
  }
51
64
  },
52
65
  webpack(config, { isServer }) {
53
66
  if (isServer) {
54
- var _config_plugins;
55
67
  if (!userConfig.nodePlugin) {
56
- var _config_plugins1;
68
+ var _config_plugins;
57
69
  userConfig.nodePlugin = new ModuleFederationPlugin(userConfig.ssrConfig);
58
- (_config_plugins1 = config.plugins) === null || _config_plugins1 === void 0 ? void 0 : _config_plugins1.push(userConfig.nodePlugin);
70
+ (_config_plugins = config.plugins) === null || _config_plugins === void 0 ? void 0 : _config_plugins.push(userConfig.nodePlugin);
59
71
  }
60
- (_config_plugins = config.plugins) === null || _config_plugins === void 0 ? void 0 : _config_plugins.push(new StreamingTargetPlugin(userConfig.nodePlugin));
61
72
  if (isDev) {
62
- var _config_plugins2;
63
- (_config_plugins2 = config.plugins) === null || _config_plugins2 === void 0 ? void 0 : _config_plugins2.push(new EntryChunkTrackerPlugin());
73
+ var _config_plugins1;
74
+ (_config_plugins1 = config.plugins) === null || _config_plugins1 === void 0 ? void 0 : _config_plugins1.push(new EntryChunkTrackerPlugin());
64
75
  }
65
76
  } else {
66
77
  var _config_output;
@@ -75,9 +86,8 @@ const moduleFederationSSRPlugin = (userConfig) => ({
75
86
  return;
76
87
  }
77
88
  try {
78
- var _req_url, _req_url1, _req_url2;
79
- const SERVER_PREFIX = `/${MODERN_JS_SERVER_DIR}`;
80
- if (((_req_url = req.url) === null || _req_url === void 0 ? void 0 : _req_url.startsWith(SERVER_PREFIX)) || ((_req_url1 = req.url) === null || _req_url1 === void 0 ? void 0 : _req_url1.includes(".json")) && !((_req_url2 = req.url) === null || _req_url2 === void 0 ? void 0 : _req_url2.includes("hot-update"))) {
89
+ var _req_url, _req_url1;
90
+ if (((_req_url = req.url) === null || _req_url === void 0 ? void 0 : _req_url.includes(".json")) && !((_req_url1 = req.url) === null || _req_url1 === void 0 ? void 0 : _req_url1.includes("hot-update"))) {
81
91
  const filepath = path.join(process.cwd(), `dist${req.url}`);
82
92
  fs.statSync(filepath);
83
93
  res.setHeader("Access-Control-Allow-Origin", "*");
@@ -97,6 +107,9 @@ const moduleFederationSSRPlugin = (userConfig) => ({
97
107
  ]
98
108
  },
99
109
  bundlerChain(chain, { isServer }) {
110
+ if (isServer) {
111
+ chain.target("async-node");
112
+ }
100
113
  if (isDev && !isServer) {
101
114
  chain.externals({
102
115
  "@module-federation/node/utils": "NOT_USED_IN_BROWSER"
@@ -102,6 +102,7 @@ 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);
105
106
  if (isDev) {
106
107
  injectRuntimePlugins(require.resolve("@module-federation/node/record-dynamic-remote-entry-hash-plugin"), runtimePlugins);
107
108
  }
@@ -132,11 +133,43 @@ const patchMFConfig = (mfConfig, isServer, remoteIpStrategy) => {
132
133
  mfConfig.dev = false;
133
134
  return mfConfig;
134
135
  };
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
+ }
135
150
  function patchBundlerConfig(options) {
136
151
  var _modernjsConfig_server, _bundlerConfig_optimization, _bundlerConfig_optimization1, _bundlerConfig_output, _modernjsConfig_deploy;
137
152
  const { bundlerConfig, modernjsConfig, isServer, mfConfig } = options;
138
153
  const enableSSR = Boolean((_modernjsConfig_server = modernjsConfig.server) === null || _modernjsConfig_server === void 0 ? void 0 : _modernjsConfig_server.ssr);
139
154
  (_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
+ }
140
173
  if (bundlerConfig.output) {
141
174
  var _bundlerConfig_output1, _bundlerConfig_output2;
142
175
  if (!((_bundlerConfig_output1 = bundlerConfig.output) === null || _bundlerConfig_output1 === void 0 ? void 0 : _bundlerConfig_output1.chunkLoadingGlobal)) {
@@ -253,5 +286,6 @@ export {
253
286
  getIPV4,
254
287
  getMFConfig,
255
288
  patchBundlerConfig,
289
+ patchIgnoreWarning,
256
290
  patchMFConfig
257
291
  };
@@ -38,6 +38,7 @@ 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"),
41
42
  path.resolve(__dirname, "./mfRuntimePlugins/inject-node-fetch.js")
42
43
  ],
43
44
  shared: {
@@ -105,13 +106,20 @@ describe("patchBundlerConfig", async () => {
105
106
  },
106
107
  mfConfig
107
108
  });
108
- expect(bundlerConfig).toStrictEqual({
109
+ const expectedConfig = {
109
110
  output: {
110
111
  chunkLoadingGlobal: "chunk_host",
111
112
  publicPath: "auto",
112
113
  uniqueName: "host"
114
+ },
115
+ watchOptions: {
116
+ ignored: [
117
+ "@mf-types"
118
+ ]
113
119
  }
114
- });
120
+ };
121
+ bundlerConfig === null || bundlerConfig === void 0 ? true : delete bundlerConfig.ignoreWarnings;
122
+ expect(bundlerConfig).toStrictEqual(expectedConfig);
115
123
  });
116
124
  it("patchBundlerConfig: client", async () => {
117
125
  const bundlerConfig = {
@@ -131,12 +139,19 @@ describe("patchBundlerConfig", async () => {
131
139
  },
132
140
  mfConfig
133
141
  });
134
- expect(bundlerConfig).toStrictEqual({
142
+ const expectedConfig = {
135
143
  output: {
136
144
  chunkLoadingGlobal: "chunk_host",
137
145
  publicPath: "auto",
138
146
  uniqueName: "host"
147
+ },
148
+ watchOptions: {
149
+ ignored: [
150
+ "@mf-types"
151
+ ]
139
152
  }
140
- });
153
+ };
154
+ bundlerConfig === null || bundlerConfig === void 0 ? true : delete bundlerConfig.ignoreWarnings;
155
+ expect(bundlerConfig).toStrictEqual(expectedConfig);
141
156
  });
142
157
  });
@@ -0,0 +1,5 @@
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
+ }
@@ -5,6 +5,7 @@ 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;
8
9
  export declare function patchBundlerConfig<T extends Bundler>(options: {
9
10
  bundlerConfig: BundlerConfig<T>;
10
11
  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-20240718061842",
3
+ "version": "0.0.0-next-20240724103050",
4
4
  "files": [
5
5
  "dist/",
6
6
  "types.d.ts",
@@ -61,18 +61,18 @@
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-20240718061842",
65
- "@module-federation/enhanced": "0.0.0-next-20240718061842",
66
- "@module-federation/node": "0.0.0-next-20240718061842"
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"
67
67
  },
68
68
  "devDependencies": {
69
69
  "@types/hoist-non-react-statics": "3.3.2",
70
- "@modern-js/app-tools": "^2.55.0",
71
- "@modern-js/core": "^2.55.0",
72
- "@modern-js/runtime": "^2.55.0",
73
- "@modern-js/module-tools": "^2.55.0",
74
- "@modern-js/tsconfig": "^2.55.0",
75
- "@module-federation/manifest": "0.0.0-next-20240718061842"
70
+ "@modern-js/app-tools": "2.56.1",
71
+ "@modern-js/core": "2.56.1",
72
+ "@modern-js/runtime": "2.56.1",
73
+ "@modern-js/module-tools": "2.56.1",
74
+ "@modern-js/tsconfig": "2.56.1",
75
+ "@module-federation/manifest": "0.0.0-next-20240724103050"
76
76
  },
77
77
  "peerDependencies": {
78
78
  "react": ">=17",