@module-federation/modern-js 0.0.0-next-20240515062211
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 +1 -0
- package/dist/CHANGELOG.md +1 -0
- package/dist/LICENSE +21 -0
- package/dist/README.md +1 -0
- package/dist/cjs/cli/index.js +165 -0
- package/dist/cjs/cli/manifest.js +72 -0
- package/dist/cjs/cli/mfRuntimePlugins/shared-strategy.js +42 -0
- package/dist/cjs/cli/utils.js +62 -0
- package/dist/cjs/constant.js +28 -0
- package/dist/cjs/runtime/MFReactComponent.js +108 -0
- package/dist/cjs/runtime/index.js +31 -0
- package/dist/cjs/types/index.js +16 -0
- package/dist/esm/cli/index.js +157 -0
- package/dist/esm/cli/manifest.js +38 -0
- package/dist/esm/cli/mfRuntimePlugins/shared-strategy.js +24 -0
- package/dist/esm/cli/utils.js +56 -0
- package/dist/esm/constant.js +4 -0
- package/dist/esm/runtime/MFReactComponent.js +77 -0
- package/dist/esm/runtime/index.js +5 -0
- package/dist/esm/types/index.js +0 -0
- package/dist/esm-node/cli/index.js +130 -0
- package/dist/esm-node/cli/manifest.js +38 -0
- package/dist/esm-node/cli/mfRuntimePlugins/shared-strategy.js +22 -0
- package/dist/esm-node/cli/utils.js +27 -0
- package/dist/esm-node/constant.js +4 -0
- package/dist/esm-node/runtime/MFReactComponent.js +74 -0
- package/dist/esm-node/runtime/index.js +5 -0
- package/dist/esm-node/types/index.js +0 -0
- package/dist/types/cli/index.d.ts +5 -0
- package/dist/types/cli/manifest.d.ts +2 -0
- package/dist/types/cli/mfRuntimePlugins/shared-strategy.d.ts +3 -0
- package/dist/types/cli/utils.d.ts +4 -0
- package/dist/types/constant.d.ts +1 -0
- package/dist/types/runtime/MFReactComponent.d.ts +7 -0
- package/dist/types/runtime/index.d.ts +2 -0
- package/dist/types/types/index.d.ts +5 -0
- package/package.json +56 -0
- package/types.d.ts +5 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024-present zhanghang(2heal1)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# @module-federation/modern-js
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# @module-federation/modern-js
|
package/dist/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024-present zhanghang(2heal1)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# @module-federation/modern-js
|
|
@@ -0,0 +1,165 @@
|
|
|
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 cli_exports = {};
|
|
30
|
+
__export(cli_exports, {
|
|
31
|
+
createModuleFederationConfig: () => import_enhanced2.createModuleFederationConfig,
|
|
32
|
+
default: () => cli_default,
|
|
33
|
+
moduleFederationPlugin: () => moduleFederationPlugin
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(cli_exports);
|
|
36
|
+
var import_path = __toESM(require("path"));
|
|
37
|
+
var import_utils = require("@modern-js/utils");
|
|
38
|
+
var import_enhanced = require("@module-federation/enhanced");
|
|
39
|
+
var import_node = require("@module-federation/node");
|
|
40
|
+
var import_utils2 = require("./utils");
|
|
41
|
+
var import_manifest = require("./manifest");
|
|
42
|
+
var import_constant = require("../constant");
|
|
43
|
+
var import_enhanced2 = require("@module-federation/enhanced");
|
|
44
|
+
const moduleFederationPlugin = (userConfig = {}) => ({
|
|
45
|
+
name: "@modern-js/plugin-module-federation",
|
|
46
|
+
setup: async ({ useConfigContext }) => {
|
|
47
|
+
var _useConfig_server, _useConfig_server1, _useConfig_server_ssr, _useConfig_server2;
|
|
48
|
+
const useConfig = useConfigContext();
|
|
49
|
+
const enableSSR = Boolean(useConfig === null || useConfig === void 0 ? void 0 : (_useConfig_server = useConfig.server) === null || _useConfig_server === void 0 ? void 0 : _useConfig_server.ssr);
|
|
50
|
+
const isStreamSSR = typeof (useConfig === null || useConfig === void 0 ? void 0 : (_useConfig_server1 = useConfig.server) === null || _useConfig_server1 === void 0 ? void 0 : _useConfig_server1.ssr) === "object" ? (useConfig === null || useConfig === void 0 ? void 0 : (_useConfig_server2 = useConfig.server) === null || _useConfig_server2 === void 0 ? void 0 : (_useConfig_server_ssr = _useConfig_server2.ssr) === null || _useConfig_server_ssr === void 0 ? void 0 : _useConfig_server_ssr.mode) === "stream" : false;
|
|
51
|
+
const mfConfig = await (0, import_utils2.getMFConfig)(userConfig);
|
|
52
|
+
let outputDir = "";
|
|
53
|
+
let browserPlugin;
|
|
54
|
+
let nodePlugin;
|
|
55
|
+
return {
|
|
56
|
+
config: () => {
|
|
57
|
+
var _useConfig_dev;
|
|
58
|
+
if (enableSSR) {
|
|
59
|
+
process.env["MF_DISABLE_EMIT_STATS"] = "true";
|
|
60
|
+
}
|
|
61
|
+
return {
|
|
62
|
+
tools: {
|
|
63
|
+
webpack(config, { isServer }) {
|
|
64
|
+
var _config_optimization, _useConfig_source, _config_output;
|
|
65
|
+
(_config_optimization = config.optimization) === null || _config_optimization === void 0 ? true : delete _config_optimization.runtimeChunk;
|
|
66
|
+
(0, import_utils2.patchMFConfig)(mfConfig);
|
|
67
|
+
if (isServer) {
|
|
68
|
+
var _config_plugins, _config_plugins1;
|
|
69
|
+
nodePlugin = new import_enhanced.ModuleFederationPlugin({
|
|
70
|
+
library: {
|
|
71
|
+
type: "commonjs-module",
|
|
72
|
+
name: mfConfig.name
|
|
73
|
+
},
|
|
74
|
+
...mfConfig
|
|
75
|
+
});
|
|
76
|
+
(_config_plugins = config.plugins) === null || _config_plugins === void 0 ? void 0 : _config_plugins.push(nodePlugin);
|
|
77
|
+
(_config_plugins1 = config.plugins) === null || _config_plugins1 === void 0 ? void 0 : _config_plugins1.push(new import_node.StreamingTargetPlugin(mfConfig));
|
|
78
|
+
} else {
|
|
79
|
+
var _config_output1, _config_plugins2, _config_optimization1;
|
|
80
|
+
outputDir = ((_config_output1 = config.output) === null || _config_output1 === void 0 ? void 0 : _config_output1.path) || import_path.default.resolve(process.cwd(), "dist");
|
|
81
|
+
browserPlugin = new import_enhanced.ModuleFederationPlugin(mfConfig);
|
|
82
|
+
(_config_plugins2 = config.plugins) === null || _config_plugins2 === void 0 ? void 0 : _config_plugins2.push(browserPlugin);
|
|
83
|
+
if (enableSSR && isStreamSSR && typeof ((_config_optimization1 = config.optimization) === null || _config_optimization1 === void 0 ? void 0 : _config_optimization1.splitChunks) === "object" && config.optimization.splitChunks.cacheGroups) {
|
|
84
|
+
config.optimization.splitChunks.chunks = "async";
|
|
85
|
+
console.warn('[Modern.js Module Federation] splitChunks.chunks = async is not allowed with stream SSR mode, it will auto changed to "async"');
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
const enableAsyncEntry = (_useConfig_source = useConfig.source) === null || _useConfig_source === void 0 ? void 0 : _useConfig_source.enableAsyncEntry;
|
|
89
|
+
if (!enableAsyncEntry && mfConfig.async) {
|
|
90
|
+
var _config_plugins3;
|
|
91
|
+
const asyncBoundaryPluginOptions = {
|
|
92
|
+
eager: (module2) => module2 && /\.federation/.test((module2 === null || module2 === void 0 ? void 0 : module2.request) || ""),
|
|
93
|
+
excludeChunk: (chunk) => chunk.name === mfConfig.name
|
|
94
|
+
};
|
|
95
|
+
(_config_plugins3 = config.plugins) === null || _config_plugins3 === void 0 ? void 0 : _config_plugins3.push(new import_enhanced.AsyncBoundaryPlugin(asyncBoundaryPluginOptions));
|
|
96
|
+
}
|
|
97
|
+
if (((_config_output = config.output) === null || _config_output === void 0 ? void 0 : _config_output.publicPath) === "auto") {
|
|
98
|
+
var _useConfig_dev2, _useConfig_server3;
|
|
99
|
+
const port = ((_useConfig_dev2 = useConfig.dev) === null || _useConfig_dev2 === void 0 ? void 0 : _useConfig_dev2.port) || ((_useConfig_server3 = useConfig.server) === null || _useConfig_server3 === void 0 ? void 0 : _useConfig_server3.port) || 8080;
|
|
100
|
+
const publicPath = `http://localhost:${port}/`;
|
|
101
|
+
config.output.publicPath = publicPath;
|
|
102
|
+
}
|
|
103
|
+
},
|
|
104
|
+
devServer: {
|
|
105
|
+
headers: {
|
|
106
|
+
"Access-Control-Allow-Origin": "*",
|
|
107
|
+
"Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, PATCH, OPTIONS",
|
|
108
|
+
"Access-Control-Allow-Headers": "X-Requested-With, content-type, Authorization"
|
|
109
|
+
},
|
|
110
|
+
before: [
|
|
111
|
+
(req, res, next) => {
|
|
112
|
+
if (!enableSSR) {
|
|
113
|
+
next();
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
try {
|
|
117
|
+
var _req_url, _req_url1, _req_url2;
|
|
118
|
+
const SERVER_PREFIX = `/${import_constant.MODERN_JS_SERVER_DIR}`;
|
|
119
|
+
if (((_req_url = req.url) === null || _req_url === void 0 ? void 0 : _req_url.startsWith(SERVER_PREFIX)) || ((_req_url1 = req.url) === null || _req_url1 === void 0 ? void 0 : _req_url1.includes("remoteEntry.js")) || ((_req_url2 = req.url) === null || _req_url2 === void 0 ? void 0 : _req_url2.includes(".json"))) {
|
|
120
|
+
const filepath = import_path.default.join(process.cwd(), `dist${req.url}`);
|
|
121
|
+
import_utils.fs.statSync(filepath);
|
|
122
|
+
res.setHeader("Access-Control-Allow-Origin", "*");
|
|
123
|
+
res.setHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, PATCH, OPTIONS");
|
|
124
|
+
res.setHeader("Access-Control-Allow-Headers", "X-Requested-With, content-type, Authorization");
|
|
125
|
+
import_utils.fs.createReadStream(filepath).pipe(res);
|
|
126
|
+
} else {
|
|
127
|
+
next();
|
|
128
|
+
}
|
|
129
|
+
} catch (err) {
|
|
130
|
+
console.error(err);
|
|
131
|
+
next();
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
]
|
|
135
|
+
}
|
|
136
|
+
},
|
|
137
|
+
source: {
|
|
138
|
+
alias: {
|
|
139
|
+
"@modern-js/runtime/mf": require.resolve("@module-federation/modern-js/runtime")
|
|
140
|
+
}
|
|
141
|
+
},
|
|
142
|
+
dev: {
|
|
143
|
+
assetPrefix: (useConfig === null || useConfig === void 0 ? void 0 : (_useConfig_dev = useConfig.dev) === null || _useConfig_dev === void 0 ? void 0 : _useConfig_dev.assetPrefix) ? useConfig.dev.assetPrefix : true
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
},
|
|
147
|
+
afterBuild: () => {
|
|
148
|
+
if (enableSSR) {
|
|
149
|
+
(0, import_manifest.updateStatsAndManifest)(nodePlugin, browserPlugin, outputDir);
|
|
150
|
+
}
|
|
151
|
+
},
|
|
152
|
+
afterDev: () => {
|
|
153
|
+
if (enableSSR) {
|
|
154
|
+
(0, import_manifest.updateStatsAndManifest)(nodePlugin, browserPlugin, outputDir);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
var cli_default = moduleFederationPlugin;
|
|
161
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
162
|
+
0 && (module.exports = {
|
|
163
|
+
createModuleFederationConfig,
|
|
164
|
+
moduleFederationPlugin
|
|
165
|
+
});
|
|
@@ -0,0 +1,72 @@
|
|
|
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 manifest_exports = {};
|
|
30
|
+
__export(manifest_exports, {
|
|
31
|
+
updateStatsAndManifest: () => updateStatsAndManifest
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(manifest_exports);
|
|
34
|
+
var import_path = __toESM(require("path"));
|
|
35
|
+
var import_utils = require("@modern-js/utils");
|
|
36
|
+
var import_constant = require("../constant");
|
|
37
|
+
function mergeStats(browserStats, nodeStats) {
|
|
38
|
+
const ssrRemoteEntry = nodeStats.metaData.remoteEntry;
|
|
39
|
+
ssrRemoteEntry.path = import_constant.MODERN_JS_SERVER_DIR;
|
|
40
|
+
browserStats.metaData.ssrRemoteEntry = ssrRemoteEntry;
|
|
41
|
+
return browserStats;
|
|
42
|
+
}
|
|
43
|
+
function mergeManifest(browserManifest, nodeManifest) {
|
|
44
|
+
const ssrRemoteEntry = nodeManifest.metaData.remoteEntry;
|
|
45
|
+
ssrRemoteEntry.path = import_constant.MODERN_JS_SERVER_DIR;
|
|
46
|
+
browserManifest.metaData.ssrRemoteEntry = ssrRemoteEntry;
|
|
47
|
+
return browserManifest;
|
|
48
|
+
}
|
|
49
|
+
function mergeStatsAndManifest(nodePlugin, browserPlugin) {
|
|
50
|
+
const nodeResourceInfo = nodePlugin.statsResourceInfo;
|
|
51
|
+
const browserResourceInfo = browserPlugin.statsResourceInfo;
|
|
52
|
+
if (!browserResourceInfo || !nodeResourceInfo || !browserResourceInfo.stats || !nodeResourceInfo.stats || !browserResourceInfo.manifest || !nodeResourceInfo.manifest) {
|
|
53
|
+
throw new Error("can not get browserResourceInfo or nodeResourceInfo");
|
|
54
|
+
}
|
|
55
|
+
const mergedStats = mergeStats(browserResourceInfo.stats.stats, nodeResourceInfo.stats.stats);
|
|
56
|
+
const mergedManifest = mergeManifest(browserResourceInfo.manifest.manifest, nodeResourceInfo.manifest.manifest);
|
|
57
|
+
return {
|
|
58
|
+
mergedStats,
|
|
59
|
+
mergedStatsFilePath: browserResourceInfo.stats.filename,
|
|
60
|
+
mergedManifest,
|
|
61
|
+
mergedManifestFilePath: browserResourceInfo.manifest.filename
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
function updateStatsAndManifest(nodePlugin, browserPlugin, outputDir) {
|
|
65
|
+
const { mergedStats, mergedStatsFilePath, mergedManifest, mergedManifestFilePath } = mergeStatsAndManifest(nodePlugin, browserPlugin);
|
|
66
|
+
import_utils.fs.writeFileSync(import_path.default.resolve(outputDir, mergedStatsFilePath), JSON.stringify(mergedStats, null, 2));
|
|
67
|
+
import_utils.fs.writeFileSync(import_path.default.resolve(outputDir, mergedManifestFilePath), JSON.stringify(mergedManifest, null, 2));
|
|
68
|
+
}
|
|
69
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
70
|
+
0 && (module.exports = {
|
|
71
|
+
updateStatsAndManifest
|
|
72
|
+
});
|
|
@@ -0,0 +1,42 @@
|
|
|
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",
|
|
26
|
+
beforeInit(args) {
|
|
27
|
+
const { shareInfo } = args;
|
|
28
|
+
if (shareInfo) {
|
|
29
|
+
Object.keys(shareInfo || {}).forEach((sharedKey) => {
|
|
30
|
+
const sharedConfigs = shareInfo[sharedKey];
|
|
31
|
+
const arraySharedConfigs = Array.isArray(sharedConfigs) ? sharedConfigs : [
|
|
32
|
+
sharedConfigs
|
|
33
|
+
];
|
|
34
|
+
arraySharedConfigs.forEach((s) => {
|
|
35
|
+
s.strategy = "loaded-first";
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
return args;
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
var shared_strategy_default = sharedStrategy;
|
|
@@ -0,0 +1,62 @@
|
|
|
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
|
+
getMFConfig: () => getMFConfig,
|
|
32
|
+
patchMFConfig: () => patchMFConfig
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(utils_exports);
|
|
35
|
+
var import_path = __toESM(require("path"));
|
|
36
|
+
var import_node_bundle_require = require("@modern-js/node-bundle-require");
|
|
37
|
+
const defaultPath = import_path.default.resolve(process.cwd(), "module-federation.config.ts");
|
|
38
|
+
const getMFConfig = async (userConfig) => {
|
|
39
|
+
const { config, configPath } = userConfig;
|
|
40
|
+
if (config) {
|
|
41
|
+
return config;
|
|
42
|
+
}
|
|
43
|
+
const mfConfigPath = configPath ? configPath : defaultPath;
|
|
44
|
+
const preBundlePath = await (0, import_node_bundle_require.bundle)(mfConfigPath);
|
|
45
|
+
const mfConfig = (await Promise.resolve().then(() => __toESM(require(preBundlePath)))).default;
|
|
46
|
+
return mfConfig;
|
|
47
|
+
};
|
|
48
|
+
const patchMFConfig = (mfConfig) => {
|
|
49
|
+
mfConfig.runtimePlugins = mfConfig.runtimePlugins || [];
|
|
50
|
+
const runtimePluginPath = import_path.default.resolve(__dirname, "./mfRuntimePlugins/shared-strategy.js");
|
|
51
|
+
if (!mfConfig.runtimePlugins.includes(runtimePluginPath)) {
|
|
52
|
+
mfConfig.runtimePlugins.push(import_path.default.resolve(__dirname, "./mfRuntimePlugins/shared-strategy.js"));
|
|
53
|
+
}
|
|
54
|
+
if (typeof mfConfig.async === "undefined") {
|
|
55
|
+
mfConfig.async = true;
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
59
|
+
0 && (module.exports = {
|
|
60
|
+
getMFConfig,
|
|
61
|
+
patchMFConfig
|
|
62
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
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
|
+
MODERN_JS_SERVER_DIR: () => MODERN_JS_SERVER_DIR
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(constant_exports);
|
|
24
|
+
const MODERN_JS_SERVER_DIR = "bundles";
|
|
25
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
26
|
+
0 && (module.exports = {
|
|
27
|
+
MODERN_JS_SERVER_DIR
|
|
28
|
+
});
|
|
@@ -0,0 +1,108 @@
|
|
|
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 MFReactComponent_exports = {};
|
|
30
|
+
__export(MFReactComponent_exports, {
|
|
31
|
+
MFReactComponent: () => MFReactComponent
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(MFReactComponent_exports);
|
|
34
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
35
|
+
var import_react = __toESM(require("react"));
|
|
36
|
+
var import_runtime = require("@module-federation/enhanced/runtime");
|
|
37
|
+
function getLoadedRemoteInfos(instance, id) {
|
|
38
|
+
const moduleName = instance.remoteHandler.idToModuleNameMap[id];
|
|
39
|
+
if (!moduleName) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
const module2 = instance.moduleCache.get(moduleName);
|
|
43
|
+
if (!module2) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
const { remoteSnapshot } = instance.snapshotHandler.getGlobalRemoteInfo(module2.remoteInfo);
|
|
47
|
+
return {
|
|
48
|
+
...module2.remoteInfo,
|
|
49
|
+
snapshot: remoteSnapshot
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
function collectLinks(id) {
|
|
53
|
+
const links = [];
|
|
54
|
+
const instance = (0, import_runtime.getInstance)();
|
|
55
|
+
if (!instance) {
|
|
56
|
+
return links;
|
|
57
|
+
}
|
|
58
|
+
const loadedRemoteInfo = getLoadedRemoteInfos(instance, id);
|
|
59
|
+
if (!loadedRemoteInfo) {
|
|
60
|
+
return links;
|
|
61
|
+
}
|
|
62
|
+
const snapshot = loadedRemoteInfo.snapshot;
|
|
63
|
+
if (!snapshot) {
|
|
64
|
+
return links;
|
|
65
|
+
}
|
|
66
|
+
const publicPath = "publicPath" in snapshot ? snapshot.publicPath : "getPublicPath" in snapshot ? new Function(snapshot.getPublicPath)() : "";
|
|
67
|
+
if (!publicPath) {
|
|
68
|
+
return links;
|
|
69
|
+
}
|
|
70
|
+
const modules = "modules" in snapshot ? snapshot.modules : [];
|
|
71
|
+
if (modules) {
|
|
72
|
+
modules.forEach((module2) => {
|
|
73
|
+
[
|
|
74
|
+
...module2.assets.css.sync,
|
|
75
|
+
...module2.assets.css.async
|
|
76
|
+
].forEach((file, index) => {
|
|
77
|
+
links.push(/* @__PURE__ */ (0, import_jsx_runtime.jsx)("link", {
|
|
78
|
+
href: `${publicPath}${file}`,
|
|
79
|
+
rel: "stylesheet",
|
|
80
|
+
type: "text/css"
|
|
81
|
+
}, index));
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
return links;
|
|
86
|
+
}
|
|
87
|
+
function MFReactComponent(props) {
|
|
88
|
+
const { loading = "loading...", id } = props;
|
|
89
|
+
const Component = /* @__PURE__ */ import_react.default.lazy(() => (0, import_runtime.loadRemote)(id).then((mod) => {
|
|
90
|
+
const links = collectLinks(id);
|
|
91
|
+
return {
|
|
92
|
+
default: () => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
|
|
93
|
+
children: [
|
|
94
|
+
links,
|
|
95
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(mod.default, {})
|
|
96
|
+
]
|
|
97
|
+
})
|
|
98
|
+
};
|
|
99
|
+
}));
|
|
100
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react.default.Suspense, {
|
|
101
|
+
fallback: loading,
|
|
102
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Component, {})
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
106
|
+
0 && (module.exports = {
|
|
107
|
+
MFReactComponent
|
|
108
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
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 __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
var runtime_exports = {};
|
|
21
|
+
__export(runtime_exports, {
|
|
22
|
+
MFReactComponent: () => import_MFReactComponent.MFReactComponent
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(runtime_exports);
|
|
25
|
+
__reExport(runtime_exports, require("@module-federation/enhanced/runtime"), module.exports);
|
|
26
|
+
var import_MFReactComponent = require("./MFReactComponent");
|
|
27
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
28
|
+
0 && (module.exports = {
|
|
29
|
+
MFReactComponent,
|
|
30
|
+
...require("@module-federation/enhanced/runtime")
|
|
31
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
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 __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
var types_exports = {};
|
|
16
|
+
module.exports = __toCommonJS(types_exports);
|