@module-federation/modern-js 0.0.0-next-20241014085010 → 0.0.0-next-20241015060033
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/{dataLoader/ast/index.js → constant.js} +6 -6
- package/dist/cjs/cli/index.js +1 -5
- package/dist/cjs/cli/mfRuntimePlugins/{node-fetch.js → inject-node-fetch.js} +6 -6
- package/dist/cjs/cli/mfRuntimePlugins/resolve-entry-ipv4.js +38 -40
- package/dist/cjs/{runtime/withMFRouteId.js → cli/mfRuntimePlugins/shared-strategy.js} +23 -11
- package/dist/cjs/cli/ssrPlugin.js +2 -5
- package/dist/cjs/cli/utils.js +6 -11
- package/dist/cjs/cli/utils.spec.js +6 -5
- package/dist/cjs/constant.js +2 -35
- package/dist/cjs/runtime/index.js +1 -4
- package/dist/cjs/ssr-runtime/plugin.js +8 -7
- package/dist/esm/cli/constant.js +4 -0
- package/dist/esm/cli/index.js +2 -6
- package/dist/esm/cli/mfRuntimePlugins/{node-fetch.js → inject-node-fetch.js} +3 -3
- package/dist/esm/cli/mfRuntimePlugins/shared-strategy.js +25 -0
- package/dist/esm/cli/ssrPlugin.js +3 -6
- package/dist/esm/cli/utils.js +8 -13
- package/dist/esm/cli/utils.spec.js +6 -5
- package/dist/esm/constant.js +1 -23
- package/dist/esm/runtime/index.js +1 -3
- package/dist/esm/ssr-runtime/plugin.js +11 -8
- package/dist/esm-node/cli/constant.js +4 -0
- package/dist/esm-node/cli/index.js +1 -5
- package/dist/esm-node/cli/mfRuntimePlugins/{node-fetch.js → inject-node-fetch.js} +3 -3
- package/dist/esm-node/cli/mfRuntimePlugins/resolve-entry-ipv4.js +38 -40
- package/dist/esm-node/cli/mfRuntimePlugins/shared-strategy.js +23 -0
- package/dist/esm-node/cli/ssrPlugin.js +2 -5
- package/dist/esm-node/cli/utils.js +5 -9
- package/dist/esm-node/cli/utils.spec.js +6 -5
- package/dist/esm-node/constant.js +1 -23
- package/dist/esm-node/runtime/index.js +1 -3
- package/dist/esm-node/ssr-runtime/plugin.js +8 -7
- package/dist/types/cli/constant.d.ts +1 -0
- package/dist/types/cli/mfRuntimePlugins/shared-strategy.d.ts +3 -0
- package/dist/types/cli/utils.d.ts +0 -2
- package/dist/types/constant.d.ts +0 -11
- package/dist/types/runtime/index.d.ts +0 -1
- package/dist/types/ssr-runtime/plugin.d.ts +1 -3
- package/dist/types/types/index.d.ts +0 -8
- package/package.json +11 -48
- package/dist/cjs/cli/dataLoader/ast/constant.js +0 -49
- package/dist/cjs/cli/dataLoader/ast/generateRoutes.js +0 -143
- package/dist/cjs/cli/dataLoader/clearMFCache.js +0 -57
- package/dist/cjs/cli/dataLoader/generateRouteFile.js +0 -148
- package/dist/cjs/cli/dataLoader/patchMFConfig.js +0 -160
- package/dist/cjs/cli/dataLoader/plugin.js +0 -219
- package/dist/cjs/cli/mfRuntimePlugins/node.js +0 -41
- package/dist/cjs/cli/server/dataLoaderPlugin.js +0 -81
- package/dist/cjs/cli/server/fetchRemoteFullRoutesMap.js +0 -72
- package/dist/cjs/interfaces/route.js +0 -16
- package/dist/cjs/runtime/dataLoader/plugin-inject-assets.js +0 -92
- package/dist/cjs/runtime/dataLoader/plugin.js +0 -75
- package/dist/cjs/runtime/dataLoader/utils.js +0 -115
- package/dist/cjs/types/modern.js +0 -16
- package/dist/esm/cli/dataLoader/ast/constant.js +0 -18
- package/dist/esm/cli/dataLoader/ast/generateRoutes.js +0 -110
- package/dist/esm/cli/dataLoader/ast/index.js +0 -4
- package/dist/esm/cli/dataLoader/clearMFCache.js +0 -34
- package/dist/esm/cli/dataLoader/generateRouteFile.js +0 -308
- package/dist/esm/cli/dataLoader/patchMFConfig.js +0 -124
- package/dist/esm/cli/dataLoader/plugin.js +0 -341
- package/dist/esm/cli/mfRuntimePlugins/node.js +0 -13
- package/dist/esm/cli/server/dataLoaderPlugin.js +0 -104
- package/dist/esm/cli/server/fetchRemoteFullRoutesMap.js +0 -93
- package/dist/esm/interfaces/route.js +0 -0
- package/dist/esm/runtime/dataLoader/plugin-inject-assets.js +0 -71
- package/dist/esm/runtime/dataLoader/plugin.js +0 -97
- package/dist/esm/runtime/dataLoader/utils.js +0 -86
- package/dist/esm/runtime/withMFRouteId.js +0 -7
- package/dist/esm/types/modern.js +0 -0
- package/dist/esm-node/cli/dataLoader/ast/constant.js +0 -18
- package/dist/esm-node/cli/dataLoader/ast/generateRoutes.js +0 -109
- package/dist/esm-node/cli/dataLoader/ast/index.js +0 -4
- package/dist/esm-node/cli/dataLoader/clearMFCache.js +0 -33
- package/dist/esm-node/cli/dataLoader/generateRouteFile.js +0 -113
- package/dist/esm-node/cli/dataLoader/patchMFConfig.js +0 -126
- package/dist/esm-node/cli/dataLoader/plugin.js +0 -184
- package/dist/esm-node/cli/mfRuntimePlugins/node.js +0 -11
- package/dist/esm-node/cli/server/dataLoaderPlugin.js +0 -61
- package/dist/esm-node/cli/server/fetchRemoteFullRoutesMap.js +0 -47
- package/dist/esm-node/interfaces/route.js +0 -0
- package/dist/esm-node/runtime/dataLoader/plugin-inject-assets.js +0 -68
- package/dist/esm-node/runtime/dataLoader/plugin.js +0 -51
- package/dist/esm-node/runtime/dataLoader/utils.js +0 -86
- package/dist/esm-node/runtime/withMFRouteId.js +0 -7
- package/dist/esm-node/types/modern.js +0 -0
- package/dist/types/cli/dataLoader/ast/constant.d.ts +0 -8
- package/dist/types/cli/dataLoader/ast/generateRoutes.d.ts +0 -5
- package/dist/types/cli/dataLoader/ast/index.d.ts +0 -1
- package/dist/types/cli/dataLoader/clearMFCache.d.ts +0 -1
- package/dist/types/cli/dataLoader/generateRouteFile.d.ts +0 -10
- package/dist/types/cli/dataLoader/patchMFConfig.d.ts +0 -10
- package/dist/types/cli/dataLoader/plugin.d.ts +0 -6
- package/dist/types/cli/mfRuntimePlugins/node.d.ts +0 -3
- package/dist/types/cli/server/dataLoaderPlugin.d.ts +0 -10
- package/dist/types/cli/server/fetchRemoteFullRoutesMap.d.ts +0 -11
- package/dist/types/interfaces/route.d.ts +0 -12
- package/dist/types/runtime/dataLoader/plugin-inject-assets.d.ts +0 -4
- package/dist/types/runtime/dataLoader/plugin.d.ts +0 -5
- package/dist/types/runtime/dataLoader/utils.d.ts +0 -22
- package/dist/types/runtime/withMFRouteId.d.ts +0 -1
- package/dist/types/types/modern.d.ts +0 -12
- /package/dist/types/cli/mfRuntimePlugins/{node-fetch.d.ts → inject-node-fetch.d.ts} +0 -0
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
import { _ as _define_property } from "@swc/helpers/_/_define_property";
|
|
2
|
-
import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
|
|
3
|
-
import path from "path";
|
|
4
|
-
import { fs } from "@modern-js/utils";
|
|
5
|
-
import { MODERN_JS_ROUTE_SERVER_LOADER } from "../../constant";
|
|
6
|
-
import { MF_ROUTES, MODERN_JS_FILE_SYSTEM_ROUTES_FILE_NAME } from "../../constant";
|
|
7
|
-
import { generateRoutes } from "./ast";
|
|
8
|
-
function generateExtraExposeFiles(options) {
|
|
9
|
-
var internalDirectory = options.internalDirectory, mfConfig = options.mfConfig, isServer = options.isServer, entries = options.entries;
|
|
10
|
-
var entryMap = {};
|
|
11
|
-
var outputDir = path.resolve(process.cwd(), "node_modules/.federation/data-loader");
|
|
12
|
-
fs.ensureDirSync(outputDir);
|
|
13
|
-
var addSuffix = function(fileName) {
|
|
14
|
-
var ext = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : ".jsx";
|
|
15
|
-
if (!isServer) {
|
|
16
|
-
return "".concat(fileName).concat(ext);
|
|
17
|
-
}
|
|
18
|
-
return "".concat(fileName, ".server").concat(ext);
|
|
19
|
-
};
|
|
20
|
-
var generateEntryRoutes = function(entry) {
|
|
21
|
-
var outputEntryDir = path.resolve(outputDir, entry);
|
|
22
|
-
fs.ensureDirSync(outputEntryDir);
|
|
23
|
-
var sourceDir = path.resolve(internalDirectory, entry);
|
|
24
|
-
var routesFilePath = path.resolve(sourceDir, addSuffix(MODERN_JS_FILE_SYSTEM_ROUTES_FILE_NAME, ".js"));
|
|
25
|
-
var routesFileContent = fs.readFileSync(routesFilePath, "utf-8");
|
|
26
|
-
var outputFullRoutesPath = path.resolve(outputEntryDir, addSuffix(MF_ROUTES));
|
|
27
|
-
generateRoutes({
|
|
28
|
-
sourceCode: routesFileContent,
|
|
29
|
-
filePath: outputFullRoutesPath
|
|
30
|
-
});
|
|
31
|
-
var routeServerLoaderPath = path.resolve(sourceDir, "".concat(MODERN_JS_ROUTE_SERVER_LOADER, ".js"));
|
|
32
|
-
var outputRouteServerLoaderPath = path.resolve(outputEntryDir, "".concat(MODERN_JS_ROUTE_SERVER_LOADER, ".js"));
|
|
33
|
-
var clientRouteServerLoaderPath = outputRouteServerLoaderPath.replace(MODERN_JS_ROUTE_SERVER_LOADER, "".concat(MODERN_JS_ROUTE_SERVER_LOADER, "-client"));
|
|
34
|
-
if (isServer) {
|
|
35
|
-
var routeServerLoaderContent = fs.readFileSync(routeServerLoaderPath, "utf-8");
|
|
36
|
-
generateRoutes({
|
|
37
|
-
sourceCode: routeServerLoaderContent,
|
|
38
|
-
filePath: outputRouteServerLoaderPath
|
|
39
|
-
});
|
|
40
|
-
} else {
|
|
41
|
-
fs.writeFileSync(clientRouteServerLoaderPath, "export const routes = []");
|
|
42
|
-
}
|
|
43
|
-
entryMap[entry] = {
|
|
44
|
-
routesPath: outputFullRoutesPath,
|
|
45
|
-
routeServerLoaderPath: outputRouteServerLoaderPath,
|
|
46
|
-
clientRouteServerLoaderPath
|
|
47
|
-
};
|
|
48
|
-
};
|
|
49
|
-
entries.forEach(function(entry) {
|
|
50
|
-
generateEntryRoutes(entry);
|
|
51
|
-
});
|
|
52
|
-
return {
|
|
53
|
-
entryMap
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
function addExpose(options) {
|
|
57
|
-
var mfConfig = options.mfConfig, isServer = options.isServer;
|
|
58
|
-
var entryMap = generateExtraExposeFiles(options).entryMap;
|
|
59
|
-
var addExposeByEntry = function(entry, routesPath, routeServerLoaderPath, clientRouteServerLoaderPath) {
|
|
60
|
-
if (!mfConfig.exposes) {
|
|
61
|
-
mfConfig.exposes = {};
|
|
62
|
-
}
|
|
63
|
-
var routesKey = "./".concat(entry, "/").concat(MF_ROUTES);
|
|
64
|
-
if (!mfConfig.exposes[routesKey]) {
|
|
65
|
-
mfConfig.exposes[routesKey] = routesPath;
|
|
66
|
-
}
|
|
67
|
-
var routeServerLoaderKey = "./".concat(entry, "/").concat(MODERN_JS_ROUTE_SERVER_LOADER);
|
|
68
|
-
if (!mfConfig.exposes[routeServerLoaderKey]) {
|
|
69
|
-
if (isServer) {
|
|
70
|
-
mfConfig.exposes[routeServerLoaderKey] = routeServerLoaderPath;
|
|
71
|
-
} else {
|
|
72
|
-
mfConfig.exposes[routeServerLoaderKey] = clientRouteServerLoaderPath;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
};
|
|
76
|
-
Object.keys(entryMap).forEach(function(entry) {
|
|
77
|
-
var _entryMap_entry = entryMap[entry], routesPath = _entryMap_entry.routesPath, routeServerLoaderPath = _entryMap_entry.routeServerLoaderPath, clientRouteServerLoaderPath = _entryMap_entry.clientRouteServerLoaderPath;
|
|
78
|
-
addExposeByEntry(entry, routesPath, routeServerLoaderPath, clientRouteServerLoaderPath);
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
function addShared(options) {
|
|
82
|
-
var metaName = options.metaName, mfConfig = options.mfConfig;
|
|
83
|
-
var reactRouterDom = "react-router-dom";
|
|
84
|
-
var reactRouterDomServer = "react-router-dom/server";
|
|
85
|
-
if (!mfConfig.shared) {
|
|
86
|
-
var _obj;
|
|
87
|
-
mfConfig.shared = (_obj = {}, _define_property(_obj, reactRouterDom, {
|
|
88
|
-
singleton: true
|
|
89
|
-
}), _define_property(_obj, reactRouterDomServer, {
|
|
90
|
-
singleton: true
|
|
91
|
-
}), _obj);
|
|
92
|
-
} else {
|
|
93
|
-
if (!Array.isArray(mfConfig.shared)) {
|
|
94
|
-
mfConfig.shared[reactRouterDom] = {
|
|
95
|
-
singleton: true
|
|
96
|
-
};
|
|
97
|
-
mfConfig.shared[reactRouterDomServer] = {
|
|
98
|
-
singleton: true
|
|
99
|
-
};
|
|
100
|
-
} else {
|
|
101
|
-
mfConfig.shared = mfConfig.shared.reduce(function(sum, cur) {
|
|
102
|
-
if (typeof cur === "string") {
|
|
103
|
-
sum[cur] = {};
|
|
104
|
-
} else {
|
|
105
|
-
sum = _object_spread({}, sum, cur);
|
|
106
|
-
}
|
|
107
|
-
return sum;
|
|
108
|
-
}, {});
|
|
109
|
-
mfConfig.shared[reactRouterDom] = {
|
|
110
|
-
singleton: true
|
|
111
|
-
};
|
|
112
|
-
mfConfig.shared[reactRouterDomServer] = {
|
|
113
|
-
singleton: true
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
function patchMFConfig(options) {
|
|
119
|
-
addShared(options);
|
|
120
|
-
addExpose(options);
|
|
121
|
-
}
|
|
122
|
-
export {
|
|
123
|
-
patchMFConfig
|
|
124
|
-
};
|
|
@@ -1,341 +0,0 @@
|
|
|
1
|
-
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
|
2
|
-
import { _ as _sliced_to_array } from "@swc/helpers/_/_sliced_to_array";
|
|
3
|
-
import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
|
|
4
|
-
import { _ as _type_of } from "@swc/helpers/_/_type_of";
|
|
5
|
-
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
6
|
-
import { fs } from "@modern-js/utils";
|
|
7
|
-
import { transformName2Prefix } from "../../runtime/dataLoader/utils";
|
|
8
|
-
import { DEFAULT_ENTRY, ROUTE_ID } from "../../constant";
|
|
9
|
-
import { META_NAME } from "../../constant";
|
|
10
|
-
import { generateRoutes } from "./ast";
|
|
11
|
-
import { generateRouteFile } from "./generateRouteFile";
|
|
12
|
-
import { patchMFConfig } from "./patchMFConfig";
|
|
13
|
-
import { clearMFCache } from "./clearMFCache";
|
|
14
|
-
import path from "path";
|
|
15
|
-
function _transformRuntimeOptions(buildOptions) {
|
|
16
|
-
var remotes = buildOptions.remotes || {};
|
|
17
|
-
var runtimeRemotes = Object.entries(remotes).map(function(remote) {
|
|
18
|
-
var _remote = _sliced_to_array(remote, 2), alias = _remote[0], nameAndEntry = _remote[1];
|
|
19
|
-
var _nameAndEntry_split = _sliced_to_array(nameAndEntry.split("@"), 2), name = _nameAndEntry_split[0], entry = _nameAndEntry_split[1];
|
|
20
|
-
return {
|
|
21
|
-
name,
|
|
22
|
-
entry,
|
|
23
|
-
alias
|
|
24
|
-
};
|
|
25
|
-
});
|
|
26
|
-
return {
|
|
27
|
-
name: buildOptions.name,
|
|
28
|
-
remotes: runtimeRemotes
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
var moduleFederationDataLoaderPlugin = function(enable, internalOptions, userConfig) {
|
|
32
|
-
return {
|
|
33
|
-
name: "@modern-js/plugin-module-federation-data-loader",
|
|
34
|
-
pre: [
|
|
35
|
-
"@modern-js/plugin-module-federation-config"
|
|
36
|
-
],
|
|
37
|
-
post: [
|
|
38
|
-
"@modern-js/plugin-router",
|
|
39
|
-
"@modern-js/plugin-module-federation"
|
|
40
|
-
],
|
|
41
|
-
setup: function() {
|
|
42
|
-
var _ref = _async_to_generator(function(param) {
|
|
43
|
-
var useAppContext, _userConfig_serverPlugin, serverPlugin, transformRuntimeOptions, appContext, name, _internalOptions_metaName, metaName, internalDirectory, transformRuntimeFn, entries, remotePathMap, ssrByRouteIdsMap, csrConfig, _ref2, scanEntries, scanRemotePathMap, dataLoaderRemotes, serverPluginOptions, hasDataLoaderRemotes;
|
|
44
|
-
return _ts_generator(this, function(_state) {
|
|
45
|
-
switch (_state.label) {
|
|
46
|
-
case 0:
|
|
47
|
-
useAppContext = param.useAppContext;
|
|
48
|
-
if (!enable) {
|
|
49
|
-
return [
|
|
50
|
-
2
|
|
51
|
-
];
|
|
52
|
-
}
|
|
53
|
-
_userConfig_serverPlugin = userConfig.serverPlugin, serverPlugin = _userConfig_serverPlugin === void 0 ? "@module-federation/modern-js/data-loader-server" : _userConfig_serverPlugin, transformRuntimeOptions = userConfig.transformRuntimeOptions;
|
|
54
|
-
appContext = useAppContext();
|
|
55
|
-
name = internalOptions.csrConfig.name;
|
|
56
|
-
_internalOptions_metaName = internalOptions.metaName, metaName = _internalOptions_metaName === void 0 ? META_NAME : _internalOptions_metaName;
|
|
57
|
-
internalDirectory = appContext.internalDirectory.replace(META_NAME, metaName || META_NAME);
|
|
58
|
-
transformRuntimeFn = transformRuntimeOptions || _transformRuntimeOptions;
|
|
59
|
-
entries = /* @__PURE__ */ new Set();
|
|
60
|
-
remotePathMap = {};
|
|
61
|
-
ssrByRouteIdsMap = {};
|
|
62
|
-
csrConfig = internalOptions.csrConfig;
|
|
63
|
-
if (!(_type_of(csrConfig.remotes) === "object" && Object.keys(csrConfig.remotes).length))
|
|
64
|
-
return [
|
|
65
|
-
3,
|
|
66
|
-
2
|
|
67
|
-
];
|
|
68
|
-
return [
|
|
69
|
-
4,
|
|
70
|
-
generateRouteFile({
|
|
71
|
-
appDirectory: appContext.appDirectory
|
|
72
|
-
})
|
|
73
|
-
];
|
|
74
|
-
case 1:
|
|
75
|
-
_ref2 = _state.sent(), scanEntries = _ref2.entries, scanRemotePathMap = _ref2.remotePathMap;
|
|
76
|
-
scanEntries.forEach(function(e) {
|
|
77
|
-
return entries.add(e);
|
|
78
|
-
});
|
|
79
|
-
remotePathMap = scanRemotePathMap;
|
|
80
|
-
return [
|
|
81
|
-
3,
|
|
82
|
-
3
|
|
83
|
-
];
|
|
84
|
-
case 2:
|
|
85
|
-
entries.add(DEFAULT_ENTRY);
|
|
86
|
-
_state.label = 3;
|
|
87
|
-
case 3:
|
|
88
|
-
dataLoaderRemotes = _to_consumable_array(new Set(Object.values(remotePathMap).map(function(i) {
|
|
89
|
-
return i.name;
|
|
90
|
-
})));
|
|
91
|
-
serverPluginOptions = {
|
|
92
|
-
runtimeOptions: transformRuntimeFn(internalOptions.csrConfig),
|
|
93
|
-
dataLoaderRemotes,
|
|
94
|
-
ssrByRouteIdsMap
|
|
95
|
-
};
|
|
96
|
-
hasDataLoaderRemotes = function() {
|
|
97
|
-
return Boolean(serverPluginOptions.dataLoaderRemotes.length);
|
|
98
|
-
};
|
|
99
|
-
return [
|
|
100
|
-
2,
|
|
101
|
-
{
|
|
102
|
-
_internalRuntimePlugins: function(param2) {
|
|
103
|
-
var entrypoint = param2.entrypoint, plugins = param2.plugins;
|
|
104
|
-
if (!hasDataLoaderRemotes()) {
|
|
105
|
-
return {
|
|
106
|
-
entrypoint,
|
|
107
|
-
plugins
|
|
108
|
-
};
|
|
109
|
-
}
|
|
110
|
-
plugins.push({
|
|
111
|
-
name: "ssrDataLoader",
|
|
112
|
-
path: "@module-federation/modern-js/data-loader",
|
|
113
|
-
config: {
|
|
114
|
-
metaName,
|
|
115
|
-
dataLoaderRemotes
|
|
116
|
-
}
|
|
117
|
-
});
|
|
118
|
-
plugins.push({
|
|
119
|
-
name: "ssrDataLoaderInjectAssets",
|
|
120
|
-
path: "@module-federation/modern-js/data-loader-inject-assets",
|
|
121
|
-
config: {
|
|
122
|
-
metaName,
|
|
123
|
-
dataLoaderRemotes
|
|
124
|
-
}
|
|
125
|
-
});
|
|
126
|
-
return {
|
|
127
|
-
entrypoint,
|
|
128
|
-
plugins
|
|
129
|
-
};
|
|
130
|
-
},
|
|
131
|
-
_internalServerPlugins: function _internalServerPlugins(param2) {
|
|
132
|
-
var plugins = param2.plugins;
|
|
133
|
-
if (!hasDataLoaderRemotes()) {
|
|
134
|
-
return {
|
|
135
|
-
plugins
|
|
136
|
-
};
|
|
137
|
-
}
|
|
138
|
-
plugins.push({
|
|
139
|
-
name: serverPlugin,
|
|
140
|
-
options: serverPluginOptions
|
|
141
|
-
});
|
|
142
|
-
return {
|
|
143
|
-
plugins
|
|
144
|
-
};
|
|
145
|
-
},
|
|
146
|
-
modifyFileSystemRoutes: function modifyFileSystemRoutes(options) {
|
|
147
|
-
return _async_to_generator(function() {
|
|
148
|
-
var routes, entrypoint, entryName, prefix, modifyRouteIds;
|
|
149
|
-
return _ts_generator(this, function(_state2) {
|
|
150
|
-
switch (_state2.label) {
|
|
151
|
-
case 0:
|
|
152
|
-
routes = options.routes, entrypoint = options.entrypoint;
|
|
153
|
-
entryName = entrypoint.entryName;
|
|
154
|
-
prefix = transformName2Prefix(internalOptions.csrConfig.name);
|
|
155
|
-
modifyRouteIds = function() {
|
|
156
|
-
var _ref3 = _async_to_generator(function(route, pathName) {
|
|
157
|
-
var currentPathName, originalId, remoteInfo, _$path, name2, remoteIdPrefix, isLayout, newId, content, _tmp;
|
|
158
|
-
return _ts_generator(this, function(_state3) {
|
|
159
|
-
switch (_state3.label) {
|
|
160
|
-
case 0:
|
|
161
|
-
currentPathName = route.path ? path.join(pathName, route.path) : pathName;
|
|
162
|
-
if (!route.id)
|
|
163
|
-
return [
|
|
164
|
-
3,
|
|
165
|
-
6
|
|
166
|
-
];
|
|
167
|
-
originalId = route.id;
|
|
168
|
-
route.originalId = originalId;
|
|
169
|
-
remoteInfo = remotePathMap[currentPathName];
|
|
170
|
-
if (!remoteInfo)
|
|
171
|
-
return [
|
|
172
|
-
3,
|
|
173
|
-
2
|
|
174
|
-
];
|
|
175
|
-
_$path = remoteInfo.path, name2 = remoteInfo.name;
|
|
176
|
-
remoteIdPrefix = transformName2Prefix(name2);
|
|
177
|
-
isLayout = Boolean(route.children);
|
|
178
|
-
newId = "".concat(remoteIdPrefix).concat(isLayout ? "layout" : "page");
|
|
179
|
-
ssrByRouteIdsMap[originalId] = newId;
|
|
180
|
-
content = fs.readFileSync(_$path, "utf-8");
|
|
181
|
-
return [
|
|
182
|
-
4,
|
|
183
|
-
fs.writeFile(_$path, content.replace(ROUTE_ID, originalId))
|
|
184
|
-
];
|
|
185
|
-
case 1:
|
|
186
|
-
_state3.sent();
|
|
187
|
-
route.id = newId;
|
|
188
|
-
return [
|
|
189
|
-
3,
|
|
190
|
-
3
|
|
191
|
-
];
|
|
192
|
-
case 2:
|
|
193
|
-
route.id = "".concat(prefix).concat(route.id);
|
|
194
|
-
_state3.label = 3;
|
|
195
|
-
case 3:
|
|
196
|
-
_tmp = route.children;
|
|
197
|
-
if (!_tmp)
|
|
198
|
-
return [
|
|
199
|
-
3,
|
|
200
|
-
5
|
|
201
|
-
];
|
|
202
|
-
return [
|
|
203
|
-
4,
|
|
204
|
-
Promise.all(route.children.map(function() {
|
|
205
|
-
var _ref4 = _async_to_generator(function(r) {
|
|
206
|
-
return _ts_generator(this, function(_state4) {
|
|
207
|
-
switch (_state4.label) {
|
|
208
|
-
case 0:
|
|
209
|
-
return [
|
|
210
|
-
4,
|
|
211
|
-
modifyRouteIds(r, currentPathName)
|
|
212
|
-
];
|
|
213
|
-
case 1:
|
|
214
|
-
return [
|
|
215
|
-
2,
|
|
216
|
-
_state4.sent()
|
|
217
|
-
];
|
|
218
|
-
}
|
|
219
|
-
});
|
|
220
|
-
});
|
|
221
|
-
return function(r) {
|
|
222
|
-
return _ref4.apply(this, arguments);
|
|
223
|
-
};
|
|
224
|
-
}()))
|
|
225
|
-
];
|
|
226
|
-
case 4:
|
|
227
|
-
_tmp = _state3.sent();
|
|
228
|
-
_state3.label = 5;
|
|
229
|
-
case 5:
|
|
230
|
-
_tmp;
|
|
231
|
-
_state3.label = 6;
|
|
232
|
-
case 6:
|
|
233
|
-
return [
|
|
234
|
-
2
|
|
235
|
-
];
|
|
236
|
-
}
|
|
237
|
-
});
|
|
238
|
-
});
|
|
239
|
-
return function modifyRouteIds2(route, pathName) {
|
|
240
|
-
return _ref3.apply(this, arguments);
|
|
241
|
-
};
|
|
242
|
-
}();
|
|
243
|
-
return [
|
|
244
|
-
4,
|
|
245
|
-
Promise.all(routes.map(function() {
|
|
246
|
-
var _ref3 = _async_to_generator(function(route) {
|
|
247
|
-
return _ts_generator(this, function(_state3) {
|
|
248
|
-
switch (_state3.label) {
|
|
249
|
-
case 0:
|
|
250
|
-
return [
|
|
251
|
-
4,
|
|
252
|
-
modifyRouteIds(route, entryName)
|
|
253
|
-
];
|
|
254
|
-
case 1:
|
|
255
|
-
_state3.sent();
|
|
256
|
-
return [
|
|
257
|
-
2
|
|
258
|
-
];
|
|
259
|
-
}
|
|
260
|
-
});
|
|
261
|
-
});
|
|
262
|
-
return function(route) {
|
|
263
|
-
return _ref3.apply(this, arguments);
|
|
264
|
-
};
|
|
265
|
-
}()))
|
|
266
|
-
];
|
|
267
|
-
case 1:
|
|
268
|
-
_state2.sent();
|
|
269
|
-
return [
|
|
270
|
-
2,
|
|
271
|
-
options
|
|
272
|
-
];
|
|
273
|
-
}
|
|
274
|
-
});
|
|
275
|
-
})();
|
|
276
|
-
},
|
|
277
|
-
config: /* @__PURE__ */ _async_to_generator(function() {
|
|
278
|
-
return _ts_generator(this, function(_state2) {
|
|
279
|
-
return [
|
|
280
|
-
2,
|
|
281
|
-
{
|
|
282
|
-
tools: {
|
|
283
|
-
// bundlerChain can not keep target order
|
|
284
|
-
rspack: function rspack(_config, param2) {
|
|
285
|
-
var isServer = param2.isServer;
|
|
286
|
-
patchMFConfig({
|
|
287
|
-
mfConfig: isServer ? internalOptions.ssrConfig : internalOptions.csrConfig,
|
|
288
|
-
metaName,
|
|
289
|
-
isServer,
|
|
290
|
-
internalDirectory,
|
|
291
|
-
entries
|
|
292
|
-
});
|
|
293
|
-
},
|
|
294
|
-
// bundlerChain can not keep target order
|
|
295
|
-
webpack: function webpack(_config, param2) {
|
|
296
|
-
var isServer = param2.isServer;
|
|
297
|
-
patchMFConfig({
|
|
298
|
-
mfConfig: isServer ? internalOptions.ssrConfig : internalOptions.csrConfig,
|
|
299
|
-
metaName,
|
|
300
|
-
isServer,
|
|
301
|
-
internalDirectory,
|
|
302
|
-
entries
|
|
303
|
-
});
|
|
304
|
-
}
|
|
305
|
-
},
|
|
306
|
-
source: {
|
|
307
|
-
define: {
|
|
308
|
-
MODERN_ROUTER_ID_PREFIX: JSON.stringify(transformName2Prefix(name))
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
];
|
|
313
|
-
});
|
|
314
|
-
}),
|
|
315
|
-
afterDev: function afterDev() {
|
|
316
|
-
return _async_to_generator(function() {
|
|
317
|
-
return _ts_generator(this, function(_state2) {
|
|
318
|
-
clearMFCache();
|
|
319
|
-
return [
|
|
320
|
-
2
|
|
321
|
-
];
|
|
322
|
-
});
|
|
323
|
-
})();
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
];
|
|
327
|
-
}
|
|
328
|
-
});
|
|
329
|
-
});
|
|
330
|
-
return function(_) {
|
|
331
|
-
return _ref.apply(this, arguments);
|
|
332
|
-
};
|
|
333
|
-
}()
|
|
334
|
-
};
|
|
335
|
-
};
|
|
336
|
-
var plugin_default = moduleFederationDataLoaderPlugin;
|
|
337
|
-
export {
|
|
338
|
-
plugin_default as default,
|
|
339
|
-
generateRoutes,
|
|
340
|
-
moduleFederationDataLoaderPlugin
|
|
341
|
-
};
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import nodeRuntimePlugin from "@module-federation/node/runtimePlugin";
|
|
2
|
-
var isContainer = typeof __filename === "string" ? __filename.includes("remote") ? true : false : false;
|
|
3
|
-
var pluginName = "node-plugin-".concat(isContainer);
|
|
4
|
-
var nodePlugin = function() {
|
|
5
|
-
return {
|
|
6
|
-
name: pluginName,
|
|
7
|
-
beforeInit: nodeRuntimePlugin().beforeInit
|
|
8
|
-
};
|
|
9
|
-
};
|
|
10
|
-
var node_default = nodePlugin;
|
|
11
|
-
export {
|
|
12
|
-
node_default as default
|
|
13
|
-
};
|
|
@@ -1,104 +0,0 @@
|
|
|
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 { init } from "@module-federation/enhanced/runtime";
|
|
5
|
-
import { isBrowserEnv } from "@module-federation/sdk";
|
|
6
|
-
import { fetchRemoteFullRoutesMap, getSSRByRouteIds } from "./fetchRemoteFullRoutesMap";
|
|
7
|
-
import { injectRemoteRoutes } from "../../runtime/dataLoader/utils";
|
|
8
|
-
import { MF_ROUTES, DEFAULT_ENTRY, MODERN_JS_ROUTE_SERVER_LOADER } from "../../constant";
|
|
9
|
-
function dataLoaderPlugin_default(param) {
|
|
10
|
-
var runtimeOptions = param.runtimeOptions, dataLoaderRemotes = param.dataLoaderRemotes, ssrByRouteIdsMap = param.ssrByRouteIdsMap;
|
|
11
|
-
return {
|
|
12
|
-
name: "MFDataLoaderServerPlugin",
|
|
13
|
-
pre: [
|
|
14
|
-
"@modern-js/plugin-inject-resource"
|
|
15
|
-
],
|
|
16
|
-
setup: function setup(api) {
|
|
17
|
-
var remotes = runtimeOptions.remotes, name = runtimeOptions.name;
|
|
18
|
-
var isHandled = false;
|
|
19
|
-
return {
|
|
20
|
-
prepare: function prepare() {
|
|
21
|
-
var middlewares = api.useAppContext().middlewares;
|
|
22
|
-
middlewares.push({
|
|
23
|
-
name: "MFPatchRouteMiddleWare",
|
|
24
|
-
handler: function() {
|
|
25
|
-
var _ref = _async_to_generator(function(c, next) {
|
|
26
|
-
var serverManifest, loaderBundles, nestedRoutesJson, _api_useConfigContext_server, instance, remoteFullRoutesMap, originalSSRByRouteIds, remoteSSRByRouteIds, ssrByRouteIds;
|
|
27
|
-
return _ts_generator(this, function(_state) {
|
|
28
|
-
switch (_state.label) {
|
|
29
|
-
case 0:
|
|
30
|
-
serverManifest = c.get("serverManifest");
|
|
31
|
-
loaderBundles = serverManifest.loaderBundles, nestedRoutesJson = serverManifest.nestedRoutesJson;
|
|
32
|
-
if (!(isHandled && !globalThis.FORCE_MF_REFRESH))
|
|
33
|
-
return [
|
|
34
|
-
3,
|
|
35
|
-
2
|
|
36
|
-
];
|
|
37
|
-
return [
|
|
38
|
-
4,
|
|
39
|
-
next()
|
|
40
|
-
];
|
|
41
|
-
case 1:
|
|
42
|
-
_state.sent();
|
|
43
|
-
return [
|
|
44
|
-
3,
|
|
45
|
-
5
|
|
46
|
-
];
|
|
47
|
-
case 2:
|
|
48
|
-
instance = init({
|
|
49
|
-
name,
|
|
50
|
-
remotes
|
|
51
|
-
});
|
|
52
|
-
return [
|
|
53
|
-
4,
|
|
54
|
-
fetchRemoteFullRoutesMap({
|
|
55
|
-
instance,
|
|
56
|
-
remotePath: isBrowserEnv() ? "".concat(DEFAULT_ENTRY, "/").concat(MF_ROUTES) : "".concat(DEFAULT_ENTRY, "/").concat(MODERN_JS_ROUTE_SERVER_LOADER),
|
|
57
|
-
dataLoaderRemotes
|
|
58
|
-
})
|
|
59
|
-
];
|
|
60
|
-
case 3:
|
|
61
|
-
remoteFullRoutesMap = _state.sent();
|
|
62
|
-
originalSSRByRouteIds = (_api_useConfigContext_server = api.useConfigContext().server) === null || _api_useConfigContext_server === void 0 ? void 0 : _api_useConfigContext_server.ssrByRouteIds;
|
|
63
|
-
if (originalSSRByRouteIds && dataLoaderRemotes.length) {
|
|
64
|
-
remoteSSRByRouteIds = getSSRByRouteIds(dataLoaderRemotes, remoteFullRoutesMap) || [];
|
|
65
|
-
ssrByRouteIds = new Set(_to_consumable_array(originalSSRByRouteIds).concat(_to_consumable_array(remoteSSRByRouteIds.map(function(id) {
|
|
66
|
-
return ssrByRouteIdsMap[id] || id;
|
|
67
|
-
}))));
|
|
68
|
-
api.useConfigContext().server.ssrByRouteIds = Array.from(ssrByRouteIds);
|
|
69
|
-
}
|
|
70
|
-
injectRemoteRoutes(loaderBundles, remoteFullRoutesMap);
|
|
71
|
-
injectRemoteRoutes(nestedRoutesJson, remoteFullRoutesMap);
|
|
72
|
-
isHandled = true;
|
|
73
|
-
globalThis.FORCE_MF_REFRESH = false;
|
|
74
|
-
return [
|
|
75
|
-
4,
|
|
76
|
-
next()
|
|
77
|
-
];
|
|
78
|
-
case 4:
|
|
79
|
-
_state.sent();
|
|
80
|
-
_state.label = 5;
|
|
81
|
-
case 5:
|
|
82
|
-
return [
|
|
83
|
-
2
|
|
84
|
-
];
|
|
85
|
-
}
|
|
86
|
-
});
|
|
87
|
-
});
|
|
88
|
-
return function(c, next) {
|
|
89
|
-
return _ref.apply(this, arguments);
|
|
90
|
-
};
|
|
91
|
-
}(),
|
|
92
|
-
before: [
|
|
93
|
-
"render"
|
|
94
|
-
]
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
;
|
|
102
|
-
export {
|
|
103
|
-
dataLoaderPlugin_default as default
|
|
104
|
-
};
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
|
2
|
-
import { _ as _sliced_to_array } from "@swc/helpers/_/_sliced_to_array";
|
|
3
|
-
import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
|
|
4
|
-
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
5
|
-
function fetchRemoteFullRoutesMap(options) {
|
|
6
|
-
return _fetchRemoteFullRoutesMap.apply(this, arguments);
|
|
7
|
-
}
|
|
8
|
-
function _fetchRemoteFullRoutesMap() {
|
|
9
|
-
_fetchRemoteFullRoutesMap = _async_to_generator(function(options) {
|
|
10
|
-
var instance, remotePath, dataLoaderRemotes, remotes, remoteRoutesMap;
|
|
11
|
-
return _ts_generator(this, function(_state) {
|
|
12
|
-
switch (_state.label) {
|
|
13
|
-
case 0:
|
|
14
|
-
instance = options.instance, remotePath = options.remotePath, dataLoaderRemotes = options.dataLoaderRemotes;
|
|
15
|
-
remotes = instance.options.remotes;
|
|
16
|
-
remoteRoutesMap = {};
|
|
17
|
-
if (!remotes.length) {
|
|
18
|
-
return [
|
|
19
|
-
2,
|
|
20
|
-
remoteRoutesMap
|
|
21
|
-
];
|
|
22
|
-
}
|
|
23
|
-
return [
|
|
24
|
-
4,
|
|
25
|
-
Promise.all(remotes.map(function() {
|
|
26
|
-
var _ref = _async_to_generator(function(remote) {
|
|
27
|
-
var remoteId, routes;
|
|
28
|
-
return _ts_generator(this, function(_state2) {
|
|
29
|
-
switch (_state2.label) {
|
|
30
|
-
case 0:
|
|
31
|
-
if (!dataLoaderRemotes.includes(remote.name)) {
|
|
32
|
-
return [
|
|
33
|
-
2
|
|
34
|
-
];
|
|
35
|
-
}
|
|
36
|
-
remoteId = "".concat(remote.name, "/").concat(remotePath);
|
|
37
|
-
return [
|
|
38
|
-
4,
|
|
39
|
-
instance.loadRemote(remoteId)
|
|
40
|
-
];
|
|
41
|
-
case 1:
|
|
42
|
-
routes = _state2.sent().routes;
|
|
43
|
-
remoteRoutesMap[remote.name] = {
|
|
44
|
-
routes
|
|
45
|
-
};
|
|
46
|
-
return [
|
|
47
|
-
2
|
|
48
|
-
];
|
|
49
|
-
}
|
|
50
|
-
});
|
|
51
|
-
});
|
|
52
|
-
return function(remote) {
|
|
53
|
-
return _ref.apply(this, arguments);
|
|
54
|
-
};
|
|
55
|
-
}()))
|
|
56
|
-
];
|
|
57
|
-
case 1:
|
|
58
|
-
_state.sent();
|
|
59
|
-
return [
|
|
60
|
-
2,
|
|
61
|
-
remoteRoutesMap
|
|
62
|
-
];
|
|
63
|
-
}
|
|
64
|
-
});
|
|
65
|
-
});
|
|
66
|
-
return _fetchRemoteFullRoutesMap.apply(this, arguments);
|
|
67
|
-
}
|
|
68
|
-
function getSSRByRouteIds(dataLoaderRemotes, remoteRoutesMap) {
|
|
69
|
-
var remoteProviderRouteIds = /* @__PURE__ */ new Set();
|
|
70
|
-
var collectIds = function(route) {
|
|
71
|
-
remoteProviderRouteIds.add(route.id);
|
|
72
|
-
if (route.children) {
|
|
73
|
-
route.children.forEach(function(r) {
|
|
74
|
-
collectIds(r);
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
};
|
|
78
|
-
Object.entries(remoteRoutesMap).forEach(function(item) {
|
|
79
|
-
var _item = _sliced_to_array(item, 2), remoteName = _item[0], routesObj = _item[1];
|
|
80
|
-
if (!dataLoaderRemotes.includes(remoteName)) {
|
|
81
|
-
return;
|
|
82
|
-
}
|
|
83
|
-
var routes = routesObj.routes;
|
|
84
|
-
routes.forEach(function(route) {
|
|
85
|
-
collectIds(route);
|
|
86
|
-
});
|
|
87
|
-
});
|
|
88
|
-
return _to_consumable_array(remoteProviderRouteIds);
|
|
89
|
-
}
|
|
90
|
-
export {
|
|
91
|
-
fetchRemoteFullRoutesMap,
|
|
92
|
-
getSSRByRouteIds
|
|
93
|
-
};
|
|
File without changes
|