@module-federation/modern-js 0.21.5 → 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
@@ -1,25 +0,0 @@
1
- var sharedStrategy = function() {
2
- return {
3
- name: "shared-strategy-plugin",
4
- beforeInit: function beforeInit(args) {
5
- var userOptions = args.userOptions;
6
- var shared = userOptions.shared;
7
- if (shared) {
8
- Object.keys(shared).forEach(function(sharedKey) {
9
- var sharedConfigs = shared[sharedKey];
10
- var arraySharedConfigs = Array.isArray(sharedConfigs) ? sharedConfigs : [
11
- sharedConfigs
12
- ];
13
- arraySharedConfigs.forEach(function(s) {
14
- s.strategy = "loaded-first";
15
- });
16
- });
17
- }
18
- return args;
19
- }
20
- };
21
- };
22
- var shared_strategy_default = sharedStrategy;
23
- export {
24
- shared_strategy_default as default
25
- };
@@ -1,20 +0,0 @@
1
- import dataFetchMiddleWare 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
- // @ts-ignore type error
11
- handler: dataFetchMiddleWare
12
- });
13
- });
14
- }
15
- };
16
- };
17
- var data_fetch_server_plugin_default = dataFetchServePlugin;
18
- export {
19
- data_fetch_server_plugin_default as default
20
- };
@@ -1,305 +0,0 @@
1
- import { _ as _async_to_generator } 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 from "fs-extra";
7
- import { ModuleFederationPlugin } from "@module-federation/enhanced/webpack";
8
- import { ModuleFederationPlugin as RspackModuleFederationPlugin } from "@module-federation/enhanced/rspack";
9
- import UniverseEntryChunkTrackerPlugin from "@module-federation/node/universe-entry-chunk-tracker-plugin";
10
- import logger from "../logger";
11
- import { isDev } from "./utils";
12
- import { updateStatsAndManifest } from "@module-federation/rsbuild-plugin/utils";
13
- import { ManifestFileName, StatsFileName, simpleJoinRemoteEntry } from "@module-federation/sdk";
14
- import { isWebTarget, skipByTarget } from "./utils";
15
- function setEnv() {
16
- process.env["MF_SSR_PRJ"] = "true";
17
- }
18
- var CHAIN_MF_PLUGIN_ID = "plugin-module-federation-server";
19
- function getManifestAssetFileNames(manifestOption) {
20
- if (!manifestOption) {
21
- return {
22
- statsFileName: StatsFileName,
23
- manifestFileName: ManifestFileName
24
- };
25
- }
26
- var JSON_EXT = ".json";
27
- var filePath = typeof manifestOption === "boolean" ? "" : manifestOption.filePath || "";
28
- var baseFileName = typeof manifestOption === "boolean" ? "" : manifestOption.fileName || "";
29
- var ensureExt = function(name) {
30
- return name.endsWith(JSON_EXT) ? name : "".concat(name).concat(JSON_EXT);
31
- };
32
- var withSuffix = function(name, suffix) {
33
- return name.replace(JSON_EXT, "".concat(suffix).concat(JSON_EXT));
34
- };
35
- var manifestFileName = baseFileName ? ensureExt(baseFileName) : ManifestFileName;
36
- var statsFileName = baseFileName ? withSuffix(manifestFileName, "-stats") : StatsFileName;
37
- return {
38
- statsFileName: simpleJoinRemoteEntry(filePath, statsFileName),
39
- manifestFileName: simpleJoinRemoteEntry(filePath, manifestFileName)
40
- };
41
- }
42
- var mfSSRRsbuildPlugin = function(pluginOptions) {
43
- return {
44
- name: "@modern-js/plugin-mf-post-config",
45
- pre: [
46
- "@modern-js/builder-plugin-ssr"
47
- ],
48
- setup: function setup(api) {
49
- var _pluginOptions_csrConfig, _pluginOptions_assetFileNames, _pluginOptions_ssrConfig;
50
- if (pluginOptions.csrConfig.getPublicPath) {
51
- return;
52
- }
53
- var csrOutputPath = "";
54
- var ssrOutputPath = "";
55
- var ssrEnv = "";
56
- var csrEnv = "";
57
- var browserAssetFileNames = pluginOptions.assetFileNames.browser || getManifestAssetFileNames((_pluginOptions_csrConfig = pluginOptions.csrConfig) === null || _pluginOptions_csrConfig === void 0 ? void 0 : _pluginOptions_csrConfig.manifest);
58
- var nodeAssetFileNames = ((_pluginOptions_assetFileNames = pluginOptions.assetFileNames) === null || _pluginOptions_assetFileNames === void 0 ? void 0 : _pluginOptions_assetFileNames.node) || getManifestAssetFileNames((_pluginOptions_ssrConfig = pluginOptions.ssrConfig) === null || _pluginOptions_ssrConfig === void 0 ? void 0 : _pluginOptions_ssrConfig.manifest);
59
- var collectAssets = function(assets, fileNames, tag) {
60
- var statsAsset = assets[fileNames.statsFileName];
61
- var manifestAsset = assets[fileNames.manifestFileName];
62
- if (!statsAsset || !manifestAsset) {
63
- return void 0;
64
- }
65
- try {
66
- var statsRaw = statsAsset.source();
67
- var manifestRaw = manifestAsset.source();
68
- var statsContent = typeof statsRaw === "string" ? statsRaw : statsRaw.toString();
69
- var manifestContent = typeof manifestRaw === "string" ? manifestRaw : manifestRaw.toString();
70
- return {
71
- stats: {
72
- data: JSON.parse(statsContent),
73
- filename: fileNames.statsFileName
74
- },
75
- manifest: {
76
- data: JSON.parse(manifestContent),
77
- filename: fileNames.manifestFileName
78
- }
79
- };
80
- } catch (err) {
81
- var message = _instanceof(err, Error) ? err.message : String(err);
82
- logger.error("Failed to parse ".concat(tag, " manifest assets: ").concat(message));
83
- return void 0;
84
- }
85
- };
86
- api.modifyEnvironmentConfig(function(config, param) {
87
- var name = param.name;
88
- var target = config.output.target;
89
- if (skipByTarget(target)) {
90
- return config;
91
- }
92
- if (isWebTarget(target)) {
93
- csrOutputPath = config.output.distPath.root;
94
- csrEnv = name;
95
- } else {
96
- ssrOutputPath = config.output.distPath.root;
97
- ssrEnv = name;
98
- }
99
- return config;
100
- });
101
- var modifySSRPublicPath = function(config, utils) {
102
- if (ssrEnv !== utils.environment.name) {
103
- return config;
104
- }
105
- var userSSRConfig = pluginOptions.userConfig.ssr ? _type_of(pluginOptions.userConfig.ssr) === "object" ? pluginOptions.userConfig.ssr : {} : {};
106
- if (userSSRConfig.distOutputDir) {
107
- return;
108
- }
109
- config.output.publicPath = "".concat(config.output.publicPath).concat(path.relative(csrOutputPath, ssrOutputPath), "/");
110
- return config;
111
- };
112
- api.modifyWebpackConfig(function(config, utils) {
113
- modifySSRPublicPath(config, utils);
114
- return config;
115
- });
116
- api.modifyRspackConfig(function(config, utils) {
117
- modifySSRPublicPath(config, utils);
118
- return config;
119
- });
120
- api.processAssets({
121
- stage: "report"
122
- }, function(param) {
123
- var assets = param.assets, envContext = param.environment;
124
- var _pluginOptions_csrConfig2, _pluginOptions_ssrConfig2;
125
- var envName = envContext.name;
126
- if (((_pluginOptions_csrConfig2 = pluginOptions.csrConfig) === null || _pluginOptions_csrConfig2 === void 0 ? void 0 : _pluginOptions_csrConfig2.manifest) !== false && csrEnv && envName === csrEnv) {
127
- var browserAssets = collectAssets(assets, browserAssetFileNames, "browser");
128
- if (browserAssets) {
129
- pluginOptions.assetResources.browser = browserAssets;
130
- }
131
- }
132
- if (((_pluginOptions_ssrConfig2 = pluginOptions.ssrConfig) === null || _pluginOptions_ssrConfig2 === void 0 ? void 0 : _pluginOptions_ssrConfig2.manifest) !== false && ssrEnv && envName === ssrEnv) {
133
- var nodeAssets = collectAssets(assets, nodeAssetFileNames, "node");
134
- if (nodeAssets) {
135
- pluginOptions.assetResources.node = nodeAssets;
136
- }
137
- }
138
- });
139
- }
140
- };
141
- };
142
- var moduleFederationSSRPlugin = function(pluginOptions) {
143
- return {
144
- name: "@modern-js/plugin-module-federation-ssr",
145
- pre: [
146
- "@modern-js/plugin-module-federation-config",
147
- "@modern-js/plugin-module-federation"
148
- ],
149
- setup: function() {
150
- var _ref = _async_to_generator(function(api) {
151
- var _pluginOptions_userConfig, _modernjsConfig_server, modernjsConfig, _pluginOptions_userConfig_ssr, enableSSR, writeMergedManifest;
152
- return _ts_generator(this, function(_state) {
153
- modernjsConfig = api.getConfig();
154
- 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);
155
- if (!enableSSR) {
156
- return [
157
- 2
158
- ];
159
- }
160
- setEnv();
161
- api._internalRuntimePlugins(function(param) {
162
- var entrypoint = param.entrypoint, plugins = param.plugins;
163
- var fetchServerQuery = pluginOptions.fetchServerQuery;
164
- plugins.push({
165
- name: "injectDataFetchFunction",
166
- path: "@module-federation/modern-js/ssr-inject-data-fetch-function-plugin",
167
- config: {
168
- fetchServerQuery
169
- }
170
- });
171
- if (!isDev()) {
172
- return {
173
- entrypoint,
174
- plugins
175
- };
176
- }
177
- plugins.push({
178
- name: "mfSSRDev",
179
- path: "@module-federation/modern-js/ssr-dev-plugin",
180
- config: {}
181
- });
182
- return {
183
- entrypoint,
184
- plugins
185
- };
186
- });
187
- if (pluginOptions.ssrConfig.remotes) {
188
- api._internalServerPlugins(function(param) {
189
- var plugins = param.plugins;
190
- plugins.push({
191
- name: "@module-federation/modern-js/data-fetch-server-plugin",
192
- options: {}
193
- });
194
- return {
195
- plugins
196
- };
197
- });
198
- }
199
- api.modifyBundlerChain(function(chain) {
200
- var target = chain.get("target");
201
- if (skipByTarget(target)) {
202
- return;
203
- }
204
- var bundlerType = api.getAppContext().bundlerType === "rspack" ? "rspack" : "webpack";
205
- var MFPlugin = bundlerType === "webpack" ? ModuleFederationPlugin : RspackModuleFederationPlugin;
206
- var isWeb = isWebTarget(target);
207
- if (!isWeb) {
208
- if (!chain.plugins.has(CHAIN_MF_PLUGIN_ID)) {
209
- chain.plugin(CHAIN_MF_PLUGIN_ID).use(MFPlugin, [
210
- pluginOptions.ssrConfig
211
- ]).init(function(Plugin, args) {
212
- pluginOptions.nodePlugin = new Plugin(args[0]);
213
- return pluginOptions.nodePlugin;
214
- });
215
- }
216
- }
217
- if (!isWeb) {
218
- chain.target("async-node");
219
- if (isDev()) {
220
- chain.plugin("UniverseEntryChunkTrackerPlugin").use(UniverseEntryChunkTrackerPlugin);
221
- }
222
- var userSSRConfig = pluginOptions.userConfig.ssr ? _type_of(pluginOptions.userConfig.ssr) === "object" ? pluginOptions.userConfig.ssr : {} : {};
223
- var publicPath = chain.output.get("publicPath");
224
- if (userSSRConfig.distOutputDir && publicPath) {
225
- chain.output.publicPath("".concat(publicPath).concat(userSSRConfig.distOutputDir, "/"));
226
- }
227
- }
228
- if (isDev() && isWeb) {
229
- chain.externals({
230
- "@module-federation/node/utils": "NOT_USED_IN_BROWSER"
231
- });
232
- }
233
- });
234
- api.config(function() {
235
- return {
236
- builderPlugins: [
237
- mfSSRRsbuildPlugin(pluginOptions)
238
- ],
239
- tools: {
240
- devServer: {
241
- before: [
242
- function(req, res, next) {
243
- if (!enableSSR) {
244
- next();
245
- return;
246
- }
247
- try {
248
- var _req_url, _req_url1;
249
- 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"))) {
250
- var filepath = path.join(process.cwd(), "dist".concat(req.url));
251
- fs.statSync(filepath);
252
- res.setHeader("Access-Control-Allow-Origin", "*");
253
- res.setHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, PATCH, OPTIONS");
254
- res.setHeader("Access-Control-Allow-Headers", "*");
255
- fs.createReadStream(filepath).pipe(res);
256
- } else {
257
- next();
258
- }
259
- } catch (err) {
260
- logger.debug(err);
261
- next();
262
- }
263
- }
264
- ]
265
- }
266
- }
267
- };
268
- });
269
- writeMergedManifest = function() {
270
- var distOutputDir = pluginOptions.distOutputDir, assetResources = pluginOptions.assetResources;
271
- var browserAssets = assetResources.browser;
272
- var nodeAssets = assetResources.node;
273
- if (!distOutputDir || !browserAssets || !nodeAssets) {
274
- return;
275
- }
276
- try {
277
- updateStatsAndManifest(nodeAssets, browserAssets, distOutputDir);
278
- } catch (err) {
279
- logger.error(err);
280
- }
281
- };
282
- api.onAfterBuild(function() {
283
- writeMergedManifest();
284
- });
285
- api.onDevCompileDone(function() {
286
- writeMergedManifest();
287
- });
288
- return [
289
- 2
290
- ];
291
- });
292
- });
293
- return function(api) {
294
- return _ref.apply(this, arguments);
295
- };
296
- }()
297
- };
298
- };
299
- var ssrPlugin_default = moduleFederationSSRPlugin;
300
- export {
301
- CHAIN_MF_PLUGIN_ID,
302
- ssrPlugin_default as default,
303
- moduleFederationSSRPlugin,
304
- setEnv
305
- };
@@ -1,53 +0,0 @@
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
- detail === null || detail === void 0 ? void 0 : detail.forEach(function(detail2) {
9
- var familyV4Value = typeof detail2.family === "string" ? "IPv4" : 4;
10
- if (detail2.family === familyV4Value && detail2.address !== localIpv4) {
11
- ipv4Interfaces.push(detail2);
12
- }
13
- });
14
- });
15
- return ipv4Interfaces;
16
- } catch (_err) {
17
- return [];
18
- }
19
- };
20
- var getIPV4 = function() {
21
- var ipv4Interfaces = getIpv4Interfaces();
22
- var ipv4Interface = ipv4Interfaces[0] || {
23
- address: localIpv4
24
- };
25
- return ipv4Interface.address;
26
- };
27
- var isWebTarget = function(target) {
28
- var WEB_TARGET = "web";
29
- if (Array.isArray(target)) {
30
- return target.includes(WEB_TARGET);
31
- } else if (typeof target === "string") {
32
- return target === WEB_TARGET;
33
- }
34
- return false;
35
- };
36
- var skipByTarget = function(target) {
37
- var IGNORE_TARGET = "webworker";
38
- if (Array.isArray(target)) {
39
- return target.includes(IGNORE_TARGET);
40
- } else if (typeof target === "string") {
41
- return target === IGNORE_TARGET;
42
- }
43
- return false;
44
- };
45
- function isDev() {
46
- return process.env.NODE_ENV === "development";
47
- }
48
- export {
49
- getIPV4,
50
- isDev,
51
- isWebTarget,
52
- skipByTarget
53
- };
@@ -1,6 +0,0 @@
1
- var LOCALHOST = "localhost";
2
- var PLUGIN_IDENTIFIER = "[ Modern.js Module Federation ]";
3
- export {
4
- LOCALHOST,
5
- PLUGIN_IDENTIFIER
6
- };
@@ -1,7 +0,0 @@
1
- import { createLogger } from "@module-federation/sdk";
2
- import { PLUGIN_IDENTIFIER } from "./constant";
3
- var logger = createLogger(PLUGIN_IDENTIFIER);
4
- var logger_default = logger;
5
- export {
6
- logger_default as default
7
- };
@@ -1,5 +0,0 @@
1
- export * from "@module-federation/bridge-react/plugin";
2
- import { default as default2 } from "@module-federation/bridge-react/plugin";
3
- export {
4
- default2 as default
5
- };
@@ -1,98 +0,0 @@
1
- import { _ as _async_to_generator } 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 from "fs-extra";
5
- import { LRUCache } from "lru-cache";
6
- var FileCache = /* @__PURE__ */ function() {
7
- "use strict";
8
- function FileCache2() {
9
- _class_call_check(this, FileCache2);
10
- this.cache = new LRUCache({
11
- maxSize: 200 * 1024 * 1024
12
- });
13
- }
14
- var _proto = FileCache2.prototype;
15
- _proto.getFile = function getFile(filepath) {
16
- var _this = this;
17
- return _async_to_generator(function() {
18
- var stat, currentModified, cachedEntry, content, newEntry, err;
19
- return _ts_generator(this, function(_state) {
20
- switch (_state.label) {
21
- case 0:
22
- return [
23
- 4,
24
- fs.pathExists(filepath)
25
- ];
26
- case 1:
27
- if (!_state.sent()) {
28
- return [
29
- 2,
30
- null
31
- ];
32
- }
33
- _state.label = 2;
34
- case 2:
35
- _state.trys.push([
36
- 2,
37
- 5,
38
- ,
39
- 6
40
- ]);
41
- return [
42
- 4,
43
- fs.lstat(filepath)
44
- ];
45
- case 3:
46
- stat = _state.sent();
47
- currentModified = stat.mtimeMs;
48
- cachedEntry = _this.cache.get(filepath);
49
- if (cachedEntry && currentModified <= cachedEntry.lastModified) {
50
- return [
51
- 2,
52
- {
53
- content: cachedEntry.content,
54
- lastModified: cachedEntry.lastModified
55
- }
56
- ];
57
- }
58
- return [
59
- 4,
60
- fs.readFile(filepath, "utf-8")
61
- ];
62
- case 4:
63
- content = _state.sent();
64
- newEntry = {
65
- content,
66
- lastModified: currentModified
67
- };
68
- _this.cache.set(filepath, newEntry, {
69
- size: stat.size || content.length
70
- });
71
- return [
72
- 2,
73
- {
74
- content,
75
- lastModified: currentModified
76
- }
77
- ];
78
- case 5:
79
- err = _state.sent();
80
- return [
81
- 2,
82
- null
83
- ];
84
- case 6:
85
- return [
86
- 2
87
- ];
88
- }
89
- });
90
- })();
91
- };
92
- return FileCache2;
93
- }();
94
- var fileCache = new FileCache();
95
- export {
96
- FileCache,
97
- fileCache
98
- };
@@ -1,50 +0,0 @@
1
- import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
- import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
3
- import { it, expect, describe, vi, beforeAll } from "vitest";
4
- import { FileCache } from "./fileCache";
5
- beforeAll(function() {
6
- vi.mock("fs-extra", function() {
7
- return {
8
- default: {
9
- pathExists: function() {
10
- return true;
11
- },
12
- lstat: function() {
13
- return {
14
- mtimeMs: Date.now(),
15
- size: 4
16
- };
17
- },
18
- readFile: function() {
19
- return "test";
20
- }
21
- }
22
- };
23
- });
24
- });
25
- describe("modern serve static file cache", /* @__PURE__ */ _async_to_generator(function() {
26
- return _ts_generator(this, function(_state) {
27
- it("should cache file", /* @__PURE__ */ _async_to_generator(function() {
28
- var cache, result;
29
- return _ts_generator(this, function(_state2) {
30
- switch (_state2.label) {
31
- case 0:
32
- cache = new FileCache();
33
- return [
34
- 4,
35
- cache.getFile("test.txt")
36
- ];
37
- case 1:
38
- result = _state2.sent();
39
- expect(result === null || result === void 0 ? void 0 : result.content).toBe("test");
40
- return [
41
- 2
42
- ];
43
- }
44
- });
45
- }));
46
- return [
47
- 2
48
- ];
49
- });
50
- }));
@@ -1,41 +0,0 @@
1
- import { createCorsMiddleware, createStaticMiddleware } from "./staticMiddleware";
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 (process.env.NODE_ENV === "development") {
9
- return;
10
- }
11
- var middlewares = api.getServerContext().middlewares;
12
- var config = api.getServerConfig();
13
- var assetPrefix = ((_config_output = config.output) === null || _config_output === void 0 ? void 0 : _config_output.assetPrefix) || "";
14
- if ((_config_server = config.server) === null || _config_server === void 0 ? void 0 : _config_server.ssr) {
15
- var context = api.getServerContext();
16
- var pwd = context.distDirectory;
17
- var serverStaticMiddleware = createStaticMiddleware({
18
- assetPrefix,
19
- pwd
20
- });
21
- middlewares.push({
22
- name: "module-federation-serve-manifest",
23
- handler: serverStaticMiddleware
24
- });
25
- }
26
- if (process.env.MODERN_MF_AUTO_CORS) {
27
- var corsMiddleware = createCorsMiddleware();
28
- middlewares.push({
29
- name: "module-federation-cors",
30
- handler: corsMiddleware
31
- });
32
- }
33
- });
34
- }
35
- };
36
- };
37
- var server_default = staticServePlugin;
38
- export {
39
- server_default as default,
40
- staticServePlugin
41
- };