@module-federation/modern-js 0.0.0-next-20250616123529 → 0.0.0-next-20250616203439

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 (90) hide show
  1. package/package.json +12 -30
  2. package/dist/LICENSE +0 -21
  3. package/dist/cjs/cli/configPlugin.js +0 -381
  4. package/dist/cjs/cli/configPlugin.spec.js +0 -114
  5. package/dist/cjs/cli/index.js +0 -95
  6. package/dist/cjs/cli/mfRuntimePlugins/inject-node-fetch.js +0 -44
  7. package/dist/cjs/cli/mfRuntimePlugins/resolve-entry-ipv4.js +0 -82
  8. package/dist/cjs/cli/mfRuntimePlugins/shared-strategy.js +0 -43
  9. package/dist/cjs/cli/server/data-fetch-server-plugin.js +0 -48
  10. package/dist/cjs/cli/ssrPlugin.js +0 -236
  11. package/dist/cjs/cli/utils.js +0 -90
  12. package/dist/cjs/constant.js +0 -31
  13. package/dist/cjs/interfaces/bundler.js +0 -16
  14. package/dist/cjs/logger.js +0 -27
  15. package/dist/cjs/runtime/index.js +0 -78
  16. package/dist/cjs/server/fileCache.js +0 -84
  17. package/dist/cjs/server/fileCache.spec.js +0 -28
  18. package/dist/cjs/server/index.js +0 -58
  19. package/dist/cjs/server/staticMiddleware.js +0 -77
  20. package/dist/cjs/server/staticMiddleware.spec.js +0 -185
  21. package/dist/cjs/ssr-runtime/SSRLiveReload.js +0 -43
  22. package/dist/cjs/ssr-runtime/devPlugin.js +0 -71
  23. package/dist/cjs/ssr-runtime/injectDataFetchFunctionPlugin.js +0 -41
  24. package/dist/cjs/types/index.js +0 -16
  25. package/dist/esm/cli/configPlugin.js +0 -388
  26. package/dist/esm/cli/configPlugin.spec.js +0 -110
  27. package/dist/esm/cli/index.js +0 -90
  28. package/dist/esm/cli/mfRuntimePlugins/inject-node-fetch.js +0 -16
  29. package/dist/esm/cli/mfRuntimePlugins/resolve-entry-ipv4.js +0 -74
  30. package/dist/esm/cli/mfRuntimePlugins/shared-strategy.js +0 -25
  31. package/dist/esm/cli/server/data-fetch-server-plugin.js +0 -20
  32. package/dist/esm/cli/ssrPlugin.js +0 -219
  33. package/dist/esm/cli/utils.js +0 -53
  34. package/dist/esm/constant.js +0 -6
  35. package/dist/esm/interfaces/bundler.js +0 -0
  36. package/dist/esm/logger.js +0 -7
  37. package/dist/esm/runtime/index.js +0 -47
  38. package/dist/esm/server/fileCache.js +0 -98
  39. package/dist/esm/server/fileCache.spec.js +0 -50
  40. package/dist/esm/server/index.js +0 -36
  41. package/dist/esm/server/staticMiddleware.js +0 -81
  42. package/dist/esm/server/staticMiddleware.spec.js +0 -328
  43. package/dist/esm/ssr-runtime/SSRLiveReload.js +0 -26
  44. package/dist/esm/ssr-runtime/devPlugin.js +0 -73
  45. package/dist/esm/ssr-runtime/injectDataFetchFunctionPlugin.js +0 -35
  46. package/dist/esm/types/index.js +0 -0
  47. package/dist/esm-node/cli/configPlugin.js +0 -340
  48. package/dist/esm-node/cli/configPlugin.spec.js +0 -91
  49. package/dist/esm-node/cli/index.js +0 -70
  50. package/dist/esm-node/cli/mfRuntimePlugins/inject-node-fetch.js +0 -14
  51. package/dist/esm-node/cli/mfRuntimePlugins/resolve-entry-ipv4.js +0 -62
  52. package/dist/esm-node/cli/mfRuntimePlugins/shared-strategy.js +0 -23
  53. package/dist/esm-node/cli/server/data-fetch-server-plugin.js +0 -18
  54. package/dist/esm-node/cli/ssrPlugin.js +0 -200
  55. package/dist/esm-node/cli/utils.js +0 -53
  56. package/dist/esm-node/constant.js +0 -6
  57. package/dist/esm-node/interfaces/bundler.js +0 -0
  58. package/dist/esm-node/logger.js +0 -7
  59. package/dist/esm-node/runtime/index.js +0 -41
  60. package/dist/esm-node/server/fileCache.js +0 -49
  61. package/dist/esm-node/server/fileCache.spec.js +0 -27
  62. package/dist/esm-node/server/index.js +0 -34
  63. package/dist/esm-node/server/staticMiddleware.js +0 -43
  64. package/dist/esm-node/server/staticMiddleware.spec.js +0 -162
  65. package/dist/esm-node/ssr-runtime/SSRLiveReload.js +0 -19
  66. package/dist/esm-node/ssr-runtime/devPlugin.js +0 -37
  67. package/dist/esm-node/ssr-runtime/injectDataFetchFunctionPlugin.js +0 -17
  68. package/dist/esm-node/types/index.js +0 -0
  69. package/dist/types/cli/configPlugin.d.ts +0 -21
  70. package/dist/types/cli/configPlugin.spec.d.ts +0 -1
  71. package/dist/types/cli/index.d.ts +0 -6
  72. package/dist/types/cli/mfRuntimePlugins/inject-node-fetch.d.ts +0 -3
  73. package/dist/types/cli/mfRuntimePlugins/resolve-entry-ipv4.d.ts +0 -3
  74. package/dist/types/cli/mfRuntimePlugins/shared-strategy.d.ts +0 -3
  75. package/dist/types/cli/server/data-fetch-server-plugin.d.ts +0 -3
  76. package/dist/types/cli/ssrPlugin.d.ts +0 -6
  77. package/dist/types/cli/utils.d.ts +0 -6
  78. package/dist/types/constant.d.ts +0 -2
  79. package/dist/types/interfaces/bundler.d.ts +0 -18
  80. package/dist/types/logger.d.ts +0 -2
  81. package/dist/types/runtime/index.d.ts +0 -14
  82. package/dist/types/server/fileCache.d.ts +0 -14
  83. package/dist/types/server/fileCache.spec.d.ts +0 -1
  84. package/dist/types/server/index.d.ts +0 -4
  85. package/dist/types/server/staticMiddleware.d.ts +0 -6
  86. package/dist/types/server/staticMiddleware.spec.d.ts +0 -1
  87. package/dist/types/ssr-runtime/SSRLiveReload.d.ts +0 -1
  88. package/dist/types/ssr-runtime/devPlugin.d.ts +0 -2
  89. package/dist/types/ssr-runtime/injectDataFetchFunctionPlugin.d.ts +0 -4
  90. package/dist/types/types/index.d.ts +0 -24
@@ -1,95 +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 cli_exports = {};
20
- __export(cli_exports, {
21
- createModuleFederationConfig: () => import_enhanced2.createModuleFederationConfig,
22
- default: () => cli_default,
23
- moduleFederationPlugin: () => moduleFederationPlugin
24
- });
25
- module.exports = __toCommonJS(cli_exports);
26
- var import_enhanced = require("@module-federation/enhanced");
27
- var import_rspack = require("@module-federation/enhanced/rspack");
28
- var import_configPlugin = require("./configPlugin");
29
- var import_ssrPlugin = require("./ssrPlugin");
30
- var import_utils = require("./utils");
31
- var import_enhanced2 = require("@module-federation/enhanced");
32
- const moduleFederationPlugin = (userConfig = {}) => {
33
- var _userConfig_fetchServerQuery;
34
- const internalModernPluginOptions = {
35
- csrConfig: void 0,
36
- ssrConfig: void 0,
37
- browserPlugin: void 0,
38
- nodePlugin: void 0,
39
- distOutputDir: "",
40
- originPluginOptions: userConfig,
41
- remoteIpStrategy: userConfig === null || userConfig === void 0 ? void 0 : userConfig.remoteIpStrategy,
42
- userConfig: userConfig || {},
43
- fetchServerQuery: (_userConfig_fetchServerQuery = userConfig.fetchServerQuery) !== null && _userConfig_fetchServerQuery !== void 0 ? _userConfig_fetchServerQuery : void 0
44
- };
45
- return {
46
- name: "@modern-js/plugin-module-federation",
47
- setup: async (api) => {
48
- const modernjsConfig = api.getConfig();
49
- api.modifyBundlerChain((chain) => {
50
- const bundlerType = api.getAppContext().bundlerType === "rspack" ? "rspack" : "webpack";
51
- const browserPluginOptions = internalModernPluginOptions.csrConfig;
52
- const MFPlugin = bundlerType === "webpack" ? import_enhanced.ModuleFederationPlugin : import_rspack.ModuleFederationPlugin;
53
- if ((0, import_utils.isWebTarget)(chain.get("target"))) {
54
- chain.plugin("plugin-module-federation").use(MFPlugin, [
55
- browserPluginOptions
56
- ]).init((Plugin, args) => {
57
- internalModernPluginOptions.browserPlugin = new Plugin(args[0]);
58
- return internalModernPluginOptions.browserPlugin;
59
- });
60
- }
61
- if (bundlerType === "webpack") {
62
- var _modernjsConfig_source;
63
- const enableAsyncEntry = (_modernjsConfig_source = modernjsConfig.source) === null || _modernjsConfig_source === void 0 ? void 0 : _modernjsConfig_source.enableAsyncEntry;
64
- if (!enableAsyncEntry && browserPluginOptions.async !== false) {
65
- const asyncBoundaryPluginOptions = typeof browserPluginOptions.async === "object" ? browserPluginOptions.async : {
66
- eager: (module2) => module2 && /\.federation/.test((module2 === null || module2 === void 0 ? void 0 : module2.request) || ""),
67
- excludeChunk: (chunk) => chunk.name === browserPluginOptions.name
68
- };
69
- chain.plugin("async-boundary-plugin").use(import_enhanced.AsyncBoundaryPlugin, [
70
- asyncBoundaryPluginOptions
71
- ]);
72
- }
73
- }
74
- });
75
- api._internalServerPlugins(({ plugins }) => {
76
- plugins.push({
77
- name: "@module-federation/modern-js/server"
78
- });
79
- return {
80
- plugins
81
- };
82
- });
83
- },
84
- usePlugins: [
85
- (0, import_configPlugin.moduleFederationConfigPlugin)(internalModernPluginOptions),
86
- (0, import_ssrPlugin.moduleFederationSSRPlugin)(internalModernPluginOptions)
87
- ]
88
- };
89
- };
90
- var cli_default = moduleFederationPlugin;
91
- // Annotate the CommonJS export names for ESM import in node:
92
- 0 && (module.exports = {
93
- createModuleFederationConfig,
94
- moduleFederationPlugin
95
- });
@@ -1,44 +0,0 @@
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 inject_node_fetch_exports = {};
30
- __export(inject_node_fetch_exports, {
31
- default: () => inject_node_fetch_default
32
- });
33
- module.exports = __toCommonJS(inject_node_fetch_exports);
34
- var import_node_fetch = __toESM(require("node-fetch"));
35
- const injectNodeFetchPlugin = () => ({
36
- name: "inject-node-fetch-plugin",
37
- beforeInit(args) {
38
- if (!globalThis.fetch) {
39
- globalThis.fetch = import_node_fetch.default;
40
- }
41
- return args;
42
- }
43
- });
44
- var inject_node_fetch_default = injectNodeFetchPlugin;
@@ -1,82 +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 resolve_entry_ipv4_exports = {};
20
- __export(resolve_entry_ipv4_exports, {
21
- default: () => resolve_entry_ipv4_default
22
- });
23
- module.exports = __toCommonJS(resolve_entry_ipv4_exports);
24
- var import_constant = require("../../constant");
25
- const ipv4 = typeof FEDERATION_IPV4 !== "undefined" ? FEDERATION_IPV4 : "127.0.0.1";
26
- const remoteIpStrategy = typeof REMOTE_IP_STRATEGY !== "undefined" ? REMOTE_IP_STRATEGY : "inherit";
27
- function replaceObjectLocalhost(key, obj) {
28
- if (remoteIpStrategy !== "ipv4") {
29
- return;
30
- }
31
- if (!(key in obj)) {
32
- return;
33
- }
34
- const remote = obj[key];
35
- if (remote && typeof remote === "string" && remote.includes(import_constant.LOCALHOST)) {
36
- obj[key] = replaceLocalhost(remote);
37
- }
38
- }
39
- function replaceLocalhost(url) {
40
- return url.replace(import_constant.LOCALHOST, ipv4);
41
- }
42
- const resolveEntryIpv4Plugin = () => ({
43
- name: "resolve-entry-ipv4",
44
- beforeRegisterRemote(args) {
45
- const { remote } = args;
46
- replaceObjectLocalhost("entry", remote);
47
- return args;
48
- },
49
- async afterResolve(args) {
50
- const { remoteInfo } = args;
51
- replaceObjectLocalhost("entry", remoteInfo);
52
- return args;
53
- },
54
- beforeLoadRemoteSnapshot(args) {
55
- const { moduleInfo } = args;
56
- if ("entry" in moduleInfo) {
57
- replaceObjectLocalhost("entry", moduleInfo);
58
- return args;
59
- }
60
- if ("version" in moduleInfo) {
61
- replaceObjectLocalhost("version", moduleInfo);
62
- }
63
- return args;
64
- },
65
- loadRemoteSnapshot(args) {
66
- const { remoteSnapshot } = args;
67
- if ("publicPath" in remoteSnapshot) {
68
- replaceObjectLocalhost("publicPath", remoteSnapshot);
69
- }
70
- if ("getPublicPath" in remoteSnapshot) {
71
- replaceObjectLocalhost("getPublicPath", remoteSnapshot);
72
- }
73
- if (remoteSnapshot.remotesInfo) {
74
- Object.keys(remoteSnapshot.remotesInfo).forEach((key) => {
75
- const remoteInfo = remoteSnapshot.remotesInfo[key];
76
- replaceObjectLocalhost("matchedVersion", remoteInfo);
77
- });
78
- }
79
- return args;
80
- }
81
- });
82
- var resolve_entry_ipv4_default = resolveEntryIpv4Plugin;
@@ -1,43 +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 shared_strategy_exports = {};
20
- __export(shared_strategy_exports, {
21
- default: () => shared_strategy_default
22
- });
23
- module.exports = __toCommonJS(shared_strategy_exports);
24
- const sharedStrategy = () => ({
25
- name: "shared-strategy-plugin",
26
- beforeInit(args) {
27
- const { userOptions } = args;
28
- const shared = userOptions.shared;
29
- if (shared) {
30
- Object.keys(shared).forEach((sharedKey) => {
31
- const sharedConfigs = shared[sharedKey];
32
- const arraySharedConfigs = Array.isArray(sharedConfigs) ? sharedConfigs : [
33
- sharedConfigs
34
- ];
35
- arraySharedConfigs.forEach((s) => {
36
- s.strategy = "loaded-first";
37
- });
38
- });
39
- }
40
- return args;
41
- }
42
- });
43
- var shared_strategy_default = sharedStrategy;
@@ -1,48 +0,0 @@
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
32
- });
33
- module.exports = __toCommonJS(data_fetch_server_plugin_exports);
34
- var import_data_fetch_server_middleware = __toESM(require("@module-federation/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
- });
45
- });
46
- }
47
- });
48
- var data_fetch_server_plugin_default = dataFetchServePlugin;
@@ -1,236 +0,0 @@
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
35
- });
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_manifest = require("@module-federation/rsbuild-plugin/manifest");
45
- var import_utils2 = require("./utils");
46
- function setEnv() {
47
- process.env["MF_DISABLE_EMIT_STATS"] = "true";
48
- process.env["MF_SSR_PRJ"] = "true";
49
- }
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_utils2.skipByTarget)(target)) {
67
- return config;
68
- }
69
- if ((0, import_utils2.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_utils2.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_utils2.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}/`);
177
- }
178
- }
179
- if ((0, import_utils.isDev)() && isWeb) {
180
- chain.externals({
181
- "@module-federation/node/utils": "NOT_USED_IN_BROWSER"
182
- });
183
- }
184
- });
185
- api.config(() => {
186
- return {
187
- builderPlugins: [
188
- mfSSRRsbuildPlugin(pluginOptions)
189
- ],
190
- tools: {
191
- devServer: {
192
- before: [
193
- (req, res, next) => {
194
- if (!enableSSR) {
195
- next();
196
- return;
197
- }
198
- 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
- }
210
- } catch (err) {
211
- import_logger.default.debug(err);
212
- next();
213
- }
214
- }
215
- ]
216
- }
217
- }
218
- };
219
- });
220
- api.onAfterBuild(() => {
221
- const { nodePlugin, browserPlugin, distOutputDir } = pluginOptions;
222
- (0, import_manifest.updateStatsAndManifest)(nodePlugin, browserPlugin, distOutputDir);
223
- });
224
- api.onDevCompileDone(() => {
225
- const { nodePlugin, browserPlugin, distOutputDir } = pluginOptions;
226
- (0, import_manifest.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
236
- });
@@ -1,90 +0,0 @@
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 utils_exports = {};
30
- __export(utils_exports, {
31
- getIPV4: () => getIPV4,
32
- isDev: () => isDev,
33
- isWebTarget: () => isWebTarget,
34
- skipByTarget: () => skipByTarget
35
- });
36
- module.exports = __toCommonJS(utils_exports);
37
- var import_os = __toESM(require("os"));
38
- const localIpv4 = "127.0.0.1";
39
- const getIpv4Interfaces = () => {
40
- try {
41
- const interfaces = import_os.default.networkInterfaces();
42
- const ipv4Interfaces = [];
43
- Object.values(interfaces).forEach((detail) => {
44
- detail === null || detail === void 0 ? void 0 : detail.forEach((detail2) => {
45
- const familyV4Value = typeof detail2.family === "string" ? "IPv4" : 4;
46
- if (detail2.family === familyV4Value && detail2.address !== localIpv4) {
47
- ipv4Interfaces.push(detail2);
48
- }
49
- });
50
- });
51
- return ipv4Interfaces;
52
- } catch (_err) {
53
- return [];
54
- }
55
- };
56
- const getIPV4 = () => {
57
- const ipv4Interfaces = getIpv4Interfaces();
58
- const ipv4Interface = ipv4Interfaces[0] || {
59
- address: localIpv4
60
- };
61
- return ipv4Interface.address;
62
- };
63
- const isWebTarget = (target) => {
64
- const WEB_TARGET = "web";
65
- if (Array.isArray(target)) {
66
- return target.includes(WEB_TARGET);
67
- } else if (typeof target === "string") {
68
- return target === WEB_TARGET;
69
- }
70
- return false;
71
- };
72
- const skipByTarget = (target) => {
73
- const IGNORE_TARGET = "webworker";
74
- if (Array.isArray(target)) {
75
- return target.includes(IGNORE_TARGET);
76
- } else if (typeof target === "string") {
77
- return target === IGNORE_TARGET;
78
- }
79
- return false;
80
- };
81
- function isDev() {
82
- return process.env.NODE_ENV === "development";
83
- }
84
- // Annotate the CommonJS export names for ESM import in node:
85
- 0 && (module.exports = {
86
- getIPV4,
87
- isDev,
88
- isWebTarget,
89
- skipByTarget
90
- });
@@ -1,31 +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 constant_exports = {};
20
- __export(constant_exports, {
21
- LOCALHOST: () => LOCALHOST,
22
- PLUGIN_IDENTIFIER: () => PLUGIN_IDENTIFIER
23
- });
24
- module.exports = __toCommonJS(constant_exports);
25
- const LOCALHOST = "localhost";
26
- const PLUGIN_IDENTIFIER = "[ Modern.js Module Federation ]";
27
- // Annotate the CommonJS export names for ESM import in node:
28
- 0 && (module.exports = {
29
- LOCALHOST,
30
- PLUGIN_IDENTIFIER
31
- });