@module-federation/runtime 0.0.7 → 0.0.9
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/README.md +513 -124
- package/dist/helpers.cjs.js +1 -1
- package/dist/helpers.esm.js +2 -2
- package/dist/index.cjs.js +189 -78
- package/dist/index.esm.js +188 -80
- package/dist/package.json +3 -3
- package/dist/share.cjs.js +92 -59
- package/dist/share.esm.js +92 -59
- package/dist/src/core.d.ts +26 -9
- package/dist/src/global.d.ts +2 -3
- package/dist/src/helpers.d.ts +2 -2
- package/dist/src/index.d.ts +3 -1
- package/dist/src/type/config.d.ts +7 -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,18 +239,25 @@ 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 || ''
|
|
224
251
|
};
|
|
252
|
+
// Help to find host instance
|
|
253
|
+
Object.defineProperty(remoteEntryInitOptions, 'hostId', {
|
|
254
|
+
value: this.host.options.id || this.host.name,
|
|
255
|
+
// remoteEntryInitOptions will be traversed and assigned during container init, ,so this attribute is not allowed to be traversed
|
|
256
|
+
enumerable: false
|
|
257
|
+
});
|
|
225
258
|
const initContainerOptions = await this.host.hooks.lifecycle.beforeInitContainer.emit({
|
|
226
259
|
shareScope,
|
|
260
|
+
// @ts-ignore hostId will be set by Object.defineProperty
|
|
227
261
|
remoteEntryInitOptions,
|
|
228
262
|
initScope,
|
|
229
263
|
remoteInfo: this.remoteInfo,
|
|
@@ -776,9 +810,9 @@ function generatePreloadAssets(origin, preloadOptions, remote, globalSnapshot, r
|
|
|
776
810
|
if (!shareInfo) {
|
|
777
811
|
return;
|
|
778
812
|
}
|
|
779
|
-
const
|
|
813
|
+
const registeredShared = share.getRegisteredShare(origin.shareScopeMap, shared.sharedName, shareInfo, origin.hooks.lifecycle.resolveShare);
|
|
780
814
|
// 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 (
|
|
815
|
+
if (registeredShared && typeof registeredShared.lib === 'function') {
|
|
782
816
|
shared.assets.js.sync.forEach((asset)=>{
|
|
783
817
|
loadedSharedJsAssets.add(asset);
|
|
784
818
|
});
|
|
@@ -1105,13 +1139,19 @@ function _object_without_properties_loose(source, excluded) {
|
|
|
1105
1139
|
return target;
|
|
1106
1140
|
}
|
|
1107
1141
|
class FederationHost {
|
|
1142
|
+
_setGlobalShareScopeMap() {
|
|
1143
|
+
const globalShareScopeMap = share.getGlobalShareScope();
|
|
1144
|
+
const identifier = this.options.id || this.options.name;
|
|
1145
|
+
if (identifier && !globalShareScopeMap[identifier]) {
|
|
1146
|
+
globalShareScopeMap[identifier] = this.shareScopeMap;
|
|
1147
|
+
}
|
|
1148
|
+
}
|
|
1108
1149
|
initOptions(userOptions) {
|
|
1109
1150
|
this.registerPlugins(userOptions.plugins);
|
|
1110
1151
|
const options = this.formatOptions(this.options, userOptions);
|
|
1111
1152
|
this.options = options;
|
|
1112
1153
|
return options;
|
|
1113
1154
|
}
|
|
1114
|
-
// overrideSharedOptions(shareScope: GlobalShareScope[string]): void {}
|
|
1115
1155
|
async loadShare(pkgName, customShareInfo) {
|
|
1116
1156
|
var _this_options_shared;
|
|
1117
1157
|
// This function performs the following steps:
|
|
@@ -1119,6 +1159,12 @@ class FederationHost {
|
|
|
1119
1159
|
// 2. Searches globally for a matching share, if found, it uses it directly
|
|
1120
1160
|
// 3. If not found, it retrieves it from the current share and stores the obtained share globally.
|
|
1121
1161
|
const shareInfo = Object.assign({}, (_this_options_shared = this.options.shared) == null ? void 0 : _this_options_shared[pkgName], customShareInfo);
|
|
1162
|
+
if (shareInfo == null ? void 0 : shareInfo.scope) {
|
|
1163
|
+
await Promise.all(shareInfo.scope.map(async (shareScope)=>{
|
|
1164
|
+
await Promise.all(this.initializeSharing(shareScope, shareInfo.strategy));
|
|
1165
|
+
return;
|
|
1166
|
+
}));
|
|
1167
|
+
}
|
|
1122
1168
|
const loadShareRes = await this.hooks.lifecycle.beforeLoadShare.emit({
|
|
1123
1169
|
pkgName,
|
|
1124
1170
|
shareInfo,
|
|
@@ -1129,30 +1175,42 @@ class FederationHost {
|
|
|
1129
1175
|
// Assert that shareInfoRes exists, if not, throw an error
|
|
1130
1176
|
share.assert(shareInfoRes, `Cannot find ${pkgName} Share in the ${this.options.name}. Please ensure that the ${pkgName} Share parameters have been injected`);
|
|
1131
1177
|
// Retrieve from cache
|
|
1132
|
-
const
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1178
|
+
const registeredShared = share.getRegisteredShare(this.shareScopeMap, pkgName, shareInfoRes, this.hooks.lifecycle.resolveShare);
|
|
1179
|
+
const addUseIn = (shared)=>{
|
|
1180
|
+
if (!shared.useIn) {
|
|
1181
|
+
shared.useIn = [];
|
|
1182
|
+
}
|
|
1183
|
+
share.addUniqueItem(shared.useIn, this.options.name);
|
|
1184
|
+
};
|
|
1185
|
+
if (registeredShared && registeredShared.lib) {
|
|
1186
|
+
addUseIn(registeredShared);
|
|
1187
|
+
return registeredShared.lib;
|
|
1188
|
+
} else if (registeredShared && registeredShared.loading && !registeredShared.loaded) {
|
|
1189
|
+
const factory = await registeredShared.loading;
|
|
1190
|
+
registeredShared.loaded = true;
|
|
1191
|
+
if (!registeredShared.lib) {
|
|
1192
|
+
registeredShared.lib = factory;
|
|
1193
|
+
}
|
|
1194
|
+
addUseIn(registeredShared);
|
|
1139
1195
|
return factory;
|
|
1140
|
-
} else if (
|
|
1196
|
+
} else if (registeredShared) {
|
|
1141
1197
|
const asyncLoadProcess = async ()=>{
|
|
1142
|
-
const factory = await
|
|
1198
|
+
const factory = await registeredShared.get();
|
|
1143
1199
|
shareInfoRes.lib = factory;
|
|
1144
|
-
|
|
1145
|
-
|
|
1200
|
+
shareInfoRes.loaded = true;
|
|
1201
|
+
addUseIn(shareInfoRes);
|
|
1202
|
+
const gShared = share.getRegisteredShare(this.shareScopeMap, pkgName, shareInfoRes, this.hooks.lifecycle.resolveShare);
|
|
1146
1203
|
if (gShared) {
|
|
1147
1204
|
gShared.lib = factory;
|
|
1205
|
+
gShared.loaded = true;
|
|
1148
1206
|
}
|
|
1149
1207
|
return factory;
|
|
1150
1208
|
};
|
|
1151
1209
|
const loading = asyncLoadProcess();
|
|
1152
1210
|
this.setShared({
|
|
1153
1211
|
pkgName,
|
|
1154
|
-
loaded:
|
|
1155
|
-
shared:
|
|
1212
|
+
loaded: false,
|
|
1213
|
+
shared: registeredShared,
|
|
1156
1214
|
from: this.options.name,
|
|
1157
1215
|
lib: null,
|
|
1158
1216
|
loading
|
|
@@ -1165,17 +1223,19 @@ class FederationHost {
|
|
|
1165
1223
|
const asyncLoadProcess = async ()=>{
|
|
1166
1224
|
const factory = await shareInfoRes.get();
|
|
1167
1225
|
shareInfoRes.lib = factory;
|
|
1168
|
-
|
|
1169
|
-
|
|
1226
|
+
shareInfoRes.loaded = true;
|
|
1227
|
+
addUseIn(shareInfoRes);
|
|
1228
|
+
const gShared = share.getRegisteredShare(this.shareScopeMap, pkgName, shareInfoRes, this.hooks.lifecycle.resolveShare);
|
|
1170
1229
|
if (gShared) {
|
|
1171
1230
|
gShared.lib = factory;
|
|
1231
|
+
gShared.loaded = true;
|
|
1172
1232
|
}
|
|
1173
1233
|
return factory;
|
|
1174
1234
|
};
|
|
1175
1235
|
const loading = asyncLoadProcess();
|
|
1176
1236
|
this.setShared({
|
|
1177
1237
|
pkgName,
|
|
1178
|
-
loaded:
|
|
1238
|
+
loaded: false,
|
|
1179
1239
|
shared: shareInfoRes,
|
|
1180
1240
|
from: this.options.name,
|
|
1181
1241
|
lib: null,
|
|
@@ -1188,19 +1248,46 @@ class FederationHost {
|
|
|
1188
1248
|
// 1. If the loaded shared already exists globally, then it will be reused
|
|
1189
1249
|
// 2. If lib exists in local shared, it will be used directly
|
|
1190
1250
|
// 3. If the local get returns something other than Promise, then it will be used directly
|
|
1191
|
-
loadShareSync(pkgName) {
|
|
1251
|
+
loadShareSync(pkgName, customShareInfo) {
|
|
1192
1252
|
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
|
-
|
|
1253
|
+
const shareInfo = Object.assign({}, (_this_options_shared = this.options.shared) == null ? void 0 : _this_options_shared[pkgName], customShareInfo);
|
|
1254
|
+
if (shareInfo == null ? void 0 : shareInfo.scope) {
|
|
1255
|
+
shareInfo.scope.forEach((shareScope)=>{
|
|
1256
|
+
this.initializeSharing(shareScope, shareInfo.strategy);
|
|
1257
|
+
});
|
|
1258
|
+
}
|
|
1259
|
+
const registeredShared = share.getRegisteredShare(this.shareScopeMap, pkgName, shareInfo, this.hooks.lifecycle.resolveShare);
|
|
1260
|
+
const addUseIn = (shared)=>{
|
|
1261
|
+
if (!shared.useIn) {
|
|
1262
|
+
shared.useIn = [];
|
|
1263
|
+
}
|
|
1264
|
+
share.addUniqueItem(shared.useIn, this.options.name);
|
|
1265
|
+
};
|
|
1266
|
+
if (registeredShared) {
|
|
1267
|
+
if (typeof registeredShared.lib === 'function') {
|
|
1268
|
+
addUseIn(registeredShared);
|
|
1269
|
+
if (!registeredShared.loaded) {
|
|
1270
|
+
registeredShared.loaded = true;
|
|
1271
|
+
if (registeredShared.from === this.options.name) {
|
|
1272
|
+
shareInfo.loaded = true;
|
|
1273
|
+
}
|
|
1274
|
+
}
|
|
1275
|
+
return registeredShared.lib;
|
|
1276
|
+
}
|
|
1277
|
+
if (typeof registeredShared.get === 'function') {
|
|
1278
|
+
const module = registeredShared.get();
|
|
1279
|
+
if (!(module instanceof Promise)) {
|
|
1280
|
+
addUseIn(registeredShared);
|
|
1281
|
+
this.setShared({
|
|
1282
|
+
pkgName,
|
|
1283
|
+
loaded: true,
|
|
1284
|
+
from: this.options.name,
|
|
1285
|
+
lib: module,
|
|
1286
|
+
shared: registeredShared
|
|
1287
|
+
});
|
|
1288
|
+
return module;
|
|
1201
1289
|
}
|
|
1202
1290
|
}
|
|
1203
|
-
return globalShare.lib;
|
|
1204
1291
|
}
|
|
1205
1292
|
if (shareInfo.lib) {
|
|
1206
1293
|
if (!shareInfo.loaded) {
|
|
@@ -1307,11 +1394,19 @@ class FederationHost {
|
|
|
1307
1394
|
});
|
|
1308
1395
|
return moduleOrFactory;
|
|
1309
1396
|
} catch (error) {
|
|
1310
|
-
|
|
1397
|
+
const { from = 'runtime' } = options || {
|
|
1398
|
+
from: 'runtime'
|
|
1399
|
+
};
|
|
1400
|
+
const failOver = await this.hooks.lifecycle.errorLoadRemote.emit({
|
|
1311
1401
|
id,
|
|
1312
|
-
error
|
|
1402
|
+
error,
|
|
1403
|
+
from,
|
|
1404
|
+
origin: this
|
|
1313
1405
|
});
|
|
1314
|
-
|
|
1406
|
+
if (!failOver) {
|
|
1407
|
+
throw error;
|
|
1408
|
+
}
|
|
1409
|
+
return failOver;
|
|
1315
1410
|
}
|
|
1316
1411
|
}
|
|
1317
1412
|
// eslint-disable-next-line @typescript-eslint/member-ordering
|
|
@@ -1345,14 +1440,9 @@ class FederationHost {
|
|
|
1345
1440
|
* It accepts one argument, the name of the share scope.
|
|
1346
1441
|
* If the share scope does not exist, it creates one.
|
|
1347
1442
|
*/ // eslint-disable-next-line @typescript-eslint/member-ordering
|
|
1348
|
-
initializeSharing(shareScopeName = share.DEFAULT_SCOPE) {
|
|
1349
|
-
const
|
|
1350
|
-
const shareScope = share.Global.__FEDERATION__.__SHARE__;
|
|
1443
|
+
initializeSharing(shareScopeName = share.DEFAULT_SCOPE, strategy) {
|
|
1444
|
+
const shareScope = this.shareScopeMap;
|
|
1351
1445
|
const hostName = this.options.name;
|
|
1352
|
-
// Executes only once
|
|
1353
|
-
if (shareScopeLoading[shareScopeName]) {
|
|
1354
|
-
return shareScopeLoading[shareScopeName];
|
|
1355
|
-
}
|
|
1356
1446
|
// Creates a new share scope if necessary
|
|
1357
1447
|
if (!shareScope[shareScopeName]) {
|
|
1358
1448
|
shareScope[shareScopeName] = {};
|
|
@@ -1360,21 +1450,27 @@ class FederationHost {
|
|
|
1360
1450
|
// Executes all initialization snippets from all accessible modules
|
|
1361
1451
|
const scope = shareScope[shareScopeName];
|
|
1362
1452
|
const register = (name, shared)=>{
|
|
1453
|
+
var _activeVersion_shareConfig;
|
|
1363
1454
|
const { version, eager } = shared;
|
|
1364
1455
|
scope[name] = scope[name] || {};
|
|
1365
1456
|
const versions = scope[name];
|
|
1366
1457
|
const activeVersion = versions[version];
|
|
1367
|
-
const activeVersionEager = Boolean(activeVersion && (activeVersion.eager || activeVersion.shareConfig.eager));
|
|
1458
|
+
const activeVersionEager = Boolean(activeVersion && (activeVersion.eager || ((_activeVersion_shareConfig = activeVersion.shareConfig) == null ? void 0 : _activeVersion_shareConfig.eager)));
|
|
1368
1459
|
if (!activeVersion || !activeVersion.loaded && (Boolean(!eager) !== !activeVersionEager ? eager : hostName > activeVersion.from)) {
|
|
1369
1460
|
versions[version] = shared;
|
|
1370
1461
|
}
|
|
1371
1462
|
};
|
|
1372
1463
|
const promises = [];
|
|
1464
|
+
const initFn = (mod)=>mod && mod.init && mod.init(shareScope[shareScopeName]);
|
|
1373
1465
|
const initRemoteModule = async (key)=>{
|
|
1374
1466
|
const { module } = await this._getRemoteModuleAndOptions(key);
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1467
|
+
if (module.getEntry) {
|
|
1468
|
+
const entry = await module.getEntry();
|
|
1469
|
+
if (!module.inited) {
|
|
1470
|
+
initFn(entry);
|
|
1471
|
+
module.inited = true;
|
|
1472
|
+
}
|
|
1473
|
+
}
|
|
1378
1474
|
};
|
|
1379
1475
|
Object.keys(this.options.shared).forEach((shareName)=>{
|
|
1380
1476
|
const shared = this.options.shared[shareName];
|
|
@@ -1382,15 +1478,22 @@ class FederationHost {
|
|
|
1382
1478
|
register(shareName, shared);
|
|
1383
1479
|
}
|
|
1384
1480
|
});
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
return shareScopeLoading[shareScopeName] = true;
|
|
1481
|
+
if (strategy === 'version-first') {
|
|
1482
|
+
this.options.remotes.forEach((remote)=>{
|
|
1483
|
+
if (remote.shareScope === shareScopeName) {
|
|
1484
|
+
promises.push(initRemoteModule(remote.name));
|
|
1485
|
+
}
|
|
1486
|
+
});
|
|
1392
1487
|
}
|
|
1393
|
-
return
|
|
1488
|
+
return promises;
|
|
1489
|
+
}
|
|
1490
|
+
initShareScopeMap(scopeName, shareScope) {
|
|
1491
|
+
this.shareScopeMap[scopeName] = shareScope;
|
|
1492
|
+
this.hooks.lifecycle.initContainerShareScopeMap.emit({
|
|
1493
|
+
shareScope,
|
|
1494
|
+
options: this.options,
|
|
1495
|
+
origin: this
|
|
1496
|
+
});
|
|
1394
1497
|
}
|
|
1395
1498
|
formatOptions(globalOptions, userOptions) {
|
|
1396
1499
|
const formatShareOptions = share.formatShareConfigs(userOptions.shared || {}, userOptions.name);
|
|
@@ -1415,7 +1518,7 @@ class FederationHost {
|
|
|
1415
1518
|
}
|
|
1416
1519
|
// Set the remote entry to a complete path
|
|
1417
1520
|
if ('entry' in remote) {
|
|
1418
|
-
if (share.isBrowserEnv()) {
|
|
1521
|
+
if (share.isBrowserEnv() && !remote.entry.startsWith('http')) {
|
|
1419
1522
|
remote.entry = new URL(remote.entry, window.location.origin).href;
|
|
1420
1523
|
}
|
|
1421
1524
|
}
|
|
@@ -1423,23 +1526,23 @@ class FederationHost {
|
|
|
1423
1526
|
remote.shareScope = share.DEFAULT_SCOPE;
|
|
1424
1527
|
}
|
|
1425
1528
|
if (!remote.type) {
|
|
1426
|
-
// FIXME: The build plugin needs to support this field
|
|
1427
1529
|
remote.type = share.DEFAULT_REMOTE_TYPE;
|
|
1428
1530
|
}
|
|
1429
1531
|
res.push(remote);
|
|
1430
1532
|
}
|
|
1431
1533
|
return res;
|
|
1432
1534
|
}, globalOptionsRes.remotes);
|
|
1433
|
-
// register shared
|
|
1535
|
+
// register shared in shareScopeMap
|
|
1434
1536
|
const sharedKeys = Object.keys(formatShareOptions);
|
|
1435
1537
|
sharedKeys.forEach((sharedKey)=>{
|
|
1436
1538
|
const sharedVal = formatShareOptions[sharedKey];
|
|
1437
|
-
const
|
|
1438
|
-
if (!
|
|
1539
|
+
const registeredShared = share.getRegisteredShare(this.shareScopeMap, sharedKey, sharedVal, this.hooks.lifecycle.resolveShare);
|
|
1540
|
+
if (!registeredShared && sharedVal && sharedVal.lib) {
|
|
1439
1541
|
this.setShared({
|
|
1440
1542
|
pkgName: sharedKey,
|
|
1441
1543
|
lib: sharedVal.lib,
|
|
1442
1544
|
get: sharedVal.get,
|
|
1545
|
+
loaded: true,
|
|
1443
1546
|
shared: sharedVal,
|
|
1444
1547
|
from: userOptions.name
|
|
1445
1548
|
});
|
|
@@ -1474,7 +1577,6 @@ class FederationHost {
|
|
|
1474
1577
|
]);
|
|
1475
1578
|
}
|
|
1476
1579
|
setShared({ pkgName, shared, from, lib, loading, loaded, get }) {
|
|
1477
|
-
const target = share.getGlobalShareScope();
|
|
1478
1580
|
const { version, scope = 'default' } = shared, shareInfo = _object_without_properties_loose(shared, [
|
|
1479
1581
|
"version",
|
|
1480
1582
|
"scope"
|
|
@@ -1483,23 +1585,16 @@ class FederationHost {
|
|
|
1483
1585
|
scope
|
|
1484
1586
|
];
|
|
1485
1587
|
scopes.forEach((sc)=>{
|
|
1486
|
-
if (!
|
|
1487
|
-
|
|
1588
|
+
if (!this.shareScopeMap[sc]) {
|
|
1589
|
+
this.shareScopeMap[sc] = {};
|
|
1488
1590
|
}
|
|
1489
|
-
if (!
|
|
1490
|
-
|
|
1591
|
+
if (!this.shareScopeMap[sc][pkgName]) {
|
|
1592
|
+
this.shareScopeMap[sc][pkgName] = {};
|
|
1491
1593
|
}
|
|
1492
|
-
if (
|
|
1493
|
-
share.warn(// eslint-disable-next-line max-len
|
|
1494
|
-
`The share \n ${share.safeToString({
|
|
1495
|
-
scope: sc,
|
|
1496
|
-
pkgName,
|
|
1497
|
-
version,
|
|
1498
|
-
from: target[sc][pkgName][version].from
|
|
1499
|
-
})} has been registered`);
|
|
1594
|
+
if (this.shareScopeMap[sc][pkgName][version]) {
|
|
1500
1595
|
return;
|
|
1501
1596
|
}
|
|
1502
|
-
|
|
1597
|
+
this.shareScopeMap[sc][pkgName][version] = _extends({
|
|
1503
1598
|
version,
|
|
1504
1599
|
scope: [
|
|
1505
1600
|
'default'
|
|
@@ -1510,7 +1605,7 @@ class FederationHost {
|
|
|
1510
1605
|
loading
|
|
1511
1606
|
});
|
|
1512
1607
|
if (get) {
|
|
1513
|
-
|
|
1608
|
+
this.shareScopeMap[sc][pkgName][version].get = get;
|
|
1514
1609
|
}
|
|
1515
1610
|
});
|
|
1516
1611
|
}
|
|
@@ -1520,26 +1615,33 @@ class FederationHost {
|
|
|
1520
1615
|
init: new SyncHook(),
|
|
1521
1616
|
beforeRequest: new AsyncWaterfallHook('beforeRequest'),
|
|
1522
1617
|
afterResolve: new AsyncWaterfallHook('afterResolve'),
|
|
1618
|
+
// maybe will change, temporarily for internal use only
|
|
1523
1619
|
beforeInitContainer: new AsyncWaterfallHook('beforeInitContainer'),
|
|
1620
|
+
// maybe will change, temporarily for internal use only
|
|
1621
|
+
initContainerShareScopeMap: new AsyncWaterfallHook('initContainer'),
|
|
1622
|
+
// maybe will change, temporarily for internal use only
|
|
1524
1623
|
initContainer: new AsyncWaterfallHook('initContainer'),
|
|
1525
1624
|
onLoad: new AsyncHook('onLoad'),
|
|
1526
1625
|
handlePreloadModule: new SyncHook('handlePreloadModule'),
|
|
1527
1626
|
errorLoadRemote: new AsyncHook('errorLoadRemote'),
|
|
1528
1627
|
beforeLoadShare: new AsyncWaterfallHook('beforeLoadShare'),
|
|
1628
|
+
// not used yet
|
|
1529
1629
|
loadShare: new AsyncHook(),
|
|
1630
|
+
resolveShare: new SyncWaterfallHook('resolveShare'),
|
|
1530
1631
|
beforePreloadRemote: new AsyncHook(),
|
|
1531
1632
|
generatePreloadAssets: new AsyncHook('generatePreloadAssets'),
|
|
1633
|
+
// not used yet
|
|
1532
1634
|
afterPreloadRemote: new AsyncHook()
|
|
1533
1635
|
});
|
|
1534
|
-
this.version =
|
|
1636
|
+
this.version = "0.0.9";
|
|
1535
1637
|
this.moduleCache = new Map();
|
|
1536
1638
|
this.loaderHook = new PluginSystem({
|
|
1537
|
-
// FIXME: may not be suitable
|
|
1639
|
+
// FIXME: may not be suitable , not open to the public yet
|
|
1538
1640
|
getModuleInfo: new SyncHook(),
|
|
1539
1641
|
createScript: new SyncHook(),
|
|
1642
|
+
// only work for manifest , so not open to the public yet
|
|
1540
1643
|
fetch: new AsyncHook('fetch')
|
|
1541
1644
|
});
|
|
1542
|
-
this.loadingShare = {};
|
|
1543
1645
|
// TODO: Validate the details of the options
|
|
1544
1646
|
// Initialize options with default values
|
|
1545
1647
|
const defaultOptions = {
|
|
@@ -1555,6 +1657,8 @@ class FederationHost {
|
|
|
1555
1657
|
};
|
|
1556
1658
|
this.name = userOptions.name;
|
|
1557
1659
|
this.options = defaultOptions;
|
|
1660
|
+
this.shareScopeMap = {};
|
|
1661
|
+
this._setGlobalShareScopeMap();
|
|
1558
1662
|
this.snapshotHandler = new SnapshotHandler(this);
|
|
1559
1663
|
this.registerPlugins([
|
|
1560
1664
|
...defaultOptions.plugins,
|
|
@@ -1577,6 +1681,9 @@ function init(options) {
|
|
|
1577
1681
|
} else {
|
|
1578
1682
|
// Merge options
|
|
1579
1683
|
instance.initOptions(options);
|
|
1684
|
+
if (!FederationInstance) {
|
|
1685
|
+
FederationInstance = instance;
|
|
1686
|
+
}
|
|
1580
1687
|
return instance;
|
|
1581
1688
|
}
|
|
1582
1689
|
}
|
|
@@ -1604,6 +1711,10 @@ function preloadRemote(...args) {
|
|
|
1604
1711
|
share.setGlobalFederationConstructor(FederationHost);
|
|
1605
1712
|
|
|
1606
1713
|
exports.registerGlobalPlugins = share.registerGlobalPlugins;
|
|
1714
|
+
Object.defineProperty(exports, 'loadScript', {
|
|
1715
|
+
enumerable: true,
|
|
1716
|
+
get: function () { return sdk.loadScript; }
|
|
1717
|
+
});
|
|
1607
1718
|
exports.FederationHost = FederationHost;
|
|
1608
1719
|
exports.init = init;
|
|
1609
1720
|
exports.loadRemote = loadRemote;
|