@module-federation/modern-js 0.21.6 → 0.22.0

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 (113) hide show
  1. package/dist/cjs/cli/configPlugin.js +301 -357
  2. package/dist/cjs/cli/index.js +103 -93
  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 +266 -298
  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 +62 -37
  14. package/dist/cjs/react/v18.js +55 -19
  15. package/dist/cjs/react/v19.js +55 -19
  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/server/fileCache.mjs +90 -0
  36. package/dist/esm/server/index.mjs +36 -0
  37. package/dist/esm/server/staticMiddleware.mjs +87 -0
  38. package/dist/esm/ssr-runtime/SSRLiveReload.mjs +22 -0
  39. package/dist/esm/ssr-runtime/devPlugin.mjs +70 -0
  40. package/dist/esm/ssr-runtime/injectDataFetchFunctionPlugin.mjs +34 -0
  41. package/dist/esm-node/cli/configPlugin.mjs +263 -0
  42. package/dist/esm-node/cli/index.mjs +67 -0
  43. package/dist/esm-node/cli/mfRuntimePlugins/inject-node-fetch.mjs +10 -0
  44. package/dist/esm-node/cli/mfRuntimePlugins/resolve-entry-ipv4.mjs +46 -0
  45. package/dist/esm-node/cli/mfRuntimePlugins/shared-strategy.mjs +19 -0
  46. package/dist/esm-node/cli/server/data-fetch-server-plugin.mjs +15 -0
  47. package/dist/esm-node/cli/ssrPlugin.mjs +228 -0
  48. package/dist/esm-node/cli/utils.mjs +40 -0
  49. package/dist/esm-node/constant.mjs +3 -0
  50. package/dist/esm-node/logger.mjs +5 -0
  51. package/dist/esm-node/react/plugin.mjs +3 -0
  52. package/dist/esm-node/server/fileCache.mjs +37 -0
  53. package/dist/esm-node/server/index.mjs +34 -0
  54. package/dist/esm-node/server/staticMiddleware.mjs +42 -0
  55. package/dist/esm-node/ssr-runtime/SSRLiveReload.mjs +15 -0
  56. package/dist/esm-node/ssr-runtime/devPlugin.mjs +33 -0
  57. package/dist/esm-node/ssr-runtime/injectDataFetchFunctionPlugin.mjs +14 -0
  58. package/package.json +32 -31
  59. package/dist/cjs/cli/configPlugin.spec.js +0 -112
  60. package/dist/cjs/server/fileCache.spec.js +0 -28
  61. package/dist/cjs/server/staticMiddleware.spec.js +0 -185
  62. package/dist/esm/cli/configPlugin.js +0 -395
  63. package/dist/esm/cli/configPlugin.spec.js +0 -108
  64. package/dist/esm/cli/index.js +0 -92
  65. package/dist/esm/cli/mfRuntimePlugins/inject-node-fetch.js +0 -16
  66. package/dist/esm/cli/mfRuntimePlugins/resolve-entry-ipv4.js +0 -74
  67. package/dist/esm/cli/mfRuntimePlugins/shared-strategy.js +0 -25
  68. package/dist/esm/cli/server/data-fetch-server-plugin.js +0 -20
  69. package/dist/esm/cli/ssrPlugin.js +0 -305
  70. package/dist/esm/cli/utils.js +0 -53
  71. package/dist/esm/constant.js +0 -6
  72. package/dist/esm/logger.js +0 -7
  73. package/dist/esm/react/plugin.js +0 -5
  74. package/dist/esm/server/fileCache.js +0 -98
  75. package/dist/esm/server/fileCache.spec.js +0 -50
  76. package/dist/esm/server/index.js +0 -41
  77. package/dist/esm/server/staticMiddleware.js +0 -104
  78. package/dist/esm/server/staticMiddleware.spec.js +0 -328
  79. package/dist/esm/ssr-runtime/SSRLiveReload.js +0 -26
  80. package/dist/esm/ssr-runtime/devPlugin.js +0 -73
  81. package/dist/esm/ssr-runtime/injectDataFetchFunctionPlugin.js +0 -34
  82. package/dist/esm-node/cli/configPlugin.js +0 -347
  83. package/dist/esm-node/cli/configPlugin.spec.js +0 -89
  84. package/dist/esm-node/cli/index.js +0 -72
  85. package/dist/esm-node/cli/mfRuntimePlugins/inject-node-fetch.js +0 -14
  86. package/dist/esm-node/cli/mfRuntimePlugins/resolve-entry-ipv4.js +0 -62
  87. package/dist/esm-node/cli/mfRuntimePlugins/shared-strategy.js +0 -23
  88. package/dist/esm-node/cli/server/data-fetch-server-plugin.js +0 -18
  89. package/dist/esm-node/cli/ssrPlugin.js +0 -280
  90. package/dist/esm-node/cli/utils.js +0 -53
  91. package/dist/esm-node/constant.js +0 -6
  92. package/dist/esm-node/logger.js +0 -7
  93. package/dist/esm-node/react/plugin.js +0 -5
  94. package/dist/esm-node/server/fileCache.js +0 -49
  95. package/dist/esm-node/server/fileCache.spec.js +0 -27
  96. package/dist/esm-node/server/index.js +0 -39
  97. package/dist/esm-node/server/staticMiddleware.js +0 -55
  98. package/dist/esm-node/server/staticMiddleware.spec.js +0 -162
  99. package/dist/esm-node/ssr-runtime/SSRLiveReload.js +0 -19
  100. package/dist/esm-node/ssr-runtime/devPlugin.js +0 -37
  101. package/dist/esm-node/ssr-runtime/injectDataFetchFunctionPlugin.js +0 -16
  102. /package/dist/esm/interfaces/{bundler.js → bundler.mjs} +0 -0
  103. /package/dist/esm/react/{index.js → index.mjs} +0 -0
  104. /package/dist/esm/react/{v18.js → v18.mjs} +0 -0
  105. /package/dist/esm/react/{v19.js → v19.mjs} +0 -0
  106. /package/dist/esm/runtime/{index.js → index.mjs} +0 -0
  107. /package/dist/esm/types/{index.js → index.mjs} +0 -0
  108. /package/dist/esm-node/interfaces/{bundler.js → bundler.mjs} +0 -0
  109. /package/dist/esm-node/react/{index.js → index.mjs} +0 -0
  110. /package/dist/esm-node/react/{v18.js → v18.mjs} +0 -0
  111. /package/dist/esm-node/react/{v19.js → v19.mjs} +0 -0
  112. /package/dist/esm-node/runtime/{index.js → index.mjs} +0 -0
  113. /package/dist/esm-node/types/{index.js → index.mjs} +0 -0
@@ -0,0 +1,83 @@
1
+ import { _ } from "@swc/helpers/_/_async_to_generator";
2
+ import { _ as _object_spread__ } from "@swc/helpers/_/_object_spread";
3
+ import { _ as _type_of__ } from "@swc/helpers/_/_type_of";
4
+ import { _ as _ts_generator__ } from "@swc/helpers/_/_ts_generator";
5
+ import { AsyncBoundaryPlugin, ModuleFederationPlugin, createModuleFederationConfig } from "@module-federation/enhanced";
6
+ import { ModuleFederationPlugin as rspack_ModuleFederationPlugin } from "@module-federation/enhanced/rspack";
7
+ import { moduleFederationConfigPlugin } from "./configPlugin.mjs";
8
+ import { moduleFederationSSRPlugin } from "./ssrPlugin.mjs";
9
+ import { isWebTarget } from "./utils.mjs";
10
+ var moduleFederationPlugin = function() {
11
+ var userConfig = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : {};
12
+ var _userConfig_fetchServerQuery;
13
+ var internalModernPluginOptions = {
14
+ csrConfig: void 0,
15
+ ssrConfig: void 0,
16
+ browserPlugin: void 0,
17
+ nodePlugin: void 0,
18
+ assetResources: {},
19
+ distOutputDir: '',
20
+ originPluginOptions: _object_spread__({}, userConfig),
21
+ remoteIpStrategy: null == userConfig ? void 0 : userConfig.remoteIpStrategy,
22
+ userConfig: userConfig || {},
23
+ assetFileNames: {},
24
+ fetchServerQuery: null != (_userConfig_fetchServerQuery = userConfig.fetchServerQuery) ? _userConfig_fetchServerQuery : void 0
25
+ };
26
+ return {
27
+ name: '@modern-js/plugin-module-federation',
28
+ setup: function(api) {
29
+ return _(function() {
30
+ var modernjsConfig;
31
+ return _ts_generator__(this, function(_state) {
32
+ modernjsConfig = api.getConfig();
33
+ api.modifyBundlerChain(function(chain) {
34
+ var bundlerType = 'rspack' === api.getAppContext().bundlerType ? 'rspack' : 'webpack';
35
+ var browserPluginOptions = internalModernPluginOptions.csrConfig;
36
+ var MFPlugin = 'webpack' === bundlerType ? ModuleFederationPlugin : rspack_ModuleFederationPlugin;
37
+ if (isWebTarget(chain.get('target'))) chain.plugin('plugin-module-federation').use(MFPlugin, [
38
+ browserPluginOptions
39
+ ]).init(function(Plugin, args) {
40
+ internalModernPluginOptions.browserPlugin = new Plugin(args[0]);
41
+ return internalModernPluginOptions.browserPlugin;
42
+ });
43
+ if ('webpack' === bundlerType) {
44
+ var _modernjsConfig_source;
45
+ var enableAsyncEntry = null == (_modernjsConfig_source = modernjsConfig.source) ? void 0 : _modernjsConfig_source.enableAsyncEntry;
46
+ if (!enableAsyncEntry && false !== browserPluginOptions.async) {
47
+ var asyncBoundaryPluginOptions = 'object' === _type_of__(browserPluginOptions.async) ? browserPluginOptions.async : {
48
+ eager: function(module) {
49
+ return module && /\.federation/.test((null == module ? void 0 : module.request) || '');
50
+ },
51
+ excludeChunk: function(chunk) {
52
+ return chunk.name === browserPluginOptions.name;
53
+ }
54
+ };
55
+ chain.plugin('async-boundary-plugin').use(AsyncBoundaryPlugin, [
56
+ asyncBoundaryPluginOptions
57
+ ]);
58
+ }
59
+ }
60
+ });
61
+ api._internalServerPlugins(function(param) {
62
+ var plugins = param.plugins;
63
+ plugins.push({
64
+ name: '@module-federation/modern-js/server'
65
+ });
66
+ return {
67
+ plugins: plugins
68
+ };
69
+ });
70
+ return [
71
+ 2
72
+ ];
73
+ });
74
+ })();
75
+ },
76
+ usePlugins: [
77
+ moduleFederationConfigPlugin(internalModernPluginOptions),
78
+ moduleFederationSSRPlugin(internalModernPluginOptions)
79
+ ]
80
+ };
81
+ };
82
+ var cli = moduleFederationPlugin;
83
+ export { createModuleFederationConfig, cli as default, moduleFederationPlugin };
@@ -0,0 +1,12 @@
1
+ import node_fetch from "node-fetch";
2
+ var injectNodeFetchPlugin = function() {
3
+ return {
4
+ name: 'inject-node-fetch-plugin',
5
+ beforeInit: function(args) {
6
+ if (!globalThis.fetch) globalThis.fetch = node_fetch;
7
+ return args;
8
+ }
9
+ };
10
+ };
11
+ var inject_node_fetch = injectNodeFetchPlugin;
12
+ export { inject_node_fetch as default };
@@ -0,0 +1,58 @@
1
+ import { _ } from "@swc/helpers/_/_async_to_generator";
2
+ import { _ as _ts_generator__ } from "@swc/helpers/_/_ts_generator";
3
+ import { LOCALHOST } from "../../constant.mjs";
4
+ var ipv4 = "u" > typeof FEDERATION_IPV4 ? FEDERATION_IPV4 : '127.0.0.1';
5
+ var remoteIpStrategy = "u" > typeof REMOTE_IP_STRATEGY ? REMOTE_IP_STRATEGY : 'inherit';
6
+ function replaceObjectLocalhost(key, obj) {
7
+ if ('ipv4' !== remoteIpStrategy) return;
8
+ if (!(key in obj)) return;
9
+ var remote = obj[key];
10
+ if (remote && 'string' == typeof remote && remote.includes(LOCALHOST)) obj[key] = replaceLocalhost(remote);
11
+ }
12
+ function replaceLocalhost(url) {
13
+ return url.replace(LOCALHOST, ipv4);
14
+ }
15
+ var resolveEntryIpv4Plugin = function() {
16
+ return {
17
+ name: 'resolve-entry-ipv4',
18
+ beforeRegisterRemote: function(args) {
19
+ var remote = args.remote;
20
+ replaceObjectLocalhost('entry', remote);
21
+ return args;
22
+ },
23
+ afterResolve: function(args) {
24
+ return _(function() {
25
+ var remoteInfo;
26
+ return _ts_generator__(this, function(_state) {
27
+ remoteInfo = args.remoteInfo;
28
+ replaceObjectLocalhost('entry', remoteInfo);
29
+ return [
30
+ 2,
31
+ args
32
+ ];
33
+ });
34
+ })();
35
+ },
36
+ beforeLoadRemoteSnapshot: function(args) {
37
+ var moduleInfo = args.moduleInfo;
38
+ if ('entry' in moduleInfo) {
39
+ replaceObjectLocalhost('entry', moduleInfo);
40
+ return args;
41
+ }
42
+ if ('version' in moduleInfo) replaceObjectLocalhost('version', moduleInfo);
43
+ return args;
44
+ },
45
+ loadRemoteSnapshot: function(args) {
46
+ var remoteSnapshot = args.remoteSnapshot;
47
+ if ('publicPath' in remoteSnapshot) replaceObjectLocalhost('publicPath', remoteSnapshot);
48
+ if ('getPublicPath' in remoteSnapshot) replaceObjectLocalhost('getPublicPath', remoteSnapshot);
49
+ if (remoteSnapshot.remotesInfo) Object.keys(remoteSnapshot.remotesInfo).forEach(function(key) {
50
+ var remoteInfo = remoteSnapshot.remotesInfo[key];
51
+ replaceObjectLocalhost('matchedVersion', remoteInfo);
52
+ });
53
+ return args;
54
+ }
55
+ };
56
+ };
57
+ var resolve_entry_ipv4 = resolveEntryIpv4Plugin;
58
+ export { resolve_entry_ipv4 as default };
@@ -0,0 +1,21 @@
1
+ var sharedStrategy = function() {
2
+ return {
3
+ name: 'shared-strategy-plugin',
4
+ beforeInit: function(args) {
5
+ var userOptions = args.userOptions;
6
+ var shared = userOptions.shared;
7
+ if (shared) Object.keys(shared).forEach(function(sharedKey) {
8
+ var sharedConfigs = shared[sharedKey];
9
+ var arraySharedConfigs = Array.isArray(sharedConfigs) ? sharedConfigs : [
10
+ sharedConfigs
11
+ ];
12
+ arraySharedConfigs.forEach(function(s) {
13
+ s.strategy = 'loaded-first';
14
+ });
15
+ });
16
+ return args;
17
+ }
18
+ };
19
+ };
20
+ var shared_strategy = sharedStrategy;
21
+ export { shared_strategy as default };
@@ -0,0 +1,17 @@
1
+ import data_fetch_server_middleware from "@module-federation/bridge-react/data-fetch-server-middleware";
2
+ var dataFetchServePlugin = function() {
3
+ return {
4
+ name: 'mf-data-fetch-server-plugin',
5
+ setup: function(api) {
6
+ api.onPrepare(function() {
7
+ var middlewares = api.getServerContext().middlewares;
8
+ middlewares.push({
9
+ name: 'module-federation-serve-manifest',
10
+ handler: data_fetch_server_middleware
11
+ });
12
+ });
13
+ }
14
+ };
15
+ };
16
+ var data_fetch_server_plugin = dataFetchServePlugin;
17
+ export { data_fetch_server_plugin as default };
@@ -0,0 +1,254 @@
1
+ import { _ } from "@swc/helpers/_/_async_to_generator";
2
+ import { _ as _instanceof__ } from "@swc/helpers/_/_instanceof";
3
+ import { _ as _type_of__ } from "@swc/helpers/_/_type_of";
4
+ import { _ as _ts_generator__ } from "@swc/helpers/_/_ts_generator";
5
+ import path from "path";
6
+ import fs_extra from "fs-extra";
7
+ import { ModuleFederationPlugin } from "@module-federation/enhanced/webpack";
8
+ import { ModuleFederationPlugin as rspack_ModuleFederationPlugin } from "@module-federation/enhanced/rspack";
9
+ import universe_entry_chunk_tracker_plugin from "@module-federation/node/universe-entry-chunk-tracker-plugin";
10
+ import logger from "../logger.mjs";
11
+ import { isDev, isWebTarget, skipByTarget } from "./utils.mjs";
12
+ import { updateStatsAndManifest } from "@module-federation/rsbuild-plugin/utils";
13
+ import { ManifestFileName, StatsFileName, simpleJoinRemoteEntry } from "@module-federation/sdk";
14
+ function setEnv() {
15
+ process.env['MF_SSR_PRJ'] = 'true';
16
+ }
17
+ var CHAIN_MF_PLUGIN_ID = 'plugin-module-federation-server';
18
+ function getManifestAssetFileNames(manifestOption) {
19
+ if (!manifestOption) return {
20
+ statsFileName: StatsFileName,
21
+ manifestFileName: ManifestFileName
22
+ };
23
+ var JSON_EXT = '.json';
24
+ var filePath = 'boolean' == typeof manifestOption ? '' : manifestOption.filePath || '';
25
+ var baseFileName = 'boolean' == typeof manifestOption ? '' : manifestOption.fileName || '';
26
+ var ensureExt = function(name) {
27
+ return name.endsWith(JSON_EXT) ? name : "".concat(name).concat(JSON_EXT);
28
+ };
29
+ var withSuffix = function(name, suffix) {
30
+ return name.replace(JSON_EXT, "".concat(suffix).concat(JSON_EXT));
31
+ };
32
+ var manifestFileName = baseFileName ? ensureExt(baseFileName) : ManifestFileName;
33
+ var statsFileName = baseFileName ? withSuffix(manifestFileName, '-stats') : StatsFileName;
34
+ return {
35
+ statsFileName: simpleJoinRemoteEntry(filePath, statsFileName),
36
+ manifestFileName: simpleJoinRemoteEntry(filePath, manifestFileName)
37
+ };
38
+ }
39
+ var mfSSRRsbuildPlugin = function(pluginOptions) {
40
+ return {
41
+ name: '@modern-js/plugin-mf-post-config',
42
+ pre: [
43
+ '@modern-js/builder-plugin-ssr'
44
+ ],
45
+ setup: function(api) {
46
+ var _pluginOptions_csrConfig, _pluginOptions_assetFileNames, _pluginOptions_ssrConfig;
47
+ if (pluginOptions.csrConfig.getPublicPath) return;
48
+ var csrOutputPath = '';
49
+ var ssrOutputPath = '';
50
+ var ssrEnv = '';
51
+ var csrEnv = '';
52
+ var browserAssetFileNames = pluginOptions.assetFileNames.browser || getManifestAssetFileNames(null == (_pluginOptions_csrConfig = pluginOptions.csrConfig) ? void 0 : _pluginOptions_csrConfig.manifest);
53
+ var nodeAssetFileNames = (null == (_pluginOptions_assetFileNames = pluginOptions.assetFileNames) ? void 0 : _pluginOptions_assetFileNames.node) || getManifestAssetFileNames(null == (_pluginOptions_ssrConfig = pluginOptions.ssrConfig) ? void 0 : _pluginOptions_ssrConfig.manifest);
54
+ var collectAssets = function(assets, fileNames, tag) {
55
+ var statsAsset = assets[fileNames.statsFileName];
56
+ var manifestAsset = assets[fileNames.manifestFileName];
57
+ if (!statsAsset || !manifestAsset) return;
58
+ try {
59
+ var statsRaw = statsAsset.source();
60
+ var manifestRaw = manifestAsset.source();
61
+ var statsContent = 'string' == typeof statsRaw ? statsRaw : statsRaw.toString();
62
+ var manifestContent = 'string' == typeof manifestRaw ? manifestRaw : manifestRaw.toString();
63
+ return {
64
+ stats: {
65
+ data: JSON.parse(statsContent),
66
+ filename: fileNames.statsFileName
67
+ },
68
+ manifest: {
69
+ data: JSON.parse(manifestContent),
70
+ filename: fileNames.manifestFileName
71
+ }
72
+ };
73
+ } catch (err) {
74
+ var message = _instanceof__(err, Error) ? err.message : String(err);
75
+ logger.error("Failed to parse ".concat(tag, " manifest assets: ").concat(message));
76
+ return;
77
+ }
78
+ };
79
+ api.modifyEnvironmentConfig(function(config, param) {
80
+ var name = param.name;
81
+ var target = config.output.target;
82
+ if (skipByTarget(target)) return config;
83
+ if (isWebTarget(target)) {
84
+ csrOutputPath = config.output.distPath.root;
85
+ csrEnv = name;
86
+ } else {
87
+ ssrOutputPath = config.output.distPath.root;
88
+ ssrEnv = name;
89
+ }
90
+ return config;
91
+ });
92
+ var modifySSRPublicPath = function(config, utils) {
93
+ if (ssrEnv !== utils.environment.name) return config;
94
+ var userSSRConfig = pluginOptions.userConfig.ssr ? 'object' === _type_of__(pluginOptions.userConfig.ssr) ? pluginOptions.userConfig.ssr : {} : {};
95
+ if (!userSSRConfig.distOutputDir) return;
96
+ config.output.publicPath = "".concat(config.output.publicPath).concat(path.relative(csrOutputPath, ssrOutputPath), "/");
97
+ return config;
98
+ };
99
+ api.modifyWebpackConfig(function(config, utils) {
100
+ modifySSRPublicPath(config, utils);
101
+ return config;
102
+ });
103
+ api.modifyRspackConfig(function(config, utils) {
104
+ modifySSRPublicPath(config, utils);
105
+ return config;
106
+ });
107
+ api.processAssets({
108
+ stage: 'report'
109
+ }, function(param) {
110
+ var assets = param.assets, envContext = param.environment;
111
+ var _pluginOptions_csrConfig, _pluginOptions_ssrConfig;
112
+ var envName = envContext.name;
113
+ if ((null == (_pluginOptions_csrConfig = pluginOptions.csrConfig) ? void 0 : _pluginOptions_csrConfig.manifest) !== false && csrEnv && envName === csrEnv) {
114
+ var browserAssets = collectAssets(assets, browserAssetFileNames, 'browser');
115
+ if (browserAssets) pluginOptions.assetResources.browser = browserAssets;
116
+ }
117
+ if ((null == (_pluginOptions_ssrConfig = pluginOptions.ssrConfig) ? void 0 : _pluginOptions_ssrConfig.manifest) !== false && ssrEnv && envName === ssrEnv) {
118
+ var nodeAssets = collectAssets(assets, nodeAssetFileNames, 'node');
119
+ if (nodeAssets) pluginOptions.assetResources.node = nodeAssets;
120
+ }
121
+ });
122
+ }
123
+ };
124
+ };
125
+ var moduleFederationSSRPlugin = function(pluginOptions) {
126
+ return {
127
+ name: '@modern-js/plugin-module-federation-ssr',
128
+ pre: [
129
+ '@modern-js/plugin-module-federation-config',
130
+ '@modern-js/plugin-module-federation'
131
+ ],
132
+ setup: function(api) {
133
+ return _(function() {
134
+ var _pluginOptions_userConfig, _modernjsConfig_server, modernjsConfig, _ref, enableSSR, writeMergedManifest;
135
+ return _ts_generator__(this, function(_state) {
136
+ modernjsConfig = api.getConfig();
137
+ 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);
138
+ if (!enableSSR) return [
139
+ 2
140
+ ];
141
+ setEnv();
142
+ api._internalRuntimePlugins(function(param) {
143
+ var entrypoint = param.entrypoint, plugins = param.plugins;
144
+ var fetchServerQuery = pluginOptions.fetchServerQuery;
145
+ plugins.push({
146
+ name: 'injectDataFetchFunction',
147
+ path: '@module-federation/modern-js/ssr-inject-data-fetch-function-plugin',
148
+ config: {
149
+ fetchServerQuery: fetchServerQuery
150
+ }
151
+ });
152
+ if (!isDev()) return {
153
+ entrypoint: entrypoint,
154
+ plugins: plugins
155
+ };
156
+ plugins.push({
157
+ name: 'mfSSRDev',
158
+ path: '@module-federation/modern-js/ssr-dev-plugin',
159
+ config: {}
160
+ });
161
+ return {
162
+ entrypoint: entrypoint,
163
+ plugins: plugins
164
+ };
165
+ });
166
+ if (pluginOptions.ssrConfig.remotes) api._internalServerPlugins(function(param) {
167
+ var plugins = param.plugins;
168
+ plugins.push({
169
+ name: '@module-federation/modern-js/data-fetch-server-plugin',
170
+ options: {}
171
+ });
172
+ return {
173
+ plugins: plugins
174
+ };
175
+ });
176
+ api.modifyBundlerChain(function(chain) {
177
+ var target = chain.get('target');
178
+ if (skipByTarget(target)) return;
179
+ var bundlerType = 'rspack' === api.getAppContext().bundlerType ? 'rspack' : 'webpack';
180
+ var MFPlugin = 'webpack' === bundlerType ? ModuleFederationPlugin : rspack_ModuleFederationPlugin;
181
+ var isWeb = isWebTarget(target);
182
+ if (!isWeb) {
183
+ if (!chain.plugins.has(CHAIN_MF_PLUGIN_ID)) chain.plugin(CHAIN_MF_PLUGIN_ID).use(MFPlugin, [
184
+ pluginOptions.ssrConfig
185
+ ]).init(function(Plugin, args) {
186
+ pluginOptions.nodePlugin = new Plugin(args[0]);
187
+ return pluginOptions.nodePlugin;
188
+ });
189
+ }
190
+ if (!isWeb) {
191
+ chain.target('async-node');
192
+ if (isDev()) chain.plugin('UniverseEntryChunkTrackerPlugin').use(universe_entry_chunk_tracker_plugin);
193
+ }
194
+ if (isDev() && isWeb) chain.externals({
195
+ '@module-federation/node/utils': 'NOT_USED_IN_BROWSER'
196
+ });
197
+ });
198
+ api.config(function() {
199
+ return {
200
+ builderPlugins: [
201
+ mfSSRRsbuildPlugin(pluginOptions)
202
+ ],
203
+ tools: {
204
+ devServer: {
205
+ before: [
206
+ function(req, res, next) {
207
+ if (!enableSSR) return void next();
208
+ try {
209
+ var _req_url, _req_url1;
210
+ if ((null == (_req_url = req.url) ? void 0 : _req_url.includes('.json')) && !(null == (_req_url1 = req.url) ? void 0 : _req_url1.includes('hot-update'))) {
211
+ var filepath = path.join(process.cwd(), "dist".concat(req.url));
212
+ fs_extra.statSync(filepath);
213
+ res.setHeader('Access-Control-Allow-Origin', '*');
214
+ res.setHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, PATCH, OPTIONS');
215
+ res.setHeader('Access-Control-Allow-Headers', '*');
216
+ fs_extra.createReadStream(filepath).pipe(res);
217
+ } else next();
218
+ } catch (err) {
219
+ logger.debug(err);
220
+ next();
221
+ }
222
+ }
223
+ ]
224
+ }
225
+ }
226
+ };
227
+ });
228
+ writeMergedManifest = function() {
229
+ var distOutputDir = pluginOptions.distOutputDir, assetResources = pluginOptions.assetResources;
230
+ var browserAssets = assetResources.browser;
231
+ var nodeAssets = assetResources.node;
232
+ if (!distOutputDir || !browserAssets || !nodeAssets) return;
233
+ try {
234
+ updateStatsAndManifest(nodeAssets, browserAssets, distOutputDir);
235
+ } catch (err) {
236
+ logger.error(err);
237
+ }
238
+ };
239
+ api.onAfterBuild(function() {
240
+ writeMergedManifest();
241
+ });
242
+ api.onDevCompileDone(function() {
243
+ writeMergedManifest();
244
+ });
245
+ return [
246
+ 2
247
+ ];
248
+ });
249
+ })();
250
+ }
251
+ };
252
+ };
253
+ var ssrPlugin = moduleFederationSSRPlugin;
254
+ export { CHAIN_MF_PLUGIN_ID, ssrPlugin as default, moduleFederationSSRPlugin, setEnv };
@@ -0,0 +1,40 @@
1
+ import os from "os";
2
+ var localIpv4 = '127.0.0.1';
3
+ var getIpv4Interfaces = function() {
4
+ try {
5
+ var interfaces = os.networkInterfaces();
6
+ var ipv4Interfaces = [];
7
+ Object.values(interfaces).forEach(function(detail) {
8
+ null == detail || detail.forEach(function(detail) {
9
+ var familyV4Value = 'string' == typeof detail.family ? 'IPv4' : 4;
10
+ if (detail.family === familyV4Value && detail.address !== localIpv4) ipv4Interfaces.push(detail);
11
+ });
12
+ });
13
+ return ipv4Interfaces;
14
+ } catch (_err) {
15
+ return [];
16
+ }
17
+ };
18
+ var getIPV4 = function() {
19
+ var ipv4Interfaces = getIpv4Interfaces();
20
+ var ipv4Interface = ipv4Interfaces[0] || {
21
+ address: localIpv4
22
+ };
23
+ return ipv4Interface.address;
24
+ };
25
+ var isWebTarget = function(target) {
26
+ var WEB_TARGET = 'web';
27
+ if (Array.isArray(target)) return target.includes(WEB_TARGET);
28
+ if ('string' == typeof target) return target === WEB_TARGET;
29
+ return false;
30
+ };
31
+ var skipByTarget = function(target) {
32
+ var IGNORE_TARGET = 'webworker';
33
+ if (Array.isArray(target)) return target.includes(IGNORE_TARGET);
34
+ if ('string' == typeof target) return target === IGNORE_TARGET;
35
+ return false;
36
+ };
37
+ function isDev() {
38
+ return 'development' === process.env.NODE_ENV;
39
+ }
40
+ export { getIPV4, isDev, isWebTarget, skipByTarget };
@@ -0,0 +1,3 @@
1
+ var LOCALHOST = 'localhost';
2
+ var PLUGIN_IDENTIFIER = '[ Modern.js Module Federation ]';
3
+ export { LOCALHOST, PLUGIN_IDENTIFIER };
@@ -0,0 +1,5 @@
1
+ import { createLogger } from "@module-federation/sdk";
2
+ import { PLUGIN_IDENTIFIER } from "./constant.mjs";
3
+ var logger = createLogger(PLUGIN_IDENTIFIER);
4
+ var src_logger = logger;
5
+ export { src_logger as default };
@@ -0,0 +1,3 @@
1
+ import bridge_react_plugin from "@module-federation/bridge-react/plugin";
2
+ export * from "@module-federation/bridge-react/plugin";
3
+ export { bridge_react_plugin as default };
@@ -0,0 +1,90 @@
1
+ import { _ } from "@swc/helpers/_/_async_to_generator";
2
+ import { _ as _class_call_check__ } from "@swc/helpers/_/_class_call_check";
3
+ import { _ as _ts_generator__ } from "@swc/helpers/_/_ts_generator";
4
+ import fs_extra from "fs-extra";
5
+ import { LRUCache } from "lru-cache";
6
+ var fileCache_FileCache = /*#__PURE__*/ function() {
7
+ "use strict";
8
+ function FileCache() {
9
+ _class_call_check__(this, FileCache);
10
+ this.cache = new LRUCache({
11
+ maxSize: 209715200
12
+ });
13
+ }
14
+ var _proto = FileCache.prototype;
15
+ _proto.getFile = function(filepath) {
16
+ return _(function() {
17
+ var stat, currentModified, cachedEntry, content, newEntry;
18
+ return _ts_generator__(this, function(_state) {
19
+ switch(_state.label){
20
+ case 0:
21
+ return [
22
+ 4,
23
+ fs_extra.pathExists(filepath)
24
+ ];
25
+ case 1:
26
+ if (!_state.sent()) return [
27
+ 2,
28
+ null
29
+ ];
30
+ _state.label = 2;
31
+ case 2:
32
+ _state.trys.push([
33
+ 2,
34
+ 5,
35
+ ,
36
+ 6
37
+ ]);
38
+ return [
39
+ 4,
40
+ fs_extra.lstat(filepath)
41
+ ];
42
+ case 3:
43
+ stat = _state.sent();
44
+ currentModified = stat.mtimeMs;
45
+ cachedEntry = this.cache.get(filepath);
46
+ if (cachedEntry && currentModified <= cachedEntry.lastModified) return [
47
+ 2,
48
+ {
49
+ content: cachedEntry.content,
50
+ lastModified: cachedEntry.lastModified
51
+ }
52
+ ];
53
+ return [
54
+ 4,
55
+ fs_extra.readFile(filepath, 'utf-8')
56
+ ];
57
+ case 4:
58
+ content = _state.sent();
59
+ newEntry = {
60
+ content: content,
61
+ lastModified: currentModified
62
+ };
63
+ this.cache.set(filepath, newEntry, {
64
+ size: stat.size || content.length
65
+ });
66
+ return [
67
+ 2,
68
+ {
69
+ content: content,
70
+ lastModified: currentModified
71
+ }
72
+ ];
73
+ case 5:
74
+ _state.sent();
75
+ return [
76
+ 2,
77
+ null
78
+ ];
79
+ case 6:
80
+ return [
81
+ 2
82
+ ];
83
+ }
84
+ });
85
+ }).call(this);
86
+ };
87
+ return FileCache;
88
+ }();
89
+ var fileCache = new fileCache_FileCache();
90
+ export { fileCache_FileCache as FileCache, fileCache };
@@ -0,0 +1,36 @@
1
+ import { createCorsMiddleware, createStaticMiddleware } from "./staticMiddleware.mjs";
2
+ var staticServePlugin = function() {
3
+ return {
4
+ name: '@modern-js/module-federation/server',
5
+ setup: function(api) {
6
+ api.onPrepare(function() {
7
+ var _config_output, _config_server;
8
+ if ('development' === process.env.NODE_ENV) return;
9
+ var middlewares = api.getServerContext().middlewares;
10
+ var config = api.getServerConfig();
11
+ var assetPrefix = (null == (_config_output = config.output) ? void 0 : _config_output.assetPrefix) || '';
12
+ if (null == (_config_server = config.server) ? void 0 : _config_server.ssr) {
13
+ var context = api.getServerContext();
14
+ var pwd = context.distDirectory;
15
+ var serverStaticMiddleware = createStaticMiddleware({
16
+ assetPrefix: assetPrefix,
17
+ pwd: pwd
18
+ });
19
+ middlewares.push({
20
+ name: 'module-federation-serve-manifest',
21
+ handler: serverStaticMiddleware
22
+ });
23
+ }
24
+ if (process.env.MODERN_MF_AUTO_CORS) {
25
+ var corsMiddleware = createCorsMiddleware();
26
+ middlewares.push({
27
+ name: 'module-federation-cors',
28
+ handler: corsMiddleware
29
+ });
30
+ }
31
+ });
32
+ }
33
+ };
34
+ };
35
+ var server = staticServePlugin;
36
+ export { server as default, staticServePlugin };