@module-federation/modern-js 0.0.0-chore-bump-node-22-20260710161714
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.
- package/LICENSE +21 -0
- package/README.md +5 -0
- package/dist/cjs/cli/configPlugin.js +346 -0
- package/dist/cjs/cli/index.js +115 -0
- package/dist/cjs/cli/mfRuntimePlugins/inject-node-fetch.js +54 -0
- package/dist/cjs/cli/mfRuntimePlugins/shared-strategy.js +53 -0
- package/dist/cjs/cli/server/data-fetch-server-plugin.js +59 -0
- package/dist/cjs/cli/ssrPlugin.js +314 -0
- package/dist/cjs/cli/utils.js +93 -0
- package/dist/cjs/constant.js +40 -0
- package/dist/cjs/interfaces/bundler.js +18 -0
- package/dist/cjs/logger.js +39 -0
- package/dist/cjs/react/data-fetch.js +58 -0
- package/dist/cjs/react/index.js +58 -0
- package/dist/cjs/react/plugin.js +65 -0
- package/dist/cjs/react/v18.js +58 -0
- package/dist/cjs/react/v19.js +58 -0
- package/dist/cjs/runtime/index.js +58 -0
- package/dist/cjs/server/fileCache.js +82 -0
- package/dist/cjs/server/index.js +71 -0
- package/dist/cjs/server/staticMiddleware.js +97 -0
- package/dist/cjs/ssr-runtime/SSRLiveReload.js +50 -0
- package/dist/cjs/ssr-runtime/devPlugin.js +67 -0
- package/dist/cjs/ssr-runtime/injectDataFetchFunctionPlugin.js +47 -0
- package/dist/cjs/types/index.js +18 -0
- package/dist/esm/cli/configPlugin.mjs +321 -0
- package/dist/esm/cli/index.mjs +91 -0
- package/dist/esm/cli/mfRuntimePlugins/inject-node-fetch.mjs +12 -0
- package/dist/esm/cli/mfRuntimePlugins/shared-strategy.mjs +21 -0
- package/dist/esm/cli/server/data-fetch-server-plugin.mjs +17 -0
- package/dist/esm/cli/ssrPlugin.mjs +297 -0
- package/dist/esm/cli/utils.mjs +40 -0
- package/dist/esm/constant.mjs +3 -0
- package/dist/esm/interfaces/bundler.mjs +0 -0
- package/dist/esm/logger.mjs +5 -0
- package/dist/esm/react/data-fetch.mjs +1 -0
- package/dist/esm/react/index.mjs +1 -0
- package/dist/esm/react/plugin.mjs +3 -0
- package/dist/esm/react/v18.mjs +1 -0
- package/dist/esm/react/v19.mjs +1 -0
- package/dist/esm/runtime/index.mjs +1 -0
- package/dist/esm/server/fileCache.mjs +125 -0
- package/dist/esm/server/index.mjs +36 -0
- package/dist/esm/server/staticMiddleware.mjs +122 -0
- package/dist/esm/ssr-runtime/SSRLiveReload.mjs +23 -0
- package/dist/esm/ssr-runtime/devPlugin.mjs +70 -0
- package/dist/esm/ssr-runtime/injectDataFetchFunctionPlugin.mjs +33 -0
- package/dist/esm/types/index.mjs +0 -0
- package/dist/esm-node/cli/configPlugin.mjs +276 -0
- package/dist/esm-node/cli/index.mjs +75 -0
- package/dist/esm-node/cli/mfRuntimePlugins/inject-node-fetch.mjs +10 -0
- package/dist/esm-node/cli/mfRuntimePlugins/shared-strategy.mjs +19 -0
- package/dist/esm-node/cli/server/data-fetch-server-plugin.mjs +15 -0
- package/dist/esm-node/cli/ssrPlugin.mjs +258 -0
- package/dist/esm-node/cli/utils.mjs +40 -0
- package/dist/esm-node/constant.mjs +3 -0
- package/dist/esm-node/interfaces/bundler.mjs +0 -0
- package/dist/esm-node/logger.mjs +5 -0
- package/dist/esm-node/react/data-fetch.mjs +1 -0
- package/dist/esm-node/react/index.mjs +1 -0
- package/dist/esm-node/react/plugin.mjs +3 -0
- package/dist/esm-node/react/v18.mjs +1 -0
- package/dist/esm-node/react/v19.mjs +1 -0
- package/dist/esm-node/runtime/index.mjs +1 -0
- package/dist/esm-node/server/fileCache.mjs +45 -0
- package/dist/esm-node/server/index.mjs +34 -0
- package/dist/esm-node/server/staticMiddleware.mjs +50 -0
- package/dist/esm-node/ssr-runtime/SSRLiveReload.mjs +16 -0
- package/dist/esm-node/ssr-runtime/devPlugin.mjs +33 -0
- package/dist/esm-node/ssr-runtime/injectDataFetchFunctionPlugin.mjs +13 -0
- package/dist/esm-node/types/index.mjs +0 -0
- package/dist/types/cli/configPlugin.d.ts +21 -0
- package/dist/types/cli/configPlugin.spec.d.ts +1 -0
- package/dist/types/cli/index.d.ts +6 -0
- package/dist/types/cli/mfRuntimePlugins/inject-node-fetch.d.ts +3 -0
- package/dist/types/cli/mfRuntimePlugins/shared-strategy.d.ts +3 -0
- package/dist/types/cli/server/data-fetch-server-plugin.d.ts +3 -0
- package/dist/types/cli/ssrPlugin.d.ts +6 -0
- package/dist/types/cli/ssrPlugin.spec.d.ts +1 -0
- package/dist/types/cli/utils.d.ts +6 -0
- package/dist/types/constant.d.ts +2 -0
- package/dist/types/interfaces/bundler.d.ts +18 -0
- package/dist/types/logger.d.ts +2 -0
- package/dist/types/react/data-fetch.d.ts +1 -0
- package/dist/types/react/index.d.ts +1 -0
- package/dist/types/react/plugin.d.ts +2 -0
- package/dist/types/react/v18.d.ts +1 -0
- package/dist/types/react/v19.d.ts +1 -0
- package/dist/types/runtime/index.d.ts +1 -0
- package/dist/types/server/fileCache.d.ts +14 -0
- package/dist/types/server/fileCache.spec.d.ts +1 -0
- package/dist/types/server/index.d.ts +4 -0
- package/dist/types/server/staticMiddleware.d.ts +7 -0
- package/dist/types/server/staticMiddleware.spec.d.ts +1 -0
- package/dist/types/ssr-runtime/SSRLiveReload.d.ts +2 -0
- package/dist/types/ssr-runtime/devPlugin.d.ts +2 -0
- package/dist/types/ssr-runtime/injectDataFetchFunctionPlugin.d.ts +4 -0
- package/dist/types/types/index.d.ts +35 -0
- package/package.json +192 -0
- package/types.d.ts +6 -0
|
@@ -0,0 +1,297 @@
|
|
|
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 from "fs";
|
|
7
|
+
import { ModuleFederationPlugin, TreeShakingSharedPlugin as enhanced_TreeShakingSharedPlugin } from "@module-federation/enhanced";
|
|
8
|
+
import { ModuleFederationPlugin as rspack_ModuleFederationPlugin, TreeShakingSharedPlugin as rspack_TreeShakingSharedPlugin } 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 STATIC_ASSET_MODULE_TYPES = [
|
|
40
|
+
'asset',
|
|
41
|
+
'asset/resource'
|
|
42
|
+
];
|
|
43
|
+
var ssrPlugin_preserveStaticAssetPublicPath = function(config, publicPath) {
|
|
44
|
+
var _config, _moduleConfig;
|
|
45
|
+
if ('string' != typeof publicPath || '' === publicPath || 'auto' === publicPath) return;
|
|
46
|
+
(_config = config).module || (_config.module = {});
|
|
47
|
+
var moduleConfig = config.module;
|
|
48
|
+
(_moduleConfig = moduleConfig).generator || (_moduleConfig.generator = {});
|
|
49
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
|
|
50
|
+
try {
|
|
51
|
+
for(var _iterator = STATIC_ASSET_MODULE_TYPES[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
52
|
+
var moduleType = _step.value;
|
|
53
|
+
var _moduleConfig_generator, _moduleType, _moduleConfig_generator_moduleType;
|
|
54
|
+
(_moduleConfig_generator = moduleConfig.generator)[_moduleType = moduleType] || (_moduleConfig_generator[_moduleType] = {});
|
|
55
|
+
null != (_moduleConfig_generator_moduleType = moduleConfig.generator[moduleType]).publicPath || (_moduleConfig_generator_moduleType.publicPath = publicPath);
|
|
56
|
+
}
|
|
57
|
+
} catch (err) {
|
|
58
|
+
_didIteratorError = true;
|
|
59
|
+
_iteratorError = err;
|
|
60
|
+
} finally{
|
|
61
|
+
try {
|
|
62
|
+
if (!_iteratorNormalCompletion && null != _iterator.return) _iterator.return();
|
|
63
|
+
} finally{
|
|
64
|
+
if (_didIteratorError) throw _iteratorError;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
var ssrPlugin_mfSSRRsbuildPlugin = function(pluginOptions) {
|
|
69
|
+
return {
|
|
70
|
+
name: '@modern-js/plugin-mf-post-config',
|
|
71
|
+
pre: [
|
|
72
|
+
'@modern-js/builder-plugin-ssr'
|
|
73
|
+
],
|
|
74
|
+
setup: function(api) {
|
|
75
|
+
var _pluginOptions_csrConfig, _pluginOptions_assetFileNames, _pluginOptions_ssrConfig;
|
|
76
|
+
if (pluginOptions.csrConfig.getPublicPath) return;
|
|
77
|
+
var csrOutputPath = '';
|
|
78
|
+
var ssrOutputPath = '';
|
|
79
|
+
var ssrEnv = '';
|
|
80
|
+
var csrEnv = '';
|
|
81
|
+
var browserAssetFileNames = pluginOptions.assetFileNames.browser || getManifestAssetFileNames(null == (_pluginOptions_csrConfig = pluginOptions.csrConfig) ? void 0 : _pluginOptions_csrConfig.manifest);
|
|
82
|
+
var nodeAssetFileNames = (null == (_pluginOptions_assetFileNames = pluginOptions.assetFileNames) ? void 0 : _pluginOptions_assetFileNames.node) || getManifestAssetFileNames(null == (_pluginOptions_ssrConfig = pluginOptions.ssrConfig) ? void 0 : _pluginOptions_ssrConfig.manifest);
|
|
83
|
+
var collectAssets = function(assets, fileNames, tag) {
|
|
84
|
+
var statsAsset = assets[fileNames.statsFileName];
|
|
85
|
+
var manifestAsset = assets[fileNames.manifestFileName];
|
|
86
|
+
if (!statsAsset || !manifestAsset) return;
|
|
87
|
+
try {
|
|
88
|
+
var statsRaw = statsAsset.source();
|
|
89
|
+
var manifestRaw = manifestAsset.source();
|
|
90
|
+
var statsContent = 'string' == typeof statsRaw ? statsRaw : statsRaw.toString();
|
|
91
|
+
var manifestContent = 'string' == typeof manifestRaw ? manifestRaw : manifestRaw.toString();
|
|
92
|
+
return {
|
|
93
|
+
stats: {
|
|
94
|
+
data: JSON.parse(statsContent),
|
|
95
|
+
filename: fileNames.statsFileName
|
|
96
|
+
},
|
|
97
|
+
manifest: {
|
|
98
|
+
data: JSON.parse(manifestContent),
|
|
99
|
+
filename: fileNames.manifestFileName
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
} catch (err) {
|
|
103
|
+
var message = _instanceof__(err, Error) ? err.message : String(err);
|
|
104
|
+
logger.error("Failed to parse ".concat(tag, " manifest assets: ").concat(message));
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
api.modifyEnvironmentConfig(function(config, param) {
|
|
109
|
+
var name = param.name;
|
|
110
|
+
var target = config.output.target;
|
|
111
|
+
if (skipByTarget(target)) return config;
|
|
112
|
+
if (isWebTarget(target)) {
|
|
113
|
+
csrOutputPath = config.output.distPath.root;
|
|
114
|
+
csrEnv = name;
|
|
115
|
+
} else {
|
|
116
|
+
ssrOutputPath = config.output.distPath.root;
|
|
117
|
+
ssrEnv = name;
|
|
118
|
+
}
|
|
119
|
+
return config;
|
|
120
|
+
});
|
|
121
|
+
var modifySSRPublicPath = function(config, utils) {
|
|
122
|
+
if (ssrEnv !== utils.environment.name) return config;
|
|
123
|
+
var userSSRConfig = pluginOptions.userConfig.ssr ? 'object' === _type_of__(pluginOptions.userConfig.ssr) ? pluginOptions.userConfig.ssr : {} : {};
|
|
124
|
+
if (!userSSRConfig.distOutputDir) return;
|
|
125
|
+
var publicPath = config.output.publicPath;
|
|
126
|
+
ssrPlugin_preserveStaticAssetPublicPath(config, publicPath);
|
|
127
|
+
config.output.publicPath = "".concat(publicPath).concat(path.relative(csrOutputPath, ssrOutputPath), "/");
|
|
128
|
+
return config;
|
|
129
|
+
};
|
|
130
|
+
api.modifyWebpackConfig(function(config, utils) {
|
|
131
|
+
modifySSRPublicPath(config, utils);
|
|
132
|
+
return config;
|
|
133
|
+
});
|
|
134
|
+
api.modifyRspackConfig(function(config, utils) {
|
|
135
|
+
modifySSRPublicPath(config, utils);
|
|
136
|
+
return config;
|
|
137
|
+
});
|
|
138
|
+
api.processAssets({
|
|
139
|
+
stage: 'report'
|
|
140
|
+
}, function(param) {
|
|
141
|
+
var assets = param.assets, envContext = param.environment;
|
|
142
|
+
var _pluginOptions_csrConfig, _pluginOptions_ssrConfig;
|
|
143
|
+
var envName = envContext.name;
|
|
144
|
+
if ((null == (_pluginOptions_csrConfig = pluginOptions.csrConfig) ? void 0 : _pluginOptions_csrConfig.manifest) !== false && csrEnv && envName === csrEnv) {
|
|
145
|
+
var browserAssets = collectAssets(assets, browserAssetFileNames, 'browser');
|
|
146
|
+
if (browserAssets) pluginOptions.assetResources.browser = browserAssets;
|
|
147
|
+
}
|
|
148
|
+
if ((null == (_pluginOptions_ssrConfig = pluginOptions.ssrConfig) ? void 0 : _pluginOptions_ssrConfig.manifest) !== false && ssrEnv && envName === ssrEnv) {
|
|
149
|
+
var nodeAssets = collectAssets(assets, nodeAssetFileNames, 'node');
|
|
150
|
+
if (nodeAssets) pluginOptions.assetResources.node = nodeAssets;
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
};
|
|
156
|
+
var ssrPlugin_moduleFederationSSRPlugin = function(pluginOptions) {
|
|
157
|
+
return {
|
|
158
|
+
name: '@modern-js/plugin-module-federation-ssr',
|
|
159
|
+
pre: [
|
|
160
|
+
'@modern-js/plugin-module-federation-config',
|
|
161
|
+
'@modern-js/plugin-module-federation'
|
|
162
|
+
],
|
|
163
|
+
setup: function(api) {
|
|
164
|
+
return _(function() {
|
|
165
|
+
var _ref, _pluginOptions_userConfig, _modernjsConfig_server, modernjsConfig, enableSSR, secondarySharedTreeShaking, writeMergedManifest;
|
|
166
|
+
return _ts_generator__(this, function(_state) {
|
|
167
|
+
modernjsConfig = api.getConfig();
|
|
168
|
+
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);
|
|
169
|
+
secondarySharedTreeShaking = pluginOptions.secondarySharedTreeShaking;
|
|
170
|
+
if (!enableSSR) return [
|
|
171
|
+
2
|
|
172
|
+
];
|
|
173
|
+
setEnv();
|
|
174
|
+
api._internalRuntimePlugins(function(param) {
|
|
175
|
+
var entrypoint = param.entrypoint, plugins = param.plugins;
|
|
176
|
+
if (secondarySharedTreeShaking) return {
|
|
177
|
+
entrypoint: entrypoint,
|
|
178
|
+
plugins: plugins
|
|
179
|
+
};
|
|
180
|
+
var fetchServerQuery = pluginOptions.fetchServerQuery;
|
|
181
|
+
plugins.push({
|
|
182
|
+
name: 'injectDataFetchFunction',
|
|
183
|
+
path: '@module-federation/modern-js/ssr-inject-data-fetch-function-plugin',
|
|
184
|
+
config: {
|
|
185
|
+
fetchServerQuery: fetchServerQuery
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
if (!isDev()) return {
|
|
189
|
+
entrypoint: entrypoint,
|
|
190
|
+
plugins: plugins
|
|
191
|
+
};
|
|
192
|
+
plugins.push({
|
|
193
|
+
name: 'mfSSRDev',
|
|
194
|
+
path: '@module-federation/modern-js/ssr-dev-plugin',
|
|
195
|
+
config: {}
|
|
196
|
+
});
|
|
197
|
+
return {
|
|
198
|
+
entrypoint: entrypoint,
|
|
199
|
+
plugins: plugins
|
|
200
|
+
};
|
|
201
|
+
});
|
|
202
|
+
if (pluginOptions.ssrConfig.remotes) api._internalServerPlugins(function(param) {
|
|
203
|
+
var plugins = param.plugins;
|
|
204
|
+
plugins.push({
|
|
205
|
+
name: '@module-federation/modern-js/data-fetch-server-plugin',
|
|
206
|
+
options: {}
|
|
207
|
+
});
|
|
208
|
+
return {
|
|
209
|
+
plugins: plugins
|
|
210
|
+
};
|
|
211
|
+
});
|
|
212
|
+
api.modifyBundlerChain(function(chain) {
|
|
213
|
+
var target = chain.get('target');
|
|
214
|
+
if (skipByTarget(target)) return;
|
|
215
|
+
var bundlerType = 'rspack' === api.getAppContext().bundlerType ? 'rspack' : 'webpack';
|
|
216
|
+
var MFPlugin = 'webpack' === bundlerType ? ModuleFederationPlugin : rspack_ModuleFederationPlugin;
|
|
217
|
+
var TreeShakingSharedPlugin = 'webpack' === bundlerType ? enhanced_TreeShakingSharedPlugin : rspack_TreeShakingSharedPlugin;
|
|
218
|
+
var isWeb = isWebTarget(target);
|
|
219
|
+
if (!isWeb) {
|
|
220
|
+
if (!chain.plugins.has(CHAIN_MF_PLUGIN_ID)) if (secondarySharedTreeShaking) chain.plugin(CHAIN_MF_PLUGIN_ID).use(TreeShakingSharedPlugin, [
|
|
221
|
+
{
|
|
222
|
+
mfConfig: pluginOptions.ssrConfig,
|
|
223
|
+
secondary: true
|
|
224
|
+
}
|
|
225
|
+
]);
|
|
226
|
+
else chain.plugin(CHAIN_MF_PLUGIN_ID).use(MFPlugin, [
|
|
227
|
+
pluginOptions.ssrConfig
|
|
228
|
+
]).init(function(Plugin, args) {
|
|
229
|
+
pluginOptions.nodePlugin = new Plugin(args[0]);
|
|
230
|
+
return pluginOptions.nodePlugin;
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
if (!isWeb && !secondarySharedTreeShaking) {
|
|
234
|
+
chain.target('async-node');
|
|
235
|
+
if (isDev()) chain.plugin('UniverseEntryChunkTrackerPlugin').use(universe_entry_chunk_tracker_plugin);
|
|
236
|
+
}
|
|
237
|
+
if (isDev() && isWeb) chain.externals({
|
|
238
|
+
'@module-federation/node/utils': 'NOT_USED_IN_BROWSER'
|
|
239
|
+
});
|
|
240
|
+
});
|
|
241
|
+
api.config(function() {
|
|
242
|
+
return {
|
|
243
|
+
builderPlugins: [
|
|
244
|
+
ssrPlugin_mfSSRRsbuildPlugin(pluginOptions)
|
|
245
|
+
],
|
|
246
|
+
tools: {
|
|
247
|
+
devServer: {
|
|
248
|
+
before: [
|
|
249
|
+
function(req, res, next) {
|
|
250
|
+
if (!enableSSR) return void next();
|
|
251
|
+
try {
|
|
252
|
+
var _req_url, _req_url1;
|
|
253
|
+
if ((null == (_req_url = req.url) ? void 0 : _req_url.includes('.json')) && !(null == (_req_url1 = req.url) ? void 0 : _req_url1.includes('hot-update'))) {
|
|
254
|
+
var filepath = path.join(process.cwd(), "dist".concat(req.url));
|
|
255
|
+
fs.statSync(filepath);
|
|
256
|
+
res.setHeader('Access-Control-Allow-Origin', '*');
|
|
257
|
+
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, PATCH, OPTIONS');
|
|
258
|
+
res.setHeader('Access-Control-Allow-Headers', '*');
|
|
259
|
+
fs.createReadStream(filepath).pipe(res);
|
|
260
|
+
} else next();
|
|
261
|
+
} catch (err) {
|
|
262
|
+
logger.debug(err);
|
|
263
|
+
next();
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
]
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
};
|
|
270
|
+
});
|
|
271
|
+
writeMergedManifest = function() {
|
|
272
|
+
var distOutputDir = pluginOptions.distOutputDir, assetResources = pluginOptions.assetResources;
|
|
273
|
+
var browserAssets = assetResources.browser;
|
|
274
|
+
var nodeAssets = assetResources.node;
|
|
275
|
+
if (!distOutputDir || !browserAssets || !nodeAssets) return;
|
|
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
|
+
}
|
|
294
|
+
};
|
|
295
|
+
};
|
|
296
|
+
var ssrPlugin = ssrPlugin_moduleFederationSSRPlugin;
|
|
297
|
+
export { CHAIN_MF_PLUGIN_ID, ssrPlugin as default, ssrPlugin_moduleFederationSSRPlugin as moduleFederationSSRPlugin, setEnv };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import os from "os";
|
|
2
|
+
var localIpv4 = '127.0.0.1';
|
|
3
|
+
var utils_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 utils_getIPV4 = function() {
|
|
19
|
+
var ipv4Interfaces = utils_getIpv4Interfaces();
|
|
20
|
+
var ipv4Interface = ipv4Interfaces[0] || {
|
|
21
|
+
address: localIpv4
|
|
22
|
+
};
|
|
23
|
+
return ipv4Interface.address;
|
|
24
|
+
};
|
|
25
|
+
var utils_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 utils_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 { utils_getIPV4 as getIPV4, isDev, utils_isWebTarget as isWebTarget, utils_skipByTarget as skipByTarget };
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "@module-federation/bridge-react/data-fetch";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "@module-federation/bridge-react";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "@module-federation/bridge-react/v18";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "@module-federation/bridge-react/v19";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "@module-federation/enhanced/runtime";
|
|
@@ -0,0 +1,125 @@
|
|
|
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 { access, lstat, readFile } from "fs/promises";
|
|
5
|
+
import { LRUCache } from "lru-cache";
|
|
6
|
+
var fileCache_pathExists = function(filepath) {
|
|
7
|
+
return _(function() {
|
|
8
|
+
return _ts_generator__(this, function(_state) {
|
|
9
|
+
switch(_state.label){
|
|
10
|
+
case 0:
|
|
11
|
+
_state.trys.push([
|
|
12
|
+
0,
|
|
13
|
+
2,
|
|
14
|
+
,
|
|
15
|
+
3
|
|
16
|
+
]);
|
|
17
|
+
return [
|
|
18
|
+
4,
|
|
19
|
+
access(filepath)
|
|
20
|
+
];
|
|
21
|
+
case 1:
|
|
22
|
+
_state.sent();
|
|
23
|
+
return [
|
|
24
|
+
2,
|
|
25
|
+
true
|
|
26
|
+
];
|
|
27
|
+
case 2:
|
|
28
|
+
_state.sent();
|
|
29
|
+
return [
|
|
30
|
+
2,
|
|
31
|
+
false
|
|
32
|
+
];
|
|
33
|
+
case 3:
|
|
34
|
+
return [
|
|
35
|
+
2
|
|
36
|
+
];
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
})();
|
|
40
|
+
};
|
|
41
|
+
var fileCache_FileCache = /*#__PURE__*/ function() {
|
|
42
|
+
"use strict";
|
|
43
|
+
function FileCache() {
|
|
44
|
+
_class_call_check__(this, FileCache);
|
|
45
|
+
this.cache = new LRUCache({
|
|
46
|
+
maxSize: 209715200
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
var _proto = FileCache.prototype;
|
|
50
|
+
_proto.getFile = function(filepath) {
|
|
51
|
+
return _(function() {
|
|
52
|
+
var stat, currentModified, cachedEntry, content, newEntry;
|
|
53
|
+
return _ts_generator__(this, function(_state) {
|
|
54
|
+
switch(_state.label){
|
|
55
|
+
case 0:
|
|
56
|
+
return [
|
|
57
|
+
4,
|
|
58
|
+
fileCache_pathExists(filepath)
|
|
59
|
+
];
|
|
60
|
+
case 1:
|
|
61
|
+
if (!_state.sent()) return [
|
|
62
|
+
2,
|
|
63
|
+
null
|
|
64
|
+
];
|
|
65
|
+
_state.label = 2;
|
|
66
|
+
case 2:
|
|
67
|
+
_state.trys.push([
|
|
68
|
+
2,
|
|
69
|
+
5,
|
|
70
|
+
,
|
|
71
|
+
6
|
|
72
|
+
]);
|
|
73
|
+
return [
|
|
74
|
+
4,
|
|
75
|
+
lstat(filepath)
|
|
76
|
+
];
|
|
77
|
+
case 3:
|
|
78
|
+
stat = _state.sent();
|
|
79
|
+
currentModified = stat.mtimeMs;
|
|
80
|
+
cachedEntry = this.cache.get(filepath);
|
|
81
|
+
if (cachedEntry && currentModified <= cachedEntry.lastModified) return [
|
|
82
|
+
2,
|
|
83
|
+
{
|
|
84
|
+
content: cachedEntry.content,
|
|
85
|
+
lastModified: cachedEntry.lastModified
|
|
86
|
+
}
|
|
87
|
+
];
|
|
88
|
+
return [
|
|
89
|
+
4,
|
|
90
|
+
readFile(filepath, 'utf-8')
|
|
91
|
+
];
|
|
92
|
+
case 4:
|
|
93
|
+
content = _state.sent();
|
|
94
|
+
newEntry = {
|
|
95
|
+
content: content,
|
|
96
|
+
lastModified: currentModified
|
|
97
|
+
};
|
|
98
|
+
this.cache.set(filepath, newEntry, {
|
|
99
|
+
size: stat.size || content.length
|
|
100
|
+
});
|
|
101
|
+
return [
|
|
102
|
+
2,
|
|
103
|
+
{
|
|
104
|
+
content: content,
|
|
105
|
+
lastModified: currentModified
|
|
106
|
+
}
|
|
107
|
+
];
|
|
108
|
+
case 5:
|
|
109
|
+
_state.sent();
|
|
110
|
+
return [
|
|
111
|
+
2,
|
|
112
|
+
null
|
|
113
|
+
];
|
|
114
|
+
case 6:
|
|
115
|
+
return [
|
|
116
|
+
2
|
|
117
|
+
];
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
}).call(this);
|
|
121
|
+
};
|
|
122
|
+
return FileCache;
|
|
123
|
+
}();
|
|
124
|
+
var fileCache = new fileCache_FileCache();
|
|
125
|
+
export { fileCache_FileCache as FileCache, fileCache };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { createCorsMiddleware, createStaticMiddleware } from "./staticMiddleware.mjs";
|
|
2
|
+
var server_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 = server_staticServePlugin;
|
|
36
|
+
export { server as default, server_staticServePlugin as staticServePlugin };
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { _ } from "@swc/helpers/_/_async_to_generator";
|
|
2
|
+
import { _ as _ts_generator__ } from "@swc/helpers/_/_ts_generator";
|
|
3
|
+
import { access } from "fs/promises";
|
|
4
|
+
import path from "path";
|
|
5
|
+
import { fileCache } from "./fileCache.mjs";
|
|
6
|
+
var staticMiddleware_pathExists = function(filepath) {
|
|
7
|
+
return _(function() {
|
|
8
|
+
return _ts_generator__(this, function(_state) {
|
|
9
|
+
switch(_state.label){
|
|
10
|
+
case 0:
|
|
11
|
+
_state.trys.push([
|
|
12
|
+
0,
|
|
13
|
+
2,
|
|
14
|
+
,
|
|
15
|
+
3
|
|
16
|
+
]);
|
|
17
|
+
return [
|
|
18
|
+
4,
|
|
19
|
+
access(filepath)
|
|
20
|
+
];
|
|
21
|
+
case 1:
|
|
22
|
+
_state.sent();
|
|
23
|
+
return [
|
|
24
|
+
2,
|
|
25
|
+
true
|
|
26
|
+
];
|
|
27
|
+
case 2:
|
|
28
|
+
_state.sent();
|
|
29
|
+
return [
|
|
30
|
+
2,
|
|
31
|
+
false
|
|
32
|
+
];
|
|
33
|
+
case 3:
|
|
34
|
+
return [
|
|
35
|
+
2
|
|
36
|
+
];
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
})();
|
|
40
|
+
};
|
|
41
|
+
var bundlesAssetPrefix = '/bundles';
|
|
42
|
+
var staticMiddleware_removeHost = function(url) {
|
|
43
|
+
try {
|
|
44
|
+
var hasProtocol = url.includes('://');
|
|
45
|
+
var hasDomain = hasProtocol || url.startsWith('//');
|
|
46
|
+
var pathname = hasDomain ? new URL(hasProtocol ? url : "http:".concat(url)).pathname : url;
|
|
47
|
+
return pathname;
|
|
48
|
+
} catch (e) {
|
|
49
|
+
return url;
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
var staticMiddleware_createStaticMiddleware = function(options) {
|
|
53
|
+
var assetPrefix = options.assetPrefix, pwd = options.pwd;
|
|
54
|
+
return function(c, next) {
|
|
55
|
+
return _(function() {
|
|
56
|
+
var pathname, prefixWithoutHost, prefixWithBundle, pathnameWithoutPrefix, filepath, fileResult;
|
|
57
|
+
return _ts_generator__(this, function(_state) {
|
|
58
|
+
switch(_state.label){
|
|
59
|
+
case 0:
|
|
60
|
+
pathname = c.req.path;
|
|
61
|
+
if ('.js' !== path.extname(pathname)) return [
|
|
62
|
+
2,
|
|
63
|
+
next()
|
|
64
|
+
];
|
|
65
|
+
prefixWithoutHost = staticMiddleware_removeHost(assetPrefix);
|
|
66
|
+
prefixWithBundle = path.join(prefixWithoutHost, bundlesAssetPrefix);
|
|
67
|
+
if (!pathname.startsWith(prefixWithBundle)) return [
|
|
68
|
+
2,
|
|
69
|
+
next()
|
|
70
|
+
];
|
|
71
|
+
pathnameWithoutPrefix = pathname.replace(prefixWithBundle, '');
|
|
72
|
+
filepath = path.join(pwd, bundlesAssetPrefix, pathnameWithoutPrefix);
|
|
73
|
+
return [
|
|
74
|
+
4,
|
|
75
|
+
staticMiddleware_pathExists(filepath)
|
|
76
|
+
];
|
|
77
|
+
case 1:
|
|
78
|
+
if (!_state.sent()) return [
|
|
79
|
+
2,
|
|
80
|
+
next()
|
|
81
|
+
];
|
|
82
|
+
return [
|
|
83
|
+
4,
|
|
84
|
+
fileCache.getFile(filepath)
|
|
85
|
+
];
|
|
86
|
+
case 2:
|
|
87
|
+
fileResult = _state.sent();
|
|
88
|
+
if (!fileResult) return [
|
|
89
|
+
2,
|
|
90
|
+
next()
|
|
91
|
+
];
|
|
92
|
+
c.header('Content-Type', "application/javascript");
|
|
93
|
+
c.header('Content-Length', String(fileResult.content.length));
|
|
94
|
+
return [
|
|
95
|
+
2,
|
|
96
|
+
c.body(fileResult.content, 200)
|
|
97
|
+
];
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
})();
|
|
101
|
+
};
|
|
102
|
+
};
|
|
103
|
+
var staticMiddleware_createCorsMiddleware = function() {
|
|
104
|
+
return function(c, next) {
|
|
105
|
+
return _(function() {
|
|
106
|
+
var pathname;
|
|
107
|
+
return _ts_generator__(this, function(_state) {
|
|
108
|
+
pathname = c.req.path;
|
|
109
|
+
if (path.extname(pathname)) {
|
|
110
|
+
c.header('Access-Control-Allow-Origin', '*');
|
|
111
|
+
c.header('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, PATCH, OPTIONS');
|
|
112
|
+
c.header('Access-Control-Allow-Headers', '*');
|
|
113
|
+
}
|
|
114
|
+
return [
|
|
115
|
+
2,
|
|
116
|
+
next()
|
|
117
|
+
];
|
|
118
|
+
});
|
|
119
|
+
})();
|
|
120
|
+
};
|
|
121
|
+
};
|
|
122
|
+
export { staticMiddleware_createCorsMiddleware as createCorsMiddleware, staticMiddleware_createStaticMiddleware as createStaticMiddleware };
|