@module-federation/modern-js 0.0.0-next-20240813065037 → 0.0.0-next-20240814082511
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/dist/cjs/cli/ast/constant.js +46 -0
- package/dist/cjs/cli/ast/generateRoutes.js +140 -0
- package/dist/cjs/cli/ast/generateSlimRoutes.js +106 -0
- package/dist/cjs/cli/ast/index.js +31 -0
- package/dist/cjs/cli/configPlugin.js +1 -0
- package/dist/cjs/cli/constant.js +6 -0
- package/dist/cjs/cli/dataLoaderPlugin.js +220 -0
- package/dist/cjs/cli/index.js +6 -1
- package/dist/cjs/cli/server/dataLoaderPlugin.js +78 -0
- package/dist/cjs/cli/ssrPlugin.js +4 -4
- package/dist/cjs/interfaces/route.js +16 -0
- package/dist/cjs/runtime/constant.js +34 -0
- package/dist/cjs/runtime/dataLoader.js +87 -0
- package/dist/cjs/runtime/index.js +4 -1
- package/dist/cjs/runtime/utils.js +43 -0
- package/dist/cjs/runtime/withMFRouteId.js +31 -0
- package/dist/cjs/ssr-runtime/plugin.js +5 -7
- package/dist/esm/cli/ast/constant.js +16 -0
- package/dist/esm/cli/ast/generateRoutes.js +107 -0
- package/dist/esm/cli/ast/generateSlimRoutes.js +75 -0
- package/dist/esm/cli/ast/index.js +6 -0
- package/dist/esm/cli/configPlugin.js +1 -0
- package/dist/esm/cli/constant.js +4 -0
- package/dist/esm/cli/dataLoaderPlugin.js +207 -0
- package/dist/esm/cli/index.js +6 -1
- package/dist/esm/cli/server/dataLoaderPlugin.js +122 -0
- package/dist/esm/cli/ssrPlugin.js +2 -2
- package/dist/esm/interfaces/route.js +0 -0
- package/dist/esm/runtime/constant.js +8 -0
- package/dist/esm/runtime/dataLoader.js +125 -0
- package/dist/esm/runtime/index.js +3 -1
- package/dist/esm/runtime/utils.js +16 -0
- package/dist/esm/runtime/withMFRouteId.js +7 -0
- package/dist/esm/ssr-runtime/plugin.js +5 -10
- package/dist/esm-node/cli/ast/constant.js +16 -0
- package/dist/esm-node/cli/ast/generateRoutes.js +106 -0
- package/dist/esm-node/cli/ast/generateSlimRoutes.js +72 -0
- package/dist/esm-node/cli/ast/index.js +6 -0
- package/dist/esm-node/cli/configPlugin.js +1 -0
- package/dist/esm-node/cli/constant.js +4 -0
- package/dist/esm-node/cli/dataLoaderPlugin.js +184 -0
- package/dist/esm-node/cli/index.js +6 -1
- package/dist/esm-node/cli/server/dataLoaderPlugin.js +58 -0
- package/dist/esm-node/cli/ssrPlugin.js +2 -2
- package/dist/esm-node/interfaces/route.js +0 -0
- package/dist/esm-node/runtime/constant.js +8 -0
- package/dist/esm-node/runtime/dataLoader.js +63 -0
- package/dist/esm-node/runtime/index.js +3 -1
- package/dist/esm-node/runtime/utils.js +19 -0
- package/dist/esm-node/runtime/withMFRouteId.js +7 -0
- package/dist/esm-node/ssr-runtime/plugin.js +5 -7
- package/dist/types/cli/ast/constant.d.ts +7 -0
- package/dist/types/cli/ast/generateRoutes.d.ts +7 -0
- package/dist/types/cli/ast/generateSlimRoutes.d.ts +7 -0
- package/dist/types/cli/ast/index.d.ts +2 -0
- package/dist/types/cli/constant.d.ts +2 -0
- package/dist/types/cli/dataLoaderPlugin.d.ts +6 -0
- package/dist/types/cli/server/dataLoaderPlugin.d.ts +5 -0
- package/dist/types/interfaces/route.d.ts +13 -0
- package/dist/types/runtime/constant.d.ts +3 -0
- package/dist/types/runtime/dataLoader.d.ts +7 -0
- package/dist/types/runtime/index.d.ts +1 -0
- package/dist/types/runtime/utils.d.ts +1 -0
- package/dist/types/runtime/withMFRouteId.d.ts +1 -0
- package/dist/types/types/index.d.ts +17 -0
- package/package.json +37 -11
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
|
2
|
+
import { _ as _define_property } from "@swc/helpers/_/_define_property";
|
|
3
|
+
import { _ as _sliced_to_array } from "@swc/helpers/_/_sliced_to_array";
|
|
4
|
+
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
5
|
+
import path from "path";
|
|
6
|
+
import { fs } from "@modern-js/utils";
|
|
7
|
+
import { transformName2Prefix } from "../runtime/utils";
|
|
8
|
+
import { PLUGIN_IDENTIFIER } from "../constant";
|
|
9
|
+
import { MF_FULL_ROUTES, MF_SLIM_ROUTES, MF_ROUTES_META } from "../runtime/constant";
|
|
10
|
+
import { generateRoutes, generateSlimRoutes } from "./ast";
|
|
11
|
+
import { MODERN_JS_FILE_SYSTEM_ROUTES_FILE_NAME, META_NAME } from "./constant";
|
|
12
|
+
function generateExtraExposeFiles(options) {
|
|
13
|
+
var routesFilePath = options.routesFilePath, mfConfig = options.mfConfig, isServer = options.isServer, baseName = options.baseName;
|
|
14
|
+
var outputDir = path.resolve(process.cwd(), "node_modules/.federation");
|
|
15
|
+
fs.ensureDirSync(outputDir);
|
|
16
|
+
var addSuffix = function(fileName) {
|
|
17
|
+
if (!isServer) {
|
|
18
|
+
return "".concat(fileName, ".jsx");
|
|
19
|
+
}
|
|
20
|
+
return "".concat(fileName, ".server.jsx");
|
|
21
|
+
};
|
|
22
|
+
var routesFileContent = fs.readFileSync(routesFilePath, "utf-8");
|
|
23
|
+
var outputSlimRoutesPath = path.resolve(outputDir, addSuffix(MF_SLIM_ROUTES));
|
|
24
|
+
var outputFullRoutesPath = path.resolve(outputDir, addSuffix(MF_FULL_ROUTES));
|
|
25
|
+
var outputRoutesMetaPath = path.resolve(outputDir, "".concat(MF_ROUTES_META, ".js"));
|
|
26
|
+
generateSlimRoutes({
|
|
27
|
+
sourceCode: routesFileContent,
|
|
28
|
+
filePath: outputSlimRoutesPath,
|
|
29
|
+
prefix: transformName2Prefix(mfConfig.name),
|
|
30
|
+
baseName
|
|
31
|
+
});
|
|
32
|
+
generateRoutes({
|
|
33
|
+
sourceCode: routesFileContent,
|
|
34
|
+
filePath: outputFullRoutesPath,
|
|
35
|
+
prefix: transformName2Prefix(mfConfig.name),
|
|
36
|
+
baseName
|
|
37
|
+
});
|
|
38
|
+
fs.writeFileSync(outputRoutesMetaPath, "export const baseName = '".concat(baseName, "';"));
|
|
39
|
+
return {
|
|
40
|
+
outputSlimRoutesPath,
|
|
41
|
+
outputFullRoutesPath,
|
|
42
|
+
outputRoutesMetaPath
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
function addExpose(options) {
|
|
46
|
+
var mfConfig = options.mfConfig;
|
|
47
|
+
var _generateExtraExposeFiles = generateExtraExposeFiles(options), outputSlimRoutesPath = _generateExtraExposeFiles.outputSlimRoutesPath, outputFullRoutesPath = _generateExtraExposeFiles.outputFullRoutesPath, outputRoutesMetaPath = _generateExtraExposeFiles.outputRoutesMetaPath;
|
|
48
|
+
var fullRoutesKey = "./".concat(MF_FULL_ROUTES);
|
|
49
|
+
var slimRoutesKey = "./".concat(MF_SLIM_ROUTES);
|
|
50
|
+
var routeMetaKey = "./".concat(MF_ROUTES_META);
|
|
51
|
+
if (!mfConfig.exposes) {
|
|
52
|
+
var _obj;
|
|
53
|
+
mfConfig.exposes = (_obj = {}, _define_property(_obj, fullRoutesKey, outputFullRoutesPath), _define_property(_obj, slimRoutesKey, outputSlimRoutesPath), _define_property(_obj, routeMetaKey, outputRoutesMetaPath), _obj);
|
|
54
|
+
} else {
|
|
55
|
+
if (!Array.isArray(mfConfig.exposes)) {
|
|
56
|
+
if (!mfConfig.exposes[fullRoutesKey]) {
|
|
57
|
+
mfConfig.exposes[fullRoutesKey] = outputFullRoutesPath;
|
|
58
|
+
}
|
|
59
|
+
if (!mfConfig.exposes[slimRoutesKey]) {
|
|
60
|
+
mfConfig.exposes[slimRoutesKey] = outputSlimRoutesPath;
|
|
61
|
+
}
|
|
62
|
+
if (!mfConfig.exposes[routeMetaKey]) {
|
|
63
|
+
mfConfig.exposes[routeMetaKey] = outputRoutesMetaPath;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
function addShared(options) {
|
|
69
|
+
var metaName = options.metaName, mfConfig = options.mfConfig;
|
|
70
|
+
var alias = "@".concat(metaName, "/runtime/router");
|
|
71
|
+
if (!mfConfig.shared) {
|
|
72
|
+
mfConfig.shared = _define_property({}, alias, {
|
|
73
|
+
singleton: true
|
|
74
|
+
});
|
|
75
|
+
} else {
|
|
76
|
+
if (!Array.isArray(mfConfig.shared)) {
|
|
77
|
+
mfConfig.shared[alias] = {
|
|
78
|
+
singleton: true
|
|
79
|
+
};
|
|
80
|
+
} else {
|
|
81
|
+
mfConfig.shared.push(alias);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
function _pathMfConfig(options) {
|
|
86
|
+
addShared(options);
|
|
87
|
+
addExpose(options);
|
|
88
|
+
}
|
|
89
|
+
function transformRuntimeOptions(buildOptions) {
|
|
90
|
+
var remotes = buildOptions.remotes || {};
|
|
91
|
+
var runtimeRemotes = Object.entries(remotes).map(function(remote) {
|
|
92
|
+
var _remote = _sliced_to_array(remote, 2), _alias = _remote[0], nameAndEntry = _remote[1];
|
|
93
|
+
var _nameAndEntry_split = _sliced_to_array(nameAndEntry.split("@"), 2), name = _nameAndEntry_split[0], entry = _nameAndEntry_split[1];
|
|
94
|
+
return {
|
|
95
|
+
name,
|
|
96
|
+
entry
|
|
97
|
+
};
|
|
98
|
+
});
|
|
99
|
+
return {
|
|
100
|
+
name: buildOptions.name,
|
|
101
|
+
remotes: runtimeRemotes
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
var moduleFederationDataLoaderPlugin = function(enable, internalOptions, userConfig) {
|
|
105
|
+
return {
|
|
106
|
+
name: "@modern-js/plugin-module-federation-data-loader",
|
|
107
|
+
pre: [
|
|
108
|
+
"@modern-js/plugin-module-federation-config"
|
|
109
|
+
],
|
|
110
|
+
post: [
|
|
111
|
+
"@modern-js/plugin-router",
|
|
112
|
+
"@modern-js/plugin-module-federation"
|
|
113
|
+
],
|
|
114
|
+
setup: function() {
|
|
115
|
+
var _ref = _async_to_generator(function(param) {
|
|
116
|
+
var useConfigContext, useAppContext, _modernjsConfig_server, _internalOptions_csrConfig, baseName, _userConfig_partialSSRRemotes, partialSSRRemotes, fetchSSRByRouteIds, patchMFConfig, _userConfig_metaName, metaName, _userConfig_serverPlugin, serverPlugin, runtimeOptions, modernjsConfig, appContext, enableSSR, name, routesFilePath;
|
|
117
|
+
return _ts_generator(this, function(_state) {
|
|
118
|
+
useConfigContext = param.useConfigContext, useAppContext = param.useAppContext;
|
|
119
|
+
if (!enable) {
|
|
120
|
+
return [
|
|
121
|
+
2
|
|
122
|
+
];
|
|
123
|
+
}
|
|
124
|
+
baseName = userConfig.baseName, _userConfig_partialSSRRemotes = userConfig.partialSSRRemotes, partialSSRRemotes = _userConfig_partialSSRRemotes === void 0 ? [] : _userConfig_partialSSRRemotes, fetchSSRByRouteIds = userConfig.fetchSSRByRouteIds, patchMFConfig = userConfig.patchMFConfig, _userConfig_metaName = userConfig.metaName, metaName = _userConfig_metaName === void 0 ? META_NAME : _userConfig_metaName, _userConfig_serverPlugin = userConfig.serverPlugin, serverPlugin = _userConfig_serverPlugin === void 0 ? "@module-federation/modern-js/data-loader-server" : _userConfig_serverPlugin, runtimeOptions = userConfig.runtimeOptions;
|
|
125
|
+
if (!baseName) {
|
|
126
|
+
throw new Error("".concat(PLUGIN_IDENTIFIER, " 'baseName' is required if you enable 'dataLoader'!"));
|
|
127
|
+
}
|
|
128
|
+
modernjsConfig = useConfigContext();
|
|
129
|
+
appContext = useAppContext();
|
|
130
|
+
enableSSR = Boolean(modernjsConfig === null || modernjsConfig === void 0 ? void 0 : (_modernjsConfig_server = modernjsConfig.server) === null || _modernjsConfig_server === void 0 ? void 0 : _modernjsConfig_server.ssr);
|
|
131
|
+
name = (_internalOptions_csrConfig = internalOptions.csrConfig) === null || _internalOptions_csrConfig === void 0 ? void 0 : _internalOptions_csrConfig.name;
|
|
132
|
+
routesFilePath = path.resolve(appContext.internalDirectory.replace(META_NAME, metaName || META_NAME), "./main/".concat(MODERN_JS_FILE_SYSTEM_ROUTES_FILE_NAME));
|
|
133
|
+
return [
|
|
134
|
+
2,
|
|
135
|
+
{
|
|
136
|
+
_internalRuntimePlugins: function(param2) {
|
|
137
|
+
var entrypoint = param2.entrypoint, plugins = param2.plugins;
|
|
138
|
+
plugins.push({
|
|
139
|
+
name: "ssrDataLoader",
|
|
140
|
+
path: "@module-federation/modern-js/data-loader",
|
|
141
|
+
config: {}
|
|
142
|
+
});
|
|
143
|
+
return {
|
|
144
|
+
entrypoint,
|
|
145
|
+
plugins
|
|
146
|
+
};
|
|
147
|
+
},
|
|
148
|
+
_internalServerPlugins: function _internalServerPlugins(param2) {
|
|
149
|
+
var plugins = param2.plugins;
|
|
150
|
+
plugins.push({
|
|
151
|
+
name: serverPlugin,
|
|
152
|
+
options: runtimeOptions || transformRuntimeOptions(internalOptions.csrConfig)
|
|
153
|
+
});
|
|
154
|
+
return {
|
|
155
|
+
plugins
|
|
156
|
+
};
|
|
157
|
+
},
|
|
158
|
+
config: /* @__PURE__ */ _async_to_generator(function() {
|
|
159
|
+
var patchMFConfigFn;
|
|
160
|
+
return _ts_generator(this, function(_state2) {
|
|
161
|
+
console.log("dataloader plugin config");
|
|
162
|
+
patchMFConfigFn = patchMFConfig || _pathMfConfig;
|
|
163
|
+
return [
|
|
164
|
+
2,
|
|
165
|
+
{
|
|
166
|
+
// server: {
|
|
167
|
+
// ssrByRouteIds: ssrByRouteIds,
|
|
168
|
+
// },
|
|
169
|
+
tools: {
|
|
170
|
+
rspack: function rspack(_config, param2) {
|
|
171
|
+
var isServer = param2.isServer;
|
|
172
|
+
patchMFConfigFn({
|
|
173
|
+
mfConfig: isServer ? internalOptions.ssrConfig : internalOptions.csrConfig,
|
|
174
|
+
baseName,
|
|
175
|
+
metaName,
|
|
176
|
+
isServer,
|
|
177
|
+
routesFilePath
|
|
178
|
+
});
|
|
179
|
+
console.log("dataloader plugin rspack");
|
|
180
|
+
}
|
|
181
|
+
},
|
|
182
|
+
source: {
|
|
183
|
+
define: {
|
|
184
|
+
MODERN_ROUTER_ID_PREFIX: JSON.stringify(transformName2Prefix(name))
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
];
|
|
189
|
+
});
|
|
190
|
+
})
|
|
191
|
+
}
|
|
192
|
+
];
|
|
193
|
+
});
|
|
194
|
+
});
|
|
195
|
+
return function(_) {
|
|
196
|
+
return _ref.apply(this, arguments);
|
|
197
|
+
};
|
|
198
|
+
}()
|
|
199
|
+
};
|
|
200
|
+
};
|
|
201
|
+
var dataLoaderPlugin_default = moduleFederationDataLoaderPlugin;
|
|
202
|
+
export {
|
|
203
|
+
dataLoaderPlugin_default as default,
|
|
204
|
+
generateRoutes,
|
|
205
|
+
generateSlimRoutes,
|
|
206
|
+
moduleFederationDataLoaderPlugin
|
|
207
|
+
};
|
package/dist/esm/cli/index.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
|
2
|
+
import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
|
|
2
3
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
3
4
|
import { ModuleFederationPlugin as WebpackModuleFederationPlugin, AsyncBoundaryPlugin } from "@module-federation/enhanced";
|
|
4
5
|
import { ModuleFederationPlugin as RspackModuleFederationPlugin } from "@module-federation/enhanced/rspack";
|
|
5
6
|
import { moduleFederationConfigPlugin } from "./configPlugin";
|
|
6
7
|
import { moduleFederationSSRPlugin } from "./ssrPlugin";
|
|
8
|
+
import { moduleFederationDataLoaderPlugin } from "./dataLoaderPlugin";
|
|
7
9
|
var moduleFederationPlugin = function() {
|
|
8
10
|
var userConfig = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
9
11
|
var internalModernPluginOptions = {
|
|
@@ -79,7 +81,10 @@ var moduleFederationPlugin = function() {
|
|
|
79
81
|
}(),
|
|
80
82
|
usePlugins: [
|
|
81
83
|
moduleFederationConfigPlugin(internalModernPluginOptions),
|
|
82
|
-
moduleFederationSSRPlugin(internalModernPluginOptions)
|
|
84
|
+
moduleFederationSSRPlugin(internalModernPluginOptions),
|
|
85
|
+
moduleFederationDataLoaderPlugin(Boolean(userConfig.dataLoader), internalModernPluginOptions, _object_spread({
|
|
86
|
+
baseName: ""
|
|
87
|
+
}, userConfig.dataLoader))
|
|
83
88
|
]
|
|
84
89
|
};
|
|
85
90
|
};
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
|
2
|
+
import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
|
|
3
|
+
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
4
|
+
import { getInstance, init } from "@module-federation/enhanced/runtime";
|
|
5
|
+
import { MF_SLIM_ROUTES } from "../../runtime/constant";
|
|
6
|
+
function dataLoaderPlugin_default(mfRuntimeOptions) {
|
|
7
|
+
return {
|
|
8
|
+
name: "MFDataLoaderServerPlugin",
|
|
9
|
+
pre: [
|
|
10
|
+
"@modern-js/plugin-inject-resource"
|
|
11
|
+
],
|
|
12
|
+
setup: function setup(api) {
|
|
13
|
+
var remotes = mfRuntimeOptions.remotes, name = mfRuntimeOptions.name;
|
|
14
|
+
if (!remotes.length) {
|
|
15
|
+
return {};
|
|
16
|
+
}
|
|
17
|
+
var isHandled = false;
|
|
18
|
+
return {
|
|
19
|
+
prepare: function prepare() {
|
|
20
|
+
var middlewares = api.useAppContext().middlewares;
|
|
21
|
+
middlewares.push({
|
|
22
|
+
name: "MFDataLoaderServerPlugin",
|
|
23
|
+
handler: function() {
|
|
24
|
+
var _ref = _async_to_generator(function(c, next) {
|
|
25
|
+
var serverManifest, loaderBundles, instance, slimRoutes;
|
|
26
|
+
return _ts_generator(this, function(_state) {
|
|
27
|
+
switch (_state.label) {
|
|
28
|
+
case 0:
|
|
29
|
+
console.log("isHandled : ", isHandled);
|
|
30
|
+
serverManifest = c.get("serverManifest");
|
|
31
|
+
loaderBundles = serverManifest.loaderBundles;
|
|
32
|
+
console.log("loaderBundles.main.routes : ", loaderBundles.main.routes);
|
|
33
|
+
if (!isHandled)
|
|
34
|
+
return [
|
|
35
|
+
3,
|
|
36
|
+
2
|
|
37
|
+
];
|
|
38
|
+
return [
|
|
39
|
+
4,
|
|
40
|
+
next()
|
|
41
|
+
];
|
|
42
|
+
case 1:
|
|
43
|
+
_state.sent();
|
|
44
|
+
return [
|
|
45
|
+
3,
|
|
46
|
+
5
|
|
47
|
+
];
|
|
48
|
+
case 2:
|
|
49
|
+
instance = getInstance() || init({
|
|
50
|
+
name,
|
|
51
|
+
remotes
|
|
52
|
+
});
|
|
53
|
+
return [
|
|
54
|
+
4,
|
|
55
|
+
Promise.all(remotes.map(function() {
|
|
56
|
+
var _ref2 = _async_to_generator(function(remote) {
|
|
57
|
+
var _ref3, routes, baseName;
|
|
58
|
+
return _ts_generator(this, function(_state2) {
|
|
59
|
+
switch (_state2.label) {
|
|
60
|
+
case 0:
|
|
61
|
+
return [
|
|
62
|
+
4,
|
|
63
|
+
instance.loadRemote("".concat(remote.name, "/").concat(MF_SLIM_ROUTES))
|
|
64
|
+
];
|
|
65
|
+
case 1:
|
|
66
|
+
_ref3 = _state2.sent(), routes = _ref3.routes, baseName = _ref3.baseName;
|
|
67
|
+
return [
|
|
68
|
+
2,
|
|
69
|
+
{
|
|
70
|
+
routes,
|
|
71
|
+
baseName
|
|
72
|
+
}
|
|
73
|
+
];
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
return function(remote) {
|
|
78
|
+
return _ref2.apply(this, arguments);
|
|
79
|
+
};
|
|
80
|
+
}()))
|
|
81
|
+
];
|
|
82
|
+
case 3:
|
|
83
|
+
slimRoutes = _state.sent();
|
|
84
|
+
slimRoutes.forEach(function(slimRoute) {
|
|
85
|
+
var _loaderBundles_main_routes;
|
|
86
|
+
var routes = slimRoute.routes, baseName = slimRoute.baseName;
|
|
87
|
+
routes[0].path = "/".concat(baseName);
|
|
88
|
+
(_loaderBundles_main_routes = loaderBundles.main.routes).push.apply(_loaderBundles_main_routes, _to_consumable_array(routes));
|
|
89
|
+
});
|
|
90
|
+
console.log("loaderBundles.main.routes : ", loaderBundles.main.routes);
|
|
91
|
+
isHandled = true;
|
|
92
|
+
return [
|
|
93
|
+
4,
|
|
94
|
+
next()
|
|
95
|
+
];
|
|
96
|
+
case 4:
|
|
97
|
+
_state.sent();
|
|
98
|
+
_state.label = 5;
|
|
99
|
+
case 5:
|
|
100
|
+
return [
|
|
101
|
+
2
|
|
102
|
+
];
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
return function(c, next) {
|
|
107
|
+
return _ref.apply(this, arguments);
|
|
108
|
+
};
|
|
109
|
+
}(),
|
|
110
|
+
before: [
|
|
111
|
+
"render"
|
|
112
|
+
]
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
;
|
|
120
|
+
export {
|
|
121
|
+
dataLoaderPlugin_default as default
|
|
122
|
+
};
|
|
@@ -2,9 +2,9 @@ import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
|
|
2
2
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
3
3
|
import path from "path";
|
|
4
4
|
import { fs } from "@modern-js/utils";
|
|
5
|
-
import { ModuleFederationPlugin } from "@module-federation/enhanced
|
|
5
|
+
import { ModuleFederationPlugin } from "@module-federation/enhanced";
|
|
6
6
|
import { ModuleFederationPlugin as RspackModuleFederationPlugin } from "@module-federation/enhanced/rspack";
|
|
7
|
-
import UniverseEntryChunkTrackerPlugin from "@module-federation/node
|
|
7
|
+
import { UniverseEntryChunkTrackerPlugin } from "@module-federation/node";
|
|
8
8
|
import { updateStatsAndManifest } from "./manifest";
|
|
9
9
|
import { isDev } from "./constant";
|
|
10
10
|
function setEnv() {
|
|
File without changes
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
|
2
|
+
import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
|
|
3
|
+
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
4
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
5
|
+
import { getInstance, loadRemote } from "@module-federation/enhanced/runtime";
|
|
6
|
+
import { MF_FULL_ROUTES } from "./constant";
|
|
7
|
+
globalThis.mfRemoteRoutes = globalThis.mfRemoteRoutes || [];
|
|
8
|
+
var _globalThis_mfHasLoadedRemoteRoutes;
|
|
9
|
+
globalThis.mfHasLoadedRemoteRoutes = (_globalThis_mfHasLoadedRemoteRoutes = globalThis.mfHasLoadedRemoteRoutes) !== null && _globalThis_mfHasLoadedRemoteRoutes !== void 0 ? _globalThis_mfHasLoadedRemoteRoutes : false;
|
|
10
|
+
function loadRoutes() {
|
|
11
|
+
return _loadRoutes.apply(this, arguments);
|
|
12
|
+
}
|
|
13
|
+
function _loadRoutes() {
|
|
14
|
+
_loadRoutes = _async_to_generator(function() {
|
|
15
|
+
var _getInstance, remotes, remoteModuleIds, traverse;
|
|
16
|
+
return _ts_generator(this, function(_state) {
|
|
17
|
+
switch (_state.label) {
|
|
18
|
+
case 0:
|
|
19
|
+
if (globalThis.mfHasLoadedRemoteRoutes) {
|
|
20
|
+
return [
|
|
21
|
+
2
|
|
22
|
+
];
|
|
23
|
+
}
|
|
24
|
+
remotes = (_getInstance = getInstance()) === null || _getInstance === void 0 ? void 0 : _getInstance.options.remotes;
|
|
25
|
+
if (!remotes) {
|
|
26
|
+
return [
|
|
27
|
+
2
|
|
28
|
+
];
|
|
29
|
+
}
|
|
30
|
+
remoteModuleIds = remotes.map(function(remote) {
|
|
31
|
+
return "".concat(remote.name, "/").concat(MF_FULL_ROUTES);
|
|
32
|
+
});
|
|
33
|
+
traverse = function(cRoutes, prefix) {
|
|
34
|
+
cRoutes.forEach(function(i) {
|
|
35
|
+
i.id = prefix + i.id;
|
|
36
|
+
var Comp = i.component;
|
|
37
|
+
i.element = /* @__PURE__ */ _jsx(Comp, {});
|
|
38
|
+
if (i.children) {
|
|
39
|
+
traverse(i.children, prefix);
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
return [
|
|
44
|
+
4,
|
|
45
|
+
Promise.all(remoteModuleIds.map(function() {
|
|
46
|
+
var _ref = _async_to_generator(function(remoteModuleId) {
|
|
47
|
+
var _globalThis_mfRemoteRoutes, remoteName, _ref2, routes, baseName;
|
|
48
|
+
return _ts_generator(this, function(_state2) {
|
|
49
|
+
switch (_state2.label) {
|
|
50
|
+
case 0:
|
|
51
|
+
remoteName = remoteModuleId.split("/".concat(MF_FULL_ROUTES))[0];
|
|
52
|
+
return [
|
|
53
|
+
4,
|
|
54
|
+
loadRemote(remoteModuleId)
|
|
55
|
+
];
|
|
56
|
+
case 1:
|
|
57
|
+
_ref2 = _state2.sent(), routes = _ref2.routes, baseName = _ref2.baseName;
|
|
58
|
+
routes[0].path = "/".concat(baseName);
|
|
59
|
+
routes[0].isRoot = false;
|
|
60
|
+
(_globalThis_mfRemoteRoutes = globalThis.mfRemoteRoutes).push.apply(_globalThis_mfRemoteRoutes, _to_consumable_array(routes));
|
|
61
|
+
return [
|
|
62
|
+
2
|
|
63
|
+
];
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
return function(remoteModuleId) {
|
|
68
|
+
return _ref.apply(this, arguments);
|
|
69
|
+
};
|
|
70
|
+
}()))
|
|
71
|
+
];
|
|
72
|
+
case 1:
|
|
73
|
+
_state.sent();
|
|
74
|
+
globalThis.mfHasLoadedRemoteRoutes = true;
|
|
75
|
+
return [
|
|
76
|
+
2,
|
|
77
|
+
globalThis.mfRemoteRoutes
|
|
78
|
+
];
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
return _loadRoutes.apply(this, arguments);
|
|
83
|
+
}
|
|
84
|
+
var ssrDataLoaderPlugin = function() {
|
|
85
|
+
return {
|
|
86
|
+
name: "@modern-js/plugin-mf-data-loader",
|
|
87
|
+
post: [
|
|
88
|
+
"@modern-js/plugin-router"
|
|
89
|
+
],
|
|
90
|
+
setup: function() {
|
|
91
|
+
return {
|
|
92
|
+
beforeRender: function beforeRender(param) {
|
|
93
|
+
var context = param.context;
|
|
94
|
+
return _async_to_generator(function() {
|
|
95
|
+
return _ts_generator(this, function(_state) {
|
|
96
|
+
switch (_state.label) {
|
|
97
|
+
case 0:
|
|
98
|
+
console.log("init");
|
|
99
|
+
return [
|
|
100
|
+
4,
|
|
101
|
+
loadRoutes()
|
|
102
|
+
];
|
|
103
|
+
case 1:
|
|
104
|
+
_state.sent();
|
|
105
|
+
return [
|
|
106
|
+
2
|
|
107
|
+
];
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
})();
|
|
111
|
+
},
|
|
112
|
+
modifyRoutes: function(routes) {
|
|
113
|
+
var _routes;
|
|
114
|
+
console.log("modifyRoutes");
|
|
115
|
+
(_routes = routes).push.apply(_routes, _to_consumable_array(globalThis.mfRemoteRoutes));
|
|
116
|
+
console.log("routes: ", routes);
|
|
117
|
+
return routes;
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
};
|
|
123
|
+
export {
|
|
124
|
+
ssrDataLoaderPlugin
|
|
125
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { _ as _define_property } from "@swc/helpers/_/_define_property";
|
|
2
|
+
function transformName2Prefix(name) {
|
|
3
|
+
var NameTransformSymbol = {
|
|
4
|
+
AT: "@",
|
|
5
|
+
HYPHEN: "-",
|
|
6
|
+
SLASH: "/",
|
|
7
|
+
UNDERLINE: "_"
|
|
8
|
+
};
|
|
9
|
+
var _obj;
|
|
10
|
+
var NameTransformMap = (_obj = {}, _define_property(_obj, NameTransformSymbol.AT, "SCOPE"), _define_property(_obj, NameTransformSymbol.HYPHEN, "HYPHEN"), _define_property(_obj, NameTransformSymbol.SLASH, "SLASH"), _define_property(_obj, NameTransformSymbol.UNDERLINE, "UNDERLINE"), _obj);
|
|
11
|
+
var SPLIT_SYMBOL = "@";
|
|
12
|
+
return "".concat(name.replace(new RegExp("".concat(NameTransformSymbol.AT), "g"), NameTransformMap[NameTransformSymbol.AT]).replace(new RegExp("".concat(NameTransformSymbol.HYPHEN), "g"), NameTransformMap[NameTransformSymbol.HYPHEN]).replace(new RegExp("".concat(NameTransformSymbol.SLASH), "g"), NameTransformMap[NameTransformSymbol.SLASH]).replace(new RegExp("".concat(NameTransformSymbol.UNDERLINE), "g"), NameTransformMap[NameTransformSymbol.UNDERLINE])).concat(SPLIT_SYMBOL);
|
|
13
|
+
}
|
|
14
|
+
export {
|
|
15
|
+
transformName2Prefix
|
|
16
|
+
};
|
|
@@ -4,24 +4,22 @@ import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
|
4
4
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
5
5
|
import hoistNonReactStatics from "hoist-non-react-statics";
|
|
6
6
|
import { SSRLiveReload } from "./SSRLiveReload";
|
|
7
|
+
console.log("mfSSRPlugin trigger");
|
|
7
8
|
var mfSSRPlugin = function() {
|
|
8
9
|
return {
|
|
9
10
|
name: "@module-federation/modern-js",
|
|
10
11
|
setup: function() {
|
|
11
12
|
return {
|
|
12
|
-
|
|
13
|
-
var context = param.context;
|
|
13
|
+
beforeRender: function beforeRender() {
|
|
14
14
|
return _async_to_generator(function() {
|
|
15
15
|
var nodeUtils, shouldUpdate;
|
|
16
16
|
return _ts_generator(this, function(_state) {
|
|
17
17
|
switch (_state.label) {
|
|
18
18
|
case 0:
|
|
19
|
+
console.log(111, "beforeRender");
|
|
19
20
|
if (typeof window !== "undefined") {
|
|
20
21
|
return [
|
|
21
|
-
2
|
|
22
|
-
next({
|
|
23
|
-
context
|
|
24
|
-
})
|
|
22
|
+
2
|
|
25
23
|
];
|
|
26
24
|
}
|
|
27
25
|
globalThis.shouldUpdate = false;
|
|
@@ -53,10 +51,7 @@ var mfSSRPlugin = function() {
|
|
|
53
51
|
_state.label = 4;
|
|
54
52
|
case 4:
|
|
55
53
|
return [
|
|
56
|
-
2
|
|
57
|
-
next({
|
|
58
|
-
context
|
|
59
|
-
})
|
|
54
|
+
2
|
|
60
55
|
];
|
|
61
56
|
}
|
|
62
57
|
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
const IS_ROOT = "isRoot";
|
|
2
|
+
const ID = "id";
|
|
3
|
+
const COMPONENT = "component";
|
|
4
|
+
const LAZY_COMPONENT = "lazyImport";
|
|
5
|
+
const SHOULD_REVALIDATE = "shouldRevalidate";
|
|
6
|
+
const PRIVATE_COMPONENT = "_component";
|
|
7
|
+
const ELEMENT = "element";
|
|
8
|
+
export {
|
|
9
|
+
COMPONENT,
|
|
10
|
+
ELEMENT,
|
|
11
|
+
ID,
|
|
12
|
+
IS_ROOT,
|
|
13
|
+
LAZY_COMPONENT,
|
|
14
|
+
PRIVATE_COMPONENT,
|
|
15
|
+
SHOULD_REVALIDATE
|
|
16
|
+
};
|