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