@module-federation/runtime 0.6.0 → 0.6.1
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/embedded.cjs.d.ts +1 -0
- package/dist/embedded.cjs.js +20 -0
- package/dist/embedded.esm.js +3 -0
- package/dist/helpers.cjs.js +2 -0
- package/dist/helpers.esm.js +3 -1
- package/dist/index.cjs.js +21 -143
- package/dist/index.esm.js +18 -140
- package/dist/package.json +5 -8
- package/dist/polyfills.cjs.js +28 -0
- package/dist/polyfills.esm.js +25 -0
- package/dist/share.cjs.js +11 -64
- package/dist/share.esm.js +6 -57
- package/dist/src/embedded.d.ts +2 -0
- package/dist/src/remote/index.d.ts +1 -1
- package/dist/src/utils/env.d.ts +1 -2
- package/dist/src/utils/tool.d.ts +1 -2
- package/package.json +6 -9
- package/dist/retry-plugin.cjs.d.ts +0 -2
- package/dist/retry-plugin.cjs.js +0 -68
- package/dist/retry-plugin.esm.js +0 -66
- package/dist/src/plugins/retry-plugin.d.ts +0 -9
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./src/embedded";
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
const { FederationHost, registerGlobalPlugins, getRemoteEntry, getRemoteInfo, loadScript, loadScriptNode, init, loadRemote, loadShare, loadShareSync, preloadRemote, registerRemotes, registerPlugins, getInstance } = __webpack_require__.federation.runtime;
|
|
6
|
+
|
|
7
|
+
exports.FederationHost = FederationHost;
|
|
8
|
+
exports.getInstance = getInstance;
|
|
9
|
+
exports.getRemoteEntry = getRemoteEntry;
|
|
10
|
+
exports.getRemoteInfo = getRemoteInfo;
|
|
11
|
+
exports.init = init;
|
|
12
|
+
exports.loadRemote = loadRemote;
|
|
13
|
+
exports.loadScript = loadScript;
|
|
14
|
+
exports.loadScriptNode = loadScriptNode;
|
|
15
|
+
exports.loadShare = loadShare;
|
|
16
|
+
exports.loadShareSync = loadShareSync;
|
|
17
|
+
exports.preloadRemote = preloadRemote;
|
|
18
|
+
exports.registerGlobalPlugins = registerGlobalPlugins;
|
|
19
|
+
exports.registerPlugins = registerPlugins;
|
|
20
|
+
exports.registerRemotes = registerRemotes;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
const { FederationHost, registerGlobalPlugins, getRemoteEntry, getRemoteInfo, loadScript, loadScriptNode, init, loadRemote, loadShare, loadShareSync, preloadRemote, registerRemotes, registerPlugins, getInstance } = __webpack_require__.federation.runtime;
|
|
2
|
+
|
|
3
|
+
export { FederationHost, getInstance, getRemoteEntry, getRemoteInfo, init, loadRemote, loadScript, loadScriptNode, loadShare, loadShareSync, preloadRemote, registerGlobalPlugins, registerPlugins, registerRemotes };
|
package/dist/helpers.cjs.js
CHANGED
package/dist/helpers.esm.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { o as getRegisteredShare, y as getGlobalShareScope, G as Global, I as nativeGlobal, J as resetFederationGlobalInfo, C as getGlobalFederationInstance, F as setGlobalFederationInstance, E as getGlobalFederationConstructor, B as setGlobalFederationConstructor, m as getInfoWithoutType, u as getGlobalSnapshot, K as getTargetSnapshotInfoByModuleInfo, q as getGlobalSnapshotInfoByModuleInfo, t as setGlobalSnapshotInfoByModuleInfo, r as addGlobalSnapshot, c as getRemoteEntryExports, H as registerGlobalPlugins, g as getGlobalHostPlugins, n as getPreloaded, s as setPreloaded } from './share.esm.js';
|
|
2
|
+
import './polyfills.esm.js';
|
|
3
|
+
import '@module-federation/sdk';
|
|
2
4
|
|
|
3
5
|
const ShareUtils = {
|
|
4
6
|
getRegisteredShare,
|
package/dist/index.cjs.js
CHANGED
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var
|
|
5
|
+
var polyfills = require('./polyfills.cjs.js');
|
|
6
6
|
var sdk = require('@module-federation/sdk');
|
|
7
|
+
var share = require('./share.cjs.js');
|
|
7
8
|
|
|
8
9
|
// Function to match a remote with its name and expose
|
|
9
10
|
// id: pkgName(@federation/app1) + expose(button) = @federation/app1/button
|
|
@@ -89,20 +90,6 @@ function registerPlugins$1(plugins, hookInstances) {
|
|
|
89
90
|
return plugins;
|
|
90
91
|
}
|
|
91
92
|
|
|
92
|
-
function _extends$7() {
|
|
93
|
-
_extends$7 = Object.assign || function(target) {
|
|
94
|
-
for(var i = 1; i < arguments.length; i++){
|
|
95
|
-
var source = arguments[i];
|
|
96
|
-
for(var key in source){
|
|
97
|
-
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
98
|
-
target[key] = source[key];
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
return target;
|
|
103
|
-
};
|
|
104
|
-
return _extends$7.apply(this, arguments);
|
|
105
|
-
}
|
|
106
93
|
async function loadEsmEntry({ entry, remoteEntryExports }) {
|
|
107
94
|
return new Promise((resolve, reject)=>{
|
|
108
95
|
try {
|
|
@@ -265,7 +252,7 @@ async function getRemoteEntry({ origin, remoteEntryExports, remoteInfo }) {
|
|
|
265
252
|
return share.globalLoading[uniqueKey];
|
|
266
253
|
}
|
|
267
254
|
function getRemoteInfo(remote) {
|
|
268
|
-
return _extends
|
|
255
|
+
return polyfills._extends({}, remote, {
|
|
269
256
|
entry: 'entry' in remote ? remote.entry : '',
|
|
270
257
|
type: remote.type || share.DEFAULT_REMOTE_TYPE,
|
|
271
258
|
entryGlobalName: remote.entryGlobalName || remote.name,
|
|
@@ -273,20 +260,6 @@ function getRemoteInfo(remote) {
|
|
|
273
260
|
});
|
|
274
261
|
}
|
|
275
262
|
|
|
276
|
-
function _extends$6() {
|
|
277
|
-
_extends$6 = Object.assign || function(target) {
|
|
278
|
-
for(var i = 1; i < arguments.length; i++){
|
|
279
|
-
var source = arguments[i];
|
|
280
|
-
for(var key in source){
|
|
281
|
-
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
282
|
-
target[key] = source[key];
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
return target;
|
|
287
|
-
};
|
|
288
|
-
return _extends$6.apply(this, arguments);
|
|
289
|
-
}
|
|
290
263
|
let Module = class Module {
|
|
291
264
|
async getEntry() {
|
|
292
265
|
if (this.remoteEntryExports) {
|
|
@@ -298,7 +271,7 @@ let Module = class Module {
|
|
|
298
271
|
remoteInfo: this.remoteInfo,
|
|
299
272
|
remoteEntryExports: this.remoteEntryExports
|
|
300
273
|
});
|
|
301
|
-
share.assert(remoteEntryExports, `remoteEntryExports is undefined \n ${
|
|
274
|
+
share.assert(remoteEntryExports, `remoteEntryExports is undefined \n ${sdk.safeToString(this.remoteInfo)}`);
|
|
302
275
|
this.remoteEntryExports = remoteEntryExports;
|
|
303
276
|
return this.remoteEntryExports;
|
|
304
277
|
}
|
|
@@ -338,7 +311,7 @@ let Module = class Module {
|
|
|
338
311
|
console.error('The remote entry interface does not contain "init"', '\n', 'Ensure the name of this remote is not reserved or in use. Check if anything already exists on window[nameOfRemote]', '\n', 'Ensure that window[nameOfRemote] is returning a {get,init} object.');
|
|
339
312
|
}
|
|
340
313
|
await remoteEntryExports.init(initContainerOptions.shareScope, initContainerOptions.initScope, initContainerOptions.remoteEntryInitOptions);
|
|
341
|
-
await this.host.hooks.lifecycle.initContainer.emit(_extends
|
|
314
|
+
await this.host.hooks.lifecycle.initContainer.emit(polyfills._extends({}, initContainerOptions, {
|
|
342
315
|
remoteEntryExports
|
|
343
316
|
}));
|
|
344
317
|
}
|
|
@@ -574,22 +547,8 @@ class PluginSystem {
|
|
|
574
547
|
}
|
|
575
548
|
}
|
|
576
549
|
|
|
577
|
-
function _extends$5() {
|
|
578
|
-
_extends$5 = Object.assign || function(target) {
|
|
579
|
-
for(var i = 1; i < arguments.length; i++){
|
|
580
|
-
var source = arguments[i];
|
|
581
|
-
for(var key in source){
|
|
582
|
-
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
583
|
-
target[key] = source[key];
|
|
584
|
-
}
|
|
585
|
-
}
|
|
586
|
-
}
|
|
587
|
-
return target;
|
|
588
|
-
};
|
|
589
|
-
return _extends$5.apply(this, arguments);
|
|
590
|
-
}
|
|
591
550
|
function defaultPreloadArgs(preloadConfig) {
|
|
592
|
-
return _extends
|
|
551
|
+
return polyfills._extends({
|
|
593
552
|
resourceCategory: 'sync',
|
|
594
553
|
share: true,
|
|
595
554
|
depsRemote: true,
|
|
@@ -599,7 +558,7 @@ function defaultPreloadArgs(preloadConfig) {
|
|
|
599
558
|
function formatPreloadArgs(remotes, preloadArgs) {
|
|
600
559
|
return preloadArgs.map((args)=>{
|
|
601
560
|
const remoteInfo = matchRemote(remotes, args.nameOrAlias);
|
|
602
|
-
share.assert(remoteInfo, `Unable to preload ${args.nameOrAlias} as it is not included in ${!remoteInfo &&
|
|
561
|
+
share.assert(remoteInfo, `Unable to preload ${args.nameOrAlias} as it is not included in ${!remoteInfo && sdk.safeToString({
|
|
603
562
|
remoteInfo,
|
|
604
563
|
remotes
|
|
605
564
|
})}`);
|
|
@@ -745,27 +704,13 @@ useLinkPreload = true) {
|
|
|
745
704
|
}
|
|
746
705
|
}
|
|
747
706
|
|
|
748
|
-
function _extends$4() {
|
|
749
|
-
_extends$4 = Object.assign || function(target) {
|
|
750
|
-
for(var i = 1; i < arguments.length; i++){
|
|
751
|
-
var source = arguments[i];
|
|
752
|
-
for(var key in source){
|
|
753
|
-
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
754
|
-
target[key] = source[key];
|
|
755
|
-
}
|
|
756
|
-
}
|
|
757
|
-
}
|
|
758
|
-
return target;
|
|
759
|
-
};
|
|
760
|
-
return _extends$4.apply(this, arguments);
|
|
761
|
-
}
|
|
762
707
|
function assignRemoteInfo(remoteInfo, remoteSnapshot) {
|
|
763
708
|
const remoteEntryInfo = share.getRemoteEntryInfoFromSnapshot(remoteSnapshot);
|
|
764
709
|
if (!remoteEntryInfo.url) {
|
|
765
710
|
share.error(`The attribute remoteEntry of ${remoteInfo.name} must not be undefined.`);
|
|
766
711
|
}
|
|
767
712
|
let entryUrl = sdk.getResourceUrl(remoteSnapshot, remoteEntryInfo.url);
|
|
768
|
-
if (!
|
|
713
|
+
if (!sdk.isBrowserEnv() && !entryUrl.startsWith('http')) {
|
|
769
714
|
entryUrl = `https:${entryUrl}`;
|
|
770
715
|
}
|
|
771
716
|
remoteInfo.type = remoteEntryInfo.type;
|
|
@@ -806,7 +751,7 @@ function snapshotPlugin() {
|
|
|
806
751
|
if (assets) {
|
|
807
752
|
preloadAssets(remoteInfo, origin, assets, false);
|
|
808
753
|
}
|
|
809
|
-
return _extends
|
|
754
|
+
return polyfills._extends({}, args, {
|
|
810
755
|
remoteSnapshot
|
|
811
756
|
});
|
|
812
757
|
}
|
|
@@ -1027,20 +972,6 @@ const generatePreloadAssetsPlugin = function() {
|
|
|
1027
972
|
};
|
|
1028
973
|
};
|
|
1029
974
|
|
|
1030
|
-
function _extends$3() {
|
|
1031
|
-
_extends$3 = Object.assign || function(target) {
|
|
1032
|
-
for(var i = 1; i < arguments.length; i++){
|
|
1033
|
-
var source = arguments[i];
|
|
1034
|
-
for(var key in source){
|
|
1035
|
-
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
1036
|
-
target[key] = source[key];
|
|
1037
|
-
}
|
|
1038
|
-
}
|
|
1039
|
-
}
|
|
1040
|
-
return target;
|
|
1041
|
-
};
|
|
1042
|
-
return _extends$3.apply(this, arguments);
|
|
1043
|
-
}
|
|
1044
975
|
function getGlobalRemoteInfo(moduleInfo, origin) {
|
|
1045
976
|
const hostGlobalSnapshot = share.getGlobalSnapshotInfoByModuleInfo({
|
|
1046
977
|
name: origin.options.name,
|
|
@@ -1108,7 +1039,7 @@ class SnapshotHandler {
|
|
|
1108
1039
|
// This ensures the snapshot's integrity and helps the chrome plugin correctly identify all producer modules, ensuring that proxyable producer modules will not be missing.
|
|
1109
1040
|
if (hostSnapshot && 'remotesInfo' in hostSnapshot && !share.getInfoWithoutType(hostSnapshot.remotesInfo, moduleInfo.name).value) {
|
|
1110
1041
|
if ('version' in moduleInfo || 'entry' in moduleInfo) {
|
|
1111
|
-
hostSnapshot.remotesInfo = _extends
|
|
1042
|
+
hostSnapshot.remotesInfo = polyfills._extends({}, hostSnapshot == null ? void 0 : hostSnapshot.remotesInfo, {
|
|
1112
1043
|
[moduleInfo.name]: {
|
|
1113
1044
|
matchedVersion: 'version' in moduleInfo ? moduleInfo.version : moduleInfo.entry
|
|
1114
1045
|
}
|
|
@@ -1126,10 +1057,10 @@ class SnapshotHandler {
|
|
|
1126
1057
|
// global snapshot includes manifest or module info includes manifest
|
|
1127
1058
|
if (globalRemoteSnapshot) {
|
|
1128
1059
|
if (sdk.isManifestProvider(globalRemoteSnapshot)) {
|
|
1129
|
-
const remoteEntry =
|
|
1060
|
+
const remoteEntry = sdk.isBrowserEnv() ? globalRemoteSnapshot.remoteEntry : globalRemoteSnapshot.ssrRemoteEntry || globalRemoteSnapshot.remoteEntry || '';
|
|
1130
1061
|
const moduleSnapshot = await this.getManifestJson(remoteEntry, moduleInfo, {});
|
|
1131
1062
|
// eslint-disable-next-line @typescript-eslint/no-shadow
|
|
1132
|
-
const globalSnapshotRes = share.setGlobalSnapshotInfoByModuleInfo(_extends
|
|
1063
|
+
const globalSnapshotRes = share.setGlobalSnapshotInfoByModuleInfo(polyfills._extends({}, moduleInfo, {
|
|
1133
1064
|
// The global remote may be overridden
|
|
1134
1065
|
// Therefore, set the snapshot key to the global address of the actual request
|
|
1135
1066
|
entry: remoteEntry
|
|
@@ -1235,32 +1166,6 @@ class SnapshotHandler {
|
|
|
1235
1166
|
}
|
|
1236
1167
|
}
|
|
1237
1168
|
|
|
1238
|
-
function _extends$2() {
|
|
1239
|
-
_extends$2 = Object.assign || function(target) {
|
|
1240
|
-
for(var i = 1; i < arguments.length; i++){
|
|
1241
|
-
var source = arguments[i];
|
|
1242
|
-
for(var key in source){
|
|
1243
|
-
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
1244
|
-
target[key] = source[key];
|
|
1245
|
-
}
|
|
1246
|
-
}
|
|
1247
|
-
}
|
|
1248
|
-
return target;
|
|
1249
|
-
};
|
|
1250
|
-
return _extends$2.apply(this, arguments);
|
|
1251
|
-
}
|
|
1252
|
-
function _object_without_properties_loose(source, excluded) {
|
|
1253
|
-
if (source == null) return {};
|
|
1254
|
-
var target = {};
|
|
1255
|
-
var sourceKeys = Object.keys(source);
|
|
1256
|
-
var key, i;
|
|
1257
|
-
for(i = 0; i < sourceKeys.length; i++){
|
|
1258
|
-
key = sourceKeys[i];
|
|
1259
|
-
if (excluded.indexOf(key) >= 0) continue;
|
|
1260
|
-
target[key] = source[key];
|
|
1261
|
-
}
|
|
1262
|
-
return target;
|
|
1263
|
-
}
|
|
1264
1169
|
class SharedHandler {
|
|
1265
1170
|
// register shared in shareScopeMap
|
|
1266
1171
|
registerShared(globalOptions, userOptions) {
|
|
@@ -1552,7 +1457,7 @@ class SharedHandler {
|
|
|
1552
1457
|
});
|
|
1553
1458
|
}
|
|
1554
1459
|
setShared({ pkgName, shared, from, lib, loading, loaded, get }) {
|
|
1555
|
-
const { version, scope = 'default' } = shared, shareInfo = _object_without_properties_loose(shared, [
|
|
1460
|
+
const { version, scope = 'default' } = shared, shareInfo = polyfills._object_without_properties_loose(shared, [
|
|
1556
1461
|
"version",
|
|
1557
1462
|
"scope"
|
|
1558
1463
|
]);
|
|
@@ -1569,7 +1474,7 @@ class SharedHandler {
|
|
|
1569
1474
|
if (this.shareScopeMap[sc][pkgName][version]) {
|
|
1570
1475
|
return;
|
|
1571
1476
|
}
|
|
1572
|
-
this.shareScopeMap[sc][pkgName][version] = _extends
|
|
1477
|
+
this.shareScopeMap[sc][pkgName][version] = polyfills._extends({
|
|
1573
1478
|
version,
|
|
1574
1479
|
scope: [
|
|
1575
1480
|
'default'
|
|
@@ -1608,20 +1513,6 @@ class SharedHandler {
|
|
|
1608
1513
|
}
|
|
1609
1514
|
}
|
|
1610
1515
|
|
|
1611
|
-
function _extends$1() {
|
|
1612
|
-
_extends$1 = Object.assign || function(target) {
|
|
1613
|
-
for(var i = 1; i < arguments.length; i++){
|
|
1614
|
-
var source = arguments[i];
|
|
1615
|
-
for(var key in source){
|
|
1616
|
-
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
1617
|
-
target[key] = source[key];
|
|
1618
|
-
}
|
|
1619
|
-
}
|
|
1620
|
-
}
|
|
1621
|
-
return target;
|
|
1622
|
-
};
|
|
1623
|
-
return _extends$1.apply(this, arguments);
|
|
1624
|
-
}
|
|
1625
1516
|
class RemoteHandler {
|
|
1626
1517
|
formatAndRegisterRemote(globalOptions, userOptions) {
|
|
1627
1518
|
const userRemotes = userOptions.remotes || [];
|
|
@@ -1778,7 +1669,7 @@ class RemoteHandler {
|
|
|
1778
1669
|
`);
|
|
1779
1670
|
const { remote: rawRemote } = remoteSplitInfo;
|
|
1780
1671
|
const remoteInfo = getRemoteInfo(rawRemote);
|
|
1781
|
-
const matchInfo = await host.sharedHandler.hooks.lifecycle.afterResolve.emit(_extends
|
|
1672
|
+
const matchInfo = await host.sharedHandler.hooks.lifecycle.afterResolve.emit(polyfills._extends({
|
|
1782
1673
|
id: idRes
|
|
1783
1674
|
}, remoteSplitInfo, {
|
|
1784
1675
|
options: host.options,
|
|
@@ -1947,7 +1838,8 @@ class RemoteHandler {
|
|
|
1947
1838
|
const remoteKey = hostGlobalSnapshot && 'remotesInfo' in hostGlobalSnapshot && hostGlobalSnapshot.remotesInfo && share.getInfoWithoutType(hostGlobalSnapshot.remotesInfo, remote.name).key;
|
|
1948
1839
|
if (remoteKey) {
|
|
1949
1840
|
delete hostGlobalSnapshot.remotesInfo[remoteKey];
|
|
1950
|
-
if (
|
|
1841
|
+
if (//eslint-disable-next-line no-extra-boolean-cast
|
|
1842
|
+
Boolean(share.Global.__FEDERATION__.__MANIFEST_LOADING__[remoteKey])) {
|
|
1951
1843
|
delete share.Global.__FEDERATION__.__MANIFEST_LOADING__[remoteKey];
|
|
1952
1844
|
}
|
|
1953
1845
|
}
|
|
@@ -1977,20 +1869,6 @@ class RemoteHandler {
|
|
|
1977
1869
|
}
|
|
1978
1870
|
}
|
|
1979
1871
|
|
|
1980
|
-
function _extends() {
|
|
1981
|
-
_extends = Object.assign || function(target) {
|
|
1982
|
-
for(var i = 1; i < arguments.length; i++){
|
|
1983
|
-
var source = arguments[i];
|
|
1984
|
-
for(var key in source){
|
|
1985
|
-
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
1986
|
-
target[key] = source[key];
|
|
1987
|
-
}
|
|
1988
|
-
}
|
|
1989
|
-
}
|
|
1990
|
-
return target;
|
|
1991
|
-
};
|
|
1992
|
-
return _extends.apply(this, arguments);
|
|
1993
|
-
}
|
|
1994
1872
|
class FederationHost {
|
|
1995
1873
|
initOptions(userOptions) {
|
|
1996
1874
|
this.registerPlugins(userOptions.plugins);
|
|
@@ -2056,7 +1934,7 @@ class FederationHost {
|
|
|
2056
1934
|
}
|
|
2057
1935
|
});
|
|
2058
1936
|
}
|
|
2059
|
-
const optionsRes = _extends({}, globalOptions, userOptions, {
|
|
1937
|
+
const optionsRes = polyfills._extends({}, globalOptions, userOptions, {
|
|
2060
1938
|
plugins,
|
|
2061
1939
|
remotes,
|
|
2062
1940
|
shared: handledShared
|
|
@@ -2096,7 +1974,7 @@ class FederationHost {
|
|
|
2096
1974
|
// maybe will change, temporarily for internal use only
|
|
2097
1975
|
initContainer: new AsyncWaterfallHook('initContainer')
|
|
2098
1976
|
});
|
|
2099
|
-
this.version = "0.6.
|
|
1977
|
+
this.version = "0.6.1";
|
|
2100
1978
|
this.moduleCache = new Map();
|
|
2101
1979
|
this.loaderHook = new PluginSystem({
|
|
2102
1980
|
// FIXME: may not be suitable , not open to the public yet
|
|
@@ -2117,7 +1995,7 @@ class FederationHost {
|
|
|
2117
1995
|
],
|
|
2118
1996
|
remotes: [],
|
|
2119
1997
|
shared: {},
|
|
2120
|
-
inBrowser:
|
|
1998
|
+
inBrowser: sdk.isBrowserEnv()
|
|
2121
1999
|
};
|
|
2122
2000
|
this.name = userOptions.name;
|
|
2123
2001
|
this.options = defaultOptions;
|
|
@@ -2191,7 +2069,6 @@ function getInstance() {
|
|
|
2191
2069
|
// Inject for debug
|
|
2192
2070
|
share.setGlobalFederationConstructor(FederationHost);
|
|
2193
2071
|
|
|
2194
|
-
exports.registerGlobalPlugins = share.registerGlobalPlugins;
|
|
2195
2072
|
Object.defineProperty(exports, 'loadScript', {
|
|
2196
2073
|
enumerable: true,
|
|
2197
2074
|
get: function () { return sdk.loadScript; }
|
|
@@ -2200,6 +2077,7 @@ Object.defineProperty(exports, 'loadScriptNode', {
|
|
|
2200
2077
|
enumerable: true,
|
|
2201
2078
|
get: function () { return sdk.loadScriptNode; }
|
|
2202
2079
|
});
|
|
2080
|
+
exports.registerGlobalPlugins = share.registerGlobalPlugins;
|
|
2203
2081
|
exports.FederationHost = FederationHost;
|
|
2204
2082
|
exports.getInstance = getInstance;
|
|
2205
2083
|
exports.getRemoteEntry = getRemoteEntry;
|
package/dist/index.esm.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
import { isBrowserEnv, loadScriptNode, composeKeyWithSeparator, loadScript, createLink, createScript, getResourceUrl, isManifestProvider, generateSnapshotFromManifest, warn as warn$1 } from '@module-federation/sdk';
|
|
1
|
+
import { _ as _extends, a as _object_without_properties_loose } from './polyfills.esm.js';
|
|
2
|
+
import { isBrowserEnv, loadScriptNode, composeKeyWithSeparator, loadScript, safeToString, createLink, createScript, getResourceUrl, isManifestProvider, generateSnapshotFromManifest, warn as warn$1 } from '@module-federation/sdk';
|
|
4
3
|
export { loadScript, loadScriptNode } from '@module-federation/sdk';
|
|
4
|
+
import { g as getGlobalHostPlugins, a as globalLoading, D as DEFAULT_REMOTE_TYPE, b as DEFAULT_SCOPE, c as getRemoteEntryExports, d as assert, e as getFMId, i as isObject, f as error, w as warn, h as isPlainObject, j as isRemoteInfoWithEntry, k as isPureRemoteEntry, l as getRemoteEntryInfoFromSnapshot, m as getInfoWithoutType, n as getPreloaded, s as setPreloaded, o as getRegisteredShare, p as arrayOptions, q as getGlobalSnapshotInfoByModuleInfo, r as addGlobalSnapshot, t as setGlobalSnapshotInfoByModuleInfo, G as Global, u as getGlobalSnapshot, v as formatShareConfigs, x as getTargetSharedOptions, y as getGlobalShareScope, z as addUniqueItem, A as getBuilderId, B as setGlobalFederationConstructor, C as getGlobalFederationInstance, E as getGlobalFederationConstructor, F as setGlobalFederationInstance } from './share.esm.js';
|
|
5
|
+
export { H as registerGlobalPlugins } from './share.esm.js';
|
|
5
6
|
|
|
6
7
|
// Function to match a remote with its name and expose
|
|
7
8
|
// id: pkgName(@federation/app1) + expose(button) = @federation/app1/button
|
|
@@ -87,20 +88,6 @@ function registerPlugins$1(plugins, hookInstances) {
|
|
|
87
88
|
return plugins;
|
|
88
89
|
}
|
|
89
90
|
|
|
90
|
-
function _extends$7() {
|
|
91
|
-
_extends$7 = Object.assign || function(target) {
|
|
92
|
-
for(var i = 1; i < arguments.length; i++){
|
|
93
|
-
var source = arguments[i];
|
|
94
|
-
for(var key in source){
|
|
95
|
-
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
96
|
-
target[key] = source[key];
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
return target;
|
|
101
|
-
};
|
|
102
|
-
return _extends$7.apply(this, arguments);
|
|
103
|
-
}
|
|
104
91
|
async function loadEsmEntry({ entry, remoteEntryExports }) {
|
|
105
92
|
return new Promise((resolve, reject)=>{
|
|
106
93
|
try {
|
|
@@ -263,7 +250,7 @@ async function getRemoteEntry({ origin, remoteEntryExports, remoteInfo }) {
|
|
|
263
250
|
return globalLoading[uniqueKey];
|
|
264
251
|
}
|
|
265
252
|
function getRemoteInfo(remote) {
|
|
266
|
-
return _extends
|
|
253
|
+
return _extends({}, remote, {
|
|
267
254
|
entry: 'entry' in remote ? remote.entry : '',
|
|
268
255
|
type: remote.type || DEFAULT_REMOTE_TYPE,
|
|
269
256
|
entryGlobalName: remote.entryGlobalName || remote.name,
|
|
@@ -271,20 +258,6 @@ function getRemoteInfo(remote) {
|
|
|
271
258
|
});
|
|
272
259
|
}
|
|
273
260
|
|
|
274
|
-
function _extends$6() {
|
|
275
|
-
_extends$6 = Object.assign || function(target) {
|
|
276
|
-
for(var i = 1; i < arguments.length; i++){
|
|
277
|
-
var source = arguments[i];
|
|
278
|
-
for(var key in source){
|
|
279
|
-
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
280
|
-
target[key] = source[key];
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
return target;
|
|
285
|
-
};
|
|
286
|
-
return _extends$6.apply(this, arguments);
|
|
287
|
-
}
|
|
288
261
|
let Module = class Module {
|
|
289
262
|
async getEntry() {
|
|
290
263
|
if (this.remoteEntryExports) {
|
|
@@ -336,7 +309,7 @@ let Module = class Module {
|
|
|
336
309
|
console.error('The remote entry interface does not contain "init"', '\n', 'Ensure the name of this remote is not reserved or in use. Check if anything already exists on window[nameOfRemote]', '\n', 'Ensure that window[nameOfRemote] is returning a {get,init} object.');
|
|
337
310
|
}
|
|
338
311
|
await remoteEntryExports.init(initContainerOptions.shareScope, initContainerOptions.initScope, initContainerOptions.remoteEntryInitOptions);
|
|
339
|
-
await this.host.hooks.lifecycle.initContainer.emit(_extends
|
|
312
|
+
await this.host.hooks.lifecycle.initContainer.emit(_extends({}, initContainerOptions, {
|
|
340
313
|
remoteEntryExports
|
|
341
314
|
}));
|
|
342
315
|
}
|
|
@@ -572,22 +545,8 @@ class PluginSystem {
|
|
|
572
545
|
}
|
|
573
546
|
}
|
|
574
547
|
|
|
575
|
-
function _extends$5() {
|
|
576
|
-
_extends$5 = Object.assign || function(target) {
|
|
577
|
-
for(var i = 1; i < arguments.length; i++){
|
|
578
|
-
var source = arguments[i];
|
|
579
|
-
for(var key in source){
|
|
580
|
-
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
581
|
-
target[key] = source[key];
|
|
582
|
-
}
|
|
583
|
-
}
|
|
584
|
-
}
|
|
585
|
-
return target;
|
|
586
|
-
};
|
|
587
|
-
return _extends$5.apply(this, arguments);
|
|
588
|
-
}
|
|
589
548
|
function defaultPreloadArgs(preloadConfig) {
|
|
590
|
-
return _extends
|
|
549
|
+
return _extends({
|
|
591
550
|
resourceCategory: 'sync',
|
|
592
551
|
share: true,
|
|
593
552
|
depsRemote: true,
|
|
@@ -743,27 +702,13 @@ useLinkPreload = true) {
|
|
|
743
702
|
}
|
|
744
703
|
}
|
|
745
704
|
|
|
746
|
-
function _extends$4() {
|
|
747
|
-
_extends$4 = Object.assign || function(target) {
|
|
748
|
-
for(var i = 1; i < arguments.length; i++){
|
|
749
|
-
var source = arguments[i];
|
|
750
|
-
for(var key in source){
|
|
751
|
-
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
752
|
-
target[key] = source[key];
|
|
753
|
-
}
|
|
754
|
-
}
|
|
755
|
-
}
|
|
756
|
-
return target;
|
|
757
|
-
};
|
|
758
|
-
return _extends$4.apply(this, arguments);
|
|
759
|
-
}
|
|
760
705
|
function assignRemoteInfo(remoteInfo, remoteSnapshot) {
|
|
761
706
|
const remoteEntryInfo = getRemoteEntryInfoFromSnapshot(remoteSnapshot);
|
|
762
707
|
if (!remoteEntryInfo.url) {
|
|
763
708
|
error(`The attribute remoteEntry of ${remoteInfo.name} must not be undefined.`);
|
|
764
709
|
}
|
|
765
710
|
let entryUrl = getResourceUrl(remoteSnapshot, remoteEntryInfo.url);
|
|
766
|
-
if (!isBrowserEnv
|
|
711
|
+
if (!isBrowserEnv() && !entryUrl.startsWith('http')) {
|
|
767
712
|
entryUrl = `https:${entryUrl}`;
|
|
768
713
|
}
|
|
769
714
|
remoteInfo.type = remoteEntryInfo.type;
|
|
@@ -804,7 +749,7 @@ function snapshotPlugin() {
|
|
|
804
749
|
if (assets) {
|
|
805
750
|
preloadAssets(remoteInfo, origin, assets, false);
|
|
806
751
|
}
|
|
807
|
-
return _extends
|
|
752
|
+
return _extends({}, args, {
|
|
808
753
|
remoteSnapshot
|
|
809
754
|
});
|
|
810
755
|
}
|
|
@@ -1025,20 +970,6 @@ const generatePreloadAssetsPlugin = function() {
|
|
|
1025
970
|
};
|
|
1026
971
|
};
|
|
1027
972
|
|
|
1028
|
-
function _extends$3() {
|
|
1029
|
-
_extends$3 = Object.assign || function(target) {
|
|
1030
|
-
for(var i = 1; i < arguments.length; i++){
|
|
1031
|
-
var source = arguments[i];
|
|
1032
|
-
for(var key in source){
|
|
1033
|
-
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
1034
|
-
target[key] = source[key];
|
|
1035
|
-
}
|
|
1036
|
-
}
|
|
1037
|
-
}
|
|
1038
|
-
return target;
|
|
1039
|
-
};
|
|
1040
|
-
return _extends$3.apply(this, arguments);
|
|
1041
|
-
}
|
|
1042
973
|
function getGlobalRemoteInfo(moduleInfo, origin) {
|
|
1043
974
|
const hostGlobalSnapshot = getGlobalSnapshotInfoByModuleInfo({
|
|
1044
975
|
name: origin.options.name,
|
|
@@ -1106,7 +1037,7 @@ class SnapshotHandler {
|
|
|
1106
1037
|
// This ensures the snapshot's integrity and helps the chrome plugin correctly identify all producer modules, ensuring that proxyable producer modules will not be missing.
|
|
1107
1038
|
if (hostSnapshot && 'remotesInfo' in hostSnapshot && !getInfoWithoutType(hostSnapshot.remotesInfo, moduleInfo.name).value) {
|
|
1108
1039
|
if ('version' in moduleInfo || 'entry' in moduleInfo) {
|
|
1109
|
-
hostSnapshot.remotesInfo = _extends
|
|
1040
|
+
hostSnapshot.remotesInfo = _extends({}, hostSnapshot == null ? void 0 : hostSnapshot.remotesInfo, {
|
|
1110
1041
|
[moduleInfo.name]: {
|
|
1111
1042
|
matchedVersion: 'version' in moduleInfo ? moduleInfo.version : moduleInfo.entry
|
|
1112
1043
|
}
|
|
@@ -1124,10 +1055,10 @@ class SnapshotHandler {
|
|
|
1124
1055
|
// global snapshot includes manifest or module info includes manifest
|
|
1125
1056
|
if (globalRemoteSnapshot) {
|
|
1126
1057
|
if (isManifestProvider(globalRemoteSnapshot)) {
|
|
1127
|
-
const remoteEntry = isBrowserEnv
|
|
1058
|
+
const remoteEntry = isBrowserEnv() ? globalRemoteSnapshot.remoteEntry : globalRemoteSnapshot.ssrRemoteEntry || globalRemoteSnapshot.remoteEntry || '';
|
|
1128
1059
|
const moduleSnapshot = await this.getManifestJson(remoteEntry, moduleInfo, {});
|
|
1129
1060
|
// eslint-disable-next-line @typescript-eslint/no-shadow
|
|
1130
|
-
const globalSnapshotRes = setGlobalSnapshotInfoByModuleInfo(_extends
|
|
1061
|
+
const globalSnapshotRes = setGlobalSnapshotInfoByModuleInfo(_extends({}, moduleInfo, {
|
|
1131
1062
|
// The global remote may be overridden
|
|
1132
1063
|
// Therefore, set the snapshot key to the global address of the actual request
|
|
1133
1064
|
entry: remoteEntry
|
|
@@ -1233,32 +1164,6 @@ class SnapshotHandler {
|
|
|
1233
1164
|
}
|
|
1234
1165
|
}
|
|
1235
1166
|
|
|
1236
|
-
function _extends$2() {
|
|
1237
|
-
_extends$2 = Object.assign || function(target) {
|
|
1238
|
-
for(var i = 1; i < arguments.length; i++){
|
|
1239
|
-
var source = arguments[i];
|
|
1240
|
-
for(var key in source){
|
|
1241
|
-
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
1242
|
-
target[key] = source[key];
|
|
1243
|
-
}
|
|
1244
|
-
}
|
|
1245
|
-
}
|
|
1246
|
-
return target;
|
|
1247
|
-
};
|
|
1248
|
-
return _extends$2.apply(this, arguments);
|
|
1249
|
-
}
|
|
1250
|
-
function _object_without_properties_loose(source, excluded) {
|
|
1251
|
-
if (source == null) return {};
|
|
1252
|
-
var target = {};
|
|
1253
|
-
var sourceKeys = Object.keys(source);
|
|
1254
|
-
var key, i;
|
|
1255
|
-
for(i = 0; i < sourceKeys.length; i++){
|
|
1256
|
-
key = sourceKeys[i];
|
|
1257
|
-
if (excluded.indexOf(key) >= 0) continue;
|
|
1258
|
-
target[key] = source[key];
|
|
1259
|
-
}
|
|
1260
|
-
return target;
|
|
1261
|
-
}
|
|
1262
1167
|
class SharedHandler {
|
|
1263
1168
|
// register shared in shareScopeMap
|
|
1264
1169
|
registerShared(globalOptions, userOptions) {
|
|
@@ -1567,7 +1472,7 @@ class SharedHandler {
|
|
|
1567
1472
|
if (this.shareScopeMap[sc][pkgName][version]) {
|
|
1568
1473
|
return;
|
|
1569
1474
|
}
|
|
1570
|
-
this.shareScopeMap[sc][pkgName][version] = _extends
|
|
1475
|
+
this.shareScopeMap[sc][pkgName][version] = _extends({
|
|
1571
1476
|
version,
|
|
1572
1477
|
scope: [
|
|
1573
1478
|
'default'
|
|
@@ -1606,20 +1511,6 @@ class SharedHandler {
|
|
|
1606
1511
|
}
|
|
1607
1512
|
}
|
|
1608
1513
|
|
|
1609
|
-
function _extends$1() {
|
|
1610
|
-
_extends$1 = Object.assign || function(target) {
|
|
1611
|
-
for(var i = 1; i < arguments.length; i++){
|
|
1612
|
-
var source = arguments[i];
|
|
1613
|
-
for(var key in source){
|
|
1614
|
-
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
1615
|
-
target[key] = source[key];
|
|
1616
|
-
}
|
|
1617
|
-
}
|
|
1618
|
-
}
|
|
1619
|
-
return target;
|
|
1620
|
-
};
|
|
1621
|
-
return _extends$1.apply(this, arguments);
|
|
1622
|
-
}
|
|
1623
1514
|
class RemoteHandler {
|
|
1624
1515
|
formatAndRegisterRemote(globalOptions, userOptions) {
|
|
1625
1516
|
const userRemotes = userOptions.remotes || [];
|
|
@@ -1776,7 +1667,7 @@ class RemoteHandler {
|
|
|
1776
1667
|
`);
|
|
1777
1668
|
const { remote: rawRemote } = remoteSplitInfo;
|
|
1778
1669
|
const remoteInfo = getRemoteInfo(rawRemote);
|
|
1779
|
-
const matchInfo = await host.sharedHandler.hooks.lifecycle.afterResolve.emit(_extends
|
|
1670
|
+
const matchInfo = await host.sharedHandler.hooks.lifecycle.afterResolve.emit(_extends({
|
|
1780
1671
|
id: idRes
|
|
1781
1672
|
}, remoteSplitInfo, {
|
|
1782
1673
|
options: host.options,
|
|
@@ -1945,7 +1836,8 @@ class RemoteHandler {
|
|
|
1945
1836
|
const remoteKey = hostGlobalSnapshot && 'remotesInfo' in hostGlobalSnapshot && hostGlobalSnapshot.remotesInfo && getInfoWithoutType(hostGlobalSnapshot.remotesInfo, remote.name).key;
|
|
1946
1837
|
if (remoteKey) {
|
|
1947
1838
|
delete hostGlobalSnapshot.remotesInfo[remoteKey];
|
|
1948
|
-
if (
|
|
1839
|
+
if (//eslint-disable-next-line no-extra-boolean-cast
|
|
1840
|
+
Boolean(Global.__FEDERATION__.__MANIFEST_LOADING__[remoteKey])) {
|
|
1949
1841
|
delete Global.__FEDERATION__.__MANIFEST_LOADING__[remoteKey];
|
|
1950
1842
|
}
|
|
1951
1843
|
}
|
|
@@ -1975,20 +1867,6 @@ class RemoteHandler {
|
|
|
1975
1867
|
}
|
|
1976
1868
|
}
|
|
1977
1869
|
|
|
1978
|
-
function _extends() {
|
|
1979
|
-
_extends = Object.assign || function(target) {
|
|
1980
|
-
for(var i = 1; i < arguments.length; i++){
|
|
1981
|
-
var source = arguments[i];
|
|
1982
|
-
for(var key in source){
|
|
1983
|
-
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
1984
|
-
target[key] = source[key];
|
|
1985
|
-
}
|
|
1986
|
-
}
|
|
1987
|
-
}
|
|
1988
|
-
return target;
|
|
1989
|
-
};
|
|
1990
|
-
return _extends.apply(this, arguments);
|
|
1991
|
-
}
|
|
1992
1870
|
class FederationHost {
|
|
1993
1871
|
initOptions(userOptions) {
|
|
1994
1872
|
this.registerPlugins(userOptions.plugins);
|
|
@@ -2094,7 +1972,7 @@ class FederationHost {
|
|
|
2094
1972
|
// maybe will change, temporarily for internal use only
|
|
2095
1973
|
initContainer: new AsyncWaterfallHook('initContainer')
|
|
2096
1974
|
});
|
|
2097
|
-
this.version = "0.6.
|
|
1975
|
+
this.version = "0.6.1";
|
|
2098
1976
|
this.moduleCache = new Map();
|
|
2099
1977
|
this.loaderHook = new PluginSystem({
|
|
2100
1978
|
// FIXME: may not be suitable , not open to the public yet
|
|
@@ -2115,7 +1993,7 @@ class FederationHost {
|
|
|
2115
1993
|
],
|
|
2116
1994
|
remotes: [],
|
|
2117
1995
|
shared: {},
|
|
2118
|
-
inBrowser: isBrowserEnv
|
|
1996
|
+
inBrowser: isBrowserEnv()
|
|
2119
1997
|
};
|
|
2120
1998
|
this.name = userOptions.name;
|
|
2121
1999
|
this.options = defaultOptions;
|
package/dist/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@module-federation/runtime",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.1",
|
|
4
4
|
"author": "zhouxiao <codingzx@gmail.com>",
|
|
5
5
|
"main": "./index.cjs.js",
|
|
6
6
|
"module": "./index.esm.js",
|
|
@@ -29,10 +29,10 @@
|
|
|
29
29
|
"import": "./dist/types.esm.js",
|
|
30
30
|
"require": "./dist/types.cjs.js"
|
|
31
31
|
},
|
|
32
|
-
"./
|
|
33
|
-
"types": "./dist/
|
|
34
|
-
"import": "./dist/
|
|
35
|
-
"require": "./dist/
|
|
32
|
+
"./embedded": {
|
|
33
|
+
"types": "./dist/embedded.cjs.d.ts",
|
|
34
|
+
"import": "./dist/embedded.esm.js",
|
|
35
|
+
"require": "./dist/embedded.cjs.js"
|
|
36
36
|
},
|
|
37
37
|
"./*": "./*"
|
|
38
38
|
},
|
|
@@ -46,9 +46,6 @@
|
|
|
46
46
|
],
|
|
47
47
|
"types": [
|
|
48
48
|
"./dist/types.cjs.d.ts"
|
|
49
|
-
],
|
|
50
|
-
"retry-plugin": [
|
|
51
|
-
"./dist/retry-plugin.cjs.d.ts"
|
|
52
49
|
]
|
|
53
50
|
}
|
|
54
51
|
},
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
function _extends() {
|
|
4
|
+
_extends = Object.assign || function assign(target) {
|
|
5
|
+
for(var i = 1; i < arguments.length; i++){
|
|
6
|
+
var source = arguments[i];
|
|
7
|
+
for(var key in source)if (Object.prototype.hasOwnProperty.call(source, key)) target[key] = source[key];
|
|
8
|
+
}
|
|
9
|
+
return target;
|
|
10
|
+
};
|
|
11
|
+
return _extends.apply(this, arguments);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function _object_without_properties_loose(source, excluded) {
|
|
15
|
+
if (source == null) return {};
|
|
16
|
+
var target = {};
|
|
17
|
+
var sourceKeys = Object.keys(source);
|
|
18
|
+
var key, i;
|
|
19
|
+
for(i = 0; i < sourceKeys.length; i++){
|
|
20
|
+
key = sourceKeys[i];
|
|
21
|
+
if (excluded.indexOf(key) >= 0) continue;
|
|
22
|
+
target[key] = source[key];
|
|
23
|
+
}
|
|
24
|
+
return target;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
exports._extends = _extends;
|
|
28
|
+
exports._object_without_properties_loose = _object_without_properties_loose;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
function _extends() {
|
|
2
|
+
_extends = Object.assign || function assign(target) {
|
|
3
|
+
for(var i = 1; i < arguments.length; i++){
|
|
4
|
+
var source = arguments[i];
|
|
5
|
+
for(var key in source)if (Object.prototype.hasOwnProperty.call(source, key)) target[key] = source[key];
|
|
6
|
+
}
|
|
7
|
+
return target;
|
|
8
|
+
};
|
|
9
|
+
return _extends.apply(this, arguments);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function _object_without_properties_loose(source, excluded) {
|
|
13
|
+
if (source == null) return {};
|
|
14
|
+
var target = {};
|
|
15
|
+
var sourceKeys = Object.keys(source);
|
|
16
|
+
var key, i;
|
|
17
|
+
for(i = 0; i < sourceKeys.length; i++){
|
|
18
|
+
key = sourceKeys[i];
|
|
19
|
+
if (excluded.indexOf(key) >= 0) continue;
|
|
20
|
+
target[key] = source[key];
|
|
21
|
+
}
|
|
22
|
+
return target;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export { _extends as _, _object_without_properties_loose as a };
|
package/dist/share.cjs.js
CHANGED
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var polyfills = require('./polyfills.cjs.js');
|
|
4
|
+
var sdk = require('@module-federation/sdk');
|
|
5
|
+
|
|
3
6
|
function getBuilderId() {
|
|
4
7
|
//@ts-ignore
|
|
5
8
|
return typeof FEDERATION_BUILD_IDENTIFIER !== 'undefined' ? FEDERATION_BUILD_IDENTIFIER : '';
|
|
6
9
|
}
|
|
7
|
-
function isDebugMode() {
|
|
8
|
-
return Boolean("");
|
|
9
|
-
}
|
|
10
|
-
function isBrowserEnv() {
|
|
11
|
-
return typeof window !== 'undefined';
|
|
12
|
-
}
|
|
13
10
|
|
|
14
11
|
const LOG_CATEGORY = '[ Federation Runtime ]';
|
|
15
12
|
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
@@ -55,14 +52,6 @@ function isRemoteInfoWithEntry(remote) {
|
|
|
55
52
|
function isPureRemoteEntry(remote) {
|
|
56
53
|
return !remote.entry.includes('.json') && remote.entry.includes('.js');
|
|
57
54
|
}
|
|
58
|
-
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
59
|
-
function safeToString(info) {
|
|
60
|
-
try {
|
|
61
|
-
return JSON.stringify(info, null, 2);
|
|
62
|
-
} catch (e) {
|
|
63
|
-
return '';
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
55
|
function isObject(val) {
|
|
67
56
|
return val && typeof val === 'object';
|
|
68
57
|
}
|
|
@@ -82,7 +71,7 @@ function getRemoteEntryInfoFromSnapshot(snapshot) {
|
|
|
82
71
|
type: 'global',
|
|
83
72
|
globalName: ''
|
|
84
73
|
};
|
|
85
|
-
if (isBrowserEnv()) {
|
|
74
|
+
if (sdk.isBrowserEnv()) {
|
|
86
75
|
return 'remoteEntry' in snapshot ? {
|
|
87
76
|
url: snapshot.remoteEntry,
|
|
88
77
|
type: snapshot.remoteEntryType,
|
|
@@ -99,32 +88,6 @@ function getRemoteEntryInfoFromSnapshot(snapshot) {
|
|
|
99
88
|
return defaultRemoteEntryInfo;
|
|
100
89
|
}
|
|
101
90
|
|
|
102
|
-
function _extends$1() {
|
|
103
|
-
_extends$1 = Object.assign || function(target) {
|
|
104
|
-
for(var i = 1; i < arguments.length; i++){
|
|
105
|
-
var source = arguments[i];
|
|
106
|
-
for(var key in source){
|
|
107
|
-
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
108
|
-
target[key] = source[key];
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
return target;
|
|
113
|
-
};
|
|
114
|
-
return _extends$1.apply(this, arguments);
|
|
115
|
-
}
|
|
116
|
-
function _object_without_properties_loose(source, excluded) {
|
|
117
|
-
if (source == null) return {};
|
|
118
|
-
var target = {};
|
|
119
|
-
var sourceKeys = Object.keys(source);
|
|
120
|
-
var key, i;
|
|
121
|
-
for(i = 0; i < sourceKeys.length; i++){
|
|
122
|
-
key = sourceKeys[i];
|
|
123
|
-
if (excluded.indexOf(key) >= 0) continue;
|
|
124
|
-
target[key] = source[key];
|
|
125
|
-
}
|
|
126
|
-
return target;
|
|
127
|
-
}
|
|
128
91
|
const nativeGlobal = (()=>{
|
|
129
92
|
try {
|
|
130
93
|
return new Function('return this')();
|
|
@@ -209,10 +172,10 @@ function setGlobalFederationInstance(FederationInstance) {
|
|
|
209
172
|
function getGlobalFederationConstructor() {
|
|
210
173
|
return globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR__;
|
|
211
174
|
}
|
|
212
|
-
function setGlobalFederationConstructor(FederationConstructor, isDebug = isDebugMode()) {
|
|
175
|
+
function setGlobalFederationConstructor(FederationConstructor, isDebug = sdk.isDebugMode()) {
|
|
213
176
|
if (isDebug) {
|
|
214
177
|
globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR__ = FederationConstructor;
|
|
215
|
-
globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = "0.6.
|
|
178
|
+
globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = "0.6.1";
|
|
216
179
|
}
|
|
217
180
|
}
|
|
218
181
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
@@ -260,7 +223,7 @@ const getTargetSnapshotInfoByModuleInfo = (moduleInfo, snapshot)=>{
|
|
|
260
223
|
}
|
|
261
224
|
// If the remote is not included in the hostSnapshot, deploy a micro app snapshot
|
|
262
225
|
if ('version' in moduleInfo && moduleInfo['version']) {
|
|
263
|
-
const { version } = moduleInfo, resModuleInfo = _object_without_properties_loose(moduleInfo, [
|
|
226
|
+
const { version } = moduleInfo, resModuleInfo = polyfills._object_without_properties_loose(moduleInfo, [
|
|
264
227
|
"version"
|
|
265
228
|
]);
|
|
266
229
|
const moduleKeyWithoutVersion = getFMId(resModuleInfo);
|
|
@@ -278,7 +241,7 @@ const setGlobalSnapshotInfoByModuleInfo = (remoteInfo, moduleDetailInfo)=>{
|
|
|
278
241
|
return nativeGlobal.__FEDERATION__.moduleInfo;
|
|
279
242
|
};
|
|
280
243
|
const addGlobalSnapshot = (moduleInfos)=>{
|
|
281
|
-
nativeGlobal.__FEDERATION__.moduleInfo = _extends
|
|
244
|
+
nativeGlobal.__FEDERATION__.moduleInfo = polyfills._extends({}, nativeGlobal.__FEDERATION__.moduleInfo, moduleInfos);
|
|
282
245
|
return ()=>{
|
|
283
246
|
const keys = Object.keys(moduleInfos);
|
|
284
247
|
for (const key of keys){
|
|
@@ -671,20 +634,6 @@ function satisfy(version, range) {
|
|
|
671
634
|
return true;
|
|
672
635
|
}
|
|
673
636
|
|
|
674
|
-
function _extends() {
|
|
675
|
-
_extends = Object.assign || function(target) {
|
|
676
|
-
for(var i = 1; i < arguments.length; i++){
|
|
677
|
-
var source = arguments[i];
|
|
678
|
-
for(var key in source){
|
|
679
|
-
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
680
|
-
target[key] = source[key];
|
|
681
|
-
}
|
|
682
|
-
}
|
|
683
|
-
}
|
|
684
|
-
return target;
|
|
685
|
-
};
|
|
686
|
-
return _extends.apply(this, arguments);
|
|
687
|
-
}
|
|
688
637
|
function formatShare(shareArgs, from, name, shareStrategy) {
|
|
689
638
|
let get;
|
|
690
639
|
if ('get' in shareArgs) {
|
|
@@ -701,13 +650,13 @@ function formatShare(shareArgs, from, name, shareStrategy) {
|
|
|
701
650
|
warn(`"shared.strategy is deprecated, please set in initOptions.shareStrategy instead!"`);
|
|
702
651
|
}
|
|
703
652
|
var _shareArgs_version, _shareArgs_scope, _shareArgs_strategy;
|
|
704
|
-
return _extends({
|
|
653
|
+
return polyfills._extends({
|
|
705
654
|
deps: [],
|
|
706
655
|
useIn: [],
|
|
707
656
|
from,
|
|
708
657
|
loading: null
|
|
709
658
|
}, shareArgs, {
|
|
710
|
-
shareConfig: _extends({
|
|
659
|
+
shareConfig: polyfills._extends({
|
|
711
660
|
requiredVersion: `^${shareArgs.version}`,
|
|
712
661
|
singleton: false,
|
|
713
662
|
eager: false,
|
|
@@ -733,7 +682,7 @@ function formatShareConfigs(globalOptions, userOptions) {
|
|
|
733
682
|
});
|
|
734
683
|
return res;
|
|
735
684
|
}, {});
|
|
736
|
-
const shared = _extends({}, globalOptions.shared);
|
|
685
|
+
const shared = polyfills._extends({}, globalOptions.shared);
|
|
737
686
|
Object.keys(shareInfos).forEach((shareKey)=>{
|
|
738
687
|
if (!shared[shareKey]) {
|
|
739
688
|
shared[shareKey] = shareInfos[shareKey];
|
|
@@ -922,7 +871,6 @@ exports.getRemoteEntryInfoFromSnapshot = getRemoteEntryInfoFromSnapshot;
|
|
|
922
871
|
exports.getTargetSharedOptions = getTargetSharedOptions;
|
|
923
872
|
exports.getTargetSnapshotInfoByModuleInfo = getTargetSnapshotInfoByModuleInfo;
|
|
924
873
|
exports.globalLoading = globalLoading;
|
|
925
|
-
exports.isBrowserEnv = isBrowserEnv;
|
|
926
874
|
exports.isObject = isObject;
|
|
927
875
|
exports.isPlainObject = isPlainObject;
|
|
928
876
|
exports.isPureRemoteEntry = isPureRemoteEntry;
|
|
@@ -930,7 +878,6 @@ exports.isRemoteInfoWithEntry = isRemoteInfoWithEntry;
|
|
|
930
878
|
exports.nativeGlobal = nativeGlobal;
|
|
931
879
|
exports.registerGlobalPlugins = registerGlobalPlugins;
|
|
932
880
|
exports.resetFederationGlobalInfo = resetFederationGlobalInfo;
|
|
933
|
-
exports.safeToString = safeToString;
|
|
934
881
|
exports.setGlobalFederationConstructor = setGlobalFederationConstructor;
|
|
935
882
|
exports.setGlobalFederationInstance = setGlobalFederationInstance;
|
|
936
883
|
exports.setGlobalSnapshotInfoByModuleInfo = setGlobalSnapshotInfoByModuleInfo;
|
package/dist/share.esm.js
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
|
+
import { a as _object_without_properties_loose, _ as _extends } from './polyfills.esm.js';
|
|
2
|
+
import { isBrowserEnv, isDebugMode } from '@module-federation/sdk';
|
|
3
|
+
|
|
1
4
|
function getBuilderId() {
|
|
2
5
|
//@ts-ignore
|
|
3
6
|
return typeof FEDERATION_BUILD_IDENTIFIER !== 'undefined' ? FEDERATION_BUILD_IDENTIFIER : '';
|
|
4
7
|
}
|
|
5
|
-
function isDebugMode() {
|
|
6
|
-
return Boolean("");
|
|
7
|
-
}
|
|
8
|
-
function isBrowserEnv() {
|
|
9
|
-
return typeof window !== 'undefined';
|
|
10
|
-
}
|
|
11
8
|
|
|
12
9
|
const LOG_CATEGORY = '[ Federation Runtime ]';
|
|
13
10
|
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
@@ -53,14 +50,6 @@ function isRemoteInfoWithEntry(remote) {
|
|
|
53
50
|
function isPureRemoteEntry(remote) {
|
|
54
51
|
return !remote.entry.includes('.json') && remote.entry.includes('.js');
|
|
55
52
|
}
|
|
56
|
-
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
57
|
-
function safeToString(info) {
|
|
58
|
-
try {
|
|
59
|
-
return JSON.stringify(info, null, 2);
|
|
60
|
-
} catch (e) {
|
|
61
|
-
return '';
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
53
|
function isObject(val) {
|
|
65
54
|
return val && typeof val === 'object';
|
|
66
55
|
}
|
|
@@ -97,32 +86,6 @@ function getRemoteEntryInfoFromSnapshot(snapshot) {
|
|
|
97
86
|
return defaultRemoteEntryInfo;
|
|
98
87
|
}
|
|
99
88
|
|
|
100
|
-
function _extends$1() {
|
|
101
|
-
_extends$1 = Object.assign || function(target) {
|
|
102
|
-
for(var i = 1; i < arguments.length; i++){
|
|
103
|
-
var source = arguments[i];
|
|
104
|
-
for(var key in source){
|
|
105
|
-
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
106
|
-
target[key] = source[key];
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
return target;
|
|
111
|
-
};
|
|
112
|
-
return _extends$1.apply(this, arguments);
|
|
113
|
-
}
|
|
114
|
-
function _object_without_properties_loose(source, excluded) {
|
|
115
|
-
if (source == null) return {};
|
|
116
|
-
var target = {};
|
|
117
|
-
var sourceKeys = Object.keys(source);
|
|
118
|
-
var key, i;
|
|
119
|
-
for(i = 0; i < sourceKeys.length; i++){
|
|
120
|
-
key = sourceKeys[i];
|
|
121
|
-
if (excluded.indexOf(key) >= 0) continue;
|
|
122
|
-
target[key] = source[key];
|
|
123
|
-
}
|
|
124
|
-
return target;
|
|
125
|
-
}
|
|
126
89
|
const nativeGlobal = (()=>{
|
|
127
90
|
try {
|
|
128
91
|
return new Function('return this')();
|
|
@@ -210,7 +173,7 @@ function getGlobalFederationConstructor() {
|
|
|
210
173
|
function setGlobalFederationConstructor(FederationConstructor, isDebug = isDebugMode()) {
|
|
211
174
|
if (isDebug) {
|
|
212
175
|
globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR__ = FederationConstructor;
|
|
213
|
-
globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = "0.6.
|
|
176
|
+
globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = "0.6.1";
|
|
214
177
|
}
|
|
215
178
|
}
|
|
216
179
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
@@ -276,7 +239,7 @@ const setGlobalSnapshotInfoByModuleInfo = (remoteInfo, moduleDetailInfo)=>{
|
|
|
276
239
|
return nativeGlobal.__FEDERATION__.moduleInfo;
|
|
277
240
|
};
|
|
278
241
|
const addGlobalSnapshot = (moduleInfos)=>{
|
|
279
|
-
nativeGlobal.__FEDERATION__.moduleInfo = _extends
|
|
242
|
+
nativeGlobal.__FEDERATION__.moduleInfo = _extends({}, nativeGlobal.__FEDERATION__.moduleInfo, moduleInfos);
|
|
280
243
|
return ()=>{
|
|
281
244
|
const keys = Object.keys(moduleInfos);
|
|
282
245
|
for (const key of keys){
|
|
@@ -669,20 +632,6 @@ function satisfy(version, range) {
|
|
|
669
632
|
return true;
|
|
670
633
|
}
|
|
671
634
|
|
|
672
|
-
function _extends() {
|
|
673
|
-
_extends = Object.assign || function(target) {
|
|
674
|
-
for(var i = 1; i < arguments.length; i++){
|
|
675
|
-
var source = arguments[i];
|
|
676
|
-
for(var key in source){
|
|
677
|
-
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
678
|
-
target[key] = source[key];
|
|
679
|
-
}
|
|
680
|
-
}
|
|
681
|
-
}
|
|
682
|
-
return target;
|
|
683
|
-
};
|
|
684
|
-
return _extends.apply(this, arguments);
|
|
685
|
-
}
|
|
686
635
|
function formatShare(shareArgs, from, name, shareStrategy) {
|
|
687
636
|
let get;
|
|
688
637
|
if ('get' in shareArgs) {
|
|
@@ -895,4 +844,4 @@ function getTargetSharedOptions(options) {
|
|
|
895
844
|
return Object.assign({}, resolver(shareInfos[pkgName]), extraOptions == null ? void 0 : extraOptions.customShareInfo);
|
|
896
845
|
}
|
|
897
846
|
|
|
898
|
-
export {
|
|
847
|
+
export { getBuilderId as A, setGlobalFederationConstructor as B, getGlobalFederationInstance as C, DEFAULT_REMOTE_TYPE as D, getGlobalFederationConstructor as E, setGlobalFederationInstance as F, Global as G, registerGlobalPlugins as H, nativeGlobal as I, resetFederationGlobalInfo as J, getTargetSnapshotInfoByModuleInfo as K, globalLoading as a, DEFAULT_SCOPE as b, getRemoteEntryExports as c, assert as d, getFMId as e, error as f, getGlobalHostPlugins as g, isPlainObject as h, isObject as i, isRemoteInfoWithEntry as j, isPureRemoteEntry as k, getRemoteEntryInfoFromSnapshot as l, getInfoWithoutType as m, getPreloaded as n, getRegisteredShare as o, arrayOptions as p, getGlobalSnapshotInfoByModuleInfo as q, addGlobalSnapshot as r, setPreloaded as s, setGlobalSnapshotInfoByModuleInfo as t, getGlobalSnapshot as u, formatShareConfigs as v, warn as w, getTargetSharedOptions as x, getGlobalShareScope as y, addUniqueItem as z };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
declare const FederationHost: any, registerGlobalPlugins: any, getRemoteEntry: any, getRemoteInfo: any, loadScript: any, loadScriptNode: any, init: any, loadRemote: any, loadShare: any, loadShareSync: any, preloadRemote: any, registerRemotes: any, registerPlugins: any, getInstance: any;
|
|
2
|
+
export { FederationHost, registerGlobalPlugins, getRemoteEntry, getRemoteInfo, loadScript, loadScriptNode, init, loadRemote, loadShare, loadShareSync, preloadRemote, registerRemotes, registerPlugins, getInstance, };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { ModuleInfo, GlobalModuleInfo } from '@module-federation/sdk';
|
|
2
2
|
import { Options, UserOptions, PreloadAssets, PreloadOptions, PreloadRemoteArgs, Remote, RemoteInfo, RemoteEntryExports, CallFrom } from '../type';
|
|
3
3
|
import { FederationHost } from '../core';
|
|
4
4
|
import { PluginSystem, AsyncHook, AsyncWaterfallHook, SyncHook, SyncWaterfallHook } from '../utils/hooks';
|
package/dist/src/utils/env.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
+
export { isBrowserEnv, isDebugMode } from '@module-federation/sdk';
|
|
1
2
|
export declare function isDevelopmentMode(): boolean;
|
|
2
3
|
export declare function getBuilderId(): string;
|
|
3
|
-
export declare function isDebugMode(): boolean;
|
|
4
|
-
export declare function isBrowserEnv(): boolean;
|
package/dist/src/utils/tool.d.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { RemoteWithEntry, ModuleInfo, RemoteEntryType } from '@module-federation/sdk';
|
|
2
2
|
import { Remote, RemoteInfoOptionalVersion } from '../type';
|
|
3
3
|
export declare function addUniqueItem(arr: Array<string>, item: string): Array<string>;
|
|
4
4
|
export declare function getFMId(remoteInfo: RemoteInfoOptionalVersion | RemoteWithEntry): string;
|
|
5
5
|
export declare function isRemoteInfoWithEntry(remote: Remote): remote is RemoteWithEntry;
|
|
6
6
|
export declare function isPureRemoteEntry(remote: RemoteWithEntry): boolean;
|
|
7
7
|
export declare function safeWrapper<T extends (...args: Array<any>) => any>(callback: T, disableWarn?: boolean): Promise<ReturnType<T> | undefined>;
|
|
8
|
-
export declare function safeToString(info: any): string;
|
|
9
8
|
export declare function isObject(val: any): boolean;
|
|
10
9
|
export declare const objectToString: () => string;
|
|
11
10
|
export declare function isPlainObject(val: any): val is object;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@module-federation/runtime",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.1",
|
|
4
4
|
"author": "zhouxiao <codingzx@gmail.com>",
|
|
5
5
|
"main": "./dist/index.cjs.js",
|
|
6
6
|
"module": "./dist/index.esm.js",
|
|
@@ -29,10 +29,10 @@
|
|
|
29
29
|
"import": "./dist/types.esm.js",
|
|
30
30
|
"require": "./dist/types.cjs.js"
|
|
31
31
|
},
|
|
32
|
-
"./
|
|
33
|
-
"types": "./dist/
|
|
34
|
-
"import": "./dist/
|
|
35
|
-
"require": "./dist/
|
|
32
|
+
"./embedded": {
|
|
33
|
+
"types": "./dist/embedded.cjs.d.ts",
|
|
34
|
+
"import": "./dist/embedded.esm.js",
|
|
35
|
+
"require": "./dist/embedded.cjs.js"
|
|
36
36
|
},
|
|
37
37
|
"./*": "./*"
|
|
38
38
|
},
|
|
@@ -46,13 +46,10 @@
|
|
|
46
46
|
],
|
|
47
47
|
"types": [
|
|
48
48
|
"./dist/types.cjs.d.ts"
|
|
49
|
-
],
|
|
50
|
-
"retry-plugin": [
|
|
51
|
-
"./dist/retry-plugin.cjs.d.ts"
|
|
52
49
|
]
|
|
53
50
|
}
|
|
54
51
|
},
|
|
55
52
|
"dependencies": {
|
|
56
|
-
"@module-federation/sdk": "0.6.
|
|
53
|
+
"@module-federation/sdk": "0.6.1"
|
|
57
54
|
}
|
|
58
55
|
}
|
package/dist/retry-plugin.cjs.js
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
function _extends() {
|
|
4
|
-
_extends = Object.assign || function(target) {
|
|
5
|
-
for(var i = 1; i < arguments.length; i++){
|
|
6
|
-
var source = arguments[i];
|
|
7
|
-
for(var key in source){
|
|
8
|
-
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
9
|
-
target[key] = source[key];
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
return target;
|
|
14
|
-
};
|
|
15
|
-
return _extends.apply(this, arguments);
|
|
16
|
-
}
|
|
17
|
-
const defaultRetries = 3;
|
|
18
|
-
async function fetchWithRetry({ url, options = {}, retryTimes = defaultRetries, fallbackUrl = '' }) {
|
|
19
|
-
try {
|
|
20
|
-
const response = await fetch(url, options);
|
|
21
|
-
// To prevent the response object from being read multiple times and causing errors, clone it
|
|
22
|
-
const responseClone = response.clone();
|
|
23
|
-
// Network error
|
|
24
|
-
if (!response.ok) {
|
|
25
|
-
throw new Error(`Server error:${response.status}`);
|
|
26
|
-
}
|
|
27
|
-
// parse json error
|
|
28
|
-
await responseClone.json().catch((error)=>{
|
|
29
|
-
throw new Error(`Json parse error: ${error}, url is: ${url}`);
|
|
30
|
-
});
|
|
31
|
-
return response;
|
|
32
|
-
} catch (error) {
|
|
33
|
-
if (retryTimes <= 0) {
|
|
34
|
-
console.log(`>>>>>>>>> retry failed after ${defaultRetries} times for url: ${url}, now will try fallbackUrl url: ${fallbackUrl} <<<<<<<<<`);
|
|
35
|
-
if (fallbackUrl && fallbackUrl !== url) {
|
|
36
|
-
return fetchWithRetry({
|
|
37
|
-
url: fallbackUrl,
|
|
38
|
-
options,
|
|
39
|
-
retryTimes: 1,
|
|
40
|
-
fallbackUrl
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
throw new Error('The request failed three times and has now been abandoned');
|
|
44
|
-
}
|
|
45
|
-
// If there are remaining times, delay 1 second and try again
|
|
46
|
-
await new Promise((resolve)=>setTimeout(resolve, 1000));
|
|
47
|
-
console.log(`Trying again. Number of retries available:${retryTimes - 1}`);
|
|
48
|
-
return await fetchWithRetry({
|
|
49
|
-
url,
|
|
50
|
-
options,
|
|
51
|
-
retryTimes: retryTimes - 1,
|
|
52
|
-
fallbackUrl
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
const RetryPlugin = (params)=>({
|
|
57
|
-
name: 'retry-plugin',
|
|
58
|
-
async fetch (url, options) {
|
|
59
|
-
return fetchWithRetry({
|
|
60
|
-
url,
|
|
61
|
-
options: _extends({}, options, params == null ? void 0 : params.options),
|
|
62
|
-
retryTimes: params == null ? void 0 : params.retryTimes,
|
|
63
|
-
fallbackUrl: params == null ? void 0 : params.fallbackUrl
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
module.exports = RetryPlugin;
|
package/dist/retry-plugin.esm.js
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
function _extends() {
|
|
2
|
-
_extends = Object.assign || function(target) {
|
|
3
|
-
for(var i = 1; i < arguments.length; i++){
|
|
4
|
-
var source = arguments[i];
|
|
5
|
-
for(var key in source){
|
|
6
|
-
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
7
|
-
target[key] = source[key];
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
return target;
|
|
12
|
-
};
|
|
13
|
-
return _extends.apply(this, arguments);
|
|
14
|
-
}
|
|
15
|
-
const defaultRetries = 3;
|
|
16
|
-
async function fetchWithRetry({ url, options = {}, retryTimes = defaultRetries, fallbackUrl = '' }) {
|
|
17
|
-
try {
|
|
18
|
-
const response = await fetch(url, options);
|
|
19
|
-
// To prevent the response object from being read multiple times and causing errors, clone it
|
|
20
|
-
const responseClone = response.clone();
|
|
21
|
-
// Network error
|
|
22
|
-
if (!response.ok) {
|
|
23
|
-
throw new Error(`Server error:${response.status}`);
|
|
24
|
-
}
|
|
25
|
-
// parse json error
|
|
26
|
-
await responseClone.json().catch((error)=>{
|
|
27
|
-
throw new Error(`Json parse error: ${error}, url is: ${url}`);
|
|
28
|
-
});
|
|
29
|
-
return response;
|
|
30
|
-
} catch (error) {
|
|
31
|
-
if (retryTimes <= 0) {
|
|
32
|
-
console.log(`>>>>>>>>> retry failed after ${defaultRetries} times for url: ${url}, now will try fallbackUrl url: ${fallbackUrl} <<<<<<<<<`);
|
|
33
|
-
if (fallbackUrl && fallbackUrl !== url) {
|
|
34
|
-
return fetchWithRetry({
|
|
35
|
-
url: fallbackUrl,
|
|
36
|
-
options,
|
|
37
|
-
retryTimes: 1,
|
|
38
|
-
fallbackUrl
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
throw new Error('The request failed three times and has now been abandoned');
|
|
42
|
-
}
|
|
43
|
-
// If there are remaining times, delay 1 second and try again
|
|
44
|
-
await new Promise((resolve)=>setTimeout(resolve, 1000));
|
|
45
|
-
console.log(`Trying again. Number of retries available:${retryTimes - 1}`);
|
|
46
|
-
return await fetchWithRetry({
|
|
47
|
-
url,
|
|
48
|
-
options,
|
|
49
|
-
retryTimes: retryTimes - 1,
|
|
50
|
-
fallbackUrl
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
const RetryPlugin = (params)=>({
|
|
55
|
-
name: 'retry-plugin',
|
|
56
|
-
async fetch (url, options) {
|
|
57
|
-
return fetchWithRetry({
|
|
58
|
-
url,
|
|
59
|
-
options: _extends({}, options, params == null ? void 0 : params.options),
|
|
60
|
-
retryTimes: params == null ? void 0 : params.retryTimes,
|
|
61
|
-
fallbackUrl: params == null ? void 0 : params.fallbackUrl
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
export { RetryPlugin as default };
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { FederationRuntimePlugin } from '../type/plugin';
|
|
2
|
-
interface FetchWithRetryOptions {
|
|
3
|
-
url: string;
|
|
4
|
-
options?: RequestInit;
|
|
5
|
-
retryTimes?: number;
|
|
6
|
-
fallbackUrl?: string;
|
|
7
|
-
}
|
|
8
|
-
declare const RetryPlugin: (params?: Omit<FetchWithRetryOptions, 'url'>) => FederationRuntimePlugin;
|
|
9
|
-
export default RetryPlugin;
|