@module-federation/modern-js 0.0.0-next-20250924123930 → 0.0.0-perf-devtools-20260106124142

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (115) hide show
  1. package/dist/cjs/cli/configPlugin.js +301 -363
  2. package/dist/cjs/cli/index.js +103 -91
  3. package/dist/cjs/cli/mfRuntimePlugins/inject-node-fetch.js +51 -41
  4. package/dist/cjs/cli/mfRuntimePlugins/resolve-entry-ipv4.js +73 -75
  5. package/dist/cjs/cli/mfRuntimePlugins/shared-strategy.js +50 -40
  6. package/dist/cjs/cli/server/data-fetch-server-plugin.js +55 -44
  7. package/dist/cjs/cli/ssrPlugin.js +270 -222
  8. package/dist/cjs/cli/utils.js +84 -81
  9. package/dist/cjs/constant.js +37 -28
  10. package/dist/cjs/interfaces/bundler.js +17 -15
  11. package/dist/cjs/logger.js +37 -25
  12. package/dist/cjs/react/index.js +55 -19
  13. package/dist/cjs/react/plugin.js +65 -0
  14. package/dist/cjs/react/v18.js +58 -0
  15. package/dist/cjs/react/v19.js +58 -0
  16. package/dist/cjs/runtime/index.js +55 -19
  17. package/dist/cjs/server/fileCache.js +76 -76
  18. package/dist/cjs/server/index.js +65 -57
  19. package/dist/cjs/server/staticMiddleware.js +84 -84
  20. package/dist/cjs/ssr-runtime/SSRLiveReload.js +40 -34
  21. package/dist/cjs/ssr-runtime/devPlugin.js +63 -67
  22. package/dist/cjs/ssr-runtime/injectDataFetchFunctionPlugin.js +44 -36
  23. package/dist/cjs/types/index.js +17 -15
  24. package/dist/esm/cli/configPlugin.mjs +305 -0
  25. package/dist/esm/cli/index.mjs +83 -0
  26. package/dist/esm/cli/mfRuntimePlugins/inject-node-fetch.mjs +12 -0
  27. package/dist/esm/cli/mfRuntimePlugins/resolve-entry-ipv4.mjs +58 -0
  28. package/dist/esm/cli/mfRuntimePlugins/shared-strategy.mjs +21 -0
  29. package/dist/esm/cli/server/data-fetch-server-plugin.mjs +17 -0
  30. package/dist/esm/cli/ssrPlugin.mjs +254 -0
  31. package/dist/esm/cli/utils.mjs +40 -0
  32. package/dist/esm/constant.mjs +3 -0
  33. package/dist/esm/logger.mjs +5 -0
  34. package/dist/esm/react/plugin.mjs +3 -0
  35. package/dist/esm/react/v18.mjs +1 -0
  36. package/dist/esm/react/v19.mjs +1 -0
  37. package/dist/esm/server/fileCache.mjs +90 -0
  38. package/dist/esm/server/index.mjs +36 -0
  39. package/dist/esm/server/staticMiddleware.mjs +87 -0
  40. package/dist/esm/ssr-runtime/SSRLiveReload.mjs +22 -0
  41. package/dist/esm/ssr-runtime/devPlugin.mjs +70 -0
  42. package/dist/esm/ssr-runtime/injectDataFetchFunctionPlugin.mjs +34 -0
  43. package/dist/esm-node/cli/configPlugin.mjs +263 -0
  44. package/dist/esm-node/cli/index.mjs +67 -0
  45. package/dist/esm-node/cli/mfRuntimePlugins/inject-node-fetch.mjs +10 -0
  46. package/dist/esm-node/cli/mfRuntimePlugins/resolve-entry-ipv4.mjs +46 -0
  47. package/dist/esm-node/cli/mfRuntimePlugins/shared-strategy.mjs +19 -0
  48. package/dist/esm-node/cli/server/data-fetch-server-plugin.mjs +15 -0
  49. package/dist/esm-node/cli/ssrPlugin.mjs +228 -0
  50. package/dist/esm-node/cli/utils.mjs +40 -0
  51. package/dist/esm-node/constant.mjs +3 -0
  52. package/dist/esm-node/logger.mjs +5 -0
  53. package/dist/esm-node/react/plugin.mjs +3 -0
  54. package/dist/esm-node/react/v18.mjs +1 -0
  55. package/dist/esm-node/react/v19.mjs +1 -0
  56. package/dist/esm-node/server/fileCache.mjs +37 -0
  57. package/dist/esm-node/server/index.mjs +34 -0
  58. package/dist/esm-node/server/staticMiddleware.mjs +42 -0
  59. package/dist/esm-node/ssr-runtime/SSRLiveReload.mjs +15 -0
  60. package/dist/esm-node/ssr-runtime/devPlugin.mjs +33 -0
  61. package/dist/esm-node/ssr-runtime/injectDataFetchFunctionPlugin.mjs +14 -0
  62. package/dist/types/react/plugin.d.ts +2 -0
  63. package/dist/types/react/v18.d.ts +1 -0
  64. package/dist/types/react/v19.d.ts +1 -0
  65. package/dist/types/types/index.d.ts +13 -0
  66. package/package.json +59 -29
  67. package/dist/cjs/cli/configPlugin.spec.js +0 -112
  68. package/dist/cjs/server/fileCache.spec.js +0 -28
  69. package/dist/cjs/server/staticMiddleware.spec.js +0 -185
  70. package/dist/esm/cli/configPlugin.js +0 -401
  71. package/dist/esm/cli/configPlugin.spec.js +0 -108
  72. package/dist/esm/cli/index.js +0 -90
  73. package/dist/esm/cli/mfRuntimePlugins/inject-node-fetch.js +0 -16
  74. package/dist/esm/cli/mfRuntimePlugins/resolve-entry-ipv4.js +0 -74
  75. package/dist/esm/cli/mfRuntimePlugins/shared-strategy.js +0 -25
  76. package/dist/esm/cli/server/data-fetch-server-plugin.js +0 -20
  77. package/dist/esm/cli/ssrPlugin.js +0 -219
  78. package/dist/esm/cli/utils.js +0 -53
  79. package/dist/esm/constant.js +0 -6
  80. package/dist/esm/logger.js +0 -7
  81. package/dist/esm/server/fileCache.js +0 -98
  82. package/dist/esm/server/fileCache.spec.js +0 -50
  83. package/dist/esm/server/index.js +0 -41
  84. package/dist/esm/server/staticMiddleware.js +0 -104
  85. package/dist/esm/server/staticMiddleware.spec.js +0 -328
  86. package/dist/esm/ssr-runtime/SSRLiveReload.js +0 -26
  87. package/dist/esm/ssr-runtime/devPlugin.js +0 -73
  88. package/dist/esm/ssr-runtime/injectDataFetchFunctionPlugin.js +0 -34
  89. package/dist/esm-node/cli/configPlugin.js +0 -353
  90. package/dist/esm-node/cli/configPlugin.spec.js +0 -89
  91. package/dist/esm-node/cli/index.js +0 -70
  92. package/dist/esm-node/cli/mfRuntimePlugins/inject-node-fetch.js +0 -14
  93. package/dist/esm-node/cli/mfRuntimePlugins/resolve-entry-ipv4.js +0 -62
  94. package/dist/esm-node/cli/mfRuntimePlugins/shared-strategy.js +0 -23
  95. package/dist/esm-node/cli/server/data-fetch-server-plugin.js +0 -18
  96. package/dist/esm-node/cli/ssrPlugin.js +0 -200
  97. package/dist/esm-node/cli/utils.js +0 -53
  98. package/dist/esm-node/constant.js +0 -6
  99. package/dist/esm-node/logger.js +0 -7
  100. package/dist/esm-node/server/fileCache.js +0 -49
  101. package/dist/esm-node/server/fileCache.spec.js +0 -27
  102. package/dist/esm-node/server/index.js +0 -39
  103. package/dist/esm-node/server/staticMiddleware.js +0 -55
  104. package/dist/esm-node/server/staticMiddleware.spec.js +0 -162
  105. package/dist/esm-node/ssr-runtime/SSRLiveReload.js +0 -19
  106. package/dist/esm-node/ssr-runtime/devPlugin.js +0 -37
  107. package/dist/esm-node/ssr-runtime/injectDataFetchFunctionPlugin.js +0 -16
  108. /package/dist/esm/interfaces/{bundler.js → bundler.mjs} +0 -0
  109. /package/dist/esm/react/{index.js → index.mjs} +0 -0
  110. /package/dist/esm/runtime/{index.js → index.mjs} +0 -0
  111. /package/dist/esm/types/{index.js → index.mjs} +0 -0
  112. /package/dist/esm-node/interfaces/{bundler.js → bundler.mjs} +0 -0
  113. /package/dist/esm-node/react/{index.js → index.mjs} +0 -0
  114. /package/dist/esm-node/runtime/{index.js → index.mjs} +0 -0
  115. /package/dist/esm-node/types/{index.js → index.mjs} +0 -0
@@ -1,48 +1,59 @@
1
1
  "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var data_fetch_server_plugin_exports = {};
30
- __export(data_fetch_server_plugin_exports, {
31
- default: () => data_fetch_server_plugin_default
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
+ (()=>{
13
+ __webpack_require__.d = (exports1, definition)=>{
14
+ for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
15
+ enumerable: true,
16
+ get: definition[key]
17
+ });
18
+ };
19
+ })();
20
+ (()=>{
21
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
22
+ })();
23
+ (()=>{
24
+ __webpack_require__.r = (exports1)=>{
25
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
26
+ value: 'Module'
27
+ });
28
+ Object.defineProperty(exports1, '__esModule', {
29
+ value: true
30
+ });
31
+ };
32
+ })();
33
+ var __webpack_exports__ = {};
34
+ __webpack_require__.r(__webpack_exports__);
35
+ __webpack_require__.d(__webpack_exports__, {
36
+ default: ()=>data_fetch_server_plugin
32
37
  });
33
- module.exports = __toCommonJS(data_fetch_server_plugin_exports);
34
- var import_data_fetch_server_middleware = __toESM(require("@module-federation/bridge-react/data-fetch-server-middleware"));
35
- const dataFetchServePlugin = () => ({
36
- name: "mf-data-fetch-server-plugin",
37
- setup: (api) => {
38
- api.onPrepare(() => {
39
- const { middlewares } = api.getServerContext();
40
- middlewares.push({
41
- name: "module-federation-serve-manifest",
42
- // @ts-ignore type error
43
- handler: import_data_fetch_server_middleware.default
44
- });
38
+ const data_fetch_server_middleware_namespaceObject = require("@module-federation/bridge-react/data-fetch-server-middleware");
39
+ var data_fetch_server_middleware_default = /*#__PURE__*/ __webpack_require__.n(data_fetch_server_middleware_namespaceObject);
40
+ const dataFetchServePlugin = ()=>({
41
+ name: 'mf-data-fetch-server-plugin',
42
+ setup: (api)=>{
43
+ api.onPrepare(()=>{
44
+ const { middlewares } = api.getServerContext();
45
+ middlewares.push({
46
+ name: 'module-federation-serve-manifest',
47
+ handler: data_fetch_server_middleware_default()
48
+ });
49
+ });
50
+ }
45
51
  });
46
- }
52
+ const data_fetch_server_plugin = dataFetchServePlugin;
53
+ exports["default"] = __webpack_exports__["default"];
54
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
55
+ "default"
56
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
57
+ Object.defineProperty(exports, '__esModule', {
58
+ value: true
47
59
  });
48
- var data_fetch_server_plugin_default = dataFetchServePlugin;
@@ -1,236 +1,284 @@
1
1
  "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var ssrPlugin_exports = {};
30
- __export(ssrPlugin_exports, {
31
- CHAIN_MF_PLUGIN_ID: () => CHAIN_MF_PLUGIN_ID,
32
- default: () => ssrPlugin_default,
33
- moduleFederationSSRPlugin: () => moduleFederationSSRPlugin,
34
- setEnv: () => setEnv
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
+ (()=>{
13
+ __webpack_require__.d = (exports1, definition)=>{
14
+ for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
15
+ enumerable: true,
16
+ get: definition[key]
17
+ });
18
+ };
19
+ })();
20
+ (()=>{
21
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
22
+ })();
23
+ (()=>{
24
+ __webpack_require__.r = (exports1)=>{
25
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
26
+ value: 'Module'
27
+ });
28
+ Object.defineProperty(exports1, '__esModule', {
29
+ value: true
30
+ });
31
+ };
32
+ })();
33
+ var __webpack_exports__ = {};
34
+ __webpack_require__.r(__webpack_exports__);
35
+ __webpack_require__.d(__webpack_exports__, {
36
+ default: ()=>ssrPlugin,
37
+ moduleFederationSSRPlugin: ()=>moduleFederationSSRPlugin,
38
+ setEnv: ()=>setEnv,
39
+ CHAIN_MF_PLUGIN_ID: ()=>CHAIN_MF_PLUGIN_ID
35
40
  });
36
- module.exports = __toCommonJS(ssrPlugin_exports);
37
- var import_path = __toESM(require("path"));
38
- var import_fs_extra = __toESM(require("fs-extra"));
39
- var import_webpack = require("@module-federation/enhanced/webpack");
40
- var import_rspack = require("@module-federation/enhanced/rspack");
41
- var import_universe_entry_chunk_tracker_plugin = __toESM(require("@module-federation/node/universe-entry-chunk-tracker-plugin"));
42
- var import_logger = __toESM(require("../logger"));
43
- var import_utils = require("./utils");
44
- var import_utils2 = require("@module-federation/rsbuild-plugin/utils");
45
- var import_utils3 = require("./utils");
41
+ const external_path_namespaceObject = require("path");
42
+ var external_path_default = /*#__PURE__*/ __webpack_require__.n(external_path_namespaceObject);
43
+ const external_fs_extra_namespaceObject = require("fs-extra");
44
+ var external_fs_extra_default = /*#__PURE__*/ __webpack_require__.n(external_fs_extra_namespaceObject);
45
+ const webpack_namespaceObject = require("@module-federation/enhanced/webpack");
46
+ const rspack_namespaceObject = require("@module-federation/enhanced/rspack");
47
+ const universe_entry_chunk_tracker_plugin_namespaceObject = require("@module-federation/node/universe-entry-chunk-tracker-plugin");
48
+ var universe_entry_chunk_tracker_plugin_default = /*#__PURE__*/ __webpack_require__.n(universe_entry_chunk_tracker_plugin_namespaceObject);
49
+ const external_logger_js_namespaceObject = require("../logger.js");
50
+ var external_logger_js_default = /*#__PURE__*/ __webpack_require__.n(external_logger_js_namespaceObject);
51
+ const external_utils_js_namespaceObject = require("./utils.js");
52
+ const utils_namespaceObject = require("@module-federation/rsbuild-plugin/utils");
53
+ const sdk_namespaceObject = require("@module-federation/sdk");
46
54
  function setEnv() {
47
- process.env["MF_DISABLE_EMIT_STATS"] = "true";
48
- process.env["MF_SSR_PRJ"] = "true";
55
+ process.env['MF_SSR_PRJ'] = 'true';
49
56
  }
50
- const CHAIN_MF_PLUGIN_ID = "plugin-module-federation-server";
51
- const mfSSRRsbuildPlugin = (pluginOptions) => {
52
- return {
53
- name: "@modern-js/plugin-mf-post-config",
54
- pre: [
55
- "@modern-js/builder-plugin-ssr"
56
- ],
57
- setup(api) {
58
- if (pluginOptions.csrConfig.getPublicPath) {
59
- return;
60
- }
61
- let csrOutputPath = "";
62
- let ssrOutputPath = "";
63
- let ssrEnv = "";
64
- api.modifyEnvironmentConfig((config, { name }) => {
65
- const target = config.output.target;
66
- if ((0, import_utils3.skipByTarget)(target)) {
67
- return config;
68
- }
69
- if ((0, import_utils3.isWebTarget)(target)) {
70
- csrOutputPath = config.output.distPath.root;
71
- } else {
72
- ssrOutputPath = config.output.distPath.root;
73
- ssrEnv = name;
74
- }
75
- return config;
76
- });
77
- const modifySSRPublicPath = (config, utils) => {
78
- if (ssrEnv !== utils.environment.name) {
79
- return config;
80
- }
81
- const userSSRConfig = pluginOptions.userConfig.ssr ? typeof pluginOptions.userConfig.ssr === "object" ? pluginOptions.userConfig.ssr : {} : {};
82
- if (userSSRConfig.distOutputDir) {
83
- return;
84
- }
85
- config.output.publicPath = `${config.output.publicPath}${import_path.default.relative(csrOutputPath, ssrOutputPath)}/`;
86
- return config;
87
- };
88
- api.modifyWebpackConfig((config, utils) => {
89
- modifySSRPublicPath(config, utils);
90
- return config;
91
- });
92
- api.modifyRspackConfig((config, utils) => {
93
- modifySSRPublicPath(config, utils);
94
- return config;
95
- });
96
- }
97
- };
98
- };
99
- const moduleFederationSSRPlugin = (pluginOptions) => ({
100
- name: "@modern-js/plugin-module-federation-ssr",
101
- pre: [
102
- "@modern-js/plugin-module-federation-config",
103
- "@modern-js/plugin-module-federation"
104
- ],
105
- setup: async (api) => {
106
- var _pluginOptions_userConfig, _modernjsConfig_server;
107
- const modernjsConfig = api.getConfig();
108
- var _pluginOptions_userConfig_ssr;
109
- const enableSSR = (_pluginOptions_userConfig_ssr = (_pluginOptions_userConfig = pluginOptions.userConfig) === null || _pluginOptions_userConfig === void 0 ? void 0 : _pluginOptions_userConfig.ssr) !== null && _pluginOptions_userConfig_ssr !== void 0 ? _pluginOptions_userConfig_ssr : Boolean(modernjsConfig === null || modernjsConfig === void 0 ? void 0 : (_modernjsConfig_server = modernjsConfig.server) === null || _modernjsConfig_server === void 0 ? void 0 : _modernjsConfig_server.ssr);
110
- if (!enableSSR) {
111
- return;
112
- }
113
- setEnv();
114
- api._internalRuntimePlugins(({ entrypoint, plugins }) => {
115
- const { fetchServerQuery } = pluginOptions;
116
- plugins.push({
117
- name: "injectDataFetchFunction",
118
- path: "@module-federation/modern-js/ssr-inject-data-fetch-function-plugin",
119
- config: {
120
- fetchServerQuery
121
- }
122
- });
123
- if (!(0, import_utils.isDev)()) {
124
- return {
125
- entrypoint,
126
- plugins
127
- };
128
- }
129
- plugins.push({
130
- name: "mfSSRDev",
131
- path: "@module-federation/modern-js/ssr-dev-plugin",
132
- config: {}
133
- });
134
- return {
135
- entrypoint,
136
- plugins
137
- };
138
- });
139
- if (pluginOptions.ssrConfig.remotes) {
140
- api._internalServerPlugins(({ plugins }) => {
141
- plugins.push({
142
- name: "@module-federation/modern-js/data-fetch-server-plugin",
143
- options: {}
144
- });
145
- return {
146
- plugins
147
- };
148
- });
149
- }
150
- api.modifyBundlerChain((chain) => {
151
- const target = chain.get("target");
152
- if ((0, import_utils3.skipByTarget)(target)) {
153
- return;
154
- }
155
- const bundlerType = api.getAppContext().bundlerType === "rspack" ? "rspack" : "webpack";
156
- const MFPlugin = bundlerType === "webpack" ? import_webpack.ModuleFederationPlugin : import_rspack.ModuleFederationPlugin;
157
- const isWeb = (0, import_utils3.isWebTarget)(target);
158
- if (!isWeb) {
159
- if (!chain.plugins.has(CHAIN_MF_PLUGIN_ID)) {
160
- chain.plugin(CHAIN_MF_PLUGIN_ID).use(MFPlugin, [
161
- pluginOptions.ssrConfig
162
- ]).init((Plugin, args) => {
163
- pluginOptions.nodePlugin = new Plugin(args[0]);
164
- return pluginOptions.nodePlugin;
165
- });
166
- }
167
- }
168
- if (!isWeb) {
169
- chain.target("async-node");
170
- if ((0, import_utils.isDev)()) {
171
- chain.plugin("UniverseEntryChunkTrackerPlugin").use(import_universe_entry_chunk_tracker_plugin.default);
172
- }
173
- const userSSRConfig = pluginOptions.userConfig.ssr ? typeof pluginOptions.userConfig.ssr === "object" ? pluginOptions.userConfig.ssr : {} : {};
174
- const publicPath = chain.output.get("publicPath");
175
- if (userSSRConfig.distOutputDir && publicPath) {
176
- chain.output.publicPath(`${publicPath}${userSSRConfig.distOutputDir}/`);
57
+ const CHAIN_MF_PLUGIN_ID = 'plugin-module-federation-server';
58
+ function getManifestAssetFileNames(manifestOption) {
59
+ if (!manifestOption) return {
60
+ statsFileName: sdk_namespaceObject.StatsFileName,
61
+ manifestFileName: sdk_namespaceObject.ManifestFileName
62
+ };
63
+ const JSON_EXT = '.json';
64
+ const filePath = 'boolean' == typeof manifestOption ? '' : manifestOption.filePath || '';
65
+ const baseFileName = 'boolean' == typeof manifestOption ? '' : manifestOption.fileName || '';
66
+ const ensureExt = (name)=>name.endsWith(JSON_EXT) ? name : `${name}${JSON_EXT}`;
67
+ const withSuffix = (name, suffix)=>name.replace(JSON_EXT, `${suffix}${JSON_EXT}`);
68
+ const manifestFileName = baseFileName ? ensureExt(baseFileName) : sdk_namespaceObject.ManifestFileName;
69
+ const statsFileName = baseFileName ? withSuffix(manifestFileName, '-stats') : sdk_namespaceObject.StatsFileName;
70
+ return {
71
+ statsFileName: (0, sdk_namespaceObject.simpleJoinRemoteEntry)(filePath, statsFileName),
72
+ manifestFileName: (0, sdk_namespaceObject.simpleJoinRemoteEntry)(filePath, manifestFileName)
73
+ };
74
+ }
75
+ const mfSSRRsbuildPlugin = (pluginOptions)=>({
76
+ name: '@modern-js/plugin-mf-post-config',
77
+ pre: [
78
+ '@modern-js/builder-plugin-ssr'
79
+ ],
80
+ setup (api) {
81
+ var _pluginOptions_csrConfig, _pluginOptions_assetFileNames, _pluginOptions_ssrConfig;
82
+ if (pluginOptions.csrConfig.getPublicPath) return;
83
+ let csrOutputPath = '';
84
+ let ssrOutputPath = '';
85
+ let ssrEnv = '';
86
+ let csrEnv = '';
87
+ const browserAssetFileNames = pluginOptions.assetFileNames.browser || getManifestAssetFileNames(null == (_pluginOptions_csrConfig = pluginOptions.csrConfig) ? void 0 : _pluginOptions_csrConfig.manifest);
88
+ const nodeAssetFileNames = (null == (_pluginOptions_assetFileNames = pluginOptions.assetFileNames) ? void 0 : _pluginOptions_assetFileNames.node) || getManifestAssetFileNames(null == (_pluginOptions_ssrConfig = pluginOptions.ssrConfig) ? void 0 : _pluginOptions_ssrConfig.manifest);
89
+ const collectAssets = (assets, fileNames, tag)=>{
90
+ const statsAsset = assets[fileNames.statsFileName];
91
+ const manifestAsset = assets[fileNames.manifestFileName];
92
+ if (!statsAsset || !manifestAsset) return;
93
+ try {
94
+ const statsRaw = statsAsset.source();
95
+ const manifestRaw = manifestAsset.source();
96
+ const statsContent = 'string' == typeof statsRaw ? statsRaw : statsRaw.toString();
97
+ const manifestContent = 'string' == typeof manifestRaw ? manifestRaw : manifestRaw.toString();
98
+ return {
99
+ stats: {
100
+ data: JSON.parse(statsContent),
101
+ filename: fileNames.statsFileName
102
+ },
103
+ manifest: {
104
+ data: JSON.parse(manifestContent),
105
+ filename: fileNames.manifestFileName
106
+ }
107
+ };
108
+ } catch (err) {
109
+ const message = err instanceof Error ? err.message : String(err);
110
+ external_logger_js_default().error(`Failed to parse ${tag} manifest assets: ${message}`);
111
+ return;
112
+ }
113
+ };
114
+ api.modifyEnvironmentConfig((config, { name })=>{
115
+ const target = config.output.target;
116
+ if ((0, external_utils_js_namespaceObject.skipByTarget)(target)) return config;
117
+ if ((0, external_utils_js_namespaceObject.isWebTarget)(target)) {
118
+ csrOutputPath = config.output.distPath.root;
119
+ csrEnv = name;
120
+ } else {
121
+ ssrOutputPath = config.output.distPath.root;
122
+ ssrEnv = name;
123
+ }
124
+ return config;
125
+ });
126
+ const modifySSRPublicPath = (config, utils)=>{
127
+ if (ssrEnv !== utils.environment.name) return config;
128
+ const userSSRConfig = pluginOptions.userConfig.ssr ? 'object' == typeof pluginOptions.userConfig.ssr ? pluginOptions.userConfig.ssr : {} : {};
129
+ if (!userSSRConfig.distOutputDir) return;
130
+ config.output.publicPath = `${config.output.publicPath}${external_path_default().relative(csrOutputPath, ssrOutputPath)}/`;
131
+ return config;
132
+ };
133
+ api.modifyWebpackConfig((config, utils)=>{
134
+ modifySSRPublicPath(config, utils);
135
+ return config;
136
+ });
137
+ api.modifyRspackConfig((config, utils)=>{
138
+ modifySSRPublicPath(config, utils);
139
+ return config;
140
+ });
141
+ api.processAssets({
142
+ stage: 'report'
143
+ }, ({ assets, environment: envContext })=>{
144
+ var _pluginOptions_csrConfig, _pluginOptions_ssrConfig;
145
+ const envName = envContext.name;
146
+ if ((null == (_pluginOptions_csrConfig = pluginOptions.csrConfig) ? void 0 : _pluginOptions_csrConfig.manifest) !== false && csrEnv && envName === csrEnv) {
147
+ const browserAssets = collectAssets(assets, browserAssetFileNames, 'browser');
148
+ if (browserAssets) pluginOptions.assetResources.browser = browserAssets;
149
+ }
150
+ if ((null == (_pluginOptions_ssrConfig = pluginOptions.ssrConfig) ? void 0 : _pluginOptions_ssrConfig.manifest) !== false && ssrEnv && envName === ssrEnv) {
151
+ const nodeAssets = collectAssets(assets, nodeAssetFileNames, 'node');
152
+ if (nodeAssets) pluginOptions.assetResources.node = nodeAssets;
153
+ }
154
+ });
177
155
  }
178
- }
179
- if ((0, import_utils.isDev)() && isWeb) {
180
- chain.externals({
181
- "@module-federation/node/utils": "NOT_USED_IN_BROWSER"
182
- });
183
- }
184
156
  });
185
- api.config(() => {
186
- return {
187
- builderPlugins: [
188
- mfSSRRsbuildPlugin(pluginOptions)
157
+ const moduleFederationSSRPlugin = (pluginOptions)=>({
158
+ name: '@modern-js/plugin-module-federation-ssr',
159
+ pre: [
160
+ '@modern-js/plugin-module-federation-config',
161
+ '@modern-js/plugin-module-federation'
189
162
  ],
190
- tools: {
191
- devServer: {
192
- before: [
193
- (req, res, next) => {
194
- if (!enableSSR) {
195
- next();
196
- return;
163
+ setup: async (api)=>{
164
+ var _pluginOptions_userConfig, _modernjsConfig_server;
165
+ const modernjsConfig = api.getConfig();
166
+ var _ref;
167
+ const enableSSR = null != (_ref = null == (_pluginOptions_userConfig = pluginOptions.userConfig) ? void 0 : _pluginOptions_userConfig.ssr) ? _ref : Boolean(null == modernjsConfig ? void 0 : null == (_modernjsConfig_server = modernjsConfig.server) ? void 0 : _modernjsConfig_server.ssr);
168
+ if (!enableSSR) return;
169
+ setEnv();
170
+ api._internalRuntimePlugins(({ entrypoint, plugins })=>{
171
+ const { fetchServerQuery } = pluginOptions;
172
+ plugins.push({
173
+ name: 'injectDataFetchFunction',
174
+ path: '@module-federation/modern-js/ssr-inject-data-fetch-function-plugin',
175
+ config: {
176
+ fetchServerQuery
177
+ }
178
+ });
179
+ if (!(0, external_utils_js_namespaceObject.isDev)()) return {
180
+ entrypoint,
181
+ plugins
182
+ };
183
+ plugins.push({
184
+ name: 'mfSSRDev',
185
+ path: '@module-federation/modern-js/ssr-dev-plugin',
186
+ config: {}
187
+ });
188
+ return {
189
+ entrypoint,
190
+ plugins
191
+ };
192
+ });
193
+ if (pluginOptions.ssrConfig.remotes) api._internalServerPlugins(({ plugins })=>{
194
+ plugins.push({
195
+ name: '@module-federation/modern-js/data-fetch-server-plugin',
196
+ options: {}
197
+ });
198
+ return {
199
+ plugins
200
+ };
201
+ });
202
+ api.modifyBundlerChain((chain)=>{
203
+ const target = chain.get('target');
204
+ if ((0, external_utils_js_namespaceObject.skipByTarget)(target)) return;
205
+ const bundlerType = 'rspack' === api.getAppContext().bundlerType ? 'rspack' : 'webpack';
206
+ const MFPlugin = 'webpack' === bundlerType ? webpack_namespaceObject.ModuleFederationPlugin : rspack_namespaceObject.ModuleFederationPlugin;
207
+ const isWeb = (0, external_utils_js_namespaceObject.isWebTarget)(target);
208
+ if (!isWeb) {
209
+ if (!chain.plugins.has(CHAIN_MF_PLUGIN_ID)) chain.plugin(CHAIN_MF_PLUGIN_ID).use(MFPlugin, [
210
+ pluginOptions.ssrConfig
211
+ ]).init((Plugin, args)=>{
212
+ pluginOptions.nodePlugin = new Plugin(args[0]);
213
+ return pluginOptions.nodePlugin;
214
+ });
215
+ }
216
+ if (!isWeb) {
217
+ chain.target('async-node');
218
+ if ((0, external_utils_js_namespaceObject.isDev)()) chain.plugin('UniverseEntryChunkTrackerPlugin').use(universe_entry_chunk_tracker_plugin_default());
197
219
  }
220
+ if ((0, external_utils_js_namespaceObject.isDev)() && isWeb) chain.externals({
221
+ '@module-federation/node/utils': 'NOT_USED_IN_BROWSER'
222
+ });
223
+ });
224
+ api.config(()=>({
225
+ builderPlugins: [
226
+ mfSSRRsbuildPlugin(pluginOptions)
227
+ ],
228
+ tools: {
229
+ devServer: {
230
+ before: [
231
+ (req, res, next)=>{
232
+ if (!enableSSR) return void next();
233
+ try {
234
+ var _req_url, _req_url1;
235
+ if ((null == (_req_url = req.url) ? void 0 : _req_url.includes('.json')) && !(null == (_req_url1 = req.url) ? void 0 : _req_url1.includes('hot-update'))) {
236
+ const filepath = external_path_default().join(process.cwd(), `dist${req.url}`);
237
+ external_fs_extra_default().statSync(filepath);
238
+ res.setHeader('Access-Control-Allow-Origin', '*');
239
+ res.setHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, PATCH, OPTIONS');
240
+ res.setHeader('Access-Control-Allow-Headers', '*');
241
+ external_fs_extra_default().createReadStream(filepath).pipe(res);
242
+ } else next();
243
+ } catch (err) {
244
+ external_logger_js_default().debug(err);
245
+ next();
246
+ }
247
+ }
248
+ ]
249
+ }
250
+ }
251
+ }));
252
+ const writeMergedManifest = ()=>{
253
+ const { distOutputDir, assetResources } = pluginOptions;
254
+ const browserAssets = assetResources.browser;
255
+ const nodeAssets = assetResources.node;
256
+ if (!distOutputDir || !browserAssets || !nodeAssets) return;
198
257
  try {
199
- var _req_url, _req_url1;
200
- 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"))) {
201
- const filepath = import_path.default.join(process.cwd(), `dist${req.url}`);
202
- import_fs_extra.default.statSync(filepath);
203
- res.setHeader("Access-Control-Allow-Origin", "*");
204
- res.setHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, PATCH, OPTIONS");
205
- res.setHeader("Access-Control-Allow-Headers", "*");
206
- import_fs_extra.default.createReadStream(filepath).pipe(res);
207
- } else {
208
- next();
209
- }
258
+ (0, utils_namespaceObject.updateStatsAndManifest)(nodeAssets, browserAssets, distOutputDir);
210
259
  } catch (err) {
211
- import_logger.default.debug(err);
212
- next();
260
+ external_logger_js_default().error(err);
213
261
  }
214
- }
215
- ]
216
- }
262
+ };
263
+ api.onAfterBuild(()=>{
264
+ writeMergedManifest();
265
+ });
266
+ api.onDevCompileDone(()=>{
267
+ writeMergedManifest();
268
+ });
217
269
  }
218
- };
219
270
  });
220
- api.onAfterBuild(() => {
221
- const { nodePlugin, browserPlugin, distOutputDir } = pluginOptions;
222
- (0, import_utils2.updateStatsAndManifest)(nodePlugin, browserPlugin, distOutputDir);
223
- });
224
- api.onDevCompileDone(() => {
225
- const { nodePlugin, browserPlugin, distOutputDir } = pluginOptions;
226
- (0, import_utils2.updateStatsAndManifest)(nodePlugin, browserPlugin, distOutputDir);
227
- });
228
- }
229
- });
230
- var ssrPlugin_default = moduleFederationSSRPlugin;
231
- // Annotate the CommonJS export names for ESM import in node:
232
- 0 && (module.exports = {
233
- CHAIN_MF_PLUGIN_ID,
234
- moduleFederationSSRPlugin,
235
- setEnv
271
+ const ssrPlugin = moduleFederationSSRPlugin;
272
+ exports.CHAIN_MF_PLUGIN_ID = __webpack_exports__.CHAIN_MF_PLUGIN_ID;
273
+ exports["default"] = __webpack_exports__["default"];
274
+ exports.moduleFederationSSRPlugin = __webpack_exports__.moduleFederationSSRPlugin;
275
+ exports.setEnv = __webpack_exports__.setEnv;
276
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
277
+ "CHAIN_MF_PLUGIN_ID",
278
+ "default",
279
+ "moduleFederationSSRPlugin",
280
+ "setEnv"
281
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
282
+ Object.defineProperty(exports, '__esModule', {
283
+ value: true
236
284
  });