@module-federation/modern-js 0.0.0-next-20250616092616 → 0.0.0-next-20250616190501
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/package.json +16 -9
- package/dist/LICENSE +0 -21
- package/dist/cjs/cli/configPlugin.js +0 -381
- package/dist/cjs/cli/configPlugin.spec.js +0 -114
- package/dist/cjs/cli/index.js +0 -95
- package/dist/cjs/cli/mfRuntimePlugins/inject-node-fetch.js +0 -44
- package/dist/cjs/cli/mfRuntimePlugins/resolve-entry-ipv4.js +0 -82
- package/dist/cjs/cli/mfRuntimePlugins/shared-strategy.js +0 -43
- package/dist/cjs/cli/server/data-fetch-server-plugin.js +0 -188
- package/dist/cjs/cli/ssrPlugin.js +0 -236
- package/dist/cjs/cli/utils.js +0 -90
- package/dist/cjs/constant.js +0 -31
- package/dist/cjs/interfaces/bundler.js +0 -16
- package/dist/cjs/logger.js +0 -27
- package/dist/cjs/runtime/index.js +0 -33
- package/dist/cjs/server/fileCache.js +0 -84
- package/dist/cjs/server/fileCache.spec.js +0 -28
- package/dist/cjs/server/index.js +0 -58
- package/dist/cjs/server/staticMiddleware.js +0 -77
- package/dist/cjs/server/staticMiddleware.spec.js +0 -185
- package/dist/cjs/ssr-runtime/SSRLiveReload.js +0 -43
- package/dist/cjs/ssr-runtime/devPlugin.js +0 -71
- package/dist/cjs/ssr-runtime/injectDataFetchFunctionPlugin.js +0 -41
- package/dist/cjs/types/index.js +0 -16
- package/dist/esm/cli/configPlugin.js +0 -388
- package/dist/esm/cli/configPlugin.spec.js +0 -110
- package/dist/esm/cli/index.js +0 -90
- package/dist/esm/cli/mfRuntimePlugins/inject-node-fetch.js +0 -16
- package/dist/esm/cli/mfRuntimePlugins/resolve-entry-ipv4.js +0 -74
- package/dist/esm/cli/mfRuntimePlugins/shared-strategy.js +0 -25
- package/dist/esm/cli/server/data-fetch-server-plugin.js +0 -236
- package/dist/esm/cli/ssrPlugin.js +0 -219
- package/dist/esm/cli/utils.js +0 -53
- package/dist/esm/constant.js +0 -6
- package/dist/esm/interfaces/bundler.js +0 -0
- package/dist/esm/logger.js +0 -7
- package/dist/esm/runtime/index.js +0 -6
- package/dist/esm/server/fileCache.js +0 -98
- package/dist/esm/server/fileCache.spec.js +0 -50
- package/dist/esm/server/index.js +0 -36
- package/dist/esm/server/staticMiddleware.js +0 -81
- package/dist/esm/server/staticMiddleware.spec.js +0 -328
- package/dist/esm/ssr-runtime/SSRLiveReload.js +0 -26
- package/dist/esm/ssr-runtime/devPlugin.js +0 -73
- package/dist/esm/ssr-runtime/injectDataFetchFunctionPlugin.js +0 -35
- package/dist/esm/types/index.js +0 -0
- package/dist/esm-node/cli/configPlugin.js +0 -340
- package/dist/esm-node/cli/configPlugin.spec.js +0 -91
- package/dist/esm-node/cli/index.js +0 -70
- package/dist/esm-node/cli/mfRuntimePlugins/inject-node-fetch.js +0 -14
- package/dist/esm-node/cli/mfRuntimePlugins/resolve-entry-ipv4.js +0 -62
- package/dist/esm-node/cli/mfRuntimePlugins/shared-strategy.js +0 -23
- package/dist/esm-node/cli/server/data-fetch-server-plugin.js +0 -158
- package/dist/esm-node/cli/ssrPlugin.js +0 -200
- package/dist/esm-node/cli/utils.js +0 -53
- package/dist/esm-node/constant.js +0 -6
- package/dist/esm-node/interfaces/bundler.js +0 -0
- package/dist/esm-node/logger.js +0 -7
- package/dist/esm-node/runtime/index.js +0 -6
- package/dist/esm-node/server/fileCache.js +0 -49
- package/dist/esm-node/server/fileCache.spec.js +0 -27
- package/dist/esm-node/server/index.js +0 -34
- package/dist/esm-node/server/staticMiddleware.js +0 -43
- package/dist/esm-node/server/staticMiddleware.spec.js +0 -162
- package/dist/esm-node/ssr-runtime/SSRLiveReload.js +0 -19
- package/dist/esm-node/ssr-runtime/devPlugin.js +0 -37
- package/dist/esm-node/ssr-runtime/injectDataFetchFunctionPlugin.js +0 -17
- package/dist/esm-node/types/index.js +0 -0
- package/dist/types/cli/configPlugin.d.ts +0 -21
- package/dist/types/cli/configPlugin.spec.d.ts +0 -1
- package/dist/types/cli/index.d.ts +0 -6
- package/dist/types/cli/mfRuntimePlugins/inject-node-fetch.d.ts +0 -3
- package/dist/types/cli/mfRuntimePlugins/resolve-entry-ipv4.d.ts +0 -3
- package/dist/types/cli/mfRuntimePlugins/shared-strategy.d.ts +0 -3
- package/dist/types/cli/server/data-fetch-server-plugin.d.ts +0 -3
- package/dist/types/cli/ssrPlugin.d.ts +0 -6
- package/dist/types/cli/utils.d.ts +0 -6
- package/dist/types/constant.d.ts +0 -2
- package/dist/types/interfaces/bundler.d.ts +0 -18
- package/dist/types/logger.d.ts +0 -2
- package/dist/types/runtime/index.d.ts +0 -3
- package/dist/types/server/fileCache.d.ts +0 -14
- package/dist/types/server/fileCache.spec.d.ts +0 -1
- package/dist/types/server/index.d.ts +0 -4
- package/dist/types/server/staticMiddleware.d.ts +0 -6
- package/dist/types/server/staticMiddleware.spec.d.ts +0 -1
- package/dist/types/ssr-runtime/SSRLiveReload.d.ts +0 -1
- package/dist/types/ssr-runtime/devPlugin.d.ts +0 -2
- package/dist/types/ssr-runtime/injectDataFetchFunctionPlugin.d.ts +0 -4
- package/dist/types/types/index.d.ts +0 -24
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
|
2
|
-
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
3
|
-
import { LOCALHOST } from "../../constant";
|
|
4
|
-
var ipv4 = typeof FEDERATION_IPV4 !== "undefined" ? FEDERATION_IPV4 : "127.0.0.1";
|
|
5
|
-
var remoteIpStrategy = typeof REMOTE_IP_STRATEGY !== "undefined" ? REMOTE_IP_STRATEGY : "inherit";
|
|
6
|
-
function replaceObjectLocalhost(key, obj) {
|
|
7
|
-
if (remoteIpStrategy !== "ipv4") {
|
|
8
|
-
return;
|
|
9
|
-
}
|
|
10
|
-
if (!(key in obj)) {
|
|
11
|
-
return;
|
|
12
|
-
}
|
|
13
|
-
var remote = obj[key];
|
|
14
|
-
if (remote && typeof remote === "string" && remote.includes(LOCALHOST)) {
|
|
15
|
-
obj[key] = replaceLocalhost(remote);
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
function replaceLocalhost(url) {
|
|
19
|
-
return url.replace(LOCALHOST, ipv4);
|
|
20
|
-
}
|
|
21
|
-
var resolveEntryIpv4Plugin = function() {
|
|
22
|
-
return {
|
|
23
|
-
name: "resolve-entry-ipv4",
|
|
24
|
-
beforeRegisterRemote: function beforeRegisterRemote(args) {
|
|
25
|
-
var remote = args.remote;
|
|
26
|
-
replaceObjectLocalhost("entry", remote);
|
|
27
|
-
return args;
|
|
28
|
-
},
|
|
29
|
-
afterResolve: function afterResolve(args) {
|
|
30
|
-
return _async_to_generator(function() {
|
|
31
|
-
var remoteInfo;
|
|
32
|
-
return _ts_generator(this, function(_state) {
|
|
33
|
-
remoteInfo = args.remoteInfo;
|
|
34
|
-
replaceObjectLocalhost("entry", remoteInfo);
|
|
35
|
-
return [
|
|
36
|
-
2,
|
|
37
|
-
args
|
|
38
|
-
];
|
|
39
|
-
});
|
|
40
|
-
})();
|
|
41
|
-
},
|
|
42
|
-
beforeLoadRemoteSnapshot: function beforeLoadRemoteSnapshot(args) {
|
|
43
|
-
var moduleInfo = args.moduleInfo;
|
|
44
|
-
if ("entry" in moduleInfo) {
|
|
45
|
-
replaceObjectLocalhost("entry", moduleInfo);
|
|
46
|
-
return args;
|
|
47
|
-
}
|
|
48
|
-
if ("version" in moduleInfo) {
|
|
49
|
-
replaceObjectLocalhost("version", moduleInfo);
|
|
50
|
-
}
|
|
51
|
-
return args;
|
|
52
|
-
},
|
|
53
|
-
loadRemoteSnapshot: function loadRemoteSnapshot(args) {
|
|
54
|
-
var remoteSnapshot = args.remoteSnapshot;
|
|
55
|
-
if ("publicPath" in remoteSnapshot) {
|
|
56
|
-
replaceObjectLocalhost("publicPath", remoteSnapshot);
|
|
57
|
-
}
|
|
58
|
-
if ("getPublicPath" in remoteSnapshot) {
|
|
59
|
-
replaceObjectLocalhost("getPublicPath", remoteSnapshot);
|
|
60
|
-
}
|
|
61
|
-
if (remoteSnapshot.remotesInfo) {
|
|
62
|
-
Object.keys(remoteSnapshot.remotesInfo).forEach(function(key) {
|
|
63
|
-
var remoteInfo = remoteSnapshot.remotesInfo[key];
|
|
64
|
-
replaceObjectLocalhost("matchedVersion", remoteInfo);
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
return args;
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
};
|
|
71
|
-
var resolve_entry_ipv4_default = resolveEntryIpv4Plugin;
|
|
72
|
-
export {
|
|
73
|
-
resolve_entry_ipv4_default as default
|
|
74
|
-
};
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
var sharedStrategy = function() {
|
|
2
|
-
return {
|
|
3
|
-
name: "shared-strategy-plugin",
|
|
4
|
-
beforeInit: function beforeInit(args) {
|
|
5
|
-
var userOptions = args.userOptions;
|
|
6
|
-
var shared = userOptions.shared;
|
|
7
|
-
if (shared) {
|
|
8
|
-
Object.keys(shared).forEach(function(sharedKey) {
|
|
9
|
-
var sharedConfigs = shared[sharedKey];
|
|
10
|
-
var arraySharedConfigs = Array.isArray(sharedConfigs) ? sharedConfigs : [
|
|
11
|
-
sharedConfigs
|
|
12
|
-
];
|
|
13
|
-
arraySharedConfigs.forEach(function(s) {
|
|
14
|
-
s.strategy = "loaded-first";
|
|
15
|
-
});
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
return args;
|
|
19
|
-
}
|
|
20
|
-
};
|
|
21
|
-
};
|
|
22
|
-
var shared_strategy_default = sharedStrategy;
|
|
23
|
-
export {
|
|
24
|
-
shared_strategy_default as default
|
|
25
|
-
};
|
|
@@ -1,236 +0,0 @@
|
|
|
1
|
-
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
|
2
|
-
import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
|
|
3
|
-
import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
|
|
4
|
-
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
5
|
-
import { DATA_FETCH_QUERY, MF_DATA_FETCH_STATUS } from "@module-federation/bridge-react/data-fetch-constant";
|
|
6
|
-
import { getDataFetchMap, fetchData, initDataFetchMap, loadDataFetchModule } from "@module-federation/bridge-react/data-fetch-utils";
|
|
7
|
-
import { SEPARATOR, MANIFEST_EXT } from "@module-federation/sdk";
|
|
8
|
-
import logger from "../../logger";
|
|
9
|
-
function wrapSetTimeout(targetPromise) {
|
|
10
|
-
var delay = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 2e4, id = arguments.length > 2 ? arguments[2] : void 0;
|
|
11
|
-
if (targetPromise && typeof targetPromise.then === "function") {
|
|
12
|
-
return new Promise(function(resolve, reject) {
|
|
13
|
-
var timeoutId = setTimeout(function() {
|
|
14
|
-
logger.warn("Data fetch for ID ".concat(id, " timed out after 20 seconds."));
|
|
15
|
-
reject(new Error("Data fetch for ID ".concat(id, " timed out after 20 seconds")));
|
|
16
|
-
}, delay);
|
|
17
|
-
targetPromise.then(function(value) {
|
|
18
|
-
clearTimeout(timeoutId);
|
|
19
|
-
resolve(value);
|
|
20
|
-
}).catch(function(err) {
|
|
21
|
-
clearTimeout(timeoutId);
|
|
22
|
-
reject(err);
|
|
23
|
-
});
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
function addProtocol(url) {
|
|
28
|
-
if (url.startsWith("//")) {
|
|
29
|
-
return "https:" + url;
|
|
30
|
-
}
|
|
31
|
-
return url;
|
|
32
|
-
}
|
|
33
|
-
var getDecodeQuery = function(url, name) {
|
|
34
|
-
var res = url.searchParams.get(name);
|
|
35
|
-
if (!res) {
|
|
36
|
-
return null;
|
|
37
|
-
}
|
|
38
|
-
return decodeURIComponent(res);
|
|
39
|
-
};
|
|
40
|
-
var middleware = function() {
|
|
41
|
-
var _ref = _async_to_generator(function(ctx, next) {
|
|
42
|
-
var _globalThis___FEDERATION__, url, dataFetchId, params, remoteInfo, remoteInfoQuery, _dataFetchMap_dataFetchId, _dataFetchMap_dataFetchId1, dataFetchMap, fetchDataPromise, targetPromise, wrappedPromise, res, hostInstance, remoteEntry, remote, _hostInstance_snapshotHandler_getGlobalRemoteInfo, hostGlobalSnapshot, remoteSnapshot, dataFetchItem, callFetchDataPromise, wrappedPromise1, res1, remoteId, hostInstance1, dataFetchFn, data, e;
|
|
43
|
-
return _ts_generator(this, function(_state) {
|
|
44
|
-
switch (_state.label) {
|
|
45
|
-
case 0:
|
|
46
|
-
try {
|
|
47
|
-
url = new URL(ctx.req.url);
|
|
48
|
-
dataFetchId = getDecodeQuery(url, DATA_FETCH_QUERY);
|
|
49
|
-
params = JSON.parse(getDecodeQuery(url, "params") || "{}");
|
|
50
|
-
remoteInfoQuery = getDecodeQuery(url, "remoteInfo");
|
|
51
|
-
remoteInfo = remoteInfoQuery ? JSON.parse(remoteInfoQuery) : null;
|
|
52
|
-
} catch (e2) {
|
|
53
|
-
logger.error("fetch data from server, error: ", e2);
|
|
54
|
-
return [
|
|
55
|
-
2,
|
|
56
|
-
next()
|
|
57
|
-
];
|
|
58
|
-
}
|
|
59
|
-
if (!dataFetchId) {
|
|
60
|
-
return [
|
|
61
|
-
2,
|
|
62
|
-
next()
|
|
63
|
-
];
|
|
64
|
-
}
|
|
65
|
-
logger.log("fetch data from server, dataFetchId: ", dataFetchId);
|
|
66
|
-
logger.debug("fetch data from server, moduleInfo: ", (_globalThis___FEDERATION__ = globalThis.__FEDERATION__) === null || _globalThis___FEDERATION__ === void 0 ? void 0 : _globalThis___FEDERATION__.moduleInfo);
|
|
67
|
-
_state.label = 1;
|
|
68
|
-
case 1:
|
|
69
|
-
_state.trys.push([
|
|
70
|
-
1,
|
|
71
|
-
9,
|
|
72
|
-
,
|
|
73
|
-
10
|
|
74
|
-
]);
|
|
75
|
-
dataFetchMap = getDataFetchMap();
|
|
76
|
-
if (!dataFetchMap) {
|
|
77
|
-
initDataFetchMap();
|
|
78
|
-
}
|
|
79
|
-
fetchDataPromise = (_dataFetchMap_dataFetchId = dataFetchMap[dataFetchId]) === null || _dataFetchMap_dataFetchId === void 0 ? void 0 : _dataFetchMap_dataFetchId[1];
|
|
80
|
-
logger.debug("fetch data from server, fetchDataPromise: ", fetchDataPromise);
|
|
81
|
-
if (!(fetchDataPromise && ((_dataFetchMap_dataFetchId1 = dataFetchMap[dataFetchId]) === null || _dataFetchMap_dataFetchId1 === void 0 ? void 0 : _dataFetchMap_dataFetchId1[2]) !== MF_DATA_FETCH_STATUS.ERROR))
|
|
82
|
-
return [
|
|
83
|
-
3,
|
|
84
|
-
4
|
|
85
|
-
];
|
|
86
|
-
targetPromise = fetchDataPromise[0];
|
|
87
|
-
wrappedPromise = wrapSetTimeout(targetPromise, 2e4, dataFetchId);
|
|
88
|
-
if (!wrappedPromise)
|
|
89
|
-
return [
|
|
90
|
-
3,
|
|
91
|
-
3
|
|
92
|
-
];
|
|
93
|
-
return [
|
|
94
|
-
4,
|
|
95
|
-
wrappedPromise
|
|
96
|
-
];
|
|
97
|
-
case 2:
|
|
98
|
-
res = _state.sent();
|
|
99
|
-
logger.log("fetch data from server, fetchDataPromise res: ", res);
|
|
100
|
-
return [
|
|
101
|
-
2,
|
|
102
|
-
ctx.json(res)
|
|
103
|
-
];
|
|
104
|
-
case 3:
|
|
105
|
-
logger.error("Expected a Promise from fetchDataPromise[0] for dataFetchId ".concat(dataFetchId, ", but received:"), targetPromise, "Will try call new dataFetch again...");
|
|
106
|
-
_state.label = 4;
|
|
107
|
-
case 4:
|
|
108
|
-
if (remoteInfo) {
|
|
109
|
-
try {
|
|
110
|
-
hostInstance = globalThis.__FEDERATION__.__INSTANCES__[0];
|
|
111
|
-
remoteEntry = "".concat(addProtocol(remoteInfo.ssrPublicPath) + remoteInfo.ssrRemoteEntry);
|
|
112
|
-
if (!hostInstance) {
|
|
113
|
-
throw new Error("host instance not found!");
|
|
114
|
-
}
|
|
115
|
-
remote = hostInstance.options.remotes.find(function(remote2) {
|
|
116
|
-
return remote2.name === remoteInfo.name;
|
|
117
|
-
});
|
|
118
|
-
logger.debug("find remote: ", JSON.stringify(remote));
|
|
119
|
-
if (!remote) {
|
|
120
|
-
hostInstance.registerRemotes([
|
|
121
|
-
{
|
|
122
|
-
name: remoteInfo.name,
|
|
123
|
-
entry: remoteEntry,
|
|
124
|
-
entryGlobalName: remoteInfo.globalName
|
|
125
|
-
}
|
|
126
|
-
]);
|
|
127
|
-
} else if (!("entry" in remote) || !remote.entry.includes(MANIFEST_EXT)) {
|
|
128
|
-
_hostInstance_snapshotHandler_getGlobalRemoteInfo = hostInstance.snapshotHandler.getGlobalRemoteInfo(remoteInfo), hostGlobalSnapshot = _hostInstance_snapshotHandler_getGlobalRemoteInfo.hostGlobalSnapshot, remoteSnapshot = _hostInstance_snapshotHandler_getGlobalRemoteInfo.remoteSnapshot;
|
|
129
|
-
logger.debug("find hostGlobalSnapshot: ", JSON.stringify(hostGlobalSnapshot));
|
|
130
|
-
logger.debug("find remoteSnapshot: ", JSON.stringify(remoteSnapshot));
|
|
131
|
-
if (!hostGlobalSnapshot || !remoteSnapshot) {
|
|
132
|
-
if ("version" in remote) {
|
|
133
|
-
delete remote.version;
|
|
134
|
-
}
|
|
135
|
-
remote.entry = remoteEntry;
|
|
136
|
-
remote.entryGlobalName = remoteInfo.globalName;
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
} catch (e2) {
|
|
140
|
-
ctx.status(500);
|
|
141
|
-
return [
|
|
142
|
-
2,
|
|
143
|
-
ctx.text("failed to fetch ".concat(remoteInfo.name, " data, error:\n ").concat(e2))
|
|
144
|
-
];
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
dataFetchItem = dataFetchMap[dataFetchId];
|
|
148
|
-
logger.debug("fetch data from server, dataFetchItem: ", dataFetchItem);
|
|
149
|
-
if (!dataFetchItem)
|
|
150
|
-
return [
|
|
151
|
-
3,
|
|
152
|
-
6
|
|
153
|
-
];
|
|
154
|
-
callFetchDataPromise = fetchData(dataFetchId, _object_spread_props(_object_spread({}, params), {
|
|
155
|
-
isDowngrade: !remoteInfo
|
|
156
|
-
}));
|
|
157
|
-
wrappedPromise1 = wrapSetTimeout(callFetchDataPromise, 2e4, dataFetchId);
|
|
158
|
-
if (!wrappedPromise1)
|
|
159
|
-
return [
|
|
160
|
-
3,
|
|
161
|
-
6
|
|
162
|
-
];
|
|
163
|
-
return [
|
|
164
|
-
4,
|
|
165
|
-
wrappedPromise1
|
|
166
|
-
];
|
|
167
|
-
case 5:
|
|
168
|
-
res1 = _state.sent();
|
|
169
|
-
logger.log("fetch data from server, dataFetchItem res: ", res1);
|
|
170
|
-
return [
|
|
171
|
-
2,
|
|
172
|
-
ctx.json(res1)
|
|
173
|
-
];
|
|
174
|
-
case 6:
|
|
175
|
-
remoteId = dataFetchId.split(SEPARATOR)[0];
|
|
176
|
-
hostInstance1 = globalThis.__FEDERATION__.__INSTANCES__[0];
|
|
177
|
-
if (!hostInstance1) {
|
|
178
|
-
throw new Error("host instance not found!");
|
|
179
|
-
}
|
|
180
|
-
return [
|
|
181
|
-
4,
|
|
182
|
-
loadDataFetchModule(hostInstance1, remoteId)
|
|
183
|
-
];
|
|
184
|
-
case 7:
|
|
185
|
-
dataFetchFn = _state.sent();
|
|
186
|
-
return [
|
|
187
|
-
4,
|
|
188
|
-
dataFetchFn(_object_spread_props(_object_spread({}, params), {
|
|
189
|
-
isDowngrade: !remoteInfo
|
|
190
|
-
}))
|
|
191
|
-
];
|
|
192
|
-
case 8:
|
|
193
|
-
data = _state.sent();
|
|
194
|
-
logger.log("fetch data from server, loadDataFetchModule res: ", data);
|
|
195
|
-
return [
|
|
196
|
-
2,
|
|
197
|
-
ctx.json(data)
|
|
198
|
-
];
|
|
199
|
-
case 9:
|
|
200
|
-
e = _state.sent();
|
|
201
|
-
logger.error("server plugin data fetch error: ", e);
|
|
202
|
-
ctx.status(500);
|
|
203
|
-
return [
|
|
204
|
-
2,
|
|
205
|
-
ctx.text("failed to fetch ".concat(remoteInfo.name, " data, error:\n ").concat(e))
|
|
206
|
-
];
|
|
207
|
-
case 10:
|
|
208
|
-
return [
|
|
209
|
-
2
|
|
210
|
-
];
|
|
211
|
-
}
|
|
212
|
-
});
|
|
213
|
-
});
|
|
214
|
-
return function middleware2(ctx, next) {
|
|
215
|
-
return _ref.apply(this, arguments);
|
|
216
|
-
};
|
|
217
|
-
}();
|
|
218
|
-
var dataFetchServePlugin = function() {
|
|
219
|
-
return {
|
|
220
|
-
name: "mf-data-fetch-server-plugin",
|
|
221
|
-
setup: function(api) {
|
|
222
|
-
api.onPrepare(function() {
|
|
223
|
-
var middlewares = api.getServerContext().middlewares;
|
|
224
|
-
middlewares.push({
|
|
225
|
-
name: "module-federation-serve-manifest",
|
|
226
|
-
// @ts-ignore type error
|
|
227
|
-
handler: middleware
|
|
228
|
-
});
|
|
229
|
-
});
|
|
230
|
-
}
|
|
231
|
-
};
|
|
232
|
-
};
|
|
233
|
-
var data_fetch_server_plugin_default = dataFetchServePlugin;
|
|
234
|
-
export {
|
|
235
|
-
data_fetch_server_plugin_default as default
|
|
236
|
-
};
|
|
@@ -1,219 +0,0 @@
|
|
|
1
|
-
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
|
2
|
-
import { _ as _type_of } from "@swc/helpers/_/_type_of";
|
|
3
|
-
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
4
|
-
import path from "path";
|
|
5
|
-
import fs from "fs-extra";
|
|
6
|
-
import { ModuleFederationPlugin } from "@module-federation/enhanced/webpack";
|
|
7
|
-
import { ModuleFederationPlugin as RspackModuleFederationPlugin } from "@module-federation/enhanced/rspack";
|
|
8
|
-
import UniverseEntryChunkTrackerPlugin from "@module-federation/node/universe-entry-chunk-tracker-plugin";
|
|
9
|
-
import logger from "../logger";
|
|
10
|
-
import { isDev } from "./utils";
|
|
11
|
-
import { updateStatsAndManifest } from "@module-federation/rsbuild-plugin/manifest";
|
|
12
|
-
import { isWebTarget, skipByTarget } from "./utils";
|
|
13
|
-
function setEnv() {
|
|
14
|
-
process.env["MF_DISABLE_EMIT_STATS"] = "true";
|
|
15
|
-
process.env["MF_SSR_PRJ"] = "true";
|
|
16
|
-
}
|
|
17
|
-
var CHAIN_MF_PLUGIN_ID = "plugin-module-federation-server";
|
|
18
|
-
var mfSSRRsbuildPlugin = function(pluginOptions) {
|
|
19
|
-
return {
|
|
20
|
-
name: "@modern-js/plugin-mf-post-config",
|
|
21
|
-
pre: [
|
|
22
|
-
"@modern-js/builder-plugin-ssr"
|
|
23
|
-
],
|
|
24
|
-
setup: function setup(api) {
|
|
25
|
-
if (pluginOptions.csrConfig.getPublicPath) {
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
var csrOutputPath = "";
|
|
29
|
-
var ssrOutputPath = "";
|
|
30
|
-
var ssrEnv = "";
|
|
31
|
-
api.modifyEnvironmentConfig(function(config, param) {
|
|
32
|
-
var name = param.name;
|
|
33
|
-
var target = config.output.target;
|
|
34
|
-
if (skipByTarget(target)) {
|
|
35
|
-
return config;
|
|
36
|
-
}
|
|
37
|
-
if (isWebTarget(target)) {
|
|
38
|
-
csrOutputPath = config.output.distPath.root;
|
|
39
|
-
} else {
|
|
40
|
-
ssrOutputPath = config.output.distPath.root;
|
|
41
|
-
ssrEnv = name;
|
|
42
|
-
}
|
|
43
|
-
return config;
|
|
44
|
-
});
|
|
45
|
-
var modifySSRPublicPath = function(config, utils) {
|
|
46
|
-
if (ssrEnv !== utils.environment.name) {
|
|
47
|
-
return config;
|
|
48
|
-
}
|
|
49
|
-
var userSSRConfig = pluginOptions.userConfig.ssr ? _type_of(pluginOptions.userConfig.ssr) === "object" ? pluginOptions.userConfig.ssr : {} : {};
|
|
50
|
-
if (userSSRConfig.distOutputDir) {
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
config.output.publicPath = "".concat(config.output.publicPath).concat(path.relative(csrOutputPath, ssrOutputPath), "/");
|
|
54
|
-
return config;
|
|
55
|
-
};
|
|
56
|
-
api.modifyWebpackConfig(function(config, utils) {
|
|
57
|
-
modifySSRPublicPath(config, utils);
|
|
58
|
-
return config;
|
|
59
|
-
});
|
|
60
|
-
api.modifyRspackConfig(function(config, utils) {
|
|
61
|
-
modifySSRPublicPath(config, utils);
|
|
62
|
-
return config;
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
};
|
|
66
|
-
};
|
|
67
|
-
var moduleFederationSSRPlugin = function(pluginOptions) {
|
|
68
|
-
return {
|
|
69
|
-
name: "@modern-js/plugin-module-federation-ssr",
|
|
70
|
-
pre: [
|
|
71
|
-
"@modern-js/plugin-module-federation-config",
|
|
72
|
-
"@modern-js/plugin-module-federation"
|
|
73
|
-
],
|
|
74
|
-
setup: function() {
|
|
75
|
-
var _ref = _async_to_generator(function(api) {
|
|
76
|
-
var _pluginOptions_userConfig, _modernjsConfig_server, modernjsConfig, _pluginOptions_userConfig_ssr, enableSSR;
|
|
77
|
-
return _ts_generator(this, function(_state) {
|
|
78
|
-
modernjsConfig = api.getConfig();
|
|
79
|
-
enableSSR = (_pluginOptions_userConfig_ssr = (_pluginOptions_userConfig = pluginOptions.userConfig) === null || _pluginOptions_userConfig === void 0 ? void 0 : _pluginOptions_userConfig.ssr) !== null && _pluginOptions_userConfig_ssr !== void 0 ? _pluginOptions_userConfig_ssr : Boolean(modernjsConfig === null || modernjsConfig === void 0 ? void 0 : (_modernjsConfig_server = modernjsConfig.server) === null || _modernjsConfig_server === void 0 ? void 0 : _modernjsConfig_server.ssr);
|
|
80
|
-
if (!enableSSR) {
|
|
81
|
-
return [
|
|
82
|
-
2
|
|
83
|
-
];
|
|
84
|
-
}
|
|
85
|
-
setEnv();
|
|
86
|
-
api._internalRuntimePlugins(function(param) {
|
|
87
|
-
var entrypoint = param.entrypoint, plugins = param.plugins;
|
|
88
|
-
var fetchServerQuery = pluginOptions.fetchServerQuery;
|
|
89
|
-
plugins.push({
|
|
90
|
-
name: "injectDataFetchFunction",
|
|
91
|
-
path: "@module-federation/modern-js/ssr-inject-data-fetch-function-plugin",
|
|
92
|
-
config: {
|
|
93
|
-
fetchServerQuery
|
|
94
|
-
}
|
|
95
|
-
});
|
|
96
|
-
if (!isDev()) {
|
|
97
|
-
return {
|
|
98
|
-
entrypoint,
|
|
99
|
-
plugins
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
plugins.push({
|
|
103
|
-
name: "mfSSRDev",
|
|
104
|
-
path: "@module-federation/modern-js/ssr-dev-plugin",
|
|
105
|
-
config: {}
|
|
106
|
-
});
|
|
107
|
-
return {
|
|
108
|
-
entrypoint,
|
|
109
|
-
plugins
|
|
110
|
-
};
|
|
111
|
-
});
|
|
112
|
-
if (pluginOptions.ssrConfig.remotes) {
|
|
113
|
-
api._internalServerPlugins(function(param) {
|
|
114
|
-
var plugins = param.plugins;
|
|
115
|
-
plugins.push({
|
|
116
|
-
name: "@module-federation/modern-js/data-fetch-server-plugin",
|
|
117
|
-
options: {}
|
|
118
|
-
});
|
|
119
|
-
return {
|
|
120
|
-
plugins
|
|
121
|
-
};
|
|
122
|
-
});
|
|
123
|
-
}
|
|
124
|
-
api.modifyBundlerChain(function(chain) {
|
|
125
|
-
var target = chain.get("target");
|
|
126
|
-
if (skipByTarget(target)) {
|
|
127
|
-
return;
|
|
128
|
-
}
|
|
129
|
-
var bundlerType = api.getAppContext().bundlerType === "rspack" ? "rspack" : "webpack";
|
|
130
|
-
var MFPlugin = bundlerType === "webpack" ? ModuleFederationPlugin : RspackModuleFederationPlugin;
|
|
131
|
-
var isWeb = isWebTarget(target);
|
|
132
|
-
if (!isWeb) {
|
|
133
|
-
if (!chain.plugins.has(CHAIN_MF_PLUGIN_ID)) {
|
|
134
|
-
chain.plugin(CHAIN_MF_PLUGIN_ID).use(MFPlugin, [
|
|
135
|
-
pluginOptions.ssrConfig
|
|
136
|
-
]).init(function(Plugin, args) {
|
|
137
|
-
pluginOptions.nodePlugin = new Plugin(args[0]);
|
|
138
|
-
return pluginOptions.nodePlugin;
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
if (!isWeb) {
|
|
143
|
-
chain.target("async-node");
|
|
144
|
-
if (isDev()) {
|
|
145
|
-
chain.plugin("UniverseEntryChunkTrackerPlugin").use(UniverseEntryChunkTrackerPlugin);
|
|
146
|
-
}
|
|
147
|
-
var userSSRConfig = pluginOptions.userConfig.ssr ? _type_of(pluginOptions.userConfig.ssr) === "object" ? pluginOptions.userConfig.ssr : {} : {};
|
|
148
|
-
var publicPath = chain.output.get("publicPath");
|
|
149
|
-
if (userSSRConfig.distOutputDir && publicPath) {
|
|
150
|
-
chain.output.publicPath("".concat(publicPath).concat(userSSRConfig.distOutputDir, "/"));
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
if (isDev() && isWeb) {
|
|
154
|
-
chain.externals({
|
|
155
|
-
"@module-federation/node/utils": "NOT_USED_IN_BROWSER"
|
|
156
|
-
});
|
|
157
|
-
}
|
|
158
|
-
});
|
|
159
|
-
api.config(function() {
|
|
160
|
-
return {
|
|
161
|
-
builderPlugins: [
|
|
162
|
-
mfSSRRsbuildPlugin(pluginOptions)
|
|
163
|
-
],
|
|
164
|
-
tools: {
|
|
165
|
-
devServer: {
|
|
166
|
-
before: [
|
|
167
|
-
function(req, res, next) {
|
|
168
|
-
if (!enableSSR) {
|
|
169
|
-
next();
|
|
170
|
-
return;
|
|
171
|
-
}
|
|
172
|
-
try {
|
|
173
|
-
var _req_url, _req_url1;
|
|
174
|
-
if (((_req_url = req.url) === null || _req_url === void 0 ? void 0 : _req_url.includes(".json")) && !((_req_url1 = req.url) === null || _req_url1 === void 0 ? void 0 : _req_url1.includes("hot-update"))) {
|
|
175
|
-
var filepath = path.join(process.cwd(), "dist".concat(req.url));
|
|
176
|
-
fs.statSync(filepath);
|
|
177
|
-
res.setHeader("Access-Control-Allow-Origin", "*");
|
|
178
|
-
res.setHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, PATCH, OPTIONS");
|
|
179
|
-
res.setHeader("Access-Control-Allow-Headers", "*");
|
|
180
|
-
fs.createReadStream(filepath).pipe(res);
|
|
181
|
-
} else {
|
|
182
|
-
next();
|
|
183
|
-
}
|
|
184
|
-
} catch (err) {
|
|
185
|
-
logger.debug(err);
|
|
186
|
-
next();
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
]
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
};
|
|
193
|
-
});
|
|
194
|
-
api.onAfterBuild(function() {
|
|
195
|
-
var nodePlugin = pluginOptions.nodePlugin, browserPlugin = pluginOptions.browserPlugin, distOutputDir = pluginOptions.distOutputDir;
|
|
196
|
-
updateStatsAndManifest(nodePlugin, browserPlugin, distOutputDir);
|
|
197
|
-
});
|
|
198
|
-
api.onDevCompileDone(function() {
|
|
199
|
-
var nodePlugin = pluginOptions.nodePlugin, browserPlugin = pluginOptions.browserPlugin, distOutputDir = pluginOptions.distOutputDir;
|
|
200
|
-
updateStatsAndManifest(nodePlugin, browserPlugin, distOutputDir);
|
|
201
|
-
});
|
|
202
|
-
return [
|
|
203
|
-
2
|
|
204
|
-
];
|
|
205
|
-
});
|
|
206
|
-
});
|
|
207
|
-
return function(api) {
|
|
208
|
-
return _ref.apply(this, arguments);
|
|
209
|
-
};
|
|
210
|
-
}()
|
|
211
|
-
};
|
|
212
|
-
};
|
|
213
|
-
var ssrPlugin_default = moduleFederationSSRPlugin;
|
|
214
|
-
export {
|
|
215
|
-
CHAIN_MF_PLUGIN_ID,
|
|
216
|
-
ssrPlugin_default as default,
|
|
217
|
-
moduleFederationSSRPlugin,
|
|
218
|
-
setEnv
|
|
219
|
-
};
|
package/dist/esm/cli/utils.js
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import os from "os";
|
|
2
|
-
var localIpv4 = "127.0.0.1";
|
|
3
|
-
var getIpv4Interfaces = function() {
|
|
4
|
-
try {
|
|
5
|
-
var interfaces = os.networkInterfaces();
|
|
6
|
-
var ipv4Interfaces = [];
|
|
7
|
-
Object.values(interfaces).forEach(function(detail) {
|
|
8
|
-
detail === null || detail === void 0 ? void 0 : detail.forEach(function(detail2) {
|
|
9
|
-
var familyV4Value = typeof detail2.family === "string" ? "IPv4" : 4;
|
|
10
|
-
if (detail2.family === familyV4Value && detail2.address !== localIpv4) {
|
|
11
|
-
ipv4Interfaces.push(detail2);
|
|
12
|
-
}
|
|
13
|
-
});
|
|
14
|
-
});
|
|
15
|
-
return ipv4Interfaces;
|
|
16
|
-
} catch (_err) {
|
|
17
|
-
return [];
|
|
18
|
-
}
|
|
19
|
-
};
|
|
20
|
-
var getIPV4 = function() {
|
|
21
|
-
var ipv4Interfaces = getIpv4Interfaces();
|
|
22
|
-
var ipv4Interface = ipv4Interfaces[0] || {
|
|
23
|
-
address: localIpv4
|
|
24
|
-
};
|
|
25
|
-
return ipv4Interface.address;
|
|
26
|
-
};
|
|
27
|
-
var isWebTarget = function(target) {
|
|
28
|
-
var WEB_TARGET = "web";
|
|
29
|
-
if (Array.isArray(target)) {
|
|
30
|
-
return target.includes(WEB_TARGET);
|
|
31
|
-
} else if (typeof target === "string") {
|
|
32
|
-
return target === WEB_TARGET;
|
|
33
|
-
}
|
|
34
|
-
return false;
|
|
35
|
-
};
|
|
36
|
-
var skipByTarget = function(target) {
|
|
37
|
-
var IGNORE_TARGET = "webworker";
|
|
38
|
-
if (Array.isArray(target)) {
|
|
39
|
-
return target.includes(IGNORE_TARGET);
|
|
40
|
-
} else if (typeof target === "string") {
|
|
41
|
-
return target === IGNORE_TARGET;
|
|
42
|
-
}
|
|
43
|
-
return false;
|
|
44
|
-
};
|
|
45
|
-
function isDev() {
|
|
46
|
-
return process.env.NODE_ENV === "development";
|
|
47
|
-
}
|
|
48
|
-
export {
|
|
49
|
-
getIPV4,
|
|
50
|
-
isDev,
|
|
51
|
-
isWebTarget,
|
|
52
|
-
skipByTarget
|
|
53
|
-
};
|
package/dist/esm/constant.js
DELETED
|
File without changes
|
package/dist/esm/logger.js
DELETED