@module-federation/runtime 0.0.0-next-20240103035759 → 0.0.0-next-20240104022642
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/helpers.cjs.js +1 -1
- package/dist/helpers.esm.js +2 -2
- package/dist/index.cjs.js +170 -69
- package/dist/index.esm.js +169 -71
- package/dist/package.json +3 -3
- package/dist/share.cjs.js +142 -107
- package/dist/share.esm.js +142 -107
- package/dist/src/core.d.ts +21 -8
- package/dist/src/global.d.ts +3 -6
- package/dist/src/helpers.d.ts +2 -2
- package/dist/src/index.d.ts +1 -0
- package/dist/src/type/config.d.ts +6 -2
- package/dist/src/utils/share.d.ts +12 -3
- package/dist/types.cjs.d.ts +1 -0
- package/package.json +4 -4
- package/dist/type.cjs.d.ts +0 -1
- /package/dist/{type.cjs.js → types.cjs.js} +0 -0
- /package/dist/{type.esm.js → types.esm.js} +0 -0
package/dist/helpers.cjs.js
CHANGED
package/dist/helpers.esm.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { l as
|
|
1
|
+
import { l as getRegisteredShare, t as getGlobalShareScope, G as Global, F as nativeGlobal, H as resetFederationGlobalInfo, A as getGlobalFederationInstance, C as setGlobalFederationInstance, B as getGlobalFederationConstructor, z as setGlobalFederationConstructor, m as getInfoWithoutType, r as getGlobalSnapshot, I as getTargetSnapshotInfoByModuleInfo, p as getGlobalSnapshotInfoByModuleInfo, q as setGlobalSnapshotInfoByModuleInfo, J as addGlobalSnapshot, c as getRemoteEntryExports, E as registerGlobalPlugins, g as getGlobalHostPlugins, n as getPreloaded, o as setPreloaded } from './share.esm.js';
|
|
2
2
|
|
|
3
3
|
const ShareUtils = {
|
|
4
|
-
|
|
4
|
+
getRegisteredShare,
|
|
5
5
|
getGlobalShareScope
|
|
6
6
|
};
|
|
7
7
|
const GlobalUtils = {
|
package/dist/index.cjs.js
CHANGED
|
@@ -121,6 +121,27 @@ async function loadEntryScript({ name, globalName, entry, createScriptHook }) {
|
|
|
121
121
|
if (remoteEntryExports) {
|
|
122
122
|
return remoteEntryExports;
|
|
123
123
|
}
|
|
124
|
+
if (typeof document === 'undefined') {
|
|
125
|
+
return sdk.loadScriptNode(entry, {
|
|
126
|
+
attrs: {
|
|
127
|
+
name,
|
|
128
|
+
globalName
|
|
129
|
+
},
|
|
130
|
+
createScriptHook
|
|
131
|
+
}).then(()=>{
|
|
132
|
+
const { remoteEntryKey, entryExports } = share.getRemoteEntryExports(name, globalName);
|
|
133
|
+
share.assert(entryExports, `
|
|
134
|
+
Unable to use the ${name}'s '${entry}' URL with ${remoteEntryKey}'s globalName to get remoteEntry exports.
|
|
135
|
+
Possible reasons could be:\n
|
|
136
|
+
1. '${entry}' is not the correct URL, or the remoteEntry resource or name is incorrect.\n
|
|
137
|
+
2. ${remoteEntryKey} cannot be used to get remoteEntry exports in the window object.
|
|
138
|
+
`);
|
|
139
|
+
console.log(entryExports);
|
|
140
|
+
return entryExports;
|
|
141
|
+
}).catch((e)=>{
|
|
142
|
+
return e;
|
|
143
|
+
});
|
|
144
|
+
}
|
|
124
145
|
return sdk.loadScript(entry, {
|
|
125
146
|
attrs: {},
|
|
126
147
|
createScriptHook
|
|
@@ -133,6 +154,8 @@ async function loadEntryScript({ name, globalName, entry, createScriptHook }) {
|
|
|
133
154
|
2. ${remoteEntryKey} cannot be used to get remoteEntry exports in the window object.
|
|
134
155
|
`);
|
|
135
156
|
return entryExports;
|
|
157
|
+
}).catch((e)=>{
|
|
158
|
+
return e;
|
|
136
159
|
});
|
|
137
160
|
}
|
|
138
161
|
async function getRemoteEntry({ remoteEntryExports, remoteInfo, createScriptHook }) {
|
|
@@ -194,6 +217,10 @@ let Module = class Module {
|
|
|
194
217
|
const res = this.host.loaderHook.lifecycle.createScript.emit({
|
|
195
218
|
url
|
|
196
219
|
});
|
|
220
|
+
if (typeof document === 'undefined') {
|
|
221
|
+
//todo: needs real fix
|
|
222
|
+
return res;
|
|
223
|
+
}
|
|
197
224
|
if (res instanceof HTMLScriptElement) {
|
|
198
225
|
return res;
|
|
199
226
|
}
|
|
@@ -212,12 +239,12 @@ let Module = class Module {
|
|
|
212
239
|
// Get remoteEntry.js
|
|
213
240
|
const remoteEntryExports = await this.getEntry();
|
|
214
241
|
if (!this.inited) {
|
|
215
|
-
const
|
|
242
|
+
const localShareScopeMap = this.host.shareScopeMap;
|
|
216
243
|
const remoteShareScope = this.remoteInfo.shareScope || 'default';
|
|
217
|
-
if (!
|
|
218
|
-
|
|
244
|
+
if (!localShareScopeMap[remoteShareScope]) {
|
|
245
|
+
localShareScopeMap[remoteShareScope] = {};
|
|
219
246
|
}
|
|
220
|
-
const shareScope =
|
|
247
|
+
const shareScope = localShareScopeMap[remoteShareScope];
|
|
221
248
|
const initScope = [];
|
|
222
249
|
const remoteEntryInitOptions = {
|
|
223
250
|
version: this.remoteInfo.version || ''
|
|
@@ -776,9 +803,9 @@ function generatePreloadAssets(origin, preloadOptions, remote, globalSnapshot, r
|
|
|
776
803
|
if (!shareInfo) {
|
|
777
804
|
return;
|
|
778
805
|
}
|
|
779
|
-
const
|
|
806
|
+
const registeredShared = share.getRegisteredShare(origin.shareScopeMap, shared.sharedName, shareInfo, origin.hooks.lifecycle.resolveShare);
|
|
780
807
|
// If the global share does not exist, or the lib function does not exist, it means that the shared has not been loaded yet and can be preloaded.
|
|
781
|
-
if (
|
|
808
|
+
if (registeredShared && typeof registeredShared.lib === 'function') {
|
|
782
809
|
shared.assets.js.sync.forEach((asset)=>{
|
|
783
810
|
loadedSharedJsAssets.add(asset);
|
|
784
811
|
});
|
|
@@ -1105,13 +1132,19 @@ function _object_without_properties_loose(source, excluded) {
|
|
|
1105
1132
|
return target;
|
|
1106
1133
|
}
|
|
1107
1134
|
class FederationHost {
|
|
1135
|
+
_setGlobalShareScopeMap() {
|
|
1136
|
+
const globalShareScopeMap = share.getGlobalShareScope();
|
|
1137
|
+
const identifier = this.options.id || this.options.name;
|
|
1138
|
+
if (identifier && !globalShareScopeMap[identifier]) {
|
|
1139
|
+
globalShareScopeMap[identifier] = this.shareScopeMap;
|
|
1140
|
+
}
|
|
1141
|
+
}
|
|
1108
1142
|
initOptions(userOptions) {
|
|
1109
1143
|
this.registerPlugins(userOptions.plugins);
|
|
1110
1144
|
const options = this.formatOptions(this.options, userOptions);
|
|
1111
1145
|
this.options = options;
|
|
1112
1146
|
return options;
|
|
1113
1147
|
}
|
|
1114
|
-
// overrideSharedOptions(shareScope: GlobalShareScope[string]): void {}
|
|
1115
1148
|
async loadShare(pkgName, customShareInfo) {
|
|
1116
1149
|
var _this_options_shared;
|
|
1117
1150
|
// This function performs the following steps:
|
|
@@ -1119,6 +1152,12 @@ class FederationHost {
|
|
|
1119
1152
|
// 2. Searches globally for a matching share, if found, it uses it directly
|
|
1120
1153
|
// 3. If not found, it retrieves it from the current share and stores the obtained share globally.
|
|
1121
1154
|
const shareInfo = Object.assign({}, (_this_options_shared = this.options.shared) == null ? void 0 : _this_options_shared[pkgName], customShareInfo);
|
|
1155
|
+
if (shareInfo == null ? void 0 : shareInfo.scope) {
|
|
1156
|
+
await Promise.all(shareInfo.scope.map(async (shareScope)=>{
|
|
1157
|
+
await Promise.all(this.initializeSharing(shareScope, shareInfo.strategy));
|
|
1158
|
+
return;
|
|
1159
|
+
}));
|
|
1160
|
+
}
|
|
1122
1161
|
const loadShareRes = await this.hooks.lifecycle.beforeLoadShare.emit({
|
|
1123
1162
|
pkgName,
|
|
1124
1163
|
shareInfo,
|
|
@@ -1129,30 +1168,42 @@ class FederationHost {
|
|
|
1129
1168
|
// Assert that shareInfoRes exists, if not, throw an error
|
|
1130
1169
|
share.assert(shareInfoRes, `Cannot find ${pkgName} Share in the ${this.options.name}. Please ensure that the ${pkgName} Share parameters have been injected`);
|
|
1131
1170
|
// Retrieve from cache
|
|
1132
|
-
const
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1171
|
+
const registeredShared = share.getRegisteredShare(this.shareScopeMap, pkgName, shareInfoRes, this.hooks.lifecycle.resolveShare);
|
|
1172
|
+
const addUseIn = (shared)=>{
|
|
1173
|
+
if (!shared.useIn) {
|
|
1174
|
+
shared.useIn = [];
|
|
1175
|
+
}
|
|
1176
|
+
share.addUniqueItem(shared.useIn, this.options.name);
|
|
1177
|
+
};
|
|
1178
|
+
if (registeredShared && registeredShared.lib) {
|
|
1179
|
+
addUseIn(registeredShared);
|
|
1180
|
+
return registeredShared.lib;
|
|
1181
|
+
} else if (registeredShared && registeredShared.loading && !registeredShared.loaded) {
|
|
1182
|
+
const factory = await registeredShared.loading;
|
|
1183
|
+
registeredShared.loaded = true;
|
|
1184
|
+
if (!registeredShared.lib) {
|
|
1185
|
+
registeredShared.lib = factory;
|
|
1186
|
+
}
|
|
1187
|
+
addUseIn(registeredShared);
|
|
1139
1188
|
return factory;
|
|
1140
|
-
} else if (
|
|
1189
|
+
} else if (registeredShared) {
|
|
1141
1190
|
const asyncLoadProcess = async ()=>{
|
|
1142
|
-
const factory = await
|
|
1191
|
+
const factory = await registeredShared.get();
|
|
1143
1192
|
shareInfoRes.lib = factory;
|
|
1144
|
-
|
|
1145
|
-
|
|
1193
|
+
shareInfoRes.loaded = true;
|
|
1194
|
+
addUseIn(shareInfoRes);
|
|
1195
|
+
const gShared = share.getRegisteredShare(this.shareScopeMap, pkgName, shareInfoRes, this.hooks.lifecycle.resolveShare);
|
|
1146
1196
|
if (gShared) {
|
|
1147
1197
|
gShared.lib = factory;
|
|
1198
|
+
gShared.loaded = true;
|
|
1148
1199
|
}
|
|
1149
1200
|
return factory;
|
|
1150
1201
|
};
|
|
1151
1202
|
const loading = asyncLoadProcess();
|
|
1152
1203
|
this.setShared({
|
|
1153
1204
|
pkgName,
|
|
1154
|
-
loaded:
|
|
1155
|
-
shared:
|
|
1205
|
+
loaded: false,
|
|
1206
|
+
shared: registeredShared,
|
|
1156
1207
|
from: this.options.name,
|
|
1157
1208
|
lib: null,
|
|
1158
1209
|
loading
|
|
@@ -1165,17 +1216,19 @@ class FederationHost {
|
|
|
1165
1216
|
const asyncLoadProcess = async ()=>{
|
|
1166
1217
|
const factory = await shareInfoRes.get();
|
|
1167
1218
|
shareInfoRes.lib = factory;
|
|
1168
|
-
|
|
1169
|
-
|
|
1219
|
+
shareInfoRes.loaded = true;
|
|
1220
|
+
addUseIn(shareInfoRes);
|
|
1221
|
+
const gShared = share.getRegisteredShare(this.shareScopeMap, pkgName, shareInfoRes, this.hooks.lifecycle.resolveShare);
|
|
1170
1222
|
if (gShared) {
|
|
1171
1223
|
gShared.lib = factory;
|
|
1224
|
+
gShared.loaded = true;
|
|
1172
1225
|
}
|
|
1173
1226
|
return factory;
|
|
1174
1227
|
};
|
|
1175
1228
|
const loading = asyncLoadProcess();
|
|
1176
1229
|
this.setShared({
|
|
1177
1230
|
pkgName,
|
|
1178
|
-
loaded:
|
|
1231
|
+
loaded: false,
|
|
1179
1232
|
shared: shareInfoRes,
|
|
1180
1233
|
from: this.options.name,
|
|
1181
1234
|
lib: null,
|
|
@@ -1188,19 +1241,46 @@ class FederationHost {
|
|
|
1188
1241
|
// 1. If the loaded shared already exists globally, then it will be reused
|
|
1189
1242
|
// 2. If lib exists in local shared, it will be used directly
|
|
1190
1243
|
// 3. If the local get returns something other than Promise, then it will be used directly
|
|
1191
|
-
loadShareSync(pkgName) {
|
|
1244
|
+
loadShareSync(pkgName, customShareInfo) {
|
|
1192
1245
|
var _this_options_shared;
|
|
1193
|
-
const shareInfo = (_this_options_shared = this.options.shared) == null ? void 0 : _this_options_shared[pkgName];
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1246
|
+
const shareInfo = Object.assign({}, (_this_options_shared = this.options.shared) == null ? void 0 : _this_options_shared[pkgName], customShareInfo);
|
|
1247
|
+
if (shareInfo == null ? void 0 : shareInfo.scope) {
|
|
1248
|
+
shareInfo.scope.forEach((shareScope)=>{
|
|
1249
|
+
this.initializeSharing(shareScope, shareInfo.strategy);
|
|
1250
|
+
});
|
|
1251
|
+
}
|
|
1252
|
+
const registeredShared = share.getRegisteredShare(this.shareScopeMap, pkgName, shareInfo, this.hooks.lifecycle.resolveShare);
|
|
1253
|
+
const addUseIn = (shared)=>{
|
|
1254
|
+
if (!shared.useIn) {
|
|
1255
|
+
shared.useIn = [];
|
|
1256
|
+
}
|
|
1257
|
+
share.addUniqueItem(shared.useIn, this.options.name);
|
|
1258
|
+
};
|
|
1259
|
+
if (registeredShared) {
|
|
1260
|
+
if (typeof registeredShared.lib === 'function') {
|
|
1261
|
+
addUseIn(registeredShared);
|
|
1262
|
+
if (!registeredShared.loaded) {
|
|
1263
|
+
registeredShared.loaded = true;
|
|
1264
|
+
if (registeredShared.from === this.options.name) {
|
|
1265
|
+
shareInfo.loaded = true;
|
|
1266
|
+
}
|
|
1267
|
+
}
|
|
1268
|
+
return registeredShared.lib;
|
|
1269
|
+
}
|
|
1270
|
+
if (typeof registeredShared.get === 'function') {
|
|
1271
|
+
const module = registeredShared.get();
|
|
1272
|
+
if (!(module instanceof Promise)) {
|
|
1273
|
+
addUseIn(registeredShared);
|
|
1274
|
+
this.setShared({
|
|
1275
|
+
pkgName,
|
|
1276
|
+
loaded: true,
|
|
1277
|
+
from: this.options.name,
|
|
1278
|
+
lib: module,
|
|
1279
|
+
shared: registeredShared
|
|
1280
|
+
});
|
|
1281
|
+
return module;
|
|
1201
1282
|
}
|
|
1202
1283
|
}
|
|
1203
|
-
return globalShare.lib;
|
|
1204
1284
|
}
|
|
1205
1285
|
if (shareInfo.lib) {
|
|
1206
1286
|
if (!shareInfo.loaded) {
|
|
@@ -1307,11 +1387,19 @@ class FederationHost {
|
|
|
1307
1387
|
});
|
|
1308
1388
|
return moduleOrFactory;
|
|
1309
1389
|
} catch (error) {
|
|
1310
|
-
|
|
1390
|
+
const { from = 'runtime' } = options || {
|
|
1391
|
+
from: 'runtime'
|
|
1392
|
+
};
|
|
1393
|
+
const failOver = await this.hooks.lifecycle.errorLoadRemote.emit({
|
|
1311
1394
|
id,
|
|
1312
|
-
error
|
|
1395
|
+
error,
|
|
1396
|
+
from,
|
|
1397
|
+
origin: this
|
|
1313
1398
|
});
|
|
1314
|
-
|
|
1399
|
+
if (!failOver) {
|
|
1400
|
+
throw error;
|
|
1401
|
+
}
|
|
1402
|
+
return failOver;
|
|
1315
1403
|
}
|
|
1316
1404
|
}
|
|
1317
1405
|
// eslint-disable-next-line @typescript-eslint/member-ordering
|
|
@@ -1345,14 +1433,9 @@ class FederationHost {
|
|
|
1345
1433
|
* It accepts one argument, the name of the share scope.
|
|
1346
1434
|
* If the share scope does not exist, it creates one.
|
|
1347
1435
|
*/ // eslint-disable-next-line @typescript-eslint/member-ordering
|
|
1348
|
-
initializeSharing(shareScopeName = share.DEFAULT_SCOPE) {
|
|
1349
|
-
const
|
|
1350
|
-
const shareScope = share.Global.__FEDERATION__.__SHARE__;
|
|
1436
|
+
initializeSharing(shareScopeName = share.DEFAULT_SCOPE, strategy) {
|
|
1437
|
+
const shareScope = this.shareScopeMap;
|
|
1351
1438
|
const hostName = this.options.name;
|
|
1352
|
-
// Executes only once
|
|
1353
|
-
if (shareScopeLoading[shareScopeName]) {
|
|
1354
|
-
return shareScopeLoading[shareScopeName];
|
|
1355
|
-
}
|
|
1356
1439
|
// Creates a new share scope if necessary
|
|
1357
1440
|
if (!shareScope[shareScopeName]) {
|
|
1358
1441
|
shareScope[shareScopeName] = {};
|
|
@@ -1360,21 +1443,27 @@ class FederationHost {
|
|
|
1360
1443
|
// Executes all initialization snippets from all accessible modules
|
|
1361
1444
|
const scope = shareScope[shareScopeName];
|
|
1362
1445
|
const register = (name, shared)=>{
|
|
1446
|
+
var _activeVersion_shareConfig;
|
|
1363
1447
|
const { version, eager } = shared;
|
|
1364
1448
|
scope[name] = scope[name] || {};
|
|
1365
1449
|
const versions = scope[name];
|
|
1366
1450
|
const activeVersion = versions[version];
|
|
1367
|
-
const activeVersionEager = Boolean(activeVersion && (activeVersion.eager || activeVersion.shareConfig.eager));
|
|
1451
|
+
const activeVersionEager = Boolean(activeVersion && (activeVersion.eager || ((_activeVersion_shareConfig = activeVersion.shareConfig) == null ? void 0 : _activeVersion_shareConfig.eager)));
|
|
1368
1452
|
if (!activeVersion || !activeVersion.loaded && (Boolean(!eager) !== !activeVersionEager ? eager : hostName > activeVersion.from)) {
|
|
1369
1453
|
versions[version] = shared;
|
|
1370
1454
|
}
|
|
1371
1455
|
};
|
|
1372
1456
|
const promises = [];
|
|
1457
|
+
const initFn = (mod)=>mod && mod.init && mod.init(shareScope[shareScopeName]);
|
|
1373
1458
|
const initRemoteModule = async (key)=>{
|
|
1374
1459
|
const { module } = await this._getRemoteModuleAndOptions(key);
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1460
|
+
if (module.getEntry) {
|
|
1461
|
+
const entry = await module.getEntry();
|
|
1462
|
+
if (!module.inited) {
|
|
1463
|
+
initFn(entry);
|
|
1464
|
+
module.inited = true;
|
|
1465
|
+
}
|
|
1466
|
+
}
|
|
1378
1467
|
};
|
|
1379
1468
|
Object.keys(this.options.shared).forEach((shareName)=>{
|
|
1380
1469
|
const shared = this.options.shared[shareName];
|
|
@@ -1382,15 +1471,17 @@ class FederationHost {
|
|
|
1382
1471
|
register(shareName, shared);
|
|
1383
1472
|
}
|
|
1384
1473
|
});
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
return shareScopeLoading[shareScopeName] = true;
|
|
1474
|
+
if (strategy === 'version-first') {
|
|
1475
|
+
this.options.remotes.forEach((remote)=>{
|
|
1476
|
+
if (remote.shareScope === shareScopeName) {
|
|
1477
|
+
promises.push(initRemoteModule(remote.name));
|
|
1478
|
+
}
|
|
1479
|
+
});
|
|
1392
1480
|
}
|
|
1393
|
-
return
|
|
1481
|
+
return promises;
|
|
1482
|
+
}
|
|
1483
|
+
initShareScopeMap(scopeName, shareScope) {
|
|
1484
|
+
this.shareScopeMap[scopeName] = shareScope;
|
|
1394
1485
|
}
|
|
1395
1486
|
formatOptions(globalOptions, userOptions) {
|
|
1396
1487
|
const formatShareOptions = share.formatShareConfigs(userOptions.shared || {}, userOptions.name);
|
|
@@ -1430,16 +1521,17 @@ class FederationHost {
|
|
|
1430
1521
|
}
|
|
1431
1522
|
return res;
|
|
1432
1523
|
}, globalOptionsRes.remotes);
|
|
1433
|
-
// register shared
|
|
1524
|
+
// register shared in shareScopeMap
|
|
1434
1525
|
const sharedKeys = Object.keys(formatShareOptions);
|
|
1435
1526
|
sharedKeys.forEach((sharedKey)=>{
|
|
1436
1527
|
const sharedVal = formatShareOptions[sharedKey];
|
|
1437
|
-
const
|
|
1438
|
-
if (!
|
|
1528
|
+
const registeredShared = share.getRegisteredShare(this.shareScopeMap, sharedKey, sharedVal, this.hooks.lifecycle.resolveShare);
|
|
1529
|
+
if (!registeredShared && sharedVal && sharedVal.lib) {
|
|
1439
1530
|
this.setShared({
|
|
1440
1531
|
pkgName: sharedKey,
|
|
1441
1532
|
lib: sharedVal.lib,
|
|
1442
1533
|
get: sharedVal.get,
|
|
1534
|
+
loaded: true,
|
|
1443
1535
|
shared: sharedVal,
|
|
1444
1536
|
from: userOptions.name
|
|
1445
1537
|
});
|
|
@@ -1474,7 +1566,6 @@ class FederationHost {
|
|
|
1474
1566
|
]);
|
|
1475
1567
|
}
|
|
1476
1568
|
setShared({ pkgName, shared, from, lib, loading, loaded, get }) {
|
|
1477
|
-
const target = share.getGlobalShareScope();
|
|
1478
1569
|
const { version, scope = 'default' } = shared, shareInfo = _object_without_properties_loose(shared, [
|
|
1479
1570
|
"version",
|
|
1480
1571
|
"scope"
|
|
@@ -1483,23 +1574,23 @@ class FederationHost {
|
|
|
1483
1574
|
scope
|
|
1484
1575
|
];
|
|
1485
1576
|
scopes.forEach((sc)=>{
|
|
1486
|
-
if (!
|
|
1487
|
-
|
|
1577
|
+
if (!this.shareScopeMap[sc]) {
|
|
1578
|
+
this.shareScopeMap[sc] = {};
|
|
1488
1579
|
}
|
|
1489
|
-
if (!
|
|
1490
|
-
|
|
1580
|
+
if (!this.shareScopeMap[sc][pkgName]) {
|
|
1581
|
+
this.shareScopeMap[sc][pkgName] = {};
|
|
1491
1582
|
}
|
|
1492
|
-
if (
|
|
1583
|
+
if (this.shareScopeMap[sc][pkgName][version]) {
|
|
1493
1584
|
share.warn(// eslint-disable-next-line max-len
|
|
1494
1585
|
`The share \n ${share.safeToString({
|
|
1495
1586
|
scope: sc,
|
|
1496
1587
|
pkgName,
|
|
1497
1588
|
version,
|
|
1498
|
-
from:
|
|
1589
|
+
from: this.shareScopeMap[sc][pkgName][version].from
|
|
1499
1590
|
})} has been registered`);
|
|
1500
1591
|
return;
|
|
1501
1592
|
}
|
|
1502
|
-
|
|
1593
|
+
this.shareScopeMap[sc][pkgName][version] = _extends({
|
|
1503
1594
|
version,
|
|
1504
1595
|
scope: [
|
|
1505
1596
|
'default'
|
|
@@ -1510,7 +1601,7 @@ class FederationHost {
|
|
|
1510
1601
|
loading
|
|
1511
1602
|
});
|
|
1512
1603
|
if (get) {
|
|
1513
|
-
|
|
1604
|
+
this.shareScopeMap[sc][pkgName][version].get = get;
|
|
1514
1605
|
}
|
|
1515
1606
|
});
|
|
1516
1607
|
}
|
|
@@ -1527,11 +1618,13 @@ class FederationHost {
|
|
|
1527
1618
|
errorLoadRemote: new AsyncHook('errorLoadRemote'),
|
|
1528
1619
|
beforeLoadShare: new AsyncWaterfallHook('beforeLoadShare'),
|
|
1529
1620
|
loadShare: new AsyncHook(),
|
|
1621
|
+
resolveShare: new SyncWaterfallHook('resolveShare'),
|
|
1530
1622
|
beforePreloadRemote: new AsyncHook(),
|
|
1531
1623
|
generatePreloadAssets: new AsyncHook('generatePreloadAssets'),
|
|
1532
1624
|
afterPreloadRemote: new AsyncHook()
|
|
1533
1625
|
});
|
|
1534
|
-
this.
|
|
1626
|
+
this.releaseNumber = `7`;
|
|
1627
|
+
this.version = `'0.0.7'`;
|
|
1535
1628
|
this.moduleCache = new Map();
|
|
1536
1629
|
this.loaderHook = new PluginSystem({
|
|
1537
1630
|
// FIXME: may not be suitable
|
|
@@ -1539,7 +1632,6 @@ class FederationHost {
|
|
|
1539
1632
|
createScript: new SyncHook(),
|
|
1540
1633
|
fetch: new AsyncHook('fetch')
|
|
1541
1634
|
});
|
|
1542
|
-
this.loadingShare = {};
|
|
1543
1635
|
// TODO: Validate the details of the options
|
|
1544
1636
|
// Initialize options with default values
|
|
1545
1637
|
const defaultOptions = {
|
|
@@ -1555,6 +1647,8 @@ class FederationHost {
|
|
|
1555
1647
|
};
|
|
1556
1648
|
this.name = userOptions.name;
|
|
1557
1649
|
this.options = defaultOptions;
|
|
1650
|
+
this.shareScopeMap = {};
|
|
1651
|
+
this._setGlobalShareScopeMap();
|
|
1558
1652
|
this.snapshotHandler = new SnapshotHandler(this);
|
|
1559
1653
|
this.registerPlugins([
|
|
1560
1654
|
...defaultOptions.plugins,
|
|
@@ -1577,6 +1671,9 @@ function init(options) {
|
|
|
1577
1671
|
} else {
|
|
1578
1672
|
// Merge options
|
|
1579
1673
|
instance.initOptions(options);
|
|
1674
|
+
if (!FederationInstance) {
|
|
1675
|
+
FederationInstance = instance;
|
|
1676
|
+
}
|
|
1580
1677
|
return instance;
|
|
1581
1678
|
}
|
|
1582
1679
|
}
|
|
@@ -1604,6 +1701,10 @@ function preloadRemote(...args) {
|
|
|
1604
1701
|
share.setGlobalFederationConstructor(FederationHost);
|
|
1605
1702
|
|
|
1606
1703
|
exports.registerGlobalPlugins = share.registerGlobalPlugins;
|
|
1704
|
+
Object.defineProperty(exports, 'loadScript', {
|
|
1705
|
+
enumerable: true,
|
|
1706
|
+
get: function () { return sdk.loadScript; }
|
|
1707
|
+
});
|
|
1607
1708
|
exports.FederationHost = FederationHost;
|
|
1608
1709
|
exports.init = init;
|
|
1609
1710
|
exports.loadRemote = loadRemote;
|