@module-federation/runtime 0.0.0-next-20231230034830 → 0.0.0-next-20240102023857
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 +71 -153
- package/dist/index.esm.js +73 -152
- package/dist/package.json +2 -2
- package/dist/share.cjs.js +51 -80
- package/dist/share.esm.js +51 -80
- package/dist/src/core.d.ts +5 -18
- package/dist/src/global.d.ts +3 -2
- package/dist/src/helpers.d.ts +2 -2
- package/dist/src/index.d.ts +0 -1
- package/dist/src/module/index.d.ts +2 -4
- package/dist/src/type/config.d.ts +2 -6
- package/dist/src/utils/share.d.ts +3 -12
- package/dist/type.cjs.d.ts +1 -0
- package/package.json +4 -4
- package/dist/types.cjs.d.ts +0 -1
- /package/dist/{types.cjs.js → type.cjs.js} +0 -0
- /package/dist/{types.esm.js → type.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 getGlobalShare, x as getGlobalShareScope, 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
|
+
getGlobalShare,
|
|
5
5
|
getGlobalShareScope
|
|
6
6
|
};
|
|
7
7
|
const GlobalUtils = {
|
package/dist/index.cjs.js
CHANGED
|
@@ -121,27 +121,6 @@ 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
|
-
}
|
|
145
124
|
return sdk.loadScript(entry, {
|
|
146
125
|
attrs: {},
|
|
147
126
|
createScriptHook
|
|
@@ -154,8 +133,6 @@ async function loadEntryScript({ name, globalName, entry, createScriptHook }) {
|
|
|
154
133
|
2. ${remoteEntryKey} cannot be used to get remoteEntry exports in the window object.
|
|
155
134
|
`);
|
|
156
135
|
return entryExports;
|
|
157
|
-
}).catch((e)=>{
|
|
158
|
-
return e;
|
|
159
136
|
});
|
|
160
137
|
}
|
|
161
138
|
async function getRemoteEntry({ remoteEntryExports, remoteInfo, createScriptHook }) {
|
|
@@ -217,10 +194,6 @@ let Module = class Module {
|
|
|
217
194
|
const res = this.loaderHook.lifecycle.createScript.emit({
|
|
218
195
|
url
|
|
219
196
|
});
|
|
220
|
-
if (typeof document === 'undefined') {
|
|
221
|
-
//todo: needs real fix
|
|
222
|
-
return res;
|
|
223
|
-
}
|
|
224
197
|
if (res instanceof HTMLScriptElement) {
|
|
225
198
|
return res;
|
|
226
199
|
}
|
|
@@ -236,16 +209,15 @@ let Module = class Module {
|
|
|
236
209
|
const { loadFactory = true } = options || {
|
|
237
210
|
loadFactory: true
|
|
238
211
|
};
|
|
239
|
-
this.hostInfo.name;
|
|
240
212
|
// Get remoteEntry.js
|
|
241
213
|
const remoteEntryExports = await this.getEntry();
|
|
242
214
|
if (!this.inited) {
|
|
243
|
-
const
|
|
215
|
+
const globalShareScope = share.Global.__FEDERATION__.__SHARE__;
|
|
244
216
|
const remoteShareScope = this.remoteInfo.shareScope || 'default';
|
|
245
|
-
if (!
|
|
246
|
-
|
|
217
|
+
if (!globalShareScope[remoteShareScope]) {
|
|
218
|
+
globalShareScope[remoteShareScope] = {};
|
|
247
219
|
}
|
|
248
|
-
const shareScope =
|
|
220
|
+
const shareScope = globalShareScope[remoteShareScope];
|
|
249
221
|
// TODO: compat logic , it could be moved after providing startup hooks
|
|
250
222
|
const remoteEntryInitOptions = {
|
|
251
223
|
version: this.remoteInfo.version || '',
|
|
@@ -255,18 +227,10 @@ let Module = class Module {
|
|
|
255
227
|
remoteEntryExports.init(shareScope, [], remoteEntryInitOptions);
|
|
256
228
|
const federationInstance = share.Global.__FEDERATION__.__INSTANCES__.find((i)=>i.options.id === sdk.composeKeyWithSeparator(this.remoteInfo.name, this.remoteInfo.buildVersion));
|
|
257
229
|
if (federationInstance) {
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
remotes: [],
|
|
263
|
-
name: this.remoteInfo.name
|
|
264
|
-
}));
|
|
265
|
-
if (!__FEDERATION__.__SHARE__['default'] && this.shareScopeMap && this.shareScopeMap['default']) {
|
|
266
|
-
// @ts-ignore compat prev logic , and it will be optimized by supporting startup hook
|
|
267
|
-
__FEDERATION__.__SHARE__['default'] = this.shareScopeMap['default'];
|
|
268
|
-
}
|
|
269
|
-
}
|
|
230
|
+
federationInstance.initOptions(_extends$4({}, remoteEntryInitOptions, {
|
|
231
|
+
remotes: [],
|
|
232
|
+
name: this.remoteInfo.name
|
|
233
|
+
}));
|
|
270
234
|
}
|
|
271
235
|
}
|
|
272
236
|
this.lib = remoteEntryExports;
|
|
@@ -281,7 +245,7 @@ let Module = class Module {
|
|
|
281
245
|
return exposeContent;
|
|
282
246
|
}
|
|
283
247
|
// loading: Record<string, undefined | Promise<RemoteEntryExports | void>> = {};
|
|
284
|
-
constructor({ hostInfo, remoteInfo, shared, loaderHook
|
|
248
|
+
constructor({ hostInfo, remoteInfo, shared, loaderHook }){
|
|
285
249
|
this.inited = false;
|
|
286
250
|
this.shared = {};
|
|
287
251
|
this.lib = undefined;
|
|
@@ -289,7 +253,6 @@ let Module = class Module {
|
|
|
289
253
|
this.remoteInfo = remoteInfo;
|
|
290
254
|
this.shared = shared;
|
|
291
255
|
this.loaderHook = loaderHook;
|
|
292
|
-
this.shareScopeMap = shareScopeMap;
|
|
293
256
|
}
|
|
294
257
|
};
|
|
295
258
|
|
|
@@ -816,9 +779,9 @@ function generatePreloadAssets(origin, preloadOptions, remote, globalSnapshot, r
|
|
|
816
779
|
if (!shareInfo) {
|
|
817
780
|
return;
|
|
818
781
|
}
|
|
819
|
-
const
|
|
782
|
+
const globalShare = share.getGlobalShare(shared.sharedName, shareInfo);
|
|
820
783
|
// 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.
|
|
821
|
-
if (
|
|
784
|
+
if (globalShare && typeof globalShare.lib === 'function') {
|
|
822
785
|
shared.assets.js.sync.forEach((asset)=>{
|
|
823
786
|
loadedSharedJsAssets.add(asset);
|
|
824
787
|
});
|
|
@@ -1145,13 +1108,6 @@ function _object_without_properties_loose(source, excluded) {
|
|
|
1145
1108
|
return target;
|
|
1146
1109
|
}
|
|
1147
1110
|
class FederationHost {
|
|
1148
|
-
_setGlobalShareScopeMap() {
|
|
1149
|
-
const globalShareScopeMap = share.getGlobalShareScope();
|
|
1150
|
-
const identifier = this.options.id || this.options.name;
|
|
1151
|
-
if (identifier && !globalShareScopeMap[identifier]) {
|
|
1152
|
-
globalShareScopeMap[identifier] = this.shareScopeMap;
|
|
1153
|
-
}
|
|
1154
|
-
}
|
|
1155
1111
|
initOptions(userOptions) {
|
|
1156
1112
|
this.registerPlugins(userOptions.plugins);
|
|
1157
1113
|
const options = this.formatOptions(this.options, userOptions);
|
|
@@ -1166,11 +1122,6 @@ class FederationHost {
|
|
|
1166
1122
|
// 2. Searches globally for a matching share, if found, it uses it directly
|
|
1167
1123
|
// 3. If not found, it retrieves it from the current share and stores the obtained share globally.
|
|
1168
1124
|
const shareInfo = Object.assign({}, (_this_options_shared = this.options.shared) == null ? void 0 : _this_options_shared[pkgName], customShareInfo);
|
|
1169
|
-
if (shareInfo == null ? void 0 : shareInfo.scope) {
|
|
1170
|
-
shareInfo.scope.forEach((shareScope)=>{
|
|
1171
|
-
this.initializeSharing(shareScope, shareInfo.strategy);
|
|
1172
|
-
});
|
|
1173
|
-
}
|
|
1174
1125
|
const loadShareRes = await this.hooks.lifecycle.beforeLoadShare.emit({
|
|
1175
1126
|
pkgName,
|
|
1176
1127
|
shareInfo,
|
|
@@ -1181,42 +1132,30 @@ class FederationHost {
|
|
|
1181
1132
|
// Assert that shareInfoRes exists, if not, throw an error
|
|
1182
1133
|
share.assert(shareInfoRes, `Cannot find ${pkgName} Share in the ${this.options.name}. Please ensure that the ${pkgName} Share parameters have been injected`);
|
|
1183
1134
|
// Retrieve from cache
|
|
1184
|
-
const
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
if (registeredShared && registeredShared.lib) {
|
|
1192
|
-
addUseIn(registeredShared);
|
|
1193
|
-
return registeredShared.lib;
|
|
1194
|
-
} else if (registeredShared && registeredShared.loading && !registeredShared.loaded) {
|
|
1195
|
-
const factory = await registeredShared.loading;
|
|
1196
|
-
registeredShared.loaded = true;
|
|
1197
|
-
if (!registeredShared.lib) {
|
|
1198
|
-
registeredShared.lib = factory;
|
|
1199
|
-
}
|
|
1200
|
-
addUseIn(registeredShared);
|
|
1135
|
+
const globalShare = share.getGlobalShare(pkgName, shareInfoRes);
|
|
1136
|
+
if (globalShare && globalShare.lib) {
|
|
1137
|
+
share.addUniqueItem(globalShare.useIn, this.options.name);
|
|
1138
|
+
return globalShare.lib;
|
|
1139
|
+
} else if (globalShare && globalShare.loading) {
|
|
1140
|
+
const factory = await globalShare.loading;
|
|
1141
|
+
share.addUniqueItem(globalShare.useIn, this.options.name);
|
|
1201
1142
|
return factory;
|
|
1202
|
-
} else if (
|
|
1143
|
+
} else if (globalShare) {
|
|
1203
1144
|
const asyncLoadProcess = async ()=>{
|
|
1204
|
-
const factory = await
|
|
1145
|
+
const factory = await globalShare.get();
|
|
1205
1146
|
shareInfoRes.lib = factory;
|
|
1206
|
-
shareInfoRes.
|
|
1207
|
-
|
|
1208
|
-
const gShared = share.getRegisteredShare(this.shareScopeMap, pkgName, shareInfoRes, this.hooks.lifecycle.resolveShare);
|
|
1147
|
+
share.addUniqueItem(shareInfoRes.useIn, this.options.name);
|
|
1148
|
+
const gShared = share.getGlobalShare(pkgName, shareInfoRes);
|
|
1209
1149
|
if (gShared) {
|
|
1210
1150
|
gShared.lib = factory;
|
|
1211
|
-
gShared.loaded = true;
|
|
1212
1151
|
}
|
|
1213
1152
|
return factory;
|
|
1214
1153
|
};
|
|
1215
1154
|
const loading = asyncLoadProcess();
|
|
1216
1155
|
this.setShared({
|
|
1217
1156
|
pkgName,
|
|
1218
|
-
loaded:
|
|
1219
|
-
shared:
|
|
1157
|
+
loaded: true,
|
|
1158
|
+
shared: shareInfoRes,
|
|
1220
1159
|
from: this.options.name,
|
|
1221
1160
|
lib: null,
|
|
1222
1161
|
loading
|
|
@@ -1229,19 +1168,17 @@ class FederationHost {
|
|
|
1229
1168
|
const asyncLoadProcess = async ()=>{
|
|
1230
1169
|
const factory = await shareInfoRes.get();
|
|
1231
1170
|
shareInfoRes.lib = factory;
|
|
1232
|
-
shareInfoRes.
|
|
1233
|
-
|
|
1234
|
-
const gShared = share.getRegisteredShare(this.shareScopeMap, pkgName, shareInfoRes, this.hooks.lifecycle.resolveShare);
|
|
1171
|
+
share.addUniqueItem(shareInfoRes.useIn, this.options.name);
|
|
1172
|
+
const gShared = share.getGlobalShare(pkgName, shareInfoRes);
|
|
1235
1173
|
if (gShared) {
|
|
1236
1174
|
gShared.lib = factory;
|
|
1237
|
-
gShared.loaded = true;
|
|
1238
1175
|
}
|
|
1239
1176
|
return factory;
|
|
1240
1177
|
};
|
|
1241
1178
|
const loading = asyncLoadProcess();
|
|
1242
1179
|
this.setShared({
|
|
1243
1180
|
pkgName,
|
|
1244
|
-
loaded:
|
|
1181
|
+
loaded: true,
|
|
1245
1182
|
shared: shareInfoRes,
|
|
1246
1183
|
from: this.options.name,
|
|
1247
1184
|
lib: null,
|
|
@@ -1257,16 +1194,16 @@ class FederationHost {
|
|
|
1257
1194
|
loadShareSync(pkgName) {
|
|
1258
1195
|
var _this_options_shared;
|
|
1259
1196
|
const shareInfo = (_this_options_shared = this.options.shared) == null ? void 0 : _this_options_shared[pkgName];
|
|
1260
|
-
const
|
|
1261
|
-
if (
|
|
1262
|
-
share.addUniqueItem(
|
|
1263
|
-
if (!
|
|
1264
|
-
|
|
1265
|
-
if (
|
|
1197
|
+
const globalShare = share.getGlobalShare(pkgName, shareInfo);
|
|
1198
|
+
if (globalShare && typeof globalShare.lib === 'function') {
|
|
1199
|
+
share.addUniqueItem(globalShare.useIn, this.options.name);
|
|
1200
|
+
if (!globalShare.loaded) {
|
|
1201
|
+
globalShare.loaded = true;
|
|
1202
|
+
if (globalShare.from === this.options.name) {
|
|
1266
1203
|
shareInfo.loaded = true;
|
|
1267
1204
|
}
|
|
1268
1205
|
}
|
|
1269
|
-
return
|
|
1206
|
+
return globalShare.lib;
|
|
1270
1207
|
}
|
|
1271
1208
|
if (shareInfo.lib) {
|
|
1272
1209
|
if (!shareInfo.loaded) {
|
|
@@ -1337,8 +1274,7 @@ class FederationHost {
|
|
|
1337
1274
|
remoteInfo,
|
|
1338
1275
|
shared: this.options.shared || {},
|
|
1339
1276
|
plugins: this.options.plugins,
|
|
1340
|
-
loaderHook: this.loaderHook
|
|
1341
|
-
shareScopeMap: this.shareScopeMap
|
|
1277
|
+
loaderHook: this.loaderHook
|
|
1342
1278
|
};
|
|
1343
1279
|
if (!module) {
|
|
1344
1280
|
module = new Module(moduleOptions);
|
|
@@ -1380,19 +1316,11 @@ class FederationHost {
|
|
|
1380
1316
|
});
|
|
1381
1317
|
return moduleOrFactory;
|
|
1382
1318
|
} catch (error) {
|
|
1383
|
-
|
|
1384
|
-
from: 'runtime'
|
|
1385
|
-
};
|
|
1386
|
-
const failOver = await this.hooks.lifecycle.errorLoadRemote.emit({
|
|
1319
|
+
this.hooks.lifecycle.errorLoadRemote.emit({
|
|
1387
1320
|
id,
|
|
1388
|
-
error
|
|
1389
|
-
from,
|
|
1390
|
-
origin: this
|
|
1321
|
+
error
|
|
1391
1322
|
});
|
|
1392
|
-
|
|
1393
|
-
throw error;
|
|
1394
|
-
}
|
|
1395
|
-
return failOver;
|
|
1323
|
+
throw error;
|
|
1396
1324
|
}
|
|
1397
1325
|
}
|
|
1398
1326
|
// eslint-disable-next-line @typescript-eslint/member-ordering
|
|
@@ -1426,9 +1354,14 @@ class FederationHost {
|
|
|
1426
1354
|
* It accepts one argument, the name of the share scope.
|
|
1427
1355
|
* If the share scope does not exist, it creates one.
|
|
1428
1356
|
*/ // eslint-disable-next-line @typescript-eslint/member-ordering
|
|
1429
|
-
initializeSharing(shareScopeName = share.DEFAULT_SCOPE
|
|
1430
|
-
const
|
|
1357
|
+
initializeSharing(shareScopeName = share.DEFAULT_SCOPE) {
|
|
1358
|
+
const shareScopeLoading = share.Global.__FEDERATION__.__SHARE_SCOPE_LOADING__;
|
|
1359
|
+
const shareScope = share.Global.__FEDERATION__.__SHARE__;
|
|
1431
1360
|
const hostName = this.options.name;
|
|
1361
|
+
// Executes only once
|
|
1362
|
+
if (shareScopeLoading[shareScopeName]) {
|
|
1363
|
+
return shareScopeLoading[shareScopeName];
|
|
1364
|
+
}
|
|
1432
1365
|
// Creates a new share scope if necessary
|
|
1433
1366
|
if (!shareScope[shareScopeName]) {
|
|
1434
1367
|
shareScope[shareScopeName] = {};
|
|
@@ -1436,27 +1369,21 @@ class FederationHost {
|
|
|
1436
1369
|
// Executes all initialization snippets from all accessible modules
|
|
1437
1370
|
const scope = shareScope[shareScopeName];
|
|
1438
1371
|
const register = (name, shared)=>{
|
|
1439
|
-
var _activeVersion_shareConfig;
|
|
1440
1372
|
const { version, eager } = shared;
|
|
1441
1373
|
scope[name] = scope[name] || {};
|
|
1442
1374
|
const versions = scope[name];
|
|
1443
1375
|
const activeVersion = versions[version];
|
|
1444
|
-
const activeVersionEager = Boolean(activeVersion && (activeVersion.eager ||
|
|
1376
|
+
const activeVersionEager = Boolean(activeVersion && (activeVersion.eager || activeVersion.shareConfig.eager));
|
|
1445
1377
|
if (!activeVersion || !activeVersion.loaded && (Boolean(!eager) !== !activeVersionEager ? eager : hostName > activeVersion.from)) {
|
|
1446
1378
|
versions[version] = shared;
|
|
1447
1379
|
}
|
|
1448
1380
|
};
|
|
1449
1381
|
const promises = [];
|
|
1450
|
-
const initFn = (mod)=>mod && mod.init && mod.init(shareScope[shareScopeName]);
|
|
1451
1382
|
const initRemoteModule = async (key)=>{
|
|
1452
1383
|
const { module } = await this._getRemoteModuleAndOptions(key);
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
initFn(entry);
|
|
1457
|
-
module.inited = true;
|
|
1458
|
-
}
|
|
1459
|
-
}
|
|
1384
|
+
const initFn = (mod)=>mod && mod.init && mod.init(shareScope[shareScopeName]);
|
|
1385
|
+
const entry = await module.getEntry();
|
|
1386
|
+
initFn(entry);
|
|
1460
1387
|
};
|
|
1461
1388
|
Object.keys(this.options.shared).forEach((shareName)=>{
|
|
1462
1389
|
const shared = this.options.shared[shareName];
|
|
@@ -1464,17 +1391,15 @@ class FederationHost {
|
|
|
1464
1391
|
register(shareName, shared);
|
|
1465
1392
|
}
|
|
1466
1393
|
});
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1394
|
+
this.options.remotes.forEach((remote)=>{
|
|
1395
|
+
if (remote.shareScope === shareScopeName) {
|
|
1396
|
+
promises.push(initRemoteModule(remote.name));
|
|
1397
|
+
}
|
|
1398
|
+
});
|
|
1399
|
+
if (!promises.length) {
|
|
1400
|
+
return shareScopeLoading[shareScopeName] = true;
|
|
1473
1401
|
}
|
|
1474
|
-
return promises;
|
|
1475
|
-
}
|
|
1476
|
-
initShareScopeMap(scopeName, shareScope) {
|
|
1477
|
-
this.shareScopeMap[scopeName] = shareScope;
|
|
1402
|
+
return shareScopeLoading[shareScopeName] = Promise.all(promises).then(()=>shareScopeLoading[shareScopeName] = true);
|
|
1478
1403
|
}
|
|
1479
1404
|
formatOptions(globalOptions, userOptions) {
|
|
1480
1405
|
const formatShareOptions = share.formatShareConfigs(userOptions.shared || {}, userOptions.name);
|
|
@@ -1514,17 +1439,16 @@ class FederationHost {
|
|
|
1514
1439
|
}
|
|
1515
1440
|
return res;
|
|
1516
1441
|
}, globalOptionsRes.remotes);
|
|
1517
|
-
// register shared
|
|
1442
|
+
// register shared include lib
|
|
1518
1443
|
const sharedKeys = Object.keys(formatShareOptions);
|
|
1519
1444
|
sharedKeys.forEach((sharedKey)=>{
|
|
1520
1445
|
const sharedVal = formatShareOptions[sharedKey];
|
|
1521
|
-
const
|
|
1522
|
-
if (!
|
|
1446
|
+
const globalShare = share.getGlobalShare(sharedKey, sharedVal);
|
|
1447
|
+
if (!globalShare && sharedVal && sharedVal.lib) {
|
|
1523
1448
|
this.setShared({
|
|
1524
1449
|
pkgName: sharedKey,
|
|
1525
1450
|
lib: sharedVal.lib,
|
|
1526
1451
|
get: sharedVal.get,
|
|
1527
|
-
loaded: true,
|
|
1528
1452
|
shared: sharedVal,
|
|
1529
1453
|
from: userOptions.name
|
|
1530
1454
|
});
|
|
@@ -1559,6 +1483,7 @@ class FederationHost {
|
|
|
1559
1483
|
]);
|
|
1560
1484
|
}
|
|
1561
1485
|
setShared({ pkgName, shared, from, lib, loading, loaded, get }) {
|
|
1486
|
+
const target = share.getGlobalShareScope();
|
|
1562
1487
|
const { version, scope = 'default' } = shared, shareInfo = _object_without_properties_loose(shared, [
|
|
1563
1488
|
"version",
|
|
1564
1489
|
"scope"
|
|
@@ -1567,23 +1492,23 @@ class FederationHost {
|
|
|
1567
1492
|
scope
|
|
1568
1493
|
];
|
|
1569
1494
|
scopes.forEach((sc)=>{
|
|
1570
|
-
if (!
|
|
1571
|
-
|
|
1495
|
+
if (!target[sc]) {
|
|
1496
|
+
target[sc] = {};
|
|
1572
1497
|
}
|
|
1573
|
-
if (!
|
|
1574
|
-
|
|
1498
|
+
if (!target[sc][pkgName]) {
|
|
1499
|
+
target[sc][pkgName] = {};
|
|
1575
1500
|
}
|
|
1576
|
-
if (
|
|
1501
|
+
if (target[sc][pkgName][version]) {
|
|
1577
1502
|
share.warn(// eslint-disable-next-line max-len
|
|
1578
1503
|
`The share \n ${share.safeToString({
|
|
1579
1504
|
scope: sc,
|
|
1580
1505
|
pkgName,
|
|
1581
1506
|
version,
|
|
1582
|
-
from:
|
|
1507
|
+
from: target[sc][pkgName][version].from
|
|
1583
1508
|
})} has been registered`);
|
|
1584
1509
|
return;
|
|
1585
1510
|
}
|
|
1586
|
-
|
|
1511
|
+
target[sc][pkgName][version] = _extends({
|
|
1587
1512
|
version,
|
|
1588
1513
|
scope: [
|
|
1589
1514
|
'default'
|
|
@@ -1594,7 +1519,7 @@ class FederationHost {
|
|
|
1594
1519
|
loading
|
|
1595
1520
|
});
|
|
1596
1521
|
if (get) {
|
|
1597
|
-
|
|
1522
|
+
target[sc][pkgName][version].get = get;
|
|
1598
1523
|
}
|
|
1599
1524
|
});
|
|
1600
1525
|
}
|
|
@@ -1609,13 +1534,11 @@ class FederationHost {
|
|
|
1609
1534
|
errorLoadRemote: new AsyncHook('errorLoadRemote'),
|
|
1610
1535
|
beforeLoadShare: new AsyncWaterfallHook('beforeLoadShare'),
|
|
1611
1536
|
loadShare: new AsyncHook(),
|
|
1612
|
-
resolveShare: new SyncWaterfallHook('resolveShare'),
|
|
1613
1537
|
beforePreloadRemote: new AsyncHook(),
|
|
1614
1538
|
generatePreloadAssets: new AsyncHook('generatePreloadAssets'),
|
|
1615
1539
|
afterPreloadRemote: new AsyncHook()
|
|
1616
1540
|
});
|
|
1617
|
-
this.
|
|
1618
|
-
this.version = `0.0.5`;
|
|
1541
|
+
this.version = '0.0.5';
|
|
1619
1542
|
this.moduleCache = new Map();
|
|
1620
1543
|
this.loaderHook = new PluginSystem({
|
|
1621
1544
|
// FIXME: may not be suitable
|
|
@@ -1623,6 +1546,7 @@ class FederationHost {
|
|
|
1623
1546
|
createScript: new SyncHook(),
|
|
1624
1547
|
fetch: new AsyncHook('fetch')
|
|
1625
1548
|
});
|
|
1549
|
+
this.loadingShare = {};
|
|
1626
1550
|
// TODO: Validate the details of the options
|
|
1627
1551
|
// Initialize options with default values
|
|
1628
1552
|
const defaultOptions = {
|
|
@@ -1638,8 +1562,6 @@ class FederationHost {
|
|
|
1638
1562
|
};
|
|
1639
1563
|
this.name = userOptions.name;
|
|
1640
1564
|
this.options = defaultOptions;
|
|
1641
|
-
this.shareScopeMap = {};
|
|
1642
|
-
this._setGlobalShareScopeMap();
|
|
1643
1565
|
this.snapshotHandler = new SnapshotHandler(this);
|
|
1644
1566
|
this.registerPlugins([
|
|
1645
1567
|
...defaultOptions.plugins,
|
|
@@ -1689,10 +1611,6 @@ function preloadRemote(...args) {
|
|
|
1689
1611
|
share.setGlobalFederationConstructor(FederationHost);
|
|
1690
1612
|
|
|
1691
1613
|
exports.registerGlobalPlugins = share.registerGlobalPlugins;
|
|
1692
|
-
Object.defineProperty(exports, 'loadScript', {
|
|
1693
|
-
enumerable: true,
|
|
1694
|
-
get: function () { return sdk.loadScript; }
|
|
1695
|
-
});
|
|
1696
1614
|
exports.FederationHost = FederationHost;
|
|
1697
1615
|
exports.init = init;
|
|
1698
1616
|
exports.loadRemote = loadRemote;
|