@module-federation/modern-js 0.0.0-next-20241016083243 → 0.0.0-next-20241017090853
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/index.js +5 -4
- package/dist/cjs/cli/routes/exportRoutePlugin.js +77 -0
- package/dist/cjs/cli/routes/importRoutesPlugin.js +120 -0
- package/dist/cjs/cli/routes/plugin.js +155 -0
- package/dist/cjs/cli/{dataLoader/generateRouteFile.js → routes/traverseRouteFiles.js} +12 -12
- package/dist/cjs/cli/{dataLoader/patchMFConfig.js → routes/utils.js} +18 -10
- package/dist/cjs/cli/server/{dataLoaderPlugin.js → fetchRoutePlugin.js} +7 -7
- package/dist/cjs/runtime/{dataLoader → routes}/plugin-inject-assets.js +3 -3
- package/dist/cjs/runtime/{dataLoader → routes}/plugin.js +1 -1
- package/dist/cjs/types/routes.js +16 -0
- package/dist/esm/cli/index.js +6 -4
- package/dist/esm/cli/routes/exportRoutePlugin.js +79 -0
- package/dist/esm/cli/routes/importRoutesPlugin.js +122 -0
- package/dist/esm/cli/{dataLoader → routes}/plugin.js +72 -149
- package/dist/esm/cli/{dataLoader/generateRouteFile.js → routes/traverseRouteFiles.js} +23 -18
- package/dist/esm/cli/{dataLoader/patchMFConfig.js → routes/utils.js} +12 -6
- package/dist/esm/cli/server/{dataLoaderPlugin.js → fetchRoutePlugin.js} +4 -4
- package/dist/esm/runtime/{dataLoader → routes}/plugin-inject-assets.js +3 -3
- package/dist/esm/runtime/{dataLoader → routes}/plugin.js +1 -1
- package/dist/esm/types/routes.js +0 -0
- package/dist/esm-node/cli/index.js +5 -4
- package/dist/esm-node/cli/routes/exportRoutePlugin.js +53 -0
- package/dist/esm-node/cli/routes/importRoutesPlugin.js +96 -0
- package/dist/esm-node/cli/routes/plugin.js +121 -0
- package/dist/esm-node/cli/{dataLoader/generateRouteFile.js → routes/traverseRouteFiles.js} +8 -8
- package/dist/esm-node/cli/{dataLoader/patchMFConfig.js → routes/utils.js} +13 -6
- package/dist/esm-node/cli/server/{dataLoaderPlugin.js → fetchRoutePlugin.js} +4 -4
- package/dist/esm-node/runtime/{dataLoader → routes}/plugin-inject-assets.js +3 -3
- package/dist/esm-node/runtime/{dataLoader → routes}/plugin.js +1 -1
- package/dist/esm-node/types/routes.js +0 -0
- package/dist/types/cli/routes/exportRoutePlugin.d.ts +4 -0
- package/dist/types/cli/routes/importRoutesPlugin.d.ts +4 -0
- package/dist/types/cli/routes/plugin.d.ts +4 -0
- package/dist/types/cli/{dataLoader/generateRouteFile.d.ts → routes/traverseRouteFiles.d.ts} +4 -3
- package/dist/types/cli/{dataLoader/patchMFConfig.d.ts → routes/utils.d.ts} +2 -1
- package/dist/types/cli/server/{dataLoaderPlugin.d.ts → fetchRoutePlugin.d.ts} +2 -2
- package/dist/types/types/index.d.ts +2 -8
- package/dist/types/types/routes.d.ts +19 -0
- package/package.json +32 -32
- package/dist/cjs/cli/dataLoader/plugin.js +0 -219
- package/dist/esm-node/cli/dataLoader/plugin.js +0 -184
- package/dist/types/cli/dataLoader/plugin.d.ts +0 -6
- /package/dist/cjs/cli/{dataLoader → routes}/ast/constant.js +0 -0
- /package/dist/cjs/cli/{dataLoader → routes}/ast/generateRoutes.js +0 -0
- /package/dist/cjs/cli/{dataLoader → routes}/ast/index.js +0 -0
- /package/dist/cjs/cli/{dataLoader → routes}/clearMFCache.js +0 -0
- /package/dist/cjs/runtime/{dataLoader → routes}/utils.js +0 -0
- /package/dist/esm/cli/{dataLoader → routes}/ast/constant.js +0 -0
- /package/dist/esm/cli/{dataLoader → routes}/ast/generateRoutes.js +0 -0
- /package/dist/esm/cli/{dataLoader → routes}/ast/index.js +0 -0
- /package/dist/esm/cli/{dataLoader → routes}/clearMFCache.js +0 -0
- /package/dist/esm/runtime/{dataLoader → routes}/utils.js +0 -0
- /package/dist/esm-node/cli/{dataLoader → routes}/ast/constant.js +0 -0
- /package/dist/esm-node/cli/{dataLoader → routes}/ast/generateRoutes.js +0 -0
- /package/dist/esm-node/cli/{dataLoader → routes}/ast/index.js +0 -0
- /package/dist/esm-node/cli/{dataLoader → routes}/clearMFCache.js +0 -0
- /package/dist/esm-node/runtime/{dataLoader → routes}/utils.js +0 -0
- /package/dist/types/cli/{dataLoader → routes}/ast/constant.d.ts +0 -0
- /package/dist/types/cli/{dataLoader → routes}/ast/generateRoutes.d.ts +0 -0
- /package/dist/types/cli/{dataLoader → routes}/ast/index.d.ts +0 -0
- /package/dist/types/cli/{dataLoader → routes}/clearMFCache.d.ts +0 -0
- /package/dist/types/runtime/{dataLoader → routes}/plugin-inject-assets.d.ts +0 -0
- /package/dist/types/runtime/{dataLoader → routes}/plugin.d.ts +0 -0
- /package/dist/types/runtime/{dataLoader → routes}/utils.d.ts +0 -0
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
|
2
|
+
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
3
|
+
import { META_NAME } from "../../constant";
|
|
4
|
+
import { addExpose } from "./utils";
|
|
5
|
+
var moduleFederationExportRoutePlugin = function(param) {
|
|
6
|
+
var userConfig = param.userConfig, internalOptions = param.internalOptions, entries = param.entries;
|
|
7
|
+
return {
|
|
8
|
+
name: "@modern-js/plugin-module-federation-export-routes",
|
|
9
|
+
pre: [
|
|
10
|
+
"@modern-js/plugin-module-federation-route"
|
|
11
|
+
],
|
|
12
|
+
post: [
|
|
13
|
+
"@modern-js/plugin-router",
|
|
14
|
+
"@modern-js/plugin-module-federation"
|
|
15
|
+
],
|
|
16
|
+
setup: function() {
|
|
17
|
+
var _ref = _async_to_generator(function(param2) {
|
|
18
|
+
var useAppContext, appContext, _internalOptions_metaName, metaName, internalDirectory;
|
|
19
|
+
return _ts_generator(this, function(_state) {
|
|
20
|
+
useAppContext = param2.useAppContext;
|
|
21
|
+
if (!userConfig.exportRoutes) {
|
|
22
|
+
return [
|
|
23
|
+
2
|
|
24
|
+
];
|
|
25
|
+
}
|
|
26
|
+
appContext = useAppContext();
|
|
27
|
+
_internalOptions_metaName = internalOptions.metaName, metaName = _internalOptions_metaName === void 0 ? META_NAME : _internalOptions_metaName;
|
|
28
|
+
internalDirectory = appContext.internalDirectory.replace(META_NAME, metaName || META_NAME);
|
|
29
|
+
return [
|
|
30
|
+
2,
|
|
31
|
+
{
|
|
32
|
+
config: /* @__PURE__ */ _async_to_generator(function() {
|
|
33
|
+
return _ts_generator(this, function(_state2) {
|
|
34
|
+
return [
|
|
35
|
+
2,
|
|
36
|
+
{
|
|
37
|
+
tools: {
|
|
38
|
+
// bundlerChain can not keep target order
|
|
39
|
+
rspack: function rspack(_config, param3) {
|
|
40
|
+
var isServer = param3.isServer;
|
|
41
|
+
addExpose({
|
|
42
|
+
mfConfig: isServer ? internalOptions.ssrConfig : internalOptions.csrConfig,
|
|
43
|
+
metaName,
|
|
44
|
+
isServer,
|
|
45
|
+
internalDirectory,
|
|
46
|
+
entries
|
|
47
|
+
});
|
|
48
|
+
},
|
|
49
|
+
// bundlerChain can not keep target order
|
|
50
|
+
webpack: function webpack(_config, param3) {
|
|
51
|
+
var isServer = param3.isServer;
|
|
52
|
+
addExpose({
|
|
53
|
+
mfConfig: isServer ? internalOptions.ssrConfig : internalOptions.csrConfig,
|
|
54
|
+
metaName,
|
|
55
|
+
isServer,
|
|
56
|
+
internalDirectory,
|
|
57
|
+
entries
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
];
|
|
63
|
+
});
|
|
64
|
+
})
|
|
65
|
+
}
|
|
66
|
+
];
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
return function(_) {
|
|
70
|
+
return _ref.apply(this, arguments);
|
|
71
|
+
};
|
|
72
|
+
}()
|
|
73
|
+
};
|
|
74
|
+
};
|
|
75
|
+
var exportRoutePlugin_default = moduleFederationExportRoutePlugin;
|
|
76
|
+
export {
|
|
77
|
+
exportRoutePlugin_default as default,
|
|
78
|
+
moduleFederationExportRoutePlugin
|
|
79
|
+
};
|
|
@@ -0,0 +1,122 @@
|
|
|
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
|
+
import { META_NAME } from "../../constant";
|
|
6
|
+
import { clearMFCache } from "./clearMFCache";
|
|
7
|
+
function _transformRuntimeOptions(buildOptions) {
|
|
8
|
+
var remotes = buildOptions.remotes || {};
|
|
9
|
+
var runtimeRemotes = Object.entries(remotes).map(function(remote) {
|
|
10
|
+
var _remote = _sliced_to_array(remote, 2), alias = _remote[0], nameAndEntry = _remote[1];
|
|
11
|
+
var _nameAndEntry_split = _sliced_to_array(nameAndEntry.split("@"), 2), name = _nameAndEntry_split[0], entry = _nameAndEntry_split[1];
|
|
12
|
+
return {
|
|
13
|
+
name,
|
|
14
|
+
entry,
|
|
15
|
+
alias
|
|
16
|
+
};
|
|
17
|
+
});
|
|
18
|
+
return {
|
|
19
|
+
name: buildOptions.name,
|
|
20
|
+
remotes: runtimeRemotes
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
var moduleFederationImportRoutePlugin = function(param) {
|
|
24
|
+
var userConfig = param.userConfig, internalOptions = param.internalOptions, remotePathMap = param.remotePathMap, _param_serverPlugin = param.serverPlugin, serverPlugin = _param_serverPlugin === void 0 ? "@module-federation/modern-js/fetch-router-server-plugin" : _param_serverPlugin, ssrByRouteIdsMap = param.ssrByRouteIdsMap, transformRuntimeOptions = param.transformRuntimeOptions;
|
|
25
|
+
return {
|
|
26
|
+
name: "@modern-js/plugin-module-federation-import-routes",
|
|
27
|
+
pre: [
|
|
28
|
+
"@modern-js/plugin-module-federation-route"
|
|
29
|
+
],
|
|
30
|
+
post: [
|
|
31
|
+
"@modern-js/plugin-router",
|
|
32
|
+
"@modern-js/plugin-module-federation"
|
|
33
|
+
],
|
|
34
|
+
setup: /* @__PURE__ */ _async_to_generator(function() {
|
|
35
|
+
var _internalOptions_metaName, metaName, transformRuntimeFn, dataLoaderRemotes, serverPluginOptions, hasDataLoaderRemotes;
|
|
36
|
+
return _ts_generator(this, function(_state) {
|
|
37
|
+
if (!userConfig.importRoutes) {
|
|
38
|
+
return [
|
|
39
|
+
2
|
|
40
|
+
];
|
|
41
|
+
}
|
|
42
|
+
_internalOptions_metaName = internalOptions.metaName, metaName = _internalOptions_metaName === void 0 ? META_NAME : _internalOptions_metaName;
|
|
43
|
+
transformRuntimeFn = transformRuntimeOptions || _transformRuntimeOptions;
|
|
44
|
+
dataLoaderRemotes = _to_consumable_array(new Set(Object.values(remotePathMap).map(function(i) {
|
|
45
|
+
return i.name;
|
|
46
|
+
})));
|
|
47
|
+
serverPluginOptions = {
|
|
48
|
+
runtimeOptions: transformRuntimeFn(internalOptions.csrConfig),
|
|
49
|
+
dataLoaderRemotes,
|
|
50
|
+
ssrByRouteIdsMap
|
|
51
|
+
};
|
|
52
|
+
hasDataLoaderRemotes = function() {
|
|
53
|
+
return Boolean(serverPluginOptions.dataLoaderRemotes.length);
|
|
54
|
+
};
|
|
55
|
+
return [
|
|
56
|
+
2,
|
|
57
|
+
{
|
|
58
|
+
_internalRuntimePlugins: function(param2) {
|
|
59
|
+
var entrypoint = param2.entrypoint, plugins = param2.plugins;
|
|
60
|
+
if (!hasDataLoaderRemotes()) {
|
|
61
|
+
return {
|
|
62
|
+
entrypoint,
|
|
63
|
+
plugins
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
plugins.push({
|
|
67
|
+
name: "ssrDataLoader",
|
|
68
|
+
path: "@module-federation/modern-js/routes",
|
|
69
|
+
config: {
|
|
70
|
+
metaName,
|
|
71
|
+
dataLoaderRemotes
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
plugins.push({
|
|
75
|
+
name: "ssrDataLoaderInjectAssets",
|
|
76
|
+
path: "@module-federation/modern-js/routes-inject-assets",
|
|
77
|
+
config: {
|
|
78
|
+
metaName,
|
|
79
|
+
dataLoaderRemotes
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
return {
|
|
83
|
+
entrypoint,
|
|
84
|
+
plugins
|
|
85
|
+
};
|
|
86
|
+
},
|
|
87
|
+
_internalServerPlugins: function _internalServerPlugins(param2) {
|
|
88
|
+
var plugins = param2.plugins;
|
|
89
|
+
if (!hasDataLoaderRemotes()) {
|
|
90
|
+
return {
|
|
91
|
+
plugins
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
plugins.push({
|
|
95
|
+
name: serverPlugin,
|
|
96
|
+
options: serverPluginOptions
|
|
97
|
+
});
|
|
98
|
+
return {
|
|
99
|
+
plugins
|
|
100
|
+
};
|
|
101
|
+
},
|
|
102
|
+
afterDev: function afterDev() {
|
|
103
|
+
return _async_to_generator(function() {
|
|
104
|
+
return _ts_generator(this, function(_state2) {
|
|
105
|
+
clearMFCache();
|
|
106
|
+
return [
|
|
107
|
+
2
|
|
108
|
+
];
|
|
109
|
+
});
|
|
110
|
+
})();
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
];
|
|
114
|
+
});
|
|
115
|
+
})
|
|
116
|
+
};
|
|
117
|
+
};
|
|
118
|
+
var importRoutesPlugin_default = moduleFederationImportRoutePlugin;
|
|
119
|
+
export {
|
|
120
|
+
importRoutesPlugin_default as default,
|
|
121
|
+
moduleFederationImportRoutePlugin
|
|
122
|
+
};
|
|
@@ -1,64 +1,48 @@
|
|
|
1
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
2
|
import { _ as _type_of } from "@swc/helpers/_/_type_of";
|
|
5
3
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
4
|
+
import path from "path";
|
|
6
5
|
import { fs } from "@modern-js/utils";
|
|
7
|
-
import { transformName2Prefix } from "../../runtime/
|
|
8
|
-
import { DEFAULT_ENTRY, ROUTE_ID } from "../../constant";
|
|
6
|
+
import { transformName2Prefix } from "../../runtime/routes/utils";
|
|
9
7
|
import { META_NAME } from "../../constant";
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import
|
|
15
|
-
function
|
|
16
|
-
var
|
|
17
|
-
var
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
return {
|
|
27
|
-
name: buildOptions.name,
|
|
28
|
-
remotes: runtimeRemotes
|
|
8
|
+
import { traverseRouteFiles } from "./traverseRouteFiles";
|
|
9
|
+
import { moduleFederationExportRoutePlugin } from "./exportRoutePlugin";
|
|
10
|
+
import { moduleFederationImportRoutePlugin } from "./importRoutesPlugin";
|
|
11
|
+
import { addShared } from "./utils";
|
|
12
|
+
import { DEFAULT_ENTRY, ROUTE_ID } from "../../constant";
|
|
13
|
+
var moduleFederationRoutesPlugin = function(param) {
|
|
14
|
+
var userConfig = param.userConfig, internalOptions = param.internalOptions;
|
|
15
|
+
var entries = /* @__PURE__ */ new Set();
|
|
16
|
+
var remotePathMap = {};
|
|
17
|
+
var ssrByRouteIdsMap = {};
|
|
18
|
+
var internalRoutesPluginOptions = {
|
|
19
|
+
userConfig,
|
|
20
|
+
internalOptions,
|
|
21
|
+
entries,
|
|
22
|
+
remotePathMap,
|
|
23
|
+
ssrByRouteIdsMap
|
|
29
24
|
};
|
|
30
|
-
}
|
|
31
|
-
var moduleFederationDataLoaderPlugin = function(enable, internalOptions, userConfig) {
|
|
32
25
|
return {
|
|
33
|
-
name: "@modern-js/plugin-module-federation-
|
|
26
|
+
name: "@modern-js/plugin-module-federation-route",
|
|
34
27
|
pre: [
|
|
35
28
|
"@modern-js/plugin-module-federation-config"
|
|
36
29
|
],
|
|
37
|
-
post: [
|
|
38
|
-
"@modern-js/plugin-router",
|
|
39
|
-
"@modern-js/plugin-module-federation"
|
|
40
|
-
],
|
|
41
30
|
setup: function() {
|
|
42
|
-
var _ref = _async_to_generator(function(
|
|
43
|
-
var useAppContext,
|
|
31
|
+
var _ref = _async_to_generator(function(param2) {
|
|
32
|
+
var useAppContext, appContext, name, _internalOptions_metaName, metaName, internalDirectory, csrConfig, _ref2, scanEntries;
|
|
44
33
|
return _ts_generator(this, function(_state) {
|
|
45
34
|
switch (_state.label) {
|
|
46
35
|
case 0:
|
|
47
|
-
useAppContext =
|
|
48
|
-
if (!
|
|
36
|
+
useAppContext = param2.useAppContext;
|
|
37
|
+
if (!userConfig.exportRoutes && !userConfig.importRoutes) {
|
|
49
38
|
return [
|
|
50
39
|
2
|
|
51
40
|
];
|
|
52
41
|
}
|
|
53
|
-
_userConfig_serverPlugin = userConfig.serverPlugin, serverPlugin = _userConfig_serverPlugin === void 0 ? "@module-federation/modern-js/data-loader-server" : _userConfig_serverPlugin, transformRuntimeOptions = userConfig.transformRuntimeOptions;
|
|
54
42
|
appContext = useAppContext();
|
|
55
43
|
name = internalOptions.csrConfig.name;
|
|
56
44
|
_internalOptions_metaName = internalOptions.metaName, metaName = _internalOptions_metaName === void 0 ? META_NAME : _internalOptions_metaName;
|
|
57
45
|
internalDirectory = appContext.internalDirectory.replace(META_NAME, metaName || META_NAME);
|
|
58
|
-
transformRuntimeFn = transformRuntimeOptions || _transformRuntimeOptions;
|
|
59
|
-
entries = /* @__PURE__ */ new Set();
|
|
60
|
-
remotePathMap = {};
|
|
61
|
-
ssrByRouteIdsMap = {};
|
|
62
46
|
csrConfig = internalOptions.csrConfig;
|
|
63
47
|
if (!(_type_of(csrConfig.remotes) === "object" && Object.keys(csrConfig.remotes).length))
|
|
64
48
|
return [
|
|
@@ -67,16 +51,17 @@ var moduleFederationDataLoaderPlugin = function(enable, internalOptions, userCon
|
|
|
67
51
|
];
|
|
68
52
|
return [
|
|
69
53
|
4,
|
|
70
|
-
|
|
71
|
-
appDirectory: appContext.appDirectory
|
|
54
|
+
traverseRouteFiles({
|
|
55
|
+
appDirectory: appContext.appDirectory,
|
|
56
|
+
generateRouteFile: userConfig.importRoutes,
|
|
57
|
+
remotePathMap
|
|
72
58
|
})
|
|
73
59
|
];
|
|
74
60
|
case 1:
|
|
75
|
-
_ref2 = _state.sent(), scanEntries = _ref2.entries
|
|
61
|
+
_ref2 = _state.sent(), scanEntries = _ref2.entries;
|
|
76
62
|
scanEntries.forEach(function(e) {
|
|
77
63
|
return entries.add(e);
|
|
78
64
|
});
|
|
79
|
-
remotePathMap = scanRemotePathMap;
|
|
80
65
|
return [
|
|
81
66
|
3,
|
|
82
67
|
3
|
|
@@ -85,64 +70,47 @@ var moduleFederationDataLoaderPlugin = function(enable, internalOptions, userCon
|
|
|
85
70
|
entries.add(DEFAULT_ENTRY);
|
|
86
71
|
_state.label = 3;
|
|
87
72
|
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
73
|
return [
|
|
100
74
|
2,
|
|
101
75
|
{
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
plugins.push({
|
|
139
|
-
name: serverPlugin,
|
|
140
|
-
options: serverPluginOptions
|
|
76
|
+
config: /* @__PURE__ */ _async_to_generator(function() {
|
|
77
|
+
return _ts_generator(this, function(_state2) {
|
|
78
|
+
return [
|
|
79
|
+
2,
|
|
80
|
+
{
|
|
81
|
+
tools: {
|
|
82
|
+
// bundlerChain can not keep target order
|
|
83
|
+
rspack: function rspack(_config, param3) {
|
|
84
|
+
var isServer = param3.isServer;
|
|
85
|
+
addShared({
|
|
86
|
+
mfConfig: isServer ? internalOptions.ssrConfig : internalOptions.csrConfig,
|
|
87
|
+
metaName,
|
|
88
|
+
isServer,
|
|
89
|
+
internalDirectory,
|
|
90
|
+
entries
|
|
91
|
+
});
|
|
92
|
+
},
|
|
93
|
+
// bundlerChain can not keep target order
|
|
94
|
+
webpack: function webpack(_config, param3) {
|
|
95
|
+
var isServer = param3.isServer;
|
|
96
|
+
addShared({
|
|
97
|
+
mfConfig: isServer ? internalOptions.ssrConfig : internalOptions.csrConfig,
|
|
98
|
+
metaName,
|
|
99
|
+
isServer,
|
|
100
|
+
internalDirectory,
|
|
101
|
+
entries
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
},
|
|
105
|
+
source: {
|
|
106
|
+
define: {
|
|
107
|
+
MODERN_ROUTER_ID_PREFIX: JSON.stringify(transformName2Prefix(name))
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
];
|
|
141
112
|
});
|
|
142
|
-
|
|
143
|
-
plugins
|
|
144
|
-
};
|
|
145
|
-
},
|
|
113
|
+
}),
|
|
146
114
|
modifyFileSystemRoutes: function modifyFileSystemRoutes(options) {
|
|
147
115
|
return _async_to_generator(function() {
|
|
148
116
|
var routes, entrypoint, entryName, prefix, modifyRouteIds;
|
|
@@ -273,54 +241,6 @@ var moduleFederationDataLoaderPlugin = function(enable, internalOptions, userCon
|
|
|
273
241
|
}
|
|
274
242
|
});
|
|
275
243
|
})();
|
|
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
244
|
}
|
|
325
245
|
}
|
|
326
246
|
];
|
|
@@ -330,12 +250,15 @@ var moduleFederationDataLoaderPlugin = function(enable, internalOptions, userCon
|
|
|
330
250
|
return function(_) {
|
|
331
251
|
return _ref.apply(this, arguments);
|
|
332
252
|
};
|
|
333
|
-
}()
|
|
253
|
+
}(),
|
|
254
|
+
usePlugins: [
|
|
255
|
+
moduleFederationExportRoutePlugin(internalRoutesPluginOptions),
|
|
256
|
+
moduleFederationImportRoutePlugin(internalRoutesPluginOptions)
|
|
257
|
+
]
|
|
334
258
|
};
|
|
335
259
|
};
|
|
336
|
-
var plugin_default =
|
|
260
|
+
var plugin_default = moduleFederationRoutesPlugin;
|
|
337
261
|
export {
|
|
338
262
|
plugin_default as default,
|
|
339
|
-
|
|
340
|
-
moduleFederationDataLoaderPlugin
|
|
263
|
+
moduleFederationRoutesPlugin
|
|
341
264
|
};
|
|
@@ -5,7 +5,7 @@ import { fs, normalizeToPosixPath } from "@modern-js/utils";
|
|
|
5
5
|
import path from "path";
|
|
6
6
|
import os from "os";
|
|
7
7
|
import { DEFAULT_ENTRY, MF_JSON, ROUTE_ID } from "../../constant";
|
|
8
|
-
import { getRemoteLayoutId } from "../../runtime/
|
|
8
|
+
import { getRemoteLayoutId } from "../../runtime/routes/utils";
|
|
9
9
|
var ROUTES = "routes";
|
|
10
10
|
function calcPathName(filePath, rootDir, entry) {
|
|
11
11
|
var relativePath = path.relative(rootDir, filePath);
|
|
@@ -37,18 +37,17 @@ function calcPathName(filePath, rootDir, entry) {
|
|
|
37
37
|
return !!p;
|
|
38
38
|
}).join("/"));
|
|
39
39
|
}
|
|
40
|
-
function
|
|
41
|
-
return
|
|
40
|
+
function traverseRouteFiles(options) {
|
|
41
|
+
return _traverseRouteFiles.apply(this, arguments);
|
|
42
42
|
}
|
|
43
|
-
function
|
|
44
|
-
|
|
45
|
-
var appDirectory,
|
|
43
|
+
function _traverseRouteFiles() {
|
|
44
|
+
_traverseRouteFiles = _async_to_generator(function(options) {
|
|
45
|
+
var appDirectory, generateRouteFile, remotePathMap, entries, srcPath, traverse, traverseRoutes, normalizedEntries;
|
|
46
46
|
return _ts_generator(this, function(_state) {
|
|
47
47
|
switch (_state.label) {
|
|
48
48
|
case 0:
|
|
49
|
-
appDirectory = options.appDirectory;
|
|
49
|
+
appDirectory = options.appDirectory, generateRouteFile = options.generateRouteFile, remotePathMap = options.remotePathMap;
|
|
50
50
|
entries = [];
|
|
51
|
-
remotePathMap = {};
|
|
52
51
|
srcPath = "".concat(appDirectory, "/src");
|
|
53
52
|
traverse = function() {
|
|
54
53
|
var _ref = _async_to_generator(function(filepath, rootDir, entry) {
|
|
@@ -224,22 +223,29 @@ function _generateRouteFile() {
|
|
|
224
223
|
}))
|
|
225
224
|
return [
|
|
226
225
|
3,
|
|
227
|
-
|
|
226
|
+
5
|
|
228
227
|
];
|
|
229
228
|
entry = path.relative(srcPath, dir);
|
|
230
229
|
entries.push(entry);
|
|
231
230
|
rootDir = "".concat(dir, "/").concat(ROUTES);
|
|
231
|
+
if (!generateRouteFile)
|
|
232
|
+
return [
|
|
233
|
+
3,
|
|
234
|
+
4
|
|
235
|
+
];
|
|
232
236
|
return [
|
|
233
237
|
4,
|
|
234
238
|
traverse(rootDir, rootDir, entry)
|
|
235
239
|
];
|
|
236
240
|
case 3:
|
|
237
241
|
_state2.sent();
|
|
242
|
+
_state2.label = 4;
|
|
243
|
+
case 4:
|
|
238
244
|
return [
|
|
239
245
|
3,
|
|
240
|
-
|
|
246
|
+
7
|
|
241
247
|
];
|
|
242
|
-
case
|
|
248
|
+
case 5:
|
|
243
249
|
return [
|
|
244
250
|
4,
|
|
245
251
|
Promise.all(items.map(function() {
|
|
@@ -264,10 +270,10 @@ function _generateRouteFile() {
|
|
|
264
270
|
};
|
|
265
271
|
}()))
|
|
266
272
|
];
|
|
267
|
-
case 5:
|
|
268
|
-
_state2.sent();
|
|
269
|
-
_state2.label = 6;
|
|
270
273
|
case 6:
|
|
274
|
+
_state2.sent();
|
|
275
|
+
_state2.label = 7;
|
|
276
|
+
case 7:
|
|
271
277
|
return [
|
|
272
278
|
2
|
|
273
279
|
];
|
|
@@ -293,16 +299,15 @@ function _generateRouteFile() {
|
|
|
293
299
|
return [
|
|
294
300
|
2,
|
|
295
301
|
{
|
|
296
|
-
entries: normalizedEntries
|
|
297
|
-
remotePathMap
|
|
302
|
+
entries: normalizedEntries
|
|
298
303
|
}
|
|
299
304
|
];
|
|
300
305
|
}
|
|
301
306
|
});
|
|
302
307
|
});
|
|
303
|
-
return
|
|
308
|
+
return _traverseRouteFiles.apply(this, arguments);
|
|
304
309
|
}
|
|
305
310
|
export {
|
|
306
311
|
calcPathName,
|
|
307
|
-
|
|
312
|
+
traverseRouteFiles
|
|
308
313
|
};
|
|
@@ -79,7 +79,8 @@ function addExpose(options) {
|
|
|
79
79
|
});
|
|
80
80
|
}
|
|
81
81
|
function addShared(options) {
|
|
82
|
-
var
|
|
82
|
+
var mfConfig = options.mfConfig;
|
|
83
|
+
var styledComponents = "styled-components";
|
|
83
84
|
var reactRouterDom = "react-router-dom";
|
|
84
85
|
var reactRouterDomServer = "react-router-dom/server";
|
|
85
86
|
if (!mfConfig.shared) {
|
|
@@ -88,6 +89,8 @@ function addShared(options) {
|
|
|
88
89
|
singleton: true
|
|
89
90
|
}), _define_property(_obj, reactRouterDomServer, {
|
|
90
91
|
singleton: true
|
|
92
|
+
}), _define_property(_obj, styledComponents, {
|
|
93
|
+
singleton: true
|
|
91
94
|
}), _obj);
|
|
92
95
|
} else {
|
|
93
96
|
if (!Array.isArray(mfConfig.shared)) {
|
|
@@ -97,6 +100,9 @@ function addShared(options) {
|
|
|
97
100
|
mfConfig.shared[reactRouterDomServer] = {
|
|
98
101
|
singleton: true
|
|
99
102
|
};
|
|
103
|
+
mfConfig.shared[styledComponents] = {
|
|
104
|
+
singleton: true
|
|
105
|
+
};
|
|
100
106
|
} else {
|
|
101
107
|
mfConfig.shared = mfConfig.shared.reduce(function(sum, cur) {
|
|
102
108
|
if (typeof cur === "string") {
|
|
@@ -112,13 +118,13 @@ function addShared(options) {
|
|
|
112
118
|
mfConfig.shared[reactRouterDomServer] = {
|
|
113
119
|
singleton: true
|
|
114
120
|
};
|
|
121
|
+
mfConfig.shared[styledComponents] = {
|
|
122
|
+
singleton: true
|
|
123
|
+
};
|
|
115
124
|
}
|
|
116
125
|
}
|
|
117
126
|
}
|
|
118
|
-
function patchMFConfig(options) {
|
|
119
|
-
addShared(options);
|
|
120
|
-
addExpose(options);
|
|
121
|
-
}
|
|
122
127
|
export {
|
|
123
|
-
|
|
128
|
+
addExpose,
|
|
129
|
+
addShared
|
|
124
130
|
};
|
|
@@ -4,12 +4,12 @@ import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
|
4
4
|
import { init } from "@module-federation/enhanced/runtime";
|
|
5
5
|
import { isBrowserEnv } from "@module-federation/sdk";
|
|
6
6
|
import { fetchRemoteFullRoutesMap, getSSRByRouteIds } from "./fetchRemoteFullRoutesMap";
|
|
7
|
-
import { injectRemoteRoutes } from "../../runtime/
|
|
7
|
+
import { injectRemoteRoutes } from "../../runtime/routes/utils";
|
|
8
8
|
import { MF_ROUTES, DEFAULT_ENTRY, MODERN_JS_ROUTE_SERVER_LOADER } from "../../constant";
|
|
9
|
-
function
|
|
9
|
+
function fetchRoutePlugin_default(param) {
|
|
10
10
|
var runtimeOptions = param.runtimeOptions, dataLoaderRemotes = param.dataLoaderRemotes, ssrByRouteIdsMap = param.ssrByRouteIdsMap;
|
|
11
11
|
return {
|
|
12
|
-
name: "
|
|
12
|
+
name: "@module-federation/modern-js-fetch-route",
|
|
13
13
|
pre: [
|
|
14
14
|
"@modern-js/plugin-inject-resource"
|
|
15
15
|
],
|
|
@@ -100,5 +100,5 @@ function dataLoaderPlugin_default(param) {
|
|
|
100
100
|
}
|
|
101
101
|
;
|
|
102
102
|
export {
|
|
103
|
-
|
|
103
|
+
fetchRoutePlugin_default as default
|
|
104
104
|
};
|